add_controller.js 20 KB

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