def get_um_sharing_model():
    LOG.debug(
        "[lifecycle.data.mf2c.data_interface] [get_um_sharing_model] Getting information about current user and device..."
    )
    # get 'my' device_id
    device_id = __get_current_device_id()
    if device_id == -1:
        return None
    else:
        return cimi.get_sharing_model_by_device(device_id)
示例#2
0
def __check_service_instance_id(service_instance_id):
    for sid in QoS_SERVICE_INSTANCES_LIST:
        if sid == service_instance_id:
            LOG.warning(
                "[lifecycle.events.handler_qos] [__check_notification] service instance ["
                + service_instance_id + "] is being processed")
            return False
    LOG.debug(
        "[lifecycle.events.handler_qos] [__check_notification] service instance ["
        + service_instance_id + "] is NOT being processed")
    return True
def update_service_instance(service_instance_id, service_instance):
    LOG.debug(
        "[lifecycle.data.mf2c.data_interface] [update_service_instance] Updating resource ... ("
        + service_instance_id + ", " + str(service_instance) + ")")
    res = cimi.update_service_instance(service_instance_id, service_instance)
    if not res:
        LOG.error(
            "[lifecycle.data.mf2c.data_interface] [update_service_instance] Error during the edition of the service_instance object"
        )
        return None
    return res
示例#4
0
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 __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
示例#6
0
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)
示例#7
0
def __deploy_docker_compss(service, service_instance, agent):
    LOG.debug(
        "[lifecycle.modules.apps.docker.adapter] [__deploy_docker_compss] " +
        str(service) + ", " + str(agent))
    try:
        # service image / location. Examples: "mf2c/compss-agent:latest", "mf2c/compss-mf2c:1.0"
        service_image = service['exec']
        # port(s); COMPSs exposes port 8080
        ports = agent['ports']
        # ip
        ip = agent['url']
        # ip_leader
        ip_leader = service_instance[
            'device_ip']  # TODO create a 'exec_device_ip'

        container1, agents_ports = docker_client.create_docker_compss_container(
            service_image, ip, ports, ip_leader)
        if container1 is not None:
            db.SERVICE_INSTANCES_LIST.append({
                "type": SERVICE_COMPSS,
                "container_main": container1['Id'],
                "container_2": "-"
            })
            LOG.debug(
                "[lifecycle.modules.apps.docker.adapter] [__deploy_docker_compss] container: "
                + str(container1))

            # update agent properties
            agent['container_id'] = container1['Id']
            agent['agent_param'] = "-"
            agent['ports'] = agents_ports
            agent['status'] = STATUS_WAITING
            return common.gen_response_ok('Deploy service in agent', 'agent',
                                          str(agent), 'service', str(service))
        else:
            LOG.error(
                "[lifecycle.modules.apps.docker.adapter] [__deploy_docker_compss] Could not connect to DOCKER API"
            )
            agent['status'] = STATUS_ERROR
            return common.gen_response(500,
                                       'Error when connecting to DOCKER API',
                                       'agent', str(agent), 'service',
                                       str(service))
    except:
        LOG.exception(
            '[lifecycle.modules.apps.docker.adapter] [__deploy_docker_compss] Exception'
        )
        return common.gen_response(500, 'Exception: __deploy_docker_compss()',
                                   'agent', str(agent), 'service',
                                   str(service))
