add_controller.js 20 KB

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