Пример #1
0
    def __init__(self):
        Plugin.__init__(self, name='scenario', log_prefix='core_')
        ### check that needed services are up on MQ side
        cli = MQSyncReq(zmq.Context())
        mq_services = None
        while mq_services == None or 'xplgw' not in mq_services:
            mq_services_raw = cli.rawrequest('mmi.services', '', timeout=10)
            if mq_services_raw != None:
                mq_services = str(mq_services_raw[0]).replace(" ",
                                                              "").split(",")
            self.log.info("Checking for MQ services : {0}".format(mq_services))
            if mq_services == None or 'xplgw' not in mq_services:
                self.log.debug(
                    "Needed MQ services not yet available : waiting")
                time.sleep(3)
        self.log.info("Needed MQ services available : continuing startup")

        ### start the scenario stuff
        self._backend = ScenarioManager(self.log)
        self.add_stop_cb(self.end)
        self.add_stop_cb(self.shutdown)
        self.log.info(
            u"Scenario Frontend and Manager initialized, let's wait for some work."
        )
        self.ready()
Пример #2
0
 def __init__(self):
     Plugin.__init__(self, name='scenario')
     self._backend = ScenarioManager(self.log)
     self.add_stop_cb(self.end)
     self.add_stop_cb(self.shutdown)
     self.log.info(
         u"Scenario Frontend and Manager initialized, let's wait for some work."
     )
     self.ready()
Пример #3
0
 def __init__(self):
     Plugin.__init__(self, name = 'scenario')
     self._backend = ScenarioManager(self.log)
     self.add_stop_cb(self.end)
     self.add_stop_cb(self.shutdown)
     self.log.info(u"Scenario Frontend and Manager initialized, let's wait for some work.")
     self.ready()
Пример #4
0
    def __init__(self):
        Plugin.__init__(self, name = 'scenario')
        ### check that needed services are up on MQ side
        cli = MQSyncReq(zmq.Context())
        mq_services = None
        while mq_services == None or 'xplgw' not in mq_services:
            mq_services_raw = cli.rawrequest('mmi.services', '', timeout=10)
            if mq_services_raw != None: 
                mq_services = mq_services_raw[0].replace(" ", "").split(",")
            self.log.info("Checking for MQ services : {0}".format(mq_services))
            if mq_services == None or 'xplgw' not in mq_services:
                self.log.debug("Needed MQ services not yet available : waiting")
                time.sleep(3)
        self.log.info("Needed MQ services available : continuing startup")

        ### start the scenario stuff
        self._backend = ScenarioManager(self.log)
        self.add_stop_cb(self.end)
        self.add_stop_cb(self.shutdown)
        self.log.info(u"Scenario Frontend and Manager initialized, let's wait for some work.")
        self.ready()
Пример #5
0
class ScenarioFrontend(Plugin):
    """ This class provides an interface to MQ system to allow Scenarii management.
    """

    def __init__(self):
        Plugin.__init__(self, name = 'scenario')
        ### check that needed services are up on MQ side
        cli = MQSyncReq(zmq.Context())
        mq_services = None
        while mq_services == None or 'xplgw' not in mq_services:
            mq_services_raw = cli.rawrequest('mmi.services', '', timeout=10)
            if mq_services_raw != None: 
                mq_services = mq_services_raw[0].replace(" ", "").split(",")
            self.log.info("Checking for MQ services : {0}".format(mq_services))
            if mq_services == None or 'xplgw' not in mq_services:
                self.log.debug("Needed MQ services not yet available : waiting")
                time.sleep(3)
        self.log.info("Needed MQ services available : continuing startup")

        ### start the scenario stuff
        self._backend = ScenarioManager(self.log)
        self.add_stop_cb(self.end)
        self.add_stop_cb(self.shutdown)
        self.log.info(u"Scenario Frontend and Manager initialized, let's wait for some work.")
        self.ready()

    def on_mdp_request(self, msg):
        """ Do real work with message
        msg.get_action() shoult contain XXXX.YYYYYY
        with XXXX in [test, condition, parameter]
        YYYYY in [list, new, etc ...]
        """
        mapping = {'test':
                    {
                        'list': self._backend.list_tests,
                    },
                    'scenario':
                    {
                        'list': self._backend.list_conditions,
                        'new': self._backend.create_scenario,
                        'update': self._backend.update_scenario,
                        'delete': self._backend.del_scenario,
                        'get': self._backend.get_parsed_condition,
                        'evaluate': self._backend.eval_condition
                    },
                    'action':
                    {
                        'list': self._backend.list_actions,
                    }
                }
        try:
            if msg.get_action().split('.')[0] not in mapping.keys():
                self._mdp_reply(msg.get_action(), {"status" : "error", "details": "{0} not in {1}".format(msg.get_action().split('.')[0], mapping.keys())})
            else:
                if msg.get_action().split('.')[1] not in mapping[msg.get_action().split('.')[0]].keys():
                    self._mdp_reply(msg.get_action(), {"status" : "error", "details": "{0} not in {1}".format(msg.get_action().split('.')[1], mapping[msg.get_action().split('.')[0]].keys())})
                else:
                    if msg.get_data() == {}:
                        payload = mapping[msg.get_action().split('.')[0]][msg.get_action().split('.')[1]]()
                    else:
                        payload = mapping[msg.get_action().split('.')[0]][msg.get_action().split('.')[1]](**msg.get_data())
                    self._mdp_reply(msg.get_action(), payload)
        except:
            self.log.error(u"Exception occured during message processing.")
            trace = str(traceback.format_exc())
            self.log.debug(trace)
            self._mdp_reply(msg.get_action(), {"status": "errpr", "details": trace})

    def _mdp_reply(self, action, payload):
        msg = MQMessage()
        msg.set_action(action)
        msg.add_data('result', payload)
        self.reply(msg.get())

    def end(self):
        """ Shutdown Scenario
        """
        self._backend.shutdown()
