Merge "Implement watcher datamodel list in watcher-decision-engine"
This commit is contained in:
@@ -38,13 +38,13 @@ See :doc:`../architecture` for more details on this component.
|
||||
"""
|
||||
|
||||
from watcher.common import service_manager
|
||||
from watcher import conf
|
||||
from watcher.decision_engine.messaging import audit_endpoint
|
||||
from watcher.decision_engine.messaging import data_model_endpoint
|
||||
from watcher.decision_engine.model.collector import manager
|
||||
from watcher.decision_engine.strategy.strategies import base \
|
||||
as strategy_endpoint
|
||||
|
||||
from watcher import conf
|
||||
|
||||
CONF = conf.CONF
|
||||
|
||||
|
||||
@@ -73,7 +73,8 @@ class DecisionEngineManager(service_manager.ServiceManager):
|
||||
@property
|
||||
def conductor_endpoints(self):
|
||||
return [audit_endpoint.AuditEndpoint,
|
||||
strategy_endpoint.StrategyEndpoint]
|
||||
strategy_endpoint.StrategyEndpoint,
|
||||
data_model_endpoint.DataModelEndpoint]
|
||||
|
||||
@property
|
||||
def notification_endpoints(self):
|
||||
|
||||
60
watcher/decision_engine/messaging/data_model_endpoint.py
Normal file
60
watcher/decision_engine/messaging/data_model_endpoint.py
Normal file
@@ -0,0 +1,60 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright 2019 ZTE corporation.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
from watcher.common import exception
|
||||
from watcher.common import utils
|
||||
from watcher.decision_engine.model.collector import manager
|
||||
from watcher import objects
|
||||
|
||||
|
||||
class DataModelEndpoint(object):
|
||||
def __init__(self, messaging):
|
||||
self._messaging = messaging
|
||||
|
||||
def get_audit_scope(self, context, audit=None):
|
||||
scope = None
|
||||
try:
|
||||
if utils.is_uuid_like(audit) or utils.is_int_like(audit):
|
||||
audit = objects.Audit.get(
|
||||
context, audit)
|
||||
else:
|
||||
audit = objects.Audit.get_by_name(
|
||||
context, audit)
|
||||
except exception.AuditNotFound:
|
||||
raise exception.InvalidIdentity(identity=audit)
|
||||
if audit:
|
||||
scope = audit.scope
|
||||
else:
|
||||
scope = []
|
||||
return scope
|
||||
|
||||
def get_data_model_info(self, context, data_model_type='compute',
|
||||
audit=None):
|
||||
if audit is not None:
|
||||
scope = self.get_audit_scope(context, audit)
|
||||
else:
|
||||
scope = []
|
||||
collector_manager = manager.CollectorManager()
|
||||
collector = collector_manager.get_cluster_model_collector(
|
||||
data_model_type)
|
||||
audit_scope_handler = collector.get_audit_scope_handler(
|
||||
audit_scope=scope)
|
||||
available_data_model = audit_scope_handler.get_scoped_model(
|
||||
collector.get_latest_cluster_data_model())
|
||||
if not available_data_model:
|
||||
return {"context": []}
|
||||
return {"context": available_data_model.to_list()}
|
||||
@@ -248,6 +248,24 @@ class ModelRoot(nx.DiGraph, base.Model):
|
||||
|
||||
return etree.tostring(root, pretty_print=True).decode('utf-8')
|
||||
|
||||
def to_list(self):
|
||||
ret_list = []
|
||||
for cn in sorted(self.get_all_compute_nodes().values(),
|
||||
key=lambda cn: cn.uuid):
|
||||
in_dict = {}
|
||||
for field in cn.fields:
|
||||
new_name = "node_"+str(field)
|
||||
in_dict[new_name] = cn[field]
|
||||
node_instances = self.get_node_instances(cn)
|
||||
for instance in sorted(node_instances, key=lambda x: x.uuid):
|
||||
for field in instance.fields:
|
||||
new_name = "server_"+str(field)
|
||||
in_dict[new_name] = instance[field]
|
||||
if in_dict != {}:
|
||||
deep_in_dict = in_dict.copy()
|
||||
ret_list.append(deep_in_dict)
|
||||
return ret_list
|
||||
|
||||
@classmethod
|
||||
def from_xml(cls, data):
|
||||
model = cls()
|
||||
|
||||
@@ -44,6 +44,11 @@ class DecisionEngineAPI(service.Service):
|
||||
return self.conductor_client.call(
|
||||
context, 'get_strategy_info', strategy_name=strategy_name)
|
||||
|
||||
def get_data_model_info(self, context, data_model_type, audit):
|
||||
return self.conductor_client.call(
|
||||
context, 'get_data_model_info',
|
||||
data_model_type=data_model_type, audit=audit)
|
||||
|
||||
|
||||
class DecisionEngineAPIManager(service_manager.ServiceManager):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user