Merge "Refactored Watcher objects to use OVO"
This commit is contained in:
@@ -26,7 +26,7 @@ from watcher.common.messaging.events import event as watcher_event
|
||||
from watcher.decision_engine.messaging import events as de_events
|
||||
from watcher.decision_engine.planner import manager as planner_manager
|
||||
from watcher.decision_engine.strategy.context import default as default_context
|
||||
from watcher.objects import audit as audit_objects
|
||||
from watcher import objects
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
@@ -89,13 +89,13 @@ class AuditHandler(BaseAuditHandler):
|
||||
def pre_execute(self, audit, request_context):
|
||||
LOG.debug("Trigger audit %s", audit.uuid)
|
||||
# change state of the audit to ONGOING
|
||||
self.update_audit_state(audit, audit_objects.State.ONGOING)
|
||||
self.update_audit_state(audit, objects.audit.State.ONGOING)
|
||||
|
||||
def post_execute(self, audit, solution, request_context):
|
||||
self.planner.schedule(request_context, audit.id, solution)
|
||||
|
||||
# change state of the audit to SUCCEEDED
|
||||
self.update_audit_state(audit, audit_objects.State.SUCCEEDED)
|
||||
self.update_audit_state(audit, objects.audit.State.SUCCEEDED)
|
||||
|
||||
def execute(self, audit, request_context):
|
||||
try:
|
||||
@@ -104,4 +104,4 @@ class AuditHandler(BaseAuditHandler):
|
||||
self.post_execute(audit, solution, request_context)
|
||||
except Exception as e:
|
||||
LOG.exception(e)
|
||||
self.update_audit_state(audit, audit_objects.State.FAILED)
|
||||
self.update_audit_state(audit, objects.audit.State.FAILED)
|
||||
|
||||
@@ -25,8 +25,7 @@ from oslo_config import cfg
|
||||
|
||||
from watcher.common import context
|
||||
from watcher.decision_engine.audit import base
|
||||
from watcher.objects import action_plan as action_objects
|
||||
from watcher.objects import audit as audit_objects
|
||||
from watcher import objects
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
@@ -56,11 +55,11 @@ class ContinuousAuditHandler(base.AuditHandler):
|
||||
return self._scheduler
|
||||
|
||||
def _is_audit_inactive(self, audit):
|
||||
audit = audit_objects.Audit.get_by_uuid(self.context_show_deleted,
|
||||
audit.uuid)
|
||||
if audit.state in (audit_objects.State.CANCELLED,
|
||||
audit_objects.State.DELETED,
|
||||
audit_objects.State.FAILED):
|
||||
audit = objects.Audit.get_by_uuid(
|
||||
self.context_show_deleted, audit.uuid)
|
||||
if audit.state in (objects.audit.State.CANCELLED,
|
||||
objects.audit.State.DELETED,
|
||||
objects.audit.State.FAILED):
|
||||
# if audit isn't in active states, audit's job must be removed to
|
||||
# prevent using of inactive audit in future.
|
||||
job_to_delete = [job for job in self.jobs
|
||||
@@ -77,14 +76,13 @@ class ContinuousAuditHandler(base.AuditHandler):
|
||||
solution = self.strategy_context.execute_strategy(
|
||||
audit, request_context)
|
||||
|
||||
if audit.audit_type == audit_objects.AuditType.CONTINUOUS.value:
|
||||
if audit.audit_type == objects.audit.AuditType.CONTINUOUS.value:
|
||||
a_plan_filters = {'audit_uuid': audit.uuid,
|
||||
'state': action_objects.State.RECOMMENDED}
|
||||
action_plans = action_objects.ActionPlan.list(
|
||||
request_context,
|
||||
filters=a_plan_filters)
|
||||
'state': objects.action_plan.State.RECOMMENDED}
|
||||
action_plans = objects.ActionPlan.list(
|
||||
request_context, filters=a_plan_filters)
|
||||
for plan in action_plans:
|
||||
plan.state = action_objects.State.CANCELLED
|
||||
plan.state = objects.action_plan.State.CANCELLED
|
||||
plan.save()
|
||||
return solution
|
||||
|
||||
@@ -98,13 +96,12 @@ class ContinuousAuditHandler(base.AuditHandler):
|
||||
def launch_audits_periodically(self):
|
||||
audit_context = context.RequestContext(is_admin=True)
|
||||
audit_filters = {
|
||||
'audit_type': audit_objects.AuditType.CONTINUOUS.value,
|
||||
'state__in': (audit_objects.State.PENDING,
|
||||
audit_objects.State.ONGOING,
|
||||
audit_objects.State.SUCCEEDED)
|
||||
'audit_type': objects.audit.AuditType.CONTINUOUS.value,
|
||||
'state__in': (objects.audit.State.PENDING,
|
||||
objects.audit.State.ONGOING,
|
||||
objects.audit.State.SUCCEEDED)
|
||||
}
|
||||
audits = audit_objects.Audit.list(audit_context,
|
||||
filters=audit_filters)
|
||||
audits = objects.Audit.list(audit_context, filters=audit_filters)
|
||||
scheduler_job_args = [job.args for job in self.scheduler.get_jobs()
|
||||
if job.name == 'execute_audit']
|
||||
for audit in audits:
|
||||
|
||||
@@ -23,7 +23,7 @@ from oslo_log import log
|
||||
|
||||
from watcher.decision_engine.audit import continuous as continuous_handler
|
||||
from watcher.decision_engine.audit import oneshot as oneshot_handler
|
||||
from watcher.objects import audit as audit_objects
|
||||
from watcher import objects
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
@@ -49,7 +49,7 @@ class AuditEndpoint(object):
|
||||
return self._messaging
|
||||
|
||||
def do_trigger_audit(self, context, audit_uuid):
|
||||
audit = audit_objects.Audit.get_by_uuid(context, audit_uuid)
|
||||
audit = objects.Audit.get_by_uuid(context, audit_uuid)
|
||||
self._oneshot_handler.execute(audit, context)
|
||||
|
||||
def trigger_audit(self, context, audit_uuid):
|
||||
|
||||
@@ -128,7 +128,7 @@ class DefaultPlanner(base.BasePlanner):
|
||||
}
|
||||
|
||||
new_action_plan = objects.ActionPlan(context, **action_plan_dict)
|
||||
new_action_plan.create(context)
|
||||
new_action_plan.create()
|
||||
|
||||
return new_action_plan
|
||||
|
||||
@@ -145,7 +145,7 @@ class DefaultPlanner(base.BasePlanner):
|
||||
}
|
||||
new_efficacy_indicator = objects.EfficacyIndicator(
|
||||
context, **efficacy_indicator_dict)
|
||||
new_efficacy_indicator.create(context)
|
||||
new_efficacy_indicator.create()
|
||||
|
||||
efficacy_indicators.append(new_efficacy_indicator)
|
||||
return efficacy_indicators
|
||||
@@ -156,7 +156,7 @@ class DefaultPlanner(base.BasePlanner):
|
||||
_action.get("action_type"))
|
||||
|
||||
new_action = objects.Action(context, **_action)
|
||||
new_action.create(context)
|
||||
new_action.create()
|
||||
new_action.save()
|
||||
|
||||
if parent_action:
|
||||
|
||||
@@ -23,8 +23,6 @@ from watcher.common import context
|
||||
from watcher.decision_engine.loading import default
|
||||
from watcher.decision_engine.scoring import scoring_factory
|
||||
from watcher import objects
|
||||
from watcher.objects import action_plan as apobjects
|
||||
from watcher.objects import audit as auditobjects
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
@@ -338,13 +336,13 @@ class Syncer(object):
|
||||
for audit in stale_audits:
|
||||
if audit.id not in self.stale_audits_map:
|
||||
audit.strategy_id = synced_strategy.id
|
||||
audit.state = auditobjects.State.CANCELLED
|
||||
audit.state = objects.audit.State.CANCELLED
|
||||
self.stale_audits_map[audit.id] = audit
|
||||
else:
|
||||
self.stale_audits_map[
|
||||
audit.id].strategy_id = synced_strategy.id
|
||||
self.stale_audits_map[
|
||||
audit.id].state = auditobjects.State.CANCELLED
|
||||
audit.id].state = objects.audit.State.CANCELLED
|
||||
|
||||
def _find_stale_action_plans_due_to_strategy(self):
|
||||
for strategy_id, synced_strategy in self.strategy_mapping.items():
|
||||
@@ -356,13 +354,14 @@ class Syncer(object):
|
||||
for action_plan in stale_action_plans:
|
||||
if action_plan.id not in self.stale_action_plans_map:
|
||||
action_plan.strategy_id = synced_strategy.id
|
||||
action_plan.state = apobjects.State.CANCELLED
|
||||
action_plan.state = objects.action_plan.State.CANCELLED
|
||||
self.stale_action_plans_map[action_plan.id] = action_plan
|
||||
else:
|
||||
self.stale_action_plans_map[
|
||||
action_plan.id].strategy_id = synced_strategy.id
|
||||
self.stale_action_plans_map[
|
||||
action_plan.id].state = apobjects.State.CANCELLED
|
||||
action_plan.id].state = (
|
||||
objects.action_plan.State.CANCELLED)
|
||||
|
||||
def _find_stale_action_plans_due_to_audit(self):
|
||||
for audit_id, synced_audit in self.stale_audits_map.items():
|
||||
@@ -374,13 +373,14 @@ class Syncer(object):
|
||||
for action_plan in stale_action_plans:
|
||||
if action_plan.id not in self.stale_action_plans_map:
|
||||
action_plan.audit_id = synced_audit.id
|
||||
action_plan.state = apobjects.State.CANCELLED
|
||||
action_plan.state = objects.action_plan.State.CANCELLED
|
||||
self.stale_action_plans_map[action_plan.id] = action_plan
|
||||
else:
|
||||
self.stale_action_plans_map[
|
||||
action_plan.id].audit_id = synced_audit.id
|
||||
self.stale_action_plans_map[
|
||||
action_plan.id].state = apobjects.State.CANCELLED
|
||||
action_plan.id].state = (
|
||||
objects.action_plan.State.CANCELLED)
|
||||
|
||||
def _soft_delete_removed_goals(self):
|
||||
removed_goals = [
|
||||
@@ -402,11 +402,11 @@ class Syncer(object):
|
||||
_LW("Audit '%(audit)s' references a "
|
||||
"goal that does not exist"), audit=audit.uuid)
|
||||
if audit.id not in self.stale_audits_map:
|
||||
audit.state = auditobjects.State.CANCELLED
|
||||
audit.state = objects.audit.State.CANCELLED
|
||||
self.stale_audits_map[audit.id] = audit
|
||||
else:
|
||||
self.stale_audits_map[
|
||||
audit.id].state = auditobjects.State.CANCELLED
|
||||
audit.id].state = objects.audit.State.CANCELLED
|
||||
|
||||
def _soft_delete_removed_strategies(self):
|
||||
removed_strategies = [
|
||||
@@ -437,11 +437,11 @@ class Syncer(object):
|
||||
_LW("Audit '%(audit)s' references a "
|
||||
"strategy that does not exist"), audit=audit.uuid)
|
||||
if audit.id not in self.stale_audits_map:
|
||||
audit.state = auditobjects.State.CANCELLED
|
||||
audit.state = objects.audit.State.CANCELLED
|
||||
self.stale_audits_map[audit.id] = audit
|
||||
else:
|
||||
self.stale_audits_map[
|
||||
audit.id].state = auditobjects.State.CANCELLED
|
||||
audit.id].state = objects.audit.State.CANCELLED
|
||||
|
||||
stale_action_plans = objects.ActionPlan.list(
|
||||
self.ctx, filters=filters)
|
||||
@@ -451,11 +451,12 @@ class Syncer(object):
|
||||
"strategy that does not exist"),
|
||||
action_plan=action_plan.uuid)
|
||||
if action_plan.id not in self.stale_action_plans_map:
|
||||
action_plan.state = apobjects.State.CANCELLED
|
||||
action_plan.state = objects.action_plan.State.CANCELLED
|
||||
self.stale_action_plans_map[action_plan.id] = action_plan
|
||||
else:
|
||||
self.stale_action_plans_map[
|
||||
action_plan.id].state = apobjects.State.CANCELLED
|
||||
action_plan.id].state = (
|
||||
objects.action_plan.State.CANCELLED)
|
||||
|
||||
def _soft_delete_removed_scoringengines(self):
|
||||
removed_se = [
|
||||
|
||||
Reference in New Issue
Block a user