Пример #1
0
def _coro_emitter(front_url, login, password, envelope_id, loop):
    """Send the replay request to Xbus.

    @return The envelope ID and logs.
    @rtype (envelope-ID, log list) tuple.
    """

    logs = []

    logs.append('Establishing RPC connection...')
    client = yield from rpc.connect_rpc(connect=front_url, loop=loop)
    logs.append('RPC connection OK')
    token = yield from client.call.login(login, password)
    logs.append('Got connection token: %s' % token)

    yield from client.call.replay_envelope(token, envelope_id)
    logs.append('Request to replay the envelope %s sent' % envelope_id)

    yield from client.call.logout(token)
    logs.append('Logged out; terminating')

    client.close()
    logs.append('Done.')

    return envelope_id, logs
Пример #2
0
def _coro_emitter(front_url, login, password, envelope_id, loop):
    """Send the replay request to Xbus.

    @return The envelope ID and logs.
    @rtype (envelope-ID, log list) tuple.
    """

    logs = []

    logs.append('Establishing RPC connection...')
    client = yield from rpc.connect_rpc(connect=front_url, loop=loop)
    logs.append('RPC connection OK')
    token = yield from client.call.login(login, password)
    logs.append('Got connection token: %s' % token)

    yield from client.call.replay_envelope(token, envelope_id)
    logs.append('Request to replay the envelope %s sent' % envelope_id)

    yield from client.call.logout(token)
    logs.append('Logged out; terminating')

    client.close()
    logs.append('Done.')

    return envelope_id, logs
Пример #3
0
def coro_emitter(front_url: str, login: str, password: str, nb_envelopes: int,
                 nb_items: int, loop):
    print("Establishing RPC connection...")
    client = yield from rpc.connect_rpc(connect=front_url, loop=loop)
    print("RPC connection OK")

    token = yield from client.call.login(login, password)
    if not token:
        # The Xbus front-end returns an empty token when validation fails.
        # TODO Raise an exception?
        print("Validation failed; check the login and password.")
        client.close()
        return
    print("Got connection token:", token)

    for _ in range(nb_envelopes):
        envelope_id = yield from client.call.start_envelope(token)
        print("Started envelope:", envelope_id)
        event_id = yield from client.call.start_event(token, envelope_id,
                                                      'test_event', 0)
        print("Started event:", event_id)
        print("Sending {} items...".format(nb_items))
        for i in range(nb_items):
            yield from client.call.send_item(token, envelope_id, event_id,
                                             b'data' + str(i).encode())
        print("Sent {} items".format(nb_items))
        yield from client.call.end_event(token, envelope_id, event_id)
        print("Ended event:", event_id)
        yield from client.call.end_envelope(token, envelope_id)
        print("Ended envelope:", envelope_id)

    yield from client.call.logout(token)
    print("Logged out; terminating.")

    client.close()
Пример #4
0
 def start(self):
     self.client = yield from rpc.connect_rpc(connect=self.back_url,
                                              loop=self.loop)
     self.token = yield from self.client.call.login(self.login,
                                                    self.password)
     res = yield from self.client.call.register_node(self.token, self.url)
     server = yield from rpc.serve_rpc(self, bind=self.url, loop=self.loop)
     return server
Пример #5
0
def replay_client(port):
    """Create an RPC client to request raw/event data and send unblock requests.

    :param port: server port.
    """
    client = yield from rpc.connect_rpc(
        connect='tcp://127.0.0.1:{}'.format(port),
        translation_table=translation_table)
    return client
Пример #6
0
def replay_client(port):
    """Create an RPC client to request raw/event data and send unblock requests.

    :param port: server port.
    """
    client = yield from rpc.connect_rpc(
        connect='tcp://127.0.0.1:{}'.format(port),
        translation_table=translation_table
    )
    return client
Пример #7
0
    def initialize_zmq():
        """
        Setup and initialize the ZeroMQ DEALER/ROUTER connectivity to
        both librarian and workflow broker services.
        """

        librarian, brokers = setup_zeromq(config, logger)

        logger.info('Connecting to ZeroMQ librarian at \'{}\'.'
                    .format(librarian))

        logger.info('Connecting to ZeroMQ brokers at \'{}\'.'
                    .format(','.join(brokers)))

        librarian, broker = yield from concurrent((
            rpc.connect_rpc(connect=librarian),
            rpc.connect_rpc(connect=brokers)
        ))

        return librarian, broker
Пример #8
0
    def __async_call(self, function_name, *args, **kwargs):
        """
        Runs the rpc call in coroutine.
        """

        client = yield from rpc.connect_rpc(connect=self.uri,
                                            timeout=self.timeout)
        result = yield from client.call.__getattr__(function_name)(*args,
                                                                   **kwargs)

        return result
Пример #9
0
    def __async_call(self, function_name, *args, **kwargs):
        """
        Runs the rpc call in coroutine.
        """

        client = yield from rpc.connect_rpc(
            connect=self.uri,
            timeout=self.timeout
        )
        result = yield from client.call.__getattr__(
            function_name
        )(*args, **kwargs)

        return result
