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

[Python Client] Use openapi generator instead of swagger #3872

Merged
merged 12 commits into from
Jun 3, 2020
Merged
24 changes: 9 additions & 15 deletions backend/api/build_kfp_server_api_python_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,20 @@ if [ -z "$VERSION" ]; then
exit 1
fi

codegen_file=/tmp/swagger-codegen-cli.jar
# Browse all versions in: https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.4.7/
codegen_uri=https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.4.7/swagger-codegen-cli-2.4.7.jar
codegen_file=/tmp/openapi-generator-cli.jar
# Browse all versions in: https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/
codegen_uri="https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/4.3.1/openapi-generator-cli-4.3.1.jar"
if ! [ -f "$codegen_file" ]; then
wget --no-verbose "$codegen_uri" -O "$codegen_file"
curl -L "$codegen_uri" -o "$codegen_file"
fi

pushd "$(dirname "$0")"

DIR=$(mktemp -d)

swagger_file=$(mktemp)

echo "Merging all Swagger API definitions to $swagger_file."
jq -s '
reduce .[] as $item ({}; . * $item) |
.info.title = "KF Pipelines API" |
.info.description = "Generated python client for the KF Pipelines server API"
' ./swagger/{run,job,pipeline,experiment,pipeline.upload}.swagger.json > "$swagger_file"
DIR="$(pwd)/python_http_client"
Bobgy marked this conversation as resolved.
Show resolved Hide resolved
swagger_file="$(pwd)/swagger/kfp_api_single_file.swagger.json"

