def __init__(self, logfile_path, console=False): """ Logger API at Client Side to store the logs locally and sent to Central Logger MQ Parameters - RMQ - Create a RabbitMQ Object and pass it - logfile_path - Path where to create log file - console - whether to diaplay log messages on screen - Default false """ self.RMQ = RabbitMQ() #Creating queue and logger self.log_queue = queue.Queue(-1) #infinite size self.queue_handler = QueueHandler(self.log_queue) self.logger = logging.getLogger() self.logger.addHandler(self.queue_handler) #formatter self.formatter = logging.Formatter(' %(message)s') #file handler - write to file self.file_handler_loc = logging.FileHandler(logfile_path) self.file_handler_loc.setFormatter(self.formatter) #console handler - print on screen if (console == True): self.console_handler = logging.StreamHandler() self.console_handler.setFormatter(self.formatter) self.listener = QueueListener(self.log_queue, self.console_handler, self.file_handler_loc) else: self.listener = QueueListener(self.log_queue, self.file_handler_loc)
def callback(ch, method, properties, body): global port print("Receiving") body = body.decode("utf-8").replace('\0', '') #Receiving_Message = json.loads(body).replace('\'','\"') Receiving_Message = json.loads(body) Request_type = Receiving_Message["Request_type"] if (Request_type == "Deploy"): Ack_msg = Request_Deploy(Receiving_Message, port) port += 1 message = json.dumps(str(Ack_msg)) obj = RabbitMQ() obj.send("", "Docker_SM", message) print("\n\nSent ack: ", message) if (Request_type == "Kill"): Request_Kill(Receiving_Message)
def callback_si(ch, method, properties, body): body = body.decode("utf-8").replace('\0', '') M.Service_Info = json.loads(body) print("\nReceiving Service Info: ", M.Service_Info) for service in M.Service_Info.keys(): Instances_list = M.Service_Info[service] request_HM_GW = {} request_HM_GW["Gateway_IPs"] = [] request_HM_HT = {} model_instances = 0 service_instances = 0 for i in range(len(Instances_list)): if Instances_list[i][4] == "model": IP = Instances_list[i][0] model_result = M.Check_Model(Instances_list[i]) service_result = 1 if i+1 < len(Instances_list) and Instances_list[i+1][4] == "exe" and Instances_list[i+1][5] == Instances_list[i][5]: service_result = M.Check_Service(Instances_list[i+1]) if model_result==0 or service_result==0: if Instances_list[i][2] == "Up" : if IP in M.Gateway_Info.keys(): request_HM_GW["Request_Type"] = "Gateway_Deploy" request_HM_GW["Gateway_IPs"].append([IP]) request_HM_GW["Service_ID"] = service else: model_instances = model_instances + 1 Instances_list[i][2] = "Down" i = i + 1 elif Instances_list[i][4] == "exe": service_result = M.Check_Service(Instances_list[i]) if service_result == 0 : if Instances_list[i][2] == "Up" : service_instances = service_instances + 1 Instances_list[i][2] = "Down" if model_instances > 0: request_HM_HT["Request_Type"] = "Model_Submit" request_HM_HT["Model_ID"] = service request_HM_HT["Instances"] = str(model_instances) request_HM_HT_json = json.dumps(request_HM_HT) msg_obj = RabbitMQ() msg_obj.send("", "MT_HM", request_HM_HT_json) print("Model start on host Request sent to HM: ", request_HM_HT_json) if service_instances > 0: request_HM_HT["Request_Type"] = "Service_Submit" request_HM_HT["Model_ID"] = service request_HM_HT["Instances"] = str(service_instances) request_HM_HT_json = json.dumps(request_HM_HT) msg_obj = RabbitMQ() msg_obj.send("", "MT_HM", request_HM_HT_json) print("Service start Request sent to HM: ", request_HM_HT_json) if len(request_HM_GW["Gateway_IPs"]) > 0: request_HM_GW_json = json.dumps(request_HM_GW) msg_obj = RabbitMQ() msg_obj.send("", "MT_HM", request_HM_GW_json) print("Model start on Gateway Request sent to HM: ", request_HM_GW_json) M.Read_Service_Info()
def Recieve_from_RG_MTHC(): msg_obj.receive(callback_hc, "", "RG_MTHC") def Recieve_from_RG_MTGC(): msg_obj.receive(callback_gc, "", "RG_MTGC") def Recieve_from_RG_MTSI(): msg_obj.receive(callback_si, "", "RG_MTSI") def Recieve_from_RG_MTPI(): msg_obj.receive(callback_pi, "", "RG_MTPI") Registry_obj = Registry_API() msg_obj = RabbitMQ() local_password = sys.argv[1] M = Monitor(local_password) t2 = threading.Thread(target=Recieve_from_RG_MTHC) t2.start() t3 = threading.Thread(target=Recieve_from_RG_MTGC) t3.start() t4 = threading.Thread(target=Recieve_from_RG_MTSI) t4.start() t5 = threading.Thread(target=Recieve_from_RG_MTPI) t5.start()
from app import db,bcrypt from passlib.hash import sha256_crypt from sqlalchemy import create_engine , update from app.models import Person,Application,User,Gateway,Sensor,Service import numpy as np import os from app.Deployment_Manager import Deployment_Manager from db_server import * from queue_req_resp import RabbitMQ from app.Registry_API import Registry_API from werkzeug.utils import secure_filename from threading import Thread RMQ=RabbitMQ() def ReceivefromSM(exchange, key): print("Listening......") RMQ.receive(processInput, exchange, key) def processInput( ch, method, properties, body): print("Received req from SM") data = json.loads(body) request_type = data["Request_Type"] if( request_type == "Register_Service_UI"): serv_id = data["Service_ID"] print("UI-service",serv_id) ip = data["IP"] port = data["Port"] ui_server=str(ip)+":"+str(port)
#Receive Application info from Deployment Manager msg_obj.receive(callback_DM, "", "DM_HM") def listen_MT(): msg_obj.receive(callback_DM, "", "MT_HM") def listen_LB(): msg_obj.receive(callback_DM, "", "LBB_HM") def listen_LB(): msg_obj.receive(callback_DM, "", "FM_HM") msg_obj = RabbitMQ() hm_obj = host_manager() rg_obj = Registry_API() msg_obj.create_ServiceQueues("DM", "RG") msg_obj.create_ServiceQueues("MT", "HM") msg_obj.create_ServiceQueues("SM", "RG") msg_obj.create_ServiceQueues("DM", "HM") msg_obj.create_ServiceQueues("RG", "HM") msg_obj.create_ServiceQueues("LBB", "HM") msg_obj.create_ServiceQueues("LB", "HM") # t0 = threading.Thread(target = listen_RG) t1 = threading.Thread(target = listen_DM) t2 = threading.Thread(target = listen_MT)
# load_at_hosts = {"service1":[["ip1",44,"yes"],["ip2",22,"no"]],"service2":[["ip1",12,"yes"]]} load_at_hosts = {} host_credentials = {} new_load_at_hosts = {} new_load_at_hosts2 = {} perm_list_of_ips = [] pool_list = {} pool_list2 = {} pool={} service_ids = [] upper_threshold = 60 lower_threshold = 2 upper_queue_threshold = 10 lower_queue_threshold = -1 msg_obj = RabbitMQ() reg_obj = Registry_API() def getting_host_credentials(): reg_obj.Read_Host_Creds("","LBHC_RG","RG_LBHC") # def reload_interval(): # value = "no" # load = 0 # pool_list = {k:load for k in perm_list_of_ips} # pool_list2 = {k:value for k in perm_list_of_ips} def get_current_status_from_registry(): reg_obj.Read_Service_Inst_Info("","LBSI_RG","RG_LBSI") # should be running on seperate thread to continuously update data structure
def Deploy_App(self, App_Dev_Id, App_Id, Package_Absolute_Path): # ---------- Unzip Package ------------- # print("Application ID-", App_Id) Current_Working_Direcory = os.getcwd() zip_ref = zipfile.ZipFile(Package_Absolute_Path, 'r') zip_ref.extractall(Current_Working_Direcory) zip_ref.close() Unzip_File_Name = os.path.basename(Package_Absolute_Path)[:-4] os.rename(Current_Working_Direcory + "/" + Unzip_File_Name, Current_Working_Direcory + "/" + str(App_Id)) # --------- check service name ---------- # # if(not self.Parse_Application_config(Current_Working_Direcory+"/"+str(App_Id))): # # Send message that service is mismatch # # print ("Mismatch service name") # sys.exit(1) # --------- Store in NFS -------------- # # print ("Connecting to NFS") # self.NFS_Obj.mount("", self.local_nfs_dir) List_Of_Directories = os.listdir(self.mount_path) print(List_Of_Directories) print(self.mount_path) if str(App_Dev_Id) not in List_Of_Directories: os.mkdir(self.mount_path + "/" + str(App_Dev_Id)) List_Of_App_Directories = os.listdir(self.mount_path + "/" + str(App_Dev_Id)) print(List_Of_App_Directories) if str(App_Id) not in List_Of_App_Directories: os.mkdir(self.mount_path + "/" + str(App_Dev_Id) + "/" + str(App_Id)) copy_tree(Current_Working_Direcory + "/" + str(App_Id), self.mount_path + "/" + str(App_Dev_Id) + "/" + str(App_Id)) # self.NFS_Obj.copy(Current_Working_Direcory+"/"+str(App_Id), self.mount_path+"/"+str(App_Dev_Id)+"/") # print ("DisConnecting to NFS") time.sleep(1) # self.NFS_Obj.unmount(self.local_nfs_dir) # -------------- Artefacts staorage links ------------------- # Model_Link = "/" + str(App_Dev_Id) + "/" + str(App_Id) + "/Models" App_Link = "/" + str(App_Dev_Id) + "/" + str(App_Id) + "/AppLogic" Service_Link = "/" + str(App_Dev_Id) + "/" + str(App_Id) + "/Services" Config_Link = "/" + str(App_Dev_Id) + "/" + str(App_Id) + "/Config" Models = self.Get_Models_Or_Services_Information( App_Dev_Id, App_Id, Current_Working_Direcory + "/" + str(App_Id), "Models") Services = self.Get_Models_Or_Services_Information( App_Dev_Id, App_Id, Current_Working_Direcory + "/" + str(App_Id), "Services") print(Models) print(Services) # print (Model_Link) # print (App_Link) # print (Service_Link) # print (Config_Link) # ------------- Store Artefacts staorage links in Registry ---------------- # Registry_Message = { "Request_Type": "Write", "DS_Name": "Storage_info", "Value": [{ "App_id": App_Id, "Model_Link": Model_Link, "App_Link": App_Link, "Service_Link": Service_Link, "Config_Link": Config_Link }] } Registry_Message = json.dumps(Registry_Message) obj_RG = RabbitMQ() obj_RG.send("", "DM_RG", Registry_Message) # ----------- Send request to Host Manager ---------------- # Host_Manager_Message = { "Request_Type": "App_Submit", "AD_ID": App_Dev_Id, "App_Id": App_Id, "Models": Models, "Services": Services, "App_Link": App_Link, "Config_Link": Config_Link } Host_Manager_Message = json.dumps(Host_Manager_Message) obj_HM = RabbitMQ() obj_HM.send("", "DM_HM", Host_Manager_Message) # Deleting temporary folders created shutil.rmtree(Current_Working_Direcory + "/" + str(App_Id))
second=0) scheduler.add_job(kill_service, 'date', run_date=end_date, args=[serviceName]) if streamType == 1: stream_interval %= 100 #scheduler.add_job(inference_batch_data, 'date', run_date=datetime(2019, 03, 18, st_hour, st_min, 5), args=[serviceName]) #job = scheduler2.add_interval_job(inference_batch_data, minutes = stream_interval, start_date = st_date + datetime.timedelta(seconds=DEPLOYMENT_TIME), args=[serviceName]) if endtime != 0: scheduler.add_job(remove_job, 'date', run_date=end_date + datetime.timedelta(seconds=KILL_TIME), args=[job]) #scheduler.add_job(inference_batch_data, 'interval', minutes=stream_interval, args=[serviceName]) else: job = scheduler.add_job( inference_live_data, 'date', run_date=st_date + datetime.timedelta(seconds=DEPLOYMENT_TIME), args=[serviceName]) RBMQ = RabbitMQ() while True: RBMQ.receive(service_configuration, "", "SM_Scheduler")
class LoggerClient(): def __init__(self, logfile_path, console=False): """ Logger API at Client Side to store the logs locally and sent to Central Logger MQ Parameters - RMQ - Create a RabbitMQ Object and pass it - logfile_path - Path where to create log file - console - whether to diaplay log messages on screen - Default false """ self.RMQ = RabbitMQ() #Creating queue and logger self.log_queue = queue.Queue(-1) #infinite size self.queue_handler = QueueHandler(self.log_queue) self.logger = logging.getLogger() self.logger.addHandler(self.queue_handler) #formatter self.formatter = logging.Formatter(' %(message)s') #file handler - write to file self.file_handler_loc = logging.FileHandler(logfile_path) self.file_handler_loc.setFormatter(self.formatter) #console handler - print on screen if (console == True): self.console_handler = logging.StreamHandler() self.console_handler.setFormatter(self.formatter) self.listener = QueueListener(self.log_queue, self.console_handler, self.file_handler_loc) else: self.listener = QueueListener(self.log_queue, self.file_handler_loc) def start_logger(self): self.listener.start() def emit(self, record): return self.queue_handler.emit(record) def __del__(self): self.listener.stop() def log(self, msg): time = datetime.datetime.now().strftime("%d-%m-%y %H:%M:%S") msg = "[" + time + "] : " + msg self.logger.error(msg) msg += "\n" self.RMQ.send("", "To_Log", msg) ###README #Create RabbitMQ Object #Create LoogerClient Object by passing required parameters #call start_logger() using this Object #Now you can use this object to log - call Object.log(msg) #The log message will be saved along with date in local log file (file_path in parameters) and send to central logger through queue (and also to the console based on parameter passed) #Example: (test_logclient.py) #---------------------------- # from logger_client import LoggerClient # from queue_req_resp import RabbitMQ # import time # def test(): # LC = LoggerClient("./test_log.log",console=True) # LC.start_logger() # for i in range(4): # time.sleep(1) # LC.log('This is a warning message') # LC.log('This is an error message') # return # test()
def Backup(): Timer = 15 while 1: Registry_obj.Store_DS() time.sleep(Timer) Registry_obj = Registry() # if __name__ == '__main__': # while True: if __name__ == '__main__': RMQ = RabbitMQ() #REGISTRY <--> DEPLOYMENT MANAGER RMQ.create_ServiceQueues("RG", "DM") #REGISTRY <--> SERVICE MANAGER RMQ.create_ServiceQueues("RG", "SM") #REGISTRY <--> MONITOR RMQ.create_ServiceQueues("RG", "MT") #REGISTRY <--> RECOVERY MANAGER RMQ.create_ServiceQueues("RG", "RM") #REGISTRY <--> LOAD BALANCER RMQ.create_ServiceQueues("RG", "LB")
def __init__(self): self.msg_obj = RabbitMQ()
class Registry_API: def __init__(self): self.msg_obj = RabbitMQ() def Write_Storage_info(self, App_Id, Model_Link, App_Link, Service_Link, Config_Link, Sending_Queue_name): Request_Msg = {} Request_Msg["Request_Type"] = "Write" Request_Msg["DS_Name"] = "Storage_info" key = "Value" if key not in Request_Msg.keys(): Request_Msg["Value"] = [] Req_Value = {} Req_Value["App_id"] = App_Id Req_Value["Model_Link"] = Model_Link Req_Value["App_Link"] = App_Link Req_Value["Service_Link"] = Service_Link Req_Value["Config_Link"] = Config_Link Request_Msg["Value"].append(Req_Value) Request_json_msg = json.dumps(Request_Msg) self.msg_obj.send("", Sending_Queue_name, Request_json_msg) print("Msg sent: ", Request_json_msg) def Write_Service_Link_Info(self, Service_id, Service_link, Sending_Queue_name): Request_Msg = {} Request_Msg["Request_Type"] = "Write" Request_Msg["DS_Name"] = "Service_link_info" key = "Value" if key not in Request_Msg.keys(): Request_Msg["Value"] = [] Req_Value = {} Req_Value["Service_id"] = Service_id Req_Value["Link"] = Service_link Request_Msg["Value"].append(Req_Value) Request_json_msg = json.dumps(Request_Msg) self.msg_obj.send("", Sending_Queue_name, Request_json_msg) print("Msg sent: ", Request_json_msg) def Write_Service_Inst_Info(self, Service_Id, Host_Port_Status_List, Sending_Queue_name): Request_Msg = {} Request_Msg["Request_Type"] = "Write" Request_Msg["DS_Name"] = "Service_inst_info" key = "Value" if key not in Request_Msg.keys(): Request_Msg["Value"] = [] Req_Value = {} Req_Value["Service_id"] = Service_Id Req_Value["Hosts"] = Host_Port_Status_List Request_Msg["Value"].append(Req_Value) Request_json_msg = json.dumps(Request_Msg) self.msg_obj.send("", Sending_Queue_name, Request_json_msg) print("Msg sent: ", Request_json_msg) def Write_App_Inst_Info(self, App_Id, Host_Port_Status_List, Sending_Queue_name): Request_Msg = {} Request_Msg["Request_Type"] = "Write" Request_Msg["DS_Name"] = "App_inst_info" key = "Value" if key not in Request_Msg.keys(): Request_Msg["Value"] = [] Req_Value = {} Req_Value["App_id"] = App_Id Req_Value["Hosts"] = Host_Port_Status_List Request_Msg["Value"].append(Req_Value) Request_json_msg = json.dumps(Request_Msg) self.msg_obj.send("", Sending_Queue_name, Request_json_msg) print("Msg sent: ", Request_json_msg) def Write_Host_Creds(self, Host_IP, Username, Password, Sending_Queue_name): Request_Msg = {} Request_Msg["Request_Type"] = "Write" Request_Msg["DS_Name"] = "Host_Creds" key = "Value" if key not in Request_Msg.keys(): Request_Msg["Value"] = [] Req_Value = {} Req_Value["Host_IP"] = Host_IP Req_Value["Username"] = Username Req_Value["Password"] = Password Request_Msg["Value"].append(Req_Value) Request_json_msg = json.dumps(Request_Msg) self.msg_obj.send("", Sending_Queue_name, Request_json_msg) print("Msg sent: ", Request_json_msg) def Write_Gateway_Creds(self, Gateway_IP, Username, Password, Sending_Queue_name): Request_Msg = {} Request_Msg["Request_Type"] = "Write" Request_Msg["DS_Name"] = "Host_Creds" key = "Value" if key not in Request_Msg.keys(): Request_Msg["Value"] = [] Req_Value = {} Req_Value["Gateway_IP"] = Gateway_IP Req_Value["Username"] = Username Req_Value["Password"] = Password Request_Msg["Value"].append(Req_Value) Request_json_msg = json.dumps(Request_Msg) self.msg_obj.send("", Sending_Queue_name, Request_json_msg) print("Msg sent: ", Request_json_msg) def Write_Platform_Module_Info(self, Module_id, PrimaryIP, PrimaryPid, RecoveryIP, RecoveryPid, Sending_Queue_name): Request_Msg = {} Request_Msg["Request_Type"] = "Write" Request_Msg["DS_Name"] = "Platform_Module_Info" key = "Value" if key not in Request_Msg.keys(): Request_Msg["Value"] = [] Req_Value = {} Req_Value["Module_id"] = Module_id Req_Value["Primary"] = {} Req_Value["Primary"]["IP"] = PrimaryIP Req_Value["Primary"]["Pid"] = PrimaryPid Req_Value["Recovery"] = {} Req_Value["Recovery"]["IP"] = RecoveryIP Req_Value["Recovery"]["Pid"] = RecoveryPid Request_Msg["Value"].append(Req_Value) Request_json_msg = json.dumps(Request_Msg) self.msg_obj.send("", Sending_Queue_name, Request_json_msg) print("Msg sent: ", Request_json_msg) def Read_Storage_info(self, App_Id_list, Sending_Queue, Recieving_Queue): Request_Msg = {} Request_Msg["Request_Type"] = "Read" Request_Msg["DS_Name"] = "Storage_info" Request_Msg["Queue_Name"] = Recieving_Queue Request_Msg["Filter"] = {} if len(App_Id_list) == 0: Request_Msg["Filter"]["App_id"] = [] else: Request_Msg["Filter"]["App_id"] = App_Id_list Request_json_msg = json.dumps(Request_Msg) self.msg_obj.send("", Sending_Queue, Request_json_msg) print("Msg sent: ", Request_json_msg) def Read_Service_Link_Info(self, Service_Id_list, Sending_Queue, Recieving_Queue): Request_Msg = {} Request_Msg["Request_Type"] = "Read" Request_Msg["DS_Name"] = "Service_link_info" Request_Msg["Queue_Name"] = Recieving_Queue Request_Msg["Filter"] = {} if len(Service_Id_list) == 0: Request_Msg["Filter"]["Service_id"] = [] else: Request_Msg["Filter"]["Service_id"] = Service_Id_list Request_json_msg = json.dumps(Request_Msg) self.msg_obj.send("", Sending_Queue, Request_json_msg) print("Msg sent: ", Request_json_msg) def Read_Service_Inst_Info(self, Service_Id_list, Sending_Queue, Recieving_Queue): Request_Msg = {} Request_Msg["Request_Type"] = "Read" Request_Msg["DS_Name"] = "Service_inst_info" Request_Msg["Queue_Name"] = Recieving_Queue Request_Msg["Filter"] = {} if len(Service_Id_list) == 0: Request_Msg["Filter"]["Service_id"] = [] else: Request_Msg["Filter"]["Service_id"] = Service_Id_list Request_json_msg = json.dumps(Request_Msg) self.msg_obj.send("", Sending_Queue, Request_json_msg) print("Msg sent: ", Request_json_msg) def Read_App_Inst_Info(self, App_Id_list, Sending_Queue, Recieving_Queue): Request_Msg = {} Request_Msg["Request_Type"] = "Read" Request_Msg["DS_Name"] = "App_inst_info" Request_Msg["Queue_Name"] = Recieving_Queue Request_Msg["Filter"] = {} if len(App_Id_list) == 0: Request_Msg["Filter"]["App_id"] = [] else: Request_Msg["Filter"]["App_id"] = App_Id_list Request_json_msg = json.dumps(Request_Msg) self.msg_obj.send("", Sending_Queue, Request_json_msg) print("Msg sent: ", Request_json_msg) def Read_Host_Creds(self, Host_IP_list, Sending_Queue, Recieving_Queue): Request_Msg = {} Request_Msg["Request_Type"] = "Read" Request_Msg["DS_Name"] = "Host_Creds" Request_Msg["Queue_Name"] = Recieving_Queue Request_Msg["Filter"] = {} if len(Host_IP_list) == 0: Request_Msg["Filter"]["Host_IP"] = [] else: Request_Msg["Filter"]["Host_IP"] = Host_IP_list Request_json_msg = json.dumps(Request_Msg) self.msg_obj.send("", Sending_Queue, Request_json_msg) print("Msg sent: ", Request_json_msg) def Read_Gateway_Creds(self, Gateway_IP_list, Sending_Queue, Recieving_Queue): Request_Msg = {} Request_Msg["Request_Type"] = "Read" Request_Msg["DS_Name"] = "Gateway_Creds" Request_Msg["Queue_Name"] = Recieving_Queue Request_Msg["Filter"] = {} if len(Gateway_IP_list) == 0: Request_Msg["Filter"]["Gateway_IP"] = [] else: Request_Msg["Filter"]["Gateway_IP"] = Gateway_IP_list Request_json_msg = json.dumps(Request_Msg) self.msg_obj.send("", Sending_Queue, Request_json_msg) print("Msg sent: ", Request_json_msg) def Read_Platform_Module_Info(self, Module_id_list, Sending_Queue, Recieving_Queue): Request_Msg = {} Request_Msg["Request_Type"] = "Read" Request_Msg["DS_Name"] = "Platform_Module_Info" Request_Msg["Queue_Name"] = Recieving_Queue Request_Msg["Filter"] = {} if len(Module_id_list) == 0: Request_Msg["Filter"]["Module_id"] = [] else: Request_Msg["Filter"]["Module_id"] = Module_id_list Request_json_msg = json.dumps(Request_Msg) self.msg_obj.send("", Sending_Queue, Request_json_msg) print("Msg sent: ", Request_json_msg)
Command = "docker kill " + Docker_Id os.system("sshpass -p \'" + IP_username_password[ip][1] + "\' ssh " + IP_username_password[ip][0] + "@" + ip + " " + Command) #Dummy_Docker_Id = os.popen("docker kill "+Docker_Id).read()[:-1] def callback(ch, method, properties, body): global port print("Receiving") body = body.decode("utf-8").replace('\0', '') #Receiving_Message = json.loads(body).replace('\'','\"') Receiving_Message = json.loads(body) Request_type = Receiving_Message["Request_type"] if (Request_type == "Deploy"): Ack_msg = Request_Deploy(Receiving_Message, port) port += 1 message = json.dumps(str(Ack_msg)) obj = RabbitMQ() obj.send("", "Docker_SM", message) print("\n\nSent ack: ", message) if (Request_type == "Kill"): Request_Kill(Receiving_Message) # while(1): #RabbitMQ object msg_obj = RabbitMQ() msg_obj.receive(callback, "", "SM_Docker")
import requests import sys import zipfile import json import os import time # import app from queue_req_resp import RabbitMQ from threading import Thread from app import db from app.models import Gateway, Service DB_REQUEST_QUEUE = "modules_DB" RBMQ = RabbitMQ() def response_send(response, sname): res = {} sname res["response"] = response json_resp = json.dumps(res) print("Sent Response: {json_resp}") RBMQ.send("", "DB_" + sname, json_resp) def db_server_requests_cb(ch, method, properties, body): req = json.loads(body) resp = {} if req["opcode"] == "SERVICE_ID_GET":
import subprocess # load_at_hosts = {"service1":[["ip1",44,"yes"],["ip2",22,"no"]],"service2":[["ip1",12,"yes"]]} load_at_hosts = {} host_credentials = {} new_load_at_hosts = {} new_load_at_hosts2 = {} perm_list_of_ips = [] pool_list = {} pool_list2 = {} pool = {} service_ids = [] upper_threshold = 60 lower_threshold = 2 upper_queue_threshold = 10 lower_queue_threshold = -1 msg_obj = RabbitMQ("10.2.135.82", "harshita", "123", 5672) reg_obj = Registry_API("10.2.135.82", 5672, "harshita", "123") def getting_host_credentials(): reg_obj.Read_Host_Creds("", "LBHC_RG", "RG_LBHC") # def reload_interval(): # value = "no" # load = 0 # pool_list = {k:load for k in perm_list_of_ips} # pool_list2 = {k:value for k in perm_list_of_ips} def get_current_status_from_registry():