-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy_stack.html
More file actions
310 lines (262 loc) · 9.78 KB
/
deploy_stack.html
File metadata and controls
310 lines (262 loc) · 9.78 KB
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta charset="utf-8" />
<title>Workspaces - BocaBaton</title>
<meta name="description" content="Workspaces" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<!-- bootstrap & fontawesome -->
<link rel="stylesheet" href="assets/css/bootstrap.min.css" />
<link rel="stylesheet" href="assets/font-awesome/4.2.0/css/font-awesome.min.css" />
<!-- page specific plugin styles -->
<!-- text fonts -->
<!-- ace styles -->
<link rel="stylesheet" href="assets/css/ace.min.css" class="ace-main-stylesheet" id="main-ace-style" />
<!--[if lte IE 9]>
<link rel="stylesheet" href="assets/css/ace-part2.min.css" class="ace-main-stylesheet" />
<![endif]-->
<!--[if lte IE 9]>
<link rel="stylesheet" href="assets/css/ace-ie.min.css" />
<![endif]-->
<!-- inline styles related to this page -->
<link rel="stylesheet" href="assets/css/bootstrap-tagsinput.css" />
<!-- BPMN-JS styles -->
<link rel="stylesheet" href="assets/js/bpmn-js/assets/diagram-js.css" />
<link rel="stylesheet" href="assets/js/bpmn-js/assets/bpmn-font/css/bpmn-embedded.css" />
<!-- ace settings handler -->
<script src="assets/js/ace-extra.min.js"></script>
<!-- HTML5shiv and Respond.js for IE8 to support HTML5 elements and media queries -->
<!--[if lte IE 8]>
<script src="assets/js/html5shiv.min.js"></script>
<script src="assets/js/respond.min.js"></script>
<![endif]-->
<style>
.highlight:not(.djs-connection) .djs-visual > :nth-child(1) {
fill: green !important; /* color elements as green */
}
</style>
</head>
<body class="no-skin">
Overriding Environment:
<input type="text" id="jeju-env" value="key1=value1,key2=value2" data-role="tagsinput" />
<hr>
<div id="bpmn_container">
<div id="bpmn"></div>
</div>
<hr>
<div align="center">
<button id="launch-btn" class="btn btn-primary">
<i class="ace-icon fa fa-fighter-jet align-top bigger-125"></i>
Launch</button>
</div>
<!-- basic scripts -->
<!--[if !IE]> -->
<script src="assets/js/jquery.2.1.1.min.js"></script>
<!-- <![endif]-->
<!--[if IE]>
<script src="assets/js/jquery.1.11.1.min.js"></script>
<![endif]-->
<!--[if !IE]> -->
<script type="text/javascript">
window.jQuery || document.write("<script src='assets/js/jquery.min.js'>"+"<"+"/script>");
</script>
<!-- <![endif]-->
<!--[if IE]>
<script type="text/javascript">
window.jQuery || document.write("<script src='assets/js/jquery1x.min.js'>"+"<"+"/script>");
</script>
<![endif]-->
<script type="text/javascript">
if('ontouchstart' in document.documentElement) document.write("<script src='assets/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
</script>
<script src="assets/js/bootstrap.min.js"></script>
<!-- page specific plugin scripts -->
<script src="assets/js/jquery-ui.min.js"></script>
<script src="assets/js/url.min.js"></script>
<script src="assets/js/bootstrap-tagsinput.js"><./script>
<!-- ace scripts -->
<script src="assets/js/ace-elements.min.js"></script>
<script src="assets/js/ace.min.js"></script>
<!-- BPMN-JS scripts -->
<script src="assets/js/bpmn-js/bpmn-viewer.js"></script>
<!-- inline scripts related to this page -->
<script type="text/javascript">
var api_server = "";
var token = "";
jQuery(function($) {
//initiate dataTables plugin
// about login
if (localStorage.getItem('token') !== null) {
token = localStorage.getItem('token');
console.log(token);
}
else {
window.location = "login.html"
}
api_server = localStorage.getItem('api_server');
var user_id = localStorage.getItem('user_id');
$('#logout').click(function() {
localStorage.removeItem('token');
window.location = "login.html?target=iaas.html";
});
if(token) {}
else {window.location = "login.html?target=iaas.html"}
console.log(token);
console.log(api_server);
var user_name = $.ajax({
type: "GET",
headers: {'X-Auth-Token':token},
url: api_server.concat("/users/").concat(user_id),
contentType: "application/json",
success: function(resultData) {
console.log(resultData);
$('#user-name').text(resultData.user_id);
},
});
// end of login
});
jQuery(document).ready(function () {
var contentType ="application/x-www-form-urlencoded; charset=utf-8";
if(window.XDomainRequest)
contentType = "text/plain";
//$('#stackDeploy').modal('modal-body').css({'height': '600px'})
// TODO: clean before create
$("#bpmn_container div").remove();
$('<div id="bpmn"></div>').appendTo('#bpmn_container');
// BPMN
package_id= url('?package_id');
var stack_id;
console.log(package_id);
var BpmnViewer = window.BpmnJS;
var viewer = new BpmnViewer({ container: $('#bpmn'), height: 500 });
function openFromUrl(bpmn_url) {
$.ajax({
url: bpmn_url,
type: 'GET',
success: function(xml) {
// BPMN
viewer.importXML(xml, function(err) {
if (err) {
console.error(err);
} else {
viewer.get('canvas').zoom('fit-viewport');
}
})
}
});
}
var bpmn_url;
$.ajax({
type: "GET",
async: false,
headers: {'X-Auth-Token':token},
url: api_server.concat("/catalog/packages/").concat(package_id),
contentType: "application/json",
success: function(resultData) {
bpmn_url = resultData.template;
console.log(bpmn_url);
openFromUrl(bpmn_url);
},
});
// Stack environment
var tag_input = $('#form-field-tags');
try{
tag_input.tag(
{
placeholder:tag_input.attr('placeholder'),
//enable typeahead by specifying the source array
source: ace.vars['US_STATES'],//defined in ace.js >> ace.enable_search_ahead
/**
//or fetch data from database, fetch those that match "query"
source: function(query, process) {
$.ajax({url: 'remote_source.php?q='+encodeURIComponent(query)})
.done(function(result_items){
process(result_items);
});
}
*/
}
)
//programmatically add a new
var $tag_obj = $('#form-field-tags').data('tag');
$tag_obj.add('key1=value1');
}
catch(e) {
//display a textarea for old IE, because it doesn't support this plugin or another one I tried!
tag_input.after('<textarea id="'+tag_input.attr('id')+'" name="'+tag_input.attr('name')+'" rows="3">'+tag_input.val()+'</textarea>').remove();
//$('#form-field-tags').autosize({append: "\n"});
}
// Launch Stack
$( "#launch-btn" ).click(function() {
var env = $("#jeju-env").tagsinput("items");
console.log(env);
var env2 = {}
for (var i in env) {
var res = env[i].split("=");
env2[res[0]] = res[1];
}
env2['TOKEN'] = token;
$.ajax({
type: "POST",
headers: {'X-Auth-Token':token},
url: api_server.concat("/catalog/stacks"),
data: JSON.stringify({package_id: package_id, env: {jeju: env2}}),
contentType: "application/json",
success: function(resultData) {
console.log(resultData);
stack_id = resultData.stack_id;
setInterval(checkState, 10000);
},
});
});
function markNodeColor(workflow_state) {
$.ajax({
url: bpmn_url,
type: 'GET',
dataType: 'xml',
success: function(data) {
// Parse XML
var xml_node = $('bpmn\\:process, process', data);
console.log(data);
console.log(xml_node);
var nodes = xml_node.find('bpmn\\:serviceTask, serviceTask');
console.log(nodes);
for (var key in workflow_state) {
console.log(key);
var state = workflow_state[key];
console.log(state);
if (state == 'running') {
// mark running color
console.log(nodes.length);
for (i = 0; i < nodes.length; i++) {
console.log(nodes[i].attributes[1])
console.log(key)
if (nodes[i].attributes[1].nodeValue == key) {
console.log("draw");
viewer.get('canvas').addMarker(nodes[i].id, 'highlight');
}
}
}
}
}
});
}
// State loop
function checkState() {
$.ajax({
type: "POST",
headers: {'X-Auth-Token':token},
url: api_server.concat('/catalog/stacks/').concat(stack_id).concat('/env'),
data: JSON.stringify({'get':'workflow_state'}),
contentType: 'application/json',
success: function(resultData) {
console.log(resultData);
markNodeColor(resultData);
}
});
}
});
</script>
</body>
</html>