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

GraphDB storage POC #2

Draft
wants to merge 42 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
79ada91
Added mock cbs node
dsmits May 25, 2020
80834be
Initial commit for vantage client module, hasn't been tested yet
dsmits May 25, 2020
5db6865
Print api keys after creating nodes
dsmits May 26, 2020
440c1e7
Added local docker registry to docker-compose
dsmits May 26, 2020
7c1efc2
Task input is now received by server
dsmits May 27, 2020
4cf2a98
Separate registry
dsmits May 27, 2020
d8c90eb
Updated readme
dsmits May 27, 2020
20767b4
Setup is working now
dsmits May 28, 2020
f526a90
Cleanup of run_task
dsmits May 28, 2020
0361fe2
Update README.MD
dsmits Jun 2, 2020
83dbef4
Added more realistic dataset
dsmits Jun 2, 2020
9168467
Merge branch 'master' of github.com:dsmits/vantage6-local-setup
dsmits Jun 2, 2020
870e877
Switched back to using most up to date node image from official registry
dsmits Jun 2, 2020
f9fd159
Clearer instructions in readme
dsmits Jun 3, 2020
cbf852d
Fixed database path for mumc node
dsmits Jun 3, 2020
ee00b35
Added option to run master algorithm
dsmits Jun 9, 2020
f0f0168
Removed unused load_mumc_data.py
dsmits Jun 9, 2020
3f3eb66
Added another node
dsmits Jun 9, 2020
0eb8bb5
Every node will be in a separate organization
dsmits Jun 9, 2020
4d01f71
DIfferent ids
dsmits Jun 10, 2020
08dd59e
Load initial configuration from sql dump
dsmits Jun 11, 2020
99a87ec
Updated readme
dsmits Jun 11, 2020
602b08c
Added sample data from FAIRhealth project
dsmits Jun 2, 2020
1da87bb
Setup now has two nodes with vertically partitioned data
dsmits Jun 2, 2020
16472d9
Created script to add a new node with a specified name
dsmits Jun 11, 2020
f5acb39
Created cbs node and added it to the database dump
dsmits Jun 11, 2020
e1255b5
Assigned every node its own shared volume
dsmits Jun 15, 2020
dcc9717
Moved all node specific data to nodes dir
dsmits Jun 15, 2020
bba5dc4
Made add_new_node.py more flexible
dsmits Jun 15, 2020
12b336e
Added escience master node
dsmits Jun 15, 2020
7359b99
Added node to escience organization
dsmits Jun 15, 2020
b66e5d5
Pretty print pandas DataFrames
dsmits Jun 18, 2020
cdc92a5
Replace csv with bostom sample linked data for escience data
svenvanderburg Jun 19, 2020
7d5fdd4
Keep only the escience data station with example .ttl data, run get_p…
svenvanderburg Jun 19, 2020
6ecfd98
Convert run_task.py into command line client
svenvanderburg Jun 22, 2020
4880502
Add comment for --master/--rpc option
svenvanderburg Jun 23, 2020
cead982
Fix num_retries bug, changed num_retries into num_tries
svenvanderburg Jun 23, 2020
0573e0a
Merge pull request #3 from CARRIER-project/run_task_cli
dsmits Jun 23, 2020
4d40671
Merge branch 'master' of github.com:CARRIER-project/vantage6-local-se…
svenvanderburg Jun 23, 2020
e77022d
Setup graphdb and populate with sample data
svenvanderburg Jun 24, 2020
4c67812
Correctly configure docker-compose so the node container can access t…
svenvanderburg Jun 24, 2020
262c3cb
Add run_task command for POC algorithm to readme
svenvanderburg Jun 24, 2020
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea
venv/
pgdata/
__pycache__/
116 changes: 16 additions & 100 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,110 +1,26 @@
# Vantage6 installation
# Vantage 6 local setup

Install:
```shell
virtualenv venv
source venv/bin/activate
pip install vantage6
## Running the local setup
Simply run:
```shell script
docker-compose up -d
```

Configure server:
```shell
# --user parameter makes sure config is stored in user directory, not system wide
vserver new --user # Wizard prompts you for basic info
# Executing a task
When your docker setup is running you can execute a task using `run_task.py`. Replace the value in `IMAGE` with your
desired docker image

vserver start --user
# Docker registry
For development purposes you might want to run your own local docker registry:
```

At the first run, a new user will be created:
```
username: root
password: root

# Run docker registry separately. Node tasks are run in a network separate from the node itself. By making the registry
# available from the host network it will be accessable by all docker containers
docker run -d --name registry --network host registry:2
```
In order to get access to the REST api you will need to request a user token:

```shell
# Get your user token
curl --location --request POST 'localhost:5000/api/token/user' \
--header 'Content-Type: application/json' \
--data-raw '{
"username": "root",
"password": "root"
}'
The `run_task.py` script runs a custom algorithm [available on github](https://github.com/CARRIER-project/vantage6-algorithms)
Make sure this task is published to the local registry by running `push_to_local_registry.sh` from that repo

```

Now you can configure your organization, collaboration and node.
This can also be done by importing a configuration file, but using the REST api ensures
the input is validated, which is nice when trying out vantage6 for the first time.

Make sure to replace `YOUR_API_KEY` with the key received in the previous step.

```shell
# Organization

curl --location --request POST 'localhost:5000/api/organization' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"address1": "Some Street 11, Amsterdam",
"country": "Netherlands",
"name": "escience center",
"zipcode": "1234ab"
}'

