coordinator-editor.ko.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. var Dataset = function (vm, dataset) {
  17. var self = this;
  18. }
  19. var InputDataset = function (vm, input_dataset) {
  20. var self = this;
  21. }
  22. var OutputDataset = function (vm, output_dataset) {
  23. var self = this;
  24. }
  25. var Coordinator = function (vm, coordinator) {
  26. var self = this;
  27. self.id = ko.observable(typeof coordinator.id != "undefined" && coordinator.id != null ? coordinator.id : null);
  28. self.uuid = ko.observable(typeof coordinator.uuid != "undefined" && coordinator.uuid != null ? coordinator.uuid : UUID());
  29. self.name = ko.observable(typeof coordinator.name != "undefined" && coordinator.name != null ? coordinator.name : "");
  30. self.properties = ko.mapping.fromJS(typeof coordinator.properties != "undefined" && coordinator.properties != null ? coordinator.properties : {});
  31. self.variables = ko.mapping.fromJS(typeof coordinator.variables != "undefined" && coordinator.variables != null ? coordinator.variables : []);
  32. self.variablesUI = ko.observableArray(['parameter', 'input_path', 'output_path']);
  33. self.properties.workflow.subscribe(function(newVal) {
  34. if (newVal) {
  35. $.get("/desktop/api2/doc/get", {
  36. "uuid": self.properties.workflow()
  37. }, function (data) {
  38. // set wf
  39. }).fail(function (xhr, textStatus, errorThrown) {
  40. $(document).trigger("error", xhr.responseText);
  41. });
  42. }
  43. });
  44. self.addVariable = function() {
  45. var _var = {
  46. 'workflow_variable': '',
  47. 'dataset_type': 'parameter',
  48. 'uuid': UUID(),
  49. 'dataset_variable': '',
  50. 'show_advanced': false,
  51. 'done_flag': '',
  52. 'timezone': 'America/Los_Angeles',
  53. 'instance_choice': 'default',
  54. 'is_advanced_start_instance': false,
  55. 'start_instance': '0',
  56. 'advanced_start_instance': '${coord:current(0)}',
  57. 'is_advanced_end_instance': false,
  58. 'advanced_end_instance': '${coord:current(0)}',
  59. 'end_instance': '0',
  60. 'frequency_number': 1,
  61. 'frequency_unit': 'DAYS',
  62. 'start': new Date(),
  63. 'shared_dataset_uuid': '' // If reusing a shared dataset
  64. };
  65. self.variables.push(ko.mapping.fromJS(_var));
  66. };
  67. self.init = function() {
  68. // load
  69. };
  70. }
  71. var CoordinatorEditorViewModel = function (coordinator_json, credentials_json, workflows_json) {
  72. var self = this;
  73. self.isEditing = ko.observable(true);
  74. self.isEditing.subscribe(function(newVal){
  75. $(document).trigger("editingToggled");
  76. });
  77. self.toggleEditing = function () {
  78. self.isEditing(! self.isEditing());
  79. };
  80. self.workflows = ko.mapping.fromJS(workflows_json);
  81. self.coordinator = new Coordinator(self, coordinator_json);
  82. self.credentials = ko.mapping.fromJS(credentials_json);
  83. self.save = function () {
  84. $.post("/oozie/editor/coordinator/save/", {
  85. "coordinator": ko.mapping.toJSON(self.coordinator)
  86. }, function (data) {
  87. if (data.status == 0) {
  88. self.coordinator.id(data.id);
  89. $(document).trigger("info", data.message);
  90. if (window.location.search.indexOf("coordinator") == -1) {
  91. window.location.hash = '#coordinator=' + data.id;
  92. }
  93. }
  94. else {
  95. $(document).trigger("error", data.message);
  96. }
  97. }).fail(function (xhr, textStatus, errorThrown) {
  98. $(document).trigger("error", xhr.responseText);
  99. });
  100. };
  101. self.gen_xml = function () {
  102. $(".jHueNotify").hide();
  103. logGA('gen_xml');
  104. $.post("/oozie/editor/coordinator/gen_xml/", {
  105. "coordinator": ko.mapping.toJSON(self.coordinator)
  106. }, function (data) {
  107. if (data.status == 0) {
  108. console.log(data.xml);
  109. }
  110. else {
  111. $(document).trigger("error", data.message);
  112. }
  113. }).fail(function (xhr, textStatus, errorThrown) {
  114. $(document).trigger("error", xhr.responseText);
  115. });
  116. };
  117. self.import_coordinators = function () {
  118. $.post("/oozie/editor/coordinator/import_coordinators/", {
  119. }, function (data) {
  120. if (data.status == 0) {
  121. console.log(data.json);
  122. }
  123. else {
  124. $(document).trigger("error", data.message);
  125. }
  126. }).fail(function (xhr, textStatus, errorThrown) {
  127. $(document).trigger("error", xhr.responseText);
  128. });
  129. };
  130. self.showSubmitPopup = function () {
  131. // If self.coordinator.id() == null, need to save wf for now
  132. $.get("/oozie/editor/coordinator/submit/" + self.coordinator.id(), {
  133. }, function (data) {
  134. $(document).trigger("showSubmitPopup", data);
  135. }).fail(function (xhr, textStatus, errorThrown) {
  136. $(document).trigger("error", xhr.responseText);
  137. });
  138. };
  139. };
  140. function logGA(page) {
  141. if (typeof trackOnGA == 'function') {
  142. trackOnGA('oozie/editor/coordinator/' + page);
  143. }
  144. }