Refactor vitrage to use global CONF instead of local one
Remove usage of local config object in Vitrage services and tests. Instead, it's been replaced with the global CONF object. The structure of the code becomes more like in other OpenStack projects. Also, this change provides an opportunity to introduce migrations and tests for them. Story: 2004059 Task: 27065 Change-Id: I37544a350adf8ca38a6fc4ff5d0fd96e38a3f922
This commit is contained in:
parent
7c76bc764b
commit
66c608cb56
@ -22,9 +22,8 @@ LOG = log.getLogger(__name__)
|
|||||||
|
|
||||||
class SampleDriver(DriverBase):
|
class SampleDriver(DriverBase):
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(SampleDriver, self).__init__()
|
super(SampleDriver, self).__init__()
|
||||||
self.cfg = conf
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_event_types():
|
def get_event_types():
|
||||||
|
@ -28,8 +28,8 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class SampleTransformer(ResourceTransformerBase):
|
class SampleTransformer(ResourceTransformerBase):
|
||||||
|
|
||||||
def __init__(self, transformers, conf):
|
def __init__(self, transformers):
|
||||||
super(SampleTransformer, self).__init__(transformers, conf)
|
super(SampleTransformer, self).__init__(transformers)
|
||||||
|
|
||||||
def _create_snapshot_entity_vertex(self, entity_event):
|
def _create_snapshot_entity_vertex(self, entity_event):
|
||||||
return self._create_vertex(entity_event)
|
return self._create_vertex(entity_event)
|
||||||
|
@ -22,9 +22,8 @@ LOG = log.getLogger(__name__)
|
|||||||
|
|
||||||
class {{cookiecutter.name|capitalize}}Driver(DriverBase):
|
class {{cookiecutter.name|capitalize}}Driver(DriverBase):
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super({{cookiecutter.name|capitalize}}Driver, self).__init__()
|
super({{cookiecutter.name|capitalize}}Driver, self).__init__()
|
||||||
self.cfg = conf
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_event_types():
|
def get_event_types():
|
||||||
|
@ -28,8 +28,8 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class {{cookiecutter.name|capitalize}}Transformer(ResourceTransformerBase):
|
class {{cookiecutter.name|capitalize}}Transformer(ResourceTransformerBase):
|
||||||
|
|
||||||
def __init__(self, transformers, conf):
|
def __init__(self, transformers:
|
||||||
super({{cookiecutter.name|capitalize}}Transformer, self).__init__(transformers, conf)
|
super({{cookiecutter.name|capitalize}}Transformer, self).__init__(transformers)
|
||||||
|
|
||||||
def _create_snapshot_entity_vertex(self, entity_event):
|
def _create_snapshot_entity_vertex(self, entity_event):
|
||||||
return self._create_vertex(entity_event)
|
return self._create_vertex(entity_event)
|
||||||
|
@ -17,14 +17,17 @@ import sys
|
|||||||
import cotyledon
|
import cotyledon
|
||||||
from futurist import periodics
|
from futurist import periodics
|
||||||
from futurist import ThreadPoolExecutor
|
from futurist import ThreadPoolExecutor
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
import oslo_messaging
|
import oslo_messaging
|
||||||
from tools.load_generator.notification_info import * # noqa
|
from tools.load_generator.notification_info import * # noqa
|
||||||
|
|
||||||
|
from vitrage.common import config
|
||||||
from vitrage.messaging import get_transport
|
from vitrage.messaging import get_transport
|
||||||
from vitrage import service
|
|
||||||
|
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
EXISTING_COMPUTES_NUM = 64
|
EXISTING_COMPUTES_NUM = 64
|
||||||
@ -62,12 +65,12 @@ to avoid Vitrage consistency deleting the created resources.
|
|||||||
|
|
||||||
|
|
||||||
class StressNotificationsService(cotyledon.Service):
|
class StressNotificationsService(cotyledon.Service):
|
||||||
def __init__(self, worker_id, conf):
|
def __init__(self, worker_id):
|
||||||
super(StressNotificationsService, self).__init__(worker_id)
|
super(StressNotificationsService, self).__init__(worker_id)
|
||||||
self.oslo_notifier = None
|
self.oslo_notifier = None
|
||||||
topics = conf.datasources.notification_topics
|
topics = CONF.datasources.notification_topics
|
||||||
self.oslo_notifier = oslo_messaging.Notifier(
|
self.oslo_notifier = oslo_messaging.Notifier(
|
||||||
get_transport(conf),
|
get_transport(),
|
||||||
driver='messagingv2',
|
driver='messagingv2',
|
||||||
publisher_id='vitrage.stress',
|
publisher_id='vitrage.stress',
|
||||||
topics=topics)
|
topics=topics)
|
||||||
@ -141,9 +144,9 @@ def create_vm(instance_num, compute_num):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
conf = service.prepare_service()
|
config.parse_config(sys.argv)
|
||||||
sm = cotyledon.ServiceManager()
|
sm = cotyledon.ServiceManager()
|
||||||
sm.add(StressNotificationsService, args=(conf,))
|
sm.add(StressNotificationsService)
|
||||||
sm.run()
|
sm.run()
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,6 +27,8 @@ from werkzeug import serving
|
|||||||
|
|
||||||
from vitrage.api import hooks
|
from vitrage.api import hooks
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
|
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
# NOTE(sileht): pastedeploy uses ConfigParser to handle
|
# NOTE(sileht): pastedeploy uses ConfigParser to handle
|
||||||
@ -40,13 +42,13 @@ APPCONFIGS = {}
|
|||||||
|
|
||||||
|
|
||||||
def setup_app(root, conf=None):
|
def setup_app(root, conf=None):
|
||||||
app_hooks = [hooks.ConfigHook(conf),
|
app_hooks = [hooks.ConfigHook(),
|
||||||
hooks.TranslationHook(),
|
hooks.TranslationHook(),
|
||||||
hooks.GCHook(),
|
hooks.GCHook(),
|
||||||
hooks.RPCHook(conf),
|
hooks.RPCHook(),
|
||||||
hooks.ContextHook(),
|
hooks.ContextHook(),
|
||||||
hooks.DBHook(conf),
|
hooks.DBHook(),
|
||||||
hooks.CoordinatorHook(conf)]
|
hooks.CoordinatorHook()]
|
||||||
|
|
||||||
app = pecan.make_app(
|
app = pecan.make_app(
|
||||||
root,
|
root,
|
||||||
@ -57,53 +59,52 @@ def setup_app(root, conf=None):
|
|||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
def load_app(conf):
|
def load_app():
|
||||||
global APPCONFIGS
|
global APPCONFIGS
|
||||||
|
|
||||||
# Build the WSGI app
|
# Build the WSGI app
|
||||||
cfg_path = conf.api.paste_config
|
cfg_path = CONF.api.paste_config
|
||||||
if not os.path.isabs(cfg_path):
|
if not os.path.isabs(cfg_path):
|
||||||
cfg_path = conf.find_file(cfg_path)
|
cfg_path = CONF.find_file(cfg_path)
|
||||||
|
|
||||||
if cfg_path is None or not os.path.exists(cfg_path):
|
if cfg_path is None or not os.path.exists(cfg_path):
|
||||||
raise cfg.ConfigFilesNotFoundError([conf.api.paste_config])
|
raise cfg.ConfigFilesNotFoundError([CONF.api.paste_config])
|
||||||
|
|
||||||
config = dict(conf=conf)
|
config = dict(conf=CONF)
|
||||||
configkey = uuidutils.generate_uuid()
|
configkey = uuidutils.generate_uuid()
|
||||||
APPCONFIGS[configkey] = config
|
APPCONFIGS[configkey] = config
|
||||||
|
|
||||||
LOG.info('Full WSGI config used: %s', cfg_path)
|
LOG.info('Full WSGI config used: %s', cfg_path)
|
||||||
|
|
||||||
appname = "vitrage+" + conf.api.auth_mode
|
appname = "vitrage+" + CONF.api.auth_mode
|
||||||
return deploy.loadapp("config:" + cfg_path, name=appname,
|
return deploy.loadapp("config:" + cfg_path, name=appname,
|
||||||
global_conf={'configkey': configkey})
|
global_conf={'configkey': configkey})
|
||||||
|
|
||||||
|
|
||||||
def build_server(conf):
|
def build_server():
|
||||||
uwsgi = spawn.find_executable("uwsgi")
|
uwsgi = spawn.find_executable("uwsgi")
|
||||||
if not uwsgi:
|
if not uwsgi:
|
||||||
LOG.warning('uwsgi not installed, starting a TEST server')
|
LOG.warning('uwsgi not installed, starting a TEST server')
|
||||||
build_simple_server(conf)
|
build_simple_server()
|
||||||
else:
|
else:
|
||||||
build_uwsgi_server(conf, uwsgi)
|
build_uwsgi_server(uwsgi)
|
||||||
|
|
||||||
|
|
||||||
def wsgi_file():
|
def wsgi_file():
|
||||||
return path.join(path.dirname(__file__), 'app.wsgi')
|
return path.join(path.dirname(__file__), 'app.wsgi')
|
||||||
|
|
||||||
|
|
||||||
def build_uwsgi_server(conf, uwsgi):
|
def build_uwsgi_server(uwsgi):
|
||||||
|
|
||||||
args = [
|
args = [
|
||||||
"--if-not-plugin", "python", "--plugin", "python", "--endif",
|
"--if-not-plugin", "python", "--plugin", "python", "--endif",
|
||||||
"--http-socket", "%s:%d" % (conf.api.host, conf.api.port),
|
"--http-socket", "%s:%d" % (CONF.api.host, CONF.api.port),
|
||||||
"--master",
|
"--master",
|
||||||
"--enable-threads",
|
"--enable-threads",
|
||||||
"--thunder-lock",
|
"--thunder-lock",
|
||||||
"--hook-master-start", "unix_signal:15 gracefully_kill_them_all",
|
"--hook-master-start", "unix_signal:15 gracefully_kill_them_all",
|
||||||
"--die-on-term",
|
"--die-on-term",
|
||||||
"--processes", str(math.floor(conf.api.workers * 1.5)),
|
"--processes", str(math.floor(CONF.api.workers * 1.5)),
|
||||||
"--threads", str(conf.api.workers),
|
"--threads", str(CONF.api.workers),
|
||||||
"--lazy-apps",
|
"--lazy-apps",
|
||||||
"--chdir", "/",
|
"--chdir", "/",
|
||||||
"--buffer-size", "65535",
|
"--buffer-size", "65535",
|
||||||
@ -119,14 +120,14 @@ def build_uwsgi_server(conf, uwsgi):
|
|||||||
return os.execl(uwsgi, uwsgi, *args)
|
return os.execl(uwsgi, uwsgi, *args)
|
||||||
|
|
||||||
|
|
||||||
def build_simple_server(conf):
|
def build_simple_server():
|
||||||
app = load_app(conf)
|
app = load_app()
|
||||||
# Create the WSGI server and start it
|
# Create the WSGI server and start it
|
||||||
host, port = conf.api.host, conf.api.port
|
host, port = CONF.api.host, CONF.api.port
|
||||||
|
|
||||||
LOG.info('Starting server in PID %s', os.getpid())
|
LOG.info('Starting server in PID %s', os.getpid())
|
||||||
LOG.info('Configuration:')
|
LOG.info('Configuration:')
|
||||||
conf.log_opt_values(LOG, log.INFO)
|
CONF.log_opt_values(LOG, log.INFO)
|
||||||
|
|
||||||
if host == '0.0.0.0':
|
if host == '0.0.0.0':
|
||||||
LOG.info(
|
LOG.info(
|
||||||
@ -139,7 +140,7 @@ def build_simple_server(conf):
|
|||||||
LOG.info('"DANGER! For testing only, do not use in production"')
|
LOG.info('"DANGER! For testing only, do not use in production"')
|
||||||
|
|
||||||
serving.run_simple(host, port,
|
serving.run_simple(host, port,
|
||||||
app, processes=conf.api.workers)
|
app, processes=CONF.api.workers)
|
||||||
|
|
||||||
|
|
||||||
def app_factory(global_config, **local_conf):
|
def app_factory(global_config, **local_conf):
|
||||||
|
@ -14,8 +14,8 @@
|
|||||||
See http://pecan.readthedocs.org/en/latest/deployment.html for details.
|
See http://pecan.readthedocs.org/en/latest/deployment.html for details.
|
||||||
"""
|
"""
|
||||||
from vitrage.api import app
|
from vitrage.api import app
|
||||||
from vitrage import service
|
from vitrage.common import config
|
||||||
|
|
||||||
# Initialize the oslo configuration library and logging
|
# Initialize the oslo configuration library and logging
|
||||||
conf = service.prepare_service()
|
config.parse_config([])
|
||||||
application = app.load_app(conf)
|
application = app.load_app()
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
import gc
|
import gc
|
||||||
import oslo_messaging
|
import oslo_messaging
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_context import context
|
from oslo_context import context
|
||||||
from oslo_policy import policy
|
from oslo_policy import policy
|
||||||
from pecan import hooks
|
from pecan import hooks
|
||||||
@ -22,31 +23,32 @@ from vitrage import messaging
|
|||||||
from vitrage import rpc as vitrage_rpc
|
from vitrage import rpc as vitrage_rpc
|
||||||
from vitrage import storage
|
from vitrage import storage
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
|
|
||||||
|
|
||||||
class ConfigHook(hooks.PecanHook):
|
class ConfigHook(hooks.PecanHook):
|
||||||
"""Attach the configuration and policy enforcer object to the request. """
|
"""Attach the configuration and policy enforcer object to the request. """
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
self.conf = conf
|
self.enforcer = policy.Enforcer(CONF)
|
||||||
self.enforcer = policy.Enforcer(conf)
|
|
||||||
self._register_rules()
|
self._register_rules()
|
||||||
|
|
||||||
def _register_rules(self):
|
def _register_rules(self):
|
||||||
self.enforcer.register_defaults(policies.list_rules())
|
self.enforcer.register_defaults(policies.list_rules())
|
||||||
|
|
||||||
def before(self, state):
|
def before(self, state):
|
||||||
state.request.cfg = self.conf
|
state.request.cfg = CONF
|
||||||
state.request.enforcer = self.enforcer
|
state.request.enforcer = self.enforcer
|
||||||
|
|
||||||
|
|
||||||
class RPCHook(hooks.PecanHook):
|
class RPCHook(hooks.PecanHook):
|
||||||
"""Create and attach an rpc to the request. """
|
"""Create and attach an rpc to the request. """
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
transport = messaging.get_rpc_transport(conf)
|
transport = messaging.get_rpc_transport()
|
||||||
target = oslo_messaging.Target(topic=conf.rpc_topic)
|
target = oslo_messaging.Target(topic=CONF.rpc_topic)
|
||||||
self.client = vitrage_rpc.get_client(transport, target)
|
self.client = vitrage_rpc.get_client(transport, target)
|
||||||
self.check_backend = conf.api.check_backend
|
self.check_backend = CONF.api.check_backend
|
||||||
|
|
||||||
def on_route(self, state):
|
def on_route(self, state):
|
||||||
state.request.client = self.client
|
state.request.client = self.client
|
||||||
@ -87,8 +89,8 @@ class ContextHook(hooks.PecanHook):
|
|||||||
|
|
||||||
class DBHook(hooks.PecanHook):
|
class DBHook(hooks.PecanHook):
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
self.storage = storage.get_connection_from_config(conf)
|
self.storage = storage.get_connection_from_config()
|
||||||
|
|
||||||
def before(self, state):
|
def before(self, state):
|
||||||
state.request.storage = self.storage
|
state.request.storage = self.storage
|
||||||
@ -102,8 +104,8 @@ class GCHook(hooks.PecanHook):
|
|||||||
|
|
||||||
class CoordinatorHook(hooks.PecanHook):
|
class CoordinatorHook(hooks.PecanHook):
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
self.coordinator = coordination.Coordinator(conf)
|
self.coordinator = coordination.Coordinator()
|
||||||
self.coordinator.start()
|
self.coordinator.start()
|
||||||
self.coordinator.join_group()
|
self.coordinator.join_group()
|
||||||
|
|
||||||
|
@ -76,9 +76,8 @@ RESOURCES_ALL_QUERY = {
|
|||||||
|
|
||||||
class EntityGraphApisBase(object):
|
class EntityGraphApisBase(object):
|
||||||
|
|
||||||
def __init__(self, entity_graph, conf, api_lock, db=None):
|
def __init__(self, entity_graph, api_lock, db=None):
|
||||||
self.entity_graph = entity_graph
|
self.entity_graph = entity_graph
|
||||||
self.conf = conf
|
|
||||||
self.db = db
|
self.db = db
|
||||||
self.api_lock = api_lock
|
self.api_lock = api_lock
|
||||||
|
|
||||||
|
@ -32,8 +32,7 @@ LOG = log.getLogger(__name__)
|
|||||||
info={}, hide_args=False, trace_private=False)
|
info={}, hide_args=False, trace_private=False)
|
||||||
class EventApis(object):
|
class EventApis(object):
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
self.conf = conf
|
|
||||||
self._init_oslo_notifier()
|
self._init_oslo_notifier()
|
||||||
|
|
||||||
def post(self, ctx, event_time, event_type, details):
|
def post(self, ctx, event_time, event_type, details):
|
||||||
@ -65,7 +64,7 @@ class EventApis(object):
|
|||||||
self.publisher = 'api_%s' % socket.gethostname()
|
self.publisher = 'api_%s' % socket.gethostname()
|
||||||
|
|
||||||
self.oslo_notifier = oslo_messaging.Notifier(
|
self.oslo_notifier = oslo_messaging.Notifier(
|
||||||
get_transport(self.conf),
|
get_transport(),
|
||||||
driver='messagingv2',
|
driver='messagingv2',
|
||||||
publisher_id=self.publisher,
|
publisher_id=self.publisher,
|
||||||
topics=['vitrage_notifications'])
|
topics=['vitrage_notifications'])
|
||||||
|
@ -19,8 +19,7 @@ LOG = log.getLogger(__name__)
|
|||||||
|
|
||||||
class OperationalApis(object):
|
class OperationalApis(object):
|
||||||
|
|
||||||
def __init__(self, conf, graph):
|
def __init__(self, graph):
|
||||||
self.conf = conf
|
|
||||||
self.graph = graph
|
self.graph = graph
|
||||||
|
|
||||||
def is_alive(self, ctx):
|
def is_alive(self, ctx):
|
||||||
|
@ -31,9 +31,6 @@ LOG = log.getLogger(__name__)
|
|||||||
info={}, hide_args=False, trace_private=False)
|
info={}, hide_args=False, trace_private=False)
|
||||||
class ResourceApis(base.EntityGraphApisBase):
|
class ResourceApis(base.EntityGraphApisBase):
|
||||||
|
|
||||||
def __init__(self, entity_graph, conf, api_lock):
|
|
||||||
super(ResourceApis, self).__init__(entity_graph, conf, api_lock)
|
|
||||||
|
|
||||||
@timed_method(log_results=True)
|
@timed_method(log_results=True)
|
||||||
@base.lock_graph
|
@base.lock_graph
|
||||||
def get_resources(self, ctx, resource_type=None, all_tenants=False,
|
def get_resources(self, ctx, resource_type=None, all_tenants=False,
|
||||||
|
@ -34,9 +34,6 @@ LOG = log.getLogger(__name__)
|
|||||||
info={}, hide_args=False, trace_private=False)
|
info={}, hide_args=False, trace_private=False)
|
||||||
class TopologyApis(base.EntityGraphApisBase):
|
class TopologyApis(base.EntityGraphApisBase):
|
||||||
|
|
||||||
def __init__(self, entity_graph, conf, api_lock):
|
|
||||||
super(TopologyApis, self).__init__(entity_graph, conf, api_lock)
|
|
||||||
|
|
||||||
@timed_method(log_results=True)
|
@timed_method(log_results=True)
|
||||||
@base.lock_graph
|
@base.lock_graph
|
||||||
def get_topology(self, ctx, graph_type, depth, query, root, all_tenants):
|
def get_topology(self, ctx, graph_type, depth, query, root, all_tenants):
|
||||||
|
@ -34,8 +34,7 @@ Result = namedtuple("Result", ["is_valid", "message"])
|
|||||||
class WebhookApis(object):
|
class WebhookApis(object):
|
||||||
DELETED_ROWS_SUCCESS = 1
|
DELETED_ROWS_SUCCESS = 1
|
||||||
|
|
||||||
def __init__(self, conf, db):
|
def __init__(self, db):
|
||||||
self.conf = conf
|
|
||||||
self.db_conn = db
|
self.db_conn = db
|
||||||
|
|
||||||
def delete_webhook(self, ctx, id):
|
def delete_webhook(self, ctx, id):
|
||||||
|
@ -16,13 +16,13 @@ import sys
|
|||||||
|
|
||||||
from vitrage.api import app
|
from vitrage.api import app
|
||||||
from vitrage.cli import VITRAGE_TITLE
|
from vitrage.cli import VITRAGE_TITLE
|
||||||
from vitrage import service
|
from vitrage.common import config
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print(VITRAGE_TITLE)
|
print(VITRAGE_TITLE)
|
||||||
conf = service.prepare_service()
|
config.parse_config(sys.argv)
|
||||||
app.build_server(conf)
|
app.build_server()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -16,10 +16,10 @@ from oslo_log import log
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from vitrage.cli import VITRAGE_TITLE
|
from vitrage.cli import VITRAGE_TITLE
|
||||||
|
from vitrage.common import config
|
||||||
from vitrage.common.utils import spawn
|
from vitrage.common.utils import spawn
|
||||||
from vitrage.entity_graph.graph_init import VitrageGraphInit
|
from vitrage.entity_graph.graph_init import VitrageGraphInit
|
||||||
from vitrage.entity_graph.workers import GraphWorkersManager
|
from vitrage.entity_graph.workers import GraphWorkersManager
|
||||||
from vitrage import service
|
|
||||||
|
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
@ -27,19 +27,19 @@ LOG = log.getLogger(__name__)
|
|||||||
def main():
|
def main():
|
||||||
"""Main method of vitrage-graph"""
|
"""Main method of vitrage-graph"""
|
||||||
|
|
||||||
conf = service.prepare_service()
|
|
||||||
LOG.info(VITRAGE_TITLE)
|
LOG.info(VITRAGE_TITLE)
|
||||||
|
config.parse_config(sys.argv)
|
||||||
workers = GraphWorkersManager(conf)
|
workers = GraphWorkersManager()
|
||||||
spawn(init, conf, workers)
|
spawn(init, workers)
|
||||||
workers.run()
|
workers.run()
|
||||||
|
|
||||||
|
|
||||||
def init(conf, workers):
|
def init(workers):
|
||||||
# Because fork duplicates the process memory.
|
# Because fork duplicates the process memory.
|
||||||
# We should only create master process resources after workers are forked.
|
# We should only create master process resources after workers are forked.
|
||||||
workers.wait_for_worker_start()
|
workers.wait_for_worker_start()
|
||||||
VitrageGraphInit(conf, workers).run()
|
VitrageGraphInit(workers).run()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
@ -16,15 +16,15 @@ import cotyledon
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from vitrage.cli import VITRAGE_TITLE
|
from vitrage.cli import VITRAGE_TITLE
|
||||||
|
from vitrage.common import config
|
||||||
from vitrage.machine_learning.service import MachineLearningService
|
from vitrage.machine_learning.service import MachineLearningService
|
||||||
from vitrage import service
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print(VITRAGE_TITLE)
|
print(VITRAGE_TITLE)
|
||||||
conf = service.prepare_service()
|
config.parse_config(sys.argv)
|
||||||
sm = cotyledon.ServiceManager()
|
sm = cotyledon.ServiceManager()
|
||||||
sm.add(MachineLearningService, args=(conf,))
|
sm.add(MachineLearningService)
|
||||||
sm.run()
|
sm.run()
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,15 +15,15 @@ import cotyledon
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from vitrage.cli import VITRAGE_TITLE
|
from vitrage.cli import VITRAGE_TITLE
|
||||||
|
from vitrage.common import config
|
||||||
from vitrage.notifier.service import VitrageNotifierService
|
from vitrage.notifier.service import VitrageNotifierService
|
||||||
from vitrage import service
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print(VITRAGE_TITLE)
|
print(VITRAGE_TITLE)
|
||||||
conf = service.prepare_service()
|
config.parse_config(sys.argv)
|
||||||
sm = cotyledon.ServiceManager()
|
sm = cotyledon.ServiceManager()
|
||||||
sm.add(VitrageNotifierService, args=(conf,))
|
sm.add(VitrageNotifierService)
|
||||||
sm.run()
|
sm.run()
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,9 +16,10 @@ import sys
|
|||||||
|
|
||||||
import cotyledon
|
import cotyledon
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
|
||||||
from vitrage.cli import VITRAGE_TITLE
|
from vitrage.cli import VITRAGE_TITLE
|
||||||
|
from vitrage.common import config
|
||||||
from vitrage.persistency.service import PersistorService
|
from vitrage.persistency.service import PersistorService
|
||||||
from vitrage import service
|
|
||||||
from vitrage import storage
|
from vitrage import storage
|
||||||
|
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
@ -26,10 +27,10 @@ LOG = log.getLogger(__name__)
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
print(VITRAGE_TITLE)
|
print(VITRAGE_TITLE)
|
||||||
conf = service.prepare_service()
|
config.parse_config(sys.argv)
|
||||||
db_connection = storage.get_connection_from_config(conf)
|
db_connection = storage.get_connection_from_config()
|
||||||
sm = cotyledon.ServiceManager()
|
sm = cotyledon.ServiceManager()
|
||||||
sm.add(PersistorService, args=(conf, db_connection))
|
sm.add(PersistorService, args=(db_connection,))
|
||||||
sm.run()
|
sm.run()
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,16 +15,17 @@
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
import cotyledon
|
import cotyledon
|
||||||
|
|
||||||
from vitrage.cli import VITRAGE_TITLE
|
from vitrage.cli import VITRAGE_TITLE
|
||||||
from vitrage import service
|
from vitrage.common import config
|
||||||
from vitrage.snmp_parsing.service import SnmpParsingService
|
from vitrage.snmp_parsing.service import SnmpParsingService
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print(VITRAGE_TITLE)
|
print(VITRAGE_TITLE)
|
||||||
conf = service.prepare_service()
|
config.parse_config(sys.argv)
|
||||||
sm = cotyledon.ServiceManager()
|
sm = cotyledon.ServiceManager()
|
||||||
sm.add(SnmpParsingService, args=(conf,))
|
sm.add(SnmpParsingService)
|
||||||
sm.run()
|
sm.run()
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,21 +12,23 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
from vitrage.cli import VITRAGE_TITLE
|
from vitrage.cli import VITRAGE_TITLE
|
||||||
from vitrage import service
|
from vitrage.common import config
|
||||||
from vitrage import storage
|
from vitrage import storage
|
||||||
|
|
||||||
|
|
||||||
def dbsync():
|
def dbsync():
|
||||||
print(VITRAGE_TITLE)
|
print(VITRAGE_TITLE)
|
||||||
conf = service.prepare_service()
|
config.parse_config(sys.argv)
|
||||||
storage.get_connection_from_config(conf).upgrade()
|
storage.get_connection_from_config().upgrade()
|
||||||
|
|
||||||
|
|
||||||
def purge_data():
|
def purge_data():
|
||||||
print(VITRAGE_TITLE)
|
print(VITRAGE_TITLE)
|
||||||
conf = service.prepare_service()
|
config.parse_config(sys.argv)
|
||||||
db = storage.get_connection_from_config(conf)
|
db = storage.get_connection_from_config()
|
||||||
db.active_actions.delete()
|
db.active_actions.delete()
|
||||||
db.events.delete()
|
db.events.delete()
|
||||||
db.graph_snapshots.delete()
|
db.graph_snapshots.delete()
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Copyright 2015 - Alcatel-Lucent
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# 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
|
# not use this file except in compliance with the License. You may obtain
|
||||||
# a copy of the License at
|
# a copy of the License at
|
||||||
@ -10,7 +10,6 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_db import options as db_options
|
from oslo_db import options as db_options
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
@ -20,47 +19,43 @@ from osprofiler import opts as osprofiler_opts
|
|||||||
from vitrage import keystone_client
|
from vitrage import keystone_client
|
||||||
from vitrage import messaging
|
from vitrage import messaging
|
||||||
from vitrage import opts
|
from vitrage import opts
|
||||||
from vitrage.opts import register_opts
|
|
||||||
|
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def prepare_service(args=None, conf=None, config_files=None):
|
def parse_config(args, default_config_files=None):
|
||||||
set_defaults()
|
set_defaults()
|
||||||
if conf is None:
|
log.register_options(CONF)
|
||||||
conf = cfg.ConfigOpts()
|
policy_opts.set_defaults(CONF)
|
||||||
log.register_options(conf)
|
osprofiler_opts.set_defaults(CONF)
|
||||||
policy_opts.set_defaults(conf)
|
db_options.set_defaults(CONF)
|
||||||
osprofiler_opts.set_defaults(conf)
|
|
||||||
db_options.set_defaults(conf)
|
|
||||||
|
|
||||||
for group, options in opts.list_opts():
|
for group, options in opts.list_opts():
|
||||||
conf.register_opts(list(options),
|
CONF.register_opts(list(options),
|
||||||
group=None if group == 'DEFAULT' else group)
|
group=None if group == 'DEFAULT' else group)
|
||||||
|
|
||||||
conf(args, project='vitrage', validate_default_values=True,
|
CONF(args[1:], project='vitrage', validate_default_values=True,
|
||||||
default_config_files=config_files)
|
default_config_files=default_config_files)
|
||||||
|
|
||||||
if conf.profiler.enabled:
|
if CONF.profiler.enabled:
|
||||||
osprofiler_initializer.init_from_conf(
|
osprofiler_initializer.init_from_conf(
|
||||||
conf=conf,
|
conf=CONF,
|
||||||
context=None,
|
context=None,
|
||||||
project="vitrage",
|
project='vitrage',
|
||||||
service="api",
|
service='api',
|
||||||
host=conf.api.host)
|
host=CONF.api.host
|
||||||
|
)
|
||||||
|
|
||||||
for datasource in conf.datasources.types:
|
for datasource in CONF.datasources.types:
|
||||||
register_opts(conf, datasource, conf.datasources.path)
|
opts.register_opts(datasource, CONF.datasources.path)
|
||||||
|
|
||||||
keystone_client.register_keystoneauth_opts(conf)
|
keystone_client.register_keystoneauth_opts()
|
||||||
|
log.setup(CONF, 'vitrage')
|
||||||
log.setup(conf, 'vitrage')
|
CONF.log_opt_values(LOG, log.DEBUG)
|
||||||
conf.log_opt_values(LOG, log.DEBUG)
|
|
||||||
messaging.setup()
|
messaging.setup()
|
||||||
|
|
||||||
return conf
|
|
||||||
|
|
||||||
|
|
||||||
def set_defaults():
|
def set_defaults():
|
||||||
from oslo_middleware import cors
|
from oslo_middleware import cors
|
@ -20,16 +20,17 @@ import six
|
|||||||
import tenacity
|
import tenacity
|
||||||
import tooz.coordination
|
import tooz.coordination
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Coordinator(object):
|
class Coordinator(object):
|
||||||
def __init__(self, conf, my_id=None):
|
def __init__(self, my_id=None):
|
||||||
self.conf = conf
|
self.backend_url = CONF.coordination.backend_url
|
||||||
self.backend_url = self.conf.coordination.backend_url
|
|
||||||
self.my_id = my_id or ' '.join(psutil.Process(os.getpid()).cmdline())
|
self.my_id = my_id or ' '.join(psutil.Process(os.getpid()).cmdline())
|
||||||
self.coordinator = None
|
self.coordinator = None
|
||||||
if self.backend_url:
|
if self.backend_url:
|
||||||
|
@ -19,10 +19,10 @@ from vitrage.coordination.coordination import Coordinator
|
|||||||
|
|
||||||
class Service(cotyledon.Service):
|
class Service(cotyledon.Service):
|
||||||
|
|
||||||
def __init__(self, worker_id, conf):
|
def __init__(self, worker_id):
|
||||||
super(Service, self).__init__(worker_id)
|
super(Service, self).__init__(worker_id)
|
||||||
self.coordinator = Coordinator(conf, '%s worker(%s)' % (self.name,
|
self.coordinator = Coordinator('%s worker(%s)' % (self.name,
|
||||||
worker_id))
|
worker_id))
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.coordinator.start()
|
self.coordinator.start()
|
||||||
|
@ -22,9 +22,6 @@ from vitrage.datasources import transformer_base as tbase
|
|||||||
|
|
||||||
class AlarmTransformerBase(tbase.TransformerBase):
|
class AlarmTransformerBase(tbase.TransformerBase):
|
||||||
|
|
||||||
def __init__(self, transformers, conf):
|
|
||||||
super(AlarmTransformerBase, self).__init__(transformers, conf)
|
|
||||||
|
|
||||||
def _ok_status(self, entity_event):
|
def _ok_status(self, entity_event):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -32,10 +32,9 @@ LOG = log.getLogger(__name__)
|
|||||||
|
|
||||||
class AodhDriver(AlarmDriverBase):
|
class AodhDriver(AlarmDriverBase):
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(AodhDriver, self).__init__()
|
super(AodhDriver, self).__init__()
|
||||||
self._client = None
|
self._client = None
|
||||||
self.conf = conf
|
|
||||||
self._init_aodh_event_actions()
|
self._init_aodh_event_actions()
|
||||||
self._init_convert_aodh_alarm_rule_actions()
|
self._init_convert_aodh_alarm_rule_actions()
|
||||||
self._init_alarm_type_to_rule()
|
self._init_alarm_type_to_rule()
|
||||||
@ -86,7 +85,7 @@ class AodhDriver(AlarmDriverBase):
|
|||||||
@property
|
@property
|
||||||
def client(self):
|
def client(self):
|
||||||
if not self._client:
|
if not self._client:
|
||||||
self._client = os_clients.aodh_client(self.conf)
|
self._client = os_clients.aodh_client()
|
||||||
return self._client
|
return self._client
|
||||||
|
|
||||||
def _vitrage_type(self):
|
def _vitrage_type(self):
|
||||||
|
@ -38,9 +38,6 @@ class AodhTransformer(AlarmTransformerBase):
|
|||||||
AodhEventType.DELETION: GraphAction.DELETE_ENTITY,
|
AodhEventType.DELETION: GraphAction.DELETE_ENTITY,
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, transformers, conf):
|
|
||||||
super(AodhTransformer, self).__init__(transformers, conf)
|
|
||||||
|
|
||||||
def _create_snapshot_entity_vertex(self, entity_event):
|
def _create_snapshot_entity_vertex(self, entity_event):
|
||||||
if _is_vitrage_alarm(entity_event):
|
if _is_vitrage_alarm(entity_event):
|
||||||
return self._create_merge_alarm_vertex(entity_event)
|
return self._create_merge_alarm_vertex(entity_event)
|
||||||
|
@ -32,17 +32,16 @@ LOG = log.getLogger(__name__)
|
|||||||
|
|
||||||
class CeilometerDriver(AlarmDriverBase):
|
class CeilometerDriver(AlarmDriverBase):
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(CeilometerDriver, self).__init__()
|
super(CeilometerDriver, self).__init__()
|
||||||
self._client = None
|
self._client = None
|
||||||
self.conf = conf
|
|
||||||
self._init_aodh_event_actions()
|
self._init_aodh_event_actions()
|
||||||
self._cache_all_alarms()
|
self._cache_all_alarms()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def client(self):
|
def client(self):
|
||||||
if not self._client:
|
if not self._client:
|
||||||
self._client = os_clients.ceilometer_client(self.conf)
|
self._client = os_clients.ceilometer_client()
|
||||||
return self._client
|
return self._client
|
||||||
|
|
||||||
def _vitrage_type(self):
|
def _vitrage_type(self):
|
||||||
|
@ -41,9 +41,6 @@ class CeilometerTransformer(AlarmTransformerBase):
|
|||||||
CeilEventType.DELETION: GraphAction.DELETE_ENTITY,
|
CeilEventType.DELETION: GraphAction.DELETE_ENTITY,
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, transformers, conf):
|
|
||||||
super(CeilometerTransformer, self).__init__(transformers, conf)
|
|
||||||
|
|
||||||
def _create_snapshot_entity_vertex(self, entity_event):
|
def _create_snapshot_entity_vertex(self, entity_event):
|
||||||
if _is_vitrage_alarm(entity_event):
|
if _is_vitrage_alarm(entity_event):
|
||||||
return self._create_merge_alarm_vertex(entity_event)
|
return self._create_merge_alarm_vertex(entity_event)
|
||||||
|
@ -21,15 +21,14 @@ from vitrage import os_clients
|
|||||||
|
|
||||||
class CinderVolumeDriver(DriverBase):
|
class CinderVolumeDriver(DriverBase):
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(CinderVolumeDriver, self).__init__()
|
super(CinderVolumeDriver, self).__init__()
|
||||||
self._client = None
|
self._client = None
|
||||||
self.conf = conf
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def client(self):
|
def client(self):
|
||||||
if not self._client:
|
if not self._client:
|
||||||
self._client = os_clients.cinder_client(self.conf)
|
self._client = os_clients.cinder_client()
|
||||||
return self._client
|
return self._client
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -39,9 +39,6 @@ class CinderVolumeTransformer(ResourceTransformerBase):
|
|||||||
'volume.attach.end': GraphAction.UPDATE_RELATIONSHIP
|
'volume.attach.end': GraphAction.UPDATE_RELATIONSHIP
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, transformers, conf):
|
|
||||||
super(CinderVolumeTransformer, self).__init__(transformers, conf)
|
|
||||||
|
|
||||||
def _create_snapshot_entity_vertex(self, entity_event):
|
def _create_snapshot_entity_vertex(self, entity_event):
|
||||||
|
|
||||||
volume_name = extract_field_value(entity_event,
|
volume_name = extract_field_value(entity_event,
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
|
||||||
from vitrage.common.constants import DatasourceAction
|
from vitrage.common.constants import DatasourceAction
|
||||||
@ -24,17 +25,17 @@ from vitrage.datasources.collectd.properties\
|
|||||||
import CollectdProperties as CProps
|
import CollectdProperties as CProps
|
||||||
from vitrage.utils import file as file_utils
|
from vitrage.utils import file as file_utils
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CollectdDriver(AlarmDriverBase):
|
class CollectdDriver(AlarmDriverBase):
|
||||||
conf_map = None
|
conf_map = None
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(CollectdDriver, self).__init__()
|
super(CollectdDriver, self).__init__()
|
||||||
self.conf = conf
|
|
||||||
if not CollectdDriver.conf_map:
|
if not CollectdDriver.conf_map:
|
||||||
mapper = CollectdDriver._configuration_mapping(conf)
|
mapper = CollectdDriver._configuration_mapping()
|
||||||
if mapper:
|
if mapper:
|
||||||
CollectdDriver.conf_map = CollectdMapper(mapper)
|
CollectdDriver.conf_map = CollectdMapper(mapper)
|
||||||
|
|
||||||
@ -59,9 +60,9 @@ class CollectdDriver(AlarmDriverBase):
|
|||||||
and alarm[CProps.RESOURCE_NAME] is not None
|
and alarm[CProps.RESOURCE_NAME] is not None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _configuration_mapping(conf):
|
def _configuration_mapping():
|
||||||
try:
|
try:
|
||||||
collectd_config_file = conf.collectd[DSOpts.CONFIG_FILE]
|
collectd_config_file = CONF.collectd[DSOpts.CONFIG_FILE]
|
||||||
collectd_config = file_utils.load_yaml_file(collectd_config_file)
|
collectd_config = file_utils.load_yaml_file(collectd_config_file)
|
||||||
collectd_config_elements = collectd_config[COLLECTD_DATASOURCE]
|
collectd_config_elements = collectd_config[COLLECTD_DATASOURCE]
|
||||||
|
|
||||||
|
@ -28,9 +28,6 @@ from vitrage.utils.datetime import format_unix_timestamp
|
|||||||
|
|
||||||
class CollectdTransformer(AlarmTransformerBase):
|
class CollectdTransformer(AlarmTransformerBase):
|
||||||
|
|
||||||
def __init__(self, transformers, conf):
|
|
||||||
super(CollectdTransformer, self).__init__(transformers, conf)
|
|
||||||
|
|
||||||
def _create_snapshot_entity_vertex(self, entity_event):
|
def _create_snapshot_entity_vertex(self, entity_event):
|
||||||
# The Collectd datasource does not support snapshot mode
|
# The Collectd datasource does not support snapshot mode
|
||||||
return None
|
return None
|
||||||
|
@ -29,8 +29,8 @@ class ConsistencyTransformer(ResourceTransformerBase):
|
|||||||
GraphAction.REMOVE_DELETED_ENTITY: GraphAction.REMOVE_DELETED_ENTITY
|
GraphAction.REMOVE_DELETED_ENTITY: GraphAction.REMOVE_DELETED_ENTITY
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, transformers, conf):
|
def __init__(self, transformers):
|
||||||
super(ConsistencyTransformer, self).__init__(transformers, conf)
|
super(ConsistencyTransformer, self).__init__(transformers)
|
||||||
|
|
||||||
def _create_snapshot_entity_vertex(self, entity_event):
|
def _create_snapshot_entity_vertex(self, entity_event):
|
||||||
return self._create_vertex(entity_event)
|
return self._create_vertex(entity_event)
|
||||||
|
@ -32,9 +32,8 @@ LOG = log.getLogger(__name__)
|
|||||||
class DoctorDriver(AlarmDriverBase):
|
class DoctorDriver(AlarmDriverBase):
|
||||||
AlarmKey = namedtuple('AlarmKey', ['alarm_name', 'hostname'])
|
AlarmKey = namedtuple('AlarmKey', ['alarm_name', 'hostname'])
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(DoctorDriver, self).__init__()
|
super(DoctorDriver, self).__init__()
|
||||||
self.conf = conf
|
|
||||||
self._client = None
|
self._client = None
|
||||||
|
|
||||||
def _vitrage_type(self):
|
def _vitrage_type(self):
|
||||||
|
@ -35,9 +35,6 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class DoctorTransformer(AlarmTransformerBase):
|
class DoctorTransformer(AlarmTransformerBase):
|
||||||
|
|
||||||
def __init__(self, transformers, conf):
|
|
||||||
super(DoctorTransformer, self).__init__(transformers, conf)
|
|
||||||
|
|
||||||
def _create_snapshot_entity_vertex(self, entity_event):
|
def _create_snapshot_entity_vertex(self, entity_event):
|
||||||
# The Doctor monitor does not support snapshot mode
|
# The Doctor monitor does not support snapshot mode
|
||||||
return None
|
return None
|
||||||
|
@ -29,9 +29,6 @@ class DriverBase(object):
|
|||||||
|
|
||||||
_datasource_name = None
|
_datasource_name = None
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_all(self, datasource_action):
|
def get_all(self, datasource_action):
|
||||||
pass
|
pass
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
|
|
||||||
from vitrage.common.constants import DatasourceAction
|
from vitrage.common.constants import DatasourceAction
|
||||||
from vitrage.common.constants import DatasourceProperties as DSProps
|
from vitrage.common.constants import DatasourceProperties as DSProps
|
||||||
from vitrage.common.constants import GraphAction
|
from vitrage.common.constants import GraphAction
|
||||||
@ -27,6 +29,8 @@ from vitrage.datasources.nova.instance.driver import InstanceDriver
|
|||||||
from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE
|
from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE
|
||||||
from vitrage import os_clients
|
from vitrage import os_clients
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
|
|
||||||
|
|
||||||
class HeatStackDriver(DriverBase):
|
class HeatStackDriver(DriverBase):
|
||||||
|
|
||||||
@ -44,21 +48,20 @@ class HeatStackDriver(DriverBase):
|
|||||||
'OS::Neutron::Port': PortDriver
|
'OS::Neutron::Port': PortDriver
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(HeatStackDriver, self).__init__()
|
super(HeatStackDriver, self).__init__()
|
||||||
self._client = None
|
self._client = None
|
||||||
self._conf = conf
|
|
||||||
self._filter_resource_types()
|
self._filter_resource_types()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def client(self):
|
def client(self):
|
||||||
if not self._client:
|
if not self._client:
|
||||||
self._client = os_clients.heat_client(self._conf)
|
self._client = os_clients.heat_client()
|
||||||
return self._client
|
return self._client
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_topic(conf):
|
def get_topic():
|
||||||
return conf[HEAT_STACK_DATASOURCE].notification_topic
|
return CONF[HEAT_STACK_DATASOURCE].notification_topic
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_event_types():
|
def get_event_types():
|
||||||
@ -93,7 +96,7 @@ class HeatStackDriver(DriverBase):
|
|||||||
return self.client.stacks.get(_id).to_dict()['parent']
|
return self.client.stacks.get(_id).to_dict()['parent']
|
||||||
|
|
||||||
def _filter_resource_types(self):
|
def _filter_resource_types(self):
|
||||||
types = self._conf.datasources.types
|
types = CONF.datasources.types
|
||||||
|
|
||||||
self.RESOURCE_TYPE = {key: value for key, value in
|
self.RESOURCE_TYPE = {key: value for key, value in
|
||||||
self.RESOURCE_TYPE.items() if value in types}
|
self.RESOURCE_TYPE.items() if value in types}
|
||||||
|
@ -46,9 +46,6 @@ class HeatStackTransformer(ResourceTransformerBase):
|
|||||||
'orchestration.stack.delete.end': GraphAction.DELETE_ENTITY,
|
'orchestration.stack.delete.end': GraphAction.DELETE_ENTITY,
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, transformers, conf):
|
|
||||||
super(HeatStackTransformer, self).__init__(transformers, conf)
|
|
||||||
|
|
||||||
def _create_snapshot_entity_vertex(self, entity_event):
|
def _create_snapshot_entity_vertex(self, entity_event):
|
||||||
|
|
||||||
stack_name = extract_field_value(entity_event, StackProps.STACK_NAME)
|
stack_name = extract_field_value(entity_event, StackProps.STACK_NAME)
|
||||||
|
@ -14,11 +14,13 @@
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
|
||||||
from vitrage.common.constants import DatasourceOpts as DSOpts
|
from vitrage.common.constants import DatasourceOpts as DSOpts
|
||||||
from vitrage.utils import file as file_utils
|
from vitrage.utils import file as file_utils
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
KAPACITOR_HOST = 'kapacitor_host'
|
KAPACITOR_HOST = 'kapacitor_host'
|
||||||
KAPACITOR = 'kapacitor'
|
KAPACITOR = 'kapacitor'
|
||||||
@ -30,9 +32,9 @@ VITRAGE_RESOURCE = 'vitrage_resource'
|
|||||||
|
|
||||||
|
|
||||||
class KapacitorConfig(object):
|
class KapacitorConfig(object):
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
try:
|
try:
|
||||||
kapacitor_config_file = conf.kapacitor[DSOpts.CONFIG_FILE]
|
kapacitor_config_file = CONF.kapacitor[DSOpts.CONFIG_FILE]
|
||||||
kapacitor_config = file_utils.load_yaml_file(kapacitor_config_file)
|
kapacitor_config = file_utils.load_yaml_file(kapacitor_config_file)
|
||||||
kapacitor = kapacitor_config[KAPACITOR]
|
kapacitor = kapacitor_config[KAPACITOR]
|
||||||
|
|
||||||
|
@ -32,12 +32,11 @@ class KapacitorDriver(AlarmDriverBase):
|
|||||||
ServiceKey = namedtuple('ServiceKey', ['hostname', 'alarmid'])
|
ServiceKey = namedtuple('ServiceKey', ['hostname', 'alarmid'])
|
||||||
conf_map = None
|
conf_map = None
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(KapacitorDriver, self).__init__()
|
super(KapacitorDriver, self).__init__()
|
||||||
self.cfg = conf
|
|
||||||
|
|
||||||
if not KapacitorDriver.conf_map:
|
if not KapacitorDriver.conf_map:
|
||||||
self.conf_map = KapacitorConfig(conf)
|
self.conf_map = KapacitorConfig()
|
||||||
self._client = None
|
self._client = None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -34,9 +34,6 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class KapacitorTransformer(AlarmTransformerBase):
|
class KapacitorTransformer(AlarmTransformerBase):
|
||||||
|
|
||||||
def __init__(self, transformers, conf):
|
|
||||||
super(KapacitorTransformer, self).__init__(transformers, conf)
|
|
||||||
|
|
||||||
def _create_snapshot_entity_vertex(self, entity_event):
|
def _create_snapshot_entity_vertex(self, entity_event):
|
||||||
return self._create_vertex(entity_event)
|
return self._create_vertex(entity_event)
|
||||||
|
|
||||||
|
@ -14,36 +14,37 @@
|
|||||||
|
|
||||||
from kubernetes import client
|
from kubernetes import client
|
||||||
from kubernetes import config
|
from kubernetes import config
|
||||||
|
from oslo_log import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
from vitrage.datasources.driver_base import DriverBase
|
from vitrage.datasources.driver_base import DriverBase
|
||||||
from vitrage.datasources.kubernetes.properties import KUBERNETES_DATASOURCE
|
from vitrage.datasources.kubernetes.properties import KUBERNETES_DATASOURCE
|
||||||
from vitrage.datasources.kubernetes.properties import KubernetesProperties\
|
from vitrage.datasources.kubernetes.properties import KubernetesProperties\
|
||||||
as kubProp
|
as kubProp
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class KubernetesDriver(DriverBase):
|
class KubernetesDriver(DriverBase):
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(KubernetesDriver, self).__init__()
|
super(KubernetesDriver, self).__init__()
|
||||||
self._client = None
|
self._client = None
|
||||||
self.conf = conf
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def client(self):
|
def client(self):
|
||||||
if not self._client:
|
if not self._client:
|
||||||
self._client = self._k8s_client(self.conf)
|
self._client = self._k8s_client()
|
||||||
return self._client
|
return self._client
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _k8s_client(conf):
|
def _k8s_client():
|
||||||
try:
|
try:
|
||||||
if not conf.kubernetes.config_file:
|
if not CONF.kubernetes.config_file:
|
||||||
LOG.warning('kubernetes config file is not defined')
|
LOG.warning('kubernetes config file is not defined')
|
||||||
return
|
return
|
||||||
|
|
||||||
kubeconf = conf.kubernetes.config_file
|
kubeconf = CONF.kubernetes.config_file
|
||||||
config.load_kube_config(config_file=kubeconf)
|
config.load_kube_config(config_file=kubeconf)
|
||||||
k8s_client = client.CoreV1Api()
|
k8s_client = client.CoreV1Api()
|
||||||
if k8s_client is None:
|
if k8s_client is None:
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
|
||||||
from vitrage.common.constants import DatasourceProperties as DSProps
|
from vitrage.common.constants import DatasourceProperties as DSProps
|
||||||
@ -32,13 +33,11 @@ from vitrage.datasources.kubernetes.properties import \
|
|||||||
KubernetesProperties as kubProp
|
KubernetesProperties as kubProp
|
||||||
from vitrage.utils import file as file_utils
|
from vitrage.utils import file as file_utils
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class KubernetesTransformer(ResourceTransformerBase):
|
class KubernetesTransformer(ResourceTransformerBase):
|
||||||
def __init__(self, transformers, conf):
|
|
||||||
super(KubernetesTransformer, self).__init__(transformers, conf)
|
|
||||||
self.conf = conf
|
|
||||||
|
|
||||||
def _create_vertex(self, entity_event):
|
def _create_vertex(self, entity_event):
|
||||||
metadata = {
|
metadata = {
|
||||||
@ -84,7 +83,7 @@ class KubernetesTransformer(ResourceTransformerBase):
|
|||||||
return KUBERNETES_DATASOURCE
|
return KUBERNETES_DATASOURCE
|
||||||
|
|
||||||
def _get_cluster_name(self):
|
def _get_cluster_name(self):
|
||||||
kubeconf = file_utils.load_yaml_file(self.conf.kubernetes.config_file)
|
kubeconf = file_utils.load_yaml_file(CONF.kubernetes.config_file)
|
||||||
if not kubeconf:
|
if not kubeconf:
|
||||||
return None
|
return None
|
||||||
contexts = kubeconf['contexts']
|
contexts = kubeconf['contexts']
|
||||||
|
@ -28,15 +28,14 @@ LOG = log.getLogger(__name__)
|
|||||||
|
|
||||||
class MonascaDriver(AlarmDriverBase):
|
class MonascaDriver(AlarmDriverBase):
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(MonascaDriver, self).__init__()
|
super(MonascaDriver, self).__init__()
|
||||||
self.conf = conf
|
|
||||||
self.__client = None
|
self.__client = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def client(self):
|
def client(self):
|
||||||
if not self.__client:
|
if not self.__client:
|
||||||
self.__client = os_clients.monasca_client(self.conf)
|
self.__client = os_clients.monasca_client()
|
||||||
return self.__client
|
return self.__client
|
||||||
|
|
||||||
def _vitrage_type(self):
|
def _vitrage_type(self):
|
||||||
|
@ -14,11 +14,13 @@
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
|
||||||
from vitrage.common.constants import DatasourceOpts as DSOpts
|
from vitrage.common.constants import DatasourceOpts as DSOpts
|
||||||
from vitrage.utils import file as file_utils
|
from vitrage.utils import file as file_utils
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
NAGIOS_HOST = 'nagios_host'
|
NAGIOS_HOST = 'nagios_host'
|
||||||
NAGIOS = 'nagios'
|
NAGIOS = 'nagios'
|
||||||
@ -28,9 +30,9 @@ NAME = 'name'
|
|||||||
|
|
||||||
|
|
||||||
class NagiosConfig(object):
|
class NagiosConfig(object):
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
try:
|
try:
|
||||||
nagios_config_file = conf.nagios[DSOpts.CONFIG_FILE]
|
nagios_config_file = CONF.nagios[DSOpts.CONFIG_FILE]
|
||||||
nagios_config = file_utils.load_yaml_file(nagios_config_file)
|
nagios_config = file_utils.load_yaml_file(nagios_config_file)
|
||||||
nagios = nagios_config[NAGIOS] # nagios root in the yaml file
|
nagios = nagios_config[NAGIOS] # nagios root in the yaml file
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
@ -26,16 +27,16 @@ from vitrage.datasources.nagios.properties import NagiosProperties\
|
|||||||
as NagiosProps
|
as NagiosProps
|
||||||
from vitrage.datasources.nagios.properties import NagiosTestStatus
|
from vitrage.datasources.nagios.properties import NagiosTestStatus
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class NagiosDriver(AlarmDriverBase):
|
class NagiosDriver(AlarmDriverBase):
|
||||||
ServiceKey = namedtuple('ServiceKey', ['hostname', 'service'])
|
ServiceKey = namedtuple('ServiceKey', ['hostname', 'service'])
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(NagiosDriver, self).__init__()
|
super(NagiosDriver, self).__init__()
|
||||||
self.conf = conf
|
self.config = NagiosConfig()
|
||||||
self.config = NagiosConfig(conf)
|
|
||||||
|
|
||||||
def _vitrage_type(self):
|
def _vitrage_type(self):
|
||||||
return NAGIOS_DATASOURCE
|
return NAGIOS_DATASOURCE
|
||||||
@ -45,9 +46,9 @@ class NagiosDriver(AlarmDriverBase):
|
|||||||
service=alarm[NagiosProps.SERVICE])
|
service=alarm[NagiosProps.SERVICE])
|
||||||
|
|
||||||
def _get_alarms(self):
|
def _get_alarms(self):
|
||||||
nagios_user = self.conf.nagios.user
|
nagios_user = CONF.nagios.user
|
||||||
nagios_password = self.conf.nagios.password
|
nagios_password = CONF.nagios.password
|
||||||
nagios_url = self.conf.nagios.url
|
nagios_url = CONF.nagios.url
|
||||||
|
|
||||||
if not nagios_user:
|
if not nagios_user:
|
||||||
return []
|
return []
|
||||||
|
@ -27,9 +27,6 @@ from vitrage.utils import datetime as datetime_utils
|
|||||||
|
|
||||||
class NagiosTransformer(AlarmTransformerBase):
|
class NagiosTransformer(AlarmTransformerBase):
|
||||||
|
|
||||||
def __init__(self, transformers, conf):
|
|
||||||
super(NagiosTransformer, self).__init__(transformers, conf)
|
|
||||||
|
|
||||||
def _create_snapshot_entity_vertex(self, entity_event):
|
def _create_snapshot_entity_vertex(self, entity_event):
|
||||||
return self._create_vertex(entity_event)
|
return self._create_vertex(entity_event)
|
||||||
|
|
||||||
|
@ -18,13 +18,12 @@ from vitrage import os_clients
|
|||||||
|
|
||||||
|
|
||||||
class NeutronBase(DriverBase):
|
class NeutronBase(DriverBase):
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(NeutronBase, self).__init__()
|
super(NeutronBase, self).__init__()
|
||||||
self._client = None
|
self._client = None
|
||||||
self.conf = conf
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def client(self):
|
def client(self):
|
||||||
if not self._client:
|
if not self._client:
|
||||||
self._client = os_clients.neutron_client(self.conf)
|
self._client = os_clients.neutron_client()
|
||||||
return self._client
|
return self._client
|
||||||
|
@ -40,9 +40,6 @@ class NetworkTransformer(ResourceTransformerBase):
|
|||||||
'network.delete.end': GraphAction.DELETE_ENTITY,
|
'network.delete.end': GraphAction.DELETE_ENTITY,
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, transformers, conf):
|
|
||||||
super(NetworkTransformer, self).__init__(transformers, conf)
|
|
||||||
|
|
||||||
def _create_snapshot_entity_vertex(self, entity_event):
|
def _create_snapshot_entity_vertex(self, entity_event):
|
||||||
|
|
||||||
name = entity_event[NetworkProps.NAME]
|
name = entity_event[NetworkProps.NAME]
|
||||||
|
@ -51,9 +51,6 @@ class PortTransformer(ResourceTransformerBase):
|
|||||||
'port.delete.end': GraphAction.DELETE_ENTITY,
|
'port.delete.end': GraphAction.DELETE_ENTITY,
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, transformers, conf):
|
|
||||||
super(PortTransformer, self).__init__(transformers, conf)
|
|
||||||
|
|
||||||
def _create_snapshot_entity_vertex(self, entity_event):
|
def _create_snapshot_entity_vertex(self, entity_event):
|
||||||
|
|
||||||
name = entity_event[PortProps.NAME]\
|
name = entity_event[PortProps.NAME]\
|
||||||
|
@ -33,9 +33,6 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class HostTransformer(ResourceTransformerBase):
|
class HostTransformer(ResourceTransformerBase):
|
||||||
|
|
||||||
def __init__(self, transformers, conf):
|
|
||||||
super(HostTransformer, self).__init__(transformers, conf)
|
|
||||||
|
|
||||||
def _create_snapshot_entity_vertex(self, entity_event):
|
def _create_snapshot_entity_vertex(self, entity_event):
|
||||||
return self._create_vertex(entity_event,
|
return self._create_vertex(entity_event,
|
||||||
entity_event.get(HostProps.HOST))
|
entity_event.get(HostProps.HOST))
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from vitrage.common.constants import DatasourceAction
|
from vitrage.common.constants import DatasourceAction
|
||||||
from vitrage.common.constants import DatasourceProperties as DSProps
|
from vitrage.common.constants import DatasourceProperties as DSProps
|
||||||
from vitrage.common.constants import GraphAction
|
from vitrage.common.constants import GraphAction
|
||||||
@ -19,6 +20,8 @@ from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE
|
|||||||
from vitrage.datasources.nova.nova_driver_base import NovaDriverBase
|
from vitrage.datasources.nova.nova_driver_base import NovaDriverBase
|
||||||
|
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
|
|
||||||
# versioned notifications
|
# versioned notifications
|
||||||
VERSIONED_NOTIFICATIONS = {
|
VERSIONED_NOTIFICATIONS = {
|
||||||
'instance.create.end',
|
'instance.create.end',
|
||||||
@ -114,7 +117,7 @@ class InstanceDriver(NovaDriverBase):
|
|||||||
*self.properties_to_filter_out())
|
*self.properties_to_filter_out())
|
||||||
|
|
||||||
def enrich_event(self, event, event_type):
|
def enrich_event(self, event, event_type):
|
||||||
use_versioned = self.conf.use_nova_versioned_notifications
|
use_versioned = CONF.use_nova_versioned_notifications
|
||||||
|
|
||||||
# Send to the processor only events of the matching types. Nova may
|
# Send to the processor only events of the matching types. Nova may
|
||||||
# send both versioned and legacy notifications, and we don't want to
|
# send both versioned and legacy notifications, and we don't want to
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
|
||||||
from vitrage.common.constants import DatasourceProperties as DSProps
|
from vitrage.common.constants import DatasourceProperties as DSProps
|
||||||
@ -32,6 +34,7 @@ from vitrage.datasources import transformer_base as tbase
|
|||||||
from vitrage.datasources.transformer_base import extract_field_value
|
from vitrage.datasources.transformer_base import extract_field_value
|
||||||
import vitrage.graph.utils as graph_utils
|
import vitrage.graph.utils as graph_utils
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -47,9 +50,6 @@ class InstanceTransformer(ResourceTransformerBase):
|
|||||||
'instance.delete.end': GraphAction.DELETE_ENTITY,
|
'instance.delete.end': GraphAction.DELETE_ENTITY,
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, transformers, conf):
|
|
||||||
super(InstanceTransformer, self).__init__(transformers, conf)
|
|
||||||
|
|
||||||
def _create_snapshot_entity_vertex(self, entity_event):
|
def _create_snapshot_entity_vertex(self, entity_event):
|
||||||
LOG.debug('got snapshot')
|
LOG.debug('got snapshot')
|
||||||
return self._create_vertex(entity_event)
|
return self._create_vertex(entity_event)
|
||||||
@ -134,7 +134,7 @@ class InstanceTransformer(ResourceTransformerBase):
|
|||||||
"""Return an object that extracts the field values from the event"""
|
"""Return an object that extracts the field values from the event"""
|
||||||
if tbase.is_update_event(event):
|
if tbase.is_update_event(event):
|
||||||
return self.versioned_notifications_extractor if \
|
return self.versioned_notifications_extractor if \
|
||||||
self.conf.use_nova_versioned_notifications is True else \
|
CONF.use_nova_versioned_notifications is True else \
|
||||||
self.legacy_notifications_extractor
|
self.legacy_notifications_extractor
|
||||||
else:
|
else:
|
||||||
return self.snapshot_extractor
|
return self.snapshot_extractor
|
||||||
|
@ -18,13 +18,12 @@ from vitrage import os_clients
|
|||||||
|
|
||||||
|
|
||||||
class NovaDriverBase(DriverBase):
|
class NovaDriverBase(DriverBase):
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(NovaDriverBase, self).__init__()
|
super(NovaDriverBase, self).__init__()
|
||||||
self._client = None
|
self._client = None
|
||||||
self.conf = conf
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def client(self):
|
def client(self):
|
||||||
if not self._client:
|
if not self._client:
|
||||||
self._client = os_clients.nova_client(self.conf)
|
self._client = os_clients.nova_client()
|
||||||
return self._client
|
return self._client
|
||||||
|
@ -38,9 +38,6 @@ class ZoneTransformer(ResourceTransformerBase):
|
|||||||
STATE_AVAILABLE = 'available'
|
STATE_AVAILABLE = 'available'
|
||||||
STATE_UNAVAILABLE = 'unavailable'
|
STATE_UNAVAILABLE = 'unavailable'
|
||||||
|
|
||||||
def __init__(self, transformers, conf):
|
|
||||||
super(ZoneTransformer, self).__init__(transformers, conf)
|
|
||||||
|
|
||||||
def _create_snapshot_entity_vertex(self, entity_event):
|
def _create_snapshot_entity_vertex(self, entity_event):
|
||||||
|
|
||||||
zone_name = extract_field_value(entity_event, ZoneProps.ZONE_NAME)
|
zone_name = extract_field_value(entity_event, ZoneProps.ZONE_NAME)
|
||||||
|
@ -16,6 +16,7 @@ import socket
|
|||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from ipaddress import ip_address
|
from ipaddress import ip_address
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
import requests
|
import requests
|
||||||
import six
|
import six
|
||||||
@ -46,6 +47,7 @@ from vitrage.datasources.prometheus.properties \
|
|||||||
from vitrage import os_clients
|
from vitrage import os_clients
|
||||||
from vitrage.utils import file as file_utils
|
from vitrage.utils import file as file_utils
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
PROMETHEUS_EVENT_TYPE = 'prometheus.alarm'
|
PROMETHEUS_EVENT_TYPE = 'prometheus.alarm'
|
||||||
@ -132,17 +134,16 @@ class PrometheusDriver(AlarmDriverBase):
|
|||||||
PCFProps.RESOURCE])
|
PCFProps.RESOURCE])
|
||||||
conf_map = {}
|
conf_map = {}
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(PrometheusDriver, self).__init__()
|
super(PrometheusDriver, self).__init__()
|
||||||
self.conf = conf
|
|
||||||
self._client = None
|
self._client = None
|
||||||
self._nova_client = None
|
self._nova_client = None
|
||||||
self.conf_map = self._configuration_mapping(conf)
|
self.conf_map = self._configuration_mapping()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def nova_client(self):
|
def nova_client(self):
|
||||||
if not self._nova_client:
|
if not self._nova_client:
|
||||||
self._nova_client = os_clients.nova_client(self.conf)
|
self._nova_client = os_clients.nova_client()
|
||||||
return self._nova_client
|
return self._nova_client
|
||||||
|
|
||||||
def _vitrage_type(self):
|
def _vitrage_type(self):
|
||||||
@ -167,8 +168,8 @@ class PrometheusDriver(AlarmDriverBase):
|
|||||||
old_alarm.get(PAlertProps.STATUS)
|
old_alarm.get(PAlertProps.STATUS)
|
||||||
|
|
||||||
def _get_all_alarms(self):
|
def _get_all_alarms(self):
|
||||||
alertmanager_url = self.conf.prometheus.alertmanager_url
|
alertmanager_url = CONF.prometheus.alertmanager_url
|
||||||
receiver = self.conf.prometheus.receiver
|
receiver = CONF.prometheus.receiver
|
||||||
if not alertmanager_url:
|
if not alertmanager_url:
|
||||||
LOG.warning('Alertmanager url is not defined')
|
LOG.warning('Alertmanager url is not defined')
|
||||||
return []
|
return []
|
||||||
@ -209,8 +210,8 @@ class PrometheusDriver(AlarmDriverBase):
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _configuration_mapping(conf):
|
def _configuration_mapping():
|
||||||
prometheus_config_file = conf.prometheus[DSOpts.CONFIG_FILE]
|
prometheus_config_file = CONF.prometheus[DSOpts.CONFIG_FILE]
|
||||||
try:
|
try:
|
||||||
prometheus_config = \
|
prometheus_config = \
|
||||||
file_utils.load_yaml_file(prometheus_config_file)
|
file_utils.load_yaml_file(prometheus_config_file)
|
||||||
|
@ -38,9 +38,6 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class PrometheusTransformer(AlarmTransformerBase):
|
class PrometheusTransformer(AlarmTransformerBase):
|
||||||
|
|
||||||
def __init__(self, transformers, conf):
|
|
||||||
super(PrometheusTransformer, self).__init__(transformers, conf)
|
|
||||||
|
|
||||||
def _create_snapshot_entity_vertex(self, entity_event):
|
def _create_snapshot_entity_vertex(self, entity_event):
|
||||||
return self._create_vertex(entity_event)
|
return self._create_vertex(entity_event)
|
||||||
|
|
||||||
|
@ -16,6 +16,4 @@ from vitrage.datasources import transformer_base as tbase
|
|||||||
|
|
||||||
|
|
||||||
class ResourceTransformerBase(tbase.TransformerBase):
|
class ResourceTransformerBase(tbase.TransformerBase):
|
||||||
|
pass
|
||||||
def __init__(self, transformers, conf):
|
|
||||||
super(ResourceTransformerBase, self).__init__(transformers, conf)
|
|
||||||
|
@ -16,6 +16,7 @@ from itertools import chain
|
|||||||
from jsonschema import validate
|
from jsonschema import validate
|
||||||
from six.moves import reduce
|
from six.moves import reduce
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
|
||||||
from vitrage.common.constants import DatasourceProperties as DSProps
|
from vitrage.common.constants import DatasourceProperties as DSProps
|
||||||
@ -26,6 +27,7 @@ from vitrage.datasources.static import STATIC_SCHEMA
|
|||||||
from vitrage.datasources.static import StaticFields
|
from vitrage.datasources.static import StaticFields
|
||||||
from vitrage.utils import file as file_utils
|
from vitrage.utils import file as file_utils
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -35,9 +37,8 @@ class StaticDriver(DriverBase):
|
|||||||
StaticFields.TYPE,
|
StaticFields.TYPE,
|
||||||
StaticFields.ID}
|
StaticFields.ID}
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(StaticDriver, self).__init__()
|
super(StaticDriver, self).__init__()
|
||||||
self.cfg = conf
|
|
||||||
self.entities_cache = []
|
self.entities_cache = []
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -77,7 +78,7 @@ class StaticDriver(DriverBase):
|
|||||||
return self.entities_cache
|
return self.entities_cache
|
||||||
|
|
||||||
def _get_all_entities(self):
|
def _get_all_entities(self):
|
||||||
files = file_utils.list_files(self.cfg.static.directory, '.yaml', True)
|
files = file_utils.list_files(CONF.static.directory, '.yaml', True)
|
||||||
return list(reduce(chain, [self._get_entities_from_file(path)
|
return list(reduce(chain, [self._get_entities_from_file(path)
|
||||||
for path in files], []))
|
for path in files], []))
|
||||||
|
|
||||||
|
@ -29,9 +29,6 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class StaticTransformer(ResourceTransformerBase):
|
class StaticTransformer(ResourceTransformerBase):
|
||||||
|
|
||||||
def __init__(self, transformers, conf):
|
|
||||||
super(StaticTransformer, self).__init__(transformers, conf)
|
|
||||||
|
|
||||||
def _create_snapshot_entity_vertex(self, entity_event):
|
def _create_snapshot_entity_vertex(self, entity_event):
|
||||||
return self._create_vertex(entity_event)
|
return self._create_vertex(entity_event)
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ import abc
|
|||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_utils import uuidutils
|
from oslo_utils import uuidutils
|
||||||
|
|
||||||
@ -35,6 +36,7 @@ import vitrage.graph.utils as graph_utils
|
|||||||
from vitrage.utils import datetime as datetime_utils
|
from vitrage.utils import datetime as datetime_utils
|
||||||
from vitrage.utils import opt_exists
|
from vitrage.utils import opt_exists
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
EntityWrapper = \
|
EntityWrapper = \
|
||||||
@ -109,8 +111,7 @@ class TransformerBase(object):
|
|||||||
|
|
||||||
key_to_uuid_cache = {}
|
key_to_uuid_cache = {}
|
||||||
|
|
||||||
def __init__(self, transformers, conf):
|
def __init__(self, transformers):
|
||||||
self.conf = conf
|
|
||||||
self.transformers = transformers
|
self.transformers = transformers
|
||||||
|
|
||||||
def transform(self, entity_event):
|
def transform(self, entity_event):
|
||||||
@ -138,11 +139,11 @@ class TransformerBase(object):
|
|||||||
|
|
||||||
def _create_entity_vertex(self, entity_event):
|
def _create_entity_vertex(self, entity_event):
|
||||||
if is_update_event(entity_event) and \
|
if is_update_event(entity_event) and \
|
||||||
opt_exists(self.conf, self.get_vitrage_type()) and \
|
opt_exists(CONF, self.get_vitrage_type()) and \
|
||||||
opt_exists(self.conf[self.get_vitrage_type()],
|
opt_exists(CONF[self.get_vitrage_type()],
|
||||||
DSOpts.UPDATE_METHOD):
|
DSOpts.UPDATE_METHOD):
|
||||||
update_method = \
|
update_method = \
|
||||||
self.conf[self.get_vitrage_type()].update_method.lower()
|
CONF[self.get_vitrage_type()].update_method.lower()
|
||||||
if update_method == UpdateMethod.PUSH:
|
if update_method == UpdateMethod.PUSH:
|
||||||
vertex = self._create_update_entity_vertex(entity_event)
|
vertex = self._create_update_entity_vertex(entity_event)
|
||||||
return self.update_uuid_in_vertex(vertex)
|
return self.update_uuid_in_vertex(vertex)
|
||||||
|
@ -27,8 +27,8 @@ LOG = log.getLogger(__name__)
|
|||||||
|
|
||||||
class TroveClusterDriver(TroveDriverBase):
|
class TroveClusterDriver(TroveDriverBase):
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(TroveClusterDriver, self).__init__(conf)
|
super(TroveClusterDriver, self).__init__()
|
||||||
self._cached_entities = []
|
self._cached_entities = []
|
||||||
|
|
||||||
def _get_vitrage_type(self):
|
def _get_vitrage_type(self):
|
||||||
|
@ -26,8 +26,8 @@ LOG = log.getLogger(__name__)
|
|||||||
|
|
||||||
class TroveInstanceDriver(TroveDriverBase):
|
class TroveInstanceDriver(TroveDriverBase):
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(TroveInstanceDriver, self).__init__(conf)
|
super(TroveInstanceDriver, self).__init__()
|
||||||
self._cached_entities = []
|
self._cached_entities = []
|
||||||
|
|
||||||
def _get_vitrage_type(self):
|
def _get_vitrage_type(self):
|
||||||
|
@ -23,16 +23,15 @@ from vitrage import os_clients
|
|||||||
|
|
||||||
class TroveDriverBase(DriverBase):
|
class TroveDriverBase(DriverBase):
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(TroveDriverBase, self).__init__()
|
super(TroveDriverBase, self).__init__()
|
||||||
self.conf = conf
|
|
||||||
self.__client = None
|
self.__client = None
|
||||||
self.__cached_entities = []
|
self.__cached_entities = []
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def client(self):
|
def client(self):
|
||||||
if not self.__client:
|
if not self.__client:
|
||||||
self.__client = os_clients.trove_client(self.conf)
|
self.__client = os_clients.trove_client()
|
||||||
return self.__client
|
return self.__client
|
||||||
|
|
||||||
def get_all(self, datasource_action):
|
def get_all(self, datasource_action):
|
||||||
|
@ -11,34 +11,38 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_utils import importutils as utils
|
from oslo_utils import importutils as utils
|
||||||
|
|
||||||
from vitrage.common.constants import DatasourceOpts as DSOpts
|
from vitrage.common.constants import DatasourceOpts as DSOpts
|
||||||
from vitrage.common.constants import UpdateMethod
|
from vitrage.common.constants import UpdateMethod
|
||||||
from vitrage.utils import opt_exists
|
from vitrage.utils import opt_exists
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
|
|
||||||
drivers = {}
|
drivers = {}
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyProtectedMember
|
# noinspection PyProtectedMember
|
||||||
def get_drivers_by_name(conf, driver_names):
|
def get_drivers_by_name(driver_names):
|
||||||
for d_name in driver_names:
|
for d_name in driver_names:
|
||||||
if not drivers.get(d_name):
|
if not drivers.get(d_name):
|
||||||
drivers[d_name] = utils.import_object(conf[d_name].driver, conf)
|
drivers[d_name] = utils.import_object(CONF[d_name].driver)
|
||||||
drivers[d_name].__class__._datasource_name = d_name
|
drivers[d_name].__class__._datasource_name = d_name
|
||||||
return [drivers[d_name] for d_name in driver_names]
|
return [drivers[d_name] for d_name in driver_names]
|
||||||
|
|
||||||
|
|
||||||
def get_pull_drivers_names(conf):
|
def get_pull_drivers_names():
|
||||||
return [name for name in conf.datasources.types
|
return [name for name in CONF.datasources.types
|
||||||
if conf[name].update_method.lower() == UpdateMethod.PULL
|
if CONF[name].update_method.lower() == UpdateMethod.PULL
|
||||||
and opt_exists(conf[name], DSOpts.CHANGES_INTERVAL)]
|
and opt_exists(CONF[name], DSOpts.CHANGES_INTERVAL)]
|
||||||
|
|
||||||
|
|
||||||
def get_push_drivers_names(conf):
|
def get_push_drivers_names():
|
||||||
return [name for name in conf.datasources.types
|
return [name for name in CONF.datasources.types
|
||||||
if conf[name].update_method.lower() == UpdateMethod.PUSH]
|
if CONF[name].update_method.lower() == UpdateMethod.PUSH]
|
||||||
|
|
||||||
|
|
||||||
def get_driver_class(conf, driver_name):
|
def get_driver_class(driver_name):
|
||||||
return utils.import_class(conf[driver_name].driver)
|
return utils.import_class(CONF[driver_name].driver)
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
from oslo_utils import importutils as utils
|
from oslo_utils import importutils as utils
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ from vitrage.datasources.zabbix.properties import ZabbixTriggerValue \
|
|||||||
from vitrage.datasources.zabbix import ZABBIX_DATASOURCE
|
from vitrage.datasources.zabbix import ZABBIX_DATASOURCE
|
||||||
from vitrage.utils import file as file_utils
|
from vitrage.utils import file as file_utils
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -36,30 +38,29 @@ class ZabbixDriver(AlarmDriverBase):
|
|||||||
ServiceKey = namedtuple('ServiceKey', ['hostname', 'triggerid'])
|
ServiceKey = namedtuple('ServiceKey', ['hostname', 'triggerid'])
|
||||||
conf_map = None
|
conf_map = None
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(ZabbixDriver, self).__init__()
|
super(ZabbixDriver, self).__init__()
|
||||||
self.conf = conf
|
|
||||||
if not ZabbixDriver.conf_map:
|
if not ZabbixDriver.conf_map:
|
||||||
ZabbixDriver.conf_map =\
|
ZabbixDriver.conf_map =\
|
||||||
ZabbixDriver._configuration_mapping(conf)
|
ZabbixDriver._configuration_mapping()
|
||||||
self._client = None
|
self._client = None
|
||||||
|
|
||||||
def zabbix_client_login(self):
|
def zabbix_client_login(self):
|
||||||
if not self.conf.zabbix.user:
|
if not CONF.zabbix.user:
|
||||||
LOG.warning('Zabbix user is not defined')
|
LOG.warning('Zabbix user is not defined')
|
||||||
if not self.conf.zabbix.password:
|
if not CONF.zabbix.password:
|
||||||
LOG.warning('Zabbix password is not defined')
|
LOG.warning('Zabbix password is not defined')
|
||||||
if not self.conf.zabbix.url:
|
if not CONF.zabbix.url:
|
||||||
LOG.warning('Zabbix url is not defined')
|
LOG.warning('Zabbix url is not defined')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not self._client:
|
if not self._client:
|
||||||
self._client = utils.import_object(
|
self._client = utils.import_object(
|
||||||
'pyzabbix.ZabbixAPI',
|
'pyzabbix.ZabbixAPI',
|
||||||
self.conf.zabbix.url)
|
CONF.zabbix.url)
|
||||||
self._client.login(
|
self._client.login(
|
||||||
self.conf.zabbix.user,
|
CONF.zabbix.user,
|
||||||
self.conf.zabbix.password)
|
CONF.zabbix.password)
|
||||||
except Exception:
|
except Exception:
|
||||||
LOG.exception('pyzabbix.ZabbixAPI error occurred.')
|
LOG.exception('pyzabbix.ZabbixAPI error occurred.')
|
||||||
self._client = None
|
self._client = None
|
||||||
@ -154,9 +155,9 @@ class ZabbixDriver(AlarmDriverBase):
|
|||||||
return alarm[ZProps.VALUE]
|
return alarm[ZProps.VALUE]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _configuration_mapping(conf):
|
def _configuration_mapping():
|
||||||
try:
|
try:
|
||||||
zabbix_config_file = conf.zabbix[DSOpts.CONFIG_FILE]
|
zabbix_config_file = CONF.zabbix[DSOpts.CONFIG_FILE]
|
||||||
zabbix_config = file_utils.load_yaml_file(zabbix_config_file)
|
zabbix_config = file_utils.load_yaml_file(zabbix_config_file)
|
||||||
zabbix_config_elements = zabbix_config[ZABBIX_DATASOURCE]
|
zabbix_config_elements = zabbix_config[ZABBIX_DATASOURCE]
|
||||||
|
|
||||||
|
@ -32,9 +32,6 @@ from vitrage.utils.datetime import format_unix_timestamp
|
|||||||
|
|
||||||
class ZabbixTransformer(AlarmTransformerBase):
|
class ZabbixTransformer(AlarmTransformerBase):
|
||||||
|
|
||||||
def __init__(self, transformers, conf):
|
|
||||||
super(ZabbixTransformer, self).__init__(transformers, conf)
|
|
||||||
|
|
||||||
def _create_snapshot_entity_vertex(self, entity_event):
|
def _create_snapshot_entity_vertex(self, entity_event):
|
||||||
return self._create_vertex(entity_event)
|
return self._create_vertex(entity_event)
|
||||||
|
|
||||||
|
@ -17,6 +17,8 @@ from oslo_config import cfg
|
|||||||
|
|
||||||
from stevedore import driver
|
from stevedore import driver
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
|
|
||||||
OPTS = [
|
OPTS = [
|
||||||
cfg.StrOpt('datasources_values_dir',
|
cfg.StrOpt('datasources_values_dir',
|
||||||
default='/etc/vitrage/datasources_values',
|
default='/etc/vitrage/datasources_values',
|
||||||
@ -35,10 +37,10 @@ OPTS = [
|
|||||||
EVALUATOR_TOPIC = 'vitrage.evaluator'
|
EVALUATOR_TOPIC = 'vitrage.evaluator'
|
||||||
|
|
||||||
|
|
||||||
def get_graph_driver(conf):
|
def get_graph_driver():
|
||||||
try:
|
try:
|
||||||
mgr = driver.DriverManager('vitrage.entity_graph',
|
mgr = driver.DriverManager('vitrage.entity_graph',
|
||||||
conf.entity_graph.graph_driver,
|
CONF.entity_graph.graph_driver,
|
||||||
invoke_on_load=True)
|
invoke_on_load=True)
|
||||||
return mgr.driver
|
return mgr.driver
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
|
||||||
from vitrage.common.constants import DatasourceAction
|
from vitrage.common.constants import DatasourceAction
|
||||||
@ -30,18 +31,17 @@ from vitrage.evaluator.actions.evaluator_event_transformer \
|
|||||||
from vitrage.messaging import VitrageNotifier
|
from vitrage.messaging import VitrageNotifier
|
||||||
from vitrage.utils.datetime import utcnow
|
from vitrage.utils.datetime import utcnow
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ConsistencyEnforcer(object):
|
class ConsistencyEnforcer(object):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
conf,
|
|
||||||
entity_graph,
|
entity_graph,
|
||||||
actions_callback=None):
|
actions_callback=None):
|
||||||
self.conf = conf
|
|
||||||
self.actions_callback = actions_callback or VitrageNotifier(
|
self.actions_callback = actions_callback or VitrageNotifier(
|
||||||
conf, 'vitrage_consistency', [EVALUATOR_TOPIC]).notify
|
'vitrage_consistency', [EVALUATOR_TOPIC]).notify
|
||||||
self.graph = entity_graph
|
self.graph = entity_graph
|
||||||
self._init_datasources_to_mark_deleted()
|
self._init_datasources_to_mark_deleted()
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ class ConsistencyEnforcer(object):
|
|||||||
|
|
||||||
def _find_outdated_entities_to_mark_as_deleted(self):
|
def _find_outdated_entities_to_mark_as_deleted(self):
|
||||||
vitrage_sample_tstmp = str(utcnow() - timedelta(
|
vitrage_sample_tstmp = str(utcnow() - timedelta(
|
||||||
seconds=2 * self.conf.datasources.snapshots_interval))
|
seconds=2 * CONF.datasources.snapshots_interval))
|
||||||
query = {
|
query = {
|
||||||
'and': [
|
'and': [
|
||||||
{'!=': {VProps.VITRAGE_TYPE: VITRAGE_DATASOURCE}},
|
{'!=': {VProps.VITRAGE_TYPE: VITRAGE_DATASOURCE}},
|
||||||
@ -87,7 +87,7 @@ class ConsistencyEnforcer(object):
|
|||||||
|
|
||||||
def _find_old_deleted_entities(self):
|
def _find_old_deleted_entities(self):
|
||||||
vitrage_sample_tstmp = str(utcnow() - timedelta(
|
vitrage_sample_tstmp = str(utcnow() - timedelta(
|
||||||
seconds=self.conf.consistency.min_time_to_delete))
|
seconds=CONF.consistency.min_time_to_delete))
|
||||||
query = {
|
query = {
|
||||||
'and': [
|
'and': [
|
||||||
{'==': {VProps.VITRAGE_IS_DELETED: True}},
|
{'==': {VProps.VITRAGE_IS_DELETED: True}},
|
||||||
@ -140,8 +140,8 @@ class ConsistencyEnforcer(object):
|
|||||||
def _init_datasources_to_mark_deleted(self):
|
def _init_datasources_to_mark_deleted(self):
|
||||||
self.datasources_to_mark_deleted = []
|
self.datasources_to_mark_deleted = []
|
||||||
|
|
||||||
for driver_name in self.conf.datasources.types:
|
for driver_name in CONF.datasources.types:
|
||||||
driver_class = utils.get_driver_class(self.conf, driver_name)
|
driver_class = utils.get_driver_class(driver_name)
|
||||||
if driver_class.should_delete_outdated_entities():
|
if driver_class.should_delete_outdated_entities():
|
||||||
self.datasources_to_mark_deleted.append(driver_name)
|
self.datasources_to_mark_deleted.append(driver_name)
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ from collections import defaultdict
|
|||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
import oslo_messaging
|
import oslo_messaging
|
||||||
|
|
||||||
@ -22,18 +23,18 @@ from vitrage.common.constants import DatasourceAction
|
|||||||
from vitrage.datasources import utils
|
from vitrage.datasources import utils
|
||||||
from vitrage import messaging
|
from vitrage import messaging
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class DriverExec(object):
|
class DriverExec(object):
|
||||||
|
|
||||||
def __init__(self, conf, process_output_func, persist):
|
def __init__(self, process_output_func, persist):
|
||||||
self.conf = conf
|
|
||||||
self.process_output_func = process_output_func
|
self.process_output_func = process_output_func
|
||||||
self.persist = persist
|
self.persist = persist
|
||||||
|
|
||||||
def snapshot_get_all(self, action=DatasourceAction.INIT_SNAPSHOT):
|
def snapshot_get_all(self, action=DatasourceAction.INIT_SNAPSHOT):
|
||||||
driver_names = self.conf.datasources.types
|
driver_names = CONF.datasources.types
|
||||||
LOG.info('get_all starting for %s', driver_names)
|
LOG.info('get_all starting for %s', driver_names)
|
||||||
t1 = time.time()
|
t1 = time.time()
|
||||||
events_count = 0
|
events_count = 0
|
||||||
@ -46,7 +47,7 @@ class DriverExec(object):
|
|||||||
def get_all(self, driver_name, action):
|
def get_all(self, driver_name, action):
|
||||||
try:
|
try:
|
||||||
LOCK_BY_DRIVER.acquire(driver_name)
|
LOCK_BY_DRIVER.acquire(driver_name)
|
||||||
driver = utils.get_drivers_by_name(self.conf, [driver_name])[0]
|
driver = utils.get_drivers_by_name([driver_name])[0]
|
||||||
LOG.info("run driver get_all: %s", driver_name)
|
LOG.info("run driver get_all: %s", driver_name)
|
||||||
events = driver.get_all(action)
|
events = driver.get_all(action)
|
||||||
count = self.process_output_func(events)
|
count = self.process_output_func(events)
|
||||||
@ -65,7 +66,7 @@ class DriverExec(object):
|
|||||||
driver_name)
|
driver_name)
|
||||||
return 0
|
return 0
|
||||||
try:
|
try:
|
||||||
driver = utils.get_drivers_by_name(self.conf, [driver_name])[0]
|
driver = utils.get_drivers_by_name([driver_name])[0]
|
||||||
LOG.info("run driver get_changes: %s", driver_name)
|
LOG.info("run driver get_changes: %s", driver_name)
|
||||||
events = driver.get_changes(DatasourceAction.UPDATE)
|
events = driver.get_changes(DatasourceAction.UPDATE)
|
||||||
count = self.process_output_func(events)
|
count = self.process_output_func(events)
|
||||||
@ -81,23 +82,22 @@ class DriverExec(object):
|
|||||||
|
|
||||||
class DriversNotificationEndpoint(object):
|
class DriversNotificationEndpoint(object):
|
||||||
|
|
||||||
def __init__(self, conf, processor_func):
|
def __init__(self, processor_func):
|
||||||
self._conf = conf
|
|
||||||
self._processor_func = processor_func
|
self._processor_func = processor_func
|
||||||
self._enrich_event_methods = defaultdict(list)
|
self._enrich_event_methods = defaultdict(list)
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
driver_names = utils.get_push_drivers_names(self._conf)
|
driver_names = utils.get_push_drivers_names()
|
||||||
push_drivers = utils.get_drivers_by_name(self._conf, driver_names)
|
push_drivers = utils.get_drivers_by_name(driver_names)
|
||||||
for driver in push_drivers:
|
for driver in push_drivers:
|
||||||
for event in driver.get_event_types():
|
for event in driver.get_event_types():
|
||||||
self._enrich_event_methods[event].append(driver.enrich_event)
|
self._enrich_event_methods[event].append(driver.enrich_event)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def get_listener(self):
|
def get_listener(self):
|
||||||
topics = self._conf.datasources.notification_topics
|
topics = CONF.datasources.notification_topics
|
||||||
exchange = self._conf.datasources.notification_exchange
|
exchange = CONF.datasources.notification_exchange
|
||||||
transport = messaging.get_transport(self._conf)
|
transport = messaging.get_transport()
|
||||||
targets = [oslo_messaging.Target(exchange=exchange, topic=topic)
|
targets = [oslo_messaging.Target(exchange=exchange, topic=topic)
|
||||||
for topic in topics]
|
for topic in topics]
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
import oslo_messaging
|
import oslo_messaging
|
||||||
|
|
||||||
@ -33,24 +34,23 @@ from vitrage.graph.driver.networkx_graph import NXGraph
|
|||||||
from vitrage import messaging
|
from vitrage import messaging
|
||||||
from vitrage import storage
|
from vitrage import storage
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class VitrageGraphInit(object):
|
class VitrageGraphInit(object):
|
||||||
def __init__(self, conf, workers):
|
def __init__(self, workers):
|
||||||
self.conf = conf
|
self.graph = get_graph_driver()('Entity Graph')
|
||||||
self.graph = get_graph_driver(conf)('Entity Graph')
|
self.db = db_connection = storage.get_connection_from_config()
|
||||||
self.db = db_connection = storage.get_connection_from_config(conf)
|
|
||||||
self.workers = workers
|
self.workers = workers
|
||||||
self.events_coordination = EventsCoordination(conf, self.process_event)
|
self.events_coordination = EventsCoordination(self.process_event)
|
||||||
self.persist = GraphPersistency(conf, db_connection, self.graph)
|
self.persist = GraphPersistency(db_connection, self.graph)
|
||||||
self.driver_exec = driver_exec.DriverExec(
|
self.driver_exec = driver_exec.DriverExec(
|
||||||
self.conf,
|
|
||||||
self.events_coordination.handle_multiple_low_priority,
|
self.events_coordination.handle_multiple_low_priority,
|
||||||
self.persist)
|
self.persist)
|
||||||
self.scheduler = Scheduler(conf, self.graph, self.driver_exec,
|
self.scheduler = Scheduler(self.graph, self.driver_exec,
|
||||||
self.persist)
|
self.persist)
|
||||||
self.processor = Processor(conf, self.graph)
|
self.processor = Processor(self.graph)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
LOG.info('Init Started')
|
LOG.info('Init Started')
|
||||||
@ -114,7 +114,7 @@ class VitrageGraphInit(object):
|
|||||||
|
|
||||||
def _add_graph_subscriptions(self):
|
def _add_graph_subscriptions(self):
|
||||||
self.graph.subscribe(self.workers.submit_graph_update)
|
self.graph.subscribe(self.workers.submit_graph_update)
|
||||||
vitrage_notifier = GraphNotifier(self.conf)
|
vitrage_notifier = GraphNotifier()
|
||||||
if vitrage_notifier.enabled:
|
if vitrage_notifier.enabled:
|
||||||
self.graph.subscribe(vitrage_notifier.notify_when_applicable)
|
self.graph.subscribe(vitrage_notifier.notify_when_applicable)
|
||||||
LOG.info('Subscribed vitrage notifier to graph changes')
|
LOG.info('Subscribed vitrage notifier to graph changes')
|
||||||
@ -122,14 +122,13 @@ class VitrageGraphInit(object):
|
|||||||
finalization=True)
|
finalization=True)
|
||||||
|
|
||||||
def subscribe_presist_notifier(self):
|
def subscribe_presist_notifier(self):
|
||||||
self.graph.subscribe(PersistNotifier(self.conf).notify_when_applicable)
|
self.graph.subscribe(PersistNotifier().notify_when_applicable)
|
||||||
|
|
||||||
PRIORITY_DELAY = 0.05
|
PRIORITY_DELAY = 0.05
|
||||||
|
|
||||||
|
|
||||||
class EventsCoordination(object):
|
class EventsCoordination(object):
|
||||||
def __init__(self, conf, do_work_func):
|
def __init__(self, do_work_func):
|
||||||
self._conf = conf
|
|
||||||
self._lock = threading.Lock()
|
self._lock = threading.Lock()
|
||||||
self._high_event_finish_time = 0
|
self._high_event_finish_time = 0
|
||||||
|
|
||||||
@ -146,7 +145,6 @@ class EventsCoordination(object):
|
|||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self._low_pri_listener = driver_exec.DriversNotificationEndpoint(
|
self._low_pri_listener = driver_exec.DriversNotificationEndpoint(
|
||||||
self._conf,
|
|
||||||
self.handle_multiple_low_priority).init().get_listener()
|
self.handle_multiple_low_priority).init().get_listener()
|
||||||
self._high_pri_listener = self._init_listener(
|
self._high_pri_listener = self._init_listener(
|
||||||
EVALUATOR_TOPIC,
|
EVALUATOR_TOPIC,
|
||||||
@ -191,7 +189,7 @@ class EventsCoordination(object):
|
|||||||
if not topic:
|
if not topic:
|
||||||
return
|
return
|
||||||
return messaging.get_notification_listener(
|
return messaging.get_notification_listener(
|
||||||
transport=messaging.get_transport(self._conf),
|
transport=messaging.get_transport(),
|
||||||
targets=[oslo_messaging.Target(topic=topic)],
|
targets=[oslo_messaging.Target(topic=topic)],
|
||||||
endpoints=[PushNotificationsEndpoint(callback)])
|
endpoints=[PushNotificationsEndpoint(callback)])
|
||||||
|
|
||||||
|
@ -24,8 +24,7 @@ LOG = log.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class GraphPersistency(object):
|
class GraphPersistency(object):
|
||||||
def __init__(self, conf, db, graph):
|
def __init__(self, db, graph):
|
||||||
self.conf = conf
|
|
||||||
self.db = db
|
self.db = db
|
||||||
self.graph = graph
|
self.graph = graph
|
||||||
self.events_buffer = []
|
self.events_buffer = []
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
|
||||||
from vitrage.common.constants import EntityCategory
|
from vitrage.common.constants import EntityCategory
|
||||||
@ -23,6 +24,7 @@ from vitrage.entity_graph.mappings.resource_handler import \
|
|||||||
ResourceHandler
|
ResourceHandler
|
||||||
from vitrage.utils import file as file_utils
|
from vitrage.utils import file as file_utils
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -34,8 +36,7 @@ class DatasourceInfoMapper(object):
|
|||||||
PRIORITY_VALUES = 'priority_values'
|
PRIORITY_VALUES = 'priority_values'
|
||||||
UNDEFINED_DATASOURCE = 'undefined datasource'
|
UNDEFINED_DATASOURCE = 'undefined datasource'
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
self.conf = conf
|
|
||||||
self.category_normalizer = self._init_category_normalizer()
|
self.category_normalizer = self._init_category_normalizer()
|
||||||
self.datasources_value_confs = self._load_value_configurations()
|
self.datasources_value_confs = self._load_value_configurations()
|
||||||
|
|
||||||
@ -62,7 +63,7 @@ class DatasourceInfoMapper(object):
|
|||||||
graph_vertex[VProps.VITRAGE_CATEGORY]
|
graph_vertex[VProps.VITRAGE_CATEGORY]
|
||||||
|
|
||||||
if vitrage_type in self.datasources_value_confs or \
|
if vitrage_type in self.datasources_value_confs or \
|
||||||
vitrage_type not in self.conf.datasources.types:
|
vitrage_type not in CONF.datasources.types:
|
||||||
value_properties = \
|
value_properties = \
|
||||||
self.category_normalizer[vitrage_category].value_properties()
|
self.category_normalizer[vitrage_category].value_properties()
|
||||||
vitrage_operational_value, vitrage_aggregated_value, value_priority = \
|
vitrage_operational_value, vitrage_aggregated_value, value_priority = \
|
||||||
@ -115,11 +116,11 @@ class DatasourceInfoMapper(object):
|
|||||||
erroneous_datasources_conf = []
|
erroneous_datasources_conf = []
|
||||||
|
|
||||||
files = file_utils.list_files(
|
files = file_utils.list_files(
|
||||||
self.conf.entity_graph.datasources_values_dir, '.yaml')
|
CONF.entity_graph.datasources_values_dir, '.yaml')
|
||||||
|
|
||||||
for file_name in files:
|
for file_name in files:
|
||||||
try:
|
try:
|
||||||
full_path = self.conf.entity_graph.datasources_values_dir \
|
full_path = CONF.entity_graph.datasources_values_dir \
|
||||||
+ '/' + file_name
|
+ '/' + file_name
|
||||||
operational_values, priority_values = \
|
operational_values, priority_values = \
|
||||||
self._retrieve_values_and_priorities_from_file(full_path)
|
self._retrieve_values_and_priorities_from_file(full_path)
|
||||||
@ -227,7 +228,7 @@ class DatasourceInfoMapper(object):
|
|||||||
ok_datasources,
|
ok_datasources,
|
||||||
error_datasources):
|
error_datasources):
|
||||||
|
|
||||||
datasource_types = self.conf.datasources.types
|
datasource_types = CONF.datasources.types
|
||||||
datasources_with_state_conf = ok_datasources + error_datasources
|
datasources_with_state_conf = ok_datasources + error_datasources
|
||||||
|
|
||||||
for datasource_type in datasource_types:
|
for datasource_type in datasource_types:
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
import oslo_messaging
|
import oslo_messaging
|
||||||
|
|
||||||
@ -24,19 +25,21 @@ from vitrage.graph.driver.networkx_graph import edge_copy
|
|||||||
from vitrage.graph.driver.networkx_graph import vertex_copy
|
from vitrage.graph.driver.networkx_graph import vertex_copy
|
||||||
from vitrage.messaging import get_transport
|
from vitrage.messaging import get_transport
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
|
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class GraphNotifier(object):
|
class GraphNotifier(object):
|
||||||
"""Allows writing to message bus"""
|
"""Allows writing to message bus"""
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
self.oslo_notifier = None
|
self.oslo_notifier = None
|
||||||
topics = self._get_topics(conf)
|
topics = self._get_topics()
|
||||||
if not topics:
|
if not topics:
|
||||||
LOG.info('Graph Notifier is disabled')
|
LOG.info('Graph Notifier is disabled')
|
||||||
return
|
return
|
||||||
self.oslo_notifier = oslo_messaging.Notifier(
|
self.oslo_notifier = oslo_messaging.Notifier(
|
||||||
get_transport(conf),
|
get_transport(),
|
||||||
driver='messagingv2',
|
driver='messagingv2',
|
||||||
publisher_id='vitrage.graph',
|
publisher_id='vitrage.graph',
|
||||||
topics=topics)
|
topics=topics)
|
||||||
@ -45,12 +48,12 @@ class GraphNotifier(object):
|
|||||||
def enabled(self):
|
def enabled(self):
|
||||||
return self.oslo_notifier is not None
|
return self.oslo_notifier is not None
|
||||||
|
|
||||||
def _get_topics(self, conf):
|
def _get_topics(self):
|
||||||
topics = []
|
topics = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
notifier_topic = conf.entity_graph.notifier_topic
|
notifier_topic = CONF.entity_graph.notifier_topic
|
||||||
notifier_plugins = conf.notifiers
|
notifier_plugins = CONF.notifiers
|
||||||
if notifier_topic and notifier_plugins:
|
if notifier_topic and notifier_plugins:
|
||||||
topics.append(notifier_topic)
|
topics.append(notifier_topic)
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -58,8 +61,8 @@ class GraphNotifier(object):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
machine_learning_topic = \
|
machine_learning_topic = \
|
||||||
conf.machine_learning.machine_learning_topic
|
CONF.machine_learning.machine_learning_topic
|
||||||
machine_learning_plugins = conf.machine_learning.plugins
|
machine_learning_plugins = CONF.machine_learning.plugins
|
||||||
if machine_learning_topic and machine_learning_plugins:
|
if machine_learning_topic and machine_learning_plugins:
|
||||||
topics.append(machine_learning_topic)
|
topics.append(machine_learning_topic)
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -117,11 +120,11 @@ class GraphNotifier(object):
|
|||||||
|
|
||||||
class PersistNotifier(object):
|
class PersistNotifier(object):
|
||||||
"""Allows writing to message bus"""
|
"""Allows writing to message bus"""
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
self.oslo_notifier = None
|
self.oslo_notifier = None
|
||||||
topics = [conf.persistency.persistor_topic]
|
topics = [CONF.persistency.persistor_topic]
|
||||||
self.oslo_notifier = oslo_messaging.Notifier(
|
self.oslo_notifier = oslo_messaging.Notifier(
|
||||||
get_transport(conf),
|
get_transport(),
|
||||||
driver='messagingv2',
|
driver='messagingv2',
|
||||||
publisher_id='vitrage.graph',
|
publisher_id='vitrage.graph',
|
||||||
topics=topics)
|
topics=topics)
|
||||||
|
@ -31,11 +31,10 @@ LOG = log.getLogger(__name__)
|
|||||||
|
|
||||||
class Processor(processor.ProcessorBase):
|
class Processor(processor.ProcessorBase):
|
||||||
|
|
||||||
def __init__(self, conf, e_graph=None):
|
def __init__(self, e_graph=None):
|
||||||
super(Processor, self).__init__()
|
super(Processor, self).__init__()
|
||||||
self.conf = conf
|
self.transformer_manager = TransformerManager()
|
||||||
self.transformer_manager = TransformerManager(self.conf)
|
self.info_mapper = DatasourceInfoMapper()
|
||||||
self.info_mapper = DatasourceInfoMapper(self.conf)
|
|
||||||
self._initialize_events_actions()
|
self._initialize_events_actions()
|
||||||
self.entity_graph = e_graph
|
self.entity_graph = e_graph
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_utils import importutils
|
from oslo_utils import importutils
|
||||||
|
|
||||||
@ -26,29 +27,30 @@ from vitrage.evaluator.actions.evaluator_event_transformer \
|
|||||||
import VITRAGE_DATASOURCE
|
import VITRAGE_DATASOURCE
|
||||||
from vitrage.utils import opt_exists
|
from vitrage.utils import opt_exists
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
ENTITIES = 'entities'
|
ENTITIES = 'entities'
|
||||||
|
|
||||||
|
|
||||||
class TransformerManager(object):
|
class TransformerManager(object):
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
self.transformers = self.register_transformer_classes(conf)
|
self.transformers = self.register_transformer_classes()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def register_transformer_classes(conf):
|
def register_transformer_classes():
|
||||||
|
|
||||||
transformers = {}
|
transformers = {}
|
||||||
for datasource_type in conf.datasources.types:
|
for datasource_type in CONF.datasources.types:
|
||||||
try:
|
try:
|
||||||
transformers[datasource_type] = importutils.import_object(
|
transformers[datasource_type] = importutils.import_object(
|
||||||
conf[datasource_type].transformer,
|
CONF[datasource_type].transformer,
|
||||||
transformers, conf)
|
transformers)
|
||||||
if opt_exists(conf[datasource_type], ENTITIES):
|
if opt_exists(CONF[datasource_type], ENTITIES):
|
||||||
for entity in conf[datasource_type].entities:
|
for entity in CONF[datasource_type].entities:
|
||||||
transformers[entity] = importutils.import_object(
|
transformers[entity] = importutils.import_object(
|
||||||
conf[datasource_type].transformer,
|
CONF[datasource_type].transformer,
|
||||||
transformers, conf)
|
transformers)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
LOG.exception('Failed to register transformer %s.',
|
LOG.exception('Failed to register transformer %s.',
|
||||||
@ -56,11 +58,11 @@ class TransformerManager(object):
|
|||||||
|
|
||||||
transformers[VITRAGE_DATASOURCE] = importutils.import_object(
|
transformers[VITRAGE_DATASOURCE] = importutils.import_object(
|
||||||
"%s.%s" % (EvaluatorEventTransformer.__module__,
|
"%s.%s" % (EvaluatorEventTransformer.__module__,
|
||||||
EvaluatorEventTransformer.__name__), transformers, conf)
|
EvaluatorEventTransformer.__name__), transformers)
|
||||||
|
|
||||||
transformers[CONSISTENCY_DATASOURCE] = importutils.import_object(
|
transformers[CONSISTENCY_DATASOURCE] = importutils.import_object(
|
||||||
"%s.%s" % (ConsistencyTransformer.__module__,
|
"%s.%s" % (ConsistencyTransformer.__module__,
|
||||||
ConsistencyTransformer.__name__), transformers, conf)
|
ConsistencyTransformer.__name__), transformers)
|
||||||
|
|
||||||
return transformers
|
return transformers
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from futurist import periodics
|
from futurist import periodics
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
from vitrage.datasources import utils
|
from vitrage.datasources import utils
|
||||||
|
|
||||||
@ -23,22 +24,22 @@ from vitrage.common.utils import spawn
|
|||||||
from vitrage.entity_graph.consistency.consistency_enforcer import\
|
from vitrage.entity_graph.consistency.consistency_enforcer import\
|
||||||
ConsistencyEnforcer
|
ConsistencyEnforcer
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Scheduler(object):
|
class Scheduler(object):
|
||||||
|
|
||||||
def __init__(self, conf, graph, driver_exec, persist):
|
def __init__(self, graph, driver_exec, persist):
|
||||||
super(Scheduler, self).__init__()
|
super(Scheduler, self).__init__()
|
||||||
self.conf = conf
|
|
||||||
self.graph = graph
|
self.graph = graph
|
||||||
self.driver_exec = driver_exec
|
self.driver_exec = driver_exec
|
||||||
self.persist = persist
|
self.persist = persist
|
||||||
self.consistency = ConsistencyEnforcer(conf, graph)
|
self.consistency = ConsistencyEnforcer(graph)
|
||||||
self.periodic = None
|
self.periodic = None
|
||||||
|
|
||||||
def start_periodic_tasks(self, immediate_get_all):
|
def start_periodic_tasks(self, immediate_get_all):
|
||||||
thread_num = len(utils.get_pull_drivers_names(self.conf))
|
thread_num = len(utils.get_pull_drivers_names())
|
||||||
thread_num += 2 # for consistency and get_all
|
thread_num += 2 # for consistency and get_all
|
||||||
self.periodic = periodics.PeriodicWorker.create(
|
self.periodic = periodics.PeriodicWorker.create(
|
||||||
[], executor_factory=lambda: ThreadPoolExecutor(
|
[], executor_factory=lambda: ThreadPoolExecutor(
|
||||||
@ -49,7 +50,7 @@ class Scheduler(object):
|
|||||||
spawn(self.periodic.start)
|
spawn(self.periodic.start)
|
||||||
|
|
||||||
def _add_consistency_timer(self):
|
def _add_consistency_timer(self):
|
||||||
spacing = self.conf.datasources.snapshots_interval
|
spacing = CONF.datasources.snapshots_interval
|
||||||
|
|
||||||
@periodics.periodic(spacing=spacing)
|
@periodics.periodic(spacing=spacing)
|
||||||
def consistency_periodic():
|
def consistency_periodic():
|
||||||
@ -62,7 +63,7 @@ class Scheduler(object):
|
|||||||
LOG.info("added consistency_periodic (spacing=%s)", spacing)
|
LOG.info("added consistency_periodic (spacing=%s)", spacing)
|
||||||
|
|
||||||
def _add_datasource_timers(self, run_immediately):
|
def _add_datasource_timers(self, run_immediately):
|
||||||
spacing = self.conf.datasources.snapshots_interval
|
spacing = CONF.datasources.snapshots_interval
|
||||||
|
|
||||||
@periodics.periodic(spacing=spacing, run_immediately=run_immediately)
|
@periodics.periodic(spacing=spacing, run_immediately=run_immediately)
|
||||||
def get_all_periodic():
|
def get_all_periodic():
|
||||||
@ -71,9 +72,9 @@ class Scheduler(object):
|
|||||||
self.periodic.add(get_all_periodic)
|
self.periodic.add(get_all_periodic)
|
||||||
LOG.info("added get_all_periodic (spacing=%s)", spacing)
|
LOG.info("added get_all_periodic (spacing=%s)", spacing)
|
||||||
|
|
||||||
driver_names = utils.get_pull_drivers_names(self.conf)
|
driver_names = utils.get_pull_drivers_names()
|
||||||
for d_name in driver_names:
|
for d_name in driver_names:
|
||||||
spacing = self.conf[d_name].changes_interval
|
spacing = CONF[d_name].changes_interval
|
||||||
|
|
||||||
@periodics.periodic(spacing=spacing)
|
@periodics.periodic(spacing=spacing)
|
||||||
def get_changes_periodic(driver_name=d_name):
|
def get_changes_periodic(driver_name=d_name):
|
||||||
|
@ -18,6 +18,7 @@ import cotyledon
|
|||||||
import multiprocessing
|
import multiprocessing
|
||||||
import multiprocessing.queues
|
import multiprocessing.queues
|
||||||
import os
|
import os
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
import oslo_messaging
|
import oslo_messaging
|
||||||
from oslo_utils import uuidutils
|
from oslo_utils import uuidutils
|
||||||
@ -45,6 +46,7 @@ from vitrage import messaging
|
|||||||
from vitrage import rpc as vitrage_rpc
|
from vitrage import rpc as vitrage_rpc
|
||||||
from vitrage import storage
|
from vitrage import storage
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = None
|
LOG = None
|
||||||
|
|
||||||
# Supported message types
|
# Supported message types
|
||||||
@ -67,9 +69,8 @@ class GraphWorkersManager(cotyledon.ServiceManager):
|
|||||||
- the queues used to communicate with these workers
|
- the queues used to communicate with these workers
|
||||||
- methods interface to submit tasks to workers
|
- methods interface to submit tasks to workers
|
||||||
"""
|
"""
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(GraphWorkersManager, self).__init__()
|
super(GraphWorkersManager, self).__init__()
|
||||||
self._conf = conf
|
|
||||||
self._db = None
|
self._db = None
|
||||||
self._evaluator_queues = []
|
self._evaluator_queues = []
|
||||||
self._template_queues = []
|
self._template_queues = []
|
||||||
@ -93,10 +94,10 @@ class GraphWorkersManager(cotyledon.ServiceManager):
|
|||||||
"""
|
"""
|
||||||
if self._evaluator_queues:
|
if self._evaluator_queues:
|
||||||
raise VitrageError('add_evaluator_workers called more than once')
|
raise VitrageError('add_evaluator_workers called more than once')
|
||||||
workers = self._conf.evaluator.workers
|
workers = CONF.evaluator.workers
|
||||||
queues = [multiprocessing.JoinableQueue() for i in range(workers)]
|
queues = [multiprocessing.JoinableQueue() for i in range(workers)]
|
||||||
self.add(EvaluatorWorker,
|
self.add(EvaluatorWorker,
|
||||||
args=(self._conf, queues, workers),
|
args=(queues, workers),
|
||||||
workers=workers)
|
workers=workers)
|
||||||
self._evaluator_queues = queues
|
self._evaluator_queues = queues
|
||||||
self._all_queues.extend(queues)
|
self._all_queues.extend(queues)
|
||||||
@ -111,9 +112,9 @@ class GraphWorkersManager(cotyledon.ServiceManager):
|
|||||||
"""
|
"""
|
||||||
if self._api_queues:
|
if self._api_queues:
|
||||||
raise VitrageError('add_api_workers called more than once')
|
raise VitrageError('add_api_workers called more than once')
|
||||||
workers = self._conf.api.workers
|
workers = CONF.api.workers
|
||||||
queues = [multiprocessing.Queue() for i in range(workers)]
|
queues = [multiprocessing.Queue() for i in range(workers)]
|
||||||
self.add(ApiWorker, args=(self._conf, queues), workers=workers)
|
self.add(ApiWorker, args=(queues,), workers=workers)
|
||||||
self._api_queues = queues
|
self._api_queues = queues
|
||||||
self._all_queues.extend(queues)
|
self._all_queues.extend(queues)
|
||||||
|
|
||||||
@ -177,7 +178,7 @@ class GraphWorkersManager(cotyledon.ServiceManager):
|
|||||||
template_action = event.get(TEMPLATE_ACTION)
|
template_action = event.get(TEMPLATE_ACTION)
|
||||||
|
|
||||||
if not self._db:
|
if not self._db:
|
||||||
self._db = storage.get_connection_from_config(self._conf)
|
self._db = storage.get_connection_from_config()
|
||||||
|
|
||||||
if template_action == ADD:
|
if template_action == ADD:
|
||||||
templates = self._db.templates.query(status=TStatus.LOADING)
|
templates = self._db.templates.query(status=TStatus.LOADING)
|
||||||
@ -219,10 +220,8 @@ class GraphWorkersManager(cotyledon.ServiceManager):
|
|||||||
class GraphCloneWorkerBase(coord.Service):
|
class GraphCloneWorkerBase(coord.Service):
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
worker_id,
|
worker_id,
|
||||||
conf,
|
|
||||||
task_queues):
|
task_queues):
|
||||||
super(GraphCloneWorkerBase, self).__init__(worker_id, conf)
|
super(GraphCloneWorkerBase, self).__init__(worker_id)
|
||||||
self._conf = conf
|
|
||||||
self._task_queue = task_queues[worker_id]
|
self._task_queue = task_queues[worker_id]
|
||||||
self._entity_graph = NXGraph()
|
self._entity_graph = NXGraph()
|
||||||
|
|
||||||
@ -285,7 +284,7 @@ class GraphCloneWorkerBase(coord.Service):
|
|||||||
self._entity_graph.remove_edge(before)
|
self._entity_graph.remove_edge(before)
|
||||||
|
|
||||||
def _read_db_graph(self):
|
def _read_db_graph(self):
|
||||||
db = storage.get_connection_from_config(self._conf)
|
db = storage.get_connection_from_config()
|
||||||
graph_snapshot = db.graph_snapshots.query()
|
graph_snapshot = db.graph_snapshots.query()
|
||||||
NXGraph.read_gpickle(graph_snapshot.graph_snapshot, self._entity_graph)
|
NXGraph.read_gpickle(graph_snapshot.graph_snapshot, self._entity_graph)
|
||||||
GraphPersistency.do_replay_events(db, self._entity_graph,
|
GraphPersistency.do_replay_events(db, self._entity_graph,
|
||||||
@ -296,25 +295,22 @@ class GraphCloneWorkerBase(coord.Service):
|
|||||||
class EvaluatorWorker(GraphCloneWorkerBase):
|
class EvaluatorWorker(GraphCloneWorkerBase):
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
worker_id,
|
worker_id,
|
||||||
conf,
|
|
||||||
task_queues,
|
task_queues,
|
||||||
workers_num):
|
workers_num):
|
||||||
super(EvaluatorWorker, self).__init__(
|
super(EvaluatorWorker, self).__init__(
|
||||||
worker_id, conf, task_queues)
|
worker_id, task_queues)
|
||||||
self._workers_num = workers_num
|
self._workers_num = workers_num
|
||||||
self._evaluator = None
|
self._evaluator = None
|
||||||
|
|
||||||
name = 'EvaluatorWorker'
|
name = 'EvaluatorWorker'
|
||||||
|
|
||||||
def _init_instance(self):
|
def _init_instance(self):
|
||||||
scenario_repo = ScenarioRepository(self._conf, self.worker_id,
|
scenario_repo = ScenarioRepository(self.worker_id,
|
||||||
self._workers_num)
|
self._workers_num)
|
||||||
actions_callback = messaging.VitrageNotifier(
|
actions_callback = messaging.VitrageNotifier(
|
||||||
conf=self._conf,
|
|
||||||
publisher_id='vitrage_evaluator',
|
publisher_id='vitrage_evaluator',
|
||||||
topics=[EVALUATOR_TOPIC]).notify
|
topics=[EVALUATOR_TOPIC]).notify
|
||||||
self._evaluator = ScenarioEvaluator(
|
self._evaluator = ScenarioEvaluator(
|
||||||
self._conf,
|
|
||||||
self._entity_graph,
|
self._entity_graph,
|
||||||
scenario_repo,
|
scenario_repo,
|
||||||
actions_callback,
|
actions_callback,
|
||||||
@ -338,7 +334,7 @@ class EvaluatorWorker(GraphCloneWorkerBase):
|
|||||||
|
|
||||||
def _reload_templates(self):
|
def _reload_templates(self):
|
||||||
LOG.info("reloading evaluator scenarios")
|
LOG.info("reloading evaluator scenarios")
|
||||||
scenario_repo = ScenarioRepository(self._conf, self.worker_id,
|
scenario_repo = ScenarioRepository(self.worker_id,
|
||||||
self._workers_num)
|
self._workers_num)
|
||||||
self._evaluator.scenario_repo = scenario_repo
|
self._evaluator.scenario_repo = scenario_repo
|
||||||
self._evaluator.scenario_repo.log_enabled_scenarios()
|
self._evaluator.scenario_repo.log_enabled_scenarios()
|
||||||
@ -347,7 +343,7 @@ class EvaluatorWorker(GraphCloneWorkerBase):
|
|||||||
# Here, we create a temporary ScenarioRepo to execute the needed
|
# Here, we create a temporary ScenarioRepo to execute the needed
|
||||||
# templates. Once _reload_templates is called, it will create a
|
# templates. Once _reload_templates is called, it will create a
|
||||||
# non temporary ScenarioRepo, to replace this one
|
# non temporary ScenarioRepo, to replace this one
|
||||||
scenario_repo = ScenarioRepository(self._conf)
|
scenario_repo = ScenarioRepository()
|
||||||
for s in scenario_repo._all_scenarios:
|
for s in scenario_repo._all_scenarios:
|
||||||
s.enabled = False
|
s.enabled = False
|
||||||
for template_name in template_names:
|
for template_name in template_names:
|
||||||
@ -363,24 +359,23 @@ class ApiWorker(GraphCloneWorkerBase):
|
|||||||
name = 'ApiWorker'
|
name = 'ApiWorker'
|
||||||
|
|
||||||
def _init_instance(self):
|
def _init_instance(self):
|
||||||
conf = self._conf
|
notifier = messaging.VitrageNotifier("vitrage.api",
|
||||||
notifier = messaging.VitrageNotifier(conf, "vitrage.api",
|
|
||||||
[EVALUATOR_TOPIC])
|
[EVALUATOR_TOPIC])
|
||||||
db = storage.get_connection_from_config(conf)
|
db = storage.get_connection_from_config()
|
||||||
transport = messaging.get_rpc_transport(conf)
|
transport = messaging.get_rpc_transport()
|
||||||
target = oslo_messaging.Target(topic=conf.rpc_topic,
|
target = oslo_messaging.Target(topic=CONF.rpc_topic,
|
||||||
server=uuidutils.generate_uuid())
|
server=uuidutils.generate_uuid())
|
||||||
self.api_lock = threading.RLock()
|
self.api_lock = threading.RLock()
|
||||||
|
|
||||||
endpoints = [
|
endpoints = [
|
||||||
TopologyApis(self._entity_graph, conf, self.api_lock),
|
TopologyApis(self._entity_graph, self.api_lock),
|
||||||
AlarmApis(self._entity_graph, conf, self.api_lock, db),
|
AlarmApis(self._entity_graph, self.api_lock, db),
|
||||||
RcaApis(self._entity_graph, conf, self.api_lock, db),
|
RcaApis(self._entity_graph, self.api_lock, db),
|
||||||
ResourceApis(self._entity_graph, conf, self.api_lock),
|
ResourceApis(self._entity_graph, self.api_lock),
|
||||||
TemplateApis(notifier, db),
|
TemplateApis(notifier, db),
|
||||||
EventApis(conf),
|
EventApis(),
|
||||||
WebhookApis(conf, db),
|
WebhookApis(db),
|
||||||
OperationalApis(conf, self._entity_graph),
|
OperationalApis(self._entity_graph),
|
||||||
]
|
]
|
||||||
|
|
||||||
server = vitrage_rpc.get_server(target, endpoints, transport)
|
server = vitrage_rpc.get_server(target, endpoints, transport)
|
||||||
|
@ -51,10 +51,10 @@ SOURCE = 'source'
|
|||||||
|
|
||||||
class ActionExecutor(object):
|
class ActionExecutor(object):
|
||||||
|
|
||||||
def __init__(self, conf, actions_callback):
|
def __init__(self, actions_callback):
|
||||||
|
|
||||||
self.actions_callback = actions_callback
|
self.actions_callback = actions_callback
|
||||||
self.notifier = EvaluatorNotifier(conf)
|
self.notifier = EvaluatorNotifier()
|
||||||
self.action_recipes = ActionExecutor._register_action_recipes()
|
self.action_recipes = ActionExecutor._register_action_recipes()
|
||||||
|
|
||||||
self.action_step_defs = {
|
self.action_step_defs = {
|
||||||
|
@ -42,8 +42,8 @@ VITRAGE_DATASOURCE = 'vitrage'
|
|||||||
|
|
||||||
class EvaluatorEventTransformer(transformer_base.TransformerBase):
|
class EvaluatorEventTransformer(transformer_base.TransformerBase):
|
||||||
|
|
||||||
def __init__(self, transformers, conf):
|
def __init__(self, transformers):
|
||||||
super(EvaluatorEventTransformer, self).__init__(transformers, conf)
|
super(EvaluatorEventTransformer, self).__init__(transformers)
|
||||||
self.actions = self._init_actions()
|
self.actions = self._init_actions()
|
||||||
|
|
||||||
def _create_snapshot_entity_vertex(self, entity_event):
|
def _create_snapshot_entity_vertex(self, entity_event):
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
import oslo_messaging
|
import oslo_messaging
|
||||||
|
|
||||||
@ -18,15 +20,16 @@ from vitrage.common.constants import NotifierEventTypes
|
|||||||
from vitrage.messaging import get_transport
|
from vitrage.messaging import get_transport
|
||||||
|
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class EvaluatorNotifier(object):
|
class EvaluatorNotifier(object):
|
||||||
"""Allows writing to message bus"""
|
"""Allows writing to message bus"""
|
||||||
def __init__(self, conf):
|
def __init__(self, ):
|
||||||
self.oslo_notifiers = {}
|
self.oslo_notifiers = {}
|
||||||
try:
|
try:
|
||||||
notifier_plugins = conf.notifiers
|
notifier_plugins = CONF.notifiers
|
||||||
|
|
||||||
LOG.debug('notifier_plugins: %s', notifier_plugins)
|
LOG.debug('notifier_plugins: %s', notifier_plugins)
|
||||||
|
|
||||||
@ -35,13 +38,13 @@ class EvaluatorNotifier(object):
|
|||||||
return
|
return
|
||||||
|
|
||||||
topic_prefix = \
|
topic_prefix = \
|
||||||
conf.evaluator_actions.evaluator_notification_topic_prefix
|
CONF.evaluator_actions.evaluator_notification_topic_prefix
|
||||||
|
|
||||||
for notifier in notifier_plugins:
|
for notifier in notifier_plugins:
|
||||||
LOG.debug('Adding evaluator notifier %s', notifier)
|
LOG.debug('Adding evaluator notifier %s', notifier)
|
||||||
|
|
||||||
self.oslo_notifiers[notifier] = oslo_messaging.Notifier(
|
self.oslo_notifiers[notifier] = oslo_messaging.Notifier(
|
||||||
get_transport(conf),
|
get_transport(),
|
||||||
driver='messagingv2',
|
driver='messagingv2',
|
||||||
publisher_id='vitrage.evaluator',
|
publisher_id='vitrage.evaluator',
|
||||||
topics=[topic_prefix + '.' + notifier])
|
topics=[topic_prefix + '.' + notifier])
|
||||||
|
@ -18,6 +18,7 @@ import copy
|
|||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
|
||||||
from vitrage.common.constants import EdgeProperties as EProps
|
from vitrage.common.constants import EdgeProperties as EProps
|
||||||
@ -42,6 +43,7 @@ from vitrage import storage
|
|||||||
from vitrage.storage.sqlalchemy import models
|
from vitrage.storage.sqlalchemy import models
|
||||||
from vitrage.utils.datetime import utcnow
|
from vitrage.utils.datetime import utcnow
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
# Entry containing action info.
|
# Entry containing action info.
|
||||||
@ -60,16 +62,14 @@ SOURCE = 'source'
|
|||||||
class ScenarioEvaluator(object):
|
class ScenarioEvaluator(object):
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
conf,
|
|
||||||
e_graph,
|
e_graph,
|
||||||
scenario_repo,
|
scenario_repo,
|
||||||
actions_callback,
|
actions_callback,
|
||||||
enabled=False):
|
enabled=False):
|
||||||
self._conf = conf
|
|
||||||
self._entity_graph = e_graph
|
self._entity_graph = e_graph
|
||||||
self._db = storage.get_connection_from_config(self._conf)
|
self._db = storage.get_connection_from_config()
|
||||||
self._scenario_repo = scenario_repo
|
self._scenario_repo = scenario_repo
|
||||||
self._action_executor = ActionExecutor(self._conf, actions_callback)
|
self._action_executor = ActionExecutor(actions_callback)
|
||||||
self._entity_graph.subscribe(self.process_event)
|
self._entity_graph.subscribe(self.process_event)
|
||||||
self.enabled = enabled
|
self.enabled = enabled
|
||||||
self.connected_component_cache = defaultdict(dict)
|
self.connected_component_cache = defaultdict(dict)
|
||||||
@ -314,7 +314,7 @@ class ScenarioEvaluator(object):
|
|||||||
if not actions:
|
if not actions:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
active_actions = ActiveActionsTracker(self._conf, self._db, actions)
|
active_actions = ActiveActionsTracker(self._db, actions)
|
||||||
for action_info in actions:
|
for action_info in actions:
|
||||||
if action_info.mode == ActionMode.DO:
|
if action_info.mode == ActionMode.DO:
|
||||||
active_actions.calc_do_action(action_info)
|
active_actions.calc_do_action(action_info)
|
||||||
@ -483,13 +483,13 @@ class ActiveActionsTracker(object):
|
|||||||
"""
|
"""
|
||||||
action_tools = None
|
action_tools = None
|
||||||
|
|
||||||
def __init__(self, conf, db, actions):
|
def __init__(self, db, actions):
|
||||||
self.db = db
|
self.db = db
|
||||||
self.data = defaultdict(set)
|
self.data = defaultdict(set)
|
||||||
self.actions_to_create = {}
|
self.actions_to_create = {}
|
||||||
self.actions_to_remove = set()
|
self.actions_to_remove = set()
|
||||||
self.actions_to_perform = [] # use a list to keep the insertion order
|
self.actions_to_perform = [] # use a list to keep the insertion order
|
||||||
self._init_action_tools(conf)
|
self._init_action_tools()
|
||||||
|
|
||||||
# Query DB for all actions with same properties
|
# Query DB for all actions with same properties
|
||||||
actions_keys = set([self._get_key(action) for action in actions])
|
actions_keys = set([self._get_key(action) for action in actions])
|
||||||
@ -499,10 +499,10 @@ class ActiveActionsTracker(object):
|
|||||||
db_row.extra_info, db_row.action_type)].add(db_row)
|
db_row.extra_info, db_row.action_type)].add(db_row)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _init_action_tools(cls, conf):
|
def _init_action_tools(cls):
|
||||||
if cls.action_tools:
|
if cls.action_tools:
|
||||||
return
|
return
|
||||||
info_mapper = DatasourceInfoMapper(conf)
|
info_mapper = DatasourceInfoMapper()
|
||||||
alarms_score = info_mapper.get_datasource_priorities('vitrage')
|
alarms_score = info_mapper.get_datasource_priorities('vitrage')
|
||||||
all_scores = info_mapper.get_datasource_priorities()
|
all_scores = info_mapper.get_datasource_priorities()
|
||||||
cls.action_tools = {
|
cls.action_tools = {
|
||||||
|
@ -35,7 +35,7 @@ DEF_TEMPLATES_DIR_OPT = 'def_templates_dir'
|
|||||||
|
|
||||||
|
|
||||||
class ScenarioRepository(object):
|
class ScenarioRepository(object):
|
||||||
def __init__(self, conf, worker_index=None, workers_num=None):
|
def __init__(self, worker_index=None, workers_num=None):
|
||||||
"""Create an instance of ScenarioRepository
|
"""Create an instance of ScenarioRepository
|
||||||
|
|
||||||
:param conf:
|
:param conf:
|
||||||
@ -45,7 +45,7 @@ class ScenarioRepository(object):
|
|||||||
self._templates = {}
|
self._templates = {}
|
||||||
self._def_templates = {}
|
self._def_templates = {}
|
||||||
self._all_scenarios = []
|
self._all_scenarios = []
|
||||||
self._db = storage.get_connection_from_config(conf)
|
self._db = storage.get_connection_from_config()
|
||||||
self.entity_equivalences = EquivalenceRepository().load(self._db)
|
self.entity_equivalences = EquivalenceRepository().load(self._db)
|
||||||
self.relationship_scenarios = defaultdict(list)
|
self.relationship_scenarios = defaultdict(list)
|
||||||
self.entity_scenarios = defaultdict(list)
|
self.entity_scenarios = defaultdict(list)
|
||||||
|
@ -24,22 +24,23 @@ from keystoneclient.v3 import client as ks_client_v3
|
|||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
CFG_GROUP = "service_credentials"
|
CFG_GROUP = "service_credentials"
|
||||||
|
|
||||||
|
|
||||||
def get_session(conf):
|
def get_session():
|
||||||
"""Get a vitrage service credentials auth session."""
|
"""Get a vitrage service credentials auth session."""
|
||||||
auth_plugin = ka_loading.load_auth_from_conf_options(conf, CFG_GROUP)
|
auth_plugin = ka_loading.load_auth_from_conf_options(CONF, CFG_GROUP)
|
||||||
return ka_loading.load_session_from_conf_options(
|
return ka_loading.load_session_from_conf_options(
|
||||||
conf, CFG_GROUP, auth=auth_plugin
|
CONF, CFG_GROUP, auth=auth_plugin
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_client(conf):
|
def get_client():
|
||||||
"""Return a client for keystone v3 endpoint."""
|
"""Return a client for keystone v3 endpoint."""
|
||||||
sess = get_session(conf)
|
sess = get_session()
|
||||||
return ks_client_v3.Client(session=sess)
|
return ks_client_v3.Client(session=sess)
|
||||||
|
|
||||||
|
|
||||||
@ -57,10 +58,10 @@ def get_client_on_behalf_user(auth_plugin):
|
|||||||
return ks_client_v3.Client(session=sess)
|
return ks_client_v3.Client(session=sess)
|
||||||
|
|
||||||
|
|
||||||
def create_trust_id(conf, trustor_user_id, trustor_project_id, roles,
|
def create_trust_id(trustor_user_id, trustor_project_id, roles,
|
||||||
auth_plugin):
|
auth_plugin):
|
||||||
"""Create a new trust using the vitrage service user."""
|
"""Create a new trust using the vitrage service user."""
|
||||||
admin_client = get_client(conf)
|
admin_client = get_client()
|
||||||
trustee_user_id = admin_client.session.get_user_id()
|
trustee_user_id = admin_client.session.get_user_id()
|
||||||
|
|
||||||
client = get_client_on_behalf_user(auth_plugin)
|
client = get_client_on_behalf_user(auth_plugin)
|
||||||
@ -98,10 +99,10 @@ OPTS = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def register_keystoneauth_opts(conf):
|
def register_keystoneauth_opts():
|
||||||
ka_loading.register_auth_conf_options(conf, CFG_GROUP)
|
ka_loading.register_auth_conf_options(CONF, CFG_GROUP)
|
||||||
ka_loading.register_session_conf_options(
|
ka_loading.register_session_conf_options(
|
||||||
conf, CFG_GROUP,
|
CONF, CFG_GROUP,
|
||||||
deprecated_opts={'cacert': [
|
deprecated_opts={'cacert': [
|
||||||
cfg.DeprecatedOpt('os-cacert', group=CFG_GROUP),
|
cfg.DeprecatedOpt('os-cacert', group=CFG_GROUP),
|
||||||
cfg.DeprecatedOpt('os-cacert', group="DEFAULT")]
|
cfg.DeprecatedOpt('os-cacert', group="DEFAULT")]
|
||||||
|
@ -19,9 +19,6 @@ import six
|
|||||||
@six.add_metaclass(abc.ABCMeta)
|
@six.add_metaclass(abc.ABCMeta)
|
||||||
class MachineLearningBase(object):
|
class MachineLearningBase(object):
|
||||||
|
|
||||||
def __init__(self, conf):
|
|
||||||
self.conf = conf
|
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def process_event(self, data, event_type):
|
def process_event(self, data, event_type):
|
||||||
pass
|
pass
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
|
||||||
from vitrage.common.constants import NotifierEventTypes
|
from vitrage.common.constants import NotifierEventTypes
|
||||||
@ -28,6 +30,8 @@ from vitrage.machine_learning.plugins.jaccard_correlation.\
|
|||||||
from vitrage.machine_learning.plugins.jaccard_correlation.correlation_manager\
|
from vitrage.machine_learning.plugins.jaccard_correlation.correlation_manager\
|
||||||
import CorrelationManager as CM
|
import CorrelationManager as CM
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
|
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
AlarmID = namedtuple('AlarmID', [VProps.VITRAGE_RESOURCE_ID,
|
AlarmID = namedtuple('AlarmID', [VProps.VITRAGE_RESOURCE_ID,
|
||||||
@ -41,12 +45,12 @@ class AlarmDataProcessor(MachineLearningBase):
|
|||||||
def get_plugin_name():
|
def get_plugin_name():
|
||||||
return 'jaccard_correlation'
|
return 'jaccard_correlation'
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(AlarmDataProcessor, self).__init__(conf)
|
super(AlarmDataProcessor, self).__init__()
|
||||||
self.data_manager = ADAcummulator(APersistor.load_data())
|
self.data_manager = ADAcummulator(APersistor.load_data())
|
||||||
self.correlation_manager = CM(conf)
|
self.correlation_manager = CM()
|
||||||
self.num_of_events_to_flush = \
|
self.num_of_events_to_flush = \
|
||||||
conf.jaccard_correlation.num_of_events_to_flush
|
CONF.jaccard_correlation.num_of_events_to_flush
|
||||||
self.event_counter = 0
|
self.event_counter = 0
|
||||||
|
|
||||||
def process_event(self, data, event_type):
|
def process_event(self, data, event_type):
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
|
||||||
from vitrage.machine_learning.plugins.jaccard_correlation.\
|
from vitrage.machine_learning.plugins.jaccard_correlation.\
|
||||||
@ -23,17 +24,18 @@ from vitrage.machine_learning.plugins.jaccard_correlation.\
|
|||||||
correlation_collection import CorrelationPriorities as CPriorities
|
correlation_collection import CorrelationPriorities as CPriorities
|
||||||
|
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CorrelationManager(object):
|
class CorrelationManager(object):
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
self.high_corr_score = conf.jaccard_correlation.high_corr_score
|
self.high_corr_score = CONF.jaccard_correlation.high_corr_score
|
||||||
self.med_corr_score = conf.jaccard_correlation.med_corr_score
|
self.med_corr_score = CONF.jaccard_correlation.med_corr_score
|
||||||
self.correlation_threshold = \
|
self.correlation_threshold = \
|
||||||
conf.jaccard_correlation.correlation_threshold
|
CONF.jaccard_correlation.correlation_threshold
|
||||||
self.output_folder = conf.jaccard_correlation.output_folder
|
self.output_folder = CONF.jaccard_correlation.output_folder
|
||||||
self.last_written_file = ""
|
self.last_written_file = ""
|
||||||
self.correlation_table = CCollection(self.high_corr_score,
|
self.correlation_table = CCollection(self.high_corr_score,
|
||||||
self.med_corr_score)
|
self.med_corr_score)
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
import oslo_messaging as oslo_m
|
import oslo_messaging as oslo_m
|
||||||
from oslo_utils import importutils
|
from oslo_utils import importutils
|
||||||
@ -21,18 +21,18 @@ from vitrage.coordination import service as coord
|
|||||||
from vitrage import messaging
|
from vitrage import messaging
|
||||||
from vitrage.opts import register_opts
|
from vitrage.opts import register_opts
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class MachineLearningService(coord.Service):
|
class MachineLearningService(coord.Service):
|
||||||
|
|
||||||
def __init__(self, worker_id, conf):
|
def __init__(self, worker_id):
|
||||||
super(MachineLearningService, self).__init__(worker_id, conf)
|
super(MachineLearningService, self).__init__(worker_id)
|
||||||
self.conf = conf
|
self.machine_learning_plugins = self.get_machine_learning_plugins()
|
||||||
self.machine_learning_plugins = self.get_machine_learning_plugins(conf)
|
transport = messaging.get_transport()
|
||||||
transport = messaging.get_transport(conf)
|
|
||||||
target = \
|
target = \
|
||||||
oslo_m.Target(topic=conf.machine_learning.machine_learning_topic)
|
oslo_m.Target(topic=CONF.machine_learning.machine_learning_topic)
|
||||||
self.listener = messaging.get_notification_listener(
|
self.listener = messaging.get_notification_listener(
|
||||||
transport, [target],
|
transport, [target],
|
||||||
[VitrageEventEndpoint(self.machine_learning_plugins)])
|
[VitrageEventEndpoint(self.machine_learning_plugins)])
|
||||||
@ -55,21 +55,21 @@ class MachineLearningService(coord.Service):
|
|||||||
LOG.info("Vitrage Machine Learning Service - Stopped!")
|
LOG.info("Vitrage Machine Learning Service - Stopped!")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_machine_learning_plugins(conf):
|
def get_machine_learning_plugins():
|
||||||
machine_learning_plugins = []
|
machine_learning_plugins = []
|
||||||
machine_learning_plugins_names = \
|
machine_learning_plugins_names = \
|
||||||
conf.machine_learning.plugins
|
CONF.machine_learning.plugins
|
||||||
if not machine_learning_plugins_names:
|
if not machine_learning_plugins_names:
|
||||||
LOG.info('There are no Machine Learning plugins in configuration')
|
LOG.info('There are no Machine Learning plugins in configuration')
|
||||||
return []
|
return []
|
||||||
for machine_learning_plugin_name in machine_learning_plugins_names:
|
for machine_learning_plugin_name in machine_learning_plugins_names:
|
||||||
register_opts(conf, machine_learning_plugin_name,
|
register_opts(machine_learning_plugin_name,
|
||||||
conf.machine_learning.plugins_path)
|
CONF.machine_learning.plugins_path)
|
||||||
LOG.info('Machine Learning plugin %s started',
|
LOG.info('Machine Learning plugin %s started',
|
||||||
machine_learning_plugin_name)
|
machine_learning_plugin_name)
|
||||||
machine_learning_plugins.append(importutils.import_object(
|
machine_learning_plugins.append(importutils.import_object(
|
||||||
conf[machine_learning_plugin_name].plugin_path,
|
CONF[machine_learning_plugin_name].plugin_path,
|
||||||
conf))
|
CONF))
|
||||||
return machine_learning_plugins
|
return machine_learning_plugins
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,11 +11,12 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
import oslo_messaging as oslo_msg
|
import oslo_messaging as oslo_msg
|
||||||
|
|
||||||
# from oslo_messaging import serializer as oslo_serializer
|
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
DEFAULT_URL = "__default__"
|
DEFAULT_URL = "__default__"
|
||||||
@ -28,11 +29,11 @@ def setup():
|
|||||||
oslo_msg.set_transport_defaults('vitrage')
|
oslo_msg.set_transport_defaults('vitrage')
|
||||||
|
|
||||||
|
|
||||||
def get_rpc_transport(conf, url=None, optional=False, cache=True):
|
def get_rpc_transport(url=None, optional=False, cache=True):
|
||||||
return get_transport(conf, url, optional, cache, rpc=True)
|
return get_transport(url, optional, cache, rpc=True)
|
||||||
|
|
||||||
|
|
||||||
def get_transport(conf, url=None, optional=False, cache=True, rpc=False):
|
def get_transport(url=None, optional=False, cache=True, rpc=False):
|
||||||
"""Initialise the oslo_messaging layer."""
|
"""Initialise the oslo_messaging layer."""
|
||||||
global TRANSPORTS, DEFAULT_URL
|
global TRANSPORTS, DEFAULT_URL
|
||||||
cache_key = url or DEFAULT_URL + '_rpc' if rpc else ''
|
cache_key = url or DEFAULT_URL + '_rpc' if rpc else ''
|
||||||
@ -40,9 +41,9 @@ def get_transport(conf, url=None, optional=False, cache=True, rpc=False):
|
|||||||
if not transport or not cache:
|
if not transport or not cache:
|
||||||
try:
|
try:
|
||||||
if rpc:
|
if rpc:
|
||||||
transport = oslo_msg.get_rpc_transport(conf, url)
|
transport = oslo_msg.get_rpc_transport(CONF, url)
|
||||||
else:
|
else:
|
||||||
transport = oslo_msg.get_notification_transport(conf, url)
|
transport = oslo_msg.get_notification_transport(CONF, url)
|
||||||
except oslo_msg.InvalidTransportURL as e:
|
except oslo_msg.InvalidTransportURL as e:
|
||||||
if not optional or e.url:
|
if not optional or e.url:
|
||||||
# NOTE(sileht): oslo_messaging is configured but unloadable
|
# NOTE(sileht): oslo_messaging is configured but unloadable
|
||||||
@ -65,8 +66,8 @@ def get_notification_listener(transport, targets, endpoints,
|
|||||||
|
|
||||||
class VitrageNotifier(object):
|
class VitrageNotifier(object):
|
||||||
"""Allows writing to message bus"""
|
"""Allows writing to message bus"""
|
||||||
def __init__(self, conf, publisher_id, topics):
|
def __init__(self, publisher_id, topics):
|
||||||
transport = get_transport(conf)
|
transport = get_transport()
|
||||||
self.notifier = oslo_msg.Notifier(
|
self.notifier = oslo_msg.Notifier(
|
||||||
transport,
|
transport,
|
||||||
driver='messagingv2',
|
driver='messagingv2',
|
||||||
|
@ -39,9 +39,9 @@ class AodhNotifier(NotifierBase):
|
|||||||
def get_notifier_name():
|
def get_notifier_name():
|
||||||
return AODH_DATASOURCE
|
return AODH_DATASOURCE
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(AodhNotifier, self).__init__(conf)
|
super(AodhNotifier, self).__init__()
|
||||||
self.client = os_clients.aodh_client(conf)
|
self.client = os_clients.aodh_client()
|
||||||
|
|
||||||
def process_event(self, data, event_type):
|
def process_event(self, data, event_type):
|
||||||
response = None
|
response = None
|
||||||
|
@ -19,9 +19,6 @@ import six
|
|||||||
@six.add_metaclass(abc.ABCMeta)
|
@six.add_metaclass(abc.ABCMeta)
|
||||||
class NotifierBase(object):
|
class NotifierBase(object):
|
||||||
|
|
||||||
def __init__(self, conf):
|
|
||||||
self.conf = conf
|
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def process_event(self, data, event_type):
|
def process_event(self, data, event_type):
|
||||||
pass
|
pass
|
||||||
|
@ -25,9 +25,8 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class MistralNotifier(NotifierBase):
|
class MistralNotifier(NotifierBase):
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(MistralNotifier, self).__init__(conf)
|
super(MistralNotifier, self).__init__()
|
||||||
self.conf = conf
|
|
||||||
self._client = None
|
self._client = None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -41,7 +40,7 @@ class MistralNotifier(NotifierBase):
|
|||||||
@property
|
@property
|
||||||
def client(self):
|
def client(self):
|
||||||
if not self._client:
|
if not self._client:
|
||||||
self._client = os_clients.mistral_client(self.conf)
|
self._client = os_clients.mistral_client()
|
||||||
return self._client
|
return self._client
|
||||||
|
|
||||||
def info(self, ctxt, publisher_id, event_type, payload, metadata):
|
def info(self, ctxt, publisher_id, event_type, payload, metadata):
|
||||||
|
@ -30,9 +30,9 @@ class NovaNotifier(NotifierBase):
|
|||||||
def get_notifier_name():
|
def get_notifier_name():
|
||||||
return 'nova'
|
return 'nova'
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(NovaNotifier, self).__init__(conf)
|
super(NovaNotifier, self).__init__()
|
||||||
self.client = os_clients.nova_client(conf)
|
self.client = os_clients.nova_client()
|
||||||
self.actions = {
|
self.actions = {
|
||||||
NOVA_HOST_DATASOURCE: self._mark_host_down,
|
NOVA_HOST_DATASOURCE: self._mark_host_down,
|
||||||
NOVA_INSTANCE_DATASOURCE: self._reset_instance_state
|
NOVA_INSTANCE_DATASOURCE: self._reset_instance_state
|
||||||
|
@ -20,9 +20,6 @@ import six
|
|||||||
class SnmpSenderBase(object):
|
class SnmpSenderBase(object):
|
||||||
"""Abstract Vitrage snmp trap sender"""
|
"""Abstract Vitrage snmp trap sender"""
|
||||||
|
|
||||||
def __init__(self, conf):
|
|
||||||
self.conf = conf
|
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def send_snmp(self, alarm_data):
|
def send_snmp(self, alarm_data):
|
||||||
pass
|
pass
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_utils import importutils
|
from oslo_utils import importutils
|
||||||
|
|
||||||
@ -19,6 +20,7 @@ from vitrage.common.constants import NotifierEventTypes
|
|||||||
from vitrage.common.constants import VertexProperties as VProps
|
from vitrage.common.constants import VertexProperties as VProps
|
||||||
from vitrage.notifier.plugins.base import NotifierBase
|
from vitrage.notifier.plugins.base import NotifierBase
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -27,10 +29,10 @@ class SnmpNotifier(NotifierBase):
|
|||||||
def get_notifier_name():
|
def get_notifier_name():
|
||||||
return 'snmp'
|
return 'snmp'
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(SnmpNotifier, self).__init__(conf)
|
super(SnmpNotifier, self).__init__()
|
||||||
self.snmp_sender = \
|
self.snmp_sender = \
|
||||||
importutils.import_object(conf.snmp.snmp_sender_class, conf)
|
importutils.import_object(CONF.snmp.snmp_sender_class)
|
||||||
|
|
||||||
def process_event(self, data, event_type):
|
def process_event(self, data, event_type):
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from pysnmp.entity.engine import SnmpEngine
|
from pysnmp.entity.engine import SnmpEngine
|
||||||
from pysnmp.hlapi.asyncore.sync.compat.ntforg import sendNotification
|
from pysnmp.hlapi.asyncore.sync.compat.ntforg import sendNotification
|
||||||
@ -27,6 +28,7 @@ from vitrage.common.constants import VertexProperties as VProps
|
|||||||
from vitrage.notifier.plugins.snmp.base import SnmpSenderBase
|
from vitrage.notifier.plugins.snmp.base import SnmpSenderBase
|
||||||
from vitrage.utils.file import load_yaml_file
|
from vitrage.utils.file import load_yaml_file
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
# TODO(annarez): change NA to N/A
|
# TODO(annarez): change NA to N/A
|
||||||
@ -43,12 +45,11 @@ PORT_PAT = re.compile('\d+')
|
|||||||
|
|
||||||
|
|
||||||
class SnmpSender(SnmpSenderBase):
|
class SnmpSender(SnmpSenderBase):
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(SnmpSender, self).__init__(conf)
|
self.hosts = load_yaml_file(CONF.snmp.consumers, True)
|
||||||
self.hosts = load_yaml_file(self.conf.snmp.consumers, True)
|
self.oid_tree = load_yaml_file(CONF.snmp.oid_tree, True)
|
||||||
self.oid_tree = load_yaml_file(self.conf.snmp.oid_tree, True)
|
|
||||||
self.alarm_mapping = \
|
self.alarm_mapping = \
|
||||||
load_yaml_file(self.conf.snmp.alarm_oid_mapping, True)
|
load_yaml_file(CONF.snmp.alarm_oid_mapping, True)
|
||||||
self.oids, self.var_fields = self._build_oids()
|
self.oids, self.var_fields = self._build_oids()
|
||||||
|
|
||||||
def send_snmp(self, alarm_data):
|
def send_snmp(self, alarm_data):
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
import ast
|
import ast
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import uuidutils
|
from oslo_utils import uuidutils
|
||||||
@ -26,6 +27,7 @@ from vitrage.notifier.plugins.base import NotifierBase
|
|||||||
from vitrage.notifier.plugins.webhook import utils as webhook_utils
|
from vitrage.notifier.plugins.webhook import utils as webhook_utils
|
||||||
from vitrage import storage
|
from vitrage import storage
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
URL = 'url'
|
URL = 'url'
|
||||||
IS_ADMIN_WEBHOOK = 'is_admin_webhook'
|
IS_ADMIN_WEBHOOK = 'is_admin_webhook'
|
||||||
@ -65,10 +67,10 @@ class Webhook(NotifierBase):
|
|||||||
def get_notifier_name():
|
def get_notifier_name():
|
||||||
return 'webhook'
|
return 'webhook'
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(Webhook, self).__init__(conf)
|
super(Webhook, self).__init__()
|
||||||
self._db = storage.get_connection_from_config(self.conf)
|
self._db = storage.get_connection_from_config()
|
||||||
self.max_retries = self.conf.webhook.max_retries
|
self.max_retries = CONF.webhook.max_retries
|
||||||
self.default_headers = {'content-type': 'application/json'}
|
self.default_headers = {'content-type': 'application/json'}
|
||||||
|
|
||||||
def process_event(self, data, event_type):
|
def process_event(self, data, event_type):
|
||||||
|
@ -11,22 +11,24 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
|
||||||
from vitrage.common.constants import NotifierEventTypes
|
from vitrage.common.constants import NotifierEventTypes
|
||||||
from vitrage.notifier.plugins.base import NotifierBase
|
from vitrage.notifier.plugins.base import NotifierBase
|
||||||
from vitrage import os_clients
|
from vitrage import os_clients
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ZaqarNotifier(NotifierBase):
|
class ZaqarNotifier(NotifierBase):
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self):
|
||||||
super(ZaqarNotifier, self).__init__(conf)
|
super(ZaqarNotifier, self).__init__()
|
||||||
client = os_clients.zaqar_client(self.conf)
|
client = os_clients.zaqar_client()
|
||||||
self._queue = client.queue(self.conf.zaqar.queue)
|
self._queue = client.queue(CONF.zaqar.queue)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_notifier_name():
|
def get_notifier_name():
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
import oslo_messaging
|
import oslo_messaging
|
||||||
from oslo_utils import importutils
|
from oslo_utils import importutils
|
||||||
@ -19,16 +21,16 @@ from vitrage.coordination import service as coord
|
|||||||
from vitrage import messaging
|
from vitrage import messaging
|
||||||
from vitrage.opts import register_opts
|
from vitrage.opts import register_opts
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class VitrageNotifierService(coord.Service):
|
class VitrageNotifierService(coord.Service):
|
||||||
|
|
||||||
def __init__(self, worker_id, conf):
|
def __init__(self, worker_id):
|
||||||
super(VitrageNotifierService, self).__init__(worker_id, conf)
|
super(VitrageNotifierService, self).__init__(worker_id)
|
||||||
self.conf = conf
|
self.notifiers = self.get_notifier_plugins()
|
||||||
self.notifiers = self.get_notifier_plugins(conf)
|
self._init_listeners()
|
||||||
self._init_listeners(self.conf)
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
super(VitrageNotifierService, self).run()
|
super(VitrageNotifierService, self).run()
|
||||||
@ -51,31 +53,30 @@ class VitrageNotifierService(coord.Service):
|
|||||||
LOG.info("Vitrage Notifier Service - Stopped!")
|
LOG.info("Vitrage Notifier Service - Stopped!")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_notifier_plugins(conf):
|
def get_notifier_plugins():
|
||||||
notifiers = []
|
notifiers = []
|
||||||
conf_notifier_names = conf.notifiers
|
conf_notifier_names = CONF.notifiers
|
||||||
if not conf_notifier_names:
|
if not conf_notifier_names:
|
||||||
LOG.info('There are no notifier plugins in configuration')
|
LOG.info('There are no notifier plugins in configuration')
|
||||||
return []
|
return []
|
||||||
for notifier_name in conf_notifier_names:
|
for notifier_name in conf_notifier_names:
|
||||||
register_opts(conf, notifier_name, conf.notifiers_path)
|
register_opts(notifier_name, CONF.notifiers_path)
|
||||||
LOG.info('Notifier plugin %s started', notifier_name)
|
LOG.info('Notifier plugin %s started', notifier_name)
|
||||||
notifiers.append(importutils.import_object(
|
notifiers.append(importutils.import_object(
|
||||||
conf[notifier_name].notifier,
|
CONF[notifier_name].notifier))
|
||||||
conf))
|
|
||||||
return notifiers
|
return notifiers
|
||||||
|
|
||||||
def _init_listeners(self, conf):
|
def _init_listeners(self):
|
||||||
self.listeners = []
|
self.listeners = []
|
||||||
transport = messaging.get_transport(conf)
|
transport = messaging.get_transport()
|
||||||
|
|
||||||
self._init_notifier(transport=transport,
|
self._init_notifier(transport=transport,
|
||||||
topic=conf.entity_graph.notifier_topic,
|
topic=CONF.entity_graph.notifier_topic,
|
||||||
endpoint=VitrageDefaultEventEndpoint(
|
endpoint=VitrageDefaultEventEndpoint(
|
||||||
self.notifiers))
|
self.notifiers))
|
||||||
|
|
||||||
topic_prefix = \
|
topic_prefix = \
|
||||||
conf.evaluator_actions.evaluator_notification_topic_prefix
|
CONF.evaluator_actions.evaluator_notification_topic_prefix
|
||||||
|
|
||||||
for notifier in self.notifiers:
|
for notifier in self.notifiers:
|
||||||
if notifier.use_private_topic():
|
if notifier.use_private_topic():
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user