From bc55b53c3ac0db74be5493d192542a4d919e83a3 Mon Sep 17 00:00:00 2001 From: Martin Weise <martin.weise@tuwien.ac.at> Date: Thu, 13 Oct 2022 23:18:20 +0200 Subject: [PATCH] Updated the clients --- swagger/api-query.yaml | 8 +-- swagger/api/api_broker/BrokerServiceClient.py | 5 +- .../api_query/api/table_data_endpoint_api.py | 4 +- .../api/table_history_endpoint_api.py | 4 +- swagger/{api => }/client/AmqpClient.py | 6 +- swagger/{api => }/client/RestClient.py | 63 ++++++++++--------- swagger/{api => }/client/__init__.py | 0 swagger/generate.sh | 3 +- 8 files changed, 49 insertions(+), 44 deletions(-) rename swagger/{api => }/client/AmqpClient.py (68%) rename swagger/{api => }/client/RestClient.py (63%) rename swagger/{api => }/client/__init__.py (100%) diff --git a/swagger/api-query.yaml b/swagger/api-query.yaml index b41ce8f..10fd0f5 100644 --- a/swagger/api-query.yaml +++ b/swagger/api-query.yaml @@ -21,7 +21,7 @@ paths: tags: - table-history-endpoint summary: Find all history - operationId: getAll + operationId: getAll_1 parameters: - name: id in: path @@ -86,7 +86,7 @@ paths: tags: - table-history-endpoint summary: Find all history - operationId: getAll_1 + operationId: getAll parameters: - name: id in: path @@ -152,7 +152,7 @@ paths: tags: - table-data-endpoint summary: Find data - operationId: getAll_2 + operationId: getAll_3 parameters: - name: id in: path @@ -428,7 +428,7 @@ paths: tags: - table-data-endpoint summary: Find data - operationId: getAll_3 + operationId: getAll_2 parameters: - name: id in: path diff --git a/swagger/api/api_broker/BrokerServiceClient.py b/swagger/api/api_broker/BrokerServiceClient.py index e7bfd58..7f1d8ba 100644 --- a/swagger/api/api_broker/BrokerServiceClient.py +++ b/swagger/api/api_broker/BrokerServiceClient.py @@ -16,10 +16,9 @@ class BrokerServiceClient: username=self.username, password=self.password))) - def send(self, message): + def send(self, payload): channel = self.connection.channel() - payload = json.dumps(message) - print("... sending tuple %s" % payload) + print("... sending tuple {}".format(payload)) channel.basic_publish(exchange=self.exchange, routing_key=self.routing_key, body=bytes(payload, encoding='utf8')) print("... sent tuple") diff --git a/swagger/api/api_query/api/table_data_endpoint_api.py b/swagger/api/api_query/api/table_data_endpoint_api.py index 8f34b37..632bf00 100644 --- a/swagger/api/api_query/api/table_data_endpoint_api.py +++ b/swagger/api/api_query/api/table_data_endpoint_api.py @@ -259,7 +259,7 @@ class TableDataEndpointApi(object): auth_settings = ['bearerAuth'] # noqa: E501 return self.api_client.call_api( - '/api/container/{id}/database/{databaseId}/table/{tableId}/data', 'GET', + '/api/container/{id}/database/{databaseId}/table/{tableId}/data', 'HEAD', path_params, query_params, header_params, @@ -380,7 +380,7 @@ class TableDataEndpointApi(object): auth_settings = ['bearerAuth'] # noqa: E501 return self.api_client.call_api( - '/api/container/{id}/database/{databaseId}/table/{tableId}/data', 'HEAD', + '/api/container/{id}/database/{databaseId}/table/{tableId}/data', 'GET', path_params, query_params, header_params, diff --git a/swagger/api/api_query/api/table_history_endpoint_api.py b/swagger/api/api_query/api/table_history_endpoint_api.py index 0248167..f013bf0 100644 --- a/swagger/api/api_query/api/table_history_endpoint_api.py +++ b/swagger/api/api_query/api/table_history_endpoint_api.py @@ -126,7 +126,7 @@ class TableHistoryEndpointApi(object): auth_settings = ['bearerAuth'] # noqa: E501 return self.api_client.call_api( - '/api/container/{id}/database/{databaseId}/table/{tableId}/history', 'GET', + '/api/container/{id}/database/{databaseId}/table/{tableId}/history', 'HEAD', path_params, query_params, header_params, @@ -235,7 +235,7 @@ class TableHistoryEndpointApi(object): auth_settings = ['bearerAuth'] # noqa: E501 return self.api_client.call_api( - '/api/container/{id}/database/{databaseId}/table/{tableId}/history', 'HEAD', + '/api/container/{id}/database/{databaseId}/table/{tableId}/history', 'GET', path_params, query_params, header_params, diff --git a/swagger/api/client/AmqpClient.py b/swagger/client/AmqpClient.py similarity index 68% rename from swagger/api/client/AmqpClient.py rename to swagger/client/AmqpClient.py index 5a0498a..9aba72a 100644 --- a/swagger/api/client/AmqpClient.py +++ b/swagger/client/AmqpClient.py @@ -1,4 +1,4 @@ -from api.api_broker.BrokerServiceClient import BrokerServiceClient +from api_broker.BrokerServiceClient import BrokerServiceClient class AmqpClient: @@ -9,9 +9,9 @@ class AmqpClient: self.username = username self.password = password - def send(self, exchange: str, routing_key: str, payload: {}): + def send(self, exchange: str, routing_key: str, payload): broker = BrokerServiceClient(exchange=exchange, routing_key=routing_key, host=self.hostname, username=self.username, password=self.password) response = broker.send(payload) - print("sent tuple to exchange with routing key {}".format(routing_key)) + print("sent tuple to exchange {} with routing key {}".format(exchange, routing_key)) return response diff --git a/swagger/api/client/RestClient.py b/swagger/client/RestClient.py similarity index 63% rename from swagger/api/client/RestClient.py rename to swagger/client/RestClient.py index 096349b..d5afb6c 100644 --- a/swagger/api/client/RestClient.py +++ b/swagger/client/RestClient.py @@ -1,8 +1,8 @@ -from api.api_authentication.api.authentication_endpoint_api import AuthenticationEndpointApi -from api.api_container.api.container_endpoint_api import ContainerEndpointApi -from api.api_database.api.database_endpoint_api import DatabaseEndpointApi -from api.api_query.api.query_endpoint_api import QueryEndpointApi -from api.api_table.api.table_endpoint_api import TableEndpointApi +from api_authentication.api.authentication_endpoint_api import AuthenticationEndpointApi +from api_container.api.container_endpoint_api import ContainerEndpointApi +from api_database.api.database_endpoint_api import DatabaseEndpointApi +from api_query.api.query_endpoint_api import QueryEndpointApi +from api_table.api.table_endpoint_api import TableEndpointApi class RestClient: @@ -13,10 +13,15 @@ class RestClient: self.username = username self.password = password self.authentication = AuthenticationEndpointApi() + self.authentication.api_client.configuration.host = self.hostname self.container = ContainerEndpointApi() + self.container.api_client.configuration.host = self.hostname self.database = DatabaseEndpointApi() + self.database.api_client.configuration.host = self.hostname self.table = TableEndpointApi() + self.table.api_client.configuration.host = self.hostname self.query = QueryEndpointApi() + self.query.api_client.configuration.host = self.hostname def login(self) -> None: """ @@ -27,16 +32,12 @@ class RestClient: "username": self.username, "password": self.password }) - print("authenticated user with id {}".format(response.id)) + print("Authenticated user with id {}".format(response.id)) self.token = response.token self.container.api_client.default_headers = {"Authorization": "Bearer " + self.token} - self.container.api_client.configuration.host = self.hostname self.database.api_client.default_headers = {"Authorization": "Bearer " + self.token} - self.database.api_client.configuration.host = self.hostname self.table.api_client.default_headers = {"Authorization": "Bearer " + self.token} - self.table.api_client.configuration.host = self.hostname self.query.api_client.default_headers = {"Authorization": "Bearer " + self.token} - self.query.api_client.configuration.host = self.hostname def find_database(self, container_id: int, database_id: int): """ @@ -46,39 +47,31 @@ class RestClient: :return: The database if successful. Exception otherwise. """ response = self.database.find_by_id(container_id, database_id) - print("found database with id {}".format(response.id)) + print("Found database with id {}".format(response.id)) return response - def create_table(self, container_id: int, database_id: int): + def create_table(self, container_id: int, database_id: int, name: str, cols: [], col_types: []): """ Creates a table in the provided container id and database id. :param: container_id: The container id. :param: database_id: The database id. + :param: name: The table name. :return: The created container, if successful. Exception otherwise. """ - # table columns name for airquality data - col = ['stationid', 'component', 'time', 'unit', 'meantype', 'value', 'meta_name', 'meta_owner', - 'meta_location', 'x_coord', 'y_coord', 'z_coord'] - # table columns type for airquality data - col_type = ['string', 'string', 'number', 'string', 'string', 'decimal', 'string', 'string', 'string', - 'decimal', 'decimal', 'decimal'] columns = [{ - "name": x, - "type": y, + "name": n, + "type": t, "null_allowed": True, "primary_key": False, - "check_expression": None, - "foreign_key": None, - "references": None, "unique": False - } for x, y in zip(col, col_type)] + } for n, t in zip(cols, col_types)] # send request - response = self.table.create({ - "name": "Data", + response = self.table.create(body={ + "name": name, "description": "This table provides real-time air-data from around 170 air measuring stations in Austria", "columns": columns - }, "Bearer " + self.token, container_id, database_id) - print("created table with id {}".format(response.id)) + }, authorization="Bearer " + self.token, id=container_id, database_id=database_id) + print("Created table with id {}".format(response.id)) def find_tables(self, container_id: int, database_id: int) -> []: """ @@ -88,5 +81,17 @@ class RestClient: :return: The list of tables """ response = self.table.find_all(container_id, database_id) - print("found {} tables".format(len(response))) + print("Found {} tables".format(len(response))) + return response + + def find_table(self, container_id: int, database_id: int, table_id: int) -> {}: + """ + Find a table in a container id and database id and table id + :param: container_id: The container id. + :param: database_id: The database id + :param: table_id: The table id + :return: The table, if successful. Exception otherwise. + """ + response = self.table.find_by_id(container_id, database_id, table_id) + print("Found table with id {}".format(table_id)) return response diff --git a/swagger/api/client/__init__.py b/swagger/client/__init__.py similarity index 100% rename from swagger/api/client/__init__.py rename to swagger/client/__init__.py diff --git a/swagger/generate.sh b/swagger/generate.sh index c50ce8f..677ce85 100755 --- a/swagger/generate.sh +++ b/swagger/generate.sh @@ -56,4 +56,5 @@ for key in "${!services[@]}"; do replace "$key" "${services[$key]}" done -cp -r "./api" "${HOME}/Projects/dbrepo-tuw/worker-airquality/api/" \ No newline at end of file +cp -r ./api/* "${HOME}/Projects/dbrepo-tuw/worker-airquality/" +cp -r ./client "${HOME}/Projects/dbrepo-tuw/worker-airquality/" -- GitLab