Example #1
0
 def marshal(self):
     return {
         u'id': self.id,
         u'started': utcstr(self.started),
         u'stopped': utcstr(self.stopped) if self.stopped else None,
         u'config': self.config,
     }
Example #2
0
    def get_workers(self, details=None):
        """
        Returns the list of workers currently running on this node.

        :returns: List of worker processes.
        :rtype: list of dicts
        """
        now = datetime.utcnow()
        res = []
        for worker in sorted(self._workers.values(), key=lambda w: w.created):
            res.append({
                'id':
                worker.id,
                'pid':
                worker.pid,
                'type':
                worker.TYPE,
                'status':
                worker.status,
                'created':
                utcstr(worker.created),
                'started':
                utcstr(worker.started),
                'startup_time':
                (worker.started -
                 worker.created).total_seconds() if worker.started else None,
                'uptime':
                (now -
                 worker.started).total_seconds() if worker.started else None,
            })
        return res
Example #3
0
    def marshal(self):
        if self._started:
            if self._ended:
                runtime = (self._ended - self._started).total_seconds()
            else:
                runtime = (datetime.utcnow() - self._started).total_seconds()
        else:
            runtime = None

        data = {
            u'id': self._trace_id,
            u'node_id': self._session._node_id,
            u'worker_id': self._session._worker_id,
            u'persistent_id': self._persistent_id,
            u'status': self._status,
            u'started': util.utcstr(self._started) if self._started else None,
            u'ended': util.utcstr(self._ended) if self._ended else None,
            u'runtime': runtime,
            u'options': {
                u'trace_level': self._trace_level,
                u'trace_app_payload': self._trace_app_payload,
                u'batching_period': self._batching_period,
                u'persist': self._persist,
                u'duration': self._duration,
                u'limit': self._limit
            },
            u'next_period': self._period,
            u'next_seq': self._seq,
        }
        return data
Example #4
0
    def get_worker(self, id, details=None):
        if id not in self._workers:
            emsg = "No worker with ID '{}'".format(id)
            raise ApplicationError(u'crossbar.error.no_such_worker', emsg)

        now = datetime.utcnow()
        worker = self._workers[id]

        worker_info = {
            u'id':
            worker.id,
            u'pid':
            worker.pid,
            u'type':
            worker.TYPE,
            u'status':
            worker.status,
            u'created':
            utcstr(worker.created),
            u'started':
            utcstr(worker.started),
            u'startup_time':
            (worker.started -
             worker.created).total_seconds() if worker.started else None,
            u'uptime':
            (now - worker.started).total_seconds() if worker.started else None,
        }

        return worker_info
Example #5
0
    def get_worker(self, worker_id, include_stats=False, details=None):
        """
        Return detailed information about worker.

        :param worker_id: ID of worker to get information for.
        :type worker_id: str

        :param include_stats: If true, include worker run-time statistics.
        :type include_stats: bool
        """
        if worker_id not in self._workers:
            emsg = "No worker with ID '{}'".format(worker_id)
            raise ApplicationError(u'crossbar.error.no_such_worker', emsg)

        now = datetime.utcnow()
        worker = self._workers[worker_id]

        worker_info = {
            u'id': worker.id,
            u'pid': worker.pid,
            u'type': worker.TYPE,
            u'status': worker.status,
            u'created': utcstr(worker.created),
            u'started': utcstr(worker.started),
            u'startup_time': (worker.started - worker.created).total_seconds() if worker.started else None,
            u'uptime': (now - worker.started).total_seconds() if worker.started else None,
        }

        if include_stats:
            stats = {
                u'controller_traffic': worker.get_stats()
            }
            worker_info[u'stats'] = stats

        return worker_info
Example #6
0
 def marshal(self):
     return {
         u'id': self.id,
         u'started': utcstr(self.started),
         u'stopped': utcstr(self.stopped) if self.stopped else None,
         u'config': self.config,
     }
