workflow.js 8.0 KB

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