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 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 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 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 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 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 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 postServiceInt(request): LOG.info("########################################################################################") LOG.info("######## DEPLOYMENT (remote call)") data = request.get_json() # check input parameters if 'service' not in data or 'service_instance' not in data or 'agent' not in data: LOG.error('[lifecycle.app_funcs] [postServiceInt] Exception - parameter not found: service / service_instance / agent') return Response(json.dumps({'error': True, 'message': 'parameter not found: service / service_instance / agent'}), status=406, content_type='application/json') # deploy operation (for internal calls - between LMs -) return operations.deploy(data['service'], data['service_instance'], data['agent'])
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 __get_agent(): LOG.info( "[lifecycle.data.mf2c.data_interface] [__get_agent] Getting 'my' device ID ..." ) agent = cimi.get_agent_info() LOG.debug("[lifecycle.data.mf2c.data_interface] [__get_agent] agent=" + str(agent)) if not agent is None and agent != -1: return agent else: return None
def get_leader_ip(): agent = __get_agent() if agent is not None and 'leader_ip' in agent and agent['leader_ip'].strip( ): LOG.info( "[lifecycle.data.mf2c.data_interface] [get_leader_ip] LEADER IP from current agent = " + agent['leader_ip']) return agent['leader_ip'] else: LOG.error( "[lifecycle.data.mf2c.data_interface] [get_leader_ip] Error retrieving LEADER IP from agent. Returning None ..." ) return None
def get_my_ip(): agent = __get_agent() if agent is not None and agent[ 'device_ip'] is not None and agent['device_ip'] != "": LOG.info( "[lifecycle.data.mf2c.data_interface] [get_my_ip] IP from current agent = " + agent['device_ip']) return agent['device_ip'] elif config.dic['HOST_IP'] is not None and config.dic['HOST_IP'] != "": return config.dic['HOST_IP'] else: LOG.error( "[lifecycle.data.mf2c.data_interface] [get_my_ip] Error retrieving IP from agent. Returning None ..." ) return None
def handle_qos_notification(notification): LOG.info( "########################################################################################" ) LOG.info("######## QoS ENFORCEMENT") try: global QoS_SERVICE_INSTANCES_LIST LOG.info( "[lifecycle.events.handler_qos] [handle_qos_notification] service_instance_id: notification: " + str(notification)) if not 'num_agents' in notification or not 'service_instance_id' in notification: LOG.error( "[lifecycle.events.handler_qos] [handle_qos_notification] 'num_agents' / 'service_instance_id' parameters not found in notification!" ) return common.gen_response( 406, 'Error', 'parameter num_agents / service_instance_id not found in qos notification', str(notification)) # handle notification if __check_service_instance_id(notification['service_instance_id']): LOG.info( "[lifecycle.events.handler_qos] [handle_qos_notification] Processing request..." ) QoS_SERVICE_INSTANCES_LIST.append( notification['service_instance_id']) t = threading.Thread(target=thr, args=(notification, )) t.start() return common.gen_response_ok( 'QoS Notification is being processed...', 'notification', str(notification)) LOG.info( "[lifecycle.events.handler_qos] [handle_qos_notification] Request not processed." ) return common.gen_response_ok( "QoS Notification was not processed: List of current service instances being processed: " + str(QoS_SERVICE_INSTANCES_LIST), "notification", str(notification)) except: LOG.exception( '[lifecycle.events.handler_qos] [handle_qos_notification] Exception' ) return common.gen_response(500, 'Exception', 'notification', str(notification))
def init(): global DB_LM_SERVICE_INSTANCES try: # DB_LM: LM DATABASE ("PHYSICAL DB") LOG.info('[lifecycle.data.app.lm_db] [init] Initializing DB_LM ...') DB_LM_SERVICE_INSTANCES = Base(config.dic['LM_WORKING_DIR_VOLUME'] + config.dic['DB_STANDALONE_MODE'] + "_service_instances") # create new base with field names if not DB_LM_SERVICE_INSTANCES.exists(): DB_LM_SERVICE_INSTANCES.create('id', 'service_instance') else: DB_LM_SERVICE_INSTANCES.open() except: LOG.exception( '[lifecycle.data.app.lm_db] [init] Exception: Error while initializing db components' )
def get_current(val): LOG.log(TRACE, "[lifecycle.connectors.atos.user_manager] [get_current] Getting current " + val + " from localhost - UM: Checking avialability ...") try: LOG.info("[lifecycle.connectors.atos.user_manager] [get_current] HTTP GET: " + str(config.dic['URL_AC_USER_MANAGEMENT']) + "/current/" + val) r = requests.get(str(config.dic['URL_AC_USER_MANAGEMENT']) + "/current/" + val, verify=config.dic['VERIFY_SSL']) LOG.log(TRACE, "[lifecycle.connectors.atos.user_manager] [get_current] response: " + str(r) + ", " + str(r.json())) json_data = json.loads(r.text) LOG.debug("[lifecycle.connectors.atos.user_manager] [get_current] json_data=" + str(json_data)) if r.status_code == 200: return json_data LOG.error("[lifecycle.connectors.atos.user_manager] [get_current] Error: status_code=" + str(r.status_code) + "; Returning None ...") except: LOG.exception("[lifecycle.connectors.atos.user_manager] [get_current] Exception; Returning None ...") return None
def get_user_profile(): LOG.log(TRACE, "[lifecycle.connectors.atos.user_manager] [get_user_profile] Getting user-profile from localhost ...") try: LOG.info("[lifecycle.connectors.atos.user_manager] [get_user_profile] HTTP GET: " + str(config.dic['URL_AC_USER_MANAGEMENT']) + "/user-profile") r = requests.get(str(config.dic['URL_AC_USER_MANAGEMENT']) + "/user-profile", verify=config.dic['VERIFY_SSL']) LOG.log(TRACE, "[lifecycle.connectors.atos.user_manager] [get_user_profile] response: " + str(r) + ", " + str(r.json())) json_data = json.loads(r.text) LOG.debug("[lifecycle.connectors.atos.user_manager] [get_user_profile] json_data=" + str(json_data)) if r.status_code == 200: return json_data LOG.error("[lifecycle.connectors.atos.user_manager] [get_user_profile] Error: status_code=" + str(r.status_code) + "; Returning None ...") except: LOG.exception("[lifecycle.connectors.atos.user_manager] [get_user_profile] Exception; Returning None ...") return None
def set_um_properties(apps=0): LOG.log(TRACE, "[lifecycle.connectors.atos.user_manager] [set_um_properties] localhost - local UM: Updating UM properties ...") try: LOG.info("[lifecycle.connectors.atos.user_manager] [set_um_properties] HTTP PUT: " + str(config.dic['URL_AC_USER_MANAGEMENT']) + "/sharing-model") r = requests.put(str(config.dic['URL_AC_USER_MANAGEMENT']) + "/sharing-model", json={"apps_running": apps}, verify=config.dic['VERIFY_SSL']) LOG.log(TRACE, "[lifecycle.connectors.atos.user_manager] [set_um_properties] response: " + str(r) + ", " + str(r.json())) if r.status_code == 200: json_data = json.loads(r.text) LOG.debug('[lifecycle.connectors.atos.user_manager] [set_um_properties] json_data=' + str(json_data)) return json_data LOG.error("[lifecycle.connectors.atos.user_manager] [set_um_properties] Error: status_code=" + str(r.status_code) + "; Returning None ...") except: LOG.exception("[lifecycle.connectors.atos.user_manager] [set_um_properties] Exception; Returning None ...") return None
def handle_dinamicity(notification): try: LOG.info( "[lifecycle.events.handler_dinamicity] [handle_dinamicity] notification: " + str(notification)) # handle notification t = threading.Thread(target=thr, args=(notification, )) t.start() return common.gen_response_ok('UM notification is being processed...', 'notification', str(notification)) except: LOG.exception( '[lifecycle.events.handler_dinamicity] [handle_dinamicity] Exception' ) return common.gen_response(500, 'Exception', 'notification', str(notification))
def handle_sla_notification(notification): try: LOG.info( "[lifecycle.events.handler_sla] [handle_sla_notification] service_instance_id: notification: " + str(notification)) # handle notification t = threading.Thread(target=thr, args=(notification, )) t.start() return common.gen_response_ok('SLA Notification has been processed', 'notification', str(notification)) except: LOG.error( '[lifecycle.events.handler_sla] [handle_sla_notification] Exception' ) return common.gen_response(500, 'Exception', 'notification', str(notification))
def start_job(body, service_instance_id): LOG.info( "########################################################################################" ) LOG.info("######## JOBS: START JOB") LOG.debug("[lifecycle.operations] [start_job] body=" + str(body)) LOG.debug("[lifecycle.operations] [start_job] service_instance_id=" + service_instance_id) try: # service instance 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) LOG.debug("[lifecycle.operations] [start_job] service_instance=" + str(service_instance)) # start job in agent(s) if len(service_instance['agents']) == 1: res = apps_adapter.start_job_compss(service_instance, body) elif len(service_instance['agents']) >= 2: res = apps_adapter.start_job_compss_multiple_agents( service_instance, body) else: LOG.warning( "[lifecycle.operations] [start_job] Execution supported in only 1 or more agents! agents size=" + str(len(service_instance['agents']))) res = None if res: return common.gen_response_ok('Start job', 'service_id', service_instance_id, 'res', res) else: return common.gen_response(500, 'Error when starting job', 'service_instance', str(service_instance)) except: LOG.exception('[lifecycle.operations] [start_job] Exception') return common.gen_response(500, 'Exception', 'data', str(body))
def __get_current_device_id(): LOG.info( "[lifecycle.data.mf2c.data_interface] [__get_current_device_id] Getting 'my' device ID ..." ) agent = cimi.get_agent_info() LOG.debug( "[lifecycle.data.mf2c.data_interface] [__get_current_device_id] agent=" + str(agent)) if not agent is None and agent != -1: LOG.info( "[lifecycle.data.mf2c.data_interface] [__get_current_device_id] Getting device 'id' by 'deviceID'=" + agent['device_id']) id = cimi.get_id_from_device(agent['device_id']) if not id is None and id != -1: LOG.info( "[lifecycle.data.mf2c.data_interface] [__get_current_device_id] Returning 'my' device ID = " + id) return id else: LOG.warning( "[lifecycle.data.mf2c.data_interface] [__get_current_device_id] Device information not found. Returning -1 ..." ) return -1 else: LOG.warning( "[lifecycle.data.mf2c.data_interface] [__get_current_device_id] Agent information not found. Returning -1 ..." ) return -1
def qos_providing(service_instance): try: if 'id' not in service_instance: LOG.error( "[lifecycle.connectors.mf2c.service_manager] [qos_providing] 'id' not found in service instance; Returning None ..." ) return None id = service_instance['id'] id_service = service_instance['service'] LOG.debug( "[lifecycle.connectors.mf2c.service_manager] [qos_providing] service: " + id_service + " service_instance_id: " + id) LOG.info( "[lifecycle.connectors.mf2c.service_manager] [qos_providing] HTTP GET: " + str(config.dic['URL_AC_SERVICE_MNGMT']) + "/" + id) r = requests.get(str(config.dic['URL_AC_SERVICE_MNGMT']) + "/" + id, verify=config.dic['VERIFY_SSL']) LOG.debug( "[lifecycle.connectors.mf2c.service_manager] [qos_providing] response: " + str(r) + ", " + str(r.json())) json_data = json.loads(r.text) LOG.debug( "[lifecycle.connectors.mf2c.service_manager] [qos_providing] json_data=" + str(json_data) + ", status=" + str(json_data['status'])) if json_data['status'] == 200: return json_data["service-instance"] LOG.error( "[lifecycle.connectors.mf2c.service_manager] [qos_providing] status: " + str(json_data['status']) + "; Returning None ...") except: LOG.exception( "[lifecycle.connectors.mf2c.service_manager] [qos_providing] Exception; Returning None ..." ) return None
def get_available_agents_resources(service): try: LOG.info( "######## GET AVAILABLE AGENTS: ANALYTICS ENGINE / RECOMMENDER ################# (1) ###########" ) LOG.info( "[lifecycle.modules.agent_decision] [get_available_agents_resources] Gets a list of available agents in the current cluster ..." ) if common.is_standalone_mode(): LOG.warning( "[lifecycle.modules.agent_decision] [get_available_agents_resources] STANDALONE_MODE enabled; returning None ..." ) return None else: # Call to ANALYTICS ENGINE (RECOMMENDER & LANDSCAPER) # The Lifecycle Management module calls the Recommender in order to get the optimal deployment configuration to run the service. # Based on this optimal configuration returned by the Recommender, the Lifecycle module asks the Landscaper for a list of resources that match this recommendation. resources = connector.get_available_devices(service) # If no resources were found, then the Lifecycle Management forwards the request (submit a service) upwards if not resources or len(resources) == 0: LOG.warning( "[lifecycle.modules.agent_decision] [get_available_agents_resources] temporal fix" ) LOG.warning( "[lifecycle.modules.agent_decision] [get_available_agents_resources] returning localhost" ) return [{"agent_ip": data_adapter.get_host_ip()}] else: LOG.debug( "[lifecycle.modules.agent_decision] [get_available_agents_resources] total=" + str(len(resources))) return resources except: LOG.exception( '[lifecycle.modules.agent_decision] [get_available_agents_resources] Exception' ) return None
def parent_deploy(leader_ip, service_id, user_id, sla_template_id, service_instance_id): LOG.debug( "[lifecycle.connectors.atos.lifecycle] [parent_deploy] forward request to leader: " + leader_ip + ", service_id: " + str(service_id) + ", user_id: " + str(user_id) + ", sla_template_id: " + sla_template_id + ", service_instance_id: " + service_instance_id) try: LOG.info( "[lifecycle.connectors.atos.lifecycle] [parent_deploy] HTTP POST: http://" + leader_ip + ":" + str(config.dic['SERVER_PORT']) + "/api/v2/lm/service") r = requests.post("http://" + leader_ip + ":" + str(config.dic['SERVER_PORT']) + "/api/v2/lm/service", json={ "service_id": service_id, "user_id": user_id, "sla_template": sla_template_id, "service_instance_id": service_instance_id }, verify=config.dic['VERIFY_SSL']) LOG.debug( "[lifecycle.connectors.atos.lifecycle] [parent_deploy] response: " + str(r) + ", " + str(r.json())) if r.status_code >= 200 and r.status_code <= 204: return True LOG.error( "[lifecycle.connectors.atos.lifecycle] [parent_deploy] Error: status_code=" + str(r.status_code) + "; Returning None ...") except: LOG.exception( "[lifecycle.connectors.atos.lifecycle] [parent_deploy] Exception; Returning False ..." ) return False
def deploy(service, service_instance, agent): LOG.debug( "[lifecycle.connectors.atos.lifecycle] [deploy] deploy service in agent: " + str(service) + ", " + str(service_instance) + ", " + str(agent)) try: LOG.info( "[lifecycle.connectors.atos.lifecycle] [deploy] HTTP POST: http://" + agent['url'] + ":" + str(config.dic['SERVER_PORT']) + "/api/v2/lm/service-instance-int") r = requests.post("http://" + agent['url'] + ":" + str(config.dic['SERVER_PORT']) + "/api/v2/lm/service-instance-int", json={ "service": service, "service_instance": service_instance, "agent": agent }, verify=config.dic['VERIFY_SSL']) LOG.debug("[lifecycle.connectors.atos.lifecycle] [deploy] response: " + str(r) + ", " + str(r.json())) if r.status_code == 200: json_data = json.loads(r.text) agent = json_data['agent'] LOG.debug( "[lifecycle.connectors.atos.lifecycle] [deploy] result: agent: " + str(agent)) return ast.literal_eval(agent) LOG.error( "[lifecycle.connectors.atos.lifecycle] [deploy] Error: status_code=" + str(r.status_code) + "; Returning None ...") except: LOG.exception( "[lifecycle.connectors.atos.lifecycle] [deploy] Exception; Returning None ..." ) return None
def putServiceInt(request): LOG.info("########################################################################################") LOG.info("######## OPERATION (remote call)") data = request.get_json() # check input parameters if 'service' not in data or 'operation' not in data or 'agent' not in data: LOG.error('[lifecycle.app_funcs] [putServiceInt] Exception - parameter not found: agent / operation') return Response(json.dumps({'error': True, 'message': 'parameter not found: agent / operation'}), status=406, content_type='application/json') # operations if data['operation'] == OPERATION_START: return operations.start(data['service'], data['agent']) elif data['operation'] == OPERATION_STOP: return operations.stop(data['service'], data['agent']) elif data['operation'] == OPERATION_RESTART: return operations.start(data['service'], data['agent']) elif data['operation'] == OPERATION_TERMINATE: return operations.terminate(data['service'], data['agent']) else: LOG.error('[lifecycle.app_funcs] [putServiceInt] operation not defined / implemented') return Response(json.dumps({'error': True, 'message': 'operation not defined / implemented'}), status=501, content_type='application/json')
def init(lm_mode): global adapter LOG.info('[lifecycle.data.data_adapter] [init] Setting data adapter...') if lm_mode == "DEFAULT" or lm_mode == "MF2C": LOG.info('[lifecycle.data.data_adapter] [init] LM_MODE = MF2C') adapter = mf2c_data_adapter.Mf2cDataAdapter() else: LOG.info('[lifecycle.data.data_adapter] [init] LM_MODE = STANDALONE') adapter = standalone_data_adapter.StandaloneDataAdapter()
def init(lm_mode): global conn LOG.info('[lifecycle.connectors.connector] [init] Setting connector...') if lm_mode == "DEFAULT" or lm_mode == "MF2C": LOG.info('[lifecycle.connectors.connector] [init] LM_MODE = MF2C') conn = mf2c_connector.Mf2cConnector() else: LOG.info('[lifecycle.connectors.connector] [init] LM_MODE = STANDALONE') conn = standalone_connector.StandaloneConnector()
def main(): LOG.info("[app] Starting Lifecycle Management application [version=" + str(cfg.dic['VERSION']) + "] ...") LOG.info("[app] Swagger running on http://" + data_adapter.get_host_ip() + ":" + str(cfg.dic['SERVER_PORT']) + cfg.dic['API_DOC_URL'] + ".html") LOG.info("[app] REST API running on http://" + data_adapter.get_host_ip() + ":" + str(cfg.dic['SERVER_PORT']) + cfg.dic['API_DOC_URL']) # START (SSL) SERVER # context = ('PATH_TO_CERT_CRT', 'PATH_TO_CERT_KEY') # app.run(host='0.0.0.0', port=config.dic['SERVER_PORT'], ssl_context=context, threaded=True, debug=False) # START SERVER app.run(host='0.0.0.0', port=cfg.dic['SERVER_PORT'], threaded=True, debug=False)
def thr(notification): try: global QoS_SERVICE_INSTANCES_LIST LOG.debug( "[lifecycle.events.handler_qos] [thr] Handling QoS notifications [" + str(notification) + "] ...") # get notification values service_instance_id = notification['service_instance_id'] service_instance = data_adapter.get_service_instance( service_instance_id) service = data_adapter.get_service(service_instance['service']) current_num_agents = len( service_instance['agents']) #service['num_agents'] new_num_agents = notification['num_agents'] appId = data_adapter.serv_instance_get_appid_from_master( service_instance) if not appId: LOG.error( "[lifecycle.events.handler_qos] [thr] Service instance reconfiguration: 'appId' not found in service_instance!" ) LOG.error( "[lifecycle.events.handler_qos] [thr] service_instance=" + str(service_instance)) else: # ADD NEW RESOURCES TO COMPSs MASTER if new_num_agents > current_num_agents: LOG.debug( "[lifecycle.events.handler_qos] [thr] new_num_agents > current_num_agents" ) LOG.info( "[lifecycle.events.handler_qos] [thr] Reconfiguring service instance: Adding more nodes to service instance (COMPSs) ..." ) # Call to landscaper/recommender LOG.debug( "[lifecycle.events.handler_qos] [thr] Getting list of available agents ..." ) available_agents_list = agent_decision.get_available_agents_resources( service) # ==> [{"agent_ip": "192.168.252.41"}, ...] LOG.debug( "[lifecycle.events.handler_qos] [thr] List of available agents: " + str(available_agents_list)) if len(available_agents_list) > 0: LOG.debug( "[lifecycle.events.handler_qos] [thr] Reconfiguring service instance: Checking available resources ..." ) for agent in available_agents_list: LOG.debug( "[lifecycle.events.handler_qos] [thr] - checking agent [" + str(agent) + "]") # add new resources to master if agent does not belong to current execution if not data_adapter.serv_instance_is_agent_in_service_instance( service_instance, agent["agent_ip"] ) and new_num_agents > current_num_agents: # DEPLOY LOG.debug( "[lifecycle.events.handler_qos] [thr] Deploying COMPSs in agent [" + str(agent) + "] ...") res, new_agent = __deploy_COMPSs_in_agent( service, service_instance, agent["agent_ip"]) if res: # ADD TO COMPSs LOG.debug( "[lifecycle.events.handler_qos] [thr] Adding to COMPSs execution ..." ) time.sleep(25) if compss_adpt.add_resources_to_job( service_instance, appId, agent["agent_ip"], new_agent['ports']): service_instance['agents'].append( new_agent) data_adapter.update_service_instance( service_instance['id'], service_instance) current_num_agents = current_num_agents + 1 else: LOG.error( "[lifecycle.events.handler_qos] [thr] Reconfiguring service instance: Error adding new resources / 'appId' not found in service_instance!" ) else: LOG.error( "[lifecycle.events.handler_qos] [thr] Handling QoS notifications: available_agents_list is None or is empty " ) LOG.debug( "[lifecycle.events.handler_qos] [thr] Waiting 60s to terminate process ..." ) time.sleep(60) # REMOVE RESOURCES FROM COMPSs MASTER elif new_num_agents < current_num_agents: LOG.debug( "[lifecycle.events.handler_qos] [thr] new_num_agents < current_num_agents" ) LOG.info( "[lifecycle.events.handler_qos] [thr] Reconfiguring service instance: Removing nodes from service instance (COMPSs) ..." ) for agent in service_instance['agents']: # if agent is not the master, it can be removed if not data_adapter.serv_instance_is_master( agent) and new_num_agents < current_num_agents: if compss_adpt.rem_resources_from_job( service_instance, appId, agent["agent_ip"]): current_num_agents = current_num_agents - 1 LOG.debug( "[lifecycle.events.handler_qos] [thr] Waiting 60s to terminate process ..." ) time.sleep(60) else: LOG.debug( "[lifecycle.events.handler_qos] [thr] new_num_agents = current_num_agents" ) LOG.debug( "[lifecycle.events.handler_qos] [thr] Waiting 10s to terminate process ..." ) time.sleep(10) LOG.debug( "[lifecycle.events.handler_qos] [thr] Removing service instance id from QoS_SERVICE_INSTANCES_LIST ..." ) QoS_SERVICE_INSTANCES_LIST.remove(notification['service_instance_id']) LOG.debug( "[lifecycle.events.handler_qos] [thr] QoS notifications handled") except: LOG.exception('[lifecycle.events.handler_qos] [thr] Exception') QoS_SERVICE_INSTANCES_LIST.remove(notification['service_instance_id'])