From 6b0286e28d9a93200906892f2a6e55cc23e2f608 Mon Sep 17 00:00:00 2001 From: Pedro Pereira Date: Fri, 26 Jul 2024 19:22:57 +0100 Subject: [PATCH] helm chart + many changes mostly bugs --- cfs-portal/Dockerfile | 2 + cfs-portal/src/api/api.tsx | 2 +- .../src/components/InstanceGrid/index.tsx | 28 +++++----- docker-compose.yml | 51 +++++++------------ meao/Dockerfile | 2 + osm-mec-helm-chart/Chart.yaml | 8 +++ osm-mec-helm-chart/README.md | 1 + ...p-mongo-db-data-persistentvolumeclaim.yaml | 12 +++++ ...s-portal-claim0-persistentvolumeclaim.yaml | 12 +++++ .../templates/cfs-portal-deployment.yaml | 33 ++++++++++++ .../templates/cfs-portal-service.yaml | 15 ++++++ .../templates/meao-deployment.yaml | 32 ++++++++++++ .../templates/mongo-deployment.yaml | 34 +++++++++++++ .../templates/mongo-express-deployment.yaml | 32 ++++++++++++ .../templates/mongo-express-service.yaml | 14 +++++ .../templates/mongo-service.yaml | 14 +++++ .../templates/oss-deployment.yaml | 41 +++++++++++++++ osm-mec-helm-chart/templates/oss-service.yaml | 19 +++++++ oss/Dockerfile | 2 + oss/utils/kafka/callbacks/get_latency.py | 13 +++-- oss/utils/threads/container_info_thread.py | 1 + oss/utils/threads/websocket_service_thread.py | 9 +++- run.sh | 11 +++- 23 files changed, 331 insertions(+), 57 deletions(-) create mode 100644 osm-mec-helm-chart/Chart.yaml create mode 100644 osm-mec-helm-chart/README.md create mode 100644 osm-mec-helm-chart/templates/app-mongo-db-data-persistentvolumeclaim.yaml create mode 100644 osm-mec-helm-chart/templates/cfs-portal-claim0-persistentvolumeclaim.yaml create mode 100644 osm-mec-helm-chart/templates/cfs-portal-deployment.yaml create mode 100644 osm-mec-helm-chart/templates/cfs-portal-service.yaml create mode 100644 osm-mec-helm-chart/templates/meao-deployment.yaml create mode 100644 osm-mec-helm-chart/templates/mongo-deployment.yaml create mode 100644 osm-mec-helm-chart/templates/mongo-express-deployment.yaml create mode 100644 osm-mec-helm-chart/templates/mongo-express-service.yaml create mode 100644 osm-mec-helm-chart/templates/mongo-service.yaml create mode 100644 osm-mec-helm-chart/templates/oss-deployment.yaml create mode 100644 osm-mec-helm-chart/templates/oss-service.yaml diff --git a/cfs-portal/Dockerfile b/cfs-portal/Dockerfile index 6b7f3f8..217ce85 100644 --- a/cfs-portal/Dockerfile +++ b/cfs-portal/Dockerfile @@ -2,6 +2,8 @@ FROM node:14 WORKDIR /usr/app +COPY . /usr/app + COPY package*.json ./ RUN npm install diff --git a/cfs-portal/src/api/api.tsx b/cfs-portal/src/api/api.tsx index 065b3ff..e6a6baa 100644 --- a/cfs-portal/src/api/api.tsx +++ b/cfs-portal/src/api/api.tsx @@ -1,7 +1,7 @@ import axios from "axios"; const api = axios.create({ - baseURL: 'http://localhost:8080/oss/v1' + baseURL: 'http://10.255.32.88:8080/oss/v1' }); // App Package diff --git a/cfs-portal/src/components/InstanceGrid/index.tsx b/cfs-portal/src/components/InstanceGrid/index.tsx index e04c476..90bd816 100644 --- a/cfs-portal/src/components/InstanceGrid/index.tsx +++ b/cfs-portal/src/components/InstanceGrid/index.tsx @@ -74,7 +74,7 @@ const InstanceGrid = ({ minimalConfig = false, instanceCount }: InstanceGridProp }, []); useEffect(() => { - const ws = new WebSocket('ws://localhost:8001'); + const ws = new WebSocket('ws://10.255.32.88:8001'); setSocket(ws); }, []); @@ -86,7 +86,15 @@ const InstanceGrid = ({ minimalConfig = false, instanceCount }: InstanceGridProp socket.onmessage = (event) => { const data = JSON.parse(event.data); setMetrics((prevMetrics) => { - if (prevMetrics && data.appi_id in prevMetrics) { + console.log(data) + console.log(prevMetrics) + if(data.appi_id != undefined){ + if(!prevMetrics){ + prevMetrics = {} + } + if (!(data.appi_id in prevMetrics)){ + prevMetrics[data.appi_id] = {} + } if (data.mem_load != undefined && data.cpu_load != undefined) { return { ...prevMetrics, @@ -98,7 +106,7 @@ const InstanceGrid = ({ minimalConfig = false, instanceCount }: InstanceGridProp }; } else { - var temp = { + return { ...prevMetrics, [data.appi_id]: { ...prevMetrics[data.appi_id], @@ -106,20 +114,8 @@ const InstanceGrid = ({ minimalConfig = false, instanceCount }: InstanceGridProp lat: data[data.node] } }; - console.log(temp) - return temp - } - } else { - return { - ...prevMetrics, - [data.appi_id]: { - memLoad: data.mem_load, - cpuLoad: data.cpu_load, - node: data.node, - lat: data[data.node] - } }; - } + }; }); }; socket.onclose = () => { diff --git a/docker-compose.yml b/docker-compose.yml index 6ae2fad..0ef0408 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,21 +14,21 @@ services: oss: build: ./oss ports: - - "${OSS_PORT}:${OSS_PORT}" - - "${OSS_WS_PORT}:${OSS_WS_PORT}" + - "8080:8080" + - "8001:8001" expose: - - "${OSS_PORT}" + - "8080" volumes: - ./oss:/usr/app depends_on: - mongo environment: - - OSM_HOSTNAME=${OSM_IP} - - OSS_PORT=${OSS_PORT} - - OSS_WS_PORT=${OSS_WS_PORT} - - KAFKA_BOOTSTRAP_SERVERS=${OSM_IP}:${KAFKA_PORT} - - MONGO_USER=${MONGO_USER} - - MONGO_PASSWORD=${MONGO_PASSWORD} + - OSM_HOSTNAME=10.255.32.88:9999 + - OSS_PORT=8080 + - OSS_WS_PORT=8001 + - KAFKA_BOOTSTRAP_SERVERS=10.255.32.88:9999:14000 + - MONGO_USER=root + - MONGO_PASSWORD=pass restart: on-failure networks: - temp-network @@ -42,35 +42,22 @@ services: # - zookeeper - mongo environment: - - OSM_HOSTNAME=${OSM_IP} - - KAFKA_BOOTSTRAP_SERVERS=${OSM_IP}:${KAFKA_PORT} - - MONGO_USER=${MONGO_USER} - - MONGO_PASSWORD=${MONGO_PASSWORD} + - OSM_HOSTNAME=10.255.32.88:9999 + - KAFKA_BOOTSTRAP_SERVERS=10.255.32.88:9999:14000 + - MONGO_USER=root + - MONGO_PASSWORD=pass restart: on-failure networks: - temp-network - #container-data-api: - # build: ./container-data-api - # ports: - # - "8000:8000" - # environment: - # - PYTHONUNBUFFERED=1 - # - NBI_URL=https://${OSM_IP}/osm - # - KUBECTL_COMMAND=${KUBECTL_COMMAND} - # - KUBECTL_CONFIG_PATH=${KUBECTL_CONFIG_PATH} - # - UPDATE_CONTAINER_IDS_FREQ=${UPDATE_CONTAINER_IDS_FREQ} - # networks: - # - temp-network - mongo: image: mongo volumes: - app-mongo-db-data:/data/db restart: always environment: - MONGO_INITDB_ROOT_USERNAME: "${MONGO_USER}" - MONGO_INITDB_ROOT_PASSWORD: "${MONGO_PASSWORD}" + MONGO_INITDB_ROOT_USERNAME: "root" + MONGO_INITDB_ROOT_PASSWORD: "pass" networks: - temp-network @@ -80,10 +67,10 @@ services: ports: - 8081:8081 environment: - ME_CONFIG_MONGODB_ADMINUSERNAME: "${MONGO_USER}" - ME_CONFIG_MONGODB_ADMINPASSWORD: "${MONGO_PASSWORD}" - ME_CONFIG_MONGODB_URL: mongodb://${MONGO_USER}:${MONGO_PASSWORD}@mongo:27017/ - ME_CONFIG_MONGODB_ENABLE_ADMIN: "${MONGO_EXPRESS_ENABLE_ADMIN}" + ME_CONFIG_MONGODB_ADMINUSERNAME: "root" + ME_CONFIG_MONGODB_ADMINPASSWORD: "pass" + ME_CONFIG_MONGODB_URL: mongodb://root:pass@mongo:27017/ + ME_CONFIG_MONGODB_ENABLE_ADMIN: "true" networks: - temp-network diff --git a/meao/Dockerfile b/meao/Dockerfile index 176ae95..8764622 100644 --- a/meao/Dockerfile +++ b/meao/Dockerfile @@ -6,6 +6,8 @@ ENV PYTHONUNBUFFERED=1 WORKDIR /usr/app +COPY . /usr/app + COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt diff --git a/osm-mec-helm-chart/Chart.yaml b/osm-mec-helm-chart/Chart.yaml new file mode 100644 index 0000000..0f39f63 --- /dev/null +++ b/osm-mec-helm-chart/Chart.yaml @@ -0,0 +1,8 @@ +name: osm-mec +description: A Helm chart for OSM-MEC project +version: 0.0.1 +apiVersion: v1 +keywords: + - osm-mec +sources: +home: diff --git a/osm-mec-helm-chart/README.md b/osm-mec-helm-chart/README.md new file mode 100644 index 0000000..d3885b6 --- /dev/null +++ b/osm-mec-helm-chart/README.md @@ -0,0 +1 @@ +This chart was created by Kompose diff --git a/osm-mec-helm-chart/templates/app-mongo-db-data-persistentvolumeclaim.yaml b/osm-mec-helm-chart/templates/app-mongo-db-data-persistentvolumeclaim.yaml new file mode 100644 index 0000000..7b1d3b8 --- /dev/null +++ b/osm-mec-helm-chart/templates/app-mongo-db-data-persistentvolumeclaim.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + labels: + app: app-mongo-db-data + name: app-mongo-db-data +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 100Mi diff --git a/osm-mec-helm-chart/templates/cfs-portal-claim0-persistentvolumeclaim.yaml b/osm-mec-helm-chart/templates/cfs-portal-claim0-persistentvolumeclaim.yaml new file mode 100644 index 0000000..dce4c09 --- /dev/null +++ b/osm-mec-helm-chart/templates/cfs-portal-claim0-persistentvolumeclaim.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + labels: + app: cfs-portal-claim0 + name: cfs-portal-claim0 +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 100Mi diff --git a/osm-mec-helm-chart/templates/cfs-portal-deployment.yaml b/osm-mec-helm-chart/templates/cfs-portal-deployment.yaml new file mode 100644 index 0000000..9c268b7 --- /dev/null +++ b/osm-mec-helm-chart/templates/cfs-portal-deployment.yaml @@ -0,0 +1,33 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: cfs-portal + name: cfs-portal +spec: + replicas: 1 + selector: + matchLabels: + app: cfs-portal + strategy: + type: Recreate + template: + metadata: + labels: + app: cfs-portal + spec: + containers: + - env: + - name: CHOKIDAR_USEPOLLING + value: "true" + image: localhost:5000/cfs-portal:latest + imagePullPolicy: Always + name: cfs-portal + ports: + - containerPort: 3000 + protocol: TCP + restartPolicy: Always + volumes: + - name: cfs-portal-claim0 + persistentVolumeClaim: + claimName: cfs-portal-claim0 diff --git a/osm-mec-helm-chart/templates/cfs-portal-service.yaml b/osm-mec-helm-chart/templates/cfs-portal-service.yaml new file mode 100644 index 0000000..f7b8062 --- /dev/null +++ b/osm-mec-helm-chart/templates/cfs-portal-service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: cfs-portal + name: cfs-portal +spec: + type: NodePort + ports: + - name: "3000" + port: 3000 + targetPort: 3000 + nodePort: 30000 + selector: + app: cfs-portal diff --git a/osm-mec-helm-chart/templates/meao-deployment.yaml b/osm-mec-helm-chart/templates/meao-deployment.yaml new file mode 100644 index 0000000..7a75187 --- /dev/null +++ b/osm-mec-helm-chart/templates/meao-deployment.yaml @@ -0,0 +1,32 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: meao + name: meao +spec: + replicas: 1 + selector: + matchLabels: + app: meao + strategy: + type: Recreate + template: + metadata: + labels: + app: meao + spec: + containers: + - env: + - name: KAFKA_BOOTSTRAP_SERVERS + value: 10.255.32.88:14000 + - name: MONGO_PASSWORD + value: pass + - name: MONGO_USER + value: root + - name: OSM_HOSTNAME + value: 10.255.32.88:9999 + image: localhost:5000/meao:latest + imagePullPolicy: Always + name: meao + restartPolicy: Always diff --git a/osm-mec-helm-chart/templates/mongo-deployment.yaml b/osm-mec-helm-chart/templates/mongo-deployment.yaml new file mode 100644 index 0000000..83f11f7 --- /dev/null +++ b/osm-mec-helm-chart/templates/mongo-deployment.yaml @@ -0,0 +1,34 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: mongo + name: mongo +spec: + replicas: 1 + selector: + matchLabels: + app: mongo + strategy: + type: Recreate + template: + metadata: + labels: + app: mongo + spec: + containers: + - env: + - name: MONGO_INITDB_ROOT_PASSWORD + value: pass + - name: MONGO_INITDB_ROOT_USERNAME + value: root + image: mongo + name: mongo + volumeMounts: + - mountPath: /data/db + name: app-mongo-db-data + restartPolicy: Always + volumes: + - name: app-mongo-db-data + persistentVolumeClaim: + claimName: app-mongo-db-data diff --git a/osm-mec-helm-chart/templates/mongo-express-deployment.yaml b/osm-mec-helm-chart/templates/mongo-express-deployment.yaml new file mode 100644 index 0000000..10cad74 --- /dev/null +++ b/osm-mec-helm-chart/templates/mongo-express-deployment.yaml @@ -0,0 +1,32 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: mongo-express + name: mongo-express +spec: + replicas: 1 + selector: + matchLabels: + app: mongo-express + template: + metadata: + labels: + app: mongo-express + spec: + containers: + - env: + - name: ME_CONFIG_MONGODB_ADMINPASSWORD + value: pass + - name: ME_CONFIG_MONGODB_ADMINUSERNAME + value: root + - name: ME_CONFIG_MONGODB_ENABLE_ADMIN + value: "true" + - name: ME_CONFIG_MONGODB_URL + value: mongodb://root:pass@mongo:27017/ + image: mongo-express + name: mongo-express + ports: + - containerPort: 8081 + protocol: TCP + restartPolicy: Always diff --git a/osm-mec-helm-chart/templates/mongo-express-service.yaml b/osm-mec-helm-chart/templates/mongo-express-service.yaml new file mode 100644 index 0000000..d0923a7 --- /dev/null +++ b/osm-mec-helm-chart/templates/mongo-express-service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: mongo-express + name: mongo-express +spec: + type: ClusterIP + ports: + - name: "8081" + port: 8081 + targetPort: 8081 + selector: + app: mongo-express diff --git a/osm-mec-helm-chart/templates/mongo-service.yaml b/osm-mec-helm-chart/templates/mongo-service.yaml new file mode 100644 index 0000000..55ef5ad --- /dev/null +++ b/osm-mec-helm-chart/templates/mongo-service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: mongo + name: mongo +spec: + type: ClusterIP + ports: + - name: "27017" + port: 27017 + targetPort: 27017 + selector: + app: mongo diff --git a/osm-mec-helm-chart/templates/oss-deployment.yaml b/osm-mec-helm-chart/templates/oss-deployment.yaml new file mode 100644 index 0000000..64cedd8 --- /dev/null +++ b/osm-mec-helm-chart/templates/oss-deployment.yaml @@ -0,0 +1,41 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: oss + name: oss +spec: + replicas: 1 + selector: + matchLabels: + app: oss + strategy: + type: Recreate + template: + metadata: + labels: + app: oss + spec: + containers: + - env: + - name: KAFKA_BOOTSTRAP_SERVERS + value: 10.255.32.88:9999:14000 + - name: MONGO_PASSWORD + value: pass + - name: MONGO_USER + value: root + - name: OSM_HOSTNAME + value: 10.255.32.88:9999 + - name: OSS_PORT + value: "8080" + - name: OSS_WS_PORT + value: "8001" + image: localhost:5000/oss:latest + imagePullPolicy: Always + name: oss + ports: + - containerPort: 8080 + protocol: TCP + - containerPort: 8001 + protocol: TCP + restartPolicy: Always \ No newline at end of file diff --git a/osm-mec-helm-chart/templates/oss-service.yaml b/osm-mec-helm-chart/templates/oss-service.yaml new file mode 100644 index 0000000..febc290 --- /dev/null +++ b/osm-mec-helm-chart/templates/oss-service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: oss + name: oss +spec: + type: NodePort + ports: + - name: "8080" + port: 8080 + targetPort: 8080 + nodePort: 8080 + - name: "8001" + port: 8001 + targetPort: 8001 + nodePort: 8001 + selector: + app: oss diff --git a/oss/Dockerfile b/oss/Dockerfile index 96f50e1..a33f9ba 100644 --- a/oss/Dockerfile +++ b/oss/Dockerfile @@ -6,6 +6,8 @@ ENV PYTHONUNBUFFERED=1 WORKDIR /usr/app +COPY . /usr/app + COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt diff --git a/oss/utils/kafka/callbacks/get_latency.py b/oss/utils/kafka/callbacks/get_latency.py index 5847e39..25ee43e 100644 --- a/oss/utils/kafka/callbacks/get_latency.py +++ b/oss/utils/kafka/callbacks/get_latency.py @@ -3,8 +3,13 @@ def callback(data): + print(containers.keys()) for container_id in containers.keys(): - data["node"] = containers[container_id]["node"] - data["appi_id"] = containers[container_id]["ns"] - break - lat_queue.put(data) \ No newline at end of file + temp_data = { + "k3s-worker1-pedrocjdpereira": data["k3s-worker1-pedrocjdpereira"], + "k3s-worker2-pedrocjdpereira": data["k3s-worker2-pedrocjdpereira"], + } + temp_data["node"] = containers[container_id]["node"] + temp_data["appi_id"] = containers[container_id]["ns"] + lat_queue.put(temp_data) + print(temp_data) \ No newline at end of file diff --git a/oss/utils/threads/container_info_thread.py b/oss/utils/threads/container_info_thread.py index 2252e1f..7f1afc4 100644 --- a/oss/utils/threads/container_info_thread.py +++ b/oss/utils/threads/container_info_thread.py @@ -26,6 +26,7 @@ def get_containers_info(): while True: try: response = requests.get("http://meao-monitoring:8000/containerInfo") + print(response) idsMonitored = [] for containerName, container in (response.json()["ContainerInfo"]).items(): idsMonitored.append(containerName) diff --git a/oss/utils/threads/websocket_service_thread.py b/oss/utils/threads/websocket_service_thread.py index 1d933a5..15e1e22 100644 --- a/oss/utils/threads/websocket_service_thread.py +++ b/oss/utils/threads/websocket_service_thread.py @@ -46,6 +46,8 @@ async def send_metrics(): await websocket.send(json.dumps(metrics)) if not lat_queue.empty(): lat = lat_queue.get() + print("sending data") + print(lat) for websocket in ws: await websocket.send(json.dumps(lat)) await asyncio.sleep(0.1) @@ -58,7 +60,10 @@ async def send_metrics(): async def receive_connection(websocket, path): ws.append(websocket) try: - async for message in websocket: - await websocket.wait_closed() + try: + async for message in websocket: + await websocket.wait_closed() + except Exception as e: + asyncio.run(send_metrics()) finally: ws.remove(websocket) diff --git a/run.sh b/run.sh index aaf7953..6df7796 100755 --- a/run.sh +++ b/run.sh @@ -1,2 +1,9 @@ -docker compose down --rmi local -docker compose up --build +helm -n meao uninstall osm-mec +docker build -t localhost:5000/cfs-portal cfs-portal +docker push localhost:5000/cfs-portal +docker build -t localhost:5000/meao meao +docker push localhost:5000/meao +docker build -t localhost:5000/oss oss +docker push localhost:5000/oss +helm -n meao upgrade --install osm-mec osm-mec-helm-chart +kubectl get pods -A \ No newline at end of file