Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 330f429a authored by LETORT Sebastien's avatar LETORT Sebastien
Browse files

[doc]minor correction. link in readme, variable name in notebooks, and cell...

[doc]minor correction. link in readme, variable name in notebooks, and cell order for the constructor.
parent 8d184e57
No related branches found
No related tags found
1 merge request!4Client api
......@@ -7,7 +7,7 @@ python 3.7: [![coverage report 3.7](https://gitlab.inria.fr/allgo/api-clients/py
## Description
AllGo is a SaaS (Software as a Service) platform provided by Inria. It may be seen as a virtual showroom of technologies developed by research teams.
First follow https://allgo18.inria.fr/accounts/signup to create an account on AllGo (anyone may create such an account). Once your account creation is confirmed, please connect to https://allgo18.inria.fr to obtain your private token, which will allow you to use the AllGo REST API. You will need this token later (cf. §3 below).
First follow https://allgo18.inria.fr/accounts/login/ to create an account on AllGo (anyone may create such an account). Once your account creation is confirmed, please connect to https://allgo18.inria.fr to obtain your private token, which will allow you to use the AllGo REST API. You will need this token later (cf. §3 below).
## Installing
```
......
%% Cell type:markdown id: tags:
# Allgo Python API-client demonstrator
## Introduction
### reminder
* Allgo project : https://allgo18.inria.fr
* Allgo API documentation legacy : https://allgo.inria.fr/documentation/api
* Allgo API documentation : https://allgo.gitlabpages.inria.fr/doc/api.html
* API-client project : https://gitlab.inria.fr/allgo/api-clients
### this is a python demonstrator
Here we will show you how to use the python client to launch allgo-job.
## CODE :)
### import allgo
%% Cell type:code id: tags:
``` python
# first import allgo
import allgo
# you can check
print(allgo.__version__)
# print(allgo.__file__)
```
%% Output
0.2.0
%% Cell type:markdown id: tags:
### constructor - an allgo object represents the user-instance connexion
%% Cell type:code id: tags:
``` python
# you could specify an alternative url
# by default, it's the "official" instance that is used.
token = None # put your token.
url = "https://localhost/" # here this is our dev instance.
client = allgo.Client(token, allgo_url=url, verify_tls=False) # on localhost we cannot verify tls.
client = allgo.Client(token)
print("You've got a connexion to {}".format(client.allgo_url))
```
%% Output
You've got a connexion to https://localhost/
You've got a connexion to https://allgo18.inria.fr
%% Cell type:code id: tags:
``` python
# by default, it's the "official" instance that is used.
# you could specify an alternative url
token = None # put your token.
client = allgo.Client(token)
print("You've got a connexion to {}".format(client.allgo_url))
url = "https://localhost/" # here this is our dev instance.
another_client = allgo.Client(token, allgo_url=url, verify_tls=False) # on localhost we cannot verify tls.
print("You've got a connexion to {}".format(another_client.allgo_url))
```
%% Output
You've got a connexion to https://allgo18.inria.fr
You've got a connexion to https://localhost/
%% Cell type:markdown id: tags:
### create a job
%% Cell type:code id: tags:
``` python
app = 'sleep' # the appli you want to execute
params = '3' # sleep duration
files = None # sleep do not use file, else create a list of filepath to load.
# your code allgo
out_dict = client.create_job(app, params=params, files=files)
job_id = out_dict['id']
print("=> Jobs launched with Id {}.".format(job_id))
print("full output dictionary : {}".format(out_dict))
```
%% Output
=> Jobs launched with Id 787.
full output dictionary : {'url': 'https://allgo18.inria.fr/api/v1/jobs/787', 'avg_time': 0, 'id': 787}
%% Cell type:markdown id: tags:
### get job status
%% Cell type:code id: tags:
``` python
# wait for the job to terminate
# = sleep until its status tell it's terminated.
from time import sleep
while True:
out_dict = client.job_status(job_id)
print( "out_dict = {}".format( out_dict ))
if out_dict['status'] != 'done':
print("... not done, let's wait 2 more sec.")
sleep(2)
else:
print("=> job's done !")
break
```
%% Output
out_dict = {'787': {'allgo.log': 'https://allgo18.inria.fr/datastore/787/allgo.log'}, 'status': 'done'}
=> job's done !
%% Cell type:markdown id: tags:
### trick to run a job in a single call
%% Cell type:code id: tags:
``` python
# you can do create_job+job_status with a single method
app = 'sleep' # the appli you want to execute
params = '3' # sleep duration
files = None # sleep do not use file, else create a list of filepath to load.
out_dict = client.run_job(app, params=params, files=files, verbose=True)
print(out_dict)
```
%% Output
running .
done
{'789': {'allgo.log': 'https://allgo18.inria.fr/datastore/789/allgo.log'}, 'status': 'done', 'id': 789}
%% Cell type:markdown id: tags:
### download a file generated
%% Cell type:code id: tags:
``` python
# last download a file generated
# here the log file.
wanted_filename = 'allgo.log'
outdir = "output_dir"
print("We will download '{}' from job '{}' in '{}'.".format(wanted_filename, job_id, outdir))
local_outdir = "output_dir"
print("We will download '{}' from job '{}' in '{}'.".format(wanted_filename, job_id, local_outdir))
job_id = out_dict['id']
url = out_dict[str(job_id)]['allgo.log']
filepath = client.download_file(url, force=True, outdir=outdir)
filepath = client.download_file(url, force=True, outdir=local_outdir)
print("downloaded file : {}".format(filepath))
with open(filepath, 'r') as fe:
for line in fe:
print("...\t{}".format(line), end='')
```
%% Output
We will download 'allgo.log' from job '787' in 'output_dir'.
downloaded file : output_dir/allgo.log
...
... This is app 'sleep' called with parameters '3'
...
... The workdir contains:
...
... total 0
... -rw-r--r-- 1 500 500 72 Dec 6 08:49 allgo.log
... POUET v1
... + sleep 3
...
... ==== ALLGO JOB SUCCESS ====
%% Cell type:markdown id: tags:
### Display the log
We provide a short cut to let the user retrieve the logfile content, the whole cell above.
Note: You get log content by chunk which may content many lines.
Note: The method get the file named 'allgo.log'.
%% Cell type:code id: tags:
``` python
job_id = out_dict['id']
print('Here is the log content of job {}\n----'.format(job_id))
for c in client.get_log(job_id):
print(c)
```
%% Output
Here is the log content of job 789
----
This is app 'sleep' called with parameters '3'
The workdir contains:
total 0
-rw-r--r-- 1 500 500 72 Dec 6 08:49 allgo.log
POUET v1
+ sleep 3
==== ALLGO JOB SUCCESS ====
%% Cell type:markdown id: tags:
## Deal with errors
### try ... except
%% Cell type:code id: tags:
``` python
# Protect your code to catch potential exception raised.
try:
# your code allgo
pass
except ag.StatusError as e:
print("status: {}, msg: {}".format(e.status_code, e.msg))
except ag.AllgoError as e:
print("Error in *client API*")
print(e)
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment