Skip to content

Commit 2b716f8

Browse files
authored
Merge pull request #21 from SovereignEdgeEU-COGNIT/dev
Some fixes
2 parents 77880f5 + aad4326 commit 2b716f8

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

cognit/modules/_cognit_frontend_client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ def _get_edge_cluster_address(self) -> str:
221221
if self.is_max_latency_activated:
222222

223223
self.logger.debug("Max latency is activated, calculating latency for Edge Cluster Frontend Engines")
224-
# Calculate latency for each Edge Cluster Frontend Engine
225224
cluster_latencies = self.latency_calculator.get_latency_for_clusters(self.available_ecfs)
226225

227226
if not cluster_latencies:

cognit/modules/_device_runtime_state_machine.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from cognit.models._device_runtime import Call
99
from statemachine import StateMachine, State
1010

11+
from threading import Event
1112
import sys
1213

1314
sys.path.append(".")
@@ -64,7 +65,7 @@ class DeviceRuntimeStateMachine(StateMachine):
6465
token_not_valid_ready = ready.to(init, unless=["is_cfc_connected"])
6566
token_not_valid_ready_2 = ready.to(init, unless=["is_ecf_connected"])
6667
# 4.3 The requirements have changed, therefore, the requirements are uploaded again
67-
ready_update_requirements = ready.to(send_init_request, cond=["is_cfc_connected", "is_ecf_connected", "have_requirements_changed"])
68+
ready_update_requirements = ready.to(send_init_request, cond=["is_cfc_connected", "is_ecf_connected", "have_requirements_changed"], unless=["is_new_ecf_address_set"])
6869
# 4.4 Connect to the Edge Cluster Frontend Client if the address has changed
6970
ready_update_ecf_address = ready.to(get_ecf_address, cond=["is_cfc_connected", "is_ecf_connected", "is_new_ecf_address_set"], unless=["have_requirements_changed"])
7071

@@ -97,6 +98,7 @@ def __init__(self, config: CognitConfig, requirements: Scheduling, call_queue: C
9798
self.call_queue = call_queue
9899
self.sync_results_queue = sync_result_queue
99100

101+
self.update_ecf_address_event = Event()
100102
super().__init__()
101103

102104
# Get credentials by instantiating a CognitFrontendClient and authenticates to the Cognit Frontend
@@ -222,11 +224,7 @@ def get_new_ecf_address(self):
222224
"""
223225
Get the new Edge Cluster Frontend address from the CFC.
224226
"""
225-
self.new_ecf_address = self.cfc._get_edge_cluster_address()
226-
227-
if self.new_ecf_address == self.ecc_address:
228-
self.logger.debug("New ECF address is the same as the current one")
229-
self.new_ecf_address = None
227+
self.update_ecf_address_event.set()
230228

231229
# Checks if CF client has connection with the CF
232230
def is_cfc_connected(self):

cognit/modules/_latency_calculator.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ def get_latency_for_clusters(self, edge_clusters: list) -> dict:
6767
continue
6868

6969
latency_by_cluster[cluster_ip] = latency
70-
71-
# Return lowest latency cluster as JSON string
72-
if not latency_by_cluster:
73-
74-
self.logger.error("No valid edge clusters found.")
75-
return {"error": "No valid edge clusters found."}
7670

7771
return latency_by_cluster
7872

cognit/modules/_sm_handler.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ def handle_ready_state(self):
7979
"""
8080
Handle the ready state
8181
"""
82+
if self.sm.update_ecf_address_event.is_set():
83+
84+
self.logger.info("Updating ECF address...")
85+
self.sm.new_ecf_address = self.sm.cfc._get_edge_cluster_address()
86+
87+
if self.sm.new_ecf_address == self.sm.ecc_address:
88+
self.logger.info("New ECF address is the same as the current one. No update needed.")
89+
self.sm.new_ecf_address = None
90+
91+
self.sm.update_ecf_address_event.clear()
92+
8293
if not self.sm.is_cfc_connected():
8394
self.sm.token_not_valid_ready()
8495
elif not self.sm.is_ecf_connected():

examples/minimal_offload_sync.dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ WORKDIR /cognit
66
# Copy repository inside the image
77
COPY . .
88

9+
# Install ping to calculate latency
10+
RUN apt update -y && apt install iputils-ping -y
11+
912
# Install dependencies with no cache and build/install package directly to avoid leftover artifacts
1013
RUN pip install --upgrade --no-cache-dir pip setuptools wheel \
1114
&& pip install --no-cache-dir -r requirements.txt \

0 commit comments

Comments
 (0)