mirroring_controller.js 13 KB

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