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