coordinator-editor.ko.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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.variables = ko.observableArray([]);
  33. self.variablesUI = ko.observableArray(['parameter', 'input_path', 'output_path']);
  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. 'done_flag': '',
  53. 'timezone': 'America/Los_Angeles',
  54. 'instance_choice': 'default', // is_advanced_start_instance, start_instance, is_advanced_end_instance, end_instance
  55. 'frequency_number': 1,
  56. 'frequency_unit': 'DAYS',
  57. 'start': null,
  58. 'name': '',
  59. 'shared_dataset_uuid': '' // If reusing a shared dataset
  60. };
  61. self.variables.push(ko.mapping.fromJS(_var));
  62. };
  63. self.init = function() {
  64. // load
  65. };
  66. }
  67. var CoordinatorEditorViewModel = function (coordinator_json, credentials_json, workflows_json) {
  68. var self = this;
  69. self.isEditing = ko.observable(true);
  70. self.isEditing.subscribe(function(newVal){
  71. $(document).trigger("editingToggled");
  72. });
  73. self.toggleEditing = function () {
  74. self.isEditing(! self.isEditing());
  75. };
  76. self.workflows = ko.mapping.fromJS(workflows_json);
  77. self.coordinator = new Coordinator(self, coordinator_json);
  78. self.credentials = ko.mapping.fromJS(credentials_json);
  79. self.save = function () {
  80. $.post("/oozie/editor/coordinator/save/", {
  81. "coordinator": ko.mapping.toJSON(self.coordinator)
  82. }, function (data) {
  83. if (data.status == 0) {
  84. self.coordinator.id(data.id);
  85. $(document).trigger("info", data.message);
  86. if (window.location.search.indexOf("coordinator") == -1) {
  87. window.location.hash = '#coordinator=' + data.id;
  88. }
  89. }
  90. else {
  91. $(document).trigger("error", data.message);
  92. }
  93. }).fail(function (xhr, textStatus, errorThrown) {
  94. $(document).trigger("error", xhr.responseText);
  95. });
  96. };
  97. self.gen_xml = function () {
  98. $.post("/oozie/editor/coordinator/gen_xml/", {
  99. "coordinator": ko.mapping.toJSON(self.coordinator)
  100. }, function (data) {
  101. if (data.status == 0) {
  102. console.log(data.xml);
  103. }
  104. else {
  105. $(document).trigger("error", data.message);
  106. }
  107. }).fail(function (xhr, textStatus, errorThrown) {
  108. $(document).trigger("error", xhr.responseText);
  109. });
  110. };
  111. self.import_coordinators = function () {
  112. $.post("/oozie/editor/coordinator/import_coordinators/", {
  113. }, function (data) {
  114. if (data.status == 0) {
  115. console.log(data.json);
  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.showSubmitPopup = function () {
  125. // If self.coordinator.id() == null, need to save wf for now
  126. $.get("/oozie/editor/coordinator/submit/" + self.coordinator.id(), {
  127. }, function (data) {
  128. $(document).trigger("showSubmitPopup", data);
  129. }).fail(function (xhr, textStatus, errorThrown) {
  130. $(document).trigger("error", xhr.responseText);
  131. });
  132. };
  133. };