Metadata-Version: 2.1
Name: nevermined-compute-api
Version: 0.1.0
Summary: Infrastructure Operator Micro-service
Home-page: https://github.com/keyko-io/nevermined-compute-api
Author: Keyko
Author-email: root@keyko.io
License: Apache Software License 2.0
Keywords: nevermined-compute-api
Platform: UNKNOWN
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Description-Content-Type: text/markdown
Requires-Dist: coloredlogs
Requires-Dist: Flask (==1.0.2)
Requires-Dist: Flask-Cors (==3.0.6)
Requires-Dist: flask-swagger (==0.2.14)
Requires-Dist: flask-swagger-ui (==3.20.9)
Requires-Dist: Jinja2 (>=2.10.1)
Requires-Dist: kubernetes (==10.0.0)
Requires-Dist: requests (>=2.21.0)
Requires-Dist: gunicorn (==19.9.0)
Requires-Dist: PyYAML (==5.1)
Requires-Dist: pytz
Provides-Extra: dev
Requires-Dist: bumpversion ; extra == 'dev'
Requires-Dist: pkginfo ; extra == 'dev'
Requires-Dist: twine ; extra == 'dev'
Requires-Dist: watchdog ; extra == 'dev'
Requires-Dist: coverage ; extra == 'dev'
Requires-Dist: mccabe ; extra == 'dev'
Requires-Dist: pylint ; extra == 'dev'
Requires-Dist: pytest ; extra == 'dev'
Provides-Extra: test
Requires-Dist: coverage ; extra == 'test'
Requires-Dist: mccabe ; extra == 'test'
Requires-Dist: pylint ; extra == 'test'
Requires-Dist: pytest ; extra == 'test'

[![banner](https://raw.githubusercontent.com/keyko-io/assets/master/images/logo/small/keyko_logo@2x-100.jpg)](https://keyko.io)

# Nevermined Compute API 

> Compute to the Data Infrastructure Operator Micro-service


Table of Contents
=================

   * [nevermined-compute-api](#nevermined-compute-api)
      * [About](#about)
      * [Getting Started](#getting-started)
         * [Local Environment](#local-environment)
            * [Installing AWS &amp; K8s tools](#installing-aws--k8s-tools)
            * [Running the Service](#running-the-service)
         * [Testing](#testing)
         * [New Version](#new-version)
      * [License](#license)



## About

The Compute API is a micro-service implementing the Nevermined Compute to the Data use case, 
in charge of managing the workflow executing requests.
Typically the Compute Service is integrated with the [Nevermined Gateway](https://github.com/keyko-io/nevermined-gateway),
but can be called independently of it.

The Compute API is in charge of establishing the communication with the K8s cluster, allowing to:

* Register workflows as K8s objects
* List the workflows registered in K8s
* Stop a running workflow execution
* Get information about the state of execution of a workflow

The Compute API doesn't provide any storage capability for workflows, all the state is stored directly in the K8s cluster.

## Getting Started

### Local Environment

The Compute API is in charge of receiving the requests for running compute workflows and the 
setup of those in the K8s infrastructure.
To do that, in a local environment the Compute API needs connectivity to you K8s environment.

There are multiple configurations and deployments of K8s possible, but here we are going to show 
how to connect to an existing K8s cluster running in Amazon Web Services (AWS).

#### Installing AWS & K8s tools

First is necessary to install the AWS CLI:

```
$ sudo pip3 install awscli --upgrade

$ aws --version
aws-cli/1.16.225 Python/3.7.3 Linux/5.0.0-25-generic botocore/1.12.215

```

You need to install the `aws-iam-authenticator`

```
$ curl -o aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.13.7/2019-06-11/bin/linux/amd64/aws-iam-authenticator
chmod +x ./aws-iam-authenticator 
```
And later the Kubectl tool:

```
$ curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
$ chmod +x ./kubectl
$ sudo mv ./kubectl /usr/local/bin/kubectl
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.3", GitCommit:"2d3c76f9091b6bec110a5e63777c332469e0cba2", GitTreeState:"clean", BuildDate:"2019-08-19T11:13:54Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
```

To connect to your specific Kubernetes cluster you need to setup the `~/.kube/config` file with your environment setup.

You can find the complete tutorials here:

* https://aws.amazon.com/cli/
* https://kubernetes.io/docs/tasks/tools/install-kubectl/
* https://docs.aws.amazon.com/eks/latest/userguide/install-aws-iam-authenticator.html


#### Running the Service

Once you have Kubectl able to connect you your K8s cluster, run the service is as simple as running the following commands:


`export FLASK_APP=operator_service/run.py`

`flask run --host=0.0.0.0 --port 8050`

Having the server running you can find the complete Swagger API documentation here:

```
http://0.0.0.0:8050/api/v1/docs/
```

And check some of the API functions like the create or the list of the existing workflow executions:

```
$ curl -X GET "http://localhost:8050/api/v1/operator/list" -H "accept: application/json"
["9f9178dcffd34130a3158ce9ca3d15ff"]
```


### ENV Vars

```
     ALGO_POD_TIMEOUT  = the maximum amount of time in seconds that an algorithm can use before it is killed
     POSTGRES_DB = Postgres database
     POSTGRES_USER = Postgresql user
     POSTGRES_PASSWORD = Postgresql password
     POSTGRES_HOST = Postgresql host
     POSTGRES_PORT = Postgresql port
     SIGNATURE_REQUIRED = 0 -> no signature required, 1 -> request brizo signature
     ALLOWED_PROVIDERS = Json array with allowed providers that can access the endpoints
```

### Testing

Automatic tests are set up via GitHub actions.

### New Version

The `bumpversion.sh` script helps bump the project version. You can execute the script using `{major|minor|patch}` 
as first argument, to bump the version accordingly.

## Attribution

This library service in the [Ocean Protocol](https://oceanprotocol.com) [Operator Service](https://github.com/oceanprotocol/operator-service).
It keeps the same Apache v2 License and adds some improvements. See [NOTICE file](NOTICE).

## License

```
Copyright 2020 Keyko GmbH
This product includes software developed at
BigchainDB GmbH and Ocean Protocol (https://www.oceanprotocol.com/)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```


