generated from Luis/nextjs-python-web-template
Merge pull request 'Fixed eventmessage formatting problem' (#62) from Qubasa-main into main
Reviewed-on: #62
This commit was merged in pull request #62.
This commit is contained in:
@@ -33,6 +33,38 @@ And then run the docker file by executing:
|
||||
docker run -p 127.0.0.1:2979:2979 clan-docker:latest
|
||||
```
|
||||
|
||||
# Uploading a Docker Image
|
||||
|
||||
Login to the tu docker image server
|
||||
|
||||
```bash
|
||||
docker login git.tu-berlin.de:5000
|
||||
```
|
||||
|
||||
Tag the imported image
|
||||
|
||||
```bash
|
||||
docker image tag clan-docker:latest git.tu-berlin.de:5000/internet-of-services-lab/service-aware-network-front-end:latest
|
||||
```
|
||||
|
||||
Push the image to the git registry
|
||||
|
||||
```bash
|
||||
docker image push git.tu-berlin.de:5000/internet-of-services-lab/service-aware-network-front-end:latest
|
||||
```
|
||||
|
||||
Pull the image
|
||||
|
||||
```bash
|
||||
docker pull git.tu-berlin.de:5000/internet-of-services-lab/service-aware-network-front-end:latest
|
||||
```
|
||||
|
||||
Run the image
|
||||
|
||||
```bash
|
||||
docker run -p 127.0.0.1:2979:2979 git.tu-berlin.de:5000/internet-of-services-lab/service-aware-network-front-end:latest
|
||||
```
|
||||
|
||||
# Auto Generating a Python Client
|
||||
|
||||
For the tests we automatically generate a python client for the API endpoints. To do this execute while inside the `pkgs/clan-cli` folder:
|
||||
|
||||
@@ -9,7 +9,70 @@ cors_ports = ["*", 3000, 2979]
|
||||
|
||||
# host for the server, frontend, backend and emulators
|
||||
host = "127.0.0.1"
|
||||
# used for emmulation and population for testing
|
||||
|
||||
# Used for eventmessage number to name mapping
|
||||
group_type_to_label = {
|
||||
1: {
|
||||
"name": "Attachement",
|
||||
1: "Request Send",
|
||||
2: "Request Received",
|
||||
3: "Response Send",
|
||||
4: "Response Received",
|
||||
},
|
||||
2: {
|
||||
"name": "Connection Setup",
|
||||
1: "Request Send",
|
||||
2: "Request Received",
|
||||
3: "Response Send",
|
||||
4: "Response Received",
|
||||
},
|
||||
3: {
|
||||
"name": "Presentation",
|
||||
1: "Request Send",
|
||||
2: "Request Received",
|
||||
3: "Respone Send",
|
||||
4: "Respone Received",
|
||||
5: "Respone Ack",
|
||||
},
|
||||
4: {
|
||||
"name": "DID Resolution",
|
||||
1: "Request Send",
|
||||
2: "Request Received",
|
||||
3: "Response Send",
|
||||
4: "Response Received",
|
||||
},
|
||||
5: {
|
||||
"name": "Service De-registration",
|
||||
1: "Send",
|
||||
2: "Received",
|
||||
3: "Success Send",
|
||||
4: "Success Received",
|
||||
},
|
||||
6: {
|
||||
"name": "Service Registration",
|
||||
1: "Send",
|
||||
2: "Received",
|
||||
3: "Success Send",
|
||||
4: "Success Received",
|
||||
},
|
||||
7: {
|
||||
"name": "Service Discovery",
|
||||
1: "Discovery Send",
|
||||
2: "Discovery Received",
|
||||
3: "Result Send",
|
||||
4: "Result Received",
|
||||
},
|
||||
8: {
|
||||
"name": "Service Operation",
|
||||
1: "Request Send",
|
||||
2: "Request Received",
|
||||
3: "Response Send",
|
||||
4: "Response Received",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
# Used for emulation and population for testing
|
||||
port_dlg = 7000
|
||||
port_ap = 7500
|
||||
_port_client_base = 8000
|
||||
@@ -19,15 +82,3 @@ dlg_url = f"http://{host}:{port_dlg}/docs"
|
||||
ap_url = f"http://{host}:{port_ap}/docs"
|
||||
c1_url = f"http://{host}:{c1_port}/docs"
|
||||
c2_url = f"http://{host}:{c2_port}/docs"
|
||||
|
||||
|
||||
msg_type_to_label = {
|
||||
1: "Attachement",
|
||||
2: "Connection Setup",
|
||||
3: "Presentation",
|
||||
4: "DID Resolution",
|
||||
5: "Service De-registration",
|
||||
6: "Service Registration",
|
||||
7: "Service Discovery",
|
||||
8: "Service Operation",
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ from fastapi import APIRouter, BackgroundTasks, Depends, Query
|
||||
from fastapi.responses import HTMLResponse, JSONResponse
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from clan_cli.config import ap_url, c1_url, c2_url, dlg_url, msg_type_to_label
|
||||
from clan_cli.config import ap_url, c1_url, c2_url, dlg_url, group_type_to_label
|
||||
|
||||
from ...errors import ClanError
|
||||
from .. import sql_crud, sql_db, sql_models
|
||||
@@ -370,25 +370,36 @@ def get_all_eventmessages(
|
||||
result: dict[int, dict[int, List[Eventmessage]]] = {}
|
||||
|
||||
for msg in eventmessages:
|
||||
msg_name = msg_type_to_label.get(msg.msg_type, None)
|
||||
# Use the group_type_to_label from config.py to get the group name and msg_type name
|
||||
group = group_type_to_label.get(msg.group, None)
|
||||
group_name = group.get("name", None) if group is not None else str(msg.group)
|
||||
msg_type_name = (
|
||||
group.get(msg.msg_type, None) if group is not None else str(msg.msg_type)
|
||||
)
|
||||
|
||||
# Get the name of the src and des entity from the database
|
||||
src_name = sql_crud.get_entity_by_did(db, msg.src_did)
|
||||
src_name = src_name if src_name is None else src_name.name
|
||||
des_name = sql_crud.get_entity_by_did(db, msg.des_did)
|
||||
des_name = des_name if des_name is None else des_name.name
|
||||
|
||||
if result.get(msg.group) is None:
|
||||
result[msg.group] = {}
|
||||
if result[msg.group].get(msg.group_id) is None:
|
||||
result[msg.group][msg.group_id] = []
|
||||
# Initialize the result array and dictionary
|
||||
if result.get(group_name) is None:
|
||||
result[group_name] = {}
|
||||
if result[group_name].get(msg.group_id) is None:
|
||||
result[group_name][msg.group_id] = []
|
||||
|
||||
result[msg.group][msg.group_id].append(
|
||||
# Append the eventmessage to the result array
|
||||
result_arr = result[group_name][msg.group_id]
|
||||
result_arr.append(
|
||||
Eventmessage(
|
||||
id=msg.id,
|
||||
timestamp=msg.timestamp,
|
||||
group=msg.group,
|
||||
group_name=group_name,
|
||||
group_id=msg.group_id,
|
||||
msg_type=msg.msg_type,
|
||||
msg_type_name=msg_name,
|
||||
msg_type_name=msg_type_name,
|
||||
src_did=msg.src_did,
|
||||
src_name=src_name,
|
||||
des_did=msg.des_did,
|
||||
@@ -396,6 +407,9 @@ def get_all_eventmessages(
|
||||
msg=msg.msg,
|
||||
).dict()
|
||||
)
|
||||
|
||||
# sort by timestamp
|
||||
result_arr.sort(key=lambda x: x["timestamp"])
|
||||
return JSONResponse(content=result, status_code=200)
|
||||
|
||||
|
||||
|
||||
@@ -185,7 +185,8 @@ class Eventmessage(EventmessageCreate):
|
||||
id: int = Field(...)
|
||||
des_name: Optional[str] = Field(default=None, example="C2")
|
||||
src_name: Optional[str] = Field(default=None, example="C1")
|
||||
msg_type_name: Optional[str] = Field(default=None, example="Service Usage")
|
||||
msg_type_name: Optional[str] = Field(default=None, example="Request Send")
|
||||
group_name: Optional[str] = Field(default=None, example="Presentation")
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
@@ -42,134 +42,6 @@ class DefaultApi:
|
||||
api_client = ApiClient.get_default()
|
||||
self.api_client = api_client
|
||||
|
||||
@validate_arguments
|
||||
def get(self, **kwargs) -> None: # noqa: E501
|
||||
"""Get # noqa: E501
|
||||
|
||||
This method makes a synchronous HTTP request by default. To make an
|
||||
asynchronous HTTP request, please pass async_req=True
|
||||
|
||||
>>> thread = api.get(async_req=True)
|
||||
>>> result = thread.get()
|
||||
|
||||
:param async_req: Whether to execute the request asynchronously.
|
||||
:type async_req: bool, optional
|
||||
:param _request_timeout: timeout setting for this request.
|
||||
If one number provided, it will be total request
|
||||
timeout. It can also be a pair (tuple) of
|
||||
(connection, read) timeouts.
|
||||
:return: Returns the result object.
|
||||
If the method is called asynchronously,
|
||||
returns the request thread.
|
||||
:rtype: None
|
||||
"""
|
||||
kwargs['_return_http_data_only'] = True
|
||||
if '_preload_content' in kwargs:
|
||||
message = "Error! Please call the get_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data" # noqa: E501
|
||||
raise ValueError(message)
|
||||
return self.get_with_http_info(**kwargs) # noqa: E501
|
||||
|
||||
@validate_arguments
|
||||
def get_with_http_info(self, **kwargs) -> ApiResponse: # noqa: E501
|
||||
"""Get # noqa: E501
|
||||
|
||||
This method makes a synchronous HTTP request by default. To make an
|
||||
asynchronous HTTP request, please pass async_req=True
|
||||
|
||||
>>> thread = api.get_with_http_info(async_req=True)
|
||||
>>> result = thread.get()
|
||||
|
||||
:param async_req: Whether to execute the request asynchronously.
|
||||
:type async_req: bool, optional
|
||||
:param _preload_content: if False, the ApiResponse.data will
|
||||
be set to none and raw_data will store the
|
||||
HTTP response body without reading/decoding.
|
||||
Default is True.
|
||||
:type _preload_content: bool, optional
|
||||
:param _return_http_data_only: response data instead of ApiResponse
|
||||
object with status code, headers, etc
|
||||
:type _return_http_data_only: bool, optional
|
||||
:param _request_timeout: timeout setting for this request. If one
|
||||
number provided, it will be total request
|
||||
timeout. It can also be a pair (tuple) of
|
||||
(connection, read) timeouts.
|
||||
:param _request_auth: set to override the auth_settings for an a single
|
||||
request; this effectively ignores the authentication
|
||||
in the spec for a single request.
|
||||
:type _request_auth: dict, optional
|
||||
:type _content_type: string, optional: force content-type for the request
|
||||
:return: Returns the result object.
|
||||
If the method is called asynchronously,
|
||||
returns the request thread.
|
||||
:rtype: None
|
||||
"""
|
||||
|
||||
_params = locals()
|
||||
|
||||
_all_params = [
|
||||
]
|
||||
_all_params.extend(
|
||||
[
|
||||
'async_req',
|
||||
'_return_http_data_only',
|
||||
'_preload_content',
|
||||
'_request_timeout',
|
||||
'_request_auth',
|
||||
'_content_type',
|
||||
'_headers'
|
||||
]
|
||||
)
|
||||
|
||||
# validate the arguments
|
||||
for _key, _val in _params['kwargs'].items():
|
||||
if _key not in _all_params:
|
||||
raise ApiTypeError(
|
||||
"Got an unexpected keyword argument '%s'"
|
||||
" to method get" % _key
|
||||
)
|
||||
_params[_key] = _val
|
||||
del _params['kwargs']
|
||||
|
||||
_collection_formats = {}
|
||||
|
||||
# process the path parameters
|
||||
_path_params = {}
|
||||
|
||||
# process the query parameters
|
||||
_query_params = []
|
||||
# process the header parameters
|
||||
_header_params = dict(_params.get('_headers', {}))
|
||||
# process the form parameters
|
||||
_form_params = []
|
||||
_files = {}
|
||||
# process the body parameter
|
||||
_body_params = None
|
||||
# set the HTTP header `Accept`
|
||||
_header_params['Accept'] = self.api_client.select_header_accept(
|
||||
['application/json']) # noqa: E501
|
||||
|
||||
# authentication setting
|
||||
_auth_settings = [] # noqa: E501
|
||||
|
||||
_response_types_map = {}
|
||||
|
||||
return self.api_client.call_api(
|
||||
'/ws2_example', 'GET',
|
||||
_path_params,
|
||||
_query_params,
|
||||
_header_params,
|
||||
body=_body_params,
|
||||
post_params=_form_params,
|
||||
files=_files,
|
||||
response_types_map=_response_types_map,
|
||||
auth_settings=_auth_settings,
|
||||
async_req=_params.get('async_req'),
|
||||
_return_http_data_only=_params.get('_return_http_data_only'), # noqa: E501
|
||||
_preload_content=_params.get('_preload_content', True),
|
||||
_request_timeout=_params.get('_request_timeout'),
|
||||
collection_formats=_collection_formats,
|
||||
_request_auth=_params.get('_request_auth'))
|
||||
|
||||
@validate_arguments
|
||||
def get_emulated_enpoints(self, **kwargs) -> str: # noqa: E501
|
||||
"""Get Emulated Enpoints # noqa: E501
|
||||
|
||||
@@ -4,70 +4,11 @@ All URIs are relative to *http://localhost*
|
||||
|
||||
Method | HTTP request | Description
|
||||
------------- | ------------- | -------------
|
||||
[**get**](DefaultApi.md#get) | **GET** /ws2_example | Get
|
||||
[**get_emulated_enpoints**](DefaultApi.md#get_emulated_enpoints) | **GET** /emulate | Get Emulated Enpoints
|
||||
[**health**](DefaultApi.md#health) | **GET** /health | Health
|
||||
[**root**](DefaultApi.md#root) | **GET** /{path_name} | Root
|
||||
|
||||
|
||||
# **get**
|
||||
> get()
|
||||
|
||||
Get
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
import time
|
||||
import os
|
||||
import openapi_client
|
||||
from openapi_client.rest import ApiException
|
||||
from pprint import pprint
|
||||
|
||||
# Defining the host is optional and defaults to http://localhost
|
||||
# See configuration.py for a list of all supported configuration parameters.
|
||||
configuration = openapi_client.Configuration(
|
||||
host = "http://localhost"
|
||||
)
|
||||
|
||||
|
||||
# Enter a context with an instance of the API client
|
||||
with openapi_client.ApiClient(configuration) as api_client:
|
||||
# Create an instance of the API class
|
||||
api_instance = openapi_client.DefaultApi(api_client)
|
||||
|
||||
try:
|
||||
# Get
|
||||
api_instance.get()
|
||||
except Exception as e:
|
||||
print("Exception when calling DefaultApi->get: %s\n" % e)
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Parameters
|
||||
This endpoint does not need any parameter.
|
||||
|
||||
### Return type
|
||||
|
||||
void (empty response body)
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/json
|
||||
|
||||
### HTTP response details
|
||||
| Status code | Description | Response headers |
|
||||
|-------------|-------------|------------------|
|
||||
**200** | Successful Response | - |
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **get_emulated_enpoints**
|
||||
> str get_emulated_enpoints()
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ Name | Type | Description | Notes
|
||||
**des_name** | **str** | | [optional]
|
||||
**src_name** | **str** | | [optional]
|
||||
**msg_type_name** | **str** | | [optional]
|
||||
**group_name** | **str** | | [optional]
|
||||
|
||||
## Example
|
||||
|
||||
|
||||
@@ -36,7 +36,8 @@ class Eventmessage(BaseModel):
|
||||
des_name: Optional[StrictStr] = None
|
||||
src_name: Optional[StrictStr] = None
|
||||
msg_type_name: Optional[StrictStr] = None
|
||||
__properties = ["timestamp", "group", "group_id", "msg_type", "src_did", "des_did", "msg", "id", "des_name", "src_name", "msg_type_name"]
|
||||
group_name: Optional[StrictStr] = None
|
||||
__properties = ["timestamp", "group", "group_id", "msg_type", "src_did", "des_did", "msg", "id", "des_name", "src_name", "msg_type_name", "group_name"]
|
||||
|
||||
class Config:
|
||||
"""Pydantic configuration"""
|
||||
@@ -84,7 +85,8 @@ class Eventmessage(BaseModel):
|
||||
"id": obj.get("id"),
|
||||
"des_name": obj.get("des_name"),
|
||||
"src_name": obj.get("src_name"),
|
||||
"msg_type_name": obj.get("msg_type_name")
|
||||
"msg_type_name": obj.get("msg_type_name"),
|
||||
"group_name": obj.get("group_name")
|
||||
})
|
||||
return _obj
|
||||
|
||||
|
||||
Reference in New Issue
Block a user