示例#8
0
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")
示例#9
0
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
示例#10
0
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
示例#11
0
def create_docker_container(service_image, service_name, service_command,
                            prts):
    LOG.debug(
        "[lifecycle.modules.apps.docker.client] [create_docker_container] [service_name="
        + service_name + "], "
        "[service_command=" + service_command + "], [service_image=" +
        service_image + "], "
        "[ports=" + str(prts) + "]")
    # connect to docker api
    lclient = get_client_agent_docker()
    try:
        if lclient:
            # check if image already exists in agent or download image
            __download_docker_image(lclient, service_image)

            LOG.debug(
                "[lifecycle.modules.apps.docker.client] [create_docker_container] Creating container ..."
            )

            prts_list = list(prts)
            ports_dict = pmngr.create_ports_dict(prts)
            LOG.debug(
                "[lifecycle.modules.apps.docker.client] [create_docker_container] ports_dict: "
                + str(ports_dict))
            LOG.debug(
                "[lifecycle.modules.apps.docker.client] [create_docker_container] prts: "
                + str(prts))
            LOG.debug(
                "[lifecycle.modules.apps.docker.client] [create_docker_container] prts_list: "
                + str(prts_list))

            # create a new container: 'docker run'
            container = lclient.create_container(
                service_image,  # command=service_command,
                name=service_name,
                tty=True,
                ports=prts_list,
                host_config=lclient.create_host_config(
                    port_bindings=ports_dict))
            return container
        else:
            LOG.error(
                "[lifecycle.modules.apps.docker.client] [create_docker_container] Could not connect to DOCKER API"
            )
            return None
    except:
        LOG.exception(
            "[lifecycle.modules.apps.docker.client] [create_docker_container] Exception"
        )
        return None
示例#12
0
def __download_docker_image(lclient, service_image, service_image_tag=None):
    # check if image already exists in agent
    l_images = lclient.images(name=service_image)
    # if not, download image
    if not l_images or len(l_images) == 0:
        LOG.debug(
            "[lifecycle.modules.apps.docker.client] [__download_docker_image] call to 'import_image' ["
            + service_image + "] ...")
        if service_image_tag is not None:
            lclient.import_image(
                tag=service_image_tag,
                image=service_image)  # (tag="latest", image="ubuntu")
        else:
            lclient.import_image(image=service_image)  # (image="ubuntu")
示例#13
0
def get_all_service_instances():
    try:
        res = requests.get(config.dic['CIMI_URL'] + '/' + RSRC_SERVICE_INSTANCE,
                           headers=CIMI_HEADER,
                           verify=False)
        LOG.debug("[lifecycle.data.mf2c.cimi] [get_all_service_instances] response: " + str(res) + ", " + str(res.json()))

        if res.status_code == 200:
            return res.json()['serviceInstances']

        LOG.warning("[lifecycle.data.mf2c.cimi] [get_all_service_instances] No service instances retrieved; Returning None ...")
    except:
        LOG.exception("[lifecycle.data.mf2c.cimi] [get_all_service_instances] Exception; Returning None ...")
    return None
示例#14
0
def thr(notification):
    try:
        LOG.debug(
            "[lifecycle.events.handler_sla] [thr] Handling SLA violations [" +
            str(notification) + "] ...")

        # TODO
        #...

        time.sleep(10)

        LOG.debug(
            "[lifecycle.events.handler_sla] [thr] SLA violations handled")
    except:
        LOG.error('[lifecycle.events.handler_sla] [thr] Exception')
示例#15
0
def __deploy_docker_image(service, agent):
    LOG.debug(
        "[lifecycle.modules.apps.docker.adapter] [__deploy_docker_image] " +
        str(service) + ", " + str(agent))
    try:
        # service image / location. Examples: "yeasy/simple-web"
        service_image = service['exec']
        # service_name examples: "simple-web-test"
        service_name = service['name'] + "-" + str(uuid.uuid4())
        # command. Docker examples: "/bin/sh -c 'python index.py'"
        service_command = ""
        # port(s)
        ports = agent['ports']

        container1 = docker_client.create_docker_container(
            service_image, service_name, service_command, ports)
        if container1 is not None:
            db.SERVICE_INSTANCES_LIST.append({
                "type": SERVICE_DOCKER,
                "container_main": container1['Id'],
                "container_2": "-"
            })
            LOG.debug(
                "[lifecycle.modules.apps.docker.adapter] [__deploy_docker_image] container: "
                + str(container1))

            # update agent properties
            agent['container_id'] = container1['Id']
            agent['agent_param'] = "-"
            agent['status'] = STATUS_WAITING
            return common.gen_response_ok('Deploy service in agent', 'agent',
                                          str(agent), 'service', str(service))
        else:
            LOG.error(
                "[lifecycle.modules.apps.docker.adapter] [__deploy_docker_image] Could not connect to DOCKER API"
            )
            agent['status'] = STATUS_ERROR
            return common.gen_response(500,
                                       'Error when connecting to DOCKER API',
                                       'agent', str(agent), 'service',
                                       str(service))
    except:
        LOG.exception(
            '[lifecycle.modules.apps.docker.adapter] [__deploy_docker_image] Exception'
        )
        return common.gen_response(500, 'Exception: __deploy_docker_image()',
                                   'agent', str(agent), 'service',
                                   str(service))
示例#16
0
def gen_resource(url, ports):
    try:
        LOG.debug(
            "[lifecycle.modules.apps.compss.adapter] [gen_resource] Getting first element from list (compss_port) ..."
        )
        compss_port = ports[0]
        LOG.debug(
            "[lifecycle.modules.apps.compss.adapter] [gen_resource] compss_port: "
            + str(compss_port))

        xml = "<externalResource>" \
              "     <adaptor>es.bsc.compss.agent.rest.master.Adaptor</adaptor>" \
              "     <description>" \
              "         <memorySize>4.0</memorySize>" \
              "         <memoryType>[unassigned]</memoryType>" \
              "         <operatingSystemDistribution>[unassigned]</operatingSystemDistribution>" \
              "         <operatingSystemType>[unassigned]</operatingSystemType>" \
              "         <operatingSystemVersion>[unassigned]</operatingSystemVersion>" \
              "         <pricePerUnit>-1.0</pricePerUnit>" \
              "         <priceTimeUnit>-1</priceTimeUnit>" \
              "         <processors>" \
              "             <architecture>[unassigned]</architecture>" \
              "             <computingUnits>2</computingUnits>" \
              "             <internalMemory>-1.0</internalMemory>" \
              "             <name>MainProcessor</name>" \
              "             <propName>[unassigned]</propName>" \
              "             <propValue>[unassigned]</propValue>" \
              "             <speed>-1.0</speed>" \
              "             <type>CPU</type>" \
              "         </processors>" \
              "         <storageSize>-1.0</storageSize>" \
              "         <storageType>[unassigned]</storageType>" \
              "         <value>0.0</value>" \
              "         <wallClockLimit>-1</wallClockLimit>" \
              "     </description>" \
              "     <name>" + url + "</name>" \
              "     <resourceConf xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"ResourcesExternalAdaptorProperties\">" \
              "         <Property>" \
              "             <Name>Port</Name>" \
              "             <Value>" + str(compss_port) + "</Value>" \
              "         </Property>" \
              "     </resourceConf>" \
              "</externalResource>"
        return xml
    except:
        LOG.exception(
            '[lifecycle.modules.apps.compss.adapter] [gen_resource] Exception')
        return False
示例#17
0
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
示例#18
0
def create_docker_compose_container(service_name, service_command):
    LOG.debug(
        "[lifecycle.modules.apps.docker.client] [create_docker_compose_container] Creating docker-compose containers [service_name="
        + service_name + "], [service_command=" + service_command + "] ...")
    try:
        # connect to docker api
        lclient = get_client_agent_docker()
        if lclient:
            # check if image already exists in agent or download image
            __download_docker_image(lclient,
                                    config.dic['DOCKER_COMPOSE_IMAGE'],
                                    config.dic['DOCKER_COMPOSE_IMAGE_TAG'])

            # create a new container: 'docker run'
            container = lclient.create_container(
                config.dic['DOCKER_COMPOSE_IMAGE'],
                command=service_command,
                name=service_name,
                tty=True,
                volumes=[
                    config.dic['WORKING_DIR_VOLUME'],
                    config.dic['DOCKER_SOCKET_VOLUME']
                ],
                host_config=lclient.create_host_config(
                    binds={
                        config.dic['WORKING_DIR_VOLUME']: {
                            'bind': config.dic['WORKING_DIR_VOLUME'],
                            'mode': 'rw',
                        },
                        '/var/run/docker.sock': {
                            'bind': config.dic['DOCKER_SOCKET_VOLUME'],
                            'mode': 'rw',
                        }
                    }),
                working_dir=config.dic['WORKING_DIR_VOLUME'])
            return container
        else:
            LOG.error(
                "[lifecycle.modules.apps.docker.client] [create_docker_compose_container] Could not connect to DOCKER API"
            )
            return None
    except:
        LOG.exception(
            "[lifecycle.modules.apps.docker.client] [create_docker_compose_container] Exception"
        )
        return None
