Esempio n. 1
0
def main():
    print(VITRAGE_TITLE)
    conf = service.prepare_service()
    db_connection = storage.get_connection_from_config(conf)
    sm = cotyledon.ServiceManager()
    sm.add(PersistorService, args=(conf, db_connection))
    sm.run()
Esempio n. 2
0
    def _init_instance(self):
        conf = self._conf
        LOG.info("Vitrage Api Handler Service - Starting...")
        notifier = messaging.VitrageNotifier(conf, "vitrage.api",
                                             [EVALUATOR_TOPIC])
        db = storage.get_connection_from_config(conf)
        transport = messaging.get_rpc_transport(conf)
        rabbit_hosts = conf.oslo_messaging_rabbit.rabbit_hosts
        target = oslo_messaging.Target(topic=conf.rpc_topic,
                                       server=rabbit_hosts)

        endpoints = [
            TopologyApis(self._entity_graph, conf),
            AlarmApis(self._entity_graph, conf, db),
            RcaApis(self._entity_graph, conf, db),
            TemplateApis(notifier, db),
            EventApis(conf),
            ResourceApis(self._entity_graph, conf),
            WebhookApis(conf)
        ]

        server = vitrage_rpc.get_server(target, endpoints, transport)

        server.start()

        LOG.info("Vitrage Api Handler Service - Started!")
Esempio n. 3
0
def main():
    print(VITRAGE_TITLE)
    conf = service.prepare_service()
    db_connection = storage.get_connection_from_config(conf)
    launcher = os_service.ServiceLauncher(conf)
    launcher.launch_service(PersistorService(conf, db_connection))
    launcher.wait()
Esempio n. 4
0
 def _read_db_graph(self):
     db = storage.get_connection_from_config(self._conf)
     graph_snapshot = db.graph_snapshots.query()
     NXGraph.read_gpickle(graph_snapshot.graph_snapshot, self._entity_graph)
     GraphPersistency.do_replay_events(db, self._entity_graph,
                                       graph_snapshot.event_id)
     self._entity_graph.ready = True
Esempio n. 5
0
    def submit_template_event(self, event):
        """Template worker to load the new/deleted template

        Load the template to scenario-evaluator and run it on the entire graph
        """
        template_action = event.get(TEMPLATE_ACTION)

        if not self._db:
            self._db = storage.get_connection_from_config(self._conf)

        if template_action == ADD:
            templates = self._db.templates.query(status=TStatus.LOADING)
            new_status = TStatus.ACTIVE
            action_mode = ActionMode.DO
        elif template_action == DELETE:
            templates = self._db.templates.query(status=TStatus.DELETING)
            new_status = TStatus.DELETED
            action_mode = ActionMode.UNDO
        else:
            raise VitrageError('Invalid template_action %s' % template_action)

        # Template event will be handled by a single evaluator worker
        self._submit_and_wait(
            [self._evaluator_queues[0]],
            (
                TEMPLATE_ACTION,
                [t.name for t in templates
                 if t.template_type == TType.STANDARD],
                action_mode,
            ))

        for t in templates:
            self._db.templates.update(t.uuid, 'status', new_status)
Esempio n. 6
0
 def __init__(self, conf, e_graph):
     super(VitrageApiHandlerService, self).__init__()
     self.conf = conf
     self.entity_graph = e_graph
     self.notifier = VitrageNotifier(self.conf, "vitrage.api",
                                     [EVALUATOR_TOPIC])
     self.db = storage.get_connection_from_config(conf)
Esempio n. 7
0
def main():
    print(VITRAGE_TITLE)
    config.parse_config(sys.argv)
    db_connection = storage.get_connection_from_config()
    sm = cotyledon.ServiceManager()
    sm.add(PersistorService, args=(db_connection, ))
    sm.run()
Esempio n. 8
0
def main():
    """Main method of vitrage-graph"""

    print(VITRAGE_TITLE)
    conf = service.prepare_service()
    e_graph = get_graph_driver(conf)('Entity Graph')
    db_connection = storage.get_connection_from_config(conf)
    VitrageGraphInit(conf, e_graph, db_connection).run()
