-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
217 lines (198 loc) · 10.8 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<!DOCTYPE html>
<html>
<head>
<title>WebGME executor</title>
<script src="http://code.jquery.com/jquery-1.11.1.min.js">
</script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link href="styles/worker.css" rel="stylesheet">
<!-- script src="./lib/moment.min.js" type="text/javascript" -->
<!-- script src="./lib/angular-file-upload-shim.min.js" type="text/javascript" -->
<script src="https://code.angularjs.org/1.2.18/angular.js" type="text/javascript"></script>
<script src="https://code.angularjs.org/1.2.18/angular-route.min.js" type="text/javascript"></script>
<!--script src="/lib/angular-momentjs.js" type="text/javascript" -->
<!-- link rel="stylesheet" href="./lib/font-awesome/css/font-awesome.min.css" -->
<!-- script src="./lib/route-styles.js" type="text/javascript" -->
<!-- script src="./lib/ui-bootstrap-tpls-0.11.0.min.js" type="text/javascript" -->
<!-- script src="./lib/angular-file-upload.js" type="text/javascript" -->
<script>
// getScript require.js
//$(document).ready(function () {config.forEach(
function addWebGMEConnection(webGMEUrl, parameters) {
var url = nodeRequire('url');
var dataControllerName = "ExecutorWorkerController_" + url.parse(webGMEUrl).hostname;
var workerView = $('\
<div class="container">\
<div class="row">\
<h1 class="hostname"><span></span> <small></small></h1>\
<div class="col-md-12 status">Connecting...</div>\
</div>\
<div class="row controller">\
<div class="col-md-12">\
<ul>\
<li data-ng-repeat="job in jobs">\
<span class="hash">{{job.hash}}</span>\
<i class="badge" data-ng-class="{\'alert-success\': job.status === \'SUCCESS\', \'alert-danger\': job.status.indexOf(\'FAILED\') === 0, \'alert-info\': job.status === \'CREATED\'}">{{job.status}}</i>\
<span>{{job.name}}</span>\
<span>{{job.url}}</span>\
<span>{{job.resultHash}}</span>\
</li>\
</ul>\
</div>\
</div>\
</div>').appendTo($("#main"));
workerView.find(".hostname span").text(url.parse(webGMEUrl).hostname);
workerView.find(".hostname small").text(webGMEUrl);
workerView.find(".controller").attr("data-ng-controller", dataControllerName);
var statusDiv = workerView.find(".status");
$.ajax({
url: webGMEUrl + "/common/lib/requirejs/require.js",
cache: true,
dataType: "script",
success: function () {
var requirejs = window.requirejs;
delete window.requirejs; // don't share requirejs state across WebGMEs, they may require different versions
requirejs([webGMEUrl + "/bin/getconfig.js"], function (gmeConfig) {
requirejs.config({
baseUrl: webGMEUrl + '/',
paths: {
//"eventDispatcher": 'common/EventDispatcher',
//"notificationManager": 'js/NotificationManager',
"clientUtil": 'js/util',
//"loaderCircles": "js/Loader/LoaderCircles",
//"loaderProgressBar": "js/Loader/LoaderProgressBar",
"superagent": "common/lib/superagent/superagent",
"q": "common/lib/q/q",
"debug": "common/lib/debug/debug",
"core": "common/core",
//"codemirror": 'lib/codemirror/codemirror.amd',
//"jquery-csszoom": 'lib/jquery/jquery.csszoom',
"blob": "common/blob",
"executor": "common/executor"
// "jszip": 'lib/jszip/jszip',
},
nodeRequire: nodeRequire
});
// FIXME ugly hack for node-webkit
var node_modules = ['fs', 'stream', 'path', 'child_process', 'minimatch', 'crypto', 'util', 'mime', 'http', 'https', 'events', 'rimraf' /*, 'superagent'*/];
node_modules.forEach(function (module_name) {
requirejs.s.contexts._.defined[module_name] = nodeRequire(module_name);
});
global.define = define;
require('./src/ExecutorWorker')
require('./src/ExecutorWorkerController')
require('./src/ExecutorOutputQueue')
delete global.define;
var worker;
requirejs(['executor-worker/ExecutorWorker', 'executor/JobInfo', 'executor-worker/ExecutorWorkerController', 'client/logger', 'debug'], function (ExecutorWorker, JobInfo, ExecutorWorkerController, Logger, _debug) {
_debug.enable('*');
var webGMEPort = url.parse(webGMEUrl).port || (url.parse(webGMEUrl).protocol === 'https:' ? 443 : 80),
logger = Logger.create('Index', gmeConfig.client.log);
logger.debug('Logger created');
worker = new ExecutorWorker({ server: url.parse(webGMEUrl).hostname, serverPort: webGMEPort,
httpsecure: url.parse(webGMEUrl).protocol === 'https:', sessionId: undefined,
availableProcessesContainer: availableProcessesContainer,
executorNonce: parameters.executorNonce,
logger: logger.fork('ExecutorWorker')});
worker.queryWorkerAPI(function (err, response) {
var refreshPeriod = 60 * 1000;
var callback = function (err, response) {
if (err) {
statusDiv.css('color', 'white');
statusDiv.css('backgroundColor', 'red');
statusDiv.text(err);
} else {
statusDiv.css('color', 'white');
statusDiv.css('backgroundColor', 'green');
statusDiv.text('OK');
}
if (response && response.refreshPeriod) {
refreshPeriod = response.refreshPeriod;
}
var timeoutID = window.setTimeout(function () {
worker.queryWorkerAPI(callback);
}, refreshPeriod);
};
callback(err, response);
});
var WebGMEApp = angular.module('WebGMEApp', ['ngRoute']);
WebGMEApp.value("worker", worker);
// WebGMEApp.value("worker", null);
WebGMEApp.controller(dataControllerName, ExecutorWorkerController);
/*WebGMEApp.config(['$routeProvider',
function ($routeProvider) {
$routeProvider.
when('/executor', {
templateUrl: 'app/workspace/views/WorkspaceView.html',
// css: 'app/workspace/styles/Workspace.css',
controller: 'ExecutorWorkerController'
}).
otherwise({
redirectTo: '/executor'
});
}]);
*/
angular.bootstrap(workerView, ['WebGMEApp']);
// TODO: authentication?
});
});
},
error: function(jqxhr, settings, exception) {
// FIXME this doesn't fire
statusDiv.text("Failed to connect");
}});
};
var webGMEUrls = Object.create(null);
var maxConcurrentJobs = 1;
var availableProcessesContainer = { availableProcesses: maxConcurrentJobs }; // shared among all ExecutorWorkers
var nodeRequire = require;
(function() {
var fs = nodeRequire('fs');
function readConfig() {
var config = [ "http://localhost:8888" ];
try {
var configJSON = fs.readFileSync('config.json', {encoding: 'utf8'});
config = JSON.parse(configJSON);
if (Array.isArray(config)) {
var oldConfig = config;
config = {};
oldConfig.forEach(function (webGMEUrl) {
config[webGMEUrl] = {};
});
} else if (typeof(config) === "string") {
config = { config: {} };
} else {
}
} catch (e) {
if (e.code !== "ENOENT") {
throw e;
}
}
Object.getOwnPropertyNames(config).forEach(function (key) {
var webGMEUrl;
if (key.indexOf("http") === 0) {
webGMEUrl = key;
if (Object.prototype.hasOwnProperty.call(webGMEUrls, webGMEUrl)) {
} else {
webGMEUrls[webGMEUrl] = addWebGMEConnection(webGMEUrl, config[webGMEUrl]);
}
// TODO: handle removing URL
} else if (key === "maxConcurrentJobs") {
availableProcessesContainer.availableProcesses += config[maxConcurrentJobs] - maxConcurrentJobs;
maxConcurrentJobs = config[maxConcurrentJobs];
} else {
console.log("Unknown configuration key " + key);
}
});
}
$(document).ready(readConfig);
fs.watch("config.json", function() { setTimeout(readConfig, 200); }); // setTimeout: likely handle O_TRUNC of config.json (though `move config.json.tmp config.json` is preferred)
})();
</script>
</head>
<body>
<div class="container" id="main">
</div>
</body>
</html>