add_controller.js 21 KB

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