Exemplo n.º 1
0
    def catch_api_proxy_experiments_post():

        json_obj = request.json

        json_obj["pipeline_run_spec"]["run_config"] = {
            "host_user_dir": app.config["HOST_USER_DIR"],
            "project_dir": get_project_directory(
                json_obj["project_uuid"], host_path=True
            ),
            "pipeline_path": pipeline_uuid_to_path(
                json_obj["pipeline_uuid"],
                json_obj["project_uuid"],
            ),
        }

        # Analytics call
        send_pipeline_run(
            app,
            f"{json_obj['project_uuid']}-{json_obj['pipeline_uuid']}",
            get_project_directory(json_obj["project_uuid"]),
            "noninteractive",
        )

        resp = requests.post(
            "http://" + app.config["ORCHEST_API_ADDRESS"] + "/api/experiments/",
            json=json_obj,
        )

        return resp.content, resp.status_code, resp.headers.items()
Exemplo n.º 2
0
    def catch_api_proxy_runs():

        if request.method == "POST":

            json_obj = request.json

            # add image mapping
            # TODO: replace with dynamic mapping instead of hardcoded
            json_obj["run_config"] = {
                "project_dir": get_project_directory(
                    json_obj["project_uuid"], host_path=True
                ),
                "pipeline_path": pipeline_uuid_to_path(
                    json_obj["pipeline_definition"]["uuid"], json_obj["project_uuid"]
                ),
            }

            # Analytics call
            send_pipeline_run(
                app,
                f"{json_obj['project_uuid']}-{json_obj['pipeline_definition']['uuid']}",
                get_project_directory(json_obj["project_uuid"]),
                "interactive",
            )

            resp = requests.post(
                "http://" + app.config["ORCHEST_API_ADDRESS"] + "/api/runs/",
                json=json_obj,
            )

            return resp.content, resp.status_code, resp.headers.items()

        elif request.method == "GET":

            resp = requests.get(
                "http://"
                + app.config["ORCHEST_API_ADDRESS"]
                + "/api/runs/?"
                + request.query_string.decode(),
            )

            return resp.content, resp.status_code, resp.headers.items()
Exemplo n.º 3
0
    def catch_api_proxy_jobs_post():

        json_obj = request.json

        pipeline_path = pipeline_uuid_to_path(
            json_obj["pipeline_uuid"], json_obj["project_uuid"]
        )
        json_obj["pipeline_run_spec"]["run_config"] = {
            "host_user_dir": app.config["HOST_USER_DIR"],
            "project_dir": get_project_directory(
                json_obj["project_uuid"], host_path=True
            ),
            "pipeline_path": pipeline_path,
        }

        json_obj["pipeline_definition"] = get_pipeline_json(
            json_obj["pipeline_uuid"], json_obj["project_uuid"]
        )

        # Jobs should always have eviction enabled.
        json_obj["pipeline_definition"]["settings"]["auto_eviction"] = True

        job_uuid = str(uuid.uuid4())
        json_obj["uuid"] = job_uuid
        create_job_directory(
            job_uuid, json_obj["pipeline_uuid"], json_obj["project_uuid"]
        )

        # Analytics call
        send_pipeline_run(
            app,
            f"{json_obj['project_uuid']}-{json_obj['pipeline_uuid']}",
            get_project_directory(json_obj["project_uuid"]),
            "noninteractive",
        )

        resp = requests.post(
            "http://" + app.config["ORCHEST_API_ADDRESS"] + "/api/jobs/",
            json=json_obj,
        )

        return resp.content, resp.status_code, resp.headers.items()
Exemplo n.º 4
0
    def catch_api_proxy_jobs_post():

        json_obj = request.json

        pipeline_path = pipeline_uuid_to_path(json_obj["pipeline_uuid"],
                                              json_obj["project_uuid"])
        json_obj["pipeline_run_spec"]["run_config"] = {
            "host_user_dir":
            app.config["HOST_USER_DIR"],
            "project_dir":
            get_project_directory(json_obj["project_uuid"], host_path=True),
            "pipeline_path":
            pipeline_path,
        }

        json_obj["pipeline_definition"] = get_pipeline_json(
            json_obj["pipeline_uuid"], json_obj["project_uuid"])

        # Validate whether the pipeline contains environments
        # that do not exist in the project.
        project_environments = get_environments(json_obj["project_uuid"])
        project_environment_uuids = set(
            [environment.uuid for environment in project_environments])
        pipeline_environment_uuids = get_environments_from_pipeline_json(
            json_obj["pipeline_definition"])

        missing_environment_uuids = (pipeline_environment_uuids -
                                     project_environment_uuids)
        if len(missing_environment_uuids) > 0:
            missing_environment_uuids_str = ", ".join(
                missing_environment_uuids)
            return (
                jsonify({
                    "message":
                    "The pipeline definition references environments "
                    f"that do not exist in the project. "
                    "The following environments do not exist:"
                    f" [{missing_environment_uuids_str}].\n\n Please make sure all"
                    " pipeline steps are assigned an environment that exists"
                    " in the project."
                }),
                500,
            )

        # Jobs should always have eviction enabled.
        json_obj["pipeline_definition"]["settings"]["auto_eviction"] = True

        job_uuid = str(uuid.uuid4())
        json_obj["uuid"] = job_uuid
        create_job_directory(job_uuid, json_obj["pipeline_uuid"],
                             json_obj["project_uuid"])

        # Analytics call
        send_pipeline_run(
            app,
            f"{json_obj['project_uuid']}-{json_obj['pipeline_uuid']}",
            get_project_directory(json_obj["project_uuid"]),
            "noninteractive",
        )

        resp = requests.post(
            "http://" + app.config["ORCHEST_API_ADDRESS"] + "/api/jobs/",
            json=json_obj,
        )

        return resp.content, resp.status_code, resp.headers.items()