coordinator-editor.ko.js 5.1 KB

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