Commit cbbf2354 authored by Swann Perarnau's avatar Swann Perarnau

[feature] Add actuator to the controller logic

This patch introduce one more level of abstraction to the controller:
an actuator. Actuators will act as the middleman between specific
managers and the controller, while providing enough info to implement
actual models on top.

For now, we only have the application threads actuator.
parent 246edb75
......@@ -34,6 +34,16 @@ class Application(object):
def get_allowed_thread_requests(self):
return self.thread_fsm_table[self.thread_state].keys()
def get_thread_request_impact(self, command):
# TODO: not a real model
if command not in self.thread_fsm_table[self.thread_state]:
return 0.0
speed = float(self.progress)/float(self.threads['cur'])
if command == 'i':
return speed
else:
return -speed
def update_threads(self, msg):
"""Update the thread tracking."""
newth = msg['payload']
......
from __future__ import print_function
import logging
from operator import attrgetter
logger = logging.getLogger('nrm')
......@@ -9,9 +10,27 @@ class Action(object):
"""Information about a control action."""
def __init__(self, target, command):
def __init__(self, target, command, delta):
self.target = target
self.command = command
self.delta = delta
class ApplicationActuator(object):
"""Actuator in charge of application thread control."""
def __init__(self, am):
self.application_manager = am
def available_actions(self, target):
ret = []
for identity, application in \
self.application_manager.applications.iteritems():
if target in application.get_allowed_thread_requests():
delta = application.get_thread_request_impact(target)
ret.append(Action(application, target, delta))
return ret
class Controller(object):
......@@ -22,20 +41,24 @@ class Controller(object):
self.application_manager = am
self.container_manager = cm
self.resource_manager = rm
self.app_actuator = ApplicationActuator(am)
def planify(self, target, machineinfo):
"""Plan the next action for the control loop."""
total_power = machineinfo['energy']['power']['total']
direction = None
if total_power < target:
for identity, application in \
self.application_manager.applications.iteritems():
if 'i' in application.get_allowed_thread_requests():
return Action(application, 'i')
direction = 'i'
elif total_power > target:
for identity, application in \
self.application_manager.applications.iteritems():
if 'd' in application.get_allowed_thread_requests():
return Action(application, 'd')
direction = 'd'
if direction:
actions = self.app_actuator.available_actions(direction)
if actions:
# TODO: better choice
actions.sort(key=attrgetter('delta'))
return actions.pop()
else:
return None
def execute(self, action):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment