Exemplo n.º 1
0
def default_route():
    data = {
        'app':
        "Lifecycle Management REST API",
        'status':
        "Running",
        'api_doc_json':
        "http://" + data_adapter.get_host_ip() + ":" +
        str(cfg.dic['SERVER_PORT']) + cfg.dic['API_DOC_URL'],
        'api_doc_html':
        "http://" + data_adapter.get_host_ip() + ":" +
        str(cfg.dic['SERVER_PORT']) + cfg.dic['API_DOC_URL'] + ".html#!/spec"
    }
    resp = Response(json.dumps(data), status=200, mimetype='application/json')
    return resp
Exemplo n.º 2
0
def getAgentConfig():
    data = {
        'app': "Lifecycle Management REST API",
        'name': "Lifecycle Management REST API",
        'mode': config.dic['LM_MODE'],
        'version': config.dic['VERSION'],
        'host': data_adapter.get_host_ip(),
        'device-identifier': 'not-defined',
        'device-ip-address': 'not-defined',
        'user-identifier': 'not-defined',
        'properties': {
            'swarm-master': config.dic['DOCKER_SWARM'],
            'k8s-master': config.dic['K8S_MASTER'],
            'cimi-url': config.dic['CIMI_URL'],
            'mf2c': {
                'LIFECYCLE MANAGER': config.dic['URL_PM_LIFECYCLE'],
                'USER MANAGEMENT MODULE': config.dic['URL_AC_USER_MANAGEMENT'],
                'RECOMENDER_LANDSCAPER': config.dic['URL_PM_RECOM_LANDSCAPER'],
                'SERVICE MANAGER': config.dic['URL_AC_SERVICE_MNGMT'],
                'SLA MANAGER': config.dic['URL_PM_SLA_MANAGER']
            }
        }
    }
    resp = Response(json.dumps(data), status=200, mimetype='application/json')
    return resp
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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
Exemplo n.º 5
0
def create_docker_compss_container(service_image, ip, prts, ip_leader):
    LOG.debug(
        "[lifecycle.modules.apps.docker.client] [create_docker_compss_container] Creating COMPSs container [service_image="
        + service_image + "], [ports=" + str(prts) + "], [ip=" + ip +
        "] [ip_leader=" + ip_leader + "] ...")
    # 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)

            # create a new container: 'docker run'
            # check ports for COMPSs container:
            if config.dic['PORT_COMPSs'] not in prts:
                prts.insert(0, config.dic['PORT_COMPSs'])
            else:
                prts.remove(config.dic['PORT_COMPSs'])
                prts.insert(0, config.dic['PORT_COMPSs'])

            LOG.debug(
                "[lifecycle.modules.apps.docker.client] [create_docker_compss_container] prts: "
                + str(prts))
            LOG.debug(
                "[lifecycle.modules.apps.docker.client] [create_docker_compss_container] prts[0]: "
                + str(prts[0]))

            prts_list = list(prts)
            ports_dict = pmngr.create_ports_dict(prts, True)
            agent_port = next(iter(ports_dict))
            agent_ports_list = []
            for key, value in ports_dict.items():
                agent_ports_list.append(key)

            LOG.debug(
                "[lifecycle.modules.apps.docker.client] [create_docker_compss_container] ports_dict: "
                + str(ports_dict))
            LOG.debug(
                "[lifecycle.modules.apps.docker.client] [create_docker_compss_container] prts_list: "
                + str(prts_list))
            LOG.debug(
                "[lifecycle.modules.apps.docker.client] [create_docker_compss_container] agent_port: "
                + str(agent_port))
            LOG.debug(
                "[lifecycle.modules.apps.docker.client] [create_docker_compss_container] agent_ports_list: "
                + str(agent_ports_list))
            LOG.debug(
                "[lifecycle.modules.apps.docker.client] [create_docker_compss_container] agent_ports_list[0]: "
                + str(agent_ports_list[0]))

            LOG.debug(
                "[lifecycle.modules.apps.docker.client] [create_docker_compss_container] AGENT_HOST: "
                + data_adapter.get_host_ip())
            LOG.debug(
                "[lifecycle.modules.apps.docker.client] [create_docker_compss_container] AGENT_PORT: "
                + str(agent_port))
            LOG.debug(
                "[lifecycle.modules.apps.docker.client] [create_docker_compss_container] DATACLAY_EP: "
                + ip_leader + config.dic['DATACLAY_EP'])
            LOG.debug(
                "[lifecycle.modules.apps.docker.client] [create_docker_compss_container] REPORT_ADDRESS: "
                + config.dic['CIMI_URL']
            )  #"http://" +  data_adapter.get_host_ip() + "/api") #config.dic['CIMI_URL'])

            # "docker run --rm -it --env MF2C_HOST=172.17.0.3 -p46100:46100 --env DEBUG=debug --name compss3123 mf2c/compss-test:latest"
            container = lclient.create_container(
                service_image,
                name="compss-" + str(uuid.uuid4()),
                environment={
                    "MF2C_HOST": ip,
                    "DEBUG": "debug",
                    "AGENT_HOST": data_adapter.get_host_ip(),
                    "AGENT_PORT":
                    agent_port,  #config.dic['PORT_COMPSs'], #data_adapter.db_get_compss_port(prts),
                    "DATACLAY_EP": ip_leader + config.dic['DATACLAY_EP'],
                    "REPORT_ADDRESS": config.dic['CIMI_URL']
                },  #"http://" +  data_adapter.get_host_ip() + "/api"}, #config.dic['CIMI_URL']},
                tty=True,
                ports=agent_ports_list,
                host_config=lclient.create_host_config(
                    port_bindings=ports_dict, auto_remove=False))

            networks = lclient.networks(names=["mf2c_default"])
            LOG.debug(
                "[lifecycle.modules.apps.docker.client] [create_docker_compss_container] networks: "
                + str(networks))
            if not networks is None and len(networks) > 0:
                LOG.debug(
                    "[lifecycle.modules.apps.docker.client] [create_docker_compss_container] networks[0]="
                    + str(networks[0]))
                id_network = networks[0]['Id']
                LOG.debug(
                    "[lifecycle.modules.apps.docker.client] [create_docker_compss_container] Connecting to network ..."
                )
                lclient.connect_container_to_network(container['Id'],
                                                     id_network)

            else:
                LOG.debug(
                    "[lifecycle.modules.apps.docker.client] [create_docker_compss_container] networks is empty / None"
                )

            return container, agent_ports_list
        else:
            LOG.error(
                "[lifecycle.modules.apps.docker.client] [create_docker_compss_container] Could not connect to DOCKER API"
            )
            return None, None
    except:
        LOG.exception(
            "[lifecycle.modules.apps.docker.client] [create_docker_compss_container] Exception"
        )
        return None, None