helyos_agent_sdk.database_connector module
- class helyos_agent_sdk.database_connector.DatabaseConnector(helyos_client)
Bases:
object
This module defines the DatabaseConnector class.
The class is responsible for handling remote procedure calls (RPCs) using the AMQP protocol. It connects to a Helyos client and makes requests to helyOS database.
Attributes: connection (obj): The pika RabbitMQ connection object . helyos_client (obj): The Helyos client object. routing_key (str): The routing key for the summary requests. username (str): The username for the RabbitMQ. channel (obj): The channel object of the connection. callback_queue (str): The callback queue for receiving responses. response (str): The response received from the RPC call. corr_id (str): The unique correlation id for the RPC call.
Methods: init(connection, helyos_client): Initializes the DatabaseConnector object and sets up the necessary attributes. on_response(ch, method, props, body): Callback function for handling the response received from the RPC call. call(request): Makes a remote procedure call with the given request and returns the response.
requests can be one of the following: “allAgents”, “allYards”, “executingMissions”, “missionAssignments” or “allMapObjects”.
helyos_client = HelyOSClient(host=’myrabbitmq.com’, port=5672, uuid=’3452345-52453-43525’) helyos_client.connect_rabbitmq(‘my_username’, ‘secret_password’) db_rpc = DatabaseConnector(helyos_client) agents_summary = db_rpc.call({‘query’: ‘allAgents’, ‘conditions’: {“yard_id”: 1}})
- __init__(helyos_client)
- on_response(ch, method, props, body)
- call(request)
- Parameters
request (dict) – a dictionary containing the query or mutation and condition or data. The query can be one of the following: “allAgents”, “allYards”, “executingMissions”, “missionAssignments”,”allMapObjects”, The mutations can be one of the following: “createMapObjects”, “deleteMapObjects”, “deleteMapObjectByIds”. The condition is a dictionary that specifies additional filtering criteria for the query or deleting. The data is a list of dictionaries containing the data to be inserted.
- Returns
the requested information based on the provided query and conditions.
- Return type
an
- Examples:
>>> db_rpc.call({'query': 'allAgents', 'conditions': {"yard_id": 1}}) >>> db_rpc.call({'mutation': 'createMapObjects', 'data': [{'name': 'object1', 'type': 'type1', 'yard_id': 1}]}) >>> db_rpc.call({'mutation': 'deleteMapObjects', 'conditions': {'id': 1}}) >>> db_rpc.call({'mutation': 'deleteMapObjectByIds', 'conditions': {'ids': [1, 2, 3]}})