Skip to content

Commit

Permalink
Create node_manager.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 10, 2024
1 parent aaa7a92 commit a1c2a2d
Showing 1 changed file with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import socket
import threading
from node import Node

class NodeManager:
def __init__(self, node_pool):
self.node_pool = node_pool
self.nodes = {}

def add_node(self, node):
self.nodes[node.node_id] = node

def remove_node(self, node_id):
del self.nodes[node_id]

def get_node(self, node_id):
return self.nodes.get(node_id)

def start_nodes(self):
for node in self.nodes.values():
node.start()

def stop_nodes(self):
for node in self.nodes.values():
node.stop()

def update_node_utilization(self):
for node in self.nodes.values():
node.update_utilization()

def get_node_info(self, node_id):
node = self.get_node(node_id)
if node:
return node.get_node_info()
return None

class NodeManagerServer:
def __init__(self, node_manager, host, port):
self.node_manager = node_manager
self.host = host
self.port = port
self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.server_socket.bind((self.host, self.port))
self.server_socket.listen(5)

def start(self):
print(f'Starting node manager server on {self.host}:{self.port}...')
while True:
client_socket, address = self.server_socket.accept()
client_thread = threading.Thread(target=self.handle_client, args=(client_socket,))
client_thread.start()

def handle_client(self, client_socket):
# Handle client requests (e.g., add node, remove node, get node info)
pass

0 comments on commit a1c2a2d

Please sign in to comment.