Esempio n. 9
0
def clear_db(conf):
    """Delete all data from vitrage tables

    The following deletes the entire vitrage database
    It should be removed once graph is persistent
    """
    db_connection = storage.get_connection_from_config(conf)
    db_connection.clear()
Esempio n. 10
0
 def add_db(self):
     db_name = "sqlite:///test-%s-%s.db" % (type(self).__name__,
                                            sys.version_info[0])
     self.config(group='database', connection=db_name)
     self._db = storage.get_connection_from_config()
     engine = self._db._engine_facade.get_engine()
     models.Base.metadata.drop_all(engine)
     models.Base.metadata.create_all(engine)
     return self._db
Esempio n. 11
0
def purge_data():
    print(VITRAGE_TITLE)
    conf = service.prepare_service()
    db = storage.get_connection_from_config(conf)
    db.active_actions.delete()
    db.events.delete()
    db.graph_snapshots.delete()
    db.changes.delete()
    db.edges.delete()
    db.alarms.delete()
Esempio n. 12
0
 def add_db(cls, conf):
     conf.register_opts(database_opts, group='database')
     db_name = "sqlite:///test-%s-%s.db" % (cls.__name__,
                                            sys.version_info[0])
     conf.set_override('connection', db_name, group='database')
     cls._db = storage.get_connection_from_config(conf)
     engine = cls._db._engine_facade.get_engine()
     models.Base.metadata.drop_all(engine)
     models.Base.metadata.create_all(engine)
     return cls._db
Esempio n. 13
0
def purge_data():
    print(VITRAGE_TITLE)
    config.parse_config(sys.argv)
    db = storage.get_connection_from_config()
    db.active_actions.delete()
    db.events.delete()
    db.graph_snapshots.delete()
    db.changes.delete()
    db.edges.delete()
    db.alarms.delete()
Esempio n. 14
0
def main():
    """Main method of vitrage-graph"""

    print(VITRAGE_TITLE)
    conf = service.prepare_service()
    e_graph = get_graph_driver(conf)('Entity Graph')
    db_connection = storage.get_connection_from_config(conf)
    clear_active_actions_table(db_connection)

    VitrageApiHandlerService(conf, e_graph).start()
    VitrageGraphInit(conf, e_graph, db_connection).run()
Esempio n. 15
0
 def __init__(self,
              e_graph,
              scenario_repo,
              actions_callback,
              enabled=False):
     self._entity_graph = e_graph
     self._db = storage.get_connection_from_config()
     self._scenario_repo = scenario_repo
     self._action_executor = ActionExecutor(actions_callback)
     self._entity_graph.subscribe(self.process_event)
     self.enabled = enabled
     self.connected_component_cache = defaultdict(dict)
Esempio n. 16
0
 def __init__(self, conf, workers):
     self.conf = conf
     self.graph = get_graph_driver(conf)('Entity Graph')
     self.db = db_connection = storage.get_connection_from_config(conf)
     self.workers = workers
     self.events_coordination = EventsCoordination(conf, self.process_event)
     self.persist = GraphPersistency(conf, db_connection, self.graph)
     self.driver_exec = driver_exec.DriverExec(
         self.conf, self.events_coordination.handle_multiple_low_priority,
         self.persist)
     self.scheduler = Scheduler(conf, self.graph, self.driver_exec,
                                self.persist)
     self.processor = Processor(conf, self.graph)
Esempio n. 17
0
 def setUpClass(cls):
     super(TestGraphPersistor, cls).setUpClass()
     cls.conf = cfg.ConfigOpts()
     cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph')
     cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources')
     cls.conf.register_opts(database_opts, group='database')
     cls.conf.set_override('connection',
                           'sqlite:///test-%s.db' % sys.version_info[0],
                           group='database')
     cls._db = storage.get_connection_from_config(cls.conf)
     engine = cls._db._engine_facade.get_engine()
     models.Base.metadata.create_all(engine)
     cls.load_datasources(cls.conf)
     cls.graph_persistor = GraphPersistor(cls.conf)
