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): ...@@ -34,6 +34,16 @@ class Application(object):
def get_allowed_thread_requests(self): def get_allowed_thread_requests(self):
return self.thread_fsm_table[self.thread_state].keys() 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): def update_threads(self, msg):
"""Update the thread tracking.""" """Update the thread tracking."""
newth = msg['payload'] newth = msg['payload']
......
from __future__ import print_function from __future__ import print_function
import logging import logging
from operator import attrgetter
logger = logging.getLogger('nrm') logger = logging.getLogger('nrm')
...@@ -9,9 +10,27 @@ class Action(object): ...@@ -9,9 +10,27 @@ class Action(object):
"""Information about a control action.""" """Information about a control action."""
def __init__(self, target, command): def __init__(self, target, command, delta):
self.target = target self.target = target
self.command = command 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): class Controller(object):
...@@ -22,21 +41,25 @@ class Controller(object): ...@@ -22,21 +41,25 @@ class Controller(object):
self.application_manager = am self.application_manager = am
self.container_manager = cm self.container_manager = cm
self.resource_manager = rm self.resource_manager = rm
self.app_actuator = ApplicationActuator(am)
def planify(self, target, machineinfo): def planify(self, target, machineinfo):
"""Plan the next action for the control loop.""" """Plan the next action for the control loop."""
total_power = machineinfo['energy']['power']['total'] total_power = machineinfo['energy']['power']['total']
direction = None
if total_power < target: if total_power < target:
for identity, application in \ direction = 'i'
self.application_manager.applications.iteritems():
if 'i' in application.get_allowed_thread_requests():
return Action(application, 'i')
elif total_power > target: elif total_power > target:
for identity, application in \ direction = 'd'
self.application_manager.applications.iteritems():
if 'd' in application.get_allowed_thread_requests(): if direction:
return Action(application, 'd') actions = self.app_actuator.available_actions(direction)
return None if actions:
# TODO: better choice
actions.sort(key=attrgetter('delta'))
return actions.pop()
else:
return None
def execute(self, action): def execute(self, action):
"""Build the action for the appropriate manager.""" """Build the action for the appropriate manager."""
......
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