diff --git a/swagger/api-query.yaml b/swagger/api-query.yaml index b41ce8f4a3f9c06531209e7f725f76a5e6111ade..10fd0f5f140b51fc570f6d4c03e8df4e35efc14b 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 e7bfd582a87bb59a8f604cc3addd760e29f5413a..7f1d8ba49f2882390f05f397b4d0c0ea862cebe2 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 8f34b37dacac4db3543dd2def4951d0d24501b87..632bf0023c0c979119e43647dec551cf4bc744ad 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 024816773f5d4328cc00116d9c298b48cd860fc9..f013bf0c6aede1359efe4f36e48a29c1d18215c9 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 5a0498adab65e33d6d2fbd337d7c53abf5ea930d..9aba72ade32309c01014839555a75534ef5765be 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 096349b35e232284b02d3f2231a6c88f3f6a703d..d5afb6c3d345f5045623224997e8f900685a7925 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 c50ce8f33906d231f39a1997b03e90fcbeef026b..677ce855f7cc4dca09fff0b7e7a342ef97e3e6d1 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/"