Пример #1
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)
Пример #2
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.")
Пример #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 test_messenger_on():

    mockSelf = Mock(event_callbacks={},
                    create_channel=Mock(),
                    subjects={},
                    global_subjects={})

    def reset_scenario():
        mockSelf.event_callbacks = {}
        mockSelf.subjects = {}
        mockSelf.global_subjects = {}
        mockSelf.create_channel.reset_mock()

    # No registered subjects
    Messenger.on(mockSelf, "sample-subject", "sample-event", "callback-dummy")
    assert "sample-subject" in mockSelf.event_callbacks
    assert "sample-event" in mockSelf.event_callbacks["sample-subject"]
    assert "callback-dummy" in mockSelf.event_callbacks["sample-subject"][
        "sample-event"]
    mockSelf.create_channel.assert_called_once_with("sample-subject")

    # Registered a local subject
    reset_scenario()
    mockSelf.subjects = ["sample-subject"]
    Messenger.on(mockSelf, "sample-subject", "sample-event", "callback-dummy")
    mockSelf.create_channel.assert_not_called()

    # Registered a global subject
    reset_scenario()
    mockSelf.global_subjects = ["sample-subject"]
    Messenger.on(mockSelf, "sample-subject", "sample-event", "callback-dummy")
    mockSelf.create_channel.assert_not_called()
Пример #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)