Added efficacy indicators to /action_plans
I this changeset, I added the efficacy indicators both at the DB and at the API level alongside the associated logic. Partially Implements: blueprint efficacy-indicator Change-Id: I824553637621da67966103c1b0c01348b09bd836
This commit is contained in:
@@ -59,19 +59,21 @@ class DefaultPlanner(base.BasePlanner):
|
||||
|
||||
def schedule(self, context, audit_id, solution):
|
||||
LOG.debug('Create an action plan for the audit uuid: %s ', audit_id)
|
||||
action_plan = self._create_action_plan(context, audit_id)
|
||||
action_plan = self._create_action_plan(context, audit_id, solution)
|
||||
|
||||
actions = list(solution.actions)
|
||||
to_schedule = []
|
||||
for action in actions:
|
||||
json_action = self.create_action(action_plan_id=action_plan.id,
|
||||
action_type=action.get(
|
||||
'action_type'),
|
||||
input_parameters=action.get(
|
||||
'input_parameters'))
|
||||
json_action = self.create_action(
|
||||
action_plan_id=action_plan.id,
|
||||
action_type=action.get('action_type'),
|
||||
input_parameters=action.get('input_parameters'))
|
||||
to_schedule.append((self.priorities[action.get('action_type')],
|
||||
json_action))
|
||||
|
||||
self._create_efficacy_indicators(
|
||||
context, action_plan.id, solution.efficacy_indicators)
|
||||
|
||||
# scheduling
|
||||
scheduled = sorted(to_schedule, key=lambda x: (x[0]))
|
||||
if len(scheduled) == 0:
|
||||
@@ -96,19 +98,38 @@ class DefaultPlanner(base.BasePlanner):
|
||||
|
||||
return action_plan
|
||||
|
||||
def _create_action_plan(self, context, audit_id):
|
||||
def _create_action_plan(self, context, audit_id, solution):
|
||||
action_plan_dict = {
|
||||
'uuid': utils.generate_uuid(),
|
||||
'audit_id': audit_id,
|
||||
'first_action_id': None,
|
||||
'state': objects.action_plan.State.RECOMMENDED
|
||||
'state': objects.action_plan.State.RECOMMENDED,
|
||||
'global_efficacy': solution.global_efficacy,
|
||||
}
|
||||
|
||||
new_action_plan = objects.ActionPlan(context, **action_plan_dict)
|
||||
new_action_plan.create(context)
|
||||
new_action_plan.save()
|
||||
|
||||
return new_action_plan
|
||||
|
||||
def _create_efficacy_indicators(self, context, action_plan_id, indicators):
|
||||
efficacy_indicators = []
|
||||
for indicator in indicators:
|
||||
efficacy_indicator_dict = {
|
||||
'uuid': utils.generate_uuid(),
|
||||
'name': indicator.name,
|
||||
'description': indicator.description,
|
||||
'unit': indicator.unit,
|
||||
'value': indicator.value,
|
||||
'action_plan_id': action_plan_id,
|
||||
}
|
||||
new_efficacy_indicator = objects.EfficacyIndicator(
|
||||
context, **efficacy_indicator_dict)
|
||||
new_efficacy_indicator.create(context)
|
||||
|
||||
efficacy_indicators.append(new_efficacy_indicator)
|
||||
return efficacy_indicators
|
||||
|
||||
def _create_action(self, context, _action, parent_action):
|
||||
try:
|
||||
LOG.debug("Creating the %s in watcher db",
|
||||
|
||||
Reference in New Issue
Block a user