Example #7
0
    def get_worker(self, worker_id, include_stats=False, details=None):
        """
        Return detailed information about worker.

        :param worker_id: ID of worker to get information for.
        :type worker_id: str

        :param include_stats: If true, include worker run-time statistics.
        :type include_stats: bool
        """
        if worker_id not in self._workers:
            emsg = "No worker with ID '{}'".format(worker_id)
            raise ApplicationError(u'crossbar.error.no_such_worker', emsg)

        now = datetime.utcnow()
        worker = self._workers[worker_id]

        worker_info = {
            u'id': worker.id,
            u'pid': worker.pid,
            u'type': worker.TYPE,
            u'status': worker.status,
            u'created': utcstr(worker.created),
            u'started': utcstr(worker.started),
            u'startup_time': (worker.started - worker.created).total_seconds() if worker.started else None,
            u'uptime': (now - worker.started).total_seconds() if worker.started else None,
        }

        if include_stats:
            stats = {
                u'controller_traffic': worker.get_stats()
            }
            worker_info[u'stats'] = stats

        return worker_info
    def test_purge_on_startup_delete_expired_cookies(self):
        max_age = 300
        now = time.time()
        valid_time = util.utcstr(datetime.fromtimestamp(now))
        expired_time = util.utcstr(datetime.fromtimestamp(now - max_age - 10))

        original = [
            {
                "id": "thisIsAnID",
                "created": expired_time,
                "max_age": max_age,
                "authid": "example.authid",
                "authrole": "example.authrole",
                "authmethod": "example.authmethod"
            },
            {
                "id": "thisIsAnotherID",
                "created": valid_time,
                "max_age": max_age,
                "authid": "example.other.authid",
                "authrole": "example.other.authrole",
                "authmethod": "example.other.authmethod"
            },
            {
                "id": "thisIsAnID",
                "modified": valid_time,
                "max_age": max_age,
                "authid": "example.second.authid",
                "authrole": "example.second.authrole",
                "authmethod": "example.second.authmethod"
            }
        ]

        expected = [
            {
                "id": "thisIsAnotherID",
                "created": valid_time,
                "max_age": max_age,
                "authid": "example.other.authid",
                "authrole": "example.other.authrole",
                "authmethod": "example.other.authmethod"
            },
        ]

        with tempfile.NamedTemporaryFile() as fp:
            self.write_cookies_to_file(original, fp)

            config = {
                'store': {
                    'type': 'file',
                    'filename': fp.name,
                    'purge_on_startup': True
                }
            }

            CookieStoreFileBacked(fp.name, config)

            actual = self.read_cookies_from_file(fp)
            self.assertEqual(actual, expected)
Example #9
0
    def test_purge_on_startup_delete_expired_cookies(self):
        max_age = 300
        now = time.time()
        valid_time = util.utcstr(datetime.fromtimestamp(now))
        expired_time = util.utcstr(datetime.fromtimestamp(now - max_age - 10))

        original = [{
            "id": "thisIsAnID",
            "created": expired_time,
            "max_age": max_age,
            "authid": "example.authid",
            "authrole": "example.authrole",
            "authrealm": "example.authrealm",
            "authmethod": "example.authmethod"
        }, {
            "id": "thisIsAnotherID",
            "created": valid_time,
            "max_age": max_age,
            "authid": "example.other.authid",
            "authrole": "example.other.authrole",
            "authrealm": "example.other.authrealm",
            "authmethod": "example.other.authmethod"
        }, {
            "id": "thisIsAnID",
            "modified": valid_time,
            "max_age": max_age,
            "authid": "example.second.authid",
            "authrole": "example.second.authrole",
            "authrealm": "example.second.authrealm",
            "authmethod": "example.second.authmethod"
        }]

        expected = [
            {
                "id": "thisIsAnotherID",
                "created": valid_time,
                "max_age": max_age,
                "authid": "example.other.authid",
                "authrole": "example.other.authrole",
                "authrealm": "example.other.authrealm",
                "authmethod": "example.other.authmethod"
            },
        ]

        with tempfile.NamedTemporaryFile() as fp:
            self.write_cookies_to_file(original, fp)

            config = {
                'store': {
                    'type': 'file',
                    'filename': fp.name,
                    'purge_on_startup': True
                }
            }

            CookieStoreFileBacked(fp.name, config)

            actual = self.read_cookies_from_file(fp)
            self.assertEqual(actual, expected)
Example #10
0
 def marshal(self):
     return {
         u'id': self._transport_id,
         u'type': self._type,
         u'config': self._config,
         u'created_at': utcstr(self._created_at),
         u'listening_since': utcstr(self._listening_since) if self._listening_since else None,
         u'state': self._state,
     }
Example #11
0
 def marshal(self):
     return {
         'id': self._transport_id,
         'type': self._type,
         'config': self._config,
         'created_at': utcstr(self._created_at),
         'listening_since': utcstr(self._listening_since) if self._listening_since else None,
         'state': self._state,
     }
 def getSystemStatus(self):
    """
    Get system status.
    """
    now = datetime.datetime.utcnow()
    booted = self.services["platform"].getBoottime()
    started = self.services["master"].started
    r = {"booted": utcstr(booted),
         "booted-ago": int(round((now - booted).total_seconds())),
         "started": utcstr(started),
         "started-ago": int(round((now - started).total_seconds()))
         }
    return r
Example #13
0
        def marshal(self):
            """
            Marshal object information for use with WAMP calls/events.

            :returns: dict -- The marshalled information.
            """
            now = datetime.utcnow()
            return {
                u'created': utcstr(self.created),
                u'status': self.status,
                u'started': utcstr(self.started) if self.started else None,
                u'uptime': (now - self.started).total_seconds() if self.started else None,
                u'config': self.config
            }
