forked from pedrocjdpereira/osm-mec
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
133 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import time | ||
from ...threads.mec_apps_thread import containers | ||
from ...threads.websocket_service_thread import lat_queue | ||
|
||
|
||
def callback(data): | ||
if "containerInfo" in data and "nodeSpecs" in data: | ||
idsMonitored = [] | ||
for containerName, container in data["containerInfo"].items(): | ||
idsMonitored.append(containerName) | ||
node_specs = data["nodeSpecs"] | ||
if containerName not in containers: | ||
containers[containerName] = { | ||
"ns": container["ns_id"], | ||
"node": container["node"], | ||
"node_specs": node_specs[container["node"]], | ||
} | ||
containers[containerName]["node_specs"]["prev_cpu"] = 0 | ||
containers[containerName]["node_specs"]["prev_timestamp"] = 0 | ||
idsToDelete = [] | ||
for container_id in containers.keys(): | ||
if container_id not in idsMonitored: | ||
idsToDelete.append(container_id) | ||
for id in idsToDelete: | ||
del containers[id] | ||
|
||
elif "warning" in data: | ||
current_time = time.time() | ||
|
||
warning = data["warning"] | ||
container_name = warning["containerName"] | ||
|
||
if container_name in containers: | ||
containers[container_name]["warning"] = { | ||
"msg": warning["msg"], | ||
"timer": current_time | ||
} | ||
|
||
for container_name, container in containers.items(): | ||
if "warning" not in container: | ||
container["warning"] = { | ||
"msg": None, | ||
"timer": None, | ||
} | ||
elif container["warning"] and container["warning"]["timer"]: | ||
current_time = time.time() | ||
if current_time - container["warning"]["timer"] > 60: | ||
container["warning"]["timer"] = None | ||
container["warning"]["msg"] = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
from ...threads.container_info_thread import containers | ||
from ...threads.mec_apps_thread import containers | ||
from ...threads.websocket_service_thread import lat_queue | ||
|
||
|
||
def callback(data): | ||
print(containers.keys()) | ||
for container_id in containers.keys(): | ||
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) | ||
lat_queue.put(temp_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from .container_info_thread import ContainerInfoThread | ||
from .kafka_consumer_thread import KafkaConsumerThread | ||
from .websocket_service_thread import WebSocketServiceThread | ||
from .mec_apps_thread import SendMECAppsThread |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import threading | ||
import time | ||
import json | ||
|
||
from cherrypy.process import plugins | ||
|
||
from utils.db import DB | ||
from utils.kafka import KafkaUtils, producer | ||
|
||
containers = {} | ||
|
||
class SendMECAppsThread(plugins.SimplePlugin): | ||
"""Background thread that sends MEC Apps information""" | ||
|
||
def __init__(self, bus): | ||
super().__init__(bus) | ||
self.t = None | ||
|
||
def start(self): | ||
"""Plugin entrypoint""" | ||
self.t = threading.Thread(target=send_mec_apps) | ||
self.t.daemon = True | ||
self.t.start() | ||
|
||
|
||
def send_mec_apps(): | ||
while True: | ||
try: | ||
mec_apps = DB._list("appis") | ||
for mec_app in mec_apps: | ||
if '_id' in mec_app: | ||
mec_app['_id'] = str(mec_app['_id']) | ||
|
||
KafkaUtils.send_message( | ||
producer, | ||
"meao-oss", | ||
{"mec_apps": mec_apps}, | ||
) | ||
|
||
time.sleep(5) | ||
except Exception as e: | ||
raise e |