def thr_submit_local(service, service_instance, agent): try: LOG.debug( "[lifecycle.deployment] [thr_submit_local] allocate service locally" ) resp_deploy = apps_adapter.deploy_service_agent( service, service_instance, agent) LOG.debug( "[lifecycle.deployment] [thr_submit_local] allocate service locally: " "[resp_deploy=" + str(resp_deploy) + "]") if agent['status'] == "waiting": LOG.debug( "[lifecycle.deployment] [thr_submit_local] execute service locally" ) # executes service apps_adapter.start_service_agent(service, agent) else: LOG.error( "[lifecycle.deployment] [thr_submit_local] allocate service locally: NOT DEPLOYED" ) agent['status'] = "not-deployed" except: LOG.exception("[lifecycle.deployment] [thr_submit_local] Exception")
def thr_submit_remote(service, service_instance, agent): try: LOG.debug( "[lifecycle.deployment] [thr_submit_remote] allocate service in remote agent [" + agent['url'] + "]") resp_deploy = connector.lifecycle_deploy(service, service_instance, agent) if resp_deploy is not None: agent['status'] = resp_deploy['status'] agent['container_id'] = resp_deploy['container_id'] agent['ports'] = resp_deploy['ports'] LOG.debug( "[lifecycle.deployment] [thr_submit_remote] allocate service in remote agent: " "[agent=" + str(agent) + "]") # executes / starts service resp_start = connector.lifecycle_operation(service, agent, "start") if resp_start is not None: agent['status'] = resp_start['status'] LOG.debug( "[lifecycle.deployment] [thr_submit_remote] execute service in remote agent: " "[agent=" + str(agent) + "]") else: LOG.error( "[lifecycle.deployment] [thr_submit_remote] allocate service in remote agent: NOT DEPLOYED" ) agent['status'] = "not-deployed" except: LOG.exception("[lifecycle.deployment] [thr_submit_remote] Exception")
def thr_operation_service_remote(operation, service, agent): try: LOG.debug( "[lifecycle.operations] [thr_operation_service_remote] service operation: " + operation + " (remote)") if operation == OPERATION_START: LOG.debug( "[lifecycle.operations] [thr_operation_service_remote] start service in remote agent" ) resp_start = connector.lifecycle_operation(service, agent, OPERATION_START) if resp_start is not None: agent['status'] = resp_start['status'] LOG.debug( "[lifecycle.operations] [thr_operation_service_remote] result (start service): [agent=" + str(agent) + "]") else: agent['status'] = STATUS_UNKNOWN LOG.error( "[lifecycle.operations] [thr_operation_service_remote] result (start service): ERROR" ) elif operation == OPERATION_STOP: LOG.debug( "[lifecycle.operations] [thr_operation_service_remote] stop service in remote agent" ) resp_stop = connector.lifecycle_operation(service, agent, OPERATION_STOP) if resp_stop is not None: agent['status'] = resp_stop['status'] LOG.debug( "[lifecycle.operations] [thr_operation_service_remote] result (stop service): [agent=" + str(agent) + "]") else: agent['status'] = STATUS_UNKNOWN LOG.error( "[lifecycle.operations] [thr_operation_service_remote] result (stop service): ERROR" ) elif operation == OPERATION_TERMINATE: LOG.debug( "[lifecycle.operations] [thr_operation_service_remote] terminate service in remote agent" ) resp_terminate = connector.lifecycle_operation( service, agent, OPERATION_TERMINATE) if resp_terminate is not None: agent['status'] = resp_terminate['status'] LOG.debug( "[lifecycle.operations] [thr_operation_service_remote] result (terminate service): [agent=" + str(agent) + "]") else: agent['status'] = STATUS_UNKNOWN LOG.error( "[lifecycle.operations] [thr_operation_service_remote] result (terminate service): ERROR" ) except: LOG.exception( "[lifecycle.operations] [thr_operation_service_remote] Exception")
def terminate(service_instance_id): LOG.debug("[lifecycle.operations] [terminate] service_instance_id=" + service_instance_id) try: # 1. get service_instance object service_instance = data_adapter.get_service_instance( service_instance_id) if service_instance is None or service_instance == -1: return common.gen_response( 500, 'Error getting service instance object', 'service_instance_id', service_instance_id) # 2. updates service instance status service_instance['status'] = STATUS_TERMINATING data_adapter.update_service_instance(service_instance_id, service_instance) # 3.1 service instance status = Stopped => stop and terminate if service_instance['status'] != "Stopped": return operation_service(service_instance_id, OPERATION_STOP_TERMINATE) # 3.2 terminate else: return operation_service(service_instance_id, OPERATION_TERMINATE) except: LOG.exception('[lifecycle.operations] [terminate] Exception') return common.gen_response(500, 'Exception', 'service_instance_id', service_instance_id)
def __filter_by_swarm(service_instance): try: LOG.debug( "[lifecycle.modules.agent_decision] [filter_by_swarm] Checking if agents support Docker Swarm ..." ) l_filtered_agents = [] try: for agent in service_instance["agents"]: if __check_swarm(agent): LOG.debug( "[lifecycle.modules.agent_decision] [filter_by_swarm] Docker Swarm supported by agent: " + str(agent)) l_filtered_agents.append(agent) except: LOG.exception( '[lifecycle.modules.agent_decision] [filter_by_swarm] Exception while processing response' ) return None service_instance['agents'] = l_filtered_agents LOG.debug( "[lifecycle.modules.agent_decision] [filter_by_swarm] service_instance=" + str(service_instance)) return service_instance except: LOG.exception( '[lifecycle.modules.agent_decision] [filter_by_swarm] Exception') return None
def thr(notification): try: LOG.debug( "[lifecycle.events.handler_dinamicity] [thr] Handling event / notification [" + str(notification) + "] ...") # TODO # Get agent information # Get service instances running in lost agent # ... # Iterate resulting service instances # 1. if service_instance is running COMPSs ... compss_adpt.notify_job_resource_lost(None) # 2. if service_instance is running other app ... # redeploy time.sleep(10) LOG.debug( "[lifecycle.events.handler_dinamicity] [thr] Event / notification handled" ) except: LOG.exception('[lifecycle.events.handler_dinamicity] [thr] Exception')
def delete_docker_service(service_id): LOG.debug( "[lifecycle.modules.apps.swarm.adapter] [delete_docker_service] [service_name=" + service_id + "]") # connect to docker api lclient = get_client_agent_docker() try: if lclient: if lclient.remove_service(service_id): LOG.info( "[lifecycle.modules.apps.swarm.adapter] [delete_docker_service] Service '" + service_id + "' removed") return True else: LOG.error( "[lifecycle.modules.apps.swarm.adapter] [delete_docker_service] Error removing service '" + service_id + "'") return False else: LOG.error( "[lifecycle.modules.apps.swarm.adapter] [delete_docker_service] Could not connect to DOCKER API" ) return None except: LOG.exception( "[lifecycle.modules.apps.swarm.adapter] [delete_docker_service] Exception" ) return None
def start_job_in_agents(service_instance, body): ceiClass = body['ceiClass'] className = body['className'] hasResult = body['hasResult'] methodName = body['methodName'] parameters = body['parameters'] LOG.debug( "[lifecycle.modules.apps.compss.adapter] [start_job_in_agents] [service_instance=" + str(service_instance) + "], [parameters=" + str(parameters) + "]") try: # create resource xml xml_resources_content = "" for agent in service_instance['agents']: if agent['status'] == STATUS_STARTED: xml_resources_content += gen_resource(agent['url'], agent['ports']) if not xml_resources_content: LOG.error( '[lifecycle.modules.apps.compss.adapter] [start_job_in_agents] xml_resources_content is empty: agents status != STATUS_STARTED' ) return False xml = "<?xml version='1.0' encoding='utf-8'?>" \ "<startApplication>" \ " <ceiClass>" + ceiClass + "</ceiClass>" \ " <className>" + className + "</className>" \ " <hasResult>" + str(hasResult) + "</hasResult>" \ " <methodName>" + methodName + "</methodName>" \ " <parameters>" + parameters + "</parameters>" \ " <resources>" + xml_resources_content + "</resources>" \ " <serviceInstanceId>" + service_instance['id'].replace("service-instance/", "") + "</serviceInstanceId>" \ "</startApplication>" LOG.debug( "[lifecycle.modules.apps.compss.adapter] [start_job_in_agents] [xml=" + xml + "]") master_agent = data_adapter.serv_instance_find_master(service_instance) compss_port = master_agent['ports'][0] res = requests.put("http://" + master_agent['url'] + ":" + str(compss_port) + "/COMPSs/startApplication", data=xml, headers={'Content-Type': 'application/xml'}) LOG.debug( "[lifecycle.modules.apps.compss.adapter] [start_job_in_agents] response: " + str(res) + ", " + str(res.json())) if res.ok: LOG.debug( "[lifecycle.modules.apps.compss.adapter] [start_job_in_agents] res.text: " + str(res.text)) data_adapter.serv_instance_store_appid_in_master( service_instance, str(res.json())) return True except: LOG.exception( '[lifecycle.modules.apps.compss.adapter] [start_job_in_agents] Exception' ) return False
def operation_service_agent(agent, operation): LOG.debug("LIFECYCLE: Docker Swarm: operation_service_agent [" + operation + "]: " + str(agent)) try: # connect to docker api / check existing connection if docker_client.get_client_agent_docker() is not None: if operation == OPERATION_STOP or operation == OPERATION_TERMINATE: # service ID is stored in 'container_id' field delete_docker_service(agent['container_id']) agent['status'] = STATUS_TERMINATED else: LOG.warning( "[lifecycle.modules.apps.swarm.adapter] [operation_service_agent] [" + operation + "]: " + str(agent) + ": operation not supported") # if error when connecting to agent... else: LOG.error( "[lifecycle.modules.apps.swarm.adapter] [operation_service_agent] Could not connect to DOCKER API" ) agent['status'] = STATUS_UNKNOWN # return status return agent['status'] except: agent['status'] = STATUS_ERROR LOG.exception( '[lifecycle.modules.apps.swarm.adapter] [operation_service_agent] Exception. Returning STATUS_ERROR ...' ) return STATUS_ERROR
def get_COMPSs_port_DB_DOCKER_PORTS(lports): try: # debug DB # print_records(DB_DOCKER_PORTS) for p in lports: records = [r for r in DB_DOCKER_PORTS if r['port'] == p] LOG.debug( "[lifecycle.data.app.db] [get_COMPSs_port_DB_DOCKER_PORTS] records: " + str(records)) if len(records) >= 1: if records[0]['mapped_to'] == config.dic['PORT_COMPSs']: LOG.debug( '[lifecycle.data.app.db] [get_COMPSs_port_DB_DOCKER_PORTS] PORT_COMPSs: ' + str(records[0]['port'])) return records[0]['port'] except: LOG.exception( '[lifecycle.data.app.db] [get_COMPSs_port_DB_DOCKER_PORTS] Exception' ) LOG.error( '[lifecycle.data.app.db] [get_COMPSs_port_DB_DOCKER_PORTS] No COMPSs ports found in DB!' ) return config.dic['PORT_COMPSs']
def getServiceInstance(service_instance_id): if service_instance_id == "all": LOG.debug("[lifecycle.app_funcs] [getServiceInstance] Call to 'get all' ") try: obj_response_cimi = common.ResponseCIMI() service_instances = data_adapter.get_all_service_instances(obj_response_cimi) if not service_instances is None: return common.gen_response_ok('Service instances content', 'service_instances', service_instances, "Msg", obj_response_cimi.msj) else: return common.gen_response(500, "Error in 'get_all' function", "Error_Msg", obj_response_cimi.msj) except: LOG.exception("[lifecycle.app_funcs] [getServiceInstance] Exception. Returning error 500 ...") return common.gen_response(500, 'Exception', 'get_all', "-") else: LOG.debug("[lifecycle.app_funcs] [getServiceInstance] " + service_instance_id) try: obj_response_cimi = common.ResponseCIMI() service_instance = data_adapter.get_service_instance(service_instance_id, obj_response_cimi) if not service_instance is None and service_instance != -1: return common.gen_response_ok('Service instance content', 'service_instance_id', service_instance_id, 'service_instance', service_instance) elif service_instance == -1: return common.gen_response_ok('Service instance not found', 'service_instance_id', service_instance_id, 'service_instance', {}) else: return common.gen_response(500, "Error in 'get' function", "service_instance_id", service_instance_id, "Error_Msg", obj_response_cimi.msj) except: LOG.exception('[lifecycle.app_funcs] [getServiceInstance] Exception. Returning error 500 ...') return common.gen_response(500, 'Exception', 'service_instance_id', service_instance_id)
def get_client_agent_docker(): global client LOG.debug( "[lifecycle.modules.apps.swarm.adapter] [get_client_agent_docker] Connecting to DOCKER API [" + DOCKER_SOCKET + "], " "[SWARM MASTER? " + str(False) + "] [client=" + str(client) + "],...") try: try: if client is not None: client.version() LOG.debug( "[lifecycle.modules.apps.swarm.adapter] [get_client_agent_docker] Returning existing client [" + json.dumps(client) + "] ...") return client except: LOG.exception( "[lifecycle.modules.apps.swarm.adapter] [get_client_agent_docker] docker client gave an error. Trying to reconnect to docker..." ) client = docker.APIClient(base_url=DOCKER_SOCKET) LOG.debug( "[lifecycle.modules.apps.swarm.adapter] [get_client_agent_docker] Connected to DOCKER in [" + DOCKER_SOCKET + "]; version: " + json.dumps(client.version())) return client except: LOG.exception( "[lifecycle.modules.apps.swarm.adapter] [get_client_agent_docker] Error when connecting to DOCKER API: " + DOCKER_SOCKET) return None
def thr_operation_service_local(operation, service, agent): try: LOG.debug( "[lifecycle.operations] [thr_operation_service_local] service operation: " + operation + " (localhost)") if operation == OPERATION_START: LOG.debug( "[lifecycle.operations] [thr_operation_service_local] start service locally: " + str(service) + ", agent: " + str(agent)) apps_adapter.start_service_agent(service, agent) elif operation == OPERATION_STOP: LOG.debug( "[lifecycle.operations] [thr_operation_service_local] stop service locally: " + str(service) + ", agent: " + str(agent)) apps_adapter.stop_service_agent(service, agent) elif operation == OPERATION_TERMINATE: LOG.debug( "[lifecycle.operations] [thr_operation_service_local] terminate service locally: " + str(service) + ", agent: " + str(agent)) apps_adapter.terminate_service_agent(service, agent) except: LOG.exception( "[lifecycle.operations] [thr_operation_service_local] Exception")
def init(): global DB_DOCKER_PORTS global SERVICE_INSTANCES_LIST try: # SERVICE_INSTANCES_LIST => "MEMORY DB" LOG.info( '[lifecycle.data.app.db] [init] Initializing SERVICE_INSTANCES_LIST ...' ) SERVICE_INSTANCES_LIST = [] # DB_DOCKER_PORTS: PORTS DATABASE for each of the Lifecycles / agents => "PHYSICAL DB" LOG.info( '[lifecycle.data.app.db] [init] Initializing DB_DOCKER_PORTS ...') DB_DOCKER_PORTS = Base(config.dic['LM_WORKING_DIR_VOLUME'] + config.dic['DB_DOCKER_PORTS'] ) #Base(config.dic['DB_DOCKER_PORTS']) # create new base with field names if not DB_DOCKER_PORTS.exists(): DB_DOCKER_PORTS.create('port', 'mapped_to') else: DB_DOCKER_PORTS.open() records = DB_DOCKER_PORTS() except: LOG.exception( '[lifecycle.data.app.db] [init] Exception: Error while initializing db components' )
def stop_agreement(agreement_id): agreement_id = agreement_id.replace('agreement/', '') LOG.debug( "[lifecycle.connectors.atos.sla_manager] [stop_agreement] agreement_id: " + agreement_id) try: LOG.info( "[lifecycle.connectors.atos.sla_manager] [stop_agreement] HTTP PUT: " + str(config.dic['URL_PM_SLA_MANAGER']) + "/agreements/" + agreement_id + "/stop") r = requests.put(str(config.dic['URL_PM_SLA_MANAGER']) + "/agreements/" + agreement_id + "/stop", verify=config.dic['VERIFY_SSL']) LOG.debug( "[lifecycle.connectors.atos.sla_manager] [stop_agreement] response: " + str(r)) # + ", " + str(r.json())) if r.status_code >= 200 and r.status_code <= 204: return True LOG.error( "[lifecycle.connectors.atos.sla_manager] [stop_agreement] rror: status_code=" + str(r.status_code) + "; Returning False ...") except: LOG.exception( "[lifecycle.connectors.atos.sla_manager] [stop_agreement] Exception; Returning False ..." ) return False
def create_sla_agreement(template_id, user_id, service): LOG.debug( "[lifecycle.connectors.atos.sla_manager] [create_sla_agreement] template_id=" + template_id + ", user_id=" + user_id + ", service=" + service['name']) try: LOG.info( "[lifecycle.connectors.atos.sla_manager] [create_sla_agreement] HTTP POST: " + str(config.dic['URL_PM_SLA_MANAGER']) + "/mf2c/create-agreement") body = {"template_id": template_id, "parameters": {"user": user_id}} r = requests.post(str(config.dic['URL_PM_SLA_MANAGER']) + "/mf2c/create-agreement", json=body, verify=config.dic['VERIFY_SSL']) LOG.debug( "[lifecycle.connectors.atos.sla_manager] [create_sla_agreement] response: " + str(r) + ", " + str(r.json())) if r.status_code >= 200 and r.status_code <= 204: json_data = json.loads(r.text) LOG.debug( "[lifecycle.connectors.atos.sla_manager] [create_sla_agreement] json_data=" + str(json_data)) return json_data['agreement_id'] LOG.error( "[lifecycle.connectors.atos.sla_manager] [create_sla_agreement] Error: status_code=" + str(r.status_code) + "; Returning None ...") except: LOG.exception( "[lifecycle.connectors.atos.sla_manager] [create_sla_agreement] Exception; Returning None ..." ) return None
def deploy_service_agent(service, service_instance, agent): LOG.debug( "[lifecycle.modules.apps.docker.adapter] [deploy_service_agent] " + str(service) + ", " + str(agent)) try: # docker-compose if service['exec_type'] == SERVICE_DOCKER_COMPOSE: return __deploy_docker_compose(service, agent) # docker elif service['exec_type'] == SERVICE_DOCKER: return __deploy_docker_image(service, agent) # compss (docker) elif service['exec_type'] == SERVICE_COMPSS: return __deploy_docker_compss(service, service_instance, agent) # not defined else: LOG.warning( "[lifecycle.modules.apps.docker.adapter] [deploy_service_agent] [" + service['exec_type'] + "] not defined") return common.gen_response( 500, 'Exception: type not defined: deploy_service_agent()', 'agent', str(agent), 'service', str(service)) except: LOG.exception( '[lifecycle.modules.apps.docker.adapter] [deploy_service_agent] Exception' ) return common.gen_response(500, 'Exception: deploy_service_agent()', 'agent', str(agent), 'service', str(service))
def notify_job_resource_lost(service_instance, appId, workerIP): # <?xml version="1.0" encoding="UTF-8" standalone="yes"?> # <lostNode> # <appId>1357211900655995414</appId> # <workerName>172.18.0.5</workerName> # </lostNode> LOG.debug( "[lifecycle.modules.apps.compss.adapter] [notify_job_resource_lost] ..." ) try: xml = "<lostNode>" \ " <appId>" + appId + "</appId>" \ " <workerName>" + workerIP + "</workerName>" \ "</lostNode>" master_agent = data_adapter.serv_instance_find_master(service_instance) compss_port = data_adapter.db_get_compss_port(master_agent['ports']) res = requests.put("http://" + master_agent['url'] + ":" + str(compss_port) + "/COMPSs/lostNode", data=xml, headers={'Content-Type': 'application/xml'}) LOG.debug( "[lifecycle.modules.apps.compss.adapter] [notify_job_resource_lost] response: " + str(res) + ", " + str(res.json())) return True except: LOG.exception( '[lifecycle.modules.apps.compss.adapter] [notify_job_resource_lost] Exception' ) return False
def check_agent_swarm(agent): LOG.debug("[lifecycle.connectors.atos.lifecycle] [check_agent_swarm] " + str(agent)) try: LOG.info( "[lifecycle.connectors.atos.lifecycle] [check_agent_swarm] HTTP GET: http://" + agent['url'] + ":" + str(config.dic['SERVER_PORT']) + "/api/v2/lm/check-agent-swarm") r = requests.get("http://" + agent['url'] + ":" + str(config.dic['SERVER_PORT']) + "/api/v2/lm/check-agent-swarm", verify=config.dic['VERIFY_SSL']) LOG.debug( "[lifecycle.connectors.atos.lifecycle] [check_agent_swarm] response: " + str(r) + ", " + str(r.json())) if r.status_code == 200: json_data = json.loads(r.text) LOG.debug( "[lifecycle.connectors.atos.lifecycle] [check_agent_swarm] json_data=" + str(json_data)) return json_data LOG.error( "[lifecycle.connectors.atos.lifecycle] [check_agent_swarm] Error: status_code=" + str(r.status_code) + "; Returning None ...") except: LOG.exception( "[lifecycle.connectors.atos.lifecycle] [check_agent_swarm] Exception; Returning None ..." ) return None
def start_job(service_instance, body): ceiClass = body['ceiClass'] className = body['className'] hasResult = body['hasResult'] methodName = body['methodName'] parameters = body['parameters'] service_instance_id = service_instance['id'] agent = service_instance['agents'][0] LOG.debug( "[lifecycle.modules.apps.compss.adapter] [start_job] service_instance_id=" + service_instance_id + ", agent=" + str(agent) + ", body=" + str(body)) try: # create resource xml xml_resource = gen_resource(agent['url'], agent['ports']) # create xml xml = "<?xml version='1.0' encoding='utf-8'?>" \ "<startApplication>" \ " <ceiClass>" + ceiClass + "</ceiClass>" \ " <className>" + className + "</className>" \ " <hasResult>" + str(hasResult) + "</hasResult>" \ " <methodName>" + methodName + "</methodName>" \ " <parameters>" + parameters + "</parameters>" \ " <resources>" + xml_resource + "</resources>" \ " <serviceInstanceId>" + service_instance['id'].replace("service-instance/", "") + "</serviceInstanceId>" \ "</startApplication>" LOG.debug("[lifecycle.modules.apps.compss.adapter] [start_job] [xml=" + xml + "]") master_agent = data_adapter.serv_instance_find_master(service_instance) compss_port = agent['ports'][0] LOG.debug( "[lifecycle.modules.apps.compss.adapter] [start_job] PUT http://" + agent['url'] + ":" + str(compss_port) + "/COMPSs/startApplication") res = requests.put("http://" + agent['url'] + ":" + str(compss_port) + "/COMPSs/startApplication", data=xml, headers={'Content-Type': 'application/xml'}) if res.ok: LOG.debug( "[lifecycle.modules.apps.compss.adapter] [start_job] response (json): " + str(res) + ", " + str(res.json()) + ", " + str(res.text)) data_adapter.serv_instance_store_appid_in_master( service_instance, str(res.json())) return True else: LOG.error( "[lifecycle.modules.apps.compss.adapter] [start_job] Response from COMPSs: " + str(res)) except: LOG.exception( '[lifecycsle.modules.apps.compss.adapter] [start_job] Exception') return False
def remove_container_by_id(id): try: lclient = get_client_agent_docker() lclient.remove_container(id, force=True) except: LOG.exception( "[lifecycle.modules.apps.docker.client] [remove_container_by_id] [" + id + "]: Exception") return False
def inspect_container(id): try: lclient = get_client_agent_docker() return lclient.inspect_container(id) except: LOG.exception( "[lifecycle.modules.apps.docker.client] [inspect_container] [" + str(id) + "]: Exception") return False
def start_container(id): try: lclient = get_client_agent_docker() lclient.start(id) return True except: LOG.exception( "[lifecycle.modules.apps.docker.client] [start_container] [" + id + "]: Exception") return False
def stop(service, agent): LOG.info("[lifecycle.int_operations] [stop] " + str(service) + ", agent: " + str(agent)) try: status = apps_adapter.stop_service_agent(service, agent) return common.gen_response_ok('Stop service', 'agent', str(agent), 'status', status) except: LOG.exception('[lifecycle.int_operations] [stop] Exception') return common.gen_response(500, 'Exception', 'agent', str(agent))
def terminate(service, agent): LOG.info("[lifecycle.int_operations] [terminate] " + str(service) + ", agent: " + str(agent)) try: status = apps_adapter.terminate_service_agent(service, agent) return common.gen_response_ok('Terminate service', 'agent', str(agent), 'status', status) except: LOG.exception('[lifecycle.int_operations] [terminate] Exception') return common.gen_response(500, 'Exception', 'agent', str(agent))
def __deploy_COMPSs_in_agent(service, service_instance, agent_ip): LOG.debug( "[lifecycle.events.handler_qos] [__deploy_COMPSs_in_agent] Deploying COMPSs service instance [" + service_instance['id'] + "] in new agent [" + agent_ip + "] ...") try: # 1. create NEW AGENT LOG.debug( "[lifecycle.events.handler_qos] [__deploy_COMPSs_in_agent] Creating new service instance agent [" + agent_ip + "]") new_agent = { "device_id": "-", "app_type": service['exec_type'], "ports": service['exec_ports'], "url": agent_ip, "status": STATUS_CREATED_NOT_INITIALIZED, "compss_app_id": "-", "allow": True, "container_id": "-", "master_compss": False, "agent_param": "not-defined" } # 2. DEPLOY COMPSs in NEW AGENT LOG.debug( "[lifecycle.events.handler_qos] [__deploy_COMPSs_in_agent] allocate service in remote agent [" + new_agent['url'] + "]") resp_deploy = connector.lifecycle_deploy(service, service_instance, new_agent) if resp_deploy is not None: new_agent['status'] = resp_deploy['status'] new_agent['container_id'] = resp_deploy['container_id'] new_agent['ports'] = resp_deploy['ports'] LOG.debug( "[lifecycle.events.handler_qos] [__deploy_COMPSs_in_agent] service deployed in remote agent: [agent=" + str(new_agent) + "]") # executes / starts service resp_start = connector.lifecycle_operation(service, new_agent, "start") if resp_start is not None: new_agent['status'] = resp_start['status'] LOG.debug( "[lifecycle.events.handler_qos] [__deploy_COMPSs_in_agent] execute service in remote agent: [agent=" + str(new_agent) + "]") return True, new_agent else: LOG.error( "[lifecycle.events.handler_qos] [__deploy_COMPSs_in_agent] allocate service in remote agent: NOT DEPLOYED" ) new_agent['status'] = "not-deployed" except: LOG.exception( "[lifecycle.events.handler_qos] [__deploy_COMPSs_in_agent] Exception. Returning False ..." ) return False, None
def remove_container(agent): try: lclient = get_client_agent_docker() lclient.remove_container(agent['container_id'], force=True) for p in agent['ports']: pmngr.release_port(p) except: LOG.exception( "[lifecycle.modules.apps.docker.client] [remove_container] [" + str(agent) + "]: Exception") return False
def handle_warning(warning): try: LOG.info("[lifecycle.events.handler_um] [handle_warning] warning: " + str(warning)) # handle notification t = threading.Thread(target=thr, args=(warning,)) t.start() return common.gen_response_ok('UM Warning is being processed...', 'warning', str(warning)) except: LOG.exception('[lifecycle.events.handler_um] [handle_warning] Exception') return common.gen_response(500, 'Exception', 'warning', str(warning))
def getServiceInstanceReport(service_instance_id): LOG.debug("[lifecycle.app_funcs] [getServiceInstanceReport] " + service_instance_id) try: service_instance_report = data_adapter.get_service_instance_report(service_instance_id) if not service_instance_report is None and service_instance_report != -1: return common.gen_response_ok('Service Operation Report content', 'service_instance_id', service_instance_id, 'report', service_instance_report) else: LOG.warning("[lifecycle.app_funcs] [getServiceInstanceReport] service_instance_report is None") return common.gen_response(500, "service_instance_report is None", "service_instance_id", service_instance_id) except: LOG.exception('[lifecycle.app_funcs] [getServiceInstanceReport] Exception') return common.gen_response(500, 'Exception', 'service_instance_id', service_instance_id)
def db_si_getrecord(id): try: records = [r for r in DB_LM_SERVICE_INSTANCES if r['id'] == id] LOG.debug("[lifecycle.data.app.lm_db] [db_si_get] records: " + str(records)) if len(records) >= 1: return records[0] else: LOG.warning( '[lifecycle.data.app.lm_db] [db_si_get] No records found') except: LOG.exception('[lifecycle.data.app.lm_db] [db_si_get] Exception') return None