Permalink
Browse files

Update Service state on apply policy loop in ha agent

  • Loading branch information...
1 parent 4609558 commit d37e171000e85db5a3011169f8e281606bd5a468 @oldpatricka oldpatricka committed Nov 9, 2012
Showing with 24 additions and 3 deletions.
  1. +17 −2 ion/agents/cei/high_availability_agent.py
  2. +7 −1 ion/agents/cei/test/test_haagent.py
@@ -6,7 +6,8 @@
from pyon.core.exception import BadRequest
from interface.objects import AgentCommand, ProcessDefinition, ProcessSchedule,\
- ProcessStateEnum, ProcessQueueingMode, ProcessTarget, ProcessRestartMode, Service
+ ProcessStateEnum, ProcessQueueingMode, ProcessTarget, ProcessRestartMode,\
+ Service, ServiceStateEnum
from interface.services.cei.iprocess_dispatcher_service import ProcessDispatcherServiceClient
from ion.agents.cei.util import looping_call
from ion.services.cei.process_dispatcher_service import _core_process_definition_from_ion, \
@@ -83,7 +84,7 @@ def on_init(self):
pd_client_kwargs={'container': self.container,
'service_id': self.service_id})
- self.policy_thread = looping_call(self.policy_interval, self.core.apply_policy)
+ self.policy_thread = looping_call(self.policy_interval, self._apply_policy)
dashi_messaging = self.CFG.get_safe("highavailability.dashi_messaging", False)
if dashi_messaging:
@@ -165,6 +166,17 @@ def _unregister_service(self):
self.container.resource_registry.delete(self.service_id, del_associations=True)
+ def _apply_policy(self):
+
+ self.core.apply_policy()
+
+ try:
+ service = self.container.resource_registry.read(self.service_id)
+ service.state = _core_hastate_to_service_state(self.core.status())
+ self.container.resource_registry.update(service)
+ except Exception:
+ log.exception("Problem when updating Service state")
+
def rcmd_reconfigure_policy(self, new_policy):
"""Service operation: Change the parameters of the policy used for service
@@ -359,3 +371,6 @@ def describe_processes(self):
}
dict_procs.append(dict_proc)
return dict_procs
+
+def _core_hastate_to_service_state(core):
+ return ServiceStateEnum._value_map.get(core)
@@ -26,7 +26,7 @@
from interface.services.icontainer_agent import ContainerAgentClient
from interface.services.cei.iprocess_dispatcher_service import ProcessDispatcherServiceClient
-from interface.objects import ProcessStateEnum, ProcessDefinition
+from interface.objects import ProcessStateEnum, ProcessDefinition, ServiceStateEnum
class FakeProcess(LocalContextMixin):
@@ -195,6 +195,12 @@ def test_features(self):
else:
assert False, "HA Service took too long to get to state STEADY"
+ # Ensure Service object has the correct state
+ result = self.haa_client.dump().result
+ service_id = result.get('service_id')
+ service = self.container.resource_registry.read(service_id)
+ self.assertEqual(service.state, ServiceStateEnum.STEADY)
+
# verifies L4-CI-CEI-RQ122 and L4-CI-CEI-RQ124
new_policy = {'preserve_n': 2}

0 comments on commit d37e171

Please sign in to comment.