Commit 97ed2fd9 authored by Daniele Venzano's avatar Daniele Venzano

Execution can be terminated and restarted from the web interface (users and admins only)

parent bf10b208
......@@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from flask import render_template, request
from flask import render_template, request, redirect, url_for
from zoe_lib.services import ZoeServiceAPI
from zoe_lib.executions import ZoeExecutionsAPI
......@@ -43,19 +43,36 @@ def execution_start(app_id):
return render_template('execution_new.html', **template_vars)
@web_bp.route('/executions/terminate/<exec_id>')
def execution_terminate(exec_id):
user = us.user_get(session['user_id'])
if user is None:
return redirect(url_for('web.index'))
execution = ex.execution_get(exec_id)
@web_bp.route('/executions/restart/<int:execution_id>')
def execution_restart(execution_id):
auth = request.authorization
if not auth:
return missing_auth()
template_vars = {
"user_id": user.id,
"email": user.email,
'execution': execution
}
return render_template('execution_terminate.html', **template_vars)
guest_identifier = auth.username
guest_password = auth.password
exec_api = ZoeExecutionsAPI(get_conf().master_url, guest_identifier, guest_password)
e = exec_api.execution_get(execution_id)
new_id = exec_api.execution_start(e['name'], e['application'])
return redirect(url_for('web.execution_inspect', execution_id=new_id))
@web_bp.route('/executions/terminate/<int:execution_id>')
def execution_terminate(execution_id):
auth = request.authorization
if not auth:
return missing_auth()
guest_identifier = auth.username
guest_password = auth.password
exec_api = ZoeExecutionsAPI(get_conf().master_url, guest_identifier, guest_password)
e = exec_api.execution_get(execution_id)
exec_api.terminate(execution_id)
return redirect(url_for('web.home_user'))
@web_bp.route('/executions/inspect/<int:execution_id>')
......
{% extends "base_user.html" %}
{% block title %}Terminate execution {{ execution.name }}{% endblock %}
{% block content %}
<script type="application/javascript">
(function() {
$.getJSON("{{ url_for("api.execution_terminate", exec_id=execution.id) }}")
.done(function( data ) {
if (data.status == "ok") {
$("#result").empty().append("Cluster terminated succesfully");
} else {
$("#result").empty().append("Cluster did not terminate succesfully, something happened")
}
});
})();
</script>
<h2>Termination request for execution "{{ execution.name }}"</h2>
<p id="result">Request sent...</p>
{% endblock %}
\ No newline at end of file
......@@ -8,7 +8,6 @@
<thead>
<tr>
<th>Execution name</th>
<th>Application name</th>
{% if is_admin %}
<th>User</th>
{% endif %}
......@@ -16,13 +15,13 @@
<th>Scheduled</th>
<th>Started</th>
<th>Finished</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for e in executions %}
<tr class="{{ loop.cycle('odd', 'even') }}">
<td><a href="/executions/inspect/{{ e['id'] }}">{{ e['name'] }}</a></td>
<td>{{ e['application']['name'] }}</td>
{% if is_admin %}
<td>{{ e['owner'] }}</td>
{% endif %}
......@@ -38,6 +37,11 @@
{% else %}
<td><script>format_timestamp("{{ e['time_finished'] }}")</script></td>
{% endif %}
{% if e['status'] == "running" or e['status'] == "scheduled" %}
<td><a href="/executions/terminate/{{ e['id'] }}">Terminate</a></td>
{% else %}
<td><a href="/executions/restart/{{ e['id'] }}">Restart</a></td>
{% endif %}
</tr>
{% endfor %}
</tbody>
......
......@@ -7,7 +7,6 @@
<ul>
<li><a href="{{ url_for('web.home_guest') }}">Guest start page</a></li>
<li><a href="{{ url_for('web.home_user') }}">User start page</a></li>
<li><a href="{{ url_for('web.home_admin') }}">Admin start page</a></li>
</ul>
{% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment