executions.py 2.69 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Copyright (c) 2015, Daniele Venzano
#
# 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.

16
17
import json

18
from flask import render_template, request, redirect, url_for
19

Daniele Venzano's avatar
Daniele Venzano committed
20
21
22
23
from zoe_api.web.utils import get_auth, catch_exceptions
import zoe_api.config as config
import zoe_api.api_endpoint
import zoe_api.exceptions
24
25


26
@catch_exceptions
27
def execution_define():
28
    get_auth(request)
29
30
31
32

    return render_template('execution_new.html')


33
@catch_exceptions
34
def execution_start():
35
    uid, role = get_auth(request)
Daniele Venzano's avatar
Daniele Venzano committed
36
    assert isinstance(config.api_endpoint, zoe_api.api_endpoint.APIEndpoint)
37

38
39
    app_descr_json = request.files['file'].read().decode('utf-8')
    app_descr = json.loads(app_descr_json)
40
41
    exec_name = request.form['exec_name']

42
    new_id = config.api_endpoint.execution_start(uid, role, exec_name, app_descr)
43
44

    return redirect(url_for('web.execution_inspect', execution_id=new_id))
45
46


47
@catch_exceptions
48
def execution_restart(execution_id):
49
    uid, role = get_auth(request)
Daniele Venzano's avatar
Daniele Venzano committed
50
    assert isinstance(config.api_endpoint, zoe_api.api_endpoint.APIEndpoint)
51

52
53
    e = config.api_endpoint.execution_by_id(uid, role, execution_id)
    new_id = config.api_endpoint.execution_start(uid, role, e.name, e.description)
54
55
56
57

    return redirect(url_for('web.execution_inspect', execution_id=new_id))


58
@catch_exceptions
59
def execution_terminate(execution_id):
60
    uid, role = get_auth(request)
Daniele Venzano's avatar
Daniele Venzano committed
61
    assert isinstance(config.api_endpoint, zoe_api.api_endpoint.APIEndpoint)
62

63
64
    success, message = config.api_endpoint.execution_terminate(uid, role, execution_id)
    if not success:
Daniele Venzano's avatar
Daniele Venzano committed
65
        raise zoe_api.exceptions.ZoeException(message)
66
67

    return redirect(url_for('web.home_user'))
68
69


70
@catch_exceptions
71
def execution_inspect(execution_id):
72
    uid, role = get_auth(request)
Daniele Venzano's avatar
Daniele Venzano committed
73
    assert isinstance(config.api_endpoint, zoe_api.api_endpoint.APIEndpoint)
74

75
    e = config.api_endpoint.execution_by_id(uid, role, execution_id)
76

Daniele Venzano's avatar
Daniele Venzano committed
77
78
79
80
    services_info = {}
    if e.service_list is not None:
        for s in e.service_list:
            services_info[s.id] = config.api_endpoint.service_inspect(s)
81
82

    template_vars = {
83
        "e": e,
Daniele Venzano's avatar
Daniele Venzano committed
84
85
        "services": e.service_list,
        "services_info": services_info
86
87
    }
    return render_template('execution_inspect.html', **template_vars)