add_controller.js 21 KB

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