Example #14
0
 def getSystemStatus(self):
     """
   Get system status.
   """
     now = datetime.datetime.utcnow()
     booted = self.services["platform"].getBoottime()
     started = self.services["master"].started
     r = {
         "booted": utcstr(booted),
         "booted-ago": int(round((now - booted).total_seconds())),
         "started": utcstr(started),
         "started-ago": int(round((now - started).total_seconds()))
     }
     return r
Example #15
0
        def on_ready_success(worker_id):
            self.log.info('{worker_type} worker "{worker_id}" process {pid} started',
                          worker_type=worker_logname, worker_id=worker.id, pid=worker.pid)

            self._node._reactor.addSystemEventTrigger(
                'before', 'shutdown',
                self._cleanup_worker, self._node._reactor, worker,
            )

            worker.on_worker_started()

            started_info = {
                u'id': worker.id,
                u'status': worker.status,
                u'started': utcstr(worker.started),
                u'who': worker.who,
            }

            # FIXME: make start of stats printer dependent on log level ..
            if False:
                worker.log_stats(5.)

            self.publish(started_topic, started_info, options=PublishOptions(exclude=details.caller))

            return started_info
Example #16
0
        def on_ready_success(id):
            log.msg("{} with ID '{}' and PID {} started".format(
                worker_logname, worker.id, worker.pid))

            def cleanup_worker():
                try:
                    worker.proto.transport.signalProcess('TERM')
                except ProcessExitedAlready:
                    pass  # ignore; it's already dead

            self._node._reactor.addSystemEventTrigger(
                'before',
                'shutdown',
                cleanup_worker,
            )

            worker.status = 'started'
            worker.started = datetime.utcnow()

            started_info = {
                'id': worker.id,
                'status': worker.status,
                'started': utcstr(worker.started),
                'who': worker.who
            }

            self.publish(started_topic,
                         started_info,
                         options=PublishOptions(exclude=[details.caller]))

            return started_info
Example #17
0
    def _clean_cookie_file(self):
        with open(self._cookie_file_name, 'w') as cookie_file:
            for cbtid, cookie in self._cookies.items():
                expiration_delta = datetime.timedelta(
                    seconds=int(cookie['max_age']))
                upper_limit = util.utcstr(datetime.datetime.now() -
                                          expiration_delta)
                if cookie['created'] < upper_limit:
                    # This cookie is expired, discard
                    continue

                cookie_record = json.dumps({
                    'id': cbtid,
                    'created': cookie['created'],
                    'max_age': cookie['max_age'],
                    'authid': cookie['authid'],
                    'authrole': cookie['authrole'],
                    'authmethod': cookie['authmethod'],
                    'authrealm': cookie['authrealm'],
                    'authextra': cookie['authextra'],
                }) + '\n'
                cookie_file.write(cookie_record)

            cookie_file.flush()
            os.fsync(cookie_file.fileno())
Example #18
0
        def on_ready_success(id):
            self.log.info("{worker} with ID '{id}' and PID {pid} started",
                          worker=worker_logname, id=worker.id, pid=worker.pid)

            self._node._reactor.addSystemEventTrigger(
                'before', 'shutdown',
                self._cleanup_worker, self._node._reactor, worker,
            )

            worker.status = 'started'
            worker.started = datetime.utcnow()

            started_info = {
                'id': worker.id,
                'status': worker.status,
                'started': utcstr(worker.started),
                'who': worker.who
            }

            # FIXME: make start of stats printer dependent on log level ..
            worker.log_stats(5.)

            self.publish(started_topic, started_info, options=PublishOptions(exclude=[details.caller]))

            return started_info
Example #19
0
        def on_ready_success(worker_id):
            self.log.info(
                '{worker_type} worker "{worker_id}" process {pid} started',
                worker_type=worker_logname,
                worker_id=worker.id,
                pid=worker.pid)

            self._node._reactor.addSystemEventTrigger(
                'before',
                'shutdown',
                self._cleanup_worker,
                self._node._reactor,
                worker,
            )

            worker.on_worker_started()

            started_info = {
                u'id': worker.id,
                u'status': worker.status,
                u'started': utcstr(worker.started),
                u'who': worker.who,
            }

            # FIXME: make start of stats printer dependent on log level ..
            if False:
                worker.log_stats(5.)

            self.publish(started_topic,
                         started_info,
                         options=PublishOptions(exclude=details.caller))

            return started_info
Example #20
0
        def on_ready_success(id):
            log.msg("{} with ID '{}' and PID {} started".format(worker_logname, worker.id, worker.pid))

            def cleanup_worker():
                try:
                    worker.proto.transport.signalProcess('TERM')
                except ProcessExitedAlready:
                    pass  # ignore; it's already dead

            self._node._reactor.addSystemEventTrigger(
                'before', 'shutdown',
                cleanup_worker,
            )

            worker.status = 'started'
            worker.started = datetime.utcnow()

            started_info = {
                'id': worker.id,
                'status': worker.status,
                'started': utcstr(worker.started),
                'who': worker.who
            }

            self.publish(started_topic, started_info, options=PublishOptions(exclude=[details.caller]))

            return started_info
