コード例 #1
0
ファイル: persister.py プロジェクト: luissajunior/history
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.")
コード例 #2
0
    def init(cls):
        if cls.messenger is not None:
            return

        LOGGER.debug("Initializing dojot.module")
        config = Config({
            "auth": {
                "url": "http://localhost:5000",
                "connection_retries": 3,
                "timeout_sleep": 5
            }
        })

        LOGGER.debug("Config is:  " + json.dumps(config.auth))
        cls.messenger = Messenger("dojot.auth", config)
        LOGGER.debug(f"Creating tenant {dojot_management_tenant}...")
        LOGGER.debug(f"Current tenants are: {cls.messenger.tenants}.")
        cls.messenger.process_new_tenant(
            dojot_management_tenant,
            json.dumps({"tenant": dojot_management_tenant}))
        LOGGER.debug("... tenant created.")
        LOGGER.debug("Creating channel " + kafka_subject)
        cls.messenger.create_channel(kafka_subject, "w")
        LOGGER.debug("... channel created.")
        LOGGER.debug("Initializing messenger")
        cls.messenger.init()
        LOGGER.debug("... messenger 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()
    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...")

    start_dojot_messenger(config, persister,
                          conf.dojot_persist_notifications_only)
    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()
コード例 #4
0
def assert_config_creation(data=None):
    config = Config(data)
    assert config is not None
    assert config.kafka is not None
    assert config.data_broker is not None
    assert config.auth is not None
    assert config.dojot is not None
    return config
コード例 #5
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)
コード例 #6
0
    def init(cls):
        if cls.messenger is not None:
            return

        LOGGER.debug("Initializing dojot.module")
        config = Config({
            "kafka": {
                "producer": {
                    "client.id": "dojot.auth",
                    "metadata.broker.list": kafka_host,
                    "compression.codec": "gzip",
                    "retry.backoff.ms": 200,
                    "message.send.max.retries": 10,
                    "socket.keepalive.enable": True,
                    "queue.buffering.max.messages": 100000,
                    "queue.buffering.max.ms": 1000,
                    "batch.num.messages": 1000000,
                    "dr_cb": True
                },
                "consumer": {
                    "group.id": "dojot.auth",
                    "metadata.broker.list": kafka_host
                }
            },
            "data_broker": {
                "url": data_broker_host,
                "connection_retries": 3,
                "timeout_sleep": 5
            },
            "auth": {
                "url": "http://localhost:5000",
                "connection_retries": 3,
                "timeout_sleep": 5
            }
        })

        LOGGER.debug("Config is:  " + json.dumps(config.auth))
        cls.messenger = Messenger("dojot.auth", config)
        LOGGER.debug("Initializing messenger")
        cls.messenger.init()
        LOGGER.debug("... messenger initialized.")
        LOGGER.debug("Creating channel " + kafka_subject)
        cls.messenger.create_channel(kafka_subject, "w")
コード例 #7
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.")
コード例 #8
0
ファイル: persister.py プロジェクト: dojot/history
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()
コード例 #9
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)
コード例 #10
0
def create_messenger():
    config = Config()
    messenger = Messenger("Dojot-Snoop", config)
    return messenger