echo "Generating python code from swagger json in $DIR."
java -jar "$codegen_file" generate -l python -i "$swagger_file" -o "$DIR" -c <(echo '{
java -jar "$codegen_file" generate -g python -i "$swagger_file" -o "$DIR" -c <(echo '{
"packageName": "kfp_server_api",
"projectName": "kfp-server-api",
"packageVersion": "'"$VERSION"'",
Expand All @@ -71,4 +63,6 @@ echo "Run the following commands to update the package on PyPI"
echo "python3 -m pip install twine"
echo "python3 -m twine upload --username kubeflow-pipelines $DIR/dist/*"

echo "Please also push local changes to github.com/kubeflow/pipelines"

popd
5 changes: 4 additions & 1 deletion backend/api/generate_api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

set -ex

VERSION="1.0.0-dev.1"
BAZEL_BINDIR=$(bazel info bazel-bin)
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null && pwd)"
SWAGGER_CMD=${DIR}/../../bazel-bin/external/com_github_go_swagger/cmd/swagger/*stripped/swagger
Expand Down Expand Up @@ -57,7 +58,9 @@ jq -s '
reduce .[] as $item ({}; . * $item) |
.info.title = "Kubeflow Pipelines API" |
.info.description = "This file contains REST API specification for Kubeflow Pipelines. The file is autogenerated from the swagger definition." |
.info.version = "0.1.38"
.info.version = "'$VERSION'" |
.info.contact = { "name": "google", "email": "[email protected]", "url": "https://www.google.com" } |
.info.license = { "name": "Apache 2.0", "url": "https://raw.githubusercontent.com/kubeflow/pipelines/master/LICENSE" }
' ${DIR}/swagger/{run,job,pipeline,experiment,pipeline.upload}.swagger.json > "${DIR}/swagger/kfp_api_single_file.swagger.json"

# Generate Go HTTP client from the swagger files.
Expand Down
66 changes: 66 additions & 0 deletions backend/api/python_http_client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
venv/
.venv/
.python-version
.pytest_cache

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

#Ipython Notebook
.ipynb_checkpoints
33 changes: 33 additions & 0 deletions backend/api/python_http_client/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# ref: https://docs.gitlab.com/ee/ci/README.html

stages:
- test

.nosetest:
stage: test
script:
- pip install -r requirements.txt
- pip install -r test-requirements.txt
- pytest --cov=kfp_server_api

nosetest-2.7:
extends: .nosetest
image: python:2.7-alpine
nosetest-3.3:
extends: .nosetest
image: python:3.3-alpine
nosetest-3.4:
extends: .nosetest
image: python:3.4-alpine
nosetest-3.5:
extends: .nosetest
image: python:3.5-alpine
nosetest-3.6:
extends: .nosetest
image: python:3.6-alpine
nosetest-3.7:
extends: .nosetest
image: python:3.7-alpine
nosetest-3.8:
extends: .nosetest
image: python:3.8-alpine
23 changes: 23 additions & 0 deletions backend/api/python_http_client/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
1 change: 1 addition & 0 deletions backend/api/python_http_client/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.3.1
17 changes: 17 additions & 0 deletions backend/api/python_http_client/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# ref: https://docs.travis-ci.com/user/languages/python
language: python
python:
- "2.7"
- "3.2"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "3.8"
# command to install dependencies
install:
- "pip install -r requirements.txt"
- "pip install -r test-requirements.txt"
# command to run tests
script: pytest --cov=kfp_server_api
188 changes: 188 additions & 0 deletions backend/api/python_http_client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
# kfp-server-api
This file contains REST API specification for Kubeflow Pipelines. The file is autogenerated from the swagger definition.

This Python package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:

- API version: 1.0.0-dev.1
- Package version: 1.0.0-dev.1
- Build package: org.openapitools.codegen.languages.PythonClientCodegen
For more information, please visit [https://www.google.com](https://www.google.com)

## Requirements.

Python 2.7 and 3.4+

## Installation & Usage
### pip install

If the python package is hosted on a repository, you can install directly using:

```sh
pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git
```
(you may need to run `pip` with root permission: `sudo pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git`)

Then import the package:
```python
import kfp_server_api
```

### Setuptools

Install via [Setuptools](http://pypi.python.org/pypi/setuptools).

```sh
python setup.py install --user
```
(or `sudo python setup.py install` to install the package for all users)

Then import the package:
```python
import kfp_server_api
```

## Getting Started

Please follow the [installation procedure](#installation--usage) and then run the following:

```python
from __future__ import print_function

import time
import kfp_server_api
from kfp_server_api.rest import ApiException
from pprint import pprint

# Defining the host is optional and defaults to http://localhost
# See configuration.py for a list of all supported configuration parameters.
configuration = kfp_server_api.Configuration(
host = "http://localhost"
)

# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.

# Configure API key authorization: Bearer
configuration = kfp_server_api.Configuration(
host = "http://localhost",
api_key = {
'authorization': 'YOUR_API_KEY'
}
)
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['authorization'] = 'Bearer'


# Enter a context with an instance of the API client
with kfp_server_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = kfp_server_api.ExperimentServiceApi(api_client)
id = 'id_example' # str |

try:
# Archive an experiment.
api_response = api_instance.archive_experiment(id)
pprint(api_response)
except ApiException as e:
print("Exception when calling ExperimentServiceApi->archive_experiment: %s\n" % e)

```

## Documentation for API Endpoints

All URIs are relative to *http://localhost*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*ExperimentServiceApi* | [**archive_experiment**](docs/ExperimentServiceApi.md#archive_experiment) | **POST** /apis/v1beta1/experiments/{id}:archive | Archive an experiment.
*ExperimentServiceApi* | [**create_experiment**](docs/ExperimentServiceApi.md#create_experiment) | **POST** /apis/v1beta1/experiments | Create a new experiment.
*ExperimentServiceApi* | [**delete_experiment**](docs/ExperimentServiceApi.md#delete_experiment) | **DELETE** /apis/v1beta1/experiments/{id} | Delete an experiment.
*ExperimentServiceApi* | [**get_experiment**](docs/ExperimentServiceApi.md#get_experiment) | **GET** /apis/v1beta1/experiments/{id} | Find a specific experiment by ID.
*ExperimentServiceApi* | [**list_experiment**](docs/ExperimentServiceApi.md#list_experiment) | **GET** /apis/v1beta1/experiments | Find all experiments.
*ExperimentServiceApi* | [**unarchive_experiment**](docs/ExperimentServiceApi.md#unarchive_experiment) | **POST** /apis/v1beta1/experiments/{id}:unarchive | Restore an archived experiment.
*JobServiceApi* | [**create_job**](docs/JobServiceApi.md#create_job) | **POST** /apis/v1beta1/jobs | Create a new job.
*JobServiceApi* | [**delete_job**](docs/JobServiceApi.md#delete_job) | **DELETE** /apis/v1beta1/jobs/{id} | Delete a job.
*JobServiceApi* | [**disable_job**](docs/JobServiceApi.md#disable_job) | **POST** /apis/v1beta1/jobs/{id}/disable | Stops a job and all its associated runs. The job is not deleted.
*JobServiceApi* | [**enable_job**](docs/JobServiceApi.md#enable_job) | **POST** /apis/v1beta1/jobs/{id}/enable | Restarts a job that was previously stopped. All runs associated with the job will continue.
*JobServiceApi* | [**get_job**](docs/JobServiceApi.md#get_job) | **GET** /apis/v1beta1/jobs/{id} | Find a specific job by ID.
*JobServiceApi* | [**list_jobs**](docs/JobServiceApi.md#list_jobs) | **GET** /apis/v1beta1/jobs | Find all jobs.
*PipelineServiceApi* | [**create_pipeline**](docs/PipelineServiceApi.md#create_pipeline) | **POST** /apis/v1beta1/pipelines | Add a pipeline.
*PipelineServiceApi* | [**create_pipeline_version**](docs/PipelineServiceApi.md#create_pipeline_version) | **POST** /apis/v1beta1/pipeline_versions |
*PipelineServiceApi* | [**delete_pipeline**](docs/PipelineServiceApi.md#delete_pipeline) | **DELETE** /apis/v1beta1/pipelines/{id} | Delete a pipeline.
*PipelineServiceApi* | [**delete_pipeline_version**](docs/PipelineServiceApi.md#delete_pipeline_version) | **DELETE** /apis/v1beta1/pipeline_versions/{version_id} |
*PipelineServiceApi* | [**get_pipeline**](docs/PipelineServiceApi.md#get_pipeline) | **GET** /apis/v1beta1/pipelines/{id} | Find a specific pipeline by ID.
*PipelineServiceApi* | [**get_pipeline_version**](docs/PipelineServiceApi.md#get_pipeline_version) | **GET** /apis/v1beta1/pipeline_versions/{version_id} |
*PipelineServiceApi* | [**get_pipeline_version_template**](docs/PipelineServiceApi.md#get_pipeline_version_template) | **GET** /apis/v1beta1/pipeline_versions/{version_id}/templates |
*PipelineServiceApi* | [**get_template**](docs/PipelineServiceApi.md#get_template) | **GET** /apis/v1beta1/pipelines/{id}/templates | Returns a single YAML template that contains the description, parameters, and metadata associated with the pipeline provided.
*PipelineServiceApi* | [**list_pipeline_versions**](docs/PipelineServiceApi.md#list_pipeline_versions) | **GET** /apis/v1beta1/pipeline_versions |
*PipelineServiceApi* | [**list_pipelines**](docs/PipelineServiceApi.md#list_pipelines) | **GET** /apis/v1beta1/pipelines | Find all pipelines.
*PipelineUploadServiceApi* | [**upload_pipeline**](docs/PipelineUploadServiceApi.md#upload_pipeline) | **POST** /apis/v1beta1/pipelines/upload |
*PipelineUploadServiceApi* | [**upload_pipeline_version**](docs/PipelineUploadServiceApi.md#upload_pipeline_version) | **POST** /apis/v1beta1/pipelines/upload_version |
*RunServiceApi* | [**archive_run**](docs/RunServiceApi.md#archive_run) | **POST** /apis/v1beta1/runs/{id}:archive | Archive a run.
*RunServiceApi* | [**create_run**](docs/RunServiceApi.md#create_run) | **POST** /apis/v1beta1/runs | Create a new run.
*RunServiceApi* | [**delete_run**](docs/RunServiceApi.md#delete_run) | **DELETE** /apis/v1beta1/runs/{id} | Delete a run.
*RunServiceApi* | [**get_run**](docs/RunServiceApi.md#get_run) | **GET** /apis/v1beta1/runs/{run_id} | Find a specific run by ID.
*RunServiceApi* | [**list_runs**](docs/RunServiceApi.md#list_runs) | **GET** /apis/v1beta1/runs | Find all runs.
*RunServiceApi* | [**read_artifact**](docs/RunServiceApi.md#read_artifact) | **GET** /apis/v1beta1/runs/{run_id}/nodes/{node_id}/artifacts/{artifact_name}:read | Find a run&#39;s artifact data.
*RunServiceApi* | [**report_run_metrics**](docs/RunServiceApi.md#report_run_metrics) | **POST** /apis/v1beta1/runs/{run_id}:reportMetrics | ReportRunMetrics reports metrics of a run. Each metric is reported in its own transaction, so this API accepts partial failures. Metric can be uniquely identified by (run_id, node_id, name). Duplicate reporting will be ignored by the API. First reporting wins.
*RunServiceApi* | [**retry_run**](docs/RunServiceApi.md#retry_run) | **POST** /apis/v1beta1/runs/{run_id}/retry | Re-initiate a failed or terminated run.
*RunServiceApi* | [**terminate_run**](docs/RunServiceApi.md#terminate_run) | **POST** /apis/v1beta1/runs/{run_id}/terminate | Terminate an active run.
*RunServiceApi* | [**unarchive_run**](docs/RunServiceApi.md#unarchive_run) | **POST** /apis/v1beta1/runs/{id}:unarchive | Restore an archived run.


## Documentation For Models

- [ApiCronSchedule](docs/ApiCronSchedule.md)
- [ApiExperiment](docs/ApiExperiment.md)
- [ApiGetTemplateResponse](docs/ApiGetTemplateResponse.md)
- [ApiJob](docs/ApiJob.md)
- [ApiListExperimentsResponse](docs/ApiListExperimentsResponse.md)
- [ApiListJobsResponse](docs/ApiListJobsResponse.md)
- [ApiListPipelineVersionsResponse](docs/ApiListPipelineVersionsResponse.md)
- [ApiListPipelinesResponse](docs/ApiListPipelinesResponse.md)
- [ApiListRunsResponse](docs/ApiListRunsResponse.md)
- [ApiParameter](docs/ApiParameter.md)
- [ApiPeriodicSchedule](docs/ApiPeriodicSchedule.md)
- [ApiPipeline](docs/ApiPipeline.md)
- [ApiPipelineRuntime](docs/ApiPipelineRuntime.md)
- [ApiPipelineSpec](docs/ApiPipelineSpec.md)
- [ApiPipelineVersion](docs/ApiPipelineVersion.md)
- [ApiReadArtifactResponse](docs/ApiReadArtifactResponse.md)
- [ApiRelationship](docs/ApiRelationship.md)
- [ApiReportRunMetricsRequest](docs/ApiReportRunMetricsRequest.md)
- [ApiReportRunMetricsResponse](docs/ApiReportRunMetricsResponse.md)
- [ApiResourceKey](docs/ApiResourceKey.md)
- [ApiResourceReference](docs/ApiResourceReference.md)
- [ApiResourceType](docs/ApiResourceType.md)
- [ApiRun](docs/ApiRun.md)
- [ApiRunDetail](docs/ApiRunDetail.md)
- [ApiRunMetric](docs/ApiRunMetric.md)
- [ApiStatus](docs/ApiStatus.md)
- [ApiTrigger](docs/ApiTrigger.md)
- [ApiUrl](docs/ApiUrl.md)
- [ExperimentStorageState](docs/ExperimentStorageState.md)
- [JobMode](docs/JobMode.md)
- [ProtobufAny](docs/ProtobufAny.md)
- [ReportRunMetricsResponseReportRunMetricResult](docs/ReportRunMetricsResponseReportRunMetricResult.md)
- [ReportRunMetricsResponseReportRunMetricResultStatus](docs/ReportRunMetricsResponseReportRunMetricResultStatus.md)
- [RunMetricFormat](docs/RunMetricFormat.md)
- [RunStorageState](docs/RunStorageState.md)


## Documentation For Authorization


## Bearer

- **Type**: API key
- **API key parameter name**: authorization
- **Location**: HTTP header


## Author

[email protected]


Loading