add_controller.js 20 KB

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