Fixed eventmessage formatting problem #62

Merged
Luis merged 4 commits from Qubasa-main into main 2024-01-24 15:52:16 +00:00
4 changed files with 107 additions and 18 deletions
Showing only changes of commit 1b433ea314 - Show all commits

View File

@@ -33,6 +33,31 @@ And then run the docker file by executing:
docker run -p 127.0.0.1:2979:2979 clan-docker:latest 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 # 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: For the tests we automatically generate a python client for the API endpoints. To do this execute while inside the `pkgs/clan-cli` folder:

View File

@@ -21,13 +21,62 @@ c1_url = f"http://{host}:{c1_port}/docs"
c2_url = f"http://{host}:{c2_port}/docs" c2_url = f"http://{host}:{c2_port}/docs"
msg_type_to_label = { group_type_to_label = {
1: "Attachement", 1: {
2: "Connection Setup", "name": "Attachement",
3: "Presentation", 1: "Request Send",
4: "DID Resolution", 2: "Request Received",
5: "Service De-registration", 3: "Response Send",
6: "Service Registration", 4: "Response Received",
7: "Service Discovery", },
8: "Service Operation", 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",
},
} }

View File

@@ -8,7 +8,7 @@ from fastapi import APIRouter, BackgroundTasks, Depends, Query
from fastapi.responses import HTMLResponse, JSONResponse from fastapi.responses import HTMLResponse, JSONResponse
from sqlalchemy.orm import Session 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 ...errors import ClanError
from .. import sql_crud, sql_db, sql_models from .. import sql_crud, sql_db, sql_models
@@ -370,25 +370,36 @@ def get_all_eventmessages(
result: dict[int, dict[int, List[Eventmessage]]] = {} result: dict[int, dict[int, List[Eventmessage]]] = {}
for msg in eventmessages: 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 = sql_crud.get_entity_by_did(db, msg.src_did)
src_name = src_name if src_name is None else src_name.name 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 = sql_crud.get_entity_by_did(db, msg.des_did)
des_name = des_name if des_name is None else des_name.name des_name = des_name if des_name is None else des_name.name
if result.get(msg.group) is None: # Initialize the result array and dictionary
result[msg.group] = {} if result.get(group_name) is None:
if result[msg.group].get(msg.group_id) is None: result[group_name] = {}
result[msg.group][msg.group_id] = [] 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( Eventmessage(
id=msg.id, id=msg.id,
timestamp=msg.timestamp, timestamp=msg.timestamp,
group=msg.group, group=msg.group,
group_name=group_name,
group_id=msg.group_id, group_id=msg.group_id,
msg_type=msg.msg_type, msg_type=msg.msg_type,
msg_type_name=msg_name, msg_type_name=msg_type_name,
src_did=msg.src_did, src_did=msg.src_did,
src_name=src_name, src_name=src_name,
des_did=msg.des_did, des_did=msg.des_did,
@@ -396,6 +407,9 @@ def get_all_eventmessages(
msg=msg.msg, msg=msg.msg,
).dict() ).dict()
) )
# sort by timestamp
result_arr.sort(key=lambda x: x["timestamp"])
return JSONResponse(content=result, status_code=200) return JSONResponse(content=result, status_code=200)

View File

@@ -185,7 +185,8 @@ class Eventmessage(EventmessageCreate):
id: int = Field(...) id: int = Field(...)
des_name: Optional[str] = Field(default=None, example="C2") des_name: Optional[str] = Field(default=None, example="C2")
src_name: Optional[str] = Field(default=None, example="C1") 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: class Config:
orm_mode = True orm_mode = True