blob: 828e310b10d9db97a27c305cdc15aa32a7b06332 [file] [log] [blame]
vinayakb70b63e22012-02-03 13:13:01 +00001$(function() {
2 var jobSpecDAG = new Graphs.DAG();
3 var jobSpecRenderer;
4
5 function drawJobGraph() {
6 var jobGraphDiv = $('#job-graph')[0];
7 jobSpecRenderer = new Graphs.JsPlumbRenderer(jobSpecDAG, jobGraphDiv, null);
8 jobSpecRenderer.refresh();
9 }
10
11 function onJobRunDataReceived(data) {
12 var run = data.result;
13
14 if (run.status != 'TERMINATED' && run.status != 'FAILURE') {
15 setTimeout(fetchJobRun, 10000);
16 }
17 }
18
19 function fetchJobRun() {
20 $.ajax({
21 url : '/rest/jobs/' + $.getURLParam('job-id') + '/job-run',
22 method : 'GET',
23 dataType : 'json',
24 success : onJobRunDataReceived
25 });
26 }
27
28 function onJobActivityGraphDataReceived(data) {
29 var jag = data.result;
30 activityMap = new Object;
31 var activities = jag.activities;
32 for ( var i = 0; i < activities.length; ++i) {
33 var activity = activities[i];
34 }
35
36 drawJobGraph();
37
38 fetchJobRun();
39 }
40
41 function fetchJobActivityGraph() {
42 $.ajax({
43 url : '/rest/jobs/' + $.getURLParam('job-id') + '/job-activity-graph',
44 method : 'GET',
45 dataType : 'json',
46 success : onJobActivityGraphDataReceived
47 });
48 }
49
50 function onJobSpecificationDataReceived(data) {
51 var jobSpec = data.result;
52 var operators = jobSpec.operators;
53 for ( var i = 0; i < operators.length; ++i) {
54 var op = operators[i];
55 jobSpecDAG.addNode(op.id, op);
56 }
57 var connectors = jobSpec.connectors;
58 for ( var i = 0; i < connectors.length; ++i) {
59 var conn = connectors[i];
60 var sNode = jobSpecDAG.lookupNode(conn['in-operator-id']);
61 var sIndex = conn['in-operator-port'];
62 var tNode = jobSpecDAG.lookupNode(conn['out-operator-id']);
63 var tIndex = conn['out-operator-port'];
64 jobSpecDAG.addEdge(conn.id, conn, sNode, sIndex, tNode, tIndex);
65 }
66 fetchJobActivityGraph();
67 }
68
69 function fetchJobSpecification() {
70 $.ajax({
71 url : '/rest/jobs/' + $.getURLParam('job-id') + '/job-specification',
72 method : 'GET',
73 dataType : 'json',
74 success : onJobSpecificationDataReceived
75 });
76 }
77
78 function init() {
79 fetchJobSpecification();
80 }
81
82 jsPlumb.bind("ready", function() {
83 init();
84 });
85});