jobs_controller.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. App.MainDatasetJobsController = Em.Controller.extend({
  20. name: 'mainDatasetJobsController',
  21. suspend: function () {
  22. App.ajax.send({
  23. name: 'mirroring.suspend_entity',
  24. sender: this,
  25. data: {
  26. name: this.get('content.prefixedName'),
  27. type: 'feed',
  28. falconServer: App.get('falconServerURL')
  29. },
  30. success: 'onSuspendSuccess',
  31. error: 'onError'
  32. });
  33. },
  34. onSuspendSuccess: function() {
  35. this.set('content.status', 'SUSPENDED');
  36. this.get('content.datasetJobs').filterProperty('status', 'RUNNING').setEach('status', 'SUSPENDED');
  37. },
  38. resume: function () {
  39. App.ajax.send({
  40. name: 'mirroring.resume_entity',
  41. sender: this,
  42. data: {
  43. name: this.get('content.prefixedName'),
  44. type: 'feed',
  45. falconServer: App.get('falconServerURL')
  46. },
  47. success: 'onResumeSuccess',
  48. error: 'onError'
  49. });
  50. },
  51. onResumeSuccess: function() {
  52. this.set('content.status', 'RUNNING');
  53. this.get('content.datasetJobs').filterProperty('status', 'SUSPENDED').setEach('status', 'RUNNING');
  54. },
  55. schedule: function () {
  56. App.ajax.send({
  57. name: 'mirroring.schedule_entity',
  58. sender: this,
  59. data: {
  60. name: this.get('content.prefixedName'),
  61. type: 'feed',
  62. falconServer: App.get('falconServerURL')
  63. },
  64. success: 'onScheduleSuccess',
  65. error: 'onError'
  66. });
  67. },
  68. onScheduleSuccess: function() {
  69. this.set('content.status', 'RUNNING');
  70. },
  71. delete: function () {
  72. var self = this;
  73. App.showConfirmationPopup(function () {
  74. App.ajax.send({
  75. name: 'mirroring.delete_entity',
  76. sender: self,
  77. data: {
  78. name: self.get('content.prefixedName'),
  79. type: 'feed',
  80. falconServer: App.get('falconServerURL')
  81. },
  82. success: 'onDeleteSuccess',
  83. error: 'onError'
  84. });
  85. });
  86. },
  87. onDeleteSuccess: function() {
  88. var dataset = this.get('content');
  89. dataset.deleteRecord();
  90. App.store.commit();
  91. dataset.get('stateManager').transitionTo('loading');
  92. this.set('content', null);
  93. App.router.get('mainMirroringController').set('selectedDataset', null);
  94. App.router.send('gotoShowJobs');
  95. },
  96. suspendInstance: function (event) {
  97. App.ajax.send({
  98. name: 'mirroring.suspend_instance',
  99. sender: this,
  100. data: {
  101. feed: this.get('content.prefixedName'),
  102. name: event.context.get('name'),
  103. job: event.context,
  104. falconServer: App.get('falconServerURL')
  105. },
  106. success: 'onSuspendInstanceSuccess',
  107. error: 'onError'
  108. });
  109. },
  110. onSuspendInstanceSuccess: function () {
  111. this.get('content.datasetJobs').filterProperty('name', arguments[2].name).setEach('status', 'SUSPENDED');
  112. },
  113. resumeInstance: function (event) {
  114. App.ajax.send({
  115. name: 'mirroring.resume_instance',
  116. sender: this,
  117. data: {
  118. feed: this.get('content.prefixedName'),
  119. name: event.context.get('name'),
  120. job: event.context,
  121. falconServer: App.get('falconServerURL')
  122. },
  123. success: 'onResumeInstanceSuccess',
  124. error: 'onError'
  125. });
  126. },
  127. onResumeInstanceSuccess: function () {
  128. this.get('content.datasetJobs').filterProperty('name', arguments[2].name).setEach('status', 'RUNNING');
  129. },
  130. killInstance: function (event) {
  131. App.ajax.send({
  132. name: 'mirroring.kill_instance',
  133. sender: this,
  134. data: {
  135. feed: this.get('content.prefixedName'),
  136. name: event.context.get('name'),
  137. job: event.context,
  138. falconServer: App.get('falconServerURL')
  139. },
  140. success: 'onKillInstanceSuccess',
  141. error: 'onError'
  142. });
  143. },
  144. onKillInstanceSuccess: function () {
  145. this.get('content.datasetJobs').filterProperty('name', arguments[2].name).setEach('status', 'KILLED');
  146. },
  147. onError: function () {
  148. App.showAlertPopup(Em.I18n.t('common.error'), arguments[2]);
  149. },
  150. downloadEntity: function () {
  151. var xml = this.formatDatasetXML(this.get('content'));
  152. if ($.browser.msie && $.browser.version < 10) {
  153. this.openInfoInNewTab(xml);
  154. } else {
  155. try {
  156. var blob = new Blob([xml], {type: 'text/xml;charset=utf-8;'});
  157. saveAs(blob, Em.I18n.t('mirroring.dataset.entity') + '.xml');
  158. } catch (e) {
  159. this.openInfoInNewTab(xml);
  160. }
  161. }
  162. },
  163. openInfoInNewTab: function (xml) {
  164. var newWindow = window.open('');
  165. var newDocument = newWindow.document;
  166. newDocument.write('<pre>' + xml + '</pre>');
  167. newWindow.focus();
  168. },
  169. formatDatasetXML: function (dataset) {
  170. return '<?xml version="1.0"?>\n' + '<feed description="" name="' + dataset.get('name') + '" xmlns="uri:falcon:feed:0.1">\n' +
  171. '<frequency>' + dataset.get('frequencyUnit') + '(' + dataset.get('frequency') + ')' + '</frequency>\n' +
  172. '<clusters>\n<cluster name="' + dataset.get('sourceClusterName') + '" type="source">\n' +
  173. '<validity start="' + dataset.get('scheduleStartDate') + '" end="' + dataset.get('scheduleEndDate') + '"/>\n' +
  174. '<retention limit="days(7)" action="delete"/>\n</cluster>\n<cluster name="' + dataset.get('targetClusterName') +
  175. '" type="target">\n<validity start="' + dataset.get('scheduleStartDate') + '" end="' + dataset.get('scheduleEndDate') + '"/>\n' +
  176. '<retention limit="months(1)" action="delete"/>\n<locations>\n<location type="data" path="' + dataset.get('targetDir') + '" />\n' +
  177. '</locations>\n</cluster>\n</clusters>\n<locations>\n<location type="data" path="' + dataset.get('sourceDir') + '" />\n' +
  178. '</locations>\n<ACL owner="hue" group="users" permission="0755" />\n<schema location="/none" provider="none"/>\n</feed>';
  179. }
  180. });