add_controller.js 20 KB

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