mirroring_controller.js 13 KB

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