Пример #6
0
class ScenarioFrontend(Plugin):
    """ This class provides an interface to MQ system to allow Scenarii management.
    """
    def __init__(self):
        Plugin.__init__(self, name='scenario')
        self._backend = ScenarioManager(self.log)
        self.add_stop_cb(self.end)
        self.add_stop_cb(self.shutdown)
        self.log.info(
            u"Scenario Frontend and Manager initialized, let's wait for some work."
        )
        self.ready()

    def on_mdp_request(self, msg):
        """ Do real work with message
        msg.get_action() shoult contain XXXX.YYYYYY
        with XXXX in [test, condition, parameter]
        YYYYY in [list, new, etc ...]
        """
        mapping = {
            'test': {
                'list': self._backend.list_tests,
            },
            'scenario': {
                'list': self._backend.list_conditions,
                'new': self._backend.create_scenario,
                'delete': self._backend.delete_scenario,
                'get': self._backend.get_parsed_condition,
                'evaluate': self._backend.eval_condition
            },
            'action': {
                'list': self._backend.list_actions,
            }
        }
        try:
            if msg.get_action().split('.')[0] not in mapping.keys():
                self._mdp_reply(
                    msg.get_action(), "error", {
                        "details":
                        "{0} not in {1}".format(msg.get_action().split('.')[0],
                                                mapping.keys())
                    })
            else:
                if msg.get_action().split('.')[1] not in mapping[
                        msg.get_action().split('.')[0]].keys():
                    self._mdp_reply(
                        msg.get_action(), "error", {
                            "details":
                            "{0} not in {1}".format(
                                msg.get_action().split('.')[1],
                                mapping[msg.get_action().split('.')[0]].keys())
                        })
                else:
                    if msg.get_data() == {}:
                        payload = mapping[msg.get_action().split('.')[0]][
                            msg.get_action().split('.')[1]]()
                    else:
                        payload = mapping[msg.get_action().split('.')[0]][
                            msg.get_action().split('.')[1]](**msg.get_data())
                    self._mdp_reply(msg.get_action(), payload)
        except:
            self.log.error(u"Exception occured during message processing.")
            trace = str(traceback.format_exc())
            self.log.debug(trace)
            self._mdp_reply(msg.get_action(), "error", {"details": trace})

    def _mdp_reply(self, action, payload):
        msg = MQMessage()
        msg.set_action(action)
        msg.add_data('result', payload)
        self.reply(msg.get())

    def end(self):
        """ Shutdown Scenario
        """
        self._backend.shutdown()
