Merge "Rename Command to Action"
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
from watcher.applier.base import Applier
|
||||
from watcher.applier.execution.executor import CommandExecutor
|
||||
from watcher.applier.execution.executor import ActionPlanExecutor
|
||||
from watcher.objects import Action
|
||||
from watcher.objects import ActionPlan
|
||||
|
||||
@@ -27,7 +27,7 @@ class DefaultApplier(Applier):
|
||||
super(DefaultApplier, self).__init__()
|
||||
self.manager_applier = manager_applier
|
||||
self.context = context
|
||||
self.executor = CommandExecutor(manager_applier, context)
|
||||
self.executor = ActionPlanExecutor(manager_applier, context)
|
||||
|
||||
def execute(self, action_plan_uuid):
|
||||
action_plan = ActionPlan.get_by_uuid(self.context, action_plan_uuid)
|
||||
|
||||
@@ -24,19 +24,31 @@ LOG = log.getLogger(__name__)
|
||||
class DeployPhase(object):
|
||||
def __init__(self, executor):
|
||||
# todo(jed) oslo_conf 10 secondes
|
||||
self.max_timeout = 100000
|
||||
self.commands = []
|
||||
self.executor = executor
|
||||
self._max_timeout = 100000
|
||||
self._actions = []
|
||||
self._executor = executor
|
||||
|
||||
@property
|
||||
def actions(self):
|
||||
return self._actions
|
||||
|
||||
@property
|
||||
def max_timeout(self):
|
||||
return self._max_timeout
|
||||
|
||||
@max_timeout.setter
|
||||
def max_timeout(self, m):
|
||||
self._max_timeout = m
|
||||
|
||||
def populate(self, action):
|
||||
self.commands.append(action)
|
||||
self._actions.append(action)
|
||||
|
||||
def execute_primitive(self, primitive):
|
||||
future = primitive.execute(primitive)
|
||||
return future.result(self.max_timeout)
|
||||
|
||||
def rollback(self):
|
||||
reverted = sorted(self.commands, reverse=True)
|
||||
reverted = sorted(self.actions, reverse=True)
|
||||
for primitive in reverted:
|
||||
try:
|
||||
self.execute_primitive(primitive)
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#
|
||||
from oslo_log import log
|
||||
|
||||
from watcher.applier.mapper.default import DefaultCommandMapper
|
||||
from watcher.applier.mapper.default import DefaultActionMapper
|
||||
|
||||
from watcher.applier.execution.deploy_phase import DeployPhase
|
||||
from watcher.applier.messaging.events import Events
|
||||
@@ -29,15 +29,15 @@ from watcher.objects.action_plan import Status
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class CommandExecutor(object):
|
||||
class ActionPlanExecutor(object):
|
||||
def __init__(self, manager_applier, context):
|
||||
self.manager_applier = manager_applier
|
||||
self.context = context
|
||||
self.deploy = DeployPhase(self)
|
||||
self.mapper = DefaultCommandMapper()
|
||||
self.mapper = DefaultActionMapper()
|
||||
|
||||
def get_primitive(self, action):
|
||||
return self.mapper.build_primitive_command(action)
|
||||
return self.mapper.build_primitive_from_action(action)
|
||||
|
||||
def notify(self, action, state):
|
||||
db_action = Action.get_by_uuid(self.context, action.uuid)
|
||||
|
||||
@@ -22,8 +22,13 @@ import six
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class CommandMapper(object):
|
||||
class BaseActionMapper(object):
|
||||
@abc.abstractmethod
|
||||
def build_primitive_command(self, action):
|
||||
def build_primitive_from_action(self, action):
|
||||
"""Transform an action to a primitive
|
||||
|
||||
:type action: watcher.decision_engine.action.BaseAction
|
||||
:return: the associated Primitive
|
||||
"""
|
||||
raise NotImplementedError(
|
||||
"Should have implemented this") # pragma:no cover
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#
|
||||
|
||||
|
||||
from watcher.applier.mapper.base import CommandMapper
|
||||
from watcher.applier.mapper.base import BaseActionMapper
|
||||
from watcher.applier.primitive.hypervisor_state import HypervisorStateCommand
|
||||
from watcher.applier.primitive.migration import MigrateCommand
|
||||
from watcher.applier.primitive.nop import NopCommand
|
||||
@@ -27,8 +27,8 @@ from watcher.common.exception import ActionNotFound
|
||||
from watcher.decision_engine.planner.default import Primitives
|
||||
|
||||
|
||||
class DefaultCommandMapper(CommandMapper):
|
||||
def build_primitive_command(self, action):
|
||||
class DefaultActionMapper(BaseActionMapper):
|
||||
def build_primitive_from_action(self, action):
|
||||
if action.action_type == Primitives.COLD_MIGRATE.value:
|
||||
return MigrateCommand(action.applies_to, Primitives.COLD_MIGRATE,
|
||||
action.src,
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#
|
||||
import mock
|
||||
|
||||
from watcher.applier.execution.executor import CommandExecutor
|
||||
from watcher.applier.execution.executor import ActionPlanExecutor
|
||||
from watcher import objects
|
||||
|
||||
from watcher.common import utils
|
||||
@@ -32,7 +32,7 @@ class TestCommandExecutor(DbTestCase):
|
||||
def setUp(self):
|
||||
super(TestCommandExecutor, self).setUp()
|
||||
self.applier = mock.MagicMock()
|
||||
self.executor = CommandExecutor(self.applier, self.context)
|
||||
self.executor = ActionPlanExecutor(self.applier, self.context)
|
||||
|
||||
def test_execute(self):
|
||||
actions = mock.MagicMock()
|
||||
@@ -17,7 +17,7 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
import mock
|
||||
from watcher.applier.mapper.default import DefaultCommandMapper
|
||||
from watcher.applier.mapper.default import DefaultActionMapper
|
||||
from watcher.decision_engine.planner.default import Primitives
|
||||
from watcher.tests import base
|
||||
|
||||
@@ -25,33 +25,34 @@ from watcher.tests import base
|
||||
class TestCommandMapper(base.TestCase):
|
||||
def setUp(self):
|
||||
super(TestCommandMapper, self).setUp()
|
||||
self.mapper = DefaultCommandMapper()
|
||||
self.mapper = DefaultActionMapper()
|
||||
|
||||
def test_build_command_cold(self):
|
||||
action = mock.MagicMock()
|
||||
action.action_type = Primitives.COLD_MIGRATE.value
|
||||
cmd = self.mapper.build_primitive_command(action)
|
||||
cmd = self.mapper.build_primitive_from_action(action)
|
||||
self.assertIsNotNone(cmd)
|
||||
|
||||
def test_build_command_live(self):
|
||||
action = mock.MagicMock()
|
||||
action.action_type = Primitives.LIVE_MIGRATE.value
|
||||
cmd = self.mapper.build_primitive_command(action)
|
||||
cmd = self.mapper.build_primitive_from_action(action)
|
||||
self.assertIsNotNone(cmd)
|
||||
|
||||
def test_build_command_h_s(self):
|
||||
action = mock.MagicMock()
|
||||
action.action_type = Primitives.HYPERVISOR_STATE.value
|
||||
cmd = self.mapper.build_primitive_command(action)
|
||||
cmd = self.mapper.build_primitive_from_action(action)
|
||||
self.assertIsNotNone(cmd)
|
||||
|
||||
def test_build_command_p_s(self):
|
||||
action = mock.MagicMock()
|
||||
action.action_type = Primitives.POWER_STATE.value
|
||||
cmd = self.mapper.build_primitive_command(action)
|
||||
cmd = self.mapper.build_primitive_from_action(action)
|
||||
self.assertIsNotNone(cmd)
|
||||
|
||||
def test_build_command_exception_attribute(self):
|
||||
action = mock.MagicMock
|
||||
self.assertRaises(AttributeError, self.mapper.build_primitive_command,
|
||||
self.assertRaises(AttributeError,
|
||||
self.mapper.build_primitive_from_action,
|
||||
action)
|
||||
Reference in New Issue
Block a user