mirroring_controller.js 13 KB

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