Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 16674 was 13860, checked in by jlodewyc, 9 years ago

#2582 RC2 migration fixed. OKB query implemented. Preparing for OKB manager

File size: 7.3 KB
Line 
1
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21
22
23var hubber = $.connection.jobUpdaterHub;
24$(function () {
25  //  $.connection.hub.logging = true;
26    var v = document.getElementById("userId").innerHTML;
27    $.connection.hub.qs = { 'userid': v };
28    $.connection.hub.start().done(function () {
29        hubber.server.initConnection();
30        redrawMain();
31    });
32    //processes updates task info for each individual task
33    hubber.client.processData = function (id, data, name) {
34        var obj = JSON.parse(data);
35        editTaskData(id, obj);
36
37        saveData(id, obj.StateLog, name);
38        console.log("#UPDATED " + id);
39    }
40    //processes updated job info
41    hubber.client.processJobData = function (calc, fin) {
42        editJobData(calc, fin);
43    }
44    //Called when server is done with request
45    hubber.client.requestDone = function () {
46        if (document.getElementById("refreshtogg").checked) {
47            setTimeout(function () {
48                hubber.server.updateAll();
49                console.log("#REFRESH ALL");
50
51            }, 5000 + (dataCollection.length * 500));
52        }
53    }
54})
55
56//Toggles the refresh button. ON is refresh every 5 sec, OFF is no refresh
57function autoRefresh() {
58    if (document.getElementById("refreshtogg").checked)
59        hubber.server.updateAll();
60
61}
62//Restarts an aborted, paused or failed task
63function restart(id) {
64    document.getElementById("restarterbtn" + id).disabled = true;
65    document.getElementById("restarterbtn" + id).value = "Sending restart request...";
66    hubber.server.restartTask(id);
67}
68//Writes the new job info to the page
69function editJobData(c, f) {
70    $("#jobcalculating").html("Calculating: " + c);
71    $("#jobfinished").html("Finished: " + f);
72}
73//Writes updated task info to the page
74function editTaskData(id, task) {
75    //lastupdate
76    if (task.LastHeartbeat != null) {
77        var dat = new Date(task.LastHeartbeat);
78        $("#lastupdpar" + id).html("Last update: " + dat.toUTCString());
79    }
80    else
81        $("#lastupdpar" + id).html("No updates yet");
82    //task restarter
83    document.getElementById("restarter" + id).style.display = "none";
84    //state
85    if (task.State == "0") {//OFFLINE
86        $("#statepar" + id).css({
87            'color': 'gray',
88            'font-weight': 'normal'
89        });
90        $("#statepar" + id).html("State: Offline");
91    }
92    else if (task.State == "1") {//WAITING
93        $("#statepar" + id).css({
94            'color': 'white',
95            'font-weight': 'normal'
96        });
97        $("#statepar" + id).html("State: Waiting");
98    }
99    else if (task.State == "2") {//TRANSFERRING
100        $("#statepar" + id).css({
101            'color': 'white',
102            'font-weight': 'normal',
103            'text-shadow': '2px 2px black'
104        });
105        $("#statepar" + id).html("State: Transferring");
106    }
107    else if (task.State == "3") {//CALCULATING
108        $("#statepar" + id).css({
109            'color': 'white',
110            'font-weight': 'normal'
111        });
112        $("#statepar" + id).html("State: Calculating");
113    }
114    else if (task.State == "4") {//PAUSED
115        $("#statepar" + id).css({
116            'color': 'white',
117            'font-weight': 'normal'
118        });
119        $("#statepar" + id).html("State: Paused");
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 == "5") {//FINISHED
126        $("#statepar" + id).css({
127            'color': '#009900',
128            'font-weight': '900',
129            'text-shadow': '1px 1px black'
130        });
131        $("#statepar" + id).html("State: Finished");
132        var datf = new Date(task.StateLog[task.StateLog.length - 1].DateTime);
133        $("#lastupdpar" + id).html("Finished: " + datf.toUTCString());
134    }
135    else if (task.State == "6") {//ABORTED
136        $("#statepar" + id).css({
137            'color': '#e60000',
138            'font-weight': '900',
139            'text-shadow': '1px 1px black'
140        });
141        $("#statepar" + id).html("State: Aborted");
142        //Able to restart
143        document.getElementById("restarter" + id).style.display = "";
144        document.getElementById("restarterbtn" + id).disabled = false;
145        document.getElementById("restarterbtn" + id).value = "Restart task";
146    }
147    else if (task.State == "7") {//FAILED
148        $("#statepar" + id).css({
149            'color': '#e60000',
150            'font-weight': '900',
151            'text-shadow': '1px 1px black'
152        });
153        $("#statepar" + id).html("State: Failed");
154        //Able to restart
155        document.getElementById("restarter" + id).style.display = "";
156        document.getElementById("restarterbtn" + id).disabled = false;
157        document.getElementById("restarterbtn" + id).value = "Restart task";
158    }
159
160    //execution time
161    $("#executionpar" + id).html(task.ExecutionTime + " executed");
162    //exception
163    if (task.StateLog[task.StateLog.length - 1].Exception != null)
164        if (task.StateLog[task.StateLog.length - 1].Exception != "") {
165            $("#exceptionpar" + id).html("Exception: " + task.StateLog[task.StateLog.length - 1].Exception)
166            $("#exceptionpar" + id).css({
167                'color': '#e60000',
168                'font-weight': '700',
169                'text-shadow': '1px 1px black'
170            });
171        }
172        else if (task.State == "6") {
173            $("#exceptionpar" + id).html("Task is aborted.")
174            $("#exceptionpar" + id).css({
175                'color': '#e65c00',
176                'font-weight': '700',
177                'text-shadow': '1px 1px black'
178            });
179        }
180        else {
181            $("#exceptionpar" + id).html("No exceptions");
182            $("#exceptionpar" + id).css({
183                'color': 'white',
184                'text-shadow': '2px 2px black'
185            });
186        }
187    else {
188        $("#exceptionpar" + id).html("No exceptions");
189        $("#exceptionpar" + id).css({
190            'color': 'white',
191            'text-shadow': '2px 2px black'
192        });
193    }
194    //state changes
195    $("#statechangespar" + id).html("Statelogs: " + task.StateLog.length);
196    //graph title
197    var dat1 = new Date(task.StateLog[0].DateTime);
198    var dat2 = new Date(task.StateLog[task.StateLog.length - 1].DateTime);
199    $("#graphtitle" + id).html(
200        "From " + dat1.toUTCString() +
201        "<br/> to " + dat2.toUTCString()
202        );
203}
Note: See TracBrowser for help on using the repository browser.