mirroring_controller.js 11 KB

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