Exemplo n.º 1
0
    def exitAll(self, timeout=10):
        """
        Called to tell the director to shutdown stopped ALL
        controllers and child processes.

        :param timeout: This is the amount of time (in seconds)
        used to wait for the director to respond. If a response
        isn't received within this then SignalTimeout will be
        raised.

        Event Dispatched: EVT_DIRECTOR_EXIT_ALL

        """
        sig = messenger.EVT("EVT_DIRECTOR_EXIT_ALL")
        self.log.warn("exitAll: (request sig id %s) shutdown signal received!" % sig.uid)
        try:
            rc = messenger.send_await(sig, timeout=timeout)

        except messenger.EventTimeout:
            raise SignalTimeout("exitAll: Director presence check failed! Is it running?")

        else:
            self.log.debug("exitAll: (request sig id %s) shutting down." % sig.uid)
            rc = rc['data']

        return rc
Exemplo n.º 2
0
    def ping(self, timeout=10, testing=None):
        """
        Called to check if the director is actually there and
        responding, otherwise we could be waiting forever for
        nothing to happen.

        :param timeout: This is the amount of time (in seconds)
        used to wait for the director to respond. If a response
        isn't received within this then SignalTimeout will be
        raised.

        Event Dispatched: EVT_DIRECTOR_PING

        """
        token = str(uuid.uuid4())
        self.log.debug("ping: waiting for director with token '%s'." % (token))
        sig = messenger.EVT("EVT_DIRECTOR_PING")
        if testing:
            # use the unittest's EVT_DIRECTOR_PING instead.
            sig = testing
        try:
            rc = messenger.send_await(sig, token, timeout=timeout)
            rtoken = rc['data']['data']
            if token != rtoken:
                self.log.warn("ping: received ping token '%s' is different to '%s'" % (token, rtoken))
            else:
                self.log.debug("ping: received correct ping from director." % ())

        except messenger.EventTimeout:
            raise SignalTimeout("Director presence check failed! Is it running?")
Exemplo n.º 3
0
    def controllerStop(self, name, timeout=DEFAULT_TIMEOUT):
        """
        Called to tell a controller to stop running.

        :param name: This will contain the name of the controller
        to be started. This name is the same name as that in the
        configuration section.

        :param timeout: This is the amount of time (in seconds)
        used to wait for the director to respond. If a response
        isn't received within this then SignalTimeout will be
        raised.

        :returns: See SignalReceiver controllerStop.

        Event Dispatched: EVT_DIRECTOR_CTRLSTOP

        """
        sig = messenger.EVT("EVT_DIRECTOR_CTRLSTOP")
        try:
            self.log.debug("controllerStop: (request sig id %s) stopping controller." % sig.uid)
            rc = messenger.send_await(sig, name, timeout=timeout)

        except messenger.EventTimeout:
            self.log.error("controllerStop: (request sig id %s) event timeout!" % sig.uid)
            raise SignalTimeout("Director communication timeout (%s)s! Is it running?" % timeout)

        else:
            self.log.debug("controllerStop: (reply for sig id %s) stop called ok." % sig.uid)
            rc = rc['data']

        return rc
Exemplo n.º 4
0
    def configuration(self, timeout=DEFAULT_TIMEOUT):
        """
        Called to return the director configuration.

        :param timeout: This is the amount of time (in seconds)
        used to wait for the director to respond. If a response
        isn't received within this then SignalTimeout will be
        raised.

        :returns: See SignalReceiver configuration.

        Event Dispatched: EVT_DIRECTOR_CONFIGURATION

        """
        sig = messenger.EVT("EVT_DIRECTOR_CONFIGURATION")
        try:
            self.log.debug("configuration: (request sig id %s) getting director configuration." % sig.uid)
            rc = messenger.send_await(sig, timeout=timeout)

        except messenger.EventTimeout:
            self.log.error("configuration: (request sig id %s) event timeout!" % sig.uid)
            raise SignalTimeout("Director communication timeout (%s)s! Is it running?" % timeout)

        else:
            self.log.debug("configuration: (reply for sig id %s) configuration recovered ok." % sig.uid)
            rc = rc['data']

        return rc
Exemplo n.º 5
0
    def xmlrpc_viewpoint_shutdown(self):
        """Broadcasts a EVT_VIEWPOINT_SHUTDOWN message if anyone is listening they will react.
        """
        self.log.debug("xmlrpc_shutdown: sending EVT_VIEWPOINT_SHUTDOWN to the director.")
        messenger.send(messenger.EVT('EVT_VIEWPOINT_SHUTDOWN'), {})
        self.log.debug("xmlrpc_shutdown: sent EVT_SHUTDOWN OK.")

        return 0
