mirroring_controller.js 13 KB

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