Coverage for watcher/decision_engine/model/collector/manager.py: 91%
26 statements
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-17 12:22 +0000
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-17 12:22 +0000
1# -*- encoding: utf-8 -*-
2# Copyright (c) 2015 b<>com
3#
4# Authors: Jean-Emile DARTOIS <jean-emile.dartois@b-com.com>
5# Vincent FRANCOISE <vincent.francoise@b-com.com>
6#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
16# implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
20from oslo_config import cfg
22from watcher.common import utils
23from watcher.decision_engine.loading import default
26class CollectorManager(object):
28 def __init__(self):
29 self.collector_loader = default.ClusterDataModelCollectorLoader()
30 self._collectors = None
31 self._notification_endpoints = None
33 def get_collectors(self):
34 if self._collectors is None: 34 ↛ 42line 34 didn't jump to line 42 because the condition on line 34 was always true
35 collectors = utils.Struct()
36 collector_plugins = cfg.CONF.collector.collector_plugins
37 for collector_name in collector_plugins:
38 collector = self.collector_loader.load(collector_name)
39 collectors[collector_name] = collector
40 self._collectors = collectors
42 return self._collectors
44 def get_notification_endpoints(self):
45 if self._notification_endpoints is None: 45 ↛ 51line 45 didn't jump to line 51 because the condition on line 45 was always true
46 endpoints = []
47 for collector in self.get_collectors().values():
48 endpoints.extend(collector.notification_endpoints)
49 self._notification_endpoints = endpoints
51 return self._notification_endpoints
53 def get_cluster_model_collector(self, name, osc=None):
54 """Retrieve cluster data model collector
56 :param name: name of the cluster data model collector plugin
57 :type name: str
58 :param osc: an OpenStackClients instance
59 :type osc: :py:class:`~.OpenStackClients` instance
60 :returns: cluster data model collector plugin
61 :rtype: :py:class:`~.BaseClusterDataModelCollector`
62 """
63 return self.collector_loader.load(
64 name, osc=osc)