-
Notifications
You must be signed in to change notification settings - Fork 0
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
svenvanderburg
wants to merge
42
commits into
master
Choose a base branch
from
linked-data-poc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
79ada91
Added mock cbs node
dsmits 80834be
Initial commit for vantage client module, hasn't been tested yet
dsmits 5db6865
Print api keys after creating nodes
dsmits 440c1e7
Added local docker registry to docker-compose
dsmits 7c1efc2
Task input is now received by server
dsmits 4cf2a98
Separate registry
dsmits d8c90eb
Updated readme
dsmits 20767b4
Setup is working now
dsmits f526a90
Cleanup of run_task
dsmits 0361fe2
Update README.MD
dsmits 83dbef4
Added more realistic dataset
dsmits 9168467
Merge branch 'master' of github.com:dsmits/vantage6-local-setup
dsmits 870e877
Switched back to using most up to date node image from official registry
dsmits f9fd159
Clearer instructions in readme
dsmits cbf852d
Fixed database path for mumc node
dsmits ee00b35
Added option to run master algorithm
dsmits f0f0168
Removed unused load_mumc_data.py
dsmits 3f3eb66
Added another node
dsmits 0eb8bb5
Every node will be in a separate organization
dsmits 4d01f71
DIfferent ids
dsmits 08dd59e
Load initial configuration from sql dump
dsmits 99a87ec
Updated readme
dsmits 602b08c
Added sample data from FAIRhealth project
dsmits 1da87bb
Setup now has two nodes with vertically partitioned data
dsmits 16472d9
Created script to add a new node with a specified name
dsmits f5acb39
Created cbs node and added it to the database dump
dsmits e1255b5
Assigned every node its own shared volume
dsmits dcc9717
Moved all node specific data to nodes dir
dsmits bba5dc4
Made add_new_node.py more flexible
dsmits 12b336e
Added escience master node
dsmits 7359b99
Added node to escience organization
dsmits b66e5d5
Pretty print pandas DataFrames
dsmits cdc92a5
Replace csv with bostom sample linked data for escience data
svenvanderburg 7d5fdd4
Keep only the escience data station with example .ttl data, run get_p…
svenvanderburg 6ecfd98
Convert run_task.py into command line client
svenvanderburg 4880502
Add comment for --master/--rpc option
svenvanderburg cead982
Fix num_retries bug, changed num_retries into num_tries
svenvanderburg 0573e0a
Merge pull request #3 from CARRIER-project/run_task_cli
dsmits 4d40671
Merge branch 'master' of github.com:CARRIER-project/vantage6-local-se…
svenvanderburg e77022d
Setup graphdb and populate with sample data
svenvanderburg 4c67812
Correctly configure docker-compose so the node container can access t…
svenvanderburg 262c3cb
Add run_task command for POC algorithm to readme
svenvanderburg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
.idea | ||
venv/ | ||
pgdata/ | ||
__pycache__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,34 @@ | ||
# Vantage6 installation | ||
# Vantage 6 local setup | ||
|
||
Install: | ||
```shell | ||
virtualenv venv | ||
source venv/bin/activate | ||
pip install vantage6 | ||
``` | ||
|
||
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 | ||
## Running the local setup | ||
Simply run: | ||
```shell script | ||
docker-compose up --force-recreate | ||
|
||
vserver start --user | ||
# Populate 'escience' node rdf store with sample data | ||
./nodes/escience/populate-rdf-store.sh | ||
``` | ||
|
||
At the first run, a new user will be created: | ||
``` | ||
username: root | ||
password: root | ||
# 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 | ||
|
||
# Docker registry | ||
For development purposes you might want to run your own local docker registry: | ||
``` | ||
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" | ||
}' | ||
|
||
# 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 | ||
``` | ||
|
||
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 | ||
}' | ||
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 | ||
|
||
``` | ||
Check the api key that you have received and use that for your configuration of the vnode. | ||
python run_task.py | ||
``` | ||
|
||
```bash | ||
vnode new # Follow wizard and specify api key | ||
To run the sample_sparqle_query method: | ||
``` | ||
python run_task.py --rpc --method 'sample_sparqle_query' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .vantage_client import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}') |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice that you updated the readme as well 👍