def test_messenger_create_channel():
    mock_self = Mock(
        tenants=["sample-tenant-1", "sample-tenant-2"],
        subjects={},
        global_subjects={},
        __bootstrap_tenants=Mock(),
        config=Mock(dojot={"management": {
            "tenant": "sample-mgmt-tenant"
        }}))

    Messenger.create_channel(mock_self, "sample-subject", "r", False)
    mock_self.__bootstrap_tenants.expect_called_with("sample-subject",
                                                     "sample-tenant-1", "r",
                                                     False)
    mock_self.__bootstrap_tenants.expect_called_with("sample-subject",
                                                     "sample-tenant-2", "r",
                                                     False)
    assert "sample-subject" in mock_self.subjects

    mock_self.__bootstrap_tenants.reset_mock()
    Messenger.create_channel(mock_self, "sample-subject", "r", True)
    mock_self.__bootstrap_tenants.expect_called_with("sample-subject",
                                                     "sample-mgmt-tenant", "r",
                                                     True)
    assert "sample-subject" in mock_self.global_subjects
Пример #2
0
def main():
    config = Config()
    messenger = Messenger("Dojot-Snoop", config)
    messenger.init()
    messenger.create_channel(config.dojot['subjects']['device_data'], "rw")
    messenger.create_channel(config.dojot['subjects']['tenancy'], "rw")
    messenger.create_channel(config.dojot['subjects']['devices'], "rw")

    messenger.on(config.dojot['subjects']['device_data'], "message", rcv_msg)
    messenger.on(config.dojot['subjects']['tenancy'], "message", rcv_msg)
    messenger.on(config.dojot['subjects']['devices'], "message", rcv_msg)
Пример #3
0
def main():
    """
    Main, inits mongo, messenger, create channels read channels for device
    and device-data topics and add callbacks to events related to that subjects
    """
    config = Config()
    LOGGER.debug("Initializing persister...")
    persister = Persister()
    persister.init_mongodb()
    LOGGER.debug("... persister was successfully initialized.")
    LOGGER.debug("Initializing dojot messenger...")
    messenger = Messenger("Persister", config)
    messenger.init()
    messenger.create_channel(config.dojot['subjects']['devices'], "r")
    messenger.create_channel(config.dojot['subjects']['device_data'], "r")
    messenger.on(config.dojot['subjects']['devices'], "message",
                 persister.handle_event_devices)
    messenger.on(config.dojot['subjects']['device_data'], "message",
                 persister.handle_event_data)
    LOGGER.debug("... dojot messenger was successfully initialized.")
Пример #4
0
def main():
    """
    Main, inits mongo, messenger, create channels read channels for device
    and device-data topics and add callbacks to events related to that subjects
    """
    config = Config()
    auth = Auth(config)
    LOGGER.debug("Initializing persister...")
    persister = Persister()
    persister.init_mongodb()
    persister.create_indexes_for_notifications(auth.get_tenants())
    LOGGER.debug("... persister was successfully initialized.")
    LOGGER.debug("Initializing dojot messenger...")
    messenger = Messenger("Persister", config)
    messenger.init()
    messenger.create_channel(config.dojot['subjects']['devices'], "r")
    messenger.create_channel(config.dojot['subjects']['device_data'], "r")
    # TODO: add notifications to config on dojot-module-python
    messenger.create_channel("dojot.notifications", "r")
    messenger.on(config.dojot['subjects']['devices'], "message",
                 persister.handle_event_devices)
    messenger.on(config.dojot['subjects']['device_data'], "message",
                 persister.handle_event_data)
    messenger.on(config.dojot['subjects']['tenancy'], "message",
                 persister.handle_new_tenant)
    messenger.on("dojot.notifications", "message",
                 persister.handle_notification)
    LOGGER.debug("... dojot messenger was successfully initialized.")
Пример #5
0
def start_dojot_messenger(config, persister, dojot_persist_notifications_only):

    messenger = Messenger("Persister", config)
    messenger.init()

    messenger.create_channel("dojot.notifications", "r")
    messenger.on(config.dojot['subjects']['tenancy'], "message",
                 persister.handle_new_tenant)
    LOGGER.info("Listen to tenancy events")
    messenger.on("dojot.notifications", "message",
                 persister.handle_notification)
    LOGGER.info('Listen to notification events')

    if str2_bool(dojot_persist_notifications_only) != True:

        messenger.create_channel(config.dojot['subjects']['devices'], "r")
        messenger.create_channel(config.dojot['subjects']['device_data'], "r")
        messenger.on(config.dojot['subjects']['devices'], "message",
                     persister.handle_event_devices)
        messenger.on(config.dojot['subjects']['device_data'], "message",
                     persister.handle_event_data)
        LOGGER.info("Listen to devices events")
Пример #6
0
def main():
    """
    Main, inits mongo, messenger, create channels read channels for device
    and device-data topics and add callbacks to events related to that subjects
    """
    config = Config()
    auth = Auth(config)
    LOGGER.debug("Initializing persister...")
    persister = Persister()
    persister.init_mongodb()
    persister.create_indexes_for_notifications(auth.get_tenants())
    LOGGER.debug("... persister was successfully initialized.")
    LOGGER.debug("Initializing dojot messenger...")
    messenger = Messenger("Persister", config)
    messenger.init()
    messenger.create_channel(config.dojot['subjects']['devices'], "r")
    messenger.create_channel(config.dojot['subjects']['device_data'], "r")
    # TODO: add notifications to config on dojot-module-python
    messenger.create_channel("dojot.notifications", "r")
    messenger.on(config.dojot['subjects']['devices'], "message",
                 persister.handle_event_devices)
    messenger.on(config.dojot['subjects']['device_data'], "message",
                 persister.handle_event_data)
    messenger.on(config.dojot['subjects']['tenancy'], "message",
                 persister.handle_new_tenant)
    messenger.on("dojot.notifications", "message",
                 persister.handle_notification)
    LOGGER.debug("... dojot messenger was successfully initialized.")

    # Create falcon app
    app = falcon.API()
    app.add_route('/persister/log', LoggingInterface())
    httpd = simple_server.make_server('0.0.0.0',
                                      os.environ.get("PERSISTER_PORT", 8057),
                                      app)
    httpd.serve_forever()
Пример #7
0
        'status': {
            'data': ret['data'],
            'responseType': ret['responseType']
        }
    }
    return make_response(json.dumps(resp_obj), 200)


if __name__ == '__main__':
    while True:
        try:
            # execute the EJBCA handshake and load SOAP API metadata
            initicalConf()
            break
        except requests.exceptions.RequestException:
            print("Cant connect to EJBCA server for initial configuration")
            print("Chances are the server is not ready yet.")
            print("Will retry in 30sec")
            sleep(30)
    # Configure and initalize the messenger
    config = Config()
    messenger = Messenger("ejbca-rest", config)
    messenger.init()
    # Subscribe to devices topics and register callback to process new events
    messenger.create_channel(config.dojot['subjects']['devices'], "r")
    messenger.on(config.dojot['subjects']['devices'], "message",
                 receiver_kafka)
    # Gets all devices that are already active on dojot
    messenger.generate_device_create_event_for_active_devices()
    app.run(host='0.0.0.0', port=5583, threaded=True)