Merge branch 'development' of gitlab.ub.uni-bielefeld.de:sfb1288inf/opaque into development

This commit is contained in:
Stephan Porada 2019-08-15 15:57:40 +02:00
commit 2832dd8b6f
4 changed files with 116 additions and 0 deletions

View File

@ -4,3 +4,35 @@
- Docker: https://www.docker.com/ - Docker: https://www.docker.com/
- Python 3.5+ - Python 3.5+
## Setup
In order to run jobs, Opaque needs access to a Docker swarm manager. Currently it's not possible to specify a dedicated Docker host, instead Opaque expects the executing system to to be a swarm manager.
1. Get the source code and navigate into the code directory
```
git clone https://gitlab.ub.uni-bielefeld.de/sfb1288inf/opaque.git
cd opaque
```
2. Create Docker swarm
2.1. Local
```
# Set the variable values in setup_local_swarm.sh (nano setup_local_swarm.sh)
./setup_local_swarm.sh
```
2.2. Distributed
2.2.1. Initialize swarm on manager machine
```
docker swarm init
```
3. Create Python virtual environment, activate it and install the required python packages.
```
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```

View File

@ -24,6 +24,9 @@ def create_app(config_name):
scheduler.init_app(app) scheduler.init_app(app)
scheduler.start() scheduler.start()
from .api import api as api_blueprint
app.register_blueprint(api_blueprint, url_prefix='/api')
from .auth import auth as auth_blueprint from .auth import auth as auth_blueprint
app.register_blueprint(auth_blueprint, url_prefix='/auth') app.register_blueprint(auth_blueprint, url_prefix='/auth')

5
app/api/__init__.py Normal file
View File

@ -0,0 +1,5 @@
from flask import Blueprint
api = Blueprint('api', __name__)
from . import views

76
app/api/views.py Normal file
View File

@ -0,0 +1,76 @@
from flask import abort, jsonify, request
from flask_login import current_user, login_required
from . import api
from ..models import Job
@api.route('/v1.0/corpora')
@login_required
def corpora():
corpora = []
for corpus in current_user.corpora.all():
corpora.append({'id': corpus.id,
'creation_date': corpus.creation_date.timestamp(),
'description': corpus.description,
'title': corpus.title})
return jsonify(corpora)
@api.route('/v1.0/corpora/<int:corpus_id>')
@login_required
def corpus(corpus_id):
corpus = current_user.corpora.filter_by(id=corpus_id).first()
if not corpus:
return abort(404)
return jsonify({'id': corpus.id,
'creation_date': corpus.creation_date,
'description': corpus.description,
'title': corpus.title})
@api.route('/v1.0/jobs')
@login_required
def jobs():
jobs = []
all = request.args.get('all')
if all and all.lower() == 'true':
if current_user.is_administrator():
jobs_query = Job.query
else:
return abort(403)
else:
jobs_query = current_user.jobs
for job in jobs_query.all():
jobs.append({'id': job.id,
'creation_date': job.creation_date.timestamp(),
'description': job.description,
'end_date': (job.end_date.timestamp() if job.end_date else
None),
'mem_mb': job.mem_mb,
'n_cores': job.n_cores,
'service': job.service,
'service_args': job.service_args,
'service_version': job.service_version,
'status': job.status,
'title': job.title})
return jsonify(jobs)
@api.route('/v1.0/jobs/<int:job_id>')
@login_required
def job(job_id):
job = current_user.jobs.filter_by(id=job_id).first()
if not job:
return abort(404)
return jsonify({'id': job.id,
'creation_date': job.creation_date.timestamp(),
'description': job.description,
'end_date': (job.end_date.timestamp() if job.end_date else
None),
'mem_mb': job.mem_mb,
'n_cores': job.n_cores,
'service': job.service,
'service_args': job.service_args,
'service_version': job.service_version,
'status': job.status,
'title': job.title})