Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Scripts/Hubs/GraphHubber.js @ 13848

Last change on this file since 13848 was 13848, checked in by jlodewyc, 8 years ago

#2582 Hive finish, start OKB

File size: 6.5 KB
Line 
1var hubber = $.connection.jobUpdaterHub;
2$(function () {
3  //  $.connection.hub.logging = true;
4    var v = document.getElementById("userId").innerHTML;
5    $.connection.hub.qs = { 'userid': v };
6    $.connection.hub.start().done(function () {
7        hubber.server.initConnection();
8        redrawMain();
9    });
10    //processes updates task info for each individual task
11    hubber.client.processData = function (id, data, name) {
12        var obj = JSON.parse(data);
13        editTaskData(id, obj);
14
15        saveData(id, obj.StateLog, name);
16        console.log("#UPDATED " + id);
17    }
18    //processes updated job info
19    hubber.client.processJobData = function (calc, fin) {
20        editJobData(calc, fin);
21    }
22    //Called when server is done with request
23    hubber.client.requestDone = function () {
24        if (document.getElementById("refreshtogg").checked) {
25            setTimeout(function () {
26                hubber.server.updateAll();
27                console.log("#REFRESH ALL");
28
29            }, 5000 + (dataCollection.length * 500));
30        }
31    }
32})
33
34//Toggles the refresh button. ON is refresh every 5 sec, OFF is no refresh
35function autoRefresh() {
36    if (document.getElementById("refreshtogg").checked)
37        hubber.server.updateAll();
38
39}
40//Restarts an aborted, paused or failed task
41function restart(id) {
42    document.getElementById("restarterbtn" + id).disabled = true;
43    document.getElementById("restarterbtn" + id).value = "Sending restart request...";
44    hubber.server.restartTask(id);
45}
46//Writes the new job info to the page
47function editJobData(c, f) {
48    $("#jobcalculating").html("Calculating: " + c);
49    $("#jobfinished").html("Finished: " + f);
50}
51//Writes updated task info to the page
52function editTaskData(id, task) {
53    //lastupdate
54    if (task.LastHeartbeat != null) {
55        var dat = new Date(task.LastHeartbeat);
56        $("#lastupdpar" + id).html("Last update: " + dat.toUTCString());
57    }
58    else
59        $("#lastupdpar" + id).html("No updates yet");
60    //task restarter
61    document.getElementById("restarter" + id).style.display = "none";
62    //state
63    if (task.State == "0") {//OFFLINE
64        $("#statepar" + id).css({
65            'color': 'gray',
66            'font-weight': 'normal'
67        });
68        $("#statepar" + id).html("State: Offline");
69    }
70    else if (task.State == "1") {//WAITING
71        $("#statepar" + id).css({
72            'color': 'white',
73            'font-weight': 'normal'
74        });
75        $("#statepar" + id).html("State: Waiting");
76    }
77    else if (task.State == "2") {//TRANSFERRING
78        $("#statepar" + id).css({
79            'color': 'white',
80            'font-weight': 'normal',
81            'text-shadow': '2px 2px black'
82        });
83        $("#statepar" + id).html("State: Transferring");
84    }
85    else if (task.State == "3") {//CALCULATING
86        $("#statepar" + id).css({
87            'color': 'white',
88            'font-weight': 'normal'
89        });
90        $("#statepar" + id).html("State: Calculating");
91    }
92    else if (task.State == "4") {//PAUSED
93        $("#statepar" + id).css({
94            'color': 'white',
95            'font-weight': 'normal'
96        });
97        $("#statepar" + id).html("State: Paused");
98        //Able to restart
99        document.getElementById("restarter" + id).style.display = "";
100        document.getElementById("restarterbtn" + id).disabled = false;
101        document.getElementById("restarterbtn" + id).value = "Restart task";
102    }
103    else if (task.State == "5") {//FINISHED
104        $("#statepar" + id).css({
105            'color': '#009900',
106            'font-weight': '900',
107            'text-shadow': '1px 1px black'
108        });
109        $("#statepar" + id).html("State: Finished");
110        var datf = new Date(task.StateLog[task.StateLog.length - 1].DateTime);
111        $("#lastupdpar" + id).html("Finished: " + datf.toUTCString());
112    }
113    else if (task.State == "6") {//ABORTED
114        $("#statepar" + id).css({
115            'color': '#e60000',
116            'font-weight': '900',
117            'text-shadow': '1px 1px black'
118        });
119        $("#statepar" + id).html("State: Aborted");
120        //Able to restart
121        document.getElementById("restarter" + id).style.display = "";
122        document.getElementById("restarterbtn" + id).disabled = false;
123        document.getElementById("restarterbtn" + id).value = "Restart task";
124    }
125    else if (task.State == "7") {//FAILED
126        $("#statepar" + id).css({
127            'color': '#e60000',
128            'font-weight': '900',
129            'text-shadow': '1px 1px black'
130        });
131        $("#statepar" + id).html("State: Failed");
132        //Able to restart
133        document.getElementById("restarter" + id).style.display = "";
134        document.getElementById("restarterbtn" + id).disabled = false;
135        document.getElementById("restarterbtn" + id).value = "Restart task";
136    }
137
138    //execution time
139    $("#executionpar" + id).html(task.ExecutionTime + " executed");
140    //exception
141    if (task.StateLog[task.StateLog.length - 1].Exception != null)
142        if (task.StateLog[task.StateLog.length - 1].Exception != "") {
143            $("#exceptionpar" + id).html("Exception: " + task.StateLog[task.StateLog.length - 1].Exception)
144            $("#exceptionpar" + id).css({
145                'color': '#e60000',
146                'font-weight': '700',
147                'text-shadow': '1px 1px black'
148            });
149        }
150        else if (task.State == "6") {
151            $("#exceptionpar" + id).html("Task is aborted.")
152            $("#exceptionpar" + id).css({
153                'color': '#e65c00',
154                'font-weight': '700',
155                'text-shadow': '1px 1px black'
156            });
157        }
158        else {
159            $("#exceptionpar" + id).html("No exceptions");
160            $("#exceptionpar" + id).css({
161                'color': 'white',
162                'text-shadow': '2px 2px black'
163            });
164        }
165    else {
166        $("#exceptionpar" + id).html("No exceptions");
167        $("#exceptionpar" + id).css({
168            'color': 'white',
169            'text-shadow': '2px 2px black'
170        });
171    }
172    //state changes
173    $("#statechangespar" + id).html("Statelogs: " + task.StateLog.length);
174    //graph title
175    var dat1 = new Date(task.StateLog[0].DateTime);
176    var dat2 = new Date(task.StateLog[task.StateLog.length - 1].DateTime);
177    $("#graphtitle" + id).html(
178        "From " + dat1.toUTCString() +
179        "<br/> to " + dat2.toUTCString()
180        );
181}
Note: See TracBrowser for help on using the repository browser.