Skip to content
Snippets Groups Projects
Commit 77b63626 authored by Sybren A. Stüvel's avatar Sybren A. Stüvel
Browse files

Server: added /f/{p-url}/jobs/{job-id}/depsgraph endpoint to draw depsgraph

For now this is intended as a debug tool. It uses vis.js to visualise the
dependency graph of the job.
parent 8802ff76
No related branches found
No related tags found
No related merge requests found
...@@ -70,6 +70,47 @@ def view_job(project, flamenco_props, job_id): ...@@ -70,6 +70,47 @@ def view_job(project, flamenco_props, job_id):
can_requeue_job=write_access and job['status'] in REQUEABLE_JOB_STATES) can_requeue_job=write_access and job['status'] in REQUEABLE_JOB_STATES)
@perproject_blueprint.route('/<job_id>/depsgraph')
@flamenco_project_view(extension_props=False)
def view_job_depsgraph(project, job_id):
# Job list is public, job details are not.
if not flask_login.current_user.has_role(*ROLES_REQUIRED_TO_VIEW_ITEMS):
raise wz_exceptions.Forbidden()
if request.is_xhr:
from flask import jsonify
# Return the vis.js nodes and edges as JSON
tasks = current_flamenco.task_manager.tasks_for_job(job_id)
nodes = []
edges = []
# Make a mapping from database ID to task index
tid_to_idx = {task['_id']: tidx
for tidx, task in enumerate(tasks._items)}
for task in tasks._items:
task_id = tid_to_idx[task['_id']]
nodes.append({
'id': task_id,
'label': task['name'],
'shape': 'box',
})
if task.parents:
for parent in task.parents:
edges.append({
'from': task_id,
'to': tid_to_idx[parent],
'arrows': 'to',
})
return jsonify(nodes=nodes, edges=edges)
return render_template('flamenco/jobs/depsgraph.html',
job_id=job_id,
project=project)
@blueprint.route('/<job_id>/set-status', methods=['POST']) @blueprint.route('/<job_id>/set-status', methods=['POST'])
def set_job_status(job_id): def set_job_status(job_id):
from flask_login import current_user from flask_login import current_user
......
This diff is collapsed.
This diff is collapsed.
function depsgraph(canvas_id, nodes, edges) {
var container = document.getElementById(canvas_id);
// provide the data in the vis format
var data = {
nodes: new vis.DataSet(nodes),
edges: new vis.DataSet(edges)
};
var options = {
layout: {
hierarchical: {
direction: "RL",
sortMethod: "directed",
blockShifting: true,
edgeMinimization: true,
parentCentralization: true,
},
},
interaction: {
dragNodes: false,
},
physics: {
enabled: false,
},
};
// initialize your network!
var network = new vis.Network(container, data, options);
}
doctype html
html(lang="en")
head
meta(charset="utf-8")
title Job Depsgraph - Flamenco
meta(name="viewport", content="width=device-width, initial-scale=1.0")
link(href="{{ url_for('static_flamenco', filename='assets/css/vendor/vis.min.css') }}", rel="stylesheet")
script(src="{{ url_for('static_pillar', filename='assets/js/vendor/jquery-3.1.0.min.js')}}")
script(src="{{ url_for('static_flamenco', filename='assets/js/vendor/vis.min.js')}}")
script(src="{{ url_for('static_flamenco', filename='assets/js/generated/depsgraph.min.js')}}")
link(href="{{ url_for('static_flamenco', filename='assets/img/favicon.png') }}", rel="shortcut icon")
style.
html, body {
background-color: white;
color: black;
margin: 0;
padding: 0;
}
#depsgraph {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
body
#depsgraph
script.
$.get('depsgraph', function(node_edge_data) {
console.log('Node/edge data: ', node_edge_data);
depsgraph('depsgraph', node_edge_data.nodes, node_edge_data.edges);
})
.fail(function(xhr) {
console.log('Could not get depsgraph data', xhr);
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment