mirroring_controller.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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 defaultFS = this.loadDefaultFS();
  191. var sourceCluster = Ember.Object.create({
  192. name: App.get('clusterName'),
  193. execute: App.HostComponent.find().findProperty('componentName', 'RESOURCEMANAGER').get('host.hostName') + ':8050',
  194. readonly: 'hftp://' + App.HostComponent.find().findProperty('componentName', 'NAMENODE').get('host.hostName') + ':50070',
  195. workflow: 'http://' + App.HostComponent.find().findProperty('componentName', 'OOZIE_SERVER').get('host.hostName') + ':11000/oozie',
  196. write: defaultFS,
  197. staging: '/apps/falcon/sandbox/staging',
  198. working: '/apps/falcon/sandbox/working',
  199. temp: '/tmp'
  200. });
  201. var sourceClusterData = App.router.get('mainMirroringManageClustersController').formatClusterXML(sourceCluster);
  202. App.ajax.send({
  203. name: 'mirroring.submit_entity',
  204. sender: this,
  205. data: {
  206. type: 'cluster',
  207. entity: sourceClusterData,
  208. falconServer: App.get('falconServerURL')
  209. },
  210. success: 'onSourceClusterCreateSuccess',
  211. error: 'onSourceClusterCreateError'
  212. });
  213. clustersData.items.push(sourceCluster);
  214. }
  215. },
  216. /**
  217. * Return fs.defaultFS config property loaded from server
  218. * @return {String}
  219. */
  220. loadDefaultFS: function () {
  221. App.ajax.send({
  222. name: 'config.tags.sync',
  223. sender: this,
  224. success: 'onLoadConfigTagsSuccess',
  225. error: 'onLoadConfigTagsError'
  226. });
  227. var configs = App.router.get('configurationController').getConfigsByTags([
  228. {
  229. siteName: "core-site",
  230. tagName: this.get('tag')
  231. }
  232. ]);
  233. return configs[0].properties['fs.defaultFS'];
  234. },
  235. // Loaded core-site tag version
  236. tag: null,
  237. onLoadConfigTagsSuccess: function (data) {
  238. this.set('tag', data.Clusters.desired_configs['core-site'].tag);
  239. },
  240. onLoadConfigTagsError: function () {
  241. console.error('Error in loading fs.defaultFS');
  242. },
  243. onLoadClustersListError: function () {
  244. console.error('Failed to load clusters list.');
  245. },
  246. onSourceClusterCreateSuccess: function () {
  247. App.targetClusterMapper.map(this.get('clustersData'));
  248. this.set('isTargetClustersLoaded', true);
  249. },
  250. onSourceClusterCreateError: function () {
  251. console.error('Error in creating source cluster entity.');
  252. },
  253. onLoadClusterDefinitionSuccess: function (data) {
  254. var parsedData = misc.xmlToObject(data);
  255. var clustersData = this.get('clustersData');
  256. var interfaces = parsedData.cluster.interfaces.interface;
  257. var locations = parsedData.cluster.locations.location;
  258. var staging = locations.findProperty('@attributes.name', 'staging');
  259. var working = locations.findProperty('@attributes.name', 'working');
  260. var temp = locations.findProperty('@attributes.name', 'temp');
  261. clustersData.items.push(
  262. {
  263. name: parsedData.cluster['@attributes'].name,
  264. execute: interfaces.findProperty('@attributes.type', 'execute')['@attributes'].endpoint,
  265. readonly: interfaces.findProperty('@attributes.type', 'readonly')['@attributes'].endpoint,
  266. workflow: interfaces.findProperty('@attributes.type', 'workflow')['@attributes'].endpoint,
  267. write: interfaces.findProperty('@attributes.type', 'write')['@attributes'].endpoint,
  268. staging: staging && staging['@attributes'].path,
  269. working: working && working['@attributes'].path,
  270. temp: temp && temp['@attributes'].path
  271. }
  272. );
  273. this.set('clusterCount', this.get('clusterCount') - 1);
  274. if (this.get('clusterCount') < 1) {
  275. App.targetClusterMapper.map(clustersData);
  276. this.set('isTargetClustersLoaded', true);
  277. }
  278. },
  279. onLoadClusterDefinitionError: function () {
  280. console.error('Failed to load cluster definition.');
  281. },
  282. onDataLoad: function () {
  283. // Open default dataset job route if mirroring route is opened
  284. if (this.get('isLoaded') && App.router.get('currentState.parentState.name') === 'mirroring') {
  285. App.router.send('gotoShowJobs');
  286. }
  287. }.observes('isLoaded'),
  288. manageClusters: function () {
  289. var self = this;
  290. App.ModalPopup.show({
  291. header: Em.I18n.t('mirroring.dataset.manageClusters'),
  292. classNames: ['sixty-percent-width-modal'],
  293. bodyClass: App.MainMirroringManageClusterstView.extend({
  294. controller: App.router.get('mainMirroringManageClustersController')
  295. }),
  296. primary: null,
  297. secondary: Em.I18n.t('common.close'),
  298. hide: function () {
  299. self.loadData();
  300. App.router.send('gotoShowJobs');
  301. this._super();
  302. },
  303. didInsertElement: function () {
  304. this._super();
  305. this.fitHeight();
  306. }
  307. });
  308. }
  309. });