workflow.js 63 KB

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