Example #21
0
        def on_ready_success(id):
            self.log.info(
                "{worker} with ID '{id}' and PID {pid} started", worker=worker_logname, id=worker.id, pid=worker.pid
            )

            self._node._reactor.addSystemEventTrigger(
                "before", "shutdown", self._cleanup_worker, self._node._reactor, worker
            )

            worker.status = "started"
            worker.started = datetime.utcnow()

            started_info = {
                u"id": worker.id,
                u"status": worker.status,
                u"started": utcstr(worker.started),
                u"who": worker.who,
            }

            # FIXME: make start of stats printer dependent on log level ..
            worker.log_stats(5.0)

            self.publish(started_topic, started_info, options=PublishOptions(exclude=details.caller))

            return started_info
Example #22
0
    def _batch_loop(self):

        period = {
            u'finished_ts': time_ns(),
            u'finished_pc': perf_counter_ns(),
            u'period': self._period,
            u'period_start': util.utcstr(self._period_ts),
        }

        current_batch = self._current_batch

        if current_batch:
            period[u'first_seq'] = current_batch[0].seq
            period[u'last_seq'] = current_batch[-1].seq
        else:
            period[u'first_seq'] = None
            period[u'last_seq'] = None

        # fire user callback with current batch
        if self._on_trace_period_finished:
            self._on_trace_period_finished(self._trace_id, period, current_batch)

        # append current batch to history
        self._trace.append((period, current_batch))

        # next period
        self._period += 1
        self._period_ts = datetime.utcnow()
        if current_batch:
            self._current_batch = []
Example #23
0
    def get_router_transports(self, details=None):
        """
        List currently running transports.

        **Usage:**

        This procedure is registered under

        * ``crossbar.node.<node_id>.worker.<worker_id>.get_router_transports``

        :returns: List of transports currently running.
        :rtype: list of dict
        """
        self.log.debug("{}.get_router_transports".format(
            self.__class__.__name__))

        res = []
        for transport in sorted(self.transports.values(),
                                key=lambda c: c.created):
            res.append({
                'id': transport.id,
                'created': utcstr(transport.created),
                'config': transport.config,
            })
        return res
Example #24
0
        def on_ready_success(id):
            self.log.info("{worker} with ID '{id}' and PID {pid} started",
                          worker=worker_logname,
                          id=worker.id,
                          pid=worker.pid)

            self._node._reactor.addSystemEventTrigger(
                'before',
                'shutdown',
                self._cleanup_worker,
                self._node._reactor,
                worker,
            )

            worker.status = 'started'
            worker.started = datetime.utcnow()

            started_info = {
                'id': worker.id,
                'status': worker.status,
                'started': utcstr(worker.started),
                'who': worker.who
            }

            # FIXME: make start of stats printer dependent on log level ..
            worker.log_stats(5.)

            self.publish(started_topic,
                         started_info,
                         options=PublishOptions(exclude=[details.caller]))

            return started_info
Example #25
0
        def _poll(current, last_value):

            # normalize with effective period
            diff = 1.
            if self._last_period:
                diff = self._last_period / 10**9

            # cmd_started = time.time()

            current['type'] = self._worker_type
            current['pid'] = self._p.pid
            current['status'] = self._p.status()

            if verbose:
                current['exe'] = self._p.exe()
                current['user'] = self._p.username()
                current['name'] = self._p.name()
                current['cmdline'] = ' '.join(self._p.cmdline())
                created = self._p.create_time()
                current['created'] = utcstr(datetime.datetime.fromtimestamp(created))

            current['num_fds'] = self._p.num_fds()
            current['num_threads'] = self._p.num_threads()
            current['num_fds'] = self._p.num_fds()

            # the following values are cumulative since process creation!
            #
            num_ctx_switches = self._p.num_ctx_switches()
            current['num_ctx_switches_voluntary'] = num_ctx_switches.voluntary
            current['num_ctx_switches_involuntary'] = num_ctx_switches.involuntary

            if self._has_io_counters:
                iocounters = self._p.io_counters()
                current['read_ios'] = iocounters.read_count
                current['write_ios'] = iocounters.write_count
                current['read_bytes'] = iocounters.read_bytes
                current['write_bytes'] = iocounters.write_bytes
            else:
                current['read_ios'] = None
                current['write_ios'] = None
                current['read_bytes'] = None
                current['write_bytes'] = None

            cpu = self._p.cpu_times()
            current['cpu_user'] = cpu.user
            current['cpu_system'] = cpu.system

            # current['command_duration'] = time.time() - cmd_started

            for key in [
                    'read_ios', 'write_ios', 'read_bytes', 'write_bytes', 'cpu_user', 'cpu_system',
                    'num_ctx_switches_voluntary', 'num_ctx_switches_involuntary'
            ]:
                if last_value and last_value[key] is not None:
                    value = float(current[key] - last_value[key]) / diff
                    current['{}_per_sec'.format(key)] = int(value)

            return current
