Skip to content
Snippets Groups Projects
Unverified Commit bc55b53c authored by Martin Weise's avatar Martin Weise
Browse files

Updated the clients

parent 2b277baa
No related branches found
No related tags found
No related merge requests found
Pipeline #2690 passed
...@@ -21,7 +21,7 @@ paths: ...@@ -21,7 +21,7 @@ paths:
tags: tags:
- table-history-endpoint - table-history-endpoint
summary: Find all history summary: Find all history
operationId: getAll operationId: getAll_1
parameters: parameters:
- name: id - name: id
in: path in: path
...@@ -86,7 +86,7 @@ paths: ...@@ -86,7 +86,7 @@ paths:
tags: tags:
- table-history-endpoint - table-history-endpoint
summary: Find all history summary: Find all history
operationId: getAll_1 operationId: getAll
parameters: parameters:
- name: id - name: id
in: path in: path
...@@ -152,7 +152,7 @@ paths: ...@@ -152,7 +152,7 @@ paths:
tags: tags:
- table-data-endpoint - table-data-endpoint
summary: Find data summary: Find data
operationId: getAll_2 operationId: getAll_3
parameters: parameters:
- name: id - name: id
in: path in: path
...@@ -428,7 +428,7 @@ paths: ...@@ -428,7 +428,7 @@ paths:
tags: tags:
- table-data-endpoint - table-data-endpoint
summary: Find data summary: Find data
operationId: getAll_3 operationId: getAll_2
parameters: parameters:
- name: id - name: id
in: path in: path
......
...@@ -16,10 +16,9 @@ class BrokerServiceClient: ...@@ -16,10 +16,9 @@ class BrokerServiceClient:
username=self.username, username=self.username,
password=self.password))) password=self.password)))
def send(self, message): def send(self, payload):
channel = self.connection.channel() channel = self.connection.channel()
payload = json.dumps(message) print("... sending tuple {}".format(payload))
print("... sending tuple %s" % payload)
channel.basic_publish(exchange=self.exchange, routing_key=self.routing_key, channel.basic_publish(exchange=self.exchange, routing_key=self.routing_key,
body=bytes(payload, encoding='utf8')) body=bytes(payload, encoding='utf8'))
print("... sent tuple") print("... sent tuple")
......
...@@ -259,7 +259,7 @@ class TableDataEndpointApi(object): ...@@ -259,7 +259,7 @@ class TableDataEndpointApi(object):
auth_settings = ['bearerAuth'] # noqa: E501 auth_settings = ['bearerAuth'] # noqa: E501
return self.api_client.call_api( 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, path_params,
query_params, query_params,
header_params, header_params,
...@@ -380,7 +380,7 @@ class TableDataEndpointApi(object): ...@@ -380,7 +380,7 @@ class TableDataEndpointApi(object):
auth_settings = ['bearerAuth'] # noqa: E501 auth_settings = ['bearerAuth'] # noqa: E501
return self.api_client.call_api( 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, path_params,
query_params, query_params,
header_params, header_params,
......
...@@ -126,7 +126,7 @@ class TableHistoryEndpointApi(object): ...@@ -126,7 +126,7 @@ class TableHistoryEndpointApi(object):
auth_settings = ['bearerAuth'] # noqa: E501 auth_settings = ['bearerAuth'] # noqa: E501
return self.api_client.call_api( 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, path_params,
query_params, query_params,
header_params, header_params,
...@@ -235,7 +235,7 @@ class TableHistoryEndpointApi(object): ...@@ -235,7 +235,7 @@ class TableHistoryEndpointApi(object):
auth_settings = ['bearerAuth'] # noqa: E501 auth_settings = ['bearerAuth'] # noqa: E501
return self.api_client.call_api( 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, path_params,
query_params, query_params,
header_params, header_params,
......
from api.api_broker.BrokerServiceClient import BrokerServiceClient from api_broker.BrokerServiceClient import BrokerServiceClient
class AmqpClient: class AmqpClient:
...@@ -9,9 +9,9 @@ class AmqpClient: ...@@ -9,9 +9,9 @@ class AmqpClient:
self.username = username self.username = username
self.password = password 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, broker = BrokerServiceClient(exchange=exchange, routing_key=routing_key, host=self.hostname,
username=self.username, password=self.password) username=self.username, password=self.password)
response = broker.send(payload) 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 return response
from api.api_authentication.api.authentication_endpoint_api import AuthenticationEndpointApi from api_authentication.api.authentication_endpoint_api import AuthenticationEndpointApi
from api.api_container.api.container_endpoint_api import ContainerEndpointApi from api_container.api.container_endpoint_api import ContainerEndpointApi
from api.api_database.api.database_endpoint_api import DatabaseEndpointApi from api_database.api.database_endpoint_api import DatabaseEndpointApi
from api.api_query.api.query_endpoint_api import QueryEndpointApi from api_query.api.query_endpoint_api import QueryEndpointApi
from api.api_table.api.table_endpoint_api import TableEndpointApi from api_table.api.table_endpoint_api import TableEndpointApi
class RestClient: class RestClient:
...@@ -13,10 +13,15 @@ class RestClient: ...@@ -13,10 +13,15 @@ class RestClient:
self.username = username self.username = username
self.password = password self.password = password
self.authentication = AuthenticationEndpointApi() self.authentication = AuthenticationEndpointApi()
self.authentication.api_client.configuration.host = self.hostname
self.container = ContainerEndpointApi() self.container = ContainerEndpointApi()
self.container.api_client.configuration.host = self.hostname
self.database = DatabaseEndpointApi() self.database = DatabaseEndpointApi()
self.database.api_client.configuration.host = self.hostname
self.table = TableEndpointApi() self.table = TableEndpointApi()
self.table.api_client.configuration.host = self.hostname
self.query = QueryEndpointApi() self.query = QueryEndpointApi()
self.query.api_client.configuration.host = self.hostname
def login(self) -> None: def login(self) -> None:
""" """
...@@ -27,16 +32,12 @@ class RestClient: ...@@ -27,16 +32,12 @@ class RestClient:
"username": self.username, "username": self.username,
"password": self.password "password": self.password
}) })
print("authenticated user with id {}".format(response.id)) print("Authenticated user with id {}".format(response.id))
self.token = response.token self.token = response.token
self.container.api_client.default_headers = {"Authorization": "Bearer " + self.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.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.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.default_headers = {"Authorization": "Bearer " + self.token}
self.query.api_client.configuration.host = self.hostname
def find_database(self, container_id: int, database_id: int): def find_database(self, container_id: int, database_id: int):
""" """
...@@ -46,39 +47,31 @@ class RestClient: ...@@ -46,39 +47,31 @@ class RestClient:
:return: The database if successful. Exception otherwise. :return: The database if successful. Exception otherwise.
""" """
response = self.database.find_by_id(container_id, database_id) 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 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. Creates a table in the provided container id and database id.
:param: container_id: The container id. :param: container_id: The container id.
:param: database_id: The database id. :param: database_id: The database id.
:param: name: The table name.
:return: The created container, if successful. Exception otherwise. :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 = [{ columns = [{
"name": x, "name": n,
"type": y, "type": t,
"null_allowed": True, "null_allowed": True,
"primary_key": False, "primary_key": False,
"check_expression": None,
"foreign_key": None,
"references": None,
"unique": False "unique": False
} for x, y in zip(col, col_type)] } for n, t in zip(cols, col_types)]
# send request # send request
response = self.table.create({ response = self.table.create(body={
"name": "Data", "name": name,
"description": "This table provides real-time air-data from around 170 air measuring stations in Austria", "description": "This table provides real-time air-data from around 170 air measuring stations in Austria",
"columns": columns "columns": columns
}, "Bearer " + self.token, container_id, database_id) }, authorization="Bearer " + self.token, id=container_id, database_id=database_id)
print("created table with id {}".format(response.id)) print("Created table with id {}".format(response.id))
def find_tables(self, container_id: int, database_id: int) -> []: def find_tables(self, container_id: int, database_id: int) -> []:
""" """
...@@ -88,5 +81,17 @@ class RestClient: ...@@ -88,5 +81,17 @@ class RestClient:
:return: The list of tables :return: The list of tables
""" """
response = self.table.find_all(container_id, database_id) 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 return response
File moved
...@@ -56,4 +56,5 @@ for key in "${!services[@]}"; do ...@@ -56,4 +56,5 @@ for key in "${!services[@]}"; do
replace "$key" "${services[$key]}" replace "$key" "${services[$key]}"
done done
cp -r "./api" "${HOME}/Projects/dbrepo-tuw/worker-airquality/api/" cp -r ./api/* "${HOME}/Projects/dbrepo-tuw/worker-airquality/"
\ No newline at end of file cp -r ./client "${HOME}/Projects/dbrepo-tuw/worker-airquality/"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment