Esempio n. 1
0
def _submit_pipeline(request, data, namespace, experiment_name, run_name):
    arguments = {}
    arguments_data = request.headers.get("pipeline-arguments")
    if arguments_data:
        arguments = ast.literal_eval(arguments_data)
        logger.info("pipeline arguments {}".format(arguments_data))

    ctype = request.headers.get("content-type", "")
    if "/yaml" in ctype:
        ctype = ".yaml"
    elif " /zip" in ctype:
        ctype = ".zip"
    else:
        log_and_raise(HTTPStatus.BAD_REQUEST, reason="unsupported pipeline type {}".format(ctype))

    logger.info("writing file {}".format(ctype))

    print(str(data))
    pipe_tmp = tempfile.mktemp(suffix=ctype)
    with open(pipe_tmp, "wb") as fp:
        fp.write(data)

    run = None
    try:
        client = kfclient(namespace=namespace)
        experiment = client.create_experiment(name=experiment_name)
        run = client.run_pipeline(experiment.id, run_name, pipe_tmp,
                                  params=arguments)
    except Exception as e:
        remove(pipe_tmp)
        log_and_raise(HTTPStatus.BAD_REQUEST, reason="kfp err: {}".format(e))

    remove(pipe_tmp)

    return run
Esempio n. 2
0
def get_pipeline(run_id, namespace: str = Query(config.namespace)):

    client = kfclient(namespace=namespace)
    try:
        run = client.get_run(run_id)
        if run:
            run = run.to_dict()
    except Exception as e:
        log_and_raise(HTTPStatus.INTERNAL_SERVER_ERROR.value,
                      reason="get kfp error: {}".format(e))

    return run
Esempio n. 3
0
def submit_pipeline():
    namespace = request.args.get('namespace', config.namespace)
    experiment_name = request.args.get('experiment', 'Default')
    run_name = request.args.get('run', '')
    run_name = run_name or \
        experiment_name + ' ' + datetime.now().strftime('%Y-%m-%d %H-%M-%S')

    arguments = {}
    arguments_data = request.headers.get('pipeline-arguments')
    if arguments_data:
        arguments = ast.literal_eval(arguments_data)
        logger.info('pipeline arguments {}'.format(arguments_data))

    ctype = request.content_type
    if '/yaml' in ctype:
        ctype = '.yaml'
    elif ' /zip' in ctype:
        ctype = '.zip'
    else:
        return json_error(HTTPStatus.BAD_REQUEST,
                          reason='unsupported pipeline type {}'.format(ctype))

    logger.info('writing file {}'.format(ctype))
    if not request.data:
        return json_error(HTTPStatus.BAD_REQUEST, reason='post data is empty')

    print(str(request.data))
    pipe_tmp = tempfile.mktemp(suffix=ctype)
    with open(pipe_tmp, 'wb') as fp:
        fp.write(request.data)

    try:
        client = kfclient(namespace=namespace)
        experiment = client.create_experiment(name=experiment_name)
        run_info = client.run_pipeline(experiment.id,
                                       run_name,
                                       pipe_tmp,
                                       params=arguments)
    except Exception as e:
        remove(pipe_tmp)
        return json_error(HTTPStatus.BAD_REQUEST,
                          reason='kfp err: {}'.format(e))

    remove(pipe_tmp)
    return jsonify(ok=True, id=run_info.run_id, name=run_info.run_info.name)