Example #26
0
        def _poll(current, last_value):

            # normalize with effective period
            diff = 1.
            if self._last_period:
                diff = self._last_period / 10**9

            # cmd_started = time.time()

            current['type'] = self._worker_type
            current['pid'] = self._p.pid
            current['status'] = self._p.status()

            if verbose:
                current['exe'] = self._p.exe()
                current['user'] = self._p.username()
                current['name'] = self._p.name()
                current['cmdline'] = ' '.join(self._p.cmdline())
                created = self._p.create_time()
                current['created'] = utcstr(datetime.datetime.fromtimestamp(created))

            current['num_fds'] = self._p.num_fds()
            current['num_threads'] = self._p.num_threads()
            current['num_fds'] = self._p.num_fds()

            # the following values are cumulative since process creation!
            #
            num_ctx_switches = self._p.num_ctx_switches()
            current['num_ctx_switches_voluntary'] = num_ctx_switches.voluntary
            current['num_ctx_switches_involuntary'] = num_ctx_switches.involuntary

            if self._has_io_counters:
                iocounters = self._p.io_counters()
                current['read_ios'] = iocounters.read_count
                current['write_ios'] = iocounters.write_count
                current['read_bytes'] = iocounters.read_bytes
                current['write_bytes'] = iocounters.write_bytes
            else:
                current['read_ios'] = None
                current['write_ios'] = None
                current['read_bytes'] = None
                current['write_bytes'] = None

            cpu = self._p.cpu_times()
            current['cpu_user'] = cpu.user
            current['cpu_system'] = cpu.system

            # current['command_duration'] = time.time() - cmd_started

            for key in [
                'read_ios', 'write_ios', 'read_bytes', 'write_bytes', 'cpu_user',
                'cpu_system', 'num_ctx_switches_voluntary', 'num_ctx_switches_involuntary'
            ]:
                if last_value and last_value[key] is not None:
                    value = float(current[key] - last_value[key]) / diff
                    current['{}_per_sec'.format(key)] = int(value)

            return current
Example #27
0
      def on_ready_success(proto):

         worker.pid = proto.transport.pid
         worker.status = 'started'
         worker.started = datetime.utcnow()

         log.msg("{} with ID '{}' and PID {} started".format(worker_logname, worker.id, worker.pid))


         ## directory watcher
         ##
         if 'watch' in options:

            if HAS_FSNOTIFY:

               ## assemble list of watched directories
               watched_dirs = []
               for d in options['watch'].get('directories', []):
                  watched_dirs.append(os.path.abspath(os.path.join(self._node._cbdir, d)))

               ## create a directory watcher
               worker.watcher = DirWatcher(dirs = watched_dirs, notify_once = True)

               ## make sure to stop the background thread running inside the
               ## watcher upon Twisted being shut down
               def on_shutdown():
                  worker.watcher.stop()

               reactor.addSystemEventTrigger('before', 'shutdown', on_shutdown)

               ## this handler will get fired by the watcher upon detecting an FS event
               def on_fsevent(evt):
                  worker.watcher.stop()
                  proto.signal('TERM')

                  if options['watch'].get('action', None) == 'restart':
                     log.msg("Restarting guest ..")
                     reactor.callLater(0.1, self.start_guest, id, config, details)

               ## now run the watcher on a background thread
               deferToThread(worker.watcher.loop, on_fsevent)

            else:
               log.msg("Warning: cannot watch directory for changes - feature DirWatcher unavailable")


         ## assemble guest worker startup information
         ##
         started_info = {
            'id': worker.id,
            'status': worker.status,
            'started': utcstr(worker.started),
            'who': worker.who
         }

         self.publish(started_topic, started_info, options = PublishOptions(exclude = [details.caller]))

         return started_info
Example #28
0
    def started(self, details=None):
        """
        Return start time of this process.

        :returns str -- Start time (UTC) in UTC ISO 8601 format.
        """
        self.log.debug("{cls}.started", cls=self.__class__.__name__)

        return utcstr(self._started)
Example #29
0
    def started(self, details=None):
        """
        Return start time of this process.

        :returns str -- Start time (UTC) in UTC ISO 8601 format.
        """
        self.log.debug("{cls}.started", cls=self.__class__.__name__)

        return utcstr(self._started)
