workflow.js 62 KB

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