-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoozie-live-editor.html
461 lines (395 loc) · 22.2 KB
/
oozie-live-editor.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
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
<html>
<head>
<meta charset="UTF-8">
<link rel=stylesheet href="css/codemirror.css">
<script src="js/codemirror.js"></script>
<script src="js/xml.js"></script>
<script src="js/format_code.js"></script>
<script src="js/mermaid.js"></script>
<script src="js/oozie_node.js"></script>
<script src="js/create_default_oozie_nodes.js"></script>
<script src="js/random_functions.js"></script>
<script>mermaid.initialize({startOnLoad:true});</script>
<link type="text/css" href="css/base.css" rel="stylesheet" />
<script>
//Global
var node_list = [];
var flag_actions = true;
var allkeys = true;
var updated_copy_of_text_area = "";
var absolute_first_node = null;
docReady(function() { // DOM is loaded and ready for manipulation
//----------------------------------------------------
//Code Mirror
//----------------------------------------------------
document.getElementById("xml_text_editor").value = vkbeautify.xml(document.getElementById("xml_text_editor").value);
var code_mirror_text_area = CodeMirror.fromTextArea(document.getElementById("xml_text_editor"), {
mode: 'application/xml',
theme: 'xq-dark',
lineNumbers: true,
lineWrapping: true,
readOnly: false,
//cursorBlinkRate: -1
});
//save text before edits
updated_copy_of_text_area = code_mirror_text_area.getValue();
//----------------------------------------------------
//On key update text and graph
//----------------------------------------------------
document.body.onkeyup = function(event) {
event.preventDefault();
if (allkeys) {
if(event.keyCode == 219 || event.keyCode == 221){ //prevent user from blowing up graph
// give some visual feadback
var toaster = document.getElementById("snackbar");
toaster.textContent = "Avoid using: { } [ ] for node names (breaks the DAG)";
toaster.className = "show";
setTimeout(function(){ toaster.className = toaster.className.replace("show", ""); }, 5000);
}
//reset node list and console output:
var node_list = [];
consoleCleanup();
code_mirror_text_area.save();
var textArea = code_mirror_text_area.getValue();
updated_copy_of_text_area = textArea;
var arrayOfLines = textArea.split("\n"); // text area
var count_node = 0;
var first_time = false;
var oozie_node = new OozieNode();
var add_node_to_list = false;
var last_node_name_was = "";
var first_node_name;
var end_node_found = false;
var decision_node_fully_initialized = false;
var last_error_node = null;
var all_error_nodes_foud = [];
var fork_node_fully_initialized = false;
var start_parsing_forks = false;
for(var i = 1;i < arrayOfLines.length;i++){
//get lines
var xml = parseXml(arrayOfLines[i]);
var node_name_parsed = xml.documentElement.nodeName;
if(arrayOfLines[i].includes("<html>") || arrayOfLines[i].includes("<body>")){continue;} //skip regular DOM elements
//alertOrConsole(node_name_parsed,false);
//console.log(arrayOfLines[i]);
//check for decision node
if(node_name_parsed.includes("decision")){
oozie_node.setDecisionNode(true);
oozie_node.setNodeID(xml.documentElement.getAttribute("name"));
}
if(oozie_node.isDecisionNode() && decision_node_fully_initialized == false){
if(arrayOfLines[i].includes("case to=")){ //case decision
var decision_case = xml.documentElement.getAttribute("to");
oozie_node.addToDecisionCaseNodesList(decision_case); //adds to list
}
if(arrayOfLines[i].includes("path start=")){ //path decision
var decision_case = xml.documentElement.getAttribute("start");
oozie_node.addToDecisionCaseNodesList(decision_case); //adds to list
}
if(arrayOfLines[i].includes("default to=")){ //default decision
oozie_node.setDecisionDefaultNextNode(xml.documentElement.getAttribute("to"));
decision_node_fully_initialized = true;
}
}
if(node_name_parsed.includes("fork")){
oozie_node.setForkNode(true);
oozie_node.setNodeID(xml.documentElement.getAttribute("name"));
start_parsing_forks = true;
fork_node_fully_initialized = false;
//alert("fork node found, booleans are:\n fork_node_fully_initialized:" +fork_node_fully_initialized + "\n start_parsing_forks: " + start_parsing_forks);
}
if(oozie_node.isForkNode() && fork_node_fully_initialized == false && start_parsing_forks){
if(arrayOfLines[i].includes("path start=")){ //path decision
var forked_path_to_join = xml.documentElement.getAttribute("start");
oozie_node.addToForkNodesList(forked_path_to_join); //adds to list
//alert("Adding fork to fork node: " + forked_path_to_join);
}
if(arrayOfLines[i].includes("join name=")){ //path decision
var forked_path_to_join = xml.documentElement.getAttribute("name");
oozie_node.addToForkNodesList(forked_path_to_join); //adds to list
//alert("Adding fork to fork node: " + forked_path_to_join);
}
}
//check for error node (could be the end node)
if(node_name_parsed.includes("error")){
var error_node = xml.documentElement.getAttribute("to");
oozie_node.setErrorNode(error_node);
all_error_nodes_foud.push(error_node);
// end_node_found = true;
}
//check for next node
if(node_name_parsed.includes("ok")){
oozie_node.setNextNode(xml.documentElement.getAttribute("to"));
}
//check for the real end node
if(arrayOfLines[i].includes("</action>")){
// alertOrConsole(arrayOfLines[i],true);
end_node_found = true;
}
if(add_node_to_list && end_node_found && oozie_node.isDecisionNode() == false){
node_list.push(oozie_node);
console.log("Adding new node --------------------------");
oozie_node.printNodeInfo();
oozie_node = new OozieNode(); //zero out for next node
add_node_to_list = false; //reset flag
end_node_found = false; //reset flag
}else if(oozie_node.isDecisionNode() && decision_node_fully_initialized){
node_list.push(oozie_node);
console.log("Adding new node --------------------------");
oozie_node.printNodeInfo();
oozie_node = new OozieNode(); //zero out for next node
add_node_to_list = false; //reset flag
end_node_found = false; //reset flag
decision_node_fully_initialized = false //reset flag for mutiple decision nodes in a row
}
//we found the first node
if(node_name_parsed.includes("start")){
first_node_name = xml.documentElement.getAttribute("to");
absolute_first_node = first_node_name;
if(first_node_name){
first_time = true;
continue;
}
}
if(node_name_parsed.includes("action")){ //we found an action node
if(start_parsing_forks){ //get out of fork check, we arn't in a fork anymore
node_list.push(oozie_node);
console.log("Adding new node --------------------------");
oozie_node.printNodeInfo();
oozie_node = new OozieNode(); //zero out for next node
add_node_to_list = false; //reset flag
end_node_found = false; //reset flag
decision_node_fully_initialized = false //reset flag for mutiple decision nodes in a row
start_parsing_forks = false;
fork_node_fully_initialized = true;
}
var action_node_name = xml.documentElement.getAttribute("name");
if(action_node_name){
//first node check, let's check to make sure it's the same as the start node:
if(oozie_node.getNodeID().includes(first_node_name) && first_time == true){
count_node = 1;
first_time = false;
oozie_node.setIsFirstNode(true);
oozie_node.setNodeID(action_node_name);
oozie_node.setPreviousNode(last_node_name_was);
oozie_node.setNodeNumber(count_node);
add_node_to_list = true;
last_node_name_was = action_node_name;
continue;
}else{ //not first node:
count_node++;
oozie_node.setIsFirstNode(false);
oozie_node.setNodeID(action_node_name);
oozie_node.setPreviousNode(last_node_name_was);
oozie_node.setNodeNumber(count_node);
add_node_to_list = true;
last_node_name_was = action_node_name;
continue;
}
}
}
}
try {
updateGraph(node_list, false); //no error
} catch (e) { //stomp error and switch render type
updateGraph(node_list, true); //error
// give some visual feadback
var toaster = document.getElementById("snackbar");
toaster.textContent = "There is an error with your workflow, please check all nodes";
toaster.className = "show";
setTimeout(function(){ toaster.className = toaster.className.replace("show", ""); }, 5000);
console.log(e);
}
}
}
//XML Parser
function parseXml(xmlStr) {
return new DOMParser().parseFromString(xmlStr, "text/xml");
}
function updateGraph(node_list, error_flag){
//----------------------------------
//ReRender Mermaid
//----------------------------------
var mermaid_diagram = new CreateMermaidDiagram(error_flag);
mermaid_diagram.setDiagram_txt(node_list);
document.getElementById("mermaid_diagram_id").innerText=mermaid_diagram.getDiagram_txt()
document.getElementById("mermaid_diagram_id").removeAttribute('data-processed');
mermaid.init(undefined, document.getElementById("mermaid_diagram_id"));
}
});
//-------------------------------------------------------------
//Mermaid Create Diagram For v1.2
//-------------------------------------------------------------
function CreateMermaidDiagram(error_flag){
this.diagram_txt;
//getters:
this.getDiagram_txt = function(){
return this.diagram_txt;
};
//setters:
this.setDiagram_txt = function(node_list){
//node_list = null;
console.log("--------------------------------")
//--------------------------------------------------
//Need to cleanup this section... spaghetti for now
//--------------------------------------------------
var diagram_txt_tmp = "";
if(node_list!=null || node_list[0].getNodeID() == null){
//Add normal path data
for(let id = 0; id < node_list.length; id++){
if(node_list[id].isDecisionNode()){//add decision node
if(id==0 && error_flag){
diagram_txt_tmp += "graph TD; "; // add header TODO: clean this up
}else if(id == 0 && error_flag == false){
diagram_txt_tmp += "stateDiagram [*] --> " + absolute_first_node + " "; // add header TODO: clean this up
}
if(error_flag){//is error decision
//----------------------
for(let dn_count = 0; dn_count < node_list[id].getDecisionCaseNodesList().length; dn_count++){ //multi decision node cases
var desc_node = node_list[id].getDecisionCaseNodesList();
diagram_txt_tmp += node_list[id].getNodeID() + " --> " + desc_node[dn_count] + "; "; //space neeeded TODO: move this to oozie bean
}
diagram_txt_tmp += node_list[id].getNodeID() + " --> " + node_list[id].getDecisionDefaultNextNode().replace(/\s+/g, '_') + "; "; //TODO: move this to oozie bean
//----------------------
}else{// not error decision
for(let dn_count = 0; dn_count < node_list[id].getDecisionCaseNodesList().length; dn_count++){ //multi decision node cases
var desc_node = node_list[id].getDecisionCaseNodesList();
diagram_txt_tmp += node_list[id].getNodeID() + " --> " + desc_node[dn_count] + " "; //space neeeded TODO: move this to oozie bean
} //end for loop
diagram_txt_tmp += node_list[id].getNodeID() + " --> " + node_list[id].getDecisionDefaultNextNode().replace(/\s+/g, '_') + " "; //TODO: move this to oozie bean
}//end else not an error decision node
} else if(node_list[id].isForkNode()){ //fork node
if(id==0 && error_flag){
diagram_txt_tmp += "graph TD; "; // add header TODO: clean this up
}else if(id == 0 && error_flag == false){
diagram_txt_tmp += "stateDiagram [*] --> " + absolute_first_node + " "; // add header TODO: clean this up
}
for(let fork_count = 0; fork_count < node_list[id].getForkNodeList().length; fork_count++){ //multi decision node cases
var desc_node = node_list[id].getForkNodeList();
diagram_txt_tmp += node_list[id].getNodeID() + " --> " + desc_node[fork_count] + " "; //space neeeded TODO: move this to oozie bean
} //end for loop
}else{//add normal node
if(id == 0){ //first
if(error_flag){
diagram_txt_tmp += "graph TD; "; // add header TODO: clean this up
diagram_txt_tmp += node_list[id].getDefaultNodeStructureForErrorGraph()+"; ";
}
if(error_flag==false){
diagram_txt_tmp += "stateDiagram [*] --> " + node_list[id].getNodeID() + " "; // add header TODO: clean this up
if(node_list[id].getDefaultNodeStructure().includes("end")){
diagram_txt_tmp += node_list[id].getDefaultNodeStructure().replace('end', 'endlabel[end] ');
}else{
diagram_txt_tmp += node_list[id].getDefaultNodeStructure();
}
}
}else{ //not a first node
if(error_flag){
diagram_txt_tmp += node_list[id].getDefaultNodeStructureForErrorGraph()+"; ";
}else{
diagram_txt_tmp += node_list[id].getDefaultNodeStructure()+"";
}
//console.log(node_list[id].getDefaultNodeStructure());
}
if(node_list[id].getErrorNode()!=null){ //add normal node error link node
if(error_flag){
diagram_txt_tmp += node_list[id].getErrorNodeStructureForErrorGraph()+"; ";
}else{
if(node_list[id].getErrorNodeStructure().includes("end")){
diagram_txt_tmp += node_list[id].getErrorNodeStructure().replace('end', 'endlabel[end] ');
}else{
diagram_txt_tmp += node_list[id].getErrorNodeStructure()
}
}
}
}
}
console.log("-----Final Mermaid String-------")
console.log(diagram_txt_tmp);
this.diagram_txt = diagram_txt_tmp;
console.log("--------------------------------")
}else{ //on node error... show a funny demo
console.log("!!!!!!!!!!!!!!-----Node List Empty Mermaid String-------!!!!!!!!!!!!!!!")
var diagram_txt_tmp =
"stateDiagram\
[*] --> Hey\
Hey --> [*]\
Hey --> Its\
Its --> Bug\
Its --> A\
Bug --> [*]";
this.diagram_txt = diagram_txt_tmp;
}
};
}
</script>
</head>
<!---prod: <body id = "main_section"> -->
<!-- for testing--> <body id = "main_section">
<div class="topnav">
<a class="active" href="#Editor">Editor</a>
<a href="#Export" onclick="exportXMLToFile()">Export Workflow</a>
<a href="#about" onclick="aboutOLE()">About</a>
<a target="_blank" rel="noopener noreferrer" href="https://oozie.apache.org/docs/4.3.1/">Oozie Doc</a>
<a href="#about" >|</a>
<a href="#about" id= "email_node_create_btn"onclick="copyToClipboard('email','email_node_create_btn')">Email Node</a>
<a href="#about" id= "hive_node_create_btn"onclick="copyToClipboard('hive','hive_node_create_btn')">Hive Node</a>
<a href="#about" id= "pig_node_create_btn"onclick="copyToClipboard('pig','pig_node_create_btn')">Pig Node</a>
<a href="#about" id= "shell_node_create_btn"onclick="copyToClipboard('shell','shell_node_create_btn')">Shell Node</a>
<a href="#about" id= "sqoop_node_create_btn"onclick="copyToClipboard('sqoop','sqoop_node_create_btn')">Sqoop Node</a>
<a href="#about" id= "distcp_node_create_btn"onclick="copyToClipboard('distcp','distcp_node_create_btn')">DistCp Node</a>
<a href="#about" id= "decision_node_create_btn"onclick="copyToClipboard('decision','decision_node_create_btn')">Decision Node</a>
<a href="#about" >|</a>
<a href="#about" id= "end_node_create_btn"onclick="copyToClipboard('end','end_node_create_btn')">End Node</a>
</div>
<!-----------FLOW CHART START------------------->
<div id="container">
<div id="left-container">
<!-----------XML EDITOR START------------------->
<textarea id="xml_text_editor">
<workflow-app
xmlns='uri:oozie:workflow:0.3' name='shell-wf'>
<start to="start_node"/>
<!---------------------------------------------->
<!-- START TYPING XML -->
<!---------------------------------------------->
</workflow-app>
</textarea>
</div>
<div id="right-container">
<!-- new mermaid diagram -->
<hr>
<div style="text-align:center; width:100%">
<div class="mermaid" id="mermaid_diagram_id">
stateDiagram
[*] --> Start
Start --> [*]
Start --> DecisionNode
DecisionNode --> Start
DecisionNode --> XML
DecisionNode --> Typing
XML --> [*]
</div>
</div>
</div>
<div id="log"></div>
</div>
<a id="scroll_top_top_btn" href="#" onclick="animateToTop(event)">Scroll Up</a>
<script>
mermaid.initialize({
// theme: 'forest', // haaaa noooo! lol
// themeCSS: '.node rect { fill: red; }',
themeCSS: ".node rect { fill: red; }",
useMaxWidth:false,
securityLevel: 'loose',
logLevel: 3,
flowchart: { curve: 'basis' },
gantt: { axisFormat: '%m/%d/%Y' },
sequence: { actorMargin: 50 },
// sequenceDiagram: { actorMargin: 300 } // deprecated
});
</script>
</body>
</body>
<!-- The actual snackbar -->
<div id="snackbar"></div>
</html>