Esempio n. 18
0
 def __init__(self,
              conf,
              e_graph,
              scenario_repo,
              actions_callback,
              enabled=False):
     super(ScenarioEvaluator, self).__init__(conf, e_graph)
     self._db_connection = storage.get_connection_from_config(self._conf)
     self._scenario_repo = scenario_repo
     self._action_executor = ActionExecutor(self._conf, actions_callback)
     self._entity_graph.subscribe(self.process_event)
     self._active_actions_tracker = ActiveActionsTracker(
         self._conf, self._db_connection)
     self.enabled = enabled
     self.connected_component_cache = defaultdict(dict)
Esempio n. 19
0
    def setUpClass(cls):
        super(TestActionExecutor, cls).setUpClass()
        cls.conf = cfg.ConfigOpts()
        cls.conf.register_opts(cls.PROCESSOR_OPTS, group='entity_graph')
        cls.conf.register_opts(cls.DATASOURCES_OPTS, group='datasources')
        cls.conf.register_opts(database_opts, group='database')
        cls.conf.set_override('connection',
                              'sqlite:///:memory:',
                              group='database')
        cls._db = storage.get_connection_from_config(cls.conf)
        engine = cls._db._engine_facade.get_engine()
        models.Base.metadata.create_all(engine)

        for datasource_name in cls.conf.datasources.types:
            register_opts(cls.conf, datasource_name, cls.conf.datasources.path)
Esempio n. 20
0
    def __init__(self, worker_index=None, workers_num=None):
        """Create an instance of ScenarioRepository

        :param conf:
        :param worker_index: Index of the current evaluator worker
        :param workers_num: Total number of evaluator workers
        """
        self._templates = {}
        self._def_templates = {}
        self._all_scenarios = []
        self._db = storage.get_connection_from_config()
        self.entity_equivalences = EquivalenceRepository().load(self._db)
        self.relationship_scenarios = defaultdict(list)
        self.entity_scenarios = defaultdict(list)
        self._load_def_templates_from_db()
        self._load_templates_from_db()
        self._enable_worker_scenarios(worker_index, workers_num)
        self.actions = self._create_actions_collection()
Esempio n. 21
0
    def _init_instance(self):
        notifier = messaging.VitrageNotifier("vitrage.api", [EVALUATOR_TOPIC])
        db = storage.get_connection_from_config()
        transport = messaging.get_rpc_transport()
        target = oslo_messaging.Target(topic=CONF.rpc_topic,
                                       server=uuidutils.generate_uuid())
        self.api_lock = threading.RLock()

        endpoints = [
            TopologyApis(self._entity_graph, self.api_lock),
            AlarmApis(self._entity_graph, self.api_lock, db),
            RcaApis(self._entity_graph, self.api_lock, db),
            ResourceApis(self._entity_graph, self.api_lock),
            TemplateApis(notifier, db),
            EventApis(),
            WebhookApis(db),
            OperationalApis(self._entity_graph),
        ]

        server = vitrage_rpc.get_server(target, endpoints, transport)

        server.start()
Esempio n. 22
0
 def __init__(self, conf):
     self.storage = storage.get_connection_from_config(conf)
Esempio n. 23
0
def dbsync():
    print(VITRAGE_TITLE)
    conf = service.prepare_service()
    storage.get_connection_from_config(conf).upgrade()
Esempio n. 24
0
 def __init__(self, conf):
     self.conf = conf
     self.db_conn = storage.get_connection_from_config(conf)
Esempio n. 25
0
 def __init__(self, conf):
     super(Webhook, self).__init__(conf)
     self._db = storage.get_connection_from_config(self.conf)
     self.max_retries = self.conf.webhook.max_retries
     self.default_headers = {'content-type': 'application/json'}
Esempio n. 26
0
def dbsync():
    print(VITRAGE_TITLE)
    config.parse_config(sys.argv)
    storage.get_connection_from_config().upgrade()
Esempio n. 27
0
 def __init__(self, conf):
     super(GraphPersistor, self).__init__()
     self.db_connection = storage.get_connection_from_config(conf)
     self.last_event_timestamp = datetime.datetime.utcnow()
Esempio n. 28
0
 def setUpClass(cls):
     super(TestEvents, cls).setUpClass()
     cls.db_connection = storage.get_connection_from_config(cls.conf)