coordinator-editor.ko.js 5.7 KB

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