# Collaboration
curl --location --request POST 'localhost:5000/api/collaboration' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "collab1",
"organization_ids": [
1
]
}'

# Add organization to collaboration

curl --location --request POST 'localhost:5000/api/collaboration/1/organization' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{"id": 1}'


# Create user tied to organization

curl --location --request POST 'localhost:5000/api/user' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{

"firstname": "djura",
"lastname": "smits",
"password": "admin",
"organization_id": "1",
"username": "admin",
"roles": ["admin"]

}'

# Now retrieve token for this new user
#
#
#

# Node
# Create node
curl --location --request POST 'localhost:5000/api/node' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"collaboration_id": 1
}'

```
Check the api key that you have received and use that for your configuration of the vnode.

```bash
vnode new # Follow wizard and specify api key
python run_task.py
```
63 changes: 63 additions & 0 deletions add_new_node.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python3

import click

from carrier import VantageClient

USERNAME = 'root'
PASSWORD = 'root'
ADMIN_PASSWORD = 'admin'
COLLABORATION_ID = 1

ORGANIZATION_BASE = ORGANIZATION = {'address1': 'my address 1, Amsterdam',
'country': 'the Netherlands',
'zipcode': '1234ab'}


@click.command()
@click.argument('name')
@click.option('--org-id')
@click.option('--username')
@click.option('--password', default=ADMIN_PASSWORD)
def create_node(name, org_id, username, password):

if not (org_id and username):

client = VantageClient(USERNAME, PASSWORD)

if not org_id:
print('Creating new organization')
org_id = create_organization(client, name)

if not username:
username = f'admin_{org_id}'
print(f'Creating new user {username}')
# Create user for organization
create_user(client, org_id, username)

# Create node
client = VantageClient(username, password)
result = client.post('node', {'collaboration_id': COLLABORATION_ID, 'organization_id': org_id})
api_key = result['api_key']

print(f'Created new node. Api key: {api_key}')


def create_organization(client, name):
# Create organization for node
organization = dict(ORGANIZATION_BASE)
organization['name'] = name
result = client.post('organization', organization)
org_id = result['id']
return org_id


def create_user(client, organization_id, username):
user = {'firstname': ' ', 'lastname': ' ', 'username': username, 'organization_id': organization_id,
'password': ADMIN_PASSWORD, 'roles': ['admin']}
result = client.post('user', user)
print(f'Created new user:\n{result}')


if __name__ == '__main__':
create_node()
1 change: 1 addition & 0 deletions carrier/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .vantage_client import *
89 changes: 89 additions & 0 deletions carrier/vantage_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import base64
import json
import pickle

import requests
from vantage6.client import Client

_HOST = 'http://localhost'
_PORT = 5001

HOST = 'localhost'
PORT = 5001
PREFIX = 'api'
DEFAULT_SERVER_ROOT = f'{HOST}:{PORT}/{PREFIX}/'
OK_RESPONSES = [200, 201]
DEFAULT_CONTENT_TYPE = 'application/json'
POST = 'POST'
DEFAULT_HEADERS = {'Content-Type': DEFAULT_CONTENT_TYPE}


def get_official_client(username, password):
"""
Get official vantage6 client.

:param username:
:param password:
:return:
"""
client = Client(_HOST, _PORT)
client.authenticate(username, password)
client.setup_encryption(None)

return client


class VantageClient():
"""
Custom made vantage client to work around some problems the official has at the moment (such as authenticating root
users).
"""

def __init__(self, username, password):
# Retrieve a authentication token
self.token = self.get_token(username, password)
self.headers = {
'Authorization': f'Bearer {self.token}',
'Content-Type': DEFAULT_CONTENT_TYPE
}

@staticmethod
def get_url(endpoint) -> str:
return 'http://' + DEFAULT_SERVER_ROOT + endpoint

def get_token(self, username, password):
result = self.request('token/user', {'username': username, 'password': password}, headers=DEFAULT_HEADERS,
method=POST)
return result['access_token']

def get(self, endpoint, payload=None, headers=None) -> dict:
return self.request(endpoint, payload, headers, 'GET')

def post(self, endpoint, payload, headers=None):
print(f'Posting: {payload}')
return self.request(endpoint, payload, headers, 'POST')

def post_task(self, name, image, collaboration_id, organizations):
for o in organizations:
input_base64 = base64.b64encode(pickle.dumps(o['input']))
o['input'] = str(input_base64, 'utf8')
print(f'Base64 converted input: {o}')

payload = {'collaboration_id': collaboration_id, 'image': image, 'name': name, 'organizations': organizations}
return self.post('task', payload)

def request(self, endpoint, payload, headers=None, method='GET') -> dict:
if headers is None:
headers = self.headers

url = VantageClient.get_url(endpoint)

print(f'Request {method} {url}')

headers['Content-Type'] = 'application/json'
response = requests.request(method, url, headers=headers, data=json.dumps(payload))

if response.status_code in OK_RESPONSES:
return response.json()
else:
raise Exception(f'Request returned status {response.status_code}\nMessage: {response.content}')
Loading