Пример #7
0
class ScenarioFrontend(Plugin):
    """ This class provides an interface to MQ system to allow Scenarii management.
    """
    def __init__(self):
        Plugin.__init__(self, name='scenario', log_prefix='core_')
        ### check that needed services are up on MQ side
        cli = MQSyncReq(zmq.Context())
        mq_services = None
        while mq_services == None or 'xplgw' not in mq_services:
            mq_services_raw = cli.rawrequest('mmi.services', '', timeout=10)
            if mq_services_raw != None:
                mq_services = str(mq_services_raw[0]).replace(" ",
                                                              "").split(",")
            self.log.info("Checking for MQ services : {0}".format(mq_services))
            if mq_services == None or 'xplgw' not in mq_services:
                self.log.debug(
                    "Needed MQ services not yet available : waiting")
                time.sleep(3)
        self.log.info("Needed MQ services available : continuing startup")

        ### start the scenario stuff
        self._backend = ScenarioManager(self.log)
        self.add_stop_cb(self.end)
        self.add_stop_cb(self.shutdown)
        self.log.info(
            u"Scenario Frontend and Manager initialized, let's wait for some work."
        )
        self.ready()

    def on_mdp_request(self, msg):
        """ Do real work with message
        msg.get_action() shoult contain XXXX.YYYYYY
        with XXXX in [test, condition, parameter]
        YYYYY in [list, new, etc ...]
        """
        mapping = {
            'test': {
                'list': self._backend.list_tests,
            },
            'scenario': {
                'list': self._backend.list_conditions,
                'new': self._backend.create_scenario,
                'update': self._backend.update_scenario,
                'delete': self._backend.del_scenario,
                'get': self._backend.get_parsed_condition,
                'evaluate': self._backend.eval_condition,
                'enable': self._backend.enable_scenario,
                'disable': self._backend.disable_scenario,
                'test': self._backend.test_scenario
            },
            'action': {
                'list': self._backend.list_actions,
            }
        }
        try:
            if msg.get_action().split('.')[0] not in mapping.keys():
                self._mdp_reply(
                    msg.get_action(), {
                        "status":
                        "error",
                        "details":
                        "{0} not in {1}".format(msg.get_action().split('.')[0],
                                                mapping.keys())
                    })
            else:
                if msg.get_action().split('.')[1] not in mapping[
                        msg.get_action().split('.')[0]].keys():
                    self._mdp_reply(
                        msg.get_action(), {
                            "status":
                            "error",
                            "details":
                            "{0} not in {1}".format(
                                msg.get_action().split('.')[1],
                                mapping[msg.get_action().split('.')[0]].keys())
                        })
                else:
                    if msg.get_data() == {}:
                        payload = mapping[msg.get_action().split('.')[0]][
                            msg.get_action().split('.')[1]]()
                    else:
                        print(msg.get_data())
                        payload = mapping[msg.get_action().split('.')[0]][
                            msg.get_action().split('.')[1]](**msg.get_data())
                    self._mdp_reply(msg.get_action(), payload)
        except:
            self.log.error(u"Exception occured during message processing.")
            trace = str(traceback.format_exc())
            self.log.debug(trace)
            self._mdp_reply(msg.get_action(), {
                "status": "errpr",
                "details": trace
            })

    def _mdp_reply(self, action, payload):
        msg = MQMessage()
        msg.set_action(action)
        msg.add_data('result', payload)
        self.reply(msg.get())

    def end(self):
        """ Shutdown Scenario
        """
        self._backend.shutdown()
Пример #8
0
class ScenarioFrontend(Plugin):
    """ This class provides an interface to MQ system to allow Scenarii management.
    """

    def __init__(self):
        Plugin.__init__(self, name = 'scenario')
        self._backend = ScenarioManager(self.log)
        self.add_stop_cb(self.end)
        self.add_stop_cb(self.shutdown)
        self.log.info(u"Scenario Frontend and Manager initialized, let's wait for some work.")
        self.ready()

    def on_mdp_request(self, msg):
        """ Do real work with message
        msg.get_action() shoult contain XXXX.YYYYYY
        with XXXX in [test, condition, parameter]
        YYYYY in [list, new, etc ...]
        """
        mapping = {'test':
                    {
                        'list': self._backend.list_tests,
                    },
                    'scenario':
                    {
                        'list': self._backend.list_conditions,
                        'new': self._backend.create_scenario,
                        'delete': self._backend.delete_scenario,
                        'get': self._backend.get_parsed_condition,
                        'evaluate': self._backend.eval_condition
                    },
                    'action':
                    {
                        'list': self._backend.list_actions,
                    }
                }
        try:
            if msg.get_action().split('.')[0] not in mapping.keys():
                self._mdp_reply(msg.get_action(), "error", {"details": "{0} not in {1}".format(msg.get_action().split('.')[0], mapping.keys())})
            else:
                if msg.get_action().split('.')[1] not in mapping[msg.get_action().split('.')[0]].keys():
                    self._mdp_reply(msg.get_action(), "error", {"details": "{0} not in {1}".format(msg.get_action().split('.')[1], mapping[msg.get_action().split('.')[0]].keys())})
                else:
                    if msg.get_data() == {}:
                        payload = mapping[msg.get_action().split('.')[0]][msg.get_action().split('.')[1]]()
                    else:
                        payload = mapping[msg.get_action().split('.')[0]][msg.get_action().split('.')[1]](**msg.get_data())
                    self._mdp_reply(msg.get_action(), payload)
        except:
            self.log.error(u"Exception occured during message processing.")
            trace = str(traceback.format_exc())
            self.log.debug(trace)
            self._mdp_reply(msg.get_action(), "error", {"details": trace})

    def _mdp_reply(self, action, payload):
        msg = MQMessage()
        msg.set_action(action)
        msg.add_data('result', payload)
        self.reply(msg.get())

    def end(self):
        """ Shutdown Scenario
        """
        self._backend.shutdown()