Example #30
0
 def marshal(self):
     return {
         u'id': self.id,
         u'config': self.config,
         u'created': utcstr(self.created),
         u'roles': self.roles,
         u'has_router': self.router is not None,
         u'has_service_session': self.session is not None,
     }
Example #31
0
    def get_router_components(self, details=None):
        """
        List application components currently running (embedded) in this router.
        """
        self.log.debug("{}.get_router_components".format(self.__class__.__name__))

        res = []
        for component in sorted(self.components.values(), key=lambda c: c.created):
            res.append({"id": component.id, "created": utcstr(component.created), "config": component.config})
        return res
Example #32
0
   def started(self, details = None):
      """
      Return start time of this process.

      :returns str -- Start time (UTC) in UTC ISO 8601 format.
      """
      if self.debug:
         log.msg("{}.started".format(self.__class__.__name__))

      return utcstr(self._started)
Example #33
0
    def started(self, details=None):
        """
        Return start time of this process.

        :returns str -- Start time (UTC) in UTC ISO 8601 format.
        """
        if self.debug:
            log.msg("{}.started".format(self.__class__.__name__))

        return utcstr(self._started)
Example #34
0
 def marshal(self):
     """
     Marshal object information for use with WAMP calls/events.
     """
     now = datetime.utcnow()
     return {
         u'id': self.id,
         u'started': utcstr(self.started),
         u'uptime': (now - self.started).total_seconds(),
         u'config': self.config
     }
Example #35
0
 def marshal(self):
     """
     Marshal object information for use with WAMP calls/events.
     """
     now = datetime.utcnow()
     return {
         u'id': self.id,
         u'started': utcstr(self.started),
         u'uptime': (now - self.started).total_seconds(),
         u'config': self.config
     }
Example #36
0
    def get_worker(self, id, details=None):
        if id not in self._workers:
            emsg = "No worker with ID '{}'".format(id)
            raise ApplicationError(u'crossbar.error.no_such_worker', emsg)

        now = datetime.utcnow()
        worker = self._workers[id]

        worker_info = {
            u'id': worker.id,
            u'pid': worker.pid,
            u'type': worker.TYPE,
            u'status': worker.status,
            u'created': utcstr(worker.created),
            u'started': utcstr(worker.started),
            u'startup_time': (worker.started - worker.created).total_seconds() if worker.started else None,
            u'uptime': (now - worker.started).total_seconds() if worker.started else None,
        }

        return worker_info
Example #37
0
 def marshal(self):
     """
     Marshal object information for use with WAMP calls/events.
     """
     now = datetime.utcnow()
     return {
         "id": self.id,
         "started": utcstr(self.started),
         "uptime": (now - self.started).total_seconds(),
         "config": self.config,
     }
Example #38
0
    def get_workers(self, details=None):
        """
        Returns the list of processes currently running on this node.

        :returns: list -- List of worker processes.
        """
        now = datetime.utcnow()
        res = []
        for worker in sorted(self._workers.values(), key=lambda w: w.created):
            res.append({
                'id': worker.id,
                'pid': worker.pid,
                'type': worker.TYPE,
                'status': worker.status,
                'created': utcstr(worker.created),
                'started': utcstr(worker.started),
                'startup_time': (worker.started - worker.created).total_seconds() if worker.started else None,
                'uptime': (now - worker.started).total_seconds() if worker.started else None,
            })
        return res
Example #39
0
    def stop_container_component(self, id, details=None):
        """
        Stop a component currently running within this container.

        :param id: The ID of the component to stop.
        :type id: int
        :param details: Caller details.
        :type details: instance of :class:`autobahn.wamp.types.CallDetails`

        :returns dict -- A dict with component start information.
        """
        if id not in self.components:
            raise ApplicationError(
                'crossbar.error.no_such_object',
                'no component with ID {} running in this container'.format(id))

        now = datetime.utcnow()

        # FIXME: should we session.leave() first and only close the transport then?
        # This gives the app component a better hook to do any cleanup.
        self.components[id].proto.close()

        c = self.components[id]
        event = {
            'id': id,
            'started': utcstr(c.started),
            'stopped': utcstr(now),
            'uptime': (now - c.started).total_seconds()
        }

        # publish event "on_component_stop" to all but the caller
        #
        topic = 'crossbar.node.{}.worker.{}.container.on_component_stop'.format(
            self.config.extra.node, self.config.extra.worker)
        self.publish(topic,
                     event,
                     options=PublishOptions(exclude=[details.caller]))

        del self.components[id]

        return event
Example #40
0
 def marshal(self):
     """
     Marshal object information for use with WAMP calls/events.
     """
     now = datetime.utcnow()
     return {
         u'id': self.id,
         # 'started' is used by container-components; keeping it
         # for consistency in the public API
         u'started': utcstr(self.created),
         u'uptime': (now - self.created).total_seconds(),
         u'config': self.config
     }
