Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List pipelines #1588

Merged
merged 3 commits into from
Jul 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions sdk/python/kfp/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@

import kfp_server_api

from .compiler import compiler
from .compiler import _k8s_helper
from kfp.compiler import compiler
from kfp.compiler import _k8s_helper

from kfp._auth import get_auth_token

from ._auth import get_auth_token


def _add_generated_apis(target_struct, api_module, api_client):
Expand Down Expand Up @@ -80,13 +81,13 @@ def __init__(self, host=None, client_id=None, namespace='kubeflow'):
https://<your-deployment>.endpoints.<your-project>.cloud.goog/pipeline".
client_id: The client ID used by Identity-Aware Proxy.
"""

self._host = host
config = self._load_config(host, client_id, namespace)
api_client = kfp_server_api.api_client.ApiClient(config)
_add_generated_apis(self, kfp_server_api.api, api_client)
self._run_api = kfp_server_api.api.run_service_api.RunServiceApi(api_client)
self._experiment_api = kfp_server_api.api.experiment_service_api.ExperimentServiceApi(api_client)
self._pipelines_api = kfp_server_api.api.pipeline_service_api.PipelineServiceApi(api_client)
self._upload_api = kfp_server_api.api.PipelineUploadServiceApi(api_client)

def _load_config(self, host, client_id, namespace):
Expand All @@ -98,7 +99,7 @@ def _load_config(self, host, client_id, namespace):
if host and client_id:
# fetch IAP auth token
token = get_auth_token(client_id)

if token:
config.api_key['authorization'] = token
config.api_key_prefix['authorization'] = 'Bearer'
Expand Down Expand Up @@ -172,7 +173,7 @@ def create_experiment(self, name):
logging.info('Creating experiment {}.'.format(name))
experiment = kfp_server_api.models.ApiExperiment(name=name)
experiment = self._experiment_api.create_experiment(body=experiment)

if self._is_ipython():
import IPython
html = \
Expand Down Expand Up @@ -223,7 +224,7 @@ def _choose_pipeline_yaml_file(file_list) -> str:
yaml_files = [file for file in file_list if file.endswith('.yaml')]
if len(yaml_files) == 0:
raise ValueError('Invalid package. Missing pipeline yaml file in the package.')

if 'pipeline.yaml' in yaml_files:
return 'pipeline.yaml'
else:
Expand All @@ -248,6 +249,17 @@ def _choose_pipeline_yaml_file(file_list) -> str:
else:
raise ValueError('The package_file '+ package_file + ' should ends with one of the following formats: [.tar.gz, .tgz, .zip, .yaml, .yml]')

def list_pipelines(self, page_token='', page_size=10, sort_by=''):
"""List pipelines.
Args:
page_token: token for starting of the page.
page_size: size of the page.
sort_by: one of 'field_name', 'field_name des'. For example, 'name des'.
Returns:
A response object including a list of pipelines and next page token.
"""
return self._pipelines_api.list_pipelines(page_token=page_token, page_size=page_size, sort_by=sort_by)

def run_pipeline(self, experiment_id, job_name, pipeline_package_path=None, params={}, pipeline_id=None):
"""Run a specified pipeline.

Expand All @@ -273,13 +285,13 @@ def run_pipeline(self, experiment_id, job_name, pipeline_package_path=None, para
reference = kfp_server_api.models.ApiResourceReference(key, kfp_server_api.models.ApiRelationship.OWNER)
spec = kfp_server_api.models.ApiPipelineSpec(
pipeline_id=pipeline_id,
workflow_manifest=pipeline_json_string,
workflow_manifest=pipeline_json_string,
parameters=api_params)
run_body = kfp_server_api.models.ApiRun(
pipeline_spec=spec, resource_references=[reference], name=job_name)

response = self._run_api.create_run(body=run_body)

if self._is_ipython():
import IPython
html = ('Run link <a href="%s/#/runs/details/%s" target="_blank" >here</a>'
Expand Down