Exemplo n.º 6
0
    def xmlrpc_viewpoint_startup(self):
        """Broadcasts a EVT_VIEWPOINT_STARTUP message if anyone is listening they will react.
        """
        self.log.debug("xmlrpc_startup: sending EVT_VIEWPOINT_STARTUP to the director.")
        messenger.send(messenger.EVT('EVT_VIEWPOINT_STARTUP'), {})
        self.log.debug("xmlrpc_startup: sent EVT_VIEWPOINT_STARTUP OK.")

        return 0
    def viewpointQuit(self):
        """
        Called to instruct the viewpoint to close and exit normally.

        This method sends the VIEWPOINT_QUIT event.

        """
        evt = messenger.EVT("VIEWPOINT_QUIT")

        self.log.debug("viewpointQuit: instructing viewpoint to quit.")
        resp = messenger.eventutils.send_await(evt)

        return resp
    def getBrowserUri(self):
        """Called to recover where the viewpoint browser is looking currently.

        This method sends the VIEWPOINT_GET_URI event and
        returns its response.

        """
        evt = messenger.EVT("VIEWPOINT_GET_URI")

        resp = messenger.eventutils.send_await(evt)

        self.log.info("getBrowserUri: returned '%s'." % (resp))

        return resp
    def setBrowserUri(self, uri):
        """Called to the viewpoint browser which URI to load.

        This method sends the VIEWPOINT_SET_URI event along
        with the new_uri and returns its response.

        """
        evt = messenger.EVT("VIEWPOINT_SET_URI")

        self.log.debug("setBrowserUri: sending new uri '%s'." % (uri))

        resp = messenger.eventutils.send_await(evt, dict(uri=uri))

        self.log.info("setBrowserUri: returned '%s'." % (resp))

        return resp
    def replaceContent(self, content_id, content):
        """Called to replace content inside the viewpoint browser with
        the given content fragment.

        This method sends the VIEWPOINT_REPLACE event along
        with the content_id & content returning its response.

        """
        evt = messenger.EVT("VIEWPOINT_REPLACE")

        self.log.debug("replaceContent: replacing content_id '%s'." %
                       (content_id))

        resp = messenger.eventutils.send_await(
            evt, dict(content_id=content_id, content=content))

        self.log.info("replaceContent: returned '%s'." % (resp))

        return resp
Exemplo n.º 11
0
    def setup(self):
        """
        Called to set up the signal handlers which subscribe to all the
        events this class currently supports.

        """
        # Register a quick event to check if the director is present
        # and responding on the message bus.
        dispatcher.connect(
            self.signalPing,
            signal=messenger.EVT("EVT_DIRECTOR_PING")
        )

        dispatcher.connect(
            self.signalControllerState,
            signal=messenger.EVT("EVT_DIRECTOR_CTRLSTATE")
        )

        dispatcher.connect(
            self.signalControllerStart,
            signal=messenger.EVT("EVT_DIRECTOR_CTRLSTART")
        )

        dispatcher.connect(
            self.signalControllerStop,
            signal=messenger.EVT("EVT_DIRECTOR_CTRLSTOP")
        )

        dispatcher.connect(
            self.signalControllerReload,
            signal=messenger.EVT("EVT_DIRECTOR_CTRLRELOAD")
        )

        dispatcher.connect(
            self.signalConfiguration,
            signal=messenger.EVT("EVT_DIRECTOR_CONFIGURATION")
        )

        # Register messenger hook for shutdown()
        dispatcher.connect(
            self.signalExit,
            signal=messenger.EVT("EVT_DIRECTOR_EXIT_ALL")
        )

        self.log.info("signalSetup: signals set up ok.")
Exemplo n.º 12
0
    def xmlrpc_dispatch(self, reply_evt, data):
        """Dispatch the given data as a reply event.
        """
        self.log.debug("xmlrpc_dispatch: sending reply event '%s' with data '%s'" % (reply_evt, data))

        if self.testing:
            self.log.debug("xmlrpc_dispatch: Send disabled in testing mode.")
        else:
            reply = messenger.EVT(reply_evt)

            #This would require the waiting source to reply confirming receipt:
            #self.log.debug("xmlrpc_dispatch: sending, waiting for confirmation receipt.")
            # messenger.send_await(reply, data)

            # This will just send without waiting.
            self.log.debug("xmlrpc_dispatch: sending (no reply looked for)")
            messenger.send(reply, data)

            self.log.debug("xmlrpc_dispatch: sending (no reply looked for - SENT OK")

        return 0
Exemplo n.º 13
0
    def controllerReload(self, name, new_config, timeout=DEFAULT_TIMEOUT):
        """
        Called to tell a controller reload and use the new
        configuration.

        This will stop it if its running, tear it down and replace
        it with whatever the new_config contains.

        :param name: This will contain the name of the controller
        to be started. This name is the same name as that in the
        configuration section.

        :param new_config: This is any valid controller
        configuration

        :param timeout: This is the amount of time (in seconds)
        used to wait for the director to respond. If a response
        isn't received within this then SignalTimeout will be
        raised.

        :returns: See SignalReceiver controllerReload.

        Event Dispatched: EVT_DIRECTOR_CTRLRELOAD

        """
        sig = messenger.EVT("EVT_DIRECTOR_CTRLRELOAD")
        try:
            self.log.debug("controllerReload: (request sig id %s) calling reload." % sig.uid)
            rc = messenger.send_await(sig, [name, new_config], timeout=timeout)

        except messenger.EventTimeout:
            self.log.error("controllerReload: (request sig id %s) event timeout!" % sig.uid)
            raise SignalTimeout("Director communication timeout (%s)s! Is it running?" % timeout)

        else:
            self.log.debug("controllerReload: (reply for sig id %s) reload called ok." % sig.uid)
            rc = rc['data']

        return rc
Exemplo n.º 14
0
 def sendexit(data):
     self.log.debug("xmlrpc_exitall: sending EVT_DIRECTOR_EXIT_ALL to the director.")
     messenger.send(messenger.EVT('EVT_DIRECTOR_EXIT_ALL'), {})
     self.log.debug("xmlrpc_exitall: sent EVT_DIRECTOR_EXIT_ALL OK.")