mirroring_controller.js 13 KB

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