add_controller.js 18 KB

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