mirroring_controller.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. var misc = require('utils/misc');
  20. App.MainMirroringController = Em.ArrayController.extend({
  21. name: 'mainMirroringController',
  22. datasetsData: [],
  23. // formatted data for targetClusterMapper
  24. clustersData: {},
  25. // counter for datasets load queries
  26. datasetCount: 0,
  27. // counter for target cluster load queries
  28. clusterCount: 0,
  29. datasets: [],
  30. isDatasetsLoaded: false,
  31. isTargetClustersLoaded: false,
  32. isLoaded: function () {
  33. return this.get('isDatasetsLoaded') && this.get('isTargetClustersLoaded');
  34. }.property('isDatasetsLoaded', 'isTargetClustersLoaded'),
  35. loadData: function () {
  36. this.set('isDatasetsLoaded', false);
  37. this.set('isTargetClustersLoaded', false);
  38. this.get('datasetsData').clear();
  39. this.set('clustersData', {});
  40. this.set('datasetCount', 0);
  41. this.set('clusterCount', 0);
  42. this.set('datasets', []);
  43. this.loadDatasets();
  44. this.loadClusters();
  45. },
  46. loadDatasets: function () {
  47. App.ajax.send({
  48. name: 'mirroring.get_all_entities',
  49. sender: this,
  50. data: {
  51. type: 'feed'
  52. },
  53. success: 'onLoadDatasetsListSuccess',
  54. error: 'onLoadDatasetsListError'
  55. });
  56. },
  57. onLoadDatasetsListSuccess: function (data) {
  58. if (data && data.entity) {
  59. this.set('datasetCount', data.entity.length);
  60. data.entity.mapProperty('name').forEach(function (dataset) {
  61. App.ajax.send({
  62. name: 'mirroring.get_definition',
  63. sender: this,
  64. data: {
  65. name: dataset,
  66. type: 'feed'
  67. },
  68. success: 'onLoadDatasetDefinitionSuccess',
  69. error: 'onLoadDatasetDefinitionError'
  70. });
  71. }, this);
  72. } else {
  73. this.onLoadDatasetsListError();
  74. }
  75. },
  76. onLoadDatasetsListError: function () {
  77. console.error('Failed to load datasets list.');
  78. },
  79. onLoadDatasetDefinitionSuccess: function (data) {
  80. var parsedData = misc.xmlToObject(data);
  81. var clusters = parsedData.feed.clusters;
  82. var targetCluster, sourceCluster;
  83. if (clusters.cluster[0].locations) {
  84. targetCluster = clusters.cluster[0];
  85. sourceCluster = clusters.cluster[1];
  86. } else {
  87. targetCluster = clusters.cluster[1];
  88. sourceCluster = clusters.cluster[0];
  89. }
  90. this.get('datasetsData').push(
  91. Ember.Object.create({
  92. name: parsedData.feed['@attributes'].name,
  93. sourceClusterName: sourceCluster['@attributes'].name,
  94. targetClusterName: targetCluster['@attributes'].name,
  95. sourceDir: parsedData.feed.locations.location['@attributes'].path,
  96. targetDir: targetCluster.locations.location['@attributes'].path,
  97. frequency: parsedData.feed.frequency['#text'].match(/\d/)[0],
  98. frequencyUnit: parsedData.feed.frequency['#text'].match(/\w+(?=\()/)[0],
  99. scheduleEndDate: sourceCluster.validity['@attributes'].end,
  100. scheduleStartDate: sourceCluster.validity['@attributes'].start,
  101. instances: []
  102. })
  103. );
  104. App.ajax.send({
  105. name: 'mirroring.dataset.get_all_instances',
  106. sender: this,
  107. data: {
  108. dataset: parsedData.feed['@attributes'].name
  109. },
  110. success: 'onLoadDatasetInstancesSuccess',
  111. error: 'onLoadDatasetsInstancesError'
  112. });
  113. },
  114. onLoadDatasetDefinitionError: function () {
  115. console.error('Failed to load dataset definition.');
  116. },
  117. onLoadDatasetInstancesSuccess: function (data, sender, opts) {
  118. var datasetJobs = [];
  119. var datasetsData = this.get('datasetsData');
  120. data.instances.forEach(function (instance) {
  121. datasetJobs.push({
  122. dataset: opts.dataset,
  123. id: instance.instance,
  124. status: instance.status,
  125. endTime: new Date(instance.endTime).getTime(),
  126. startTime: new Date(instance.startTime).getTime()
  127. });
  128. }, this);
  129. datasetsData.findProperty('name', opts.dataset).set('instances', datasetJobs);
  130. this.set('datasetCount', this.get('datasetCount') - 1);
  131. var sortedDatasets = [];
  132. if (this.get('datasetCount') < 1) {
  133. App.dataSetMapper.map(datasetsData);
  134. sortedDatasets = App.Dataset.find().toArray().sort(function (a, b) {
  135. if (a.get('name') < b.get('name')) return -1;
  136. if (a.get('name') > b.get('name')) return 1;
  137. return 0;
  138. });
  139. this.set('datasets', sortedDatasets);
  140. this.set('isDatasetsLoaded', true);
  141. var selectedDataset = this.get('selectedDataset');
  142. if (!selectedDataset) {
  143. this.set('selectedDataset', sortedDatasets[0]);
  144. }
  145. }
  146. },
  147. onLoadDatasetsInstancesError: function () {
  148. console.error('Failed to load dataset instances.');
  149. },
  150. loadClusters: function () {
  151. App.ajax.send({
  152. name: 'mirroring.get_all_entities',
  153. sender: this,
  154. data: {
  155. type: 'cluster'
  156. },
  157. success: 'onLoadClustersListSuccess',
  158. error: 'onLoadClustersListError'
  159. });
  160. },
  161. onLoadClustersListSuccess: function (data) {
  162. if (data && data.entity) {
  163. this.set('clusterCount', data.entity.length);
  164. this.set('clustersData.items', [
  165. {
  166. name: App.get('clusterName'),
  167. execute: App.HostComponent.find().findProperty('componentName', 'RESOURCEMANAGER').get('host.hostName') + ':8050',
  168. readonly: 'hftp://' + App.HostComponent.find().findProperty('componentName', 'NAMENODE').get('host.hostName') + ':50070',
  169. workflow: 'http://' + App.HostComponent.find().findProperty('componentName', 'OOZIE_SERVER').get('host.hostName') + ':11000/oozie',
  170. staging: '',
  171. working: '',
  172. temp: ''
  173. }
  174. ]);
  175. data.entity.mapProperty('name').forEach(function (cluster) {
  176. App.ajax.send({
  177. name: 'mirroring.get_definition',
  178. sender: this,
  179. data: {
  180. name: cluster,
  181. type: 'cluster'
  182. },
  183. success: 'onLoadClusterDefinitionSuccess',
  184. error: 'onLoadClusterDefinitionError'
  185. });
  186. }, this);
  187. } else {
  188. this.onLoadClustersListError();
  189. }
  190. },
  191. onLoadClustersListError: function () {
  192. console.error('Failed to load clusters list.');
  193. },
  194. onLoadClusterDefinitionSuccess: function (data) {
  195. var parsedData = misc.xmlToObject(data);
  196. var clustersData = this.get('clustersData');
  197. var interfaces = parsedData.cluster.interfaces.interface;
  198. var locations = parsedData.cluster.locations.location;
  199. var staging = locations.findProperty('@attributes.name', 'staging');
  200. var working = locations.findProperty('@attributes.name', 'working');
  201. var temp = locations.findProperty('@attributes.name', 'temp');
  202. clustersData.items.push(
  203. {
  204. name: parsedData.cluster['@attributes'].name,
  205. execute: interfaces.findProperty('@attributes.type', 'execute')['@attributes'].endpoint,
  206. readonly: interfaces.findProperty('@attributes.type', 'readonly')['@attributes'].endpoint,
  207. workflow: interfaces.findProperty('@attributes.type', 'workflow')['@attributes'].endpoint,
  208. staging: staging && staging['@attributes'].path,
  209. working: working && working['@attributes'].path,
  210. temp: temp && temp['@attributes'].path
  211. }
  212. );
  213. this.set('clusterCount', this.get('clusterCount') - 1);
  214. if (this.get('clusterCount') < 1) {
  215. App.targetClusterMapper.map(clustersData);
  216. this.set('isTargetClustersLoaded', true);
  217. }
  218. },
  219. onLoadClusterDefinitionError: function () {
  220. console.error('Failed to load cluster definition.');
  221. },
  222. onDataLoad: function () {
  223. if (this.get('isLoaded') && App.router.get('currentState.name') === 'index') {
  224. App.router.send('gotoShowJobs');
  225. }
  226. }.observes('isLoaded'),
  227. manageClusters: function () {
  228. var manageClustersController = App.router.get('mainMirroringManageClustersController');
  229. var popup = App.ModalPopup.show({
  230. header: Em.I18n.t('mirroring.dataset.manageClusters'),
  231. bodyClass: App.MainMirroringManageClusterstView.extend({
  232. controller: manageClustersController
  233. }),
  234. primary: Em.I18n.t('common.save'),
  235. secondary: null,
  236. onPrimary: function () {
  237. manageClustersController.save();
  238. },
  239. hide: function () {
  240. App.router.send('gotoShowJobs');
  241. this._super();
  242. },
  243. didInsertElement: function () {
  244. this._super();
  245. this.fitHeight();
  246. }
  247. });
  248. manageClustersController.set('popup', popup);
  249. }
  250. });