mirroring_controller.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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().sortProperty('name');
  146. this.set('isDatasetsLoaded', true);
  147. var selectedDataset = this.get('selectedDataset');
  148. if (!selectedDataset) {
  149. this.set('selectedDataset', sortedDatasets[0]);
  150. }
  151. }
  152. },
  153. onLoadDatasetsInstancesError: function () {
  154. console.error('Failed to load dataset instances.');
  155. },
  156. loadClusters: function () {
  157. App.ajax.send({
  158. name: 'mirroring.get_all_entities',
  159. sender: this,
  160. data: {
  161. type: 'cluster',
  162. falconServer: App.get('falconServerURL')
  163. },
  164. success: 'onLoadClustersListSuccess',
  165. error: 'onLoadClustersListError'
  166. });
  167. },
  168. onLoadClustersListSuccess: function (data) {
  169. var clustersData = this.get('clustersData');
  170. clustersData.items = [];
  171. var parsedData = misc.xmlToObject(data);
  172. var clusters = parsedData.entities.entity;
  173. if (data && clusters) {
  174. clusters = Em.isArray(clusters) ? clusters : [clusters];
  175. this.set('clusterCount', clusters.length);
  176. clusters.mapProperty('name.#text').forEach(function (cluster) {
  177. App.ajax.send({
  178. name: 'mirroring.get_definition',
  179. sender: this,
  180. data: {
  181. name: cluster,
  182. type: 'cluster',
  183. falconServer: App.get('falconServerURL')
  184. },
  185. success: 'onLoadClusterDefinitionSuccess',
  186. error: 'onLoadClusterDefinitionError'
  187. });
  188. }, this);
  189. } else {
  190. var sourceCluster = Ember.Object.create({
  191. name: App.get('clusterName'),
  192. execute: App.HostComponent.find().findProperty('componentName', 'RESOURCEMANAGER').get('host.hostName') + ':8050',
  193. readonly: 'hftp://' + App.HostComponent.find().findProperty('componentName', 'NAMENODE').get('host.hostName') + ':50070',
  194. workflow: 'http://' + App.HostComponent.find().findProperty('componentName', 'OOZIE_SERVER').get('host.hostName') + ':11000/oozie',
  195. staging: '/apps/falcon/sandbox/staging',
  196. working: '/apps/falcon/sandbox/working',
  197. temp: '/tmp'
  198. });
  199. var sourceClusterData = App.router.get('mainMirroringManageClustersController').formatClusterXML(sourceCluster);
  200. App.ajax.send({
  201. name: 'mirroring.submit_entity',
  202. sender: this,
  203. data: {
  204. type: 'cluster',
  205. entity: sourceClusterData,
  206. falconServer: App.get('falconServerURL')
  207. },
  208. success: 'onSourceClusterCreateSuccess',
  209. error: 'onSourceClusterCreateError'
  210. });
  211. clustersData.items.push(sourceCluster);
  212. }
  213. },
  214. onLoadClustersListError: function () {
  215. console.error('Failed to load clusters list.');
  216. },
  217. onSourceClusterCreateSuccess: function () {
  218. App.targetClusterMapper.map(this.get('clustersData'));
  219. this.set('isTargetClustersLoaded', true);
  220. },
  221. onSourceClusterCreateError: function () {
  222. console.error('Error in creating source cluster entity.');
  223. },
  224. onLoadClusterDefinitionSuccess: function (data) {
  225. var parsedData = misc.xmlToObject(data);
  226. var clustersData = this.get('clustersData');
  227. var interfaces = parsedData.cluster.interfaces.interface;
  228. var locations = parsedData.cluster.locations.location;
  229. var staging = locations.findProperty('@attributes.name', 'staging');
  230. var working = locations.findProperty('@attributes.name', 'working');
  231. var temp = locations.findProperty('@attributes.name', 'temp');
  232. clustersData.items.push(
  233. {
  234. name: parsedData.cluster['@attributes'].name,
  235. execute: interfaces.findProperty('@attributes.type', 'execute')['@attributes'].endpoint,
  236. readonly: interfaces.findProperty('@attributes.type', 'readonly')['@attributes'].endpoint,
  237. workflow: interfaces.findProperty('@attributes.type', 'workflow')['@attributes'].endpoint,
  238. staging: staging && staging['@attributes'].path,
  239. working: working && working['@attributes'].path,
  240. temp: temp && temp['@attributes'].path
  241. }
  242. );
  243. this.set('clusterCount', this.get('clusterCount') - 1);
  244. if (this.get('clusterCount') < 1) {
  245. App.targetClusterMapper.map(clustersData);
  246. this.set('isTargetClustersLoaded', true);
  247. }
  248. },
  249. onLoadClusterDefinitionError: function () {
  250. console.error('Failed to load cluster definition.');
  251. },
  252. onDataLoad: function () {
  253. if (this.get('isLoaded') && App.router.get('currentState.name') === 'index') {
  254. App.router.send('gotoShowJobs');
  255. }
  256. }.observes('isLoaded'),
  257. manageClusters: function () {
  258. var self = this;
  259. var manageClustersController = App.router.get('mainMirroringManageClustersController');
  260. var popup = App.ModalPopup.show({
  261. header: Em.I18n.t('mirroring.dataset.manageClusters'),
  262. bodyClass: App.MainMirroringManageClusterstView.extend({
  263. controller: manageClustersController
  264. }),
  265. primary: Em.I18n.t('common.save'),
  266. secondary: null,
  267. onPrimary: function () {
  268. manageClustersController.save();
  269. },
  270. hide: function () {
  271. self.loadData();
  272. App.router.send('gotoShowJobs');
  273. this._super();
  274. },
  275. didInsertElement: function () {
  276. this._super();
  277. this.fitHeight();
  278. }
  279. });
  280. manageClustersController.set('popup', popup);
  281. }
  282. });