示例#1
0
    def sendevent(self, model):
        """
        Send an event message on behalf of a mobility model.
        This communicates the current and end (max) times to the GUI.

        :param WayPointMobility model: mobility model to send event for
        :return: nothing
        """
        event_type = EventTypes.NONE.value
        if model.state == model.STATE_STOPPED:
            event_type = EventTypes.STOP.value
        elif model.state == model.STATE_RUNNING:
            event_type = EventTypes.START.value
        elif model.state == model.STATE_PAUSED:
            event_type = EventTypes.PAUSE.value

        data = "start=%d" % int(model.lasttime - model.timezero)
        data += " end=%d" % int(model.endtime)

        event_data = EventData(node=model.object_id,
                               event_type=event_type,
                               name="mobility:%s" % model.name,
                               data=data,
                               time="%s" % time.time())

        self.session.broadcast_event(event_data)
示例#2
0
    def instantiate(self):
        """
        We have entered the instantiation state, invoke startup methods
        of various managers and boot the nodes. Validate nodes and check
        for transition to the runtime state.
        """

        # write current objects out to session directory file
        self.write_objects()

        # controlnet may be needed by some EMANE models
        self.add_remove_control_interface(node=None, remove=False)

        # instantiate will be invoked again upon Emane configure
        if self.emane.startup() == self.emane.NOT_READY:
            return

        # start feature helpers
        self.broker.startup()
        self.mobility.startup()

        # boot the services on each node
        self.boot_nodes()

        # set broker local instantiation to complete
        self.broker.local_instantiation_complete()

        # notify listeners that instantiation is complete
        event = EventData(event_type=EventTypes.INSTANTIATION_COMPLETE.value)
        self.broadcast_event(event)

        # assume either all nodes have booted already, or there are some
        # nodes on slave servers that will be booted and those servers will
        # send a node status response message
        self.check_runtime()
示例#3
0
    def set_state(self, state, send_event=False):
        """
        Set the session's current state.

        :param core.enumerations.EventTypes state: state to set to
        :param send_event: if true, generate core API event messages
        :return: nothing
        """
        state_value = state.value
        state_name = state.name

        if self.state == state_value:
            logger.info("session(%s) is already in state: %s, skipping change",
                        self.session_id, state_name)
            return

        self.state = state_value
        self._state_time = time.time()
        logger.info("changing session(%s) to state %s", self.session_id,
                    state_name)

        self.write_state(state_value)
        self.run_hooks(state_value)
        self.run_state_hooks(state_value)

        if send_event:
            event_data = EventData(event_type=state_value,
                                   time="%s" % time.time())
            self.broadcast_event(event_data)
示例#4
0
def index():
    data = json.loads(request.data.decode("utf-8"))

    if data['type'] == EventType.CONFIRMATION:
        return config.VkConfig.RETURN_STR
    else:
        event = EventData.from_raw(data)
        controler.recognition(event)

        return 'ok'
示例#5
0
文件: service.py 项目: troglobit/core
    def handleevent(self, event_data):
        """
        Handle an Event Message used to start, stop, restart, or validate
        a service on a given node.

        :param EventData event_data: event data to handle
        :return: nothing
        """
        event_type = event_data.event_type
        node_id = event_data.node
        name = event_data.name

        try:
            node = self.session.get_object(node_id)
        except KeyError:
            logger.warn("Ignoring event for service '%s', unknown node '%s'",
                        name, node_id)
            return

        fail = ""
        services, unknown = self.servicesfromopaque(name, node_id)
        for s in services:
            if event_type == EventTypes.STOP.value or event_type == EventTypes.RESTART.value:
                status = self.stopnodeservice(node, s)
                if status != "0":
                    fail += "Stop %s," % s._name
            if event_type == EventTypes.START.value or event_type == EventTypes.RESTART.value:
                if s._custom:
                    cmds = s._startup
                else:
                    cmds = s.getstartup(node, services)
                if len(cmds) > 0:
                    for args in cmds:
                        try:
                            node.check_cmd(args)
                        except CoreCommandError:
                            logger.exception("error starting command")
                            fail += "Start %s(%s)," % (s._name, args)
            if event_type == EventTypes.PAUSE.value:
                status = self.validatenodeservice(node, s, services)
                if status != 0:
                    fail += "%s," % s._name
            if event_type == EventTypes.RECONFIGURE.value:
                if s._custom:
                    cfgfiles = s._configs
                else:
                    cfgfiles = s.getconfigfilenames(node.objid, services)
                if len(cfgfiles) > 0:
                    for filename in cfgfiles:
                        if filename[:7] == "file:///":
                            # TODO: implement this
                            raise NotImplementedError
                        cfg = self.getservicefiledata(s, filename)
                        if cfg is None:
                            cfg = s.generateconfig(node, filename, services)

                        node.nodefile(filename, cfg)

        fail_data = ""
        if len(fail) > 0:
            fail_data += "Fail:" + fail
        unknown_data = ""
        num = len(unknown)
        if num > 0:
            for u in unknown:
                unknown_data += u
                if num > 1:
                    unknown_data += ", "
                num -= 1
            logger.warn("Event requested for unknown service(s): %s",
                        unknown_data)
            unknown_data = "Unknown:" + unknown_data

        event_data = EventData(node=node_id,
                               event_type=event_type,
                               name=name,
                               data=fail_data + ";" + unknown_data,
                               time="%s" % time.time())

        self.session.broadcast_event(event_data)