Example #41
0
 def marshal(self):
     """
     Marshal object information for use with WAMP calls/events.
     """
     now = datetime.utcnow()
     return {
         u'id': self.id,
         # 'started' is used by container-components; keeping it
         # for consistency in the public API
         u'started': utcstr(self.created),
         u'uptime': (now - self.created).total_seconds(),
         u'config': self.config
     }
Example #42
0
    def get_router_components(self, details=None):
        """
        List application components currently running (embedded) in this router.
        """
        self.log.debug("{}.get_router_components".format(self.__class__.__name__))

        res = []
        for component in sorted(self.components.values(), key=lambda c: c.created):
            res.append({
                'id': component.id,
                'created': utcstr(component.created),
                'config': component.config,
            })
        return res
Example #43
0
    def get_workers(self, details=None):
        """
        Returns the list of workers currently running on this node.

        :returns: List of worker processes.
        :rtype: list of dicts
        """
        now = datetime.utcnow()
        res = []
        for worker in sorted(self._workers.values(), key=lambda w: w.created):
            res.append(
                {
                    u"id": worker.id,
                    u"pid": worker.pid,
                    u"type": worker.TYPE,
                    u"status": worker.status,
                    u"created": utcstr(worker.created),
                    u"started": utcstr(worker.started),
                    u"startup_time": (worker.started - worker.created).total_seconds() if worker.started else None,
                    u"uptime": (now - worker.started).total_seconds() if worker.started else None,
                }
            )
        return res
Example #44
0
    def get_router_transports(self, details=None):
        """
        List currently running transports.
        """
        self.log.debug("{}.get_router_transports".format(self.__class__.__name__))

        res = []
        for transport in sorted(self.transports.values(), key=lambda c: c.created):
            res.append({
                'id': transport.id,
                'created': utcstr(transport.created),
                'config': transport.config,
            })
        return res
Example #45
0
    def stop_container_component(self, id, details=None):
        """
        Stop a component currently running within this container.

        :param id: The ID of the component to stop.
        :type id: int
        :param details: Caller details.
        :type details: instance of :class:`autobahn.wamp.types.CallDetails`

        :returns dict -- A dict with component start information.
        """
        if id not in self.components:
            raise ApplicationError('crossbar.error.no_such_object', 'no component with ID {} running in this container'.format(id))

        now = datetime.utcnow()

        # FIXME: should we session.leave() first and only close the transport then?
        # This gives the app component a better hook to do any cleanup.
        self.components[id].proto.close()

        c = self.components[id]
        event = {
            'id': id,
            'started': utcstr(c.started),
            'stopped': utcstr(now),
            'uptime': (now - c.started).total_seconds()
        }

        # publish event "on_component_stop" to all but the caller
        #
        topic = 'crossbar.node.{}.worker.{}.container.on_component_stop'.format(self.config.extra.node, self.config.extra.worker)
        self.publish(topic, event, options=PublishOptions(exclude=[details.caller]))

        del self.components[id]

        return event
Example #46
0
    def get_router_transports(self, details=None):
        """
        List currently running transports.
        """
        if self.debug:
            log.msg("{}.get_router_transports".format(self.__class__.__name__))

        res = []
        for transport in sorted(self.transports.values(),
                                key=lambda c: c.created):
            res.append({
                'id': transport.id,
                'created': utcstr(transport.created),
                'config': transport.config,
            })
        return res
Example #47
0
      def on_ready_success(id):
         log.msg("{} with ID '{}' and PID {} started".format(worker_logname, worker.id, worker.pid))

         worker.status = 'started'
         worker.started = datetime.utcnow()

         started_info = {
            'id': worker.id,
            'status': worker.status,
            'started': utcstr(worker.started),
            'who': worker.who
         }

         self.publish(started_topic, started_info, options = PublishOptions(exclude = [details.caller]))

         return started_info
Example #48
0
    def started(self, details=None):
        """
        Return start time of this process.

        **Usage:**

        This procedure is registered under

        * ``crossbar.node.<node_id>.worker.<worker_id>.started`` for native workers and under
        * ``crossbar.node.<node_id>.controller.started`` for node controllers

        :returns: Start time (UTC) in UTC ISO 8601 format.
        :rtype: unicode
        """
        self.log.debug("{cls}.started", cls=self.__class__.__name__)

        return utcstr(self._started)
Example #49
0
    def started(self, details=None):
        """
        Return start time of this process.

        **Usage:**

        This procedure is registered under

        * ``crossbar.node.<node_id>.worker.<worker_id>.started`` for native workers and under
        * ``crossbar.node.<node_id>.controller.started`` for node controllers

        :returns: Start time (UTC) in UTC ISO 8601 format.
        :rtype: unicode
        """
        self.log.debug("{cls}.started", cls=self.__class__.__name__)

        return utcstr(self._started)
