mirroring_controller.js 11 KB

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