coordinator-editor.ko.js 6.0 KB

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