Example #50
0
    def marshal(self):
        marshalled = {
            u'id': self.id,
            u'config': self.config,
            u'created': utcstr(self.created),
            u'roles': [self.roles[role].marshal() for role in self.roles if self.roles],
            u'has_router': self.router is not None,
            u'has_service_session': self.session is not None,
        }

        rlinks = []
        for link_id in self.rlink_manager.keys():
            rlinks.append(self.rlink_manager[link_id].marshal())

        marshalled['rlinks'] = rlinks

        return marshalled
Example #51
0
    def get_router_transports(self, details=None):
        """
        Get transports currently running in this router worker.

        :returns: List of transports currently running.
        :rtype: list of dict
        """
        self.log.debug("{}.get_router_transports".format(self.__class__.__name__))

        res = []
        for transport in sorted(self.transports.values(), key=lambda c: c.created):
            res.append({
                'id': transport.id,
                'created': utcstr(transport.created),
                'config': transport.config,
            })
        return res
Example #52
0
    def get_router_transports(self, details=None):
        """
        Get transports currently running in this router worker.

        :returns: List of transports currently running.
        :rtype: list of dict
        """
        self.log.debug("{}.get_router_transports".format(self.__class__.__name__))

        res = []
        for transport in sorted(self.transports.values(), key=lambda c: c.created):
            res.append({
                'id': transport.id,
                'created': utcstr(transport.created),
                'config': transport.config,
            })
        return res
Example #53
0
    def get_router_components(self, details=None):
        """
        Get app components currently running in this router worker.

        :returns: List of app components currently running.
        :rtype: list of dict
        """
        self.log.debug("{name}.get_router_components", name=self.__class__.__name__)

        res = []
        for component in sorted(self.components.values(), key=lambda c: c.created):
            res.append({
                u'id': component.id,
                u'created': utcstr(component.created),
                u'config': component.config,
            })
        return res
Example #54
0
    def get_router_transports(self, details=None):
        """
        List currently running transports.

        **Usage:**

        This procedure is registered under

        * ``crossbar.node.<node_id>.worker.<worker_id>.get_router_transports``

        :returns: List of transports currently running.
        :rtype: list of dict
        """
        self.log.debug("{}.get_router_transports".format(self.__class__.__name__))

        res = []
        for transport in sorted(self.transports.values(), key=lambda c: c.created):
            res.append({"id": transport.id, "created": utcstr(transport.created), "config": transport.config})
        return res
Example #55
0
        def on_ready_success(id):
            log.msg("{} with ID '{}' and PID {} started".format(
                worker_logname, worker.id, worker.pid))

            worker.status = 'started'
            worker.started = datetime.utcnow()

            started_info = {
                'id': worker.id,
                'status': worker.status,
                'started': utcstr(worker.started),
                'who': worker.who
            }

            self.publish(started_topic,
                         started_info,
                         options=PublishOptions(exclude=[details.caller]))

            return started_info
Example #56
0
    def get_router_transports(self, details=None):
        """
        Get transports currently running in this router worker.

        :param details: Call details.
        :type details: autobahn.wamp.types.CallDetails

        :returns: List of transports currently running.
        :rtype: list of dict
        """
        self.log.debug("{name}.get_router_transports", name=self.__class__.__name__)

        res = []
        for transport in sorted(self.transports.values(), key=lambda c: c.created):
            res.append({
                u'id': transport.id,
                u'created': utcstr(transport.created),
                u'config': transport.config,
            })
        return res
Example #57
0
    def get_router_components(self, details=None):
        """
        Get app components currently running in this router worker.

        :param details: Call details.
        :type details: :class:`autobahn.wamp.types.CallDetails`

        :returns: List of app components currently running.
        :rtype: list[dict]
        """
        self.log.debug("{name}.get_router_components", name=self.__class__.__name__)

        res = []
        for component in sorted(self.components.values(), key=lambda c: c.created):
            res.append({
                'id': component.id,
                'created': utcstr(component.created),
                'config': component.config,
            })
        return res
Example #58
0
    def _clean_cookie_file(self):
        with open(self._cookie_file_name, 'w') as cookie_file:
            for cbtid, cookie in self._cookies.items():
                expiration_delta = datetime.timedelta(seconds=int(cookie['max_age']))
                upper_limit = util.utcstr(datetime.datetime.now() - expiration_delta)
                if cookie['created'] < upper_limit:
                    # This cookie is expired, discard
                    continue

                cookie_record = json.dumps({
                    'id': cbtid,
                    'created': cookie['created'],
                    'max_age': cookie['max_age'],
                    'authid': cookie['authid'],
                    'authrole': cookie['authrole'],
                    'authmethod': cookie['authmethod']
                }) + '\n'
                cookie_file.write(cookie_record)

            cookie_file.flush()
            os.fsync(cookie_file.fileno())