Пример #10
0
def log(idb, host, dt, name):
    dev = yield from rpc.connect_rpc(connect="tcp://%s:6881" % host)
    keys = yield from dev.call.keys()
    logger.info("have: %s", [wlm_constants.cmi_rev.get(k, k) for k in keys])
    keys = "Pressure Temperature".split()
    keys += ["Wavelength%i" % i for i in range(1, 9)]
    while True:
        dati = yield from dev.call.get_many(keys)
        t0 = time.time()
        dat = {
            k.lower(): d
            for k, (t, m, i, d) in dati.items() if d >= 0 and t > t0 - dt
        }
        if dat:
            logger.info("%s", dat)
            idb.write_row(name, **dat)
        yield from asyncio.sleep(dt)
Пример #11
0
    def initialize_zmq():
        """
        Setup and initialize the ZeroMQ connectivity.
        """

        broker, engine = setup_zeromq(config, logger)

        logger.info('Binding ZeroMQ broker service at \'{}\'.'
                    .format(broker))
        logger.info('Connecting to ZeroMQ engine at \'{}\'.'
                    .format(','.join(engine)))

        engine = yield from rpc.connect_rpc(bind=engine)
        broker_handler = BrokerHandler(config, logger, engine, directory)
        broker = yield from rpc.serve_rpc(broker_handler, bind=broker,
                                          log_exceptions=True)

        return broker, engine
Пример #12
0
def _send_item_request_(front_url, login, password, data, loop):
    """Send a data clearing item request to Xbus.
    :param data: Data (of any type) to send to the Xbus consumer.
    :return: The result of an "end_event" Xbus API call.
    """

    log.debug('Establishing RPC connection...')
    client = yield from rpc.connect_rpc(connect=front_url, loop=loop)
    log.debug('RPC connection OK')
    token = yield from client.call.login(login, password)
    log.debug('Got connection token: %s', token)

    envelope_id = yield from client.call.start_envelope(token)
    log.debug('Envelope created: %s', envelope_id)

    event_id = yield from client.call.start_event(token, envelope_id,
                                                  DATA_CLEARING_EVENT_TYPE, 0)
    log.debug('Event created: %s', event_id)

    yield from client.call.send_item(
        token,
        envelope_id,
        event_id,
        msgpack.packb(data, use_bin_type=True),
    )
    log.debug('Data sent (event ID: %s)', event_id)

    ret = yield from client.call.end_event(token, envelope_id, event_id)
    log.debug('Event %s done: return value: %s', event_id, ret)

    yield from client.call.end_envelope(token, envelope_id)
    log.debug('Envelope %s closed', envelope_id)

    yield from client.call.logout(token)
    log.debug('Logged out; terminating')

    client.close()
    log.debug('Done.')

    return ret
Пример #13
0
def _request_consumers(front_url, login, password, loop):
    """Ask Xbus for the list of consumers.

    :return: List of 2-element tuples (metadata dict, feature dict).
    """

    log.debug('Establishing RPC connection...')
    client = yield from rpc.connect_rpc(connect=front_url, loop=loop)
    log.debug('RPC connection OK')
    token = yield from client.call.login(login, password)
    log.debug('Got connection token: %s', token)

    consumers = yield from client.call.get_consumers(token)
    log.debug('Got the consumer list: %s', consumers)

    yield from client.call.logout(token)
    log.debug('Logged out; terminating')

    client.close()
    log.debug('Done.')

    return consumers
Пример #14
0
def _send_item_request_(front_url, login, password, data, loop):
    """Send a data clearing item request to Xbus.
    :param data: Data (of any type) to send to the Xbus consumer.
    :return: The result of an "end_event" Xbus API call.
    """

    log.debug('Establishing RPC connection...')
    client = yield from rpc.connect_rpc(connect=front_url, loop=loop)
    log.debug('RPC connection OK')
    token = yield from client.call.login(login, password)
    log.debug('Got connection token: %s', token)

    envelope_id = yield from client.call.start_envelope(token)
    log.debug('Envelope created: %s', envelope_id)

    event_id = yield from client.call.start_event(
        token, envelope_id, DATA_CLEARING_EVENT_TYPE, 0
    )
    log.debug('Event created: %s', event_id)

    yield from client.call.send_item(
        token, envelope_id, event_id,
        msgpack.packb(data, use_bin_type=True),
    )
    log.debug('Data sent (event ID: %s)', event_id)

    ret = yield from client.call.end_event(token, envelope_id, event_id)
    log.debug('Event %s done: return value: %s', event_id, ret)

    yield from client.call.end_envelope(token, envelope_id)
    log.debug('Envelope %s closed', envelope_id)

    yield from client.call.logout(token)
    log.debug('Logged out; terminating')

    client.close()
    log.debug('Done.')

    return ret
Пример #15
0
def align_client(port):
    client = yield from rpc.connect_rpc(
        connect='tcp://127.0.0.1:{}'.format(port), )
    return client
Пример #16
0
def align_client(port):
    client = yield from rpc.connect_rpc(
        connect='tcp://127.0.0.1:{}'.format(port),
    )
    return client