示例#19
0
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
示例#20
0
def add_container_to_network(id):
    try:
        LOG.debug(
            "[lifecycle.modules.apps.docker.client] [add_container_to_network] "
            "[NETWORK_COMPSs=" + config.dic['NETWORK_COMPSs'] + "], [id=" +
            id + "]")
        lclient = get_client_agent_docker()
        LOG.debug(
            "[lifecycle.modules.apps.docker.client] [add_container_to_network] resp: "
            + str(
                lclient.connect_container_to_network(
                    id, config.dic['NETWORK_COMPSs'])))
    except:
        LOG.exception(
            "[lifecycle.modules.apps.docker.client] [add_container_to_network] ["
            + id + "]: Exception")
        return False
示例#21
0
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
示例#22
0
def __select_agents_service_default(service_instance):
    # docker swarm ==> deploy in first available agent
    if len(service_instance['agents']) > 0:
        list_of_agents = [service_instance['agents'][0]]
        LOG.debug(
            "[lifecycle.modules.agent_decision] [__select_agents_service_default] first agent: "
            + str(list_of_agents))
        service_instance['agents'] = list_of_agents

    # docker swarm: not-enough-resources-found
    else:
        return service_instance, "not-enough-resources-found"

    LOG.debug(
        "[lifecycle.modules.agent_decision] [__select_agents_service_default] agents FINAL list: "
        + str(service_instance['agents']))
    return service_instance, "ok"
示例#23
0
def is_port_free(port):
    try:
        if port < 10000:
            LOG.warning(
                "[lifecycle.modules.apps.ports_mngr] [is_port_free] Ports (" +
                str(port) + ") under 10000 are nor allowed")
            return False

        if data_adapter.db_get_port_mapped(port) is None and tryPort(port):
            LOG.debug(
                "[lifecycle.modules.apps.ports_mngr] [is_port_free] Port (" +
                str(port) + ") is free")
            return True
    except:
        LOG.exception("[lifecycle.modules.apps.ports_mngr] [is_port_free] [" +
                      str(port) + "]: Exception")
    return False
示例#24
0
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
示例#25
0
def db_si_del(id):
    try:
        record = db_si_getrecord(id)
        if record is not None:
            LOG.debug(
                "[lifecycle.data.app.lm_db] [db_si_del] deleted records: " +
                str(DB_LM_SERVICE_INSTANCES.delete(record)))
            # save changes on disk
            DB_LM_SERVICE_INSTANCES.commit()
            return True
        else:
            LOG.warning(
                '[lifecycle.data.app.lm_db] [db_si_del] Service Instance was not found in DB'
            )
            return False
    except:
        LOG.exception('[lifecycle.data.app.lm_db] [db_si_del] Exception')
        return False
示例#26
0
def db_si_getall():
    try:
        records = DB_LM_SERVICE_INSTANCES()
        LOG.debug(
            "[lifecycle.data.app.lm_db] [db_si_getall] Getting all records ... total="
            + str(len(records)))

        if len(records) >= 1:
            list_of_records = []
            for r in records:
                list_of_records.append(r['service_instance'])
            return list_of_records
        else:
            LOG.warning(
                '[lifecycle.data.app.lm_db] [db_si_getall] No records found')
    except:
        LOG.exception('[lifecycle.data.app.lm_db] [db_si_getall] Exception')
    return None
