Documentation Communication¶
-
class
motey.communication.apiserver.APIServer(logger, host=‘127.0.0.1’, port=5023)[source]¶ Starts a Flask webserver which acts as an REST API to control the Motey service. The webserver runs in a separate thread and will not block the main thread.
-
check_heartbeat()[source]¶ Method to get the heartbeat. Checks if all the requirements for a healthy webserver are fulfilled. :return: True if the service is in a healthy state, otherwise False.
-
-
class
motey.communication.communication_manager.CommunicationManager(api_server, mqtt_server, zeromq_server)[source]¶ This class acts as an facade for the communication endpoints like the
MQTT server, theAPI serverand theZeroMQ server. It covers all method calls and can start and stop the mentioned components.-
after_capabilities_request¶ Facades the
ZeroMQServer.after_capabilities_request_handler()getter. Returns the handler which will be executed after a capability request was received.Returns: the handler which will be executed after a capability request was received.
-
after_connect_callback()[source]¶ Will be called after the MQTTServer has established a connection to the broker. Send out a request to fetch the ip from all existing nodes.
-
deploy_image(image)[source]¶ Facades the
ZeroMQServer.deploy_image()method. Will deploy an image to the node stored in theImage.nodeattribute.Parameters: image (motey.models.image.Image) – Image to be deployed. Returns: the id of the deployed image or None if something went wrong.
-
request_capabilities(ip)[source]¶ Facades the
ZeroMQServer.request_capabilities()method. Will fetch the capabilities of a specific node and will return them.Parameters: ip (str) – The ip of the node to be requested. Returns: the capabilities of a specific node
-
request_image_status(image)[source]¶ Facades the
ZeroMQServer.request_image_status()method. Request the status of an specific image instance or None if something went wrong.Parameters: image (motey.models.image.Image) – Image to be used to get the status. Returns: the status of the image or None if something went wrong
-
stop()[source]¶ Stop all the connected communication components. Will send out a mqtt message to remove the current node.
-
terminate_image(image)[source]¶ Facades the
ZeroMQServer.terminate_image()method. Will terminate an image instance.Parameters: image (motey.models.image.Image) – the image instance to be terminated
-
-
class
motey.communication.mqttserver.MQTTServer(logger, nodes_repository, host=‘127.0.0.1’, port=1883, username=None, password=None, keepalive=60)[source]¶ MQTT server to register and unregister adjacent fog nodes. The webserver runs in a separate thread and will not block the main thread.
-
handle_nodes_request(client, userdata, message)[source]¶ Define the node request callback implementation. Will execute the callback of the request to fetch the ip from all existing nodes.
Parameters: - client – the client instance for this callback
- userdata – the private user data as set in Client() or userdata_set()
- message – the data which was send
-
handle_on_connect(client, userdata, flags, resultcode)[source]¶ Define the connect callback implementation. If the client is connected to the MQTT broker, the nodes will be registered and the
_after_connectmethod will be executed.- flags is a dict that contains response flags from the broker:
- flags[‘session present’] - this flag is useful for clients that are
- using clean session set to 0 only. If a client with clean session=0, that reconnects to a broker that it has previously connected to, this flag indicates whether the broker still has the session information for the client. If 1, the session still exists.
- The value of rc indicates success or not:
- 0: Connection successful 1: Connection refused - incorrect protocol version 2: Connection refused - invalid client identifier 3: Connection refused - server unavailable 4: Connection refused - bad username or password 5: Connection refused - not authorised 6-255: Currently unused.
Parameters: - client – the client instance for this callback
- userdata – the private user data as set in Client() or userdata_set()
- flags – response flags sent by the broker
- resultcode – the connection result
-
handle_on_disconnect(client, userdata, resultcode)[source]¶ Define the disconnect callback implementation.
Parameters: - client – the client instance for this callback
- userdata – the private user data as set in Client() or userdata_set()
- resultcode – the connection result
-
handle_register_node(client, userdata, message)[source]¶ Define the register new node callback implementation. Adds the new node to the
NodesRepository.Parameters: - client – the client instance for this callback
- userdata – the private user data as set in Client() or userdata_set()
- message – the data which was send
-
publish_new_node(ip=None)[source]¶ Publish the info that a new node is available to the all subscribers. If the
ipis none, nothing will be send.Parameters: ip – The IP address of the new node. Default is None.
-
publish_node_request(ip=None)[source]¶ Publish the request to fetch the ip from all existing nodes.
Parameters: ip – the own ip to let the other nodes know where the request cames from.
-
remove_node(ip=None)[source]¶ Remove a specific node and publish it to all subscribers. If the
ipis none, nothing will be send.Parameters: ip – The IP address of the new node. Default is None.
-
-
class
motey.communication.zeromq_server.ZeroMQServer(logger, valmanager)[source]¶ ZeroMQ server to communicate with adjacent fog nodes and to reply to requests. The different listeners will be executed in a separate thread and will not block the main thread.
-
after_capabilities_request¶ Returns the handler which will be executed after a capability request was received.
Returns: the handler which will be executed after a capability request was received.
-
deploy_image(image)[source]¶ Will deploy an image to the node stored in the
Image.nodeattribute.Parameters: image (motey.models.image.Image) – Image to be deployed. Returns: the id of the deployed image or None if something went wrong.
-
request_capabilities(ip)[source]¶ Method to request all capabilities from another node. Will request via the ZeroMQ.REQ pattern. After the request is send, the method will wait for the response.
Parameters: ip – the IP address of the node to request the capabilities Returns: the capabilities as a JSON object
-
request_image_status(image)[source]¶ Request the status of an specific image instance or None if something went wrong.
Parameters: image (motey.models.image.Image) – Image to be used to get the status. Returns: the status of the image or None if something went wrong
-
start()[source]¶ Starts the listening on a given port. This method will be executed on a separate thread.
-
terminate_image(image)[source]¶ Will terminate an image instance.
Parameters: image (motey.models.image.Image) – the image instance to be terminated
-