workflow.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. describe("WorkflowModel", function(){
  17. function create_three_step_workflow(workflow_id) {
  18. var workflow_model = new WorkflowModel({
  19. "id": workflow_id,
  20. "name": "Test-Three-Step-Workflow",
  21. "start": 1,
  22. "end": 5,
  23. "nodes":[{
  24. "description":"",
  25. "workflow":workflow_id,
  26. "child_links":[{
  27. "comment":"",
  28. "name":"to",
  29. "parent":1,
  30. "child":2
  31. },{
  32. "comment":"",
  33. "name":"related",
  34. "parent":1,
  35. "child":5
  36. }],
  37. "node_type":"start",
  38. "id":1,
  39. "name":"start"
  40. },{
  41. "id":2,
  42. "name":"Sleep-1",
  43. "workflow":workflow_id,
  44. "node_type":"mapreduce",
  45. "jar_path":"/user/hue/oozie/workspaces/lib/hadoop-examples.jar",
  46. "child_links":[{
  47. "comment":"",
  48. "name":"ok",
  49. "parent":2,
  50. "child":3
  51. },{
  52. "comment":"",
  53. "name":"error",
  54. "parent":2,
  55. "child":6
  56. }],
  57. },{
  58. "id":3,
  59. "name":"Sleep-2",
  60. "workflow":workflow_id,
  61. "node_type":"mapreduce",
  62. "jar_path":"/user/hue/oozie/workspaces/lib/hadoop-examples.jar",
  63. "child_links":[{
  64. "comment":"",
  65. "name":"ok",
  66. "parent":3,
  67. "child":4
  68. },{
  69. "comment":"",
  70. "name":"error",
  71. "parent":3,
  72. "child":6
  73. }],
  74. },{
  75. "id":4,
  76. "name":"Sleep-3",
  77. "workflow":workflow_id,
  78. "node_type":"mapreduce",
  79. "jar_path":"/user/hue/oozie/workspaces/lib/hadoop-examples.jar",
  80. "child_links":[{
  81. "comment":"",
  82. "name":"ok",
  83. "parent":4,
  84. "child":5
  85. },{
  86. "comment":"",
  87. "name":"error",
  88. "parent":4,
  89. "child":6
  90. }],
  91. },{
  92. "id":6,
  93. "name":"kill",
  94. "workflow":workflow_id,
  95. "node_type":"kill",
  96. "child_links":[],
  97. "message":"Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]",
  98. },{
  99. "id":5,
  100. "name":"end",
  101. "workflow":workflow_id,
  102. "node_type":"end",
  103. "child_links":[],
  104. }],
  105. });
  106. var registry = new Registry();
  107. var workflow = new Workflow({
  108. model: workflow_model,
  109. registry: registry
  110. });
  111. return workflow;
  112. }
  113. function create_pig_workflow(workflow_id) {
  114. var workflow_model = new WorkflowModel({
  115. "id": workflow_id,
  116. "name": "Test-pig-Workflow",
  117. "start": 1,
  118. "end": 5,
  119. "nodes":[{
  120. "description":"",
  121. "workflow":workflow_id,
  122. "child_links":[{
  123. "comment":"",
  124. "name":"to",
  125. "parent":1,
  126. "child":2
  127. },{
  128. "comment":"",
  129. "name":"related",
  130. "parent":1,
  131. "child":5
  132. }],
  133. "node_type":"start",
  134. "id":1,
  135. "name":"start"
  136. },{
  137. "id":2,
  138. "name":"Pig-1",
  139. "workflow":workflow_id,
  140. "node_type":"pig",
  141. "script_path":"test.pig",
  142. "child_links":[{
  143. "comment":"",
  144. "name":"ok",
  145. "parent":2,
  146. "child":3
  147. },{
  148. "comment":"",
  149. "name":"error",
  150. "parent":2,
  151. "child":4
  152. }],
  153. },{
  154. "id":4,
  155. "name":"kill",
  156. "workflow":workflow_id,
  157. "node_type":"kill",
  158. "child_links":[],
  159. "message":"Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]",
  160. },{
  161. "id":3,
  162. "name":"end",
  163. "workflow":workflow_id,
  164. "node_type":"end",
  165. "child_links":[],
  166. }],
  167. })
  168. var registry = new Registry();
  169. var workflow = new Workflow({
  170. model: workflow_model,
  171. registry: registry
  172. });
  173. return workflow;
  174. }
  175. describe("Workflow operations", function(){
  176. 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":""}';
  177. var node = null;
  178. var viewModel = create_pig_workflow(1);
  179. viewModel.rebuild();
  180. it("Ensure serialized data sent to server is proper", function() {
  181. expect(viewModel.toJSON()).toEqual(ko.toJSON($.parseJSON(json)));
  182. });
  183. it("Ensure data received from server can be loaded", function() {
  184. viewModel.reload($.parseJSON(json.replace('test.pig','test1.pig')));
  185. expect(viewModel.id()).toEqual(1);
  186. expect(viewModel.name()).toEqual('Test-pig-Workflow');
  187. expect(viewModel.start()).toEqual(1);
  188. expect(viewModel.description()).toEqual("");
  189. expect(viewModel.schema_version()).toEqual(0.4);
  190. expect(viewModel.deployment_dir()).toEqual("");
  191. expect(viewModel.is_shared()).toEqual(true);
  192. expect(viewModel.parameters().length).toEqual(0);
  193. expect(viewModel.job_xml()).toEqual("");
  194. expect(viewModel.nodes().length).toEqual(3);
  195. expect(viewModel.nodes()[1].script_path()).toEqual('test1.pig');
  196. });
  197. });
  198. describe("Node APIs", function(){
  199. var node = null;
  200. var viewModel = create_three_step_workflow(2);
  201. viewModel.rebuild();
  202. it("Should be able to detach a node", function() {
  203. node = viewModel.nodes()[2];
  204. node.detach();
  205. viewModel.rebuild();
  206. expect(viewModel.nodes().length).toEqual(4);
  207. });
  208. it("Should be able to append a node", function() {
  209. viewModel.nodes()[1].append(node);
  210. viewModel.rebuild();
  211. expect(viewModel.nodes().length).toEqual(5);
  212. });
  213. it("Should be able to fail when appending the same node", function() {
  214. viewModel.nodes()[1].append(node);
  215. viewModel.rebuild();
  216. expect(viewModel.nodes().length).toEqual(5);
  217. });
  218. it("Should be able to add error node", function() {
  219. viewModel.nodes()[1].putErrorChild(viewModel.nodes()[2]);
  220. viewModel.rebuild();
  221. expect(viewModel.nodes().length).toEqual(5);
  222. expect(viewModel.nodes()[1].meta_links().length).toEqual(1);
  223. expect(viewModel.nodes()[1].meta_links()[0].name()).toEqual("error");
  224. expect(viewModel.nodes()[1].meta_links()[0].parent()).toEqual(viewModel.nodes()[1].id());
  225. expect(viewModel.nodes()[1].meta_links()[0].child()).toEqual(viewModel.nodes()[2].id());
  226. });
  227. it("Should be able to get error node", function() {
  228. viewModel.nodes()[1].putErrorChild(viewModel.nodes()[2]);
  229. viewModel.rebuild();
  230. expect(viewModel.nodes().length).toEqual(5);
  231. expect(viewModel.nodes()[1].getErrorChild().id()).toEqual(viewModel.nodes()[2].id());
  232. });
  233. });
  234. // describe("Node movement", function(){
  235. // it("Should be able to move a node up", function() {
  236. // });
  237. // it("Should be able to move a node down", function() {
  238. // });
  239. // it("Should be able to create a fork", function() {
  240. // });
  241. // it("Should be able to create a decision", function() {
  242. // });
  243. // });
  244. // describe("Node operations", function(){
  245. // it("Should be able to edit a node", function() {
  246. // $('.edit-node-link')[0].click();
  247. // expect($("#node-modal").length).toBeGreaterThan(0);
  248. // });
  249. // it("Should be able to create a node", function() {
  250. // $('.new-node-link[data-node-type=mapreduce]')[0].click();
  251. // expect($("#node-modal").length).toBeGreaterThan(0);
  252. // });
  253. // it("Should be able to clone a node", function() {
  254. // $('.clone-node-link')[0].click();
  255. // expect($("#node-modal").length).toBeGreaterThan(0);
  256. // });
  257. // it("Should be able to remove a node", function() {
  258. // $('.delete-node-btn')[0].click();
  259. // expect($("#node-modal").length).toBeGreaterThan(0);
  260. // });
  261. // });
  262. });