示例#27
0
def del_from_DB_DOCKER_PORTS(port):
    try:
        record = get_from_DB_DOCKER_PORTS(port)
        if record is not None:
            LOG.debug(
                "[lifecycle.data.app.db] [del_from_DB_DOCKER_PORTS] deleted records: "
                + str(DB_DOCKER_PORTS.delete(record)))
            # save changes on disk
            DB_DOCKER_PORTS.commit()
            return True
        else:
            LOG.warning(
                '[lifecycle.data.app.db] [del_from_DB_DOCKER_PORTS] Port was not found in DB'
            )
            return False
    except:
        LOG.exception(
            '[lifecycle.data.app.db] [del_from_DB_DOCKER_PORTS] Exception')
        return False
示例#28
0
def operation_service(service_instance_id, operation):
    LOG.debug("[lifecycle.operations] [operation_service] operation=" +
              operation + ", 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)

        if operation == OPERATION_STOP_TERMINATE:
            service_instance['status'] = STATUS_TERMINATING
            # execute thread
            t = threading.Thread(target=__thr_stop_terminate_service,
                                 args=(service_instance, ))
            t.start()
        else:
            # submit operation thread
            if operation == OPERATION_START:
                service_instance['status'] = STATUS_STARTING
            elif operation == OPERATION_STOP:
                service_instance['status'] = STATUS_STOPPING
            elif operation == OPERATION_TERMINATE:
                service_instance['status'] = STATUS_TERMINATING
            # execute thread
            t = threading.Thread(target=__thr_operation_service,
                                 args=(
                                     service_instance,
                                     operation,
                                 ))
            t.start()

        # response
        return common.gen_response_ok(
            "Service " + operation + " operation is being processed ...",
            "service_instance", service_instance)
    except:
        LOG.exception('[lifecycle.operations] [operation_service] Exception')
        return common.gen_response(500, 'Exception', 'service_instance_id',
                                   service_instance_id)
示例#29
0
def get_from_DB_DOCKER_PORTS(port):
    try:
        # debug DB
        # print_records(DB_DOCKER_PORTS)
        records = [r for r in DB_DOCKER_PORTS if r['port'] == port]
        LOG.debug(
            "[lifecycle.data.app.db] [get_from_DB_DOCKER_PORTS] records: " +
            str(records))

        #records = DB_DOCKER_PORTS(port=port)
        if len(records) >= 1:
            return records[0]
        else:
            LOG.warning(
                '[lifecycle.data.app.db] [get_from_DB_DOCKER_PORTS] No records found'
            )
    except:
        LOG.exception(
            '[lifecycle.data.app.db] [get_from_DB_DOCKER_PORTS] Exception')
    return None
示例#30
0
def deploy_service(service, agent):
    LOG.debug("[lifecycle.modules.apps.kubernetes.adapter] [deploy_service] " +
              str(service) + ", " + str(agent))
    try:
        '''
        :oauth-token (config/get-openshift-oauth-token) 
        :insecure? true
        :content-type :json
        :accept :json
        
        requests.post:
            :param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.
            
            requests.get('https://api.github.com/user', auth=HTTPBasicAuth('user', 'pass'))
        '''
        headers = {'content-type': 'application/json'}
        # deployment
        r = requests.post(config.dic['K8S_PROXY'] +
                          "/apis/apps/v1/namespaces/" +
                          config.dic['K8S_NAMESPACE'] + "/deployments",
                          headers=headers,
                          json=shemas.genDeploymentDict(service['name']),
                          verify=config.dic['VERIFY_SSL'])

        # service
        r = requests.post(config.dic['K8S_PROXY'] + "/api/v1/namespaces/" +
                          config.dic['K8S_NAMESPACE'] + "/services",
                          headers=headers,
                          json=shemas.genServiceDict(service['name']),
                          verify=config.dic['VERIFY_SSL'])

        # app name is stored in 'container_id' field
        agent['container_id'] = service['name']
        agent['status'] = STATUS_WAITING

    except:
        LOG.exception(
            '[lifecycle.modules.apps.kubernetes.adapter] [deploy_service] Exception'
        )
        return common.gen_response(500, 'Exception: deploy_service()', 'agent',
                                   str(agent), 'service', str(service))