add_controller.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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. App.AddServiceController = App.WizardController.extend(App.AddSecurityConfigs, {
  20. name: 'addServiceController',
  21. totalSteps: 8,
  22. /**
  23. * @type {string}
  24. */
  25. displayName: Em.I18n.t('services.add.header'),
  26. /**
  27. * Used for hiding back button in wizard
  28. */
  29. hideBackButton: true,
  30. /**
  31. * @type {string}
  32. * @default null
  33. */
  34. serviceToInstall: null,
  35. /**
  36. *
  37. */
  38. installClientQueueLength: 0,
  39. areInstalledConfigGroupsLoaded: false,
  40. /**
  41. * All wizards data will be stored in this variable
  42. *
  43. * cluster - cluster name
  44. * installOptions - ssh key, repo info, etc.
  45. * services - services list
  46. * hosts - list of selected hosts
  47. * slaveComponentHosts, - info about slave hosts
  48. * masterComponentHosts - info about master hosts
  49. * config??? - to be described later
  50. */
  51. content: Em.Object.create({
  52. cluster: null,
  53. hosts: null,
  54. installOptions: null,
  55. services: null,
  56. slaveComponentHosts: null,
  57. masterComponentHosts: null,
  58. serviceConfigProperties: null,
  59. advancedServiceConfig: null,
  60. controllerName: 'addServiceController',
  61. configGroups: [],
  62. clients: [],
  63. additionalClients: [],
  64. installedHosts: {}
  65. }),
  66. loadMap: {
  67. '1': [
  68. {
  69. type: 'sync',
  70. callback: function () {
  71. this.loadServices();
  72. }
  73. }
  74. ],
  75. '2': [
  76. {
  77. type: 'async',
  78. callback: function () {
  79. var dfd = $.Deferred();
  80. var self = this;
  81. this.loadHosts().done(function () {
  82. self.loadMasterComponentHosts();
  83. self.load('hosts');
  84. self.loadRecommendations();
  85. dfd.resolve();
  86. });
  87. return dfd.promise();
  88. }
  89. }
  90. ],
  91. '3': [
  92. {
  93. type: 'async',
  94. callback: function () {
  95. var dfd = $.Deferred();
  96. var self = this;
  97. this.loadHosts().done(function () {
  98. self.loadServices();
  99. self.loadClients();
  100. self.loadSlaveComponentHosts();//depends on loadServices
  101. dfd.resolve();
  102. });
  103. return dfd.promise();
  104. }
  105. }
  106. ],
  107. '4': [
  108. {
  109. type: 'async',
  110. callback: function () {
  111. var self = this;
  112. var dfd = $.Deferred();
  113. this.loadKerberosDescriptorConfigs().done(function() {
  114. self.loadConfigThemes().then(function() {
  115. dfd.resolve();
  116. });
  117. self.loadServiceConfigGroups();
  118. self.loadServiceConfigProperties();
  119. self.loadCurrentHostGroups();
  120. });
  121. return dfd.promise();
  122. }
  123. }
  124. ],
  125. '5': [
  126. {
  127. type: 'sync',
  128. callback: function () {
  129. this.checkSecurityStatus();
  130. this.load('cluster');
  131. this.set('content.additionalClients', []);
  132. this.set('installClientQueueLength', 0);
  133. this.set('installClietsQueue', App.ajaxQueue.create({abortOnError: false}));
  134. }
  135. }
  136. ]
  137. },
  138. setCurrentStep: function (currentStep, completed) {
  139. this._super(currentStep, completed);
  140. App.clusterStatus.setClusterStatus({
  141. wizardControllerName: this.get('name'),
  142. localdb: App.db.data
  143. });
  144. },
  145. loadCurrentHostGroups: function () {
  146. this.set("content.recommendationsHostGroups", this.getDBProperty('recommendationsHostGroups'));
  147. },
  148. /**
  149. * Load services data. Will be used at <code>Select services(step4)</code> step
  150. */
  151. loadServices: function () {
  152. var services = this.getDBProperty('services');
  153. if (!services) {
  154. services = {
  155. selectedServices: [],
  156. installedServices: []
  157. };
  158. App.StackService.find().forEach(function (item) {
  159. var isInstalled = App.Service.find().someProperty('id', item.get('serviceName'));
  160. var isSelected = (item.get('serviceName') == this.get('serviceToInstall')) || item.get('coSelectedServices').contains(this.get('serviceToInstall'));
  161. item.set('isSelected', isInstalled || isSelected);
  162. item.set('isInstalled', isInstalled);
  163. if (isInstalled) {
  164. services.selectedServices.push(item.get('serviceName'));
  165. services.installedServices.push(item.get('serviceName'));
  166. } else if(isSelected) {
  167. services.selectedServices.push(item.get('serviceName'));
  168. }
  169. }, this);
  170. this.setDBProperty('services', services);
  171. } else {
  172. App.StackService.find().forEach(function (item) {
  173. var isSelected = services.selectedServices.contains(item.get('serviceName')) || item.get('serviceName') == this.get('serviceToInstall');
  174. var isInstalled = services.installedServices.contains(item.get('serviceName'));
  175. item.set('isSelected', isSelected || (this.get("currentStep") == "1" ? isInstalled : isSelected));
  176. item.set('isInstalled', isInstalled);
  177. }, this);
  178. this.setSkipSlavesStep(App.StackService.find().filterProperty('isSelected').filterProperty('isInstalled', false), 3);
  179. }
  180. this.set('serviceToInstall', null);
  181. this.set('content.services', App.StackService.find());
  182. },
  183. /**
  184. * Save data to model
  185. * @param stepController App.WizardStep4Controller
  186. */
  187. saveServices: function (stepController) {
  188. var services = {
  189. selectedServices: [],
  190. installedServices: []
  191. };
  192. var selectedServices = stepController.get('content').filterProperty('isSelected', true).filterProperty('isInstalled', false);
  193. var selectedServiceNames = selectedServices.mapProperty('serviceName');
  194. services.selectedServices.pushObjects(selectedServiceNames);
  195. services.installedServices.pushObjects(stepController.get('content').filterProperty('isInstalled', true).mapProperty('serviceName'));
  196. // save services that already installed but ignored on choose services page
  197. // these services marked by `isInstallable` flag with value `false`, for example `Kerberos` service
  198. services.installedServices.pushObjects(App.Service.find().mapProperty('serviceName').filter(function(serviceName) {
  199. return !services.installedServices.contains(serviceName);
  200. }));
  201. this.setDBProperty('services', services);
  202. this.set('content.selectedServiceNames', selectedServiceNames);
  203. this.setDBProperty('selectedServiceNames', selectedServiceNames);
  204. this.setSkipSlavesStep(selectedServices, 3);
  205. },
  206. /**
  207. * Save Master Component Hosts data to Main Controller
  208. * @param stepController App.WizardStep5Controller
  209. */
  210. saveMasterComponentHosts: function (stepController) {
  211. var obj = stepController.get('selectedServicesMasters');
  212. var masterComponentHosts = [];
  213. var installedComponents = App.HostComponent.find();
  214. obj.forEach(function (_component) {
  215. var installedComponent = installedComponents.findProperty('componentName', _component.component_name);
  216. masterComponentHosts.push({
  217. display_name: _component.display_name,
  218. component: _component.component_name,
  219. hostName: _component.selectedHost,
  220. serviceId: _component.serviceId,
  221. isInstalled: !!installedComponent,
  222. workStatus: installedComponent && installedComponent.get('workStatus')
  223. });
  224. });
  225. this.setDBProperty('masterComponentHosts', masterComponentHosts);
  226. this.set('content.masterComponentHosts', masterComponentHosts);
  227. this.set('content.skipMasterStep', this.get('content.masterComponentHosts').everyProperty('isInstalled', true));
  228. this.get('isStepDisabled').findProperty('step', 2).set('value', this.get('content.skipMasterStep'));
  229. },
  230. /**
  231. * Load master component hosts data for using in required step controllers
  232. */
  233. loadMasterComponentHosts: function () {
  234. this._super();
  235. this.set('content.skipMasterStep', App.StackService.find().filterProperty('isSelected').filterProperty('hasMaster').everyProperty('isInstalled', true));
  236. this.get('isStepDisabled').findProperty('step', 2).set('value', this.get('content.skipMasterStep') || (this.get('currentStep') == 7 || this.get('currentStep') == 8));
  237. },
  238. /**
  239. * Does service have any configs
  240. * @param {string} serviceName
  241. * @returns {boolean}
  242. */
  243. isServiceNotConfigurable: function (serviceName) {
  244. return App.get('services.noConfigTypes').contains(serviceName);
  245. },
  246. /**
  247. * Should Config Step be skipped (based on selected services list)
  248. * @returns {boolean}
  249. */
  250. skipConfigStep: function () {
  251. var skipConfigStep = true;
  252. var selectedServices = this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).mapProperty('serviceName');
  253. selectedServices.map(function (serviceName) {
  254. skipConfigStep = skipConfigStep && this.isServiceNotConfigurable(serviceName);
  255. }, this);
  256. return skipConfigStep;
  257. },
  258. loadServiceConfigProperties: function () {
  259. this._super();
  260. if (!this.get('content.services')) {
  261. this.loadServices();
  262. }
  263. if (this.get('currentStep') > 1 && this.get('currentStep') < 6) {
  264. this.set('content.skipConfigStep', this.skipConfigStep());
  265. this.get('isStepDisabled').findProperty('step', 4).set('value', this.get('content.skipConfigStep'));
  266. }
  267. },
  268. /**
  269. * Load kerberos descriptor configuration
  270. * @returns {$.Deferred}
  271. */
  272. loadKerberosDescriptorConfigs: function() {
  273. var self = this,
  274. dfd = $.Deferred();
  275. if (App.get('isKerberosEnabled')) {
  276. this.loadClusterDescriptorConfigs().then(function(properties) {
  277. self.set('kerberosDescriptorConfigs', self.createServicesStackDescriptorConfigs(properties));
  278. }).always(function(){
  279. dfd.resolve();
  280. });
  281. } else {
  282. dfd.resolve();
  283. }
  284. return dfd.promise();
  285. },
  286. saveServiceConfigProperties: function (stepController) {
  287. this._super(stepController);
  288. if (this.get('currentStep') > 1 && this.get('currentStep') < 6) {
  289. this.set('content.skipConfigStep', this.skipConfigStep());
  290. this.get('isStepDisabled').findProperty('step', 4).set('value', this.get('content.skipConfigStep'));
  291. }
  292. },
  293. /**
  294. * Load master component hosts data for using in required step controllers
  295. */
  296. loadSlaveComponentHosts: function () {
  297. var props = this.getDBProperties(['slaveComponentHosts', 'hosts']);
  298. var slaveComponentHosts = props.slaveComponentHosts,
  299. hosts = props.hosts || {},
  300. host_names = Em.keys(hosts);
  301. if (!Em.isNone(slaveComponentHosts)) {
  302. slaveComponentHosts.forEach(function (component) {
  303. component.hosts.forEach(function (host) {
  304. //Em.set(host, 'hostName', hosts[host.host_id].name);
  305. for (var i = 0; i < host_names.length; i++) {
  306. if (hosts[host_names[i]].id === host.host_id) {
  307. host.hostName = host_names[i];
  308. break;
  309. }
  310. }
  311. });
  312. });
  313. }
  314. this.set('content.installedHosts', this.getDBProperty('hosts') || this.get('content.hosts'));
  315. this.set("content.slaveComponentHosts", slaveComponentHosts);
  316. },
  317. /**
  318. * Generate clients list for selected services and save it to model
  319. */
  320. saveClients: function () {
  321. var clients = [];
  322. var serviceComponents = App.StackServiceComponent.find();
  323. this.get('content.services').filterProperty('isSelected').filterProperty('isInstalled',false).forEach(function (_service) {
  324. var serviceClients = serviceComponents.filterProperty('serviceName', _service.get('serviceName')).filterProperty('isClient');
  325. serviceClients.forEach(function (client) {
  326. clients.push({
  327. component_name: client.get('componentName'),
  328. display_name: client.get('displayName'),
  329. isInstalled: false
  330. });
  331. }, this);
  332. }, this);
  333. this.setDBProperty('clientInfo', clients);
  334. this.set('content.clients', clients);
  335. },
  336. /**
  337. * Remove all loaded data.
  338. * Created as copy for App.router.clearAllSteps
  339. */
  340. clearAllSteps: function () {
  341. this.clearInstallOptions();
  342. // clear temporary information stored during the install
  343. this.set('content.cluster', this.getCluster());
  344. },
  345. /**
  346. * Clear all temporary data
  347. */
  348. finish: function () {
  349. this.clearAllSteps();
  350. this.clearStorageData();
  351. this.resetDbNamespace();
  352. App.router.get('updateController').updateAll();
  353. },
  354. /**
  355. * genarates data for ajax request to launch install services
  356. * @method generateDataForInstallServices
  357. * @param {Array} selectedServices
  358. * @returns {{context: *, ServiceInfo: {state: string}, urlParams: string}}
  359. */
  360. generateDataForInstallServices: function(selectedServices) {
  361. if (selectedServices.contains('OOZIE')) {
  362. selectedServices = selectedServices.concat(['HDFS', 'YARN', 'MAPREDUCE2']);
  363. }
  364. return {
  365. "context": Em.I18n.t('requestInfo.installServices'),
  366. "ServiceInfo": {"state": "INSTALLED"},
  367. "urlParams": "ServiceInfo/service_name.in(" + selectedServices.join(',') + ")"
  368. };
  369. },
  370. /**
  371. * main method for installing additional clients and services
  372. * @param {function} callback
  373. * @method installServices
  374. */
  375. installServices: function (callback) {
  376. var self = this;
  377. this.set('content.cluster.oldRequestsId', []);
  378. this.installAdditionalClients().done(function () {
  379. self.installSelectedServices(callback);
  380. });
  381. },
  382. /**
  383. * method to install added services
  384. * @param {function} callback
  385. * @method installSelectedServices
  386. */
  387. installSelectedServices: function (callback) {
  388. var name = 'common.services.update';
  389. var selectedServices = this.get('content.services').filterProperty('isInstalled', false).filterProperty('isSelected', true).mapProperty('serviceName');
  390. var data = this.generateDataForInstallServices(selectedServices);
  391. this.installServicesRequest(name, data, callback.bind(this));
  392. },
  393. installServicesRequest: function (name, data, callback) {
  394. callback = callback || Em.K;
  395. App.ajax.send({
  396. name: name,
  397. sender: this,
  398. data: data,
  399. success: 'installServicesSuccessCallback',
  400. error: 'installServicesErrorCallback'
  401. }).then(callback, callback);
  402. },
  403. /**
  404. * installs clients before install new services
  405. * on host where some components require this
  406. * @method installAdditionalClients
  407. */
  408. installAdditionalClients: function () {
  409. var dfd = $.Deferred();
  410. var count = 0;
  411. if (this.get('content.additionalClients.length') > 0) {
  412. this.get('content.additionalClients').forEach(function (c) {
  413. if (c.hostNames.length > 0) {
  414. var queryStr = 'HostRoles/component_name='+ c.componentName + '&HostRoles/host_name.in(' + c.hostNames.join() + ')';
  415. this.get('installClietsQueue').addRequest({
  416. name: 'common.host_component.update',
  417. sender: this,
  418. data: {
  419. query: queryStr,
  420. context: 'Install ' + App.format.role(c.componentName, false),
  421. HostRoles: {
  422. state: 'INSTALLED'
  423. },
  424. counter: count++,
  425. deferred: dfd
  426. },
  427. success: 'installClientSuccess',
  428. error: 'installClientError'
  429. });
  430. }
  431. }, this);
  432. if (this.get('installClietsQueue.queue.length') == 0) {
  433. return dfd.resolve();
  434. } else {
  435. this.set('installClientQueueLength', this.get('installClietsQueue.queue.length'));
  436. App.get('router.wizardStep8Controller').set('servicesInstalled', true);
  437. this.get('installClietsQueue').start();
  438. }
  439. } else {
  440. dfd.resolve();
  441. }
  442. return dfd.promise();
  443. },
  444. /**
  445. * callback for when install clients success
  446. * @param data
  447. * @param opt
  448. * @param params
  449. * @method installClientComplete
  450. */
  451. installClientSuccess: function(data, opt, params) {
  452. if (this.get('installClientQueueLength') - 1 == params.counter) {
  453. params.deferred.resolve();
  454. }
  455. },
  456. /**
  457. * callback for when install clients fail
  458. * @param request
  459. * @param ajaxOptions
  460. * @param error
  461. * @param opt
  462. * @param params
  463. */
  464. installClientError: function(request, ajaxOptions, error, opt, params) {
  465. if (this.get('installClientQueueLength') - 1 == params.counter) {
  466. params.deferred.resolve();
  467. }
  468. },
  469. checkSecurityStatus: function() {
  470. if (!App.get('isKerberosEnabled')) {
  471. this.set('skipConfigureIdentitiesStep', true);
  472. this.get('isStepDisabled').findProperty('step', 5).set('value', true);
  473. }
  474. },
  475. loadServiceConfigGroups: function () {
  476. this._super();
  477. this.set('areInstalledConfigGroupsLoaded', !Em.isNone(this.getDBProperty('serviceConfigGroups')));
  478. },
  479. clearStorageData: function () {
  480. this._super();
  481. this.set('areInstalledConfigGroupsLoaded', false);
  482. }
  483. });