From 1b433ea31467b0fac142ffbaf03a2e19fd52d595 Mon Sep 17 00:00:00 2001 From: Luis-Hebendanz Date: Wed, 24 Jan 2024 16:19:36 +0100 Subject: [PATCH] Fixed eventmessage formatting problem --- pkgs/clan-cli/README.md | 25 +++++++ pkgs/clan-cli/clan_cli/config.py | 67 ++++++++++++++++--- .../clan_cli/webui/routers/endpoints.py | 30 ++++++--- pkgs/clan-cli/clan_cli/webui/schemas.py | 3 +- 4 files changed, 107 insertions(+), 18 deletions(-) diff --git a/pkgs/clan-cli/README.md b/pkgs/clan-cli/README.md index 3a11936..922c317 100644 --- a/pkgs/clan-cli/README.md +++ b/pkgs/clan-cli/README.md @@ -33,6 +33,31 @@ And then run the docker file by executing: docker run -p 127.0.0.1:2979:2979 clan-docker:latest ``` +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: diff --git a/pkgs/clan-cli/clan_cli/config.py b/pkgs/clan-cli/clan_cli/config.py index 24e5fcd..5baac19 100644 --- a/pkgs/clan-cli/clan_cli/config.py +++ b/pkgs/clan-cli/clan_cli/config.py @@ -21,13 +21,62 @@ 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", +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", + }, } diff --git a/pkgs/clan-cli/clan_cli/webui/routers/endpoints.py b/pkgs/clan-cli/clan_cli/webui/routers/endpoints.py index 56016d9..4417c78 100644 --- a/pkgs/clan-cli/clan_cli/webui/routers/endpoints.py +++ b/pkgs/clan-cli/clan_cli/webui/routers/endpoints.py @@ -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) diff --git a/pkgs/clan-cli/clan_cli/webui/schemas.py b/pkgs/clan-cli/clan_cli/webui/schemas.py index c87c4b5..a17986f 100644 --- a/pkgs/clan-cli/clan_cli/webui/schemas.py +++ b/pkgs/clan-cli/clan_cli/webui/schemas.py @@ -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: str = Field(..., example="Request Send") + group_name: str = Field(..., example="Presentation") class Config: orm_mode = True