workflow.js 63 KB

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