workflow.js 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376
  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! Use addChild or replaceChild instead!
  1306. */
  1307. append: function(node) {
  1308. var self = this;
  1309. if (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! Use addChild or replaceChild instead!
  1433. */
  1434. append: function(node) {
  1435. var self = this;
  1436. var end = self.end();
  1437. if (end.id() == node.id()) {
  1438. return false;
  1439. }
  1440. self.addChild(node);
  1441. node.append(end);
  1442. return true;
  1443. },
  1444. /**
  1445. * Replace child node with another node
  1446. * 1. Remove child if the replacement is end
  1447. * 2. Apply Node.replaceChild for all other causes
  1448. */
  1449. replaceChild: function(child, replacement) {
  1450. var self = this;
  1451. var ret = true;
  1452. var end = self.end();
  1453. if (end && end.id() == replacement.id()) {
  1454. ret = self.removeChild(child);
  1455. } else {
  1456. ret = Node.prototype.replaceChild.apply(self, arguments);
  1457. }
  1458. if (self.links().length < 2) {
  1459. self.detach();
  1460. end.detach();
  1461. self.erase();
  1462. end.erase();
  1463. }
  1464. return ret;
  1465. }
  1466. });
  1467. /**
  1468. * Workflow module
  1469. */
  1470. var WorkflowModule = function($, NodeModelChooser, Node, ForkNode, DecisionNode, IdGeneratorTable) {
  1471. var module = function(options) {
  1472. var self = this;
  1473. // @see http://knockoutjs.com/documentation/plugins-mapping.html
  1474. var mapping = ko.mapping.fromJS(options.model, {
  1475. ignore: ['initialize', 'toString'],
  1476. job_properties: {
  1477. create: function(options) {
  1478. var parent = options.parent;
  1479. var subscribe = function(mapping) {
  1480. mapping.name.subscribe(function(value) {
  1481. parent.job_properties.valueHasMutated();
  1482. });
  1483. mapping.value.subscribe(function(value) {
  1484. parent.job_properties.valueHasMutated();
  1485. });
  1486. };
  1487. return map_params(options, subscribe);
  1488. },
  1489. update: function(options) {
  1490. var parent = options.parent;
  1491. var subscribe = function(mapping) {
  1492. mapping.name.subscribe(function(value) {
  1493. parent.job_properties.valueHasMutated();
  1494. });
  1495. mapping.value.subscribe(function(value) {
  1496. parent.job_properties.valueHasMutated();
  1497. });
  1498. };
  1499. return map_params(options, subscribe);
  1500. }
  1501. },
  1502. parameters: {
  1503. // Will receive individual objects to subscribe.
  1504. // Containing array is mapped automagically
  1505. create: function(options) {
  1506. var parent = options.parent;
  1507. var subscribe = function(mapping) {
  1508. mapping.name.subscribe(function(value) {
  1509. parent.parameters.valueHasMutated();
  1510. });
  1511. mapping.value.subscribe(function(value) {
  1512. parent.parameters.valueHasMutated();
  1513. });
  1514. };
  1515. return map_params(options, subscribe);
  1516. },
  1517. update: function(options) {
  1518. var parent = options.parent;
  1519. var subscribe = function(mapping) {
  1520. mapping.name.subscribe(function(value) {
  1521. parent.parameters.valueHasMutated();
  1522. });
  1523. mapping.value.subscribe(function(value) {
  1524. parent.parameters.valueHasMutated();
  1525. });
  1526. };
  1527. return map_params(options, subscribe);
  1528. },
  1529. }
  1530. });
  1531. $.extend(self, mapping);
  1532. $.each(mapping['__ko_mapping__'].mappedProperties, function(key, value) {
  1533. var key = key;
  1534. self[key].subscribe(function(value) {
  1535. self.is_dirty( true );
  1536. self.model[key] = ko.mapping.toJS(value);
  1537. });
  1538. });
  1539. self.model = options.model;
  1540. self.registry = options.registry;
  1541. self.options = options;
  1542. self.el = $('#workflow');
  1543. self.nodes = ko.observableArray([]);
  1544. self.kill = null;
  1545. self.is_dirty = ko.observable( false );
  1546. self.read_only = ko.observable( options.read_only || false );
  1547. self.new_node = ko.observable();
  1548. self.url = ko.computed(function() {
  1549. return '/oozie/workflows/' + self.id()
  1550. });
  1551. // Events
  1552. self.el.on('workflow:rebuild', function() {
  1553. self.rebuild();
  1554. });
  1555. self.el.on('workflow:events:load', function() {
  1556. self.dragAndDropEvents( options );
  1557. });
  1558. self.el.on('workflow:droppables:load', function() {
  1559. self.droppables();
  1560. });
  1561. self.el.on('workflow:draggables:load', function() {
  1562. self.draggables();
  1563. });
  1564. self.dragAndDropEvents( options );
  1565. self.el.trigger('workflow:events:loaded');
  1566. module.prototype.initialize.apply(self, arguments);
  1567. return self;
  1568. };
  1569. $.extend(module.prototype, {
  1570. // Normal stuff
  1571. initialize: function(options) {
  1572. var self = this;
  1573. $.extend(self.options, options);
  1574. if ('model' in options) {
  1575. self.model = options.model;
  1576. // Initialize nodes
  1577. if (self.model.nodes) {
  1578. self.registry.clear();
  1579. $.each(self.model.nodes, function(index, node) {
  1580. var NodeModel = NodeModelChooser(node.node_type);
  1581. var model = new NodeModel(node);
  1582. var temp = null;
  1583. switch(node.node_type) {
  1584. case 'start':
  1585. temp = new StartNode(self, model, self.registry);
  1586. break;
  1587. case 'fork':
  1588. temp = new ForkNode(self, model, self.registry);
  1589. break;
  1590. case 'decision':
  1591. temp = new DecisionNode(self, model, self.registry);
  1592. break;
  1593. case 'kill':
  1594. temp = self.kill = new Node(self, model, self.registry);
  1595. break;
  1596. default:
  1597. temp = new Node(self, model, self.registry);
  1598. break;
  1599. }
  1600. self.registry.add(temp.id(), temp);
  1601. });
  1602. }
  1603. // Update data
  1604. $.each(self.model, function (key, value) {
  1605. if (key in self) {
  1606. switch(key) {
  1607. case 'job_properties':
  1608. case 'parameters':
  1609. // These may be serialized JSON data since that is how they are stored
  1610. self[key].removeAll();
  1611. var arr = $.parseJSON(value) || value;
  1612. $.each(arr, function(index, obj) {
  1613. var mapping = ko.mapping.fromJS(obj);
  1614. mapping.name.subscribe(function(value) {
  1615. self[key].valueHasMutated();
  1616. });
  1617. mapping.value.subscribe(function(value) {
  1618. self[key].valueHasMutated();
  1619. });
  1620. self[key].push(mapping);
  1621. });
  1622. break;
  1623. case 'nodes':
  1624. break;
  1625. default:
  1626. self[key](value);
  1627. break;
  1628. }
  1629. }
  1630. });
  1631. self.is_dirty( false );
  1632. }
  1633. if (!self.kill) {
  1634. var kill_json = {
  1635. "description": "",
  1636. "workflow": self.id(),
  1637. "child_links": [],
  1638. "node_type": "kill",
  1639. "message": "Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]",
  1640. "name": "kill",
  1641. "id": IdGeneratorTable['kill'].nextId()
  1642. };
  1643. var NodeModel = NodeModelChooser(kill_json.node_type);
  1644. var model = new NodeModel(kill_json);
  1645. self.kill = new Node(self, model, self.registry);
  1646. self.registry.add(self.kill.id(), self.kill);
  1647. }
  1648. if ('read_only' in options) {
  1649. self.read_only(options['read_only']);
  1650. }
  1651. },
  1652. toString: function() {
  1653. return '';
  1654. var s = '[';
  1655. $.each(self.registry.nodes, function(key, node) {
  1656. s += node.model.toString() + ",\n";
  1657. });
  1658. return s + ']';
  1659. },
  1660. // Data manipulation
  1661. toJSON: function() {
  1662. var self = this;
  1663. data = $.extend(true, {}, self.model);
  1664. var nodes = [];
  1665. $.each(self.registry.nodes, function(key, node) {
  1666. // Create object with members from the actual model to address JSON.stringify bug
  1667. // JSON.stringify does not pick up members specified in prototype prior to object creation.
  1668. var model = {};
  1669. for (var key in node.model) {
  1670. model[key] = node.model[key];
  1671. }
  1672. nodes.push(model);
  1673. });
  1674. data['nodes'] = nodes;
  1675. return JSON.stringify(data);
  1676. },
  1677. save: function( options ) {
  1678. var self = this;
  1679. var request = $.extend({
  1680. url: self.url() + '/save',
  1681. type: 'POST',
  1682. data: { workflow: self.toJSON() },
  1683. success: $.noop,
  1684. error: $.noop,
  1685. }, options || {});
  1686. $.ajax(request);
  1687. },
  1688. load: function( options ) {
  1689. var self = this;
  1690. var request = $.extend({
  1691. url: self.url(),
  1692. dataType: 'json',
  1693. type: 'GET',
  1694. success: $.noop,
  1695. error: $.noop,
  1696. }, options || {});
  1697. $.ajax(request);
  1698. },
  1699. reload: function(model) {
  1700. var self = this;
  1701. // Clear all children
  1702. $.each(self.registry.nodes, function(index, node) {
  1703. node.children.removeAll();
  1704. });
  1705. self.nodes.removeAll();
  1706. self.initialize({model: model});
  1707. self.rebuild();
  1708. self.el.trigger('workflow:loaded');
  1709. },
  1710. addParameter: function(data, event) {
  1711. var self = this;
  1712. var prop = { name: ko.observable(""), value: ko.observable("") };
  1713. // force bubble up to containing observable array.
  1714. prop.name.subscribe(function(){
  1715. self.parameters.valueHasMutated();
  1716. });
  1717. prop.value.subscribe(function(){
  1718. self.parameters.valueHasMutated();
  1719. });
  1720. self.parameters.push(prop);
  1721. },
  1722. removeParameter: function(data, event) {
  1723. var self = this;
  1724. self.parameters.remove(data);
  1725. },
  1726. addJobProperty: function(data, event) {
  1727. var self = this;
  1728. var prop = { name: ko.observable(""), value: ko.observable("") };
  1729. // force bubble up to containing observable array.
  1730. prop.name.subscribe(function(){
  1731. self.parameters.valueHasMutated();
  1732. });
  1733. prop.value.subscribe(function(){
  1734. self.parameters.valueHasMutated();
  1735. });
  1736. self.job_properties.push(prop);
  1737. },
  1738. removeJobProperty: function(data, event) {
  1739. var self = this;
  1740. self.job_properties.remove(data);
  1741. },
  1742. // Workflow UI
  1743. // Function to build nodes... recursively.
  1744. build: function() {
  1745. var self = this;
  1746. var maximum = 50;
  1747. var count = 0;
  1748. var methodChooser = function(node, collection, skip_parents_check) {
  1749. if (count++ >= maximum) {
  1750. if (window.error) {
  1751. console.error('Hit maximum number of node recursion: ' + maximum);
  1752. }
  1753. return null;
  1754. }
  1755. if (!node) {
  1756. return node;
  1757. }
  1758. var parents = node.findParents();
  1759. // Found end of decision node or found join!
  1760. if (parents.length > 1 && !skip_parents_check) {
  1761. return node;
  1762. }
  1763. switch(node.node_type()) {
  1764. case 'start':
  1765. case 'end':
  1766. case 'kill':
  1767. case 'fork':
  1768. case 'join':
  1769. case 'decision':
  1770. case 'decisionend':
  1771. return control(node, collection);
  1772. default:
  1773. return normal(node, collection);
  1774. }
  1775. };
  1776. var normal = function(node, collection) {
  1777. collection.push(node);
  1778. var retNode = null;
  1779. $.each(node.links(), function(index, link) {
  1780. var next_node = self.registry.get(link.child());
  1781. retNode = methodChooser(next_node, collection, false, true);
  1782. });
  1783. return retNode;
  1784. };
  1785. var control = function(node, collection, skip_parents_check) {
  1786. switch(node.node_type()) {
  1787. case 'start':
  1788. case 'end':
  1789. case 'kill':
  1790. case 'join':
  1791. case 'decisionend':
  1792. return normal(node, collection, false, true);
  1793. case 'fork':
  1794. collection.push(node);
  1795. // Wait for join.
  1796. // Iterate through all children and add them to child collection.
  1797. var join = null;
  1798. $.each(node.links(), function(index, link) {
  1799. var next_node = self.registry.get(link.child());
  1800. var collection = ko.observableArray([]);
  1801. node.children.push(collection);
  1802. join = methodChooser(next_node, collection, false, true);
  1803. });
  1804. // Add join to collection, then find its single child.
  1805. return methodChooser(join, collection, true, true);
  1806. case 'decision':
  1807. collection.push(node);
  1808. // Waits for end, then runs through children of end node
  1809. var end = null;
  1810. $.each(node.links(), function(index, link) {
  1811. var next_node = self.registry.get(link.child());
  1812. var collection = ko.observableArray([]);
  1813. node.children.push(collection);
  1814. end = methodChooser(next_node, collection, true, true);
  1815. });
  1816. // Add end
  1817. return methodChooser(node.end(), collection, true, true);
  1818. default:
  1819. // Should never get here.
  1820. return node;
  1821. }
  1822. };
  1823. methodChooser(self.registry.get(self.start()), self.nodes, false, true);
  1824. $(".tooltip").remove();
  1825. $("*[rel=tooltip]").tooltip();
  1826. },
  1827. rebuild: function() {
  1828. var self = this;
  1829. // Clear all children
  1830. $.each(self.registry.nodes, function(index, node) {
  1831. node.children.removeAll();
  1832. });
  1833. self.nodes.removeAll();
  1834. // Rebuild
  1835. self.build();
  1836. self.draggables();
  1837. self.droppables();
  1838. self.el.trigger('workflow:rebuilt');
  1839. },
  1840. draggables: function() {
  1841. var self = this;
  1842. self.el.find('.node-action').each(function(index, el) {
  1843. if (!$(el).hasClass('ui-draggable')) {
  1844. $(el).find('.row-fluid').eq(0).css('cursor', 'move');
  1845. $(el).draggable({
  1846. containment: [ self.el.offset().left - 10, self.el.offset().top - 10,
  1847. self.el.offset().left + self.el.outerWidth(), self.el.offset().top + self.el.outerHeight() ],
  1848. refreshPositions: true,
  1849. revert: true,
  1850. zIndex: 1000,
  1851. opacity: 0.45,
  1852. revertDuration: 0,
  1853. cancel: '.node-action-bar'
  1854. });
  1855. }
  1856. });
  1857. },
  1858. droppables: function() {
  1859. var self = this;
  1860. self.el.find('.node-link').each(function(index, el) {
  1861. $(el).droppable({
  1862. 'hoverClass': 'node-link-hover',
  1863. 'greedy': true,
  1864. 'accept': '.node-action',
  1865. 'tolerance': 'pointer'
  1866. });
  1867. });
  1868. self.el.find('.node-decision-end').each(function(index, el) {
  1869. $(el).droppable({
  1870. 'hoverClass': 'node-link-hover',
  1871. 'greedy': true,
  1872. 'accept': '.node-action',
  1873. 'tolerance': 'pointer'
  1874. });
  1875. });
  1876. self.el.find('.node-fork .action').each(function(index, el) {
  1877. $(el).droppable({
  1878. 'hoverClass': 'node-fork-hover',
  1879. 'greedy': true,
  1880. 'accept': '.node-action',
  1881. 'tolerance': 'pointer'
  1882. });
  1883. });
  1884. self.el.find('.node-decision .action').each(function(index, el) {
  1885. $(el).droppable({
  1886. 'hoverClass': 'node-fork-hover',
  1887. 'greedy': true,
  1888. 'accept': '.node-action',
  1889. 'tolerance': 'pointer'
  1890. });
  1891. });
  1892. self.el.find('.node-action .action').each(function(index, el) {
  1893. $(el).droppable({
  1894. 'hoverClass': 'node-action-hover',
  1895. 'greedy': true,
  1896. 'accept': '.node-action',
  1897. 'tolerance': 'pointer'
  1898. });
  1899. });
  1900. },
  1901. dragAndDropEvents: function( options ) {
  1902. var self = this;
  1903. var read_only_error_handler = options.read_only_error_handler;
  1904. // Build event delegations.
  1905. // Drop on node link
  1906. self.el.on('drop', '.node-link', function(e, ui) {
  1907. if (self.read_only()) {
  1908. read_only_error_handler();
  1909. return false;
  1910. }
  1911. // draggable should be a node.
  1912. // droppable should be a link.
  1913. var draggable = ko.contextFor(ui.draggable[0]).$data;
  1914. var droppable = ko.contextFor(this).$data;
  1915. // If newParent is fork, prepend to child instead.
  1916. // This will make it so that we can drop and drop to the top of a node list within a fork.
  1917. var newParent = self.registry.get(droppable.parent());
  1918. if (newParent.id() != draggable.id() && !newParent.isChild(draggable)) {
  1919. switch(newParent.node_type()) {
  1920. case 'fork':
  1921. case 'decision':
  1922. draggable.detach();
  1923. var child = self.registry.get(droppable.child());
  1924. newParent.replaceChild(child, draggable);
  1925. draggable.addChild(child);
  1926. break;
  1927. case 'join':
  1928. case 'decisionend':
  1929. // Join and decisionend may disappear when we detach...
  1930. // Remember its children and append to child.
  1931. var parents = newParent.findParents();
  1932. draggable.detach();
  1933. if (newParent.findParents().length < 2) {
  1934. $.each(parents, function(index, parent) {
  1935. parent.append(draggable);
  1936. });
  1937. } else {
  1938. newParent.append(draggable);
  1939. }
  1940. break;
  1941. default:
  1942. draggable.detach();
  1943. newParent.append(draggable);
  1944. break;
  1945. }
  1946. workflow.is_dirty( true );
  1947. self.rebuild();
  1948. }
  1949. // Prevent bubbling events
  1950. return false;
  1951. });
  1952. // Drop on fork
  1953. self.el.on('drop', '.node-fork', function(e, ui) {
  1954. if (self.read_only()) {
  1955. read_only_error_handler();
  1956. return false;
  1957. }
  1958. // draggable should be a node.
  1959. // droppable should be a fork.
  1960. var draggable = ko.contextFor(ui.draggable[0]).$data;
  1961. var droppable = ko.contextFor(this).$data;
  1962. if (!droppable.isChild(draggable) && droppable.id() != draggable.id()) {
  1963. draggable.detach();
  1964. droppable.append(draggable);
  1965. self.rebuild();
  1966. }
  1967. // Prevent bubbling events
  1968. return false;
  1969. });
  1970. // Drop on decision
  1971. self.el.on('drop', '.node-decision', function(e, ui) {
  1972. if (self.read_only()) {
  1973. read_only_error_handler();
  1974. return false;
  1975. }
  1976. // draggable should be a node.
  1977. // droppable should be a fork.
  1978. var draggable = ko.contextFor(ui.draggable[0]).$data;
  1979. var droppable = ko.contextFor(this).$data;
  1980. if (!droppable.isChild(draggable) && droppable.id() != draggable.id()) {
  1981. draggable.detach();
  1982. droppable.append(draggable);
  1983. self.rebuild();
  1984. }
  1985. // Prevent bubbling events
  1986. return false;
  1987. });
  1988. // Drop on action
  1989. self.el.on('drop', '.node-action', function(e, ui) {
  1990. if (self.read_only()) {
  1991. read_only_error_handler();
  1992. return false;
  1993. }
  1994. // draggable should be a node.
  1995. // droppable should be a node.
  1996. var draggable = ko.contextFor(ui.draggable[0]).$data;
  1997. var droppable = ko.contextFor(this).$data;
  1998. // Create a fork and join programatically.
  1999. var newParents = droppable.findParents();
  2000. // skip forking beneathe a decision node
  2001. if (droppable.id() != draggable.id() && newParents.length == 1 && draggable.findParents().length <= 1) {
  2002. var ForkModel = NodeModelChooser('fork');
  2003. var JoinModel = NodeModelChooser('join');
  2004. var fork = new ForkModel({
  2005. id: IdGeneratorTable['fork'].nextId(),
  2006. description: "",
  2007. workflow: self.id,
  2008. node_type: "fork",
  2009. child_links: []
  2010. });
  2011. var forkNode = new ForkNode(self, fork, self.registry);
  2012. var join = new JoinModel({
  2013. id: IdGeneratorTable['join'].nextId(),
  2014. description: "",
  2015. workflow: self.id,
  2016. node_type: "join",
  2017. child_links: []
  2018. });
  2019. var joinNode = new Node(self, join, self.registry);
  2020. self.registry.add(forkNode.id(), forkNode);
  2021. self.registry.add(joinNode.id(), joinNode);
  2022. forkNode.addChild(joinNode);
  2023. // Handles fork creation.
  2024. $.each(newParents, function(index, parent) {
  2025. parent.replaceChild(droppable, forkNode);
  2026. });
  2027. draggable.detach();
  2028. forkNode.append(draggable);
  2029. forkNode.append(droppable);
  2030. self.rebuild();
  2031. }
  2032. // Prevent bubbling events.
  2033. return false;
  2034. });
  2035. }
  2036. });
  2037. return module;
  2038. };
  2039. var Workflow = WorkflowModule($, nodeModelChooser, Node, ForkNode, DecisionNode, IdGeneratorTable);