workflow.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*
  2. Licensed to Cloudera, Inc. under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. Cloudera, Inc. licenses this file
  6. to you under the Apache License, Version 2.0 (the
  7. "License"); you may not use this file except in compliance
  8. with the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. */
  16. function getFileBrowseButton() {}
  17. describe("WorkflowModel", function(){
  18. function create_three_step_workflow(workflow_id) {
  19. var workflow_model = new WorkflowModel({
  20. "id": workflow_id,
  21. "name": "Test-Three-Step-Workflow",
  22. "start": 1,
  23. "end": 5,
  24. "nodes":[{
  25. "description":"",
  26. "workflow":workflow_id,
  27. "child_links":[{
  28. "comment":"",
  29. "name":"to",
  30. "parent":1,
  31. "child":2
  32. },{
  33. "comment":"",
  34. "name":"related",
  35. "parent":1,
  36. "child":5
  37. }],
  38. "node_type":"start",
  39. "id":1,
  40. "name":"start"
  41. },{
  42. "id":2,
  43. "name":"Sleep-1",
  44. "workflow":workflow_id,
  45. "node_type":"mapreduce",
  46. "jar_path":"/user/hue/oozie/workspaces/lib/hadoop-examples.jar",
  47. "child_links":[{
  48. "comment":"",
  49. "name":"ok",
  50. "parent":2,
  51. "child":3
  52. },{
  53. "comment":"",
  54. "name":"error",
  55. "parent":2,
  56. "child":6
  57. }],
  58. },{
  59. "id":3,
  60. "name":"Sleep-2",
  61. "workflow":workflow_id,
  62. "node_type":"mapreduce",
  63. "jar_path":"/user/hue/oozie/workspaces/lib/hadoop-examples.jar",
  64. "child_links":[{
  65. "comment":"",
  66. "name":"ok",
  67. "parent":3,
  68. "child":4
  69. },{
  70. "comment":"",
  71. "name":"error",
  72. "parent":3,
  73. "child":6
  74. }],
  75. },{
  76. "id":4,
  77. "name":"Sleep-3",
  78. "workflow":workflow_id,
  79. "node_type":"mapreduce",
  80. "jar_path":"/user/hue/oozie/workspaces/lib/hadoop-examples.jar",
  81. "child_links":[{
  82. "comment":"",
  83. "name":"ok",
  84. "parent":4,
  85. "child":5
  86. },{
  87. "comment":"",
  88. "name":"error",
  89. "parent":4,
  90. "child":6
  91. }],
  92. },{
  93. "id":6,
  94. "name":"kill",
  95. "workflow":workflow_id,
  96. "node_type":"kill",
  97. "child_links":[],
  98. "message":"Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]",
  99. },{
  100. "id":5,
  101. "name":"end",
  102. "workflow":workflow_id,
  103. "node_type":"end",
  104. "child_links":[],
  105. }],
  106. });
  107. var registry = new Registry();
  108. var workflow = new Workflow({
  109. model: workflow_model,
  110. registry: registry
  111. });
  112. return workflow;
  113. }
  114. function create_pig_workflow(workflow_id) {
  115. var workflow_model = new WorkflowModel({
  116. "id": workflow_id,
  117. "name": "Test-pig-Workflow",
  118. "start": 1,
  119. "end": 5,
  120. "nodes":[{
  121. "description":"",
  122. "workflow":workflow_id,
  123. "child_links":[{
  124. "comment":"",
  125. "name":"to",
  126. "parent":1,
  127. "child":2
  128. },{
  129. "comment":"",
  130. "name":"related",
  131. "parent":1,
  132. "child":5
  133. }],
  134. "node_type":"start",
  135. "id":1,
  136. "name":"start"
  137. },{
  138. "id":2,
  139. "name":"Pig-1",
  140. "workflow":workflow_id,
  141. "node_type":"pig",
  142. "script_path":"test.pig",
  143. "child_links":[{
  144. "comment":"",
  145. "name":"ok",
  146. "parent":2,
  147. "child":3
  148. },{
  149. "comment":"",
  150. "name":"error",
  151. "parent":2,
  152. "child":4
  153. }],
  154. },{
  155. "id":4,
  156. "name":"kill",
  157. "workflow":workflow_id,
  158. "node_type":"kill",
  159. "child_links":[],
  160. "message":"Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]",
  161. },{
  162. "id":3,
  163. "name":"end",
  164. "workflow":workflow_id,
  165. "node_type":"end",
  166. "child_links":[],
  167. }],
  168. })
  169. var registry = new Registry();
  170. var workflow = new Workflow({
  171. model: workflow_model,
  172. registry: registry
  173. });
  174. return workflow;
  175. }
  176. describe("Workflow operations", function(){
  177. var json = '{"id":1,"name":"Test-pig-Workflow","start":1,"end":5,"nodes":[{"description":"","workflow":1,"child_links":[{"comment":"","name":"to","parent":1,"child":2},{"comment":"","name":"related","parent":1,"child":5}],"node_type":"start","id":1,"name":"start"},{"id":2,"name":"Pig-1","workflow":1,"node_type":"pig","script_path":"test.pig","child_links":[{"comment":"","name":"ok","parent":2,"child":3},{"comment":"","name":"error","parent":2,"child":4}],"description":"","files":"[]","archives":"[]","job_properties":"[]","prepares":"[]","job_xml":"","params":"[]"},{"id":3,"name":"end","workflow":1,"node_type":"end","child_links":[],"description":""},{"id":4,"name":"kill","workflow":1,"node_type":"kill","child_links":[],"message":"Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]","description":""}],"parameters":[],"description":"","schema_version":0.4,"deployment_dir":"","is_shared":true,"job_xml":""}';
  178. var node = null;
  179. var viewModel = create_pig_workflow(1);
  180. viewModel.rebuild();
  181. it("Ensure serialized data sent to server is proper", function() {
  182. expect(viewModel.toJSON()).toEqual(ko.toJSON($.parseJSON(json)));
  183. });
  184. it("Ensure data received from server can be loaded", function() {
  185. viewModel.reload($.parseJSON(json.replace('test.pig','test1.pig')));
  186. expect(viewModel.id()).toEqual(1);
  187. expect(viewModel.name()).toEqual('Test-pig-Workflow');
  188. expect(viewModel.start()).toEqual(1);
  189. expect(viewModel.description()).toEqual("");
  190. expect(viewModel.schema_version()).toEqual(0.4);
  191. expect(viewModel.deployment_dir()).toEqual("");
  192. expect(viewModel.is_shared()).toEqual(true);
  193. expect(viewModel.parameters().length).toEqual(0);
  194. expect(viewModel.job_xml()).toEqual("");
  195. expect(viewModel.nodes().length).toEqual(3);
  196. expect(viewModel.nodes()[1].script_path()).toEqual('test1.pig');
  197. });
  198. });
  199. describe("Node APIs", function(){
  200. var node = null;
  201. var viewModel = create_three_step_workflow(2);
  202. viewModel.rebuild();
  203. it("Should be able to detach a node", function() {
  204. node = viewModel.nodes()[2];
  205. node.detach();
  206. viewModel.rebuild();
  207. expect(viewModel.nodes().length).toEqual(4);
  208. });
  209. it("Should be able to append a node", function() {
  210. viewModel.nodes()[1].append(node);
  211. viewModel.rebuild();
  212. expect(viewModel.nodes().length).toEqual(5);
  213. });
  214. it("Should be able to fail when appending the same node", function() {
  215. viewModel.nodes()[1].append(node);
  216. viewModel.rebuild();
  217. expect(viewModel.nodes().length).toEqual(5);
  218. });
  219. it("Should be able to add error node", function() {
  220. viewModel.nodes()[1].putErrorChild(viewModel.nodes()[2]);
  221. viewModel.rebuild();
  222. expect(viewModel.nodes().length).toEqual(5);
  223. expect(viewModel.nodes()[1].meta_links().length).toEqual(1);
  224. expect(viewModel.nodes()[1].meta_links()[0].name()).toEqual("error");
  225. expect(viewModel.nodes()[1].meta_links()[0].parent()).toEqual(viewModel.nodes()[1].id());
  226. expect(viewModel.nodes()[1].meta_links()[0].child()).toEqual(viewModel.nodes()[2].id());
  227. });
  228. it("Should be able to get error node", function() {
  229. viewModel.nodes()[1].putErrorChild(viewModel.nodes()[2]);
  230. viewModel.rebuild();
  231. expect(viewModel.nodes().length).toEqual(5);
  232. expect(viewModel.nodes()[1].getErrorChild().id()).toEqual(viewModel.nodes()[2].id());
  233. });
  234. });
  235. describe("Workflow node modal", function(){
  236. var node = null;
  237. var viewModel = create_three_step_workflow(2);
  238. var modal = new Modal($('#node-modal'));
  239. viewModel.rebuild();
  240. it("Ensure can open and close modal", function() {
  241. edit_node_modal(modal, viewModel, viewModel.nodes()[1]);
  242. expect(modal.el.is(":visible"));
  243. $('.doneButton').click();
  244. expect(!modal.el.is(":visible"));
  245. edit_node_modal(modal, viewModel, viewModel.nodes()[1]);
  246. expect(modal.el.is(":visible"));
  247. $('.cancelButton').click();
  248. expect(!modal.el.is(":visible"));
  249. });
  250. it("Ensure can change kill node of existing node", function() {
  251. edit_node_modal(modal, viewModel, viewModel.nodes()[1]);
  252. modal.context().error_node(viewModel.nodes()[0].id());
  253. expect(viewModel.nodes()[1].getErrorChild().id()).toEqual(viewModel.nodes()[0].id());
  254. $('.done').click();
  255. expect(viewModel.nodes()[1].getErrorChild().id()).toEqual(viewModel.nodes()[0].id());
  256. });
  257. });
  258. });