workflow.js 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366
  1. // Licensed to Cloudera, Inc. under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. Cloudera, Inc. licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. // adding missing .filter for IE8
  17. if (!('filter' in Array.prototype)) {
  18. Array.prototype.filter= function(filter, that /*opt*/) {
  19. var other= [], v;
  20. for (var i=0, n= this.length; i<n; i++)
  21. if (i in this && filter.call(that, v= this[i], i, this))
  22. other.push(v);
  23. return other;
  24. };
  25. }
  26. // Since knockout maps arrays without calling "update" nor "create"
  27. // Provide a JSON string that will be parsed in custom 'create' and 'update' functions.
  28. var normalize_model_fields = (function() {
  29. var FIELDS = ['parameters', 'job_properties', 'files', 'archives', 'prepares', 'params',
  30. 'deletes', 'mkdirs', 'moves', 'chmods', 'touchzs'];
  31. function fn(node_model) {
  32. $.each(FIELDS, function(index, field) {
  33. if (field in node_model && $.isArray(node_model[field])) {
  34. node_model[field] = JSON.stringify(node_model[field]);
  35. }
  36. });
  37. }
  38. return fn;
  39. })();
  40. // Parse JSON if it is JSON and appropriately map.
  41. // Apply subscriber to each mapping.
  42. var map_params = function(options, subscribe) {
  43. options.data = ($.type(options.data) == "string") ? $.parseJSON(options.data) : options.data;
  44. if ($.isArray(options.data)) {
  45. var mapping = ko.mapping.fromJS(options.data);
  46. $.each(mapping(), function(index, value) {
  47. subscribe(value);
  48. });
  49. return mapping;
  50. } else {
  51. var mapping = ko.mapping.fromJS(options.data, {});
  52. subscribe(mapping);
  53. return mapping;
  54. }
  55. };
  56. /**
  57. * Registry of models
  58. * - Each model should have an ID attribute.
  59. */
  60. var RegistryModule = function($) {
  61. var module = function() {
  62. var self = this;
  63. self.nodes = {};
  64. module.prototype.initialize.apply(self, arguments);
  65. return self;
  66. };
  67. $.extend(module.prototype, {
  68. // Normal stuff
  69. initialize: function() {},
  70. toString: function() {
  71. var self = this;
  72. var s = $.map(self.nodes, function(node) {
  73. return node.id();
  74. }).join();
  75. return s;
  76. },
  77. add: function(id, node) {
  78. var self = this;
  79. $(self).trigger('registry:add');
  80. self.nodes[String(id)] = node;
  81. },
  82. remove: function(id) {
  83. var self = this;
  84. $(self).trigger('registry:remove');
  85. delete self.nodes[String(id)];
  86. },
  87. get: function(id) {
  88. var self = this;
  89. return self.nodes[id];
  90. },
  91. clear: function() {
  92. var self = this;
  93. delete self.nodes;
  94. self.nodes = {};
  95. }
  96. });
  97. return module;
  98. };
  99. var Registry = RegistryModule($);
  100. /**
  101. * Modal Control
  102. * Displays a single node in a modal window of your choosing.
  103. * Make sure to update the 'context' member and 'template' members.
  104. * IMPORTANT: Use 'setTemplate', then 'show'.
  105. */
  106. var ModalModule = function($, ko) {
  107. var module = function(modal, template) {
  108. var self = this;
  109. self.el = self.modal = $(modal);
  110. self.context = ko.observable();
  111. self.template = ko.observable(template || '');
  112. self.bound = false;
  113. };
  114. module.prototype.show = function(context) {
  115. var self = this;
  116. if (context) {
  117. self.context(context);
  118. }
  119. ko.applyBindings(self, self.modal[0]);
  120. self.modal.modal('show');
  121. };
  122. module.prototype.hide = function() {
  123. var self = this;
  124. self.el.modal('hide');
  125. };
  126. module.prototype.setTemplate = function(template) {
  127. var self = this;
  128. ko.cleanNode(self.modal[0]);
  129. self.template( template );
  130. };
  131. module.prototype.recenter = function(offset_x, offset_y) {
  132. var self = this;
  133. var MARGIN = 10; // pixels around the modal
  134. var modalContentHeight = (($(window).height() - MARGIN*2) -
  135. (self.modal.find(".modal-header").outerHeight() + self.modal.find(".modal-header").outerHeight())) - 20;
  136. self.modal.css("width", ($(window).width() - MARGIN*2)+"px");
  137. self.modal.find(".modal-content").css("max-height", modalContentHeight+"px").css("height", modalContentHeight+"px");
  138. var top = ( ($(window).height() - self.modal.outerHeight(false)) / 2 );
  139. var left = ( ($(window).width() - self.modal.outerWidth(false)) / 2 );
  140. if (top < 0) {
  141. top = 0;
  142. }
  143. if (left < 0) {
  144. left = 0;
  145. }
  146. top += offset_y || 0;
  147. left += offset_x || 0;
  148. self.modal.css({top: top +'px', left: left+'px'});
  149. };
  150. module.prototype.addDecorations = function () {
  151. $(".popover").remove();
  152. $("input[name='job_xml']:not(.pathChooser)").addClass("pathChooser").after(getFileBrowseButton($("input[name='job_xml']:not(.pathChooser)")));
  153. $("input[name='jar_path']").addClass("pathChooser").after(getFileBrowseButton($("input[name='jar_path']")));
  154. $("input[name='script_path']").addClass("pathChooser").after(getFileBrowseButton($("input[name='script_path']")));
  155. $("input[name='command']").addClass("pathChooser").after(getFileBrowseButton($("input[name='command']")));
  156. if (typeof CodeMirror !== 'undefined' && $("textarea[name='xml']").length > 0) {
  157. $("textarea[name='xml']").hide();
  158. var xmlEditor = $("<textarea>").attr("id", "tempXml").prependTo($("textarea[name='xml']").parent())[0];
  159. var codeMirror = CodeMirror(function (elt) {
  160. xmlEditor.parentNode.replaceChild(elt, xmlEditor);
  161. }, {
  162. value:$("textarea[name='xml']").val(),
  163. lineNumbers:true,
  164. autoCloseTags:true
  165. });
  166. codeMirror.on("update", function () {
  167. ko.dataFor($("textarea[name='xml']")[0]).xml(codeMirror.getValue());
  168. });
  169. }
  170. $("*[rel=popover]").popover({
  171. placement:'left',
  172. trigger:'hover'
  173. });
  174. }
  175. return module;
  176. };
  177. var Modal = ModalModule($, ko);
  178. var ModelModule = function($) {
  179. var module = function(attrs) {
  180. var self = this;
  181. $.extend(self, attrs);
  182. module.prototype.initialize.apply(self, arguments);
  183. return self;
  184. };
  185. $.extend(module.prototype, {
  186. // Normal stuff
  187. initialize: function(){},
  188. toString: function() {
  189. var self = this;
  190. return JSON.stringify(self, null, '\t');
  191. }
  192. });
  193. return module;
  194. };
  195. var WorkflowModel = ModelModule($);
  196. $.extend(WorkflowModel.prototype, {
  197. id: 0,
  198. name: '',
  199. description: '',
  200. start: 0,
  201. end: 0,
  202. schema_version: 0.4,
  203. deployment_dir: '',
  204. is_shared: true,
  205. parameters: '[]',
  206. job_xml: ''
  207. });
  208. var NodeModel = ModelModule($);
  209. $.extend(NodeModel.prototype, {
  210. id: 0,
  211. name: '',
  212. description: '',
  213. node_type: '',
  214. workflow: 0,
  215. child_links: []
  216. });
  217. var ForkModel = ModelModule($);
  218. $.extend(ForkModel.prototype, {
  219. id: 0,
  220. name: '',
  221. description: '',
  222. node_type: 'fork',
  223. workflow: 0,
  224. child_links: []
  225. });
  226. var DecisionModel = ModelModule($);
  227. $.extend(DecisionModel.prototype, {
  228. id: 0,
  229. name: '',
  230. description: '',
  231. node_type: 'decision',
  232. workflow: 0,
  233. child_links: []
  234. });
  235. var DistCPModel = ModelModule($);
  236. $.extend(DistCPModel.prototype, {
  237. id: 0,
  238. name: '',
  239. description: '',
  240. node_type: 'distcp',
  241. workflow: 0,
  242. job_properties: '[]',
  243. prepares: '[]',
  244. job_xml: '',
  245. params: '[]',
  246. child_links: []
  247. });
  248. var MapReduceModel = ModelModule($);
  249. $.extend(MapReduceModel.prototype, {
  250. id: 0,
  251. name: '',
  252. description: '',
  253. node_type: 'mapreduce',
  254. workflow: 0,
  255. files: '[]',
  256. archives: '[]',
  257. job_properties: '[]',
  258. jar_path: '',
  259. prepares: '[]',
  260. job_xml: '',
  261. child_links: []
  262. });
  263. var StreamingModel = ModelModule($);
  264. $.extend(StreamingModel.prototype, {
  265. id: 0,
  266. name: '',
  267. description: '',
  268. node_type: 'streaming',
  269. workflow: 0,
  270. files: '[]',
  271. archives: '[]',
  272. job_properties: '[]',
  273. mapper: '',
  274. reducer: '',
  275. child_links: []
  276. });
  277. var JavaModel = ModelModule($);
  278. $.extend(JavaModel.prototype, {
  279. id: 0,
  280. name: '',
  281. description: '',
  282. node_type: 'java',
  283. workflow: 0,
  284. files: '[]',
  285. archives: '[]',
  286. job_properties: '[]',
  287. jar_path: '',
  288. prepares: '[]',
  289. job_xml: '',
  290. main_class: '',
  291. args: '',
  292. java_opts: '',
  293. child_links: []
  294. });
  295. var PigModel = ModelModule($);
  296. $.extend(PigModel.prototype, {
  297. id: 0,
  298. name: '',
  299. description: '',
  300. node_type: 'pig',
  301. workflow: 0,
  302. files: '[]',
  303. archives: '[]',
  304. job_properties: '[]',
  305. prepares: '[]',
  306. job_xml: '',
  307. params: '[]',
  308. script_path: '',
  309. child_links: []
  310. });
  311. var HiveModel = ModelModule($);
  312. $.extend(HiveModel.prototype, {
  313. id: 0,
  314. name: '',
  315. description: '',
  316. node_type: 'hive',
  317. workflow: 0,
  318. files: '[]',
  319. archives: '[]',
  320. job_properties: '[]',
  321. prepares: '[]',
  322. job_xml: '',
  323. params: '[]',
  324. script_path: '',
  325. child_links: []
  326. });
  327. var SqoopModel = ModelModule($);
  328. $.extend(SqoopModel.prototype, {
  329. id: 0,
  330. name: '',
  331. description: '',
  332. node_type: 'sqoop',
  333. workflow: 0,
  334. files: '[]',
  335. archives: '[]',
  336. job_properties: '[]',
  337. prepares: '[]',
  338. job_xml: '',
  339. params: '[]',
  340. script_path: '',
  341. child_links: []
  342. });
  343. var ShellModel = ModelModule($);
  344. $.extend(ShellModel.prototype, {
  345. id: 0,
  346. name: '',
  347. description: '',
  348. node_type: 'shell',
  349. workflow: 0,
  350. files: '[]',
  351. archives: '[]',
  352. job_properties: '[]',
  353. prepares: '[]',
  354. job_xml: '',
  355. params: '[]',
  356. command: '',
  357. capture_output: false,
  358. child_links: []
  359. });
  360. var SshModel = ModelModule($);
  361. $.extend(SshModel.prototype, {
  362. id: 0,
  363. name: '',
  364. description: '',
  365. node_type: 'ssh',
  366. workflow: 0,
  367. user: '',
  368. host: '',
  369. params: '[]',
  370. command: '',
  371. capture_output: false,
  372. child_links: []
  373. });
  374. var FsModel = ModelModule($);
  375. $.extend(FsModel.prototype, {
  376. id: 0,
  377. name: '',
  378. description: '',
  379. node_type: 'fs',
  380. workflow: 0,
  381. deletes: '[]',
  382. mkdirs: '[]',
  383. moves: '[]',
  384. chmods: '[]',
  385. touchzs: '[]',
  386. child_links: []
  387. });
  388. var EmailModel = ModelModule($);
  389. $.extend(EmailModel.prototype, {
  390. id: 0,
  391. name: '',
  392. description: '',
  393. node_type: 'email',
  394. workflow: 0,
  395. to: '',
  396. cc: '',
  397. subject: '',
  398. body: '',
  399. child_links: []
  400. });
  401. var SubWorkflowModel = ModelModule($);
  402. $.extend(SubWorkflowModel.prototype, {
  403. id: 0,
  404. name: '',
  405. description: '',
  406. node_type: 'subworkflow',
  407. workflow: 0,
  408. sub_workflow: 0,
  409. propagate_configuration: true,
  410. job_properties: '[]',
  411. child_links: []
  412. });
  413. var GenericModel = ModelModule($);
  414. $.extend(GenericModel.prototype, {
  415. id: 0,
  416. name: '',
  417. description: '',
  418. node_type: 'generic',
  419. workflow: 0,
  420. xml: '',
  421. child_links: []
  422. });
  423. function nodeModelChooser(node_type) {
  424. switch(node_type) {
  425. case 'mapreduce':
  426. return MapReduceModel;
  427. case 'streaming':
  428. return StreamingModel;
  429. case 'java':
  430. return JavaModel;
  431. case 'pig':
  432. return PigModel;
  433. case 'hive':
  434. return HiveModel;
  435. case 'sqoop':
  436. return SqoopModel;
  437. case 'shell':
  438. return ShellModel;
  439. case 'ssh':
  440. return SshModel;
  441. case 'distcp':
  442. return DistCPModel;
  443. case 'fs':
  444. return FsModel;
  445. case 'email':
  446. return EmailModel;
  447. case 'subworkflow':
  448. return SubWorkflowModel;
  449. case 'generic':
  450. return GenericModel;
  451. case 'fork':
  452. return ForkModel;
  453. case 'decision':
  454. return DecisionModel;
  455. default:
  456. return NodeModel;
  457. }
  458. }
  459. /**
  460. * Import node module
  461. * Assists in the conversion of a jobsub node.
  462. * Assists in the population of available nodes.
  463. */
  464. var ImportNodeModule = function($) {
  465. var module = function(options) {
  466. var self = this;
  467. self.workflow = options.workflow;
  468. self.available_nodes = [];
  469. self.url = ko.computed(function() {
  470. return '/oozie/workflows/' + options.workflow.id() + '/jobsub/actions'
  471. });
  472. module.prototype.initialize.apply(self, arguments);
  473. return self;
  474. };
  475. $.extend(module.prototype, {
  476. initialize: function(options) {
  477. var self = this;
  478. if (options.nodes) {
  479. $.each(options.nodes, function(index, node) {
  480. self.available_nodes.push(node);
  481. });
  482. }
  483. },
  484. getAvailableNodes: function() {
  485. var self = this;
  486. return self.available_nodes;
  487. },
  488. loadAvailableNodes: function(options) {
  489. var self = this;
  490. var request = $.extend({
  491. url: self.url(),
  492. dataType: 'json',
  493. type: 'GET',
  494. success: $.noop,
  495. error: $.noop,
  496. }, options || {});
  497. $.ajax(request);
  498. },
  499. convertNode: function(options, jobsub_id) {
  500. var self = this;
  501. var options = options || {};
  502. var request = $.extend({
  503. url: self.url(),
  504. type: 'POST',
  505. data: { 'jobsub_id': jobsub_id },
  506. success: $.noop,
  507. error: $.noop
  508. }, options);
  509. $.ajax(request);
  510. },
  511. });
  512. return module;
  513. };
  514. var ImportNode = ImportNodeModule($);
  515. /**
  516. * ID Generator
  517. * Generate a new ID starting from 1.
  518. * - Accepts a prefix that will be prepended like so: <prefix>:<id number>
  519. */
  520. var IdGeneratorModule = function($) {
  521. return function(options) {
  522. var self = this;
  523. $.extend(self, options);
  524. self.counter = 1;
  525. self.nextId = function() {
  526. return ((self.prefix) ? self.prefix + ':' : '') + self.counter++;
  527. };
  528. };
  529. };
  530. var IdGenerator = IdGeneratorModule($);
  531. var IdGeneratorTable = {
  532. mapreduce: new IdGenerator({prefix: 'mapreduce'}),
  533. streaming: new IdGenerator({prefix: 'streaming'}),
  534. java: new IdGenerator({prefix: 'java'}),
  535. pig: new IdGenerator({prefix: 'pig'}),
  536. hive: new IdGenerator({prefix: 'hive'}),
  537. sqoop: new IdGenerator({prefix: 'sqoop'}),
  538. shell: new IdGenerator({prefix: 'shell'}),
  539. ssh: new IdGenerator({prefix: 'ssh'}),
  540. distcp: new IdGenerator({prefix: 'distcp'}),
  541. fs: new IdGenerator({prefix: 'fs'}),
  542. email: new IdGenerator({prefix: 'email'}),
  543. subworkflow: new IdGenerator({prefix: 'subworkflow'}),
  544. generic: new IdGenerator({prefix: 'generic'}),
  545. fork: new IdGenerator({prefix: 'fork'}),
  546. decision: new IdGenerator({prefix: 'decision'}),
  547. join: new IdGenerator({prefix: 'join'}),
  548. decisionend: new IdGenerator({prefix: 'decisionend'}),
  549. kill: new IdGenerator({prefix: 'kill'})
  550. };
  551. var NodeModule = function($, IdGeneratorTable) {
  552. var META_LINKS = ['related', 'default', 'error'];
  553. var linkTypeChooser = function(parent, child) {
  554. if (child.node_type() == 'kill') {
  555. return 'error';
  556. }
  557. switch(parent.node_type()) {
  558. case 'start':
  559. return (child.node_type() == 'end') ? 'related' : 'to';
  560. case 'fork':
  561. return (child.node_type() == 'join') ? 'related' : 'start';
  562. case 'decision':
  563. return (child.node_type() == 'decisionend') ? 'related' : 'start';
  564. case 'join':
  565. case 'decisionend':
  566. return 'to';
  567. default:
  568. return 'ok';
  569. };
  570. };
  571. var module = function(workflow, model, registry) {
  572. var self = this;
  573. self.map(model);
  574. self.links = ko.computed(function() {
  575. var links = self.child_links().filter(function(element, index, arr) {
  576. return $.inArray(element.name(), META_LINKS) == -1;
  577. });
  578. return links;
  579. });
  580. self.meta_links = ko.computed(function() {
  581. var links = self.child_links().filter(function(element, index, arr) {
  582. return $.inArray(element.name(), META_LINKS) != -1;
  583. });
  584. return links;
  585. });
  586. self._workflow = workflow;
  587. self.registry = registry;
  588. self.children = ko.observableArray([]);
  589. self.model = model;
  590. var errors = {};
  591. for(var key in model) {
  592. switch(key) {
  593. case 'child_links':
  594. case 'node_ptr':
  595. case 'initialize':
  596. case 'toString':
  597. break;
  598. default:
  599. errors[key] = [];
  600. break;
  601. }
  602. }
  603. self.errors = ko.mapping.fromJS(errors);
  604. self.edit_template = model.node_type + 'EditTemplate';
  605. switch(model.node_type) {
  606. case 'start':
  607. self.view_template = ko.observable('startTemplate');
  608. break;
  609. case 'kill':
  610. case 'end':
  611. self.view_template = ko.observable('emptyTemplate');
  612. break;
  613. case 'fork':
  614. self.view_template = ko.observable('forkTemplate');
  615. break;
  616. case 'join':
  617. self.view_template = ko.observable('joinTemplate');
  618. break;
  619. case 'decision':
  620. self.view_template = ko.observable('decisionTemplate');
  621. break;
  622. case 'decisionend':
  623. self.view_template = ko.observable('decisionEndTemplate');
  624. break;
  625. default:
  626. self.view_template = ko.observable('nodeTemplate');
  627. break;
  628. }
  629. // Data manipulation
  630. if ('job_properties' in model) {
  631. self.addProp = function() {
  632. var prop = { name: ko.observable(""), value: ko.observable("") };
  633. prop.name.subscribe(function(value) {
  634. self.job_properties.valueHasMutated();
  635. });
  636. prop.value.subscribe(function(value) {
  637. self.job_properties.valueHasMutated();
  638. });
  639. self.job_properties.push(prop);
  640. // $(".propKey:last").each(addAutoComplete);
  641. };
  642. self.removeProp = function(val) {
  643. self.job_properties.remove(val);
  644. };
  645. }
  646. if ('files' in model) {
  647. self.addFile = function() {
  648. var prop = { name: ko.observable(""), dummy: ko.observable("") };
  649. prop.name.subscribe(function(value) {
  650. self.files.valueHasMutated();
  651. });
  652. prop.dummy.subscribe(function(value) {
  653. self.files.valueHasMutated();
  654. });
  655. self.files.push(prop);
  656. };
  657. self.removeFile = function(val) {
  658. self.files.remove(val);
  659. };
  660. }
  661. if ('archives' in model) {
  662. self.addArchive = function() {
  663. var prop = { name: ko.observable(""), dummy: ko.observable("") };
  664. prop.name.subscribe(function(value) {
  665. self.archives.valueHasMutated();
  666. });
  667. prop.dummy.subscribe(function(value) {
  668. self.archives.valueHasMutated();
  669. });
  670. self.archives.push(prop);
  671. };
  672. self.removeArchive = function(val) {
  673. self.archives.remove(val);
  674. };
  675. }
  676. if ('params' in model) {
  677. self.addParam = function() {
  678. var prop = { value: ko.observable(""), type: ko.observable("param") };
  679. prop.value.subscribe(function(value) {
  680. self.params.valueHasMutated();
  681. });
  682. prop.type.subscribe(function(value) {
  683. self.params.valueHasMutated();
  684. });
  685. self.params.push(prop);
  686. };
  687. self.addArgument = function() {
  688. var prop = { value: ko.observable(""), type: ko.observable("argument") };
  689. prop.value.subscribe(function(value) {
  690. self.params.valueHasMutated();
  691. });
  692. prop.type.subscribe(function(value) {
  693. self.params.valueHasMutated();
  694. });
  695. self.params.push(prop);
  696. };
  697. self.addArg = function() {
  698. var prop = { value: ko.observable(""), type: ko.observable("arg") };
  699. prop.value.subscribe(function(value) {
  700. self.params.valueHasMutated();
  701. });
  702. prop.type.subscribe(function(value) {
  703. self.params.valueHasMutated();
  704. });
  705. self.params.push(prop);
  706. };
  707. self.addEnvVar = function() {
  708. var prop = { value: ko.observable(""), type: ko.observable("env-var") };
  709. prop.value.subscribe(function(value) {
  710. self.params.valueHasMutated();
  711. });
  712. prop.type.subscribe(function(value) {
  713. self.params.valueHasMutated();
  714. });
  715. self.params.push(prop);
  716. };
  717. self.removeParam = function(val) {
  718. self.params.remove(val);
  719. };
  720. }
  721. if ('prepares' in model) {
  722. self.addPrepareDelete = function() {
  723. var prop = { value: ko.observable(""), type: ko.observable("delete") };
  724. prop.value.subscribe(function(value) {
  725. self.prepares.valueHasMutated();
  726. });
  727. prop.type.subscribe(function(value) {
  728. self.prepares.valueHasMutated();
  729. });
  730. self.prepares.push(prop);
  731. };
  732. self.addPrepareMkdir = function() {
  733. var prop = { value: ko.observable(""), type: ko.observable("mkdir") };
  734. prop.value.subscribe(function(value) {
  735. self.prepares.valueHasMutated();
  736. });
  737. prop.type.subscribe(function(value) {
  738. self.prepares.valueHasMutated();
  739. });
  740. self.prepares.push(prop);
  741. };
  742. self.removePrepare = function(val) {
  743. self.prepares.remove(val);
  744. };
  745. }
  746. if ('deletes' in model) {
  747. self.addDelete = function() {
  748. var prop = { name: ko.observable("") };
  749. prop.name.subscribe(function(value) {
  750. self.deletes.valueHasMutated();
  751. });
  752. self.deletes.push(prop);
  753. };
  754. self.removeDelete = function(val) {
  755. self.deletes.remove(val);
  756. };
  757. }
  758. if ('mkdirs' in model) {
  759. self.addMkdir = function() {
  760. var prop = { name: ko.observable("") };
  761. prop.name.subscribe(function(value) {
  762. self.mkdirs.valueHasMutated();
  763. });
  764. self.mkdirs.push(prop);
  765. };
  766. self.removeMkdir = function(val) {
  767. self.mkdirs.remove(val);
  768. };
  769. }
  770. if ('moves' in model) {
  771. self.addMove = function() {
  772. var prop = { source: ko.observable(""), destination: ko.observable("") };
  773. prop.source.subscribe(function(value) {
  774. self.moves.valueHasMutated();
  775. });
  776. prop.destination.subscribe(function(value) {
  777. self.moves.valueHasMutated();
  778. });
  779. self.moves.push(prop);
  780. };
  781. self.removeMove = function(val) {
  782. self.moves.remove(val);
  783. };
  784. }
  785. if ('chmods' in model) {
  786. self.addChmod = function() {
  787. var prop = { path: ko.observable(""), permissions: ko.observable(""), recursive: ko.observable("") };
  788. prop.path.subscribe(function(value) {
  789. self.chmods.valueHasMutated();
  790. });
  791. prop.permissions.subscribe(function(value) {
  792. self.chmods.valueHasMutated();
  793. });
  794. prop.recursive.subscribe(function(value) {
  795. self.chmods.valueHasMutated();
  796. });
  797. self.chmods.push(prop);
  798. };
  799. self.removeChmod = function(val) {
  800. self.chmods.remove(val);
  801. };
  802. }
  803. if ('touchzs' in model) {
  804. self.addTouchz = function() {
  805. var prop = { name: ko.observable("") };
  806. prop.name.subscribe(function(value) {
  807. self.touchzs.valueHasMutated();
  808. });
  809. self.touchzs.push(prop);
  810. };
  811. self.removeTouchz = function(val) {
  812. self.touchzs.remove(val);
  813. };
  814. }
  815. self.initialize.apply(self, arguments);
  816. return self;
  817. };
  818. $.extend(module.prototype, {
  819. // Data.
  820. children: null,
  821. model: null,
  822. // Normal stuff
  823. /**
  824. * Called when creating a new node
  825. */
  826. initialize: function(workflow, model, registry) {},
  827. toString: function() {
  828. return '';
  829. },
  830. /**
  831. * Fetches registry
  832. */
  833. getRegistry: function() {
  834. return registry;
  835. },
  836. /**
  837. * Maps a model to self
  838. * Called when creating a new node before any thing else
  839. */
  840. map: function(model) {
  841. var self = this;
  842. // @see http://knockoutjs.com/documentation/plugins-mapping.html
  843. var mapping = ko.mapping.fromJS(model, {
  844. ignore: ['initialize', 'toString'],
  845. job_properties: {
  846. create: function(options) {
  847. var parent = options.parent;
  848. var subscribe = function(mapping) {
  849. mapping.name.subscribe(function(value) {
  850. parent.job_properties.valueHasMutated();
  851. });
  852. mapping.value.subscribe(function(value) {
  853. parent.job_properties.valueHasMutated();
  854. });
  855. };
  856. return map_params(options, subscribe);
  857. },
  858. update: function(options) {
  859. var parent = options.parent;
  860. var subscribe = function(mapping) {
  861. mapping.name.subscribe(function(value) {
  862. parent.job_properties.valueHasMutated();
  863. });
  864. mapping.value.subscribe(function(value) {
  865. parent.job_properties.valueHasMutated();
  866. });
  867. };
  868. return map_params(options, subscribe);
  869. }
  870. },
  871. files: {
  872. create: function(options) {
  873. return map_params(options, function() {});
  874. },
  875. update: function(options) {
  876. return map_params(options, function() {});
  877. }
  878. },
  879. archives: {
  880. create: function(options) {
  881. var parent = options.parent;
  882. var subscribe = function(mapping) {
  883. mapping.name.subscribe(function(value) {
  884. parent.archives.valueHasMutated();
  885. });
  886. mapping.dummy.subscribe(function(value) {
  887. parent.archives.valueHasMutated();
  888. });
  889. };
  890. return map_params(options, subscribe);
  891. },
  892. update: function(options) {
  893. var parent = options.parent;
  894. var subscribe = function(mapping) {
  895. mapping.name.subscribe(function(value) {
  896. parent.archives.valueHasMutated();
  897. });
  898. mapping.dummy.subscribe(function(value) {
  899. parent.archives.valueHasMutated();
  900. });
  901. };
  902. return map_params(options, subscribe);
  903. }
  904. },
  905. params: {
  906. create: function(options) {
  907. var parent = options.parent;
  908. var subscribe = function(mapping) {
  909. mapping.value.subscribe(function(value) {
  910. parent.params.valueHasMutated();
  911. });
  912. mapping.type.subscribe(function(value) {
  913. parent.params.valueHasMutated();
  914. });
  915. };
  916. return map_params(options, subscribe);
  917. },
  918. update: function(options) {
  919. var parent = options.parent;
  920. var subscribe = function(mapping) {
  921. mapping.value.subscribe(function(value) {
  922. parent.params.valueHasMutated();
  923. });
  924. mapping.type.subscribe(function(value) {
  925. parent.params.valueHasMutated();
  926. });
  927. };
  928. return map_params(options, subscribe);
  929. }
  930. },
  931. prepares: {
  932. create: function(options) {
  933. var parent = options.parent;
  934. var subscribe = function(mapping) {
  935. mapping.value.subscribe(function(value) {
  936. parent.prepares.valueHasMutated();
  937. });
  938. mapping.type.subscribe(function(value) {
  939. parent.prepares.valueHasMutated();
  940. });
  941. };
  942. return map_params(options, subscribe);
  943. },
  944. update: function(options) {
  945. var parent = options.parent;
  946. var subscribe = function(mapping) {
  947. mapping.value.subscribe(function(value) {
  948. parent.prepares.valueHasMutated();
  949. });
  950. mapping.type.subscribe(function(value) {
  951. parent.prepares.valueHasMutated();
  952. });
  953. };
  954. return map_params(options, subscribe);
  955. }
  956. },
  957. deletes: {
  958. create: function(options) {
  959. return map_params(options, function() {});
  960. },
  961. update: function(options) {
  962. return map_params(options, function() {});
  963. }
  964. },
  965. mkdirs: {
  966. create: function(options) {
  967. return map_params(options, function() {});
  968. },
  969. update: function(options) {
  970. return map_params(options, function() {});
  971. }
  972. },
  973. moves: {
  974. create: function(options) {
  975. var parent = options.parent;
  976. var subscribe = function(mapping) {
  977. mapping.source.subscribe(function(value) {
  978. parent.moves.valueHasMutated();
  979. });
  980. mapping.destination.subscribe(function(value) {
  981. parent.moves.valueHasMutated();
  982. });
  983. };
  984. return map_params(options, subscribe);
  985. },
  986. update: function(options) {
  987. var parent = options.parent;
  988. var subscribe = function(mapping) {
  989. mapping.source.subscribe(function(value) {
  990. parent.moves.valueHasMutated();
  991. });
  992. mapping.destination.subscribe(function(value) {
  993. parent.moves.valueHasMutated();
  994. });
  995. };
  996. return map_params(options, subscribe);
  997. }
  998. },
  999. chmods: {
  1000. create: function(options) {
  1001. var parent = options.parent;
  1002. var subscribe = function(mapping) {
  1003. mapping.path.subscribe(function(value) {
  1004. parent.chmods.valueHasMutated();
  1005. });
  1006. mapping.permissions.subscribe(function(value) {
  1007. parent.chmods.valueHasMutated();
  1008. });
  1009. mapping.recursive.subscribe(function(value) {
  1010. parent.chmods.valueHasMutated();
  1011. });
  1012. };
  1013. return map_params(options, subscribe);
  1014. },
  1015. update: function(options) {
  1016. var parent = options.parent;
  1017. var subscribe = function(mapping) {
  1018. mapping.path.subscribe(function(value) {
  1019. parent.chmods.valueHasMutated();
  1020. });
  1021. mapping.permissions.subscribe(function(value) {
  1022. parent.chmods.valueHasMutated();
  1023. });
  1024. mapping.recursive.subscribe(function(value) {
  1025. parent.chmods.valueHasMutated();
  1026. });
  1027. };
  1028. return map_params(options, subscribe);
  1029. }
  1030. },
  1031. touchzs: {
  1032. create: function(options) {
  1033. return map_params(options, function() {});
  1034. },
  1035. update: function(options) {
  1036. return map_params(options, function() {});
  1037. }
  1038. },
  1039. });
  1040. $.extend(self, mapping);
  1041. $.each(mapping, function(key, value) {
  1042. var key = key;
  1043. if (ko.isObservable(self[key])) {
  1044. self[key].subscribe(function(value) {
  1045. model[key] = ko.mapping.toJS(value);
  1046. });
  1047. }
  1048. });
  1049. $.each(self.child_links(), function(index, link) {
  1050. var $index = index;
  1051. link.comment.subscribe(function(value) {
  1052. self.model.child_links[$index].comment = value;
  1053. });
  1054. link.child.subscribe(function(value) {
  1055. self.model.child_links[$index].child = value;
  1056. });
  1057. });
  1058. },
  1059. validate: function( ) {
  1060. var self = this;
  1061. var options = {};
  1062. data = $.extend(true, {}, self.model);
  1063. var success = false;
  1064. var request = $.extend({
  1065. url: '/oozie/workflows/' + self._workflow.id() + '/nodes/' + self.node_type() + '/validate',
  1066. type: 'POST',
  1067. data: { node: JSON.stringify(data) },
  1068. success: function(data) {
  1069. ko.mapping.fromJS(data.data, self.errors);
  1070. success = data.status == 0;
  1071. },
  1072. async: false,
  1073. }, options);
  1074. $.ajax(request);
  1075. return success;
  1076. },
  1077. // Hierarchy manipulation.
  1078. /**
  1079. * Append node to self
  1080. * Does not support multiple children.
  1081. * Ensures single child.
  1082. * Ensures no cycles.
  1083. * 1. Finds all children and attaches them to node (cleans node first).
  1084. * 2. Remove all children from self.
  1085. * 3. Attach node to self.
  1086. */
  1087. append: function(node) {
  1088. var self = this;
  1089. // Not fork nor decision nor self
  1090. if ($.inArray(self.node_type(), ['fork', 'decision']) == -1 && node.id() != self.id() && !self.isChild(node)) {
  1091. node.removeAllChildren();
  1092. $.each(self.links(), function(index, link) {
  1093. node.addChild(self.registry.get(link.child()));
  1094. });
  1095. self.removeAllChildren();
  1096. self.addChild(node);
  1097. }
  1098. },
  1099. /**
  1100. * Find all parents of current node
  1101. */
  1102. findParents: function() {
  1103. var self = this;
  1104. var parents = [];
  1105. $.each(self.registry.nodes, function(id, node) {
  1106. $.each(node.links(), function(index, link) {
  1107. if (link.child() == self.id()) {
  1108. parents.push(node);
  1109. }
  1110. });
  1111. });
  1112. return parents;
  1113. },
  1114. /**
  1115. * Find all children of current node
  1116. */
  1117. findChildren: function() {
  1118. var self = this;
  1119. var children = [];
  1120. $.each(self.links(), function(index, link) {
  1121. children.push(self.registry.get(link.child()));
  1122. });
  1123. return children;
  1124. },
  1125. /**
  1126. * Detach current node from the graph
  1127. * 1. Takes children of self node, removes them from self node, and adds them to each parent of self node.
  1128. * 2. The self node is then removed from every parent.
  1129. * 3. Does not support multiple children since we do not automatically fork.
  1130. */
  1131. detach: function() {
  1132. var self = this;
  1133. $.each(self.findParents(), function(index, parent) {
  1134. $.each(self.links(), function(index, link) {
  1135. var node = self.registry.get(link.child());
  1136. parent.replaceChild(self, node);
  1137. });
  1138. });
  1139. $(self).trigger('detached');
  1140. self.removeAllChildren();
  1141. },
  1142. /**
  1143. * Add child
  1144. * Update child links for this node.
  1145. */
  1146. addChild: function(node) {
  1147. var self = this;
  1148. var link = {
  1149. parent: ko.observable(self.id()),
  1150. child: ko.observable(node.id()),
  1151. name: ko.observable(linkTypeChooser(self, node)),
  1152. comment: ko.observable('')
  1153. };
  1154. self.child_links.unshift(link);
  1155. },
  1156. /**
  1157. * Remove child node
  1158. * 1. Find child node link
  1159. * 2. Remove child node link
  1160. */
  1161. removeChild: function(node) {
  1162. var self = this;
  1163. var spliceIndex = -1;
  1164. $.each(self.child_links(), function(index, link) {
  1165. if (link.child() == node.id()) {
  1166. spliceIndex = index;
  1167. }
  1168. });
  1169. if (spliceIndex > -1) {
  1170. self.child_links.splice(spliceIndex, 1);
  1171. }
  1172. return spliceIndex != -1;
  1173. },
  1174. /**
  1175. * Remove all children
  1176. * Removes all children except for related, default, and error links
  1177. * Note: we hold on to related, default, and error links because
  1178. * we have to.
  1179. */
  1180. removeAllChildren: function() {
  1181. var self = this;
  1182. var keep_links = [];
  1183. $.each(self.child_links(), function(index, link) {
  1184. if ($.inArray(link.name(), META_LINKS) > -1) {
  1185. keep_links.push(link);
  1186. }
  1187. });
  1188. self.child_links.removeAll();
  1189. $.each(keep_links, function(index, link) {
  1190. self.child_links.push(link);
  1191. });
  1192. },
  1193. /**
  1194. * Replace child node with another node in the following way:
  1195. * 1. Find child index
  1196. * 2. Remove child index
  1197. * 3. Remove and remember every element after child
  1198. * 4. Add replacement node
  1199. * 5. Add every child that was remembered
  1200. */
  1201. replaceChild: function(child, replacement) {
  1202. var self = this;
  1203. var index = -1;
  1204. $.each(self.child_links(), function(i, link) {
  1205. if (link.child() == child.id()) {
  1206. index = i;
  1207. }
  1208. });
  1209. if (index > -1) {
  1210. self.child_links.splice(index, 1);
  1211. var links = self.child_links.splice(index);
  1212. var link = {
  1213. parent: ko.observable(self.id()),
  1214. child: ko.observable(replacement.id()),
  1215. name: ko.observable(linkTypeChooser(self, replacement)),
  1216. comment: ko.observable(''),
  1217. };
  1218. self.child_links.push(link);
  1219. $.each(links, function(index, link) {
  1220. self.child_links.push(link);
  1221. });
  1222. }
  1223. return index != -1;
  1224. },
  1225. isChild: function(node) {
  1226. var self = this;
  1227. var res = false;
  1228. $.each(self.links(), function(index, link) {
  1229. if (link.child() == node.id()) {
  1230. res = true;
  1231. }
  1232. });
  1233. return res;
  1234. },
  1235. erase: function() {
  1236. var self = this;
  1237. self.registry.remove(self.id());
  1238. }
  1239. });
  1240. return module;
  1241. };
  1242. var Node = NodeModule($, IdGeneratorTable);
  1243. var StartNode = NodeModule($, IdGeneratorTable);
  1244. $.extend(StartNode.prototype, Node.prototype, {
  1245. /**
  1246. * Same as addChild for nodes, except if we reach the end,
  1247. * we add the end node to our child_links in the form of a
  1248. * 'related' link and 'start' link.
  1249. * We should always have a start link in an empty workflow!
  1250. */
  1251. replaceChild: function(child, replacement) {
  1252. var self = this;
  1253. var index = -1;
  1254. $.each(self.child_links(), function(i, link) {
  1255. if (link.child() == child.id()) {
  1256. index = i;
  1257. }
  1258. });
  1259. if (index > -1) {
  1260. self.child_links.splice(index, 1);
  1261. var links = self.child_links.splice(index);
  1262. var link = {
  1263. parent: ko.observable(self.id()),
  1264. child: ko.observable(replacement.id()),
  1265. name: ko.observable('to'),
  1266. comment: ko.observable(''),
  1267. };
  1268. self.child_links.push(link);
  1269. $.each(links, function(index, link) {
  1270. self.child_links.push(link);
  1271. });
  1272. }
  1273. return index != -1;
  1274. },
  1275. });
  1276. var ForkNode = NodeModule($, IdGeneratorTable);
  1277. $.extend(ForkNode.prototype, Node.prototype, {
  1278. // Join nodes are connected through 'related' links
  1279. join: function() {
  1280. var self = this;
  1281. var join = null;
  1282. $.each(self.child_links(), function(index, link) {
  1283. if (link.name() == 'related') {
  1284. join = self.registry.get(link.child());
  1285. }
  1286. });
  1287. return join;
  1288. },
  1289. /**
  1290. * Append a node to the current fork
  1291. * Also adds join node to node.
  1292. * When adding the join node, append will remove all the children from the join!
  1293. * We need to make sure the join remembers its children since append will replace them.
  1294. * NOTE: Cannot append a fork! Use addChild or replaceChild instead!
  1295. */
  1296. append: function(node) {
  1297. var self = this;
  1298. if (node.node_type() != 'fork') {
  1299. var join = self.join();
  1300. if (join.id() != node.id()) {
  1301. var children = join.findChildren();
  1302. self.addChild(node);
  1303. node.append(join);
  1304. // remember children
  1305. $.each(children, function(index, child) {
  1306. join.addChild(child);
  1307. });
  1308. }
  1309. }
  1310. },
  1311. /**
  1312. * Replace child node with another node
  1313. * 1. Remove child if the replacement is related join
  1314. * 2. Apply Node.replaceChild for all other causes
  1315. * NOTE: can assume the only join this fork will ever see is the related join!
  1316. * This is because the related will always be the closest join for children.
  1317. * Also, the operations allowed that would make this all possible: detach, append;
  1318. * are inherently going to remove any other joins if they exist.
  1319. * This is also easier given nodes are contained within Forks!
  1320. */
  1321. replaceChild: function(child, replacement) {
  1322. var self = this;
  1323. var ret = true;
  1324. if (self.join().id() == replacement.id()) {
  1325. ret = self.removeChild(child);
  1326. } else {
  1327. ret = Node.prototype.replaceChild.apply(self, arguments);
  1328. }
  1329. var links = self.links().filter(function(element, index, arr) {
  1330. return self.registry.get(element.child()).node_type() != 'join';
  1331. });
  1332. if (links.length < 2) {
  1333. self.detach();
  1334. self.join().detach();
  1335. self.erase();
  1336. self.join().erase();
  1337. }
  1338. return ret;
  1339. },
  1340. /**
  1341. * Converts fork node into decision node in the following way:
  1342. * 1. Copies contents of current fork node into a new decision node
  1343. * 2. Detach fork node
  1344. * 3. Erase fork node
  1345. * 4. Append decision node to parent
  1346. */
  1347. convertToDecision: function() {
  1348. var self = this;
  1349. var join = self.join();
  1350. var end = null;
  1351. var child = join.findChildren()[0];
  1352. // Replace join with decision end
  1353. var decision_end_model = new NodeModel({
  1354. id: IdGeneratorTable['decisionend'].nextId(),
  1355. node_type: 'decisionend',
  1356. workflow: self.workflow(),
  1357. child_links: join.model.child_links
  1358. });
  1359. var decision_end_node = new Node(self._workflow, decision_end_model, self.registry);
  1360. $.each(decision_end_model.child_links, function(index, link) {
  1361. link.parent = decision_end_model.id;
  1362. });
  1363. var parents = join.findParents();
  1364. $.each(parents, function(index, parent) {
  1365. parent.replaceChild(join, decision_end_node);
  1366. });
  1367. // Replace fork with decision node
  1368. var decision_model = new DecisionModel({
  1369. id: IdGeneratorTable['decision'].nextId(),
  1370. name: self.name(),
  1371. description: self.description(),
  1372. node_type: 'decision',
  1373. workflow: self.workflow(),
  1374. child_links: self.model.child_links
  1375. });
  1376. var default_link = {
  1377. parent: decision_model.id,
  1378. child: self._workflow.end(),
  1379. name: 'default',
  1380. comment: ''
  1381. };
  1382. decision_model.child_links.push(default_link);
  1383. $.each(decision_model.child_links, function(index, link) {
  1384. link.parent = decision_model.id;
  1385. });
  1386. var parents = self.findParents();
  1387. var decision_node = new DecisionNode(self._workflow, decision_model, self.registry);
  1388. decision_node.removeChild(join);
  1389. decision_node.addChild(decision_end_node);
  1390. $.each(parents, function(index, parent) {
  1391. parent.replaceChild(self, decision_node);
  1392. });
  1393. // Get rid of fork and join in registry
  1394. join.erase();
  1395. self.erase();
  1396. // Add decision and decision end to registry
  1397. self.registry.add(decision_node.id(), decision_node);
  1398. self.registry.add(decision_end_node.id(), decision_end_node);
  1399. }
  1400. });
  1401. var DecisionNode = NodeModule($, IdGeneratorTable);
  1402. $.extend(DecisionNode.prototype, ForkNode.prototype, {
  1403. initialize: function(workflow, model, registry) {
  1404. var self = this;
  1405. var registry = registry;
  1406. var end = null;
  1407. },
  1408. end: function() {
  1409. var self = this;
  1410. var end = null;
  1411. $.each(self.child_links(), function(index, link) {
  1412. if (link.name() == 'related') {
  1413. end = self.registry.get(link.child());
  1414. }
  1415. });
  1416. return end;
  1417. },
  1418. /**
  1419. * Append a node to the current decision
  1420. * Also appends end node to node.
  1421. * NOTE: Cannot append a decision! Use addChild or replaceChild instead!
  1422. */
  1423. append: function(node) {
  1424. var self = this;
  1425. var end = self.end();
  1426. if (end.id() == node.id()) {
  1427. return false;
  1428. }
  1429. self.addChild(node);
  1430. node.append(end);
  1431. return true;
  1432. },
  1433. /**
  1434. * Replace child node with another node
  1435. * 1. Remove child if the replacement is end
  1436. * 2. Apply Node.replaceChild for all other causes
  1437. */
  1438. replaceChild: function(child, replacement) {
  1439. var self = this;
  1440. var ret = true;
  1441. var end = self.end();
  1442. if (end && end.id() == replacement.id()) {
  1443. ret = self.removeChild(child);
  1444. } else {
  1445. ret = Node.prototype.replaceChild.apply(self, arguments);
  1446. }
  1447. if (self.links().length < 2) {
  1448. self.detach();
  1449. end.detach();
  1450. self.erase();
  1451. end.erase();
  1452. }
  1453. return ret;
  1454. }
  1455. });
  1456. /**
  1457. * Workflow module
  1458. */
  1459. var WorkflowModule = function($, NodeModelChooser, Node, ForkNode, DecisionNode, IdGeneratorTable) {
  1460. var module = function(options) {
  1461. var self = this;
  1462. // @see http://knockoutjs.com/documentation/plugins-mapping.html
  1463. var mapping = ko.mapping.fromJS(options.model, {
  1464. ignore: ['initialize', 'toString'],
  1465. job_properties: {
  1466. create: function(options) {
  1467. var parent = options.parent;
  1468. var subscribe = function(mapping) {
  1469. mapping.name.subscribe(function(value) {
  1470. parent.job_properties.valueHasMutated();
  1471. });
  1472. mapping.value.subscribe(function(value) {
  1473. parent.job_properties.valueHasMutated();
  1474. });
  1475. };
  1476. return map_params(options, subscribe);
  1477. },
  1478. update: function(options) {
  1479. var parent = options.parent;
  1480. var subscribe = function(mapping) {
  1481. mapping.name.subscribe(function(value) {
  1482. parent.job_properties.valueHasMutated();
  1483. });
  1484. mapping.value.subscribe(function(value) {
  1485. parent.job_properties.valueHasMutated();
  1486. });
  1487. };
  1488. return map_params(options, subscribe);
  1489. }
  1490. },
  1491. parameters: {
  1492. // Will receive individual objects to subscribe.
  1493. // Containing array is mapped automagically
  1494. create: function(options) {
  1495. var parent = options.parent;
  1496. var subscribe = function(mapping) {
  1497. mapping.name.subscribe(function(value) {
  1498. parent.parameters.valueHasMutated();
  1499. });
  1500. mapping.value.subscribe(function(value) {
  1501. parent.parameters.valueHasMutated();
  1502. });
  1503. };
  1504. return map_params(options, subscribe);
  1505. },
  1506. update: function(options) {
  1507. var parent = options.parent;
  1508. var subscribe = function(mapping) {
  1509. mapping.name.subscribe(function(value) {
  1510. parent.parameters.valueHasMutated();
  1511. });
  1512. mapping.value.subscribe(function(value) {
  1513. parent.parameters.valueHasMutated();
  1514. });
  1515. };
  1516. return map_params(options, subscribe);
  1517. },
  1518. }
  1519. });
  1520. $.extend(self, mapping);
  1521. $.each(mapping['__ko_mapping__'].mappedProperties, function(key, value) {
  1522. var key = key;
  1523. self[key].subscribe(function(value) {
  1524. self.is_dirty( true );
  1525. self.model[key] = ko.mapping.toJS(value);
  1526. });
  1527. });
  1528. self.model = options.model;
  1529. self.registry = options.registry;
  1530. self.options = options;
  1531. self.el = $('#workflow');
  1532. self.nodes = ko.observableArray([]);
  1533. self.kill = null;
  1534. self.is_dirty = ko.observable( false );
  1535. self.read_only = ko.observable( options.read_only || false );
  1536. self.new_node = ko.observable();
  1537. self.url = ko.computed(function() {
  1538. return '/oozie/workflows/' + self.id()
  1539. });
  1540. // Events
  1541. self.el.on('workflow:rebuild', function() {
  1542. self.rebuild();
  1543. });
  1544. self.el.on('workflow:events:load', function() {
  1545. self.dragAndDropEvents( options );
  1546. });
  1547. self.el.on('workflow:droppables:load', function() {
  1548. self.droppables();
  1549. });
  1550. self.el.on('workflow:draggables:load', function() {
  1551. self.draggables();
  1552. });
  1553. self.dragAndDropEvents( options );
  1554. self.el.trigger('workflow:events:loaded');
  1555. module.prototype.initialize.apply(self, arguments);
  1556. return self;
  1557. };
  1558. $.extend(module.prototype, {
  1559. // Normal stuff
  1560. initialize: function(options) {
  1561. var self = this;
  1562. $.extend(self.options, options);
  1563. if ('model' in options) {
  1564. self.model = options.model;
  1565. // Initialize nodes
  1566. if (self.model.nodes) {
  1567. self.registry.clear();
  1568. $.each(self.model.nodes, function(index, node) {
  1569. var NodeModel = NodeModelChooser(node.node_type);
  1570. var model = new NodeModel(node);
  1571. var temp = null;
  1572. switch(node.node_type) {
  1573. case 'start':
  1574. temp = new StartNode(self, model, self.registry);
  1575. break;
  1576. case 'fork':
  1577. temp = new ForkNode(self, model, self.registry);
  1578. break;
  1579. case 'decision':
  1580. temp = new DecisionNode(self, model, self.registry);
  1581. break;
  1582. case 'kill':
  1583. temp = self.kill = new Node(self, model, self.registry);
  1584. break;
  1585. default:
  1586. temp = new Node(self, model, self.registry);
  1587. break;
  1588. }
  1589. self.registry.add(temp.id(), temp);
  1590. });
  1591. }
  1592. // Update data
  1593. $.each(self.model, function (key, value) {
  1594. if (key in self) {
  1595. switch(key) {
  1596. case 'job_properties':
  1597. case 'parameters':
  1598. // These may be serialized JSON data since that is how they are stored
  1599. self[key].removeAll();
  1600. var arr = $.parseJSON(value) || value;
  1601. $.each(arr, function(index, obj) {
  1602. var mapping = ko.mapping.fromJS(obj);
  1603. mapping.name.subscribe(function(value) {
  1604. self[key].valueHasMutated();
  1605. });
  1606. mapping.value.subscribe(function(value) {
  1607. self[key].valueHasMutated();
  1608. });
  1609. self[key].push(mapping);
  1610. });
  1611. break;
  1612. case 'nodes':
  1613. break;
  1614. default:
  1615. self[key](value);
  1616. break;
  1617. }
  1618. }
  1619. });
  1620. self.is_dirty( false );
  1621. }
  1622. if (!self.kill) {
  1623. var kill_json = {
  1624. "description": "",
  1625. "workflow": self.id(),
  1626. "child_links": [],
  1627. "node_type": "kill",
  1628. "message": "Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]",
  1629. "name": "kill",
  1630. "id": IdGeneratorTable['kill'].nextId()
  1631. };
  1632. var NodeModel = NodeModelChooser(kill_json.node_type);
  1633. var model = new NodeModel(kill_json);
  1634. self.kill = new Node(self, model, self.registry);
  1635. self.registry.add(self.kill.id(), self.kill);
  1636. }
  1637. if ('read_only' in options) {
  1638. self.read_only(options['read_only']);
  1639. }
  1640. },
  1641. toString: function() {
  1642. return '';
  1643. var s = '[';
  1644. $.each(self.registry.nodes, function(key, node) {
  1645. s += node.model.toString() + ",\n";
  1646. });
  1647. return s + ']';
  1648. },
  1649. // Data manipulation
  1650. toJSON: function() {
  1651. var self = this;
  1652. data = $.extend(true, {}, self.model);
  1653. var nodes = [];
  1654. $.each(self.registry.nodes, function(key, node) {
  1655. // Create object with members from the actual model to address JSON.stringify bug
  1656. // JSON.stringify does not pick up members specified in prototype prior to object creation.
  1657. var model = {};
  1658. for (var key in node.model) {
  1659. model[key] = node.model[key];
  1660. }
  1661. nodes.push(model);
  1662. });
  1663. data['nodes'] = nodes;
  1664. return JSON.stringify(data);
  1665. },
  1666. save: function( options ) {
  1667. var self = this;
  1668. var request = $.extend({
  1669. url: self.url() + '/save',
  1670. type: 'POST',
  1671. data: { workflow: self.toJSON() },
  1672. success: $.noop,
  1673. error: $.noop,
  1674. }, options || {});
  1675. $.ajax(request);
  1676. },
  1677. load: function( options ) {
  1678. var self = this;
  1679. var request = $.extend({
  1680. url: self.url(),
  1681. dataType: 'json',
  1682. type: 'GET',
  1683. success: $.noop,
  1684. error: $.noop,
  1685. }, options || {});
  1686. $.ajax(request);
  1687. },
  1688. reload: function(model) {
  1689. var self = this;
  1690. // Clear all children
  1691. $.each(self.registry.nodes, function(index, node) {
  1692. node.children.removeAll();
  1693. });
  1694. self.nodes.removeAll();
  1695. self.initialize({model: model});
  1696. self.rebuild();
  1697. self.el.trigger('workflow:loaded');
  1698. },
  1699. addParameter: function(data, event) {
  1700. var self = this;
  1701. var prop = { name: ko.observable(""), value: ko.observable("") };
  1702. // force bubble up to containing observable array.
  1703. prop.name.subscribe(function(){
  1704. self.parameters.valueHasMutated();
  1705. });
  1706. prop.value.subscribe(function(){
  1707. self.parameters.valueHasMutated();
  1708. });
  1709. self.parameters.push(prop);
  1710. },
  1711. removeParameter: function(data, event) {
  1712. var self = this;
  1713. self.parameters.remove(data);
  1714. },
  1715. addJobProperty: function(data, event) {
  1716. var self = this;
  1717. var prop = { name: ko.observable(""), value: ko.observable("") };
  1718. // force bubble up to containing observable array.
  1719. prop.name.subscribe(function(){
  1720. self.parameters.valueHasMutated();
  1721. });
  1722. prop.value.subscribe(function(){
  1723. self.parameters.valueHasMutated();
  1724. });
  1725. self.job_properties.push(prop);
  1726. },
  1727. removeJobProperty: function(data, event) {
  1728. var self = this;
  1729. self.job_properties.remove(data);
  1730. },
  1731. // Workflow UI
  1732. // Function to build nodes... recursively.
  1733. build: function() {
  1734. var self = this;
  1735. var maximum = 50;
  1736. var count = 0;
  1737. var methodChooser = function(node, collection, skip_parents_check) {
  1738. if (count++ >= maximum) {
  1739. if (window.error) {
  1740. console.error('Hit maximum number of node recursion: ' + maximum);
  1741. }
  1742. return null;
  1743. }
  1744. if (!node) {
  1745. return node;
  1746. }
  1747. var parents = node.findParents();
  1748. // Found end of decision node or found join!
  1749. if (parents.length > 1 && !skip_parents_check) {
  1750. return node;
  1751. }
  1752. switch(node.node_type()) {
  1753. case 'start':
  1754. case 'end':
  1755. case 'kill':
  1756. case 'fork':
  1757. case 'join':
  1758. case 'decision':
  1759. case 'decisionend':
  1760. return control(node, collection);
  1761. default:
  1762. return normal(node, collection);
  1763. }
  1764. };
  1765. var normal = function(node, collection) {
  1766. collection.push(node);
  1767. var retNode = null;
  1768. $.each(node.links(), function(index, link) {
  1769. var next_node = self.registry.get(link.child());
  1770. retNode = methodChooser(next_node, collection, false, true);
  1771. });
  1772. return retNode;
  1773. };
  1774. var control = function(node, collection, skip_parents_check) {
  1775. switch(node.node_type()) {
  1776. case 'start':
  1777. case 'end':
  1778. case 'kill':
  1779. case 'join':
  1780. case 'decisionend':
  1781. return normal(node, collection, false, true);
  1782. case 'fork':
  1783. collection.push(node);
  1784. // Wait for join.
  1785. // Iterate through all children and add them to child collection.
  1786. var join = null;
  1787. $.each(node.links(), function(index, link) {
  1788. var next_node = self.registry.get(link.child());
  1789. var collection = ko.observableArray([]);
  1790. node.children.push(collection);
  1791. join = methodChooser(next_node, collection, false, true);
  1792. });
  1793. // Add join to collection, then find its single child.
  1794. return methodChooser(join, collection, true, true);
  1795. case 'decision':
  1796. collection.push(node);
  1797. // Waits for end, then runs through children of end node
  1798. var end = null;
  1799. $.each(node.links(), function(index, link) {
  1800. var next_node = self.registry.get(link.child());
  1801. var collection = ko.observableArray([]);
  1802. node.children.push(collection);
  1803. end = methodChooser(next_node, collection, true, true);
  1804. });
  1805. // Add end
  1806. return methodChooser(node.end(), collection, true, true);
  1807. default:
  1808. // Should never get here.
  1809. return node;
  1810. }
  1811. };
  1812. methodChooser(self.registry.get(self.start()), self.nodes, false, true);
  1813. $(".tooltip").remove();
  1814. $("*[rel=tooltip]").tooltip();
  1815. },
  1816. rebuild: function() {
  1817. var self = this;
  1818. // Clear all children
  1819. $.each(self.registry.nodes, function(index, node) {
  1820. node.children.removeAll();
  1821. });
  1822. self.nodes.removeAll();
  1823. // Rebuild
  1824. self.build();
  1825. self.draggables();
  1826. self.droppables();
  1827. self.el.trigger('workflow:rebuilt');
  1828. },
  1829. draggables: function() {
  1830. var self = this;
  1831. self.el.find('.node-action').each(function(index, el) {
  1832. if (!$(el).hasClass('ui-draggable')) {
  1833. $(el).find('.row-fluid').eq(0).css('cursor', 'move');
  1834. $(el).draggable({
  1835. containment: [ self.el.offset().left - 10, self.el.offset().top - 10,
  1836. self.el.offset().left + self.el.outerWidth(), self.el.offset().top + self.el.outerHeight() ],
  1837. refreshPositions: true,
  1838. revert: true,
  1839. zIndex: 1000,
  1840. opacity: 0.45,
  1841. revertDuration: 0,
  1842. cancel: '.node-action-bar'
  1843. });
  1844. }
  1845. });
  1846. },
  1847. droppables: function() {
  1848. var self = this;
  1849. self.el.find('.node-link').each(function(index, el) {
  1850. $(el).droppable({
  1851. 'hoverClass': 'node-link-hover',
  1852. 'greedy': true,
  1853. 'accept': '.node-action',
  1854. 'tolerance': 'pointer'
  1855. });
  1856. });
  1857. self.el.find('.node-decision-end').each(function(index, el) {
  1858. $(el).droppable({
  1859. 'hoverClass': 'node-link-hover',
  1860. 'greedy': true,
  1861. 'accept': '.node-action',
  1862. 'tolerance': 'pointer'
  1863. });
  1864. });
  1865. self.el.find('.node-fork .action').each(function(index, el) {
  1866. $(el).droppable({
  1867. 'hoverClass': 'node-fork-hover',
  1868. 'greedy': true,
  1869. 'accept': '.node-action',
  1870. 'tolerance': 'pointer'
  1871. });
  1872. });
  1873. self.el.find('.node-decision .action').each(function(index, el) {
  1874. $(el).droppable({
  1875. 'hoverClass': 'node-fork-hover',
  1876. 'greedy': true,
  1877. 'accept': '.node-action',
  1878. 'tolerance': 'pointer'
  1879. });
  1880. });
  1881. self.el.find('.node-action .action').each(function(index, el) {
  1882. $(el).droppable({
  1883. 'hoverClass': 'node-action-hover',
  1884. 'greedy': true,
  1885. 'accept': '.node-action',
  1886. 'tolerance': 'pointer'
  1887. });
  1888. });
  1889. },
  1890. dragAndDropEvents: function( options ) {
  1891. var self = this;
  1892. var read_only_error_handler = options.read_only_error_handler;
  1893. // Build event delegations.
  1894. // Drop on node link
  1895. self.el.on('drop', '.node-link', function(e, ui) {
  1896. if (self.read_only()) {
  1897. read_only_error_handler();
  1898. return false;
  1899. }
  1900. // draggable should be a node.
  1901. // droppable should be a link.
  1902. var draggable = ko.contextFor(ui.draggable[0]).$data;
  1903. var droppable = ko.contextFor(this).$data;
  1904. // If newParent is fork, prepend to child instead.
  1905. // This will make it so that we can drop and drop to the top of a node list within a fork.
  1906. var newParent = self.registry.get(droppable.parent());
  1907. if (newParent.id() != draggable.id() && !newParent.isChild(draggable)) {
  1908. switch(newParent.node_type()) {
  1909. case 'fork':
  1910. case 'decision':
  1911. draggable.detach();
  1912. var child = self.registry.get(droppable.child());
  1913. newParent.replaceChild(child, draggable);
  1914. draggable.addChild(child);
  1915. break;
  1916. case 'join':
  1917. case 'decisionend':
  1918. // Join and decisionend may disappear when we detach...
  1919. // Remember its children and append to child.
  1920. var parents = newParent.findParents();
  1921. draggable.detach();
  1922. if (newParent.findParents().length < 2) {
  1923. $.each(parents, function(index, parent) {
  1924. parent.append(draggable);
  1925. });
  1926. } else {
  1927. newParent.append(draggable);
  1928. }
  1929. break;
  1930. default:
  1931. draggable.detach();
  1932. newParent.append(draggable);
  1933. break;
  1934. }
  1935. workflow.is_dirty( true );
  1936. self.rebuild();
  1937. }
  1938. // Prevent bubbling events
  1939. return false;
  1940. });
  1941. // Drop on fork
  1942. self.el.on('drop', '.node-fork', function(e, ui) {
  1943. if (self.read_only()) {
  1944. read_only_error_handler();
  1945. return false;
  1946. }
  1947. // draggable should be a node.
  1948. // droppable should be a fork.
  1949. var draggable = ko.contextFor(ui.draggable[0]).$data;
  1950. var droppable = ko.contextFor(this).$data;
  1951. if (!droppable.isChild(draggable) && droppable.id() != draggable.id()) {
  1952. draggable.detach();
  1953. droppable.append(draggable);
  1954. self.rebuild();
  1955. }
  1956. // Prevent bubbling events
  1957. return false;
  1958. });
  1959. // Drop on decision
  1960. self.el.on('drop', '.node-decision', function(e, ui) {
  1961. if (self.read_only()) {
  1962. read_only_error_handler();
  1963. return false;
  1964. }
  1965. // draggable should be a node.
  1966. // droppable should be a fork.
  1967. var draggable = ko.contextFor(ui.draggable[0]).$data;
  1968. var droppable = ko.contextFor(this).$data;
  1969. if (!droppable.isChild(draggable) && droppable.id() != draggable.id()) {
  1970. draggable.detach();
  1971. droppable.append(draggable);
  1972. self.rebuild();
  1973. }
  1974. // Prevent bubbling events
  1975. return false;
  1976. });
  1977. // Drop on action
  1978. self.el.on('drop', '.node-action', function(e, ui) {
  1979. if (self.read_only()) {
  1980. read_only_error_handler();
  1981. return false;
  1982. }
  1983. // draggable should be a node.
  1984. // droppable should be a node.
  1985. var draggable = ko.contextFor(ui.draggable[0]).$data;
  1986. var droppable = ko.contextFor(this).$data;
  1987. // Create a fork and join programatically.
  1988. var newParents = droppable.findParents();
  1989. // skip forking beneathe a decision node
  1990. if (droppable.id() != draggable.id() && newParents.length == 1 && draggable.findParents().length <= 1) {
  1991. var ForkModel = NodeModelChooser('fork');
  1992. var JoinModel = NodeModelChooser('join');
  1993. var fork = new ForkModel({
  1994. id: IdGeneratorTable['fork'].nextId(),
  1995. description: "",
  1996. workflow: self.id,
  1997. node_type: "fork",
  1998. child_links: []
  1999. });
  2000. var forkNode = new ForkNode(self, fork, self.registry);
  2001. var join = new JoinModel({
  2002. id: IdGeneratorTable['join'].nextId(),
  2003. description: "",
  2004. workflow: self.id,
  2005. node_type: "join",
  2006. child_links: []
  2007. });
  2008. var joinNode = new Node(self, join, self.registry);
  2009. self.registry.add(forkNode.id(), forkNode);
  2010. self.registry.add(joinNode.id(), joinNode);
  2011. forkNode.addChild(joinNode);
  2012. // Handles fork creation.
  2013. $.each(newParents, function(index, parent) {
  2014. parent.replaceChild(droppable, forkNode);
  2015. });
  2016. draggable.detach();
  2017. forkNode.append(draggable);
  2018. forkNode.append(droppable);
  2019. self.rebuild();
  2020. }
  2021. // Prevent bubbling events.
  2022. return false;
  2023. });
  2024. }
  2025. });
  2026. return module;
  2027. };
  2028. var Workflow = WorkflowModule($, nodeModelChooser, Node, ForkNode, DecisionNode, IdGeneratorTable);