step5_controller.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074
  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. var numberUtils = require('utils/number_utils');
  20. var validationUtils = require('utils/validator');
  21. App.WizardStep5Controller = Em.Controller.extend({
  22. name: "wizardStep5Controller",
  23. /**
  24. * Step title
  25. * Custom if <code>App.ReassignMasterController</code> is used
  26. * @type {string}
  27. */
  28. title: function () {
  29. if (this.get('content.controllerName') == 'reassignMasterController') {
  30. return Em.I18n.t('installer.step5.reassign.header');
  31. }
  32. return Em.I18n.t('installer.step5.header');
  33. }.property('content.controllerName'),
  34. /**
  35. * Is ReassignWizard used
  36. * @type {bool}
  37. */
  38. isReassignWizard: function () {
  39. return this.get('content.controllerName') == 'reassignMasterController';
  40. }.property('content.controllerName'),
  41. /**
  42. * Is isHighAvailabilityWizard used
  43. * @type {bool}
  44. */
  45. isHighAvailabilityWizard: function () {
  46. return this.get('content.controllerName') == 'highAvailabilityWizardController';
  47. }.property('content.controllerName'),
  48. /**
  49. * Is AddServiceWizard used
  50. * @type {bool}
  51. */
  52. isAddServiceWizard: function () {
  53. return this.get('content.controllerName') == 'addServiceController';
  54. }.property('content.controllerName'),
  55. /**
  56. * Master components which could be assigned to multiple hosts
  57. * @type {string[]}
  58. */
  59. multipleComponents: function () {
  60. return App.get('components.multipleMasters');
  61. }.property('App.components.multipleMasters'),
  62. /**
  63. * Master components which could be assigned to multiple hosts
  64. * @type {string[]}
  65. */
  66. addableComponents: function () {
  67. return App.get('components.addableMasterInstallerWizard');
  68. }.property('App.components.addableMasterInstallerWizard'),
  69. /**
  70. * Define state for submit button
  71. * @type {bool}
  72. */
  73. submitDisabled: false,
  74. /**
  75. * Trigger for executing host names check for components
  76. * Should de "triggered" when host changed for some component and when new multiple component is added/removed
  77. * @type {bool}
  78. */
  79. hostNameCheckTrigger: false,
  80. /**
  81. * List of hosts
  82. * @type {Array}
  83. */
  84. hosts: [],
  85. /**
  86. * Name of multiple component which host name was changed last
  87. * @type {Object|null}
  88. */
  89. componentToRebalance: null,
  90. /**
  91. * Name of component which host was changed last
  92. * @type {string}
  93. */
  94. lastChangedComponent: null,
  95. /**
  96. * Flag for rebalance multiple components
  97. * @type {number}
  98. */
  99. rebalanceComponentHostsCounter: 0,
  100. /**
  101. * @type {Ember.Enumerable}
  102. */
  103. servicesMasters: [],
  104. /**
  105. * @type {Ember.Enumerable}
  106. */
  107. selectedServicesMasters: [],
  108. /**
  109. * Is data for current step loaded
  110. * @type {bool}
  111. */
  112. isLoaded: false,
  113. /**
  114. * Validation error messages which don't related with any master
  115. */
  116. generalErrorMessages: [],
  117. /**
  118. * Validation warning messages which don't related with any master
  119. */
  120. generalWarningMessages: [],
  121. /**
  122. * true if any warning exists
  123. */
  124. anyWarning: function() {
  125. return this.get('servicesMasters').some(function(m) { return m.get('warnMessage'); }) || this.get('generalWarningMessages').some(function(m) { return m; });
  126. }.property('servicesMasters.@each.warnMessage', 'generalWarningMessages'),
  127. /**
  128. * List of host with assigned masters
  129. * Format:
  130. * <code>
  131. * [
  132. * {
  133. * host_name: '',
  134. * hostInfo: {},
  135. * masterServices: [],
  136. * masterServicesToDisplay: [] // used only in template
  137. * },
  138. * ....
  139. * ]
  140. * </code>
  141. * @type {Ember.Enumerable}
  142. */
  143. masterHostMapping: function () {
  144. var mapping = [], mappingObject, mappedHosts, hostObj;
  145. //get the unique assigned hosts and find the master services assigned to them
  146. mappedHosts = this.get("selectedServicesMasters").mapProperty("selectedHost").uniq();
  147. mappedHosts.forEach(function (item) {
  148. hostObj = this.get("hosts").findProperty("host_name", item);
  149. // User may input invalid host name (this is handled in hostname checker). Here we just skip it
  150. if (!hostObj) return;
  151. var masterServices = this.get("selectedServicesMasters").filterProperty("selectedHost", item),
  152. masterServicesToDisplay = [];
  153. masterServices.mapProperty('display_name').uniq().forEach(function (n) {
  154. masterServicesToDisplay.pushObject(masterServices.findProperty('display_name', n));
  155. });
  156. mappingObject = Em.Object.create({
  157. host_name: item,
  158. hostInfo: hostObj.host_info,
  159. masterServices: masterServices,
  160. masterServicesToDisplay: masterServicesToDisplay
  161. });
  162. mapping.pushObject(mappingObject);
  163. }, this);
  164. return mapping.sortProperty('host_name');
  165. }.property("selectedServicesMasters.@each.selectedHost", 'selectedServicesMasters.@each.isHostNameValid'),
  166. /**
  167. * Count of hosts without masters
  168. * @type {number}
  169. */
  170. remainingHosts: function () {
  171. if (this.get('content.controllerName') === 'installerController') {
  172. return 0;
  173. } else {
  174. return (this.get("hosts.length") - this.get("masterHostMapping.length"));
  175. }
  176. }.property('masterHostMapping.length', 'selectedServicesMasters.@each.selectedHost'),
  177. /**
  178. * Update submit button status
  179. * @metohd updateIsSubmitDisabled
  180. */
  181. updateIsSubmitDisabled: function () {
  182. var self = this;
  183. if (self.thereIsNoMasters()) {
  184. return false;
  185. }
  186. if (App.supports.serverRecommendValidate) {
  187. self.set('submitDisabled', true);
  188. // reset previous recommendations
  189. App.router.set('installerController.recommendations', null);
  190. if (self.get('servicesMasters').length === 0) {
  191. return;
  192. }
  193. var isSubmitDisabled = this.get('servicesMasters').someProperty('isHostNameValid', false);
  194. if (!isSubmitDisabled) {
  195. self.recommendAndValidate();
  196. }
  197. } else {
  198. var isSubmitDisabled = this.get('servicesMasters').someProperty('isHostNameValid', false);
  199. self.set('submitDisabled', isSubmitDisabled);
  200. return isSubmitDisabled;
  201. }
  202. }.observes('servicesMasters.@each.selectedHost', 'servicesMasters.@each.isHostNameValid'),
  203. /**
  204. * Send AJAX request to validate current host layout
  205. * @param blueprint - blueprint for validation (can be with/withour slave/client components)
  206. */
  207. validate: function(blueprint, callback) {
  208. var self = this;
  209. var selectedServices = App.StackService.find().filterProperty('isSelected').mapProperty('serviceName');
  210. var installedServices = App.StackService.find().filterProperty('isInstalled').mapProperty('serviceName');
  211. var services = installedServices.concat(selectedServices).uniq();
  212. var hostNames = self.get('hosts').mapProperty('host_name');
  213. App.ajax.send({
  214. name: 'config.validations',
  215. sender: self,
  216. data: {
  217. stackVersionUrl: App.get('stackVersionURL'),
  218. hosts: hostNames,
  219. services: services,
  220. validate: 'host_groups',
  221. recommendations: blueprint
  222. },
  223. success: 'updateValidationsSuccessCallback'
  224. }).
  225. retry({
  226. times: App.maxRetries,
  227. timeout: App.timeout
  228. }).
  229. then(function() {
  230. if (callback) {
  231. callback();
  232. }
  233. }, function () {
  234. App.showReloadPopup();
  235. console.log('Load validations failed');
  236. }
  237. );
  238. },
  239. /**
  240. * Success-callback for validations request
  241. * @param {object} data
  242. * @method updateValidationsSuccessCallback
  243. */
  244. updateValidationsSuccessCallback: function (data) {
  245. var self = this;
  246. generalErrorMessages = [];
  247. generalWarningMessages = [];
  248. this.get('servicesMasters').setEach('warnMessage', null);
  249. this.get('servicesMasters').setEach('errorMessage', null);
  250. var anyErrors = false;
  251. var validationData = validationUtils.filterNotInstalledComponents(data);
  252. validationData.filterProperty('type', 'host-component').forEach(function(item) {
  253. var master = self.get('servicesMasters').find(function(m) {
  254. return m.component_name === item['component-name'] && m.selectedHost === item.host;
  255. });
  256. if (master) {
  257. if (item.level === 'ERROR') {
  258. anyErrors = true;
  259. master.set('errorMessage', item.message);
  260. } else if (item.level === 'WARN') {
  261. master.set('warnMessage', item.message);
  262. }
  263. } else {
  264. var details = " (" + item['component-name'] + " on " + item.host + ")";
  265. if (item.level === 'ERROR') {
  266. anyErrors = true;
  267. generalErrorMessages.push(item.message + details);
  268. } else if (item.level === 'WARN') {
  269. generalWarningMessages.push(item.message + details);
  270. }
  271. }
  272. });
  273. this.set('generalErrorMessages', generalErrorMessages);
  274. this.set('generalWarningMessages', generalWarningMessages);
  275. this.set('submitDisabled', anyErrors);
  276. },
  277. /**
  278. * Composes selected values of comboboxes into blueprint format
  279. */
  280. getCurrentBlueprint: function() {
  281. var self = this;
  282. var res = {
  283. blueprint: { host_groups: [] },
  284. blueprint_cluster_binding: { host_groups: [] }
  285. };
  286. var mapping = self.get('masterHostMapping');
  287. var i = 0;
  288. mapping.forEach(function(item) {
  289. i += 1;
  290. var group_name = 'host-group-' + i;
  291. var host_group = {
  292. name: group_name,
  293. components: item.masterServices.map(function(master) {
  294. return { name: master.component_name };
  295. })
  296. };
  297. var binding = {
  298. name: group_name,
  299. hosts: [ { fqdn: item.host_name } ]
  300. }
  301. res.blueprint.host_groups.push(host_group);
  302. res.blueprint_cluster_binding.host_groups.push(binding);
  303. });
  304. return res;
  305. },
  306. /**
  307. * Clear controller data (hosts, masters etc)
  308. * @method clearStep
  309. */
  310. clearStep: function () {
  311. this.set('hosts', []);
  312. this.set('selectedServicesMasters', []);
  313. this.set('servicesMasters', []);
  314. App.StackServiceComponent.find().forEach(function (stackComponent) {
  315. stackComponent.set('serviceComponentId', 1);
  316. }, this);
  317. },
  318. /**
  319. * Load controller data (hosts, host components etc)
  320. * @method loadStep
  321. */
  322. loadStep: function () {
  323. console.log("WizardStep5Controller: Loading step5: Assign Masters");
  324. this.clearStep();
  325. this.renderHostInfo();
  326. if (App.supports.serverRecommendValidate ) {
  327. this.loadComponentsRecommendationsFromServer(this.loadStepCallback);
  328. } else {
  329. this.loadComponentsRecommendationsLocally(this.loadStepCallback);
  330. }
  331. },
  332. /**
  333. * Callback after load controller data (hosts, host components etc)
  334. * @method loadStepCallback
  335. */
  336. loadStepCallback: function(components, self) {
  337. self.renderComponents(components);
  338. self.get('addableComponents').forEach(function (componentName) {
  339. self.updateComponent(componentName);
  340. }, self);
  341. if (self.thereIsNoMasters()) {
  342. console.log('no master components to add');
  343. App.router.send('next');
  344. }
  345. },
  346. /**
  347. * Returns true if there is no new master components which need assigment to host
  348. */
  349. thereIsNoMasters: function() {
  350. return !this.get("selectedServicesMasters").filterProperty('isInstalled', false).length;
  351. },
  352. /**
  353. * Used to set showAddControl flag for installer wizard
  354. * @method updateComponent
  355. */
  356. updateComponent: function (componentName) {
  357. var component = this.last(componentName);
  358. if (!component) {
  359. return;
  360. }
  361. var services = App.StackService.find().filterProperty('isInstalled', true).mapProperty('serviceName');
  362. var currentService = componentName.split('_')[0];
  363. var showControl = !services.contains(currentService);
  364. if (showControl) {
  365. var mastersLength = this.get("selectedServicesMasters").filterProperty("component_name", componentName).length;
  366. if (mastersLength < this.get("hosts.length") && !this.get('isReassignWizard') && !this.get('isHighAvailabilityWizard')) {
  367. component.set('showAddControl', true);
  368. } else if (mastersLength == 1 || this.get('isReassignWizard') || this.get('isHighAvailabilityWizard')) {
  369. component.set('showRemoveControl', false);
  370. }
  371. }
  372. },
  373. /**
  374. * Load active host list to <code>hosts</code> variable
  375. * @method renderHostInfo
  376. */
  377. renderHostInfo: function () {
  378. var hostInfo = this.get('content.hosts');
  379. var result = [];
  380. for (var index in hostInfo) {
  381. var _host = hostInfo[index];
  382. if (_host.bootStatus === 'REGISTERED') {
  383. result.push(Em.Object.create({
  384. host_name: _host.name,
  385. cpu: _host.cpu,
  386. memory: _host.memory,
  387. disk_info: _host.disk_info,
  388. host_info: Em.I18n.t('installer.step5.hostInfo').fmt(_host.name, numberUtils.bytesToSize(_host.memory, 1, 'parseFloat', 1024), _host.cpu)
  389. }));
  390. }
  391. }
  392. this.set("hosts", result);
  393. this.sortHosts(this.get('hosts'));
  394. this.set('isLoaded', true);
  395. },
  396. /**
  397. * Sort list of host-objects by properties (memory - desc, cpu - desc, hostname - asc)
  398. * @param {object[]} hosts
  399. */
  400. sortHosts: function (hosts) {
  401. hosts.sort(function (a, b) {
  402. if (a.get('memory') == b.get('memory')) {
  403. if (a.get('cpu') == b.get('cpu')) {
  404. return a.get('host_name').localeCompare(b.get('host_name')); // hostname asc
  405. }
  406. return b.get('cpu') - a.get('cpu'); // cores desc
  407. }
  408. return b.get('memory') - a.get('memory'); // ram desc
  409. });
  410. },
  411. /**
  412. * Get recommendations info from API
  413. * @return {undefined}
  414. * @param function(componentInstallationobjects, this) callback
  415. * @param bool includeMasters
  416. */
  417. loadComponentsRecommendationsFromServer: function(callback, includeMasters) {
  418. var self = this;
  419. if (App.router.get('installerController.recommendations')) {
  420. // Don't do AJAX call if recommendations has been already received
  421. // But if user returns to previous step (selecting services), stored recommendations will be cleared in routers' next handler and AJAX call will be made again
  422. callback(self.createComponentInstallationObjects(), self);
  423. } else {
  424. var selectedServices = App.StackService.find().filterProperty('isSelected').mapProperty('serviceName');
  425. var installedServices = App.StackService.find().filterProperty('isInstalled').mapProperty('serviceName');
  426. var services = installedServices.concat(selectedServices).uniq();
  427. var hostNames = self.get('hosts').mapProperty('host_name');
  428. var data = {
  429. stackVersionUrl: App.get('stackVersionURL'),
  430. hosts: hostNames,
  431. services: services,
  432. recommend: 'host_groups'
  433. };
  434. if (includeMasters) {
  435. data.recommendations = self.getCurrentBlueprint();
  436. }
  437. return App.ajax.send({
  438. name: 'wizard.loadrecommendations',
  439. sender: self,
  440. data: data,
  441. success: 'loadRecommendationsSuccessCallback'
  442. }).
  443. retry({
  444. times: App.maxRetries,
  445. timeout: App.timeout
  446. }).
  447. then(function () {
  448. callback(self.createComponentInstallationObjects(), self);
  449. },
  450. function () {
  451. App.showReloadPopup();
  452. console.log('Load recommendations failed');
  453. }
  454. );
  455. }
  456. },
  457. /**
  458. * Create components for displaying component-host comboboxes in UI assign dialog
  459. * expects installerController.recommendations will be filled with recommendations API call result
  460. * @return {Object[]}
  461. */
  462. createComponentInstallationObjects: function() {
  463. var self = this;
  464. var masterComponents = [];
  465. if (self.get('isAddServiceWizard')) {
  466. masterComponents = App.StackServiceComponent.find().filterProperty('isShownOnAddServiceAssignMasterPage');
  467. } else {
  468. masterComponents = App.StackServiceComponent.find().filterProperty('isShownOnInstallerAssignMasterPage');
  469. }
  470. var masterHosts = self.get('content.masterComponentHosts'); //saved to local storage info
  471. var selectedNotInstalledServices = self.get('content.services').filterProperty('isSelected').filterProperty('isInstalled', false).mapProperty('serviceName');
  472. var recommendations = App.router.get('installerController.recommendations');
  473. var resultComponents = [];
  474. var multipleComponentHasBeenAdded = {};
  475. recommendations.blueprint.host_groups.forEach(function(host_group) {
  476. var hosts = recommendations.blueprint_cluster_binding.host_groups.findProperty('name', host_group.name).hosts;
  477. hosts.forEach(function(host) {
  478. host_group.components.forEach(function(component) {
  479. var willBeAdded = true;
  480. var fullComponent = masterComponents.findProperty('componentName', component.name);
  481. // If it's master component which should be shown
  482. if (fullComponent) {
  483. // If service is already installed and not being added as a new service then render on UI only those master components
  484. // that have already installed hostComponents.
  485. // NOTE: On upgrade there might be a prior installed service with non-installed newly introduced serviceComponent
  486. var isNotSelectedService = !selectedNotInstalledServices.contains(fullComponent.get('serviceName'));
  487. if (isNotSelectedService) {
  488. willBeAdded = App.HostComponent.find().someProperty('componentName', component.name);
  489. }
  490. if (willBeAdded) {
  491. var savedComponents = masterHosts.filterProperty('component', component.name);
  492. if (self.get('multipleComponents').contains(component.name) && savedComponents.length > 0) {
  493. if (!multipleComponentHasBeenAdded[component.name]) {
  494. multipleComponentHasBeenAdded[component.name] = true;
  495. savedComponents.forEach(function(saved) {
  496. resultComponents.push(self.createComponentInstallationObject(fullComponent, host.fqdn, saved));
  497. });
  498. }
  499. } else {
  500. var savedComponent = masterHosts.findProperty('component', component.name);
  501. resultComponents.push(self.createComponentInstallationObject(fullComponent, host.fqdn, savedComponent));
  502. }
  503. }
  504. }
  505. });
  506. });
  507. });
  508. return resultComponents;
  509. },
  510. /**
  511. * Create component for displaying component-host comboboxes in UI assign dialog
  512. * @param fullComponent - full component description
  513. * @param hostName - host fqdn where component will be installed
  514. * @param savedComponent - the same object which function returns but created before
  515. * @return {Object}
  516. */
  517. createComponentInstallationObject: function(fullComponent, hostName, savedComponent) {
  518. var componentName = fullComponent.get('componentName');
  519. var componentObj = {};
  520. componentObj.component_name = componentName;
  521. componentObj.display_name = fullComponent.get('displayName');
  522. componentObj.serviceId = fullComponent.get('serviceName');
  523. componentObj.isServiceCoHost = App.StackServiceComponent.find().findProperty('componentName', componentName).get('isCoHostedComponent') && !this.get('isReassignWizard');
  524. if (savedComponent) {
  525. componentObj.selectedHost = savedComponent.hostName;
  526. componentObj.isInstalled = savedComponent.isInstalled;
  527. } else {
  528. componentObj.selectedHost = hostName;
  529. componentObj.isInstalled = false;
  530. }
  531. return componentObj;
  532. },
  533. /**
  534. * Success-callback for recommendations request
  535. * @param {object} data
  536. * @method loadRecommendationsSuccessCallback
  537. */
  538. loadRecommendationsSuccessCallback: function (data) {
  539. App.router.set('installerController.recommendations', data.resources[0].recommendations);
  540. },
  541. /**
  542. * Load services info to appropriate variable and return masterComponentHosts
  543. * @return {Object[]}
  544. */
  545. loadComponentsRecommendationsLocally: function (callback) {
  546. var selectedServices = App.StackService.find().filterProperty('isSelected').mapProperty('serviceName');
  547. var installedServices = App.StackService.find().filterProperty('isInstalled').mapProperty('serviceName');
  548. var services = installedServices.concat(selectedServices).uniq();
  549. var selectedNotInstalledServices = this.get('content.services').filterProperty('isSelected').filterProperty('isInstalled', false).mapProperty('serviceName');
  550. var masterComponents = [];
  551. //get full list from mock data
  552. if (this.get('isAddServiceWizard')) {
  553. masterComponents = App.StackServiceComponent.find().filterProperty('isShownOnAddServiceAssignMasterPage');
  554. } else {
  555. masterComponents = App.StackServiceComponent.find().filterProperty('isShownOnInstallerAssignMasterPage');
  556. }
  557. var masterHosts = this.get('content.masterComponentHosts'); //saved to local storage info
  558. var resultComponents = [];
  559. for (var index = 0; index < services.length; index++) {
  560. var componentInfo = masterComponents.filterProperty('serviceName', services[index]);
  561. // If service is already installed and not being added as a new service then render on UI only those master components
  562. // that have already installed hostComponents.
  563. // NOTE: On upgrade there might be a prior installed service with non-installed newly introduced serviceComponent
  564. var isNotSelectedService = !selectedNotInstalledServices.contains(services[index]);
  565. if (isNotSelectedService) {
  566. componentInfo = componentInfo.filter(function (_component) {
  567. return App.HostComponent.find().someProperty('componentName',_component.get('componentName'));
  568. });
  569. }
  570. componentInfo.forEach(function (_componentInfo) {
  571. if (this.get('multipleComponents').contains(_componentInfo.get('componentName'))) {
  572. var savedComponents = masterHosts.filterProperty('component', _componentInfo.get('componentName'));
  573. if (savedComponents.length) {
  574. savedComponents.forEach(function (item) {
  575. var multipleMasterHost = {};
  576. multipleMasterHost.component_name = _componentInfo.get('componentName');
  577. multipleMasterHost.display_name = _componentInfo.get('displayName');
  578. multipleMasterHost.selectedHost = item.hostName;
  579. multipleMasterHost.serviceId = services[index];
  580. multipleMasterHost.isInstalled = item.isInstalled;
  581. multipleMasterHost.isServiceCoHost = false;
  582. resultComponents.push(multipleMasterHost);
  583. })
  584. } else {
  585. var multipleMasterHosts = this.selectHostLocally(_componentInfo.get('componentName'));
  586. multipleMasterHosts.forEach(function (_host) {
  587. var multipleMasterHost = {};
  588. multipleMasterHost.component_name = _componentInfo.get('componentName');
  589. multipleMasterHost.display_name = _componentInfo.get('displayName');
  590. multipleMasterHost.selectedHost = _host;
  591. multipleMasterHost.serviceId = services[index];
  592. multipleMasterHost.isInstalled = false;
  593. multipleMasterHost.isServiceCoHost = false;
  594. resultComponents.push(multipleMasterHost);
  595. });
  596. }
  597. } else {
  598. var savedComponent = masterHosts.findProperty('component', _componentInfo.get('componentName'));
  599. var componentObj = {};
  600. componentObj.component_name = _componentInfo.get('componentName');
  601. componentObj.display_name = _componentInfo.get('displayName');
  602. componentObj.selectedHost = savedComponent ? savedComponent.hostName : this.selectHostLocally(_componentInfo.get('componentName')); // call the method that plays selectNode algorithm or fetches from server
  603. componentObj.isInstalled = savedComponent ? savedComponent.isInstalled : false;
  604. componentObj.serviceId = services[index];
  605. componentObj.isServiceCoHost = App.StackServiceComponent.find().findProperty('componentName', _componentInfo.get('componentName')).get('isCoHostedComponent') && !this.get('isReassignWizard');
  606. resultComponents.push(componentObj);
  607. }
  608. }, this);
  609. }
  610. callback(resultComponents, this);
  611. },
  612. /**
  613. * @param {string} componentName
  614. * @returns {bool}
  615. * @private
  616. * @method _isHiveCoHost
  617. */
  618. _isHiveCoHost: function (componentName) {
  619. return ['HIVE_METASTORE', 'WEBHCAT_SERVER'].contains(componentName) && !this.get('isReassignWizard');
  620. },
  621. /**
  622. * Put master components to <code>selectedServicesMasters</code>, which will be automatically rendered in template
  623. * @param {Ember.Enumerable} masterComponents
  624. * @method renderComponents
  625. */
  626. renderComponents: function (masterComponents) {
  627. var installedServices = App.StackService.find().filterProperty('isSelected').filterProperty('isInstalled', false).mapProperty('serviceName'); //list of shown services
  628. var result = [];
  629. var serviceComponentId, previousComponentName;
  630. masterComponents.forEach(function (item) {
  631. var serviceComponent = App.StackServiceComponent.find().findProperty('componentName', item.component_name);
  632. var showRemoveControl = installedServices.contains(serviceComponent.get('stackService.serviceName')) &&
  633. (masterComponents.filterProperty('component_name', item.component_name).length > 1);
  634. var componentObj = Em.Object.create(item);
  635. console.log("TRACE: render master component name is: " + item.component_name);
  636. var masterComponent = App.StackServiceComponent.find().findProperty('componentName', item.component_name);
  637. if (masterComponent.get('isMasterWithMultipleInstances')) {
  638. previousComponentName = item.component_name;
  639. componentObj.set('serviceComponentId', result.filterProperty('component_name', item.component_name).length + 1);
  640. componentObj.set("showRemoveControl", showRemoveControl);
  641. }
  642. componentObj.set('isHostNameValid', true);
  643. result.push(componentObj);
  644. }, this);
  645. result = this.sortComponentsByServiceName(result);
  646. this.set("selectedServicesMasters", result);
  647. if (this.get('isReassignWizard')) {
  648. var components = result.filterProperty('component_name', this.get('content.reassign.component_name'));
  649. components.setEach('isInstalled', false);
  650. this.set('servicesMasters', components);
  651. } else {
  652. this.set('servicesMasters', result);
  653. }
  654. },
  655. sortComponentsByServiceName: function(components) {
  656. var displayOrder = App.StackService.displayOrder;
  657. return components.sort(function (a, b) {
  658. var aValue = displayOrder.indexOf(a.serviceId) != -1 ? displayOrder.indexOf(a.serviceId) : components.length;
  659. var bValue = displayOrder.indexOf(b.serviceId) != -1 ? displayOrder.indexOf(b.serviceId) : components.length;
  660. return aValue - bValue;
  661. });
  662. },
  663. /**
  664. * Update dependent co-hosted components according to the change in the component host
  665. * @method updateCoHosts
  666. */
  667. updateCoHosts: function () {
  668. var components = App.StackServiceComponent.find().filterProperty('isOtherComponentCoHosted');
  669. var selectedServicesMasters = this.get('selectedServicesMasters');
  670. components.forEach(function (component) {
  671. var componentName = component.get('componentName');
  672. var hostComponent = selectedServicesMasters.findProperty('component_name', componentName);
  673. var dependentCoHosts = component.get('coHostedComponents');
  674. dependentCoHosts.forEach(function (coHostedComponent) {
  675. var dependentHostComponent = selectedServicesMasters.findProperty('component_name', coHostedComponent);
  676. if (hostComponent && dependentHostComponent) dependentHostComponent.set('selectedHost', hostComponent.get('selectedHost'));
  677. }, this);
  678. }, this);
  679. }.observes('selectedServicesMasters.@each.selectedHost'),
  680. /**
  681. * select and return host for component by scheme
  682. * Scheme is an object that has keys which compared to number of hosts,
  683. * if key more that number of hosts, then return value of that key.
  684. * Value is index of host in hosts array.
  685. *
  686. * @param {object} componentName
  687. * @param {object} hosts
  688. * @return {string}
  689. * @method getHostForComponent
  690. */
  691. getHostForComponent: function (componentName, hosts) {
  692. var component = App.StackServiceComponent.find().findProperty('componentName', componentName);
  693. if (component) {
  694. var selectionScheme = App.StackServiceComponent.find().findProperty('componentName', componentName).get('selectionSchemeForMasterComponent');
  695. } else {
  696. return hosts[0];
  697. }
  698. if (hosts.length === 1 || $.isEmptyObject(selectionScheme)) {
  699. return hosts[0];
  700. } else {
  701. for (var i in selectionScheme) {
  702. if (window.isFinite(i)) {
  703. if (hosts.length < window.parseInt(i)) {
  704. return hosts[selectionScheme[i]];
  705. }
  706. }
  707. }
  708. return hosts[selectionScheme['else']]
  709. }
  710. },
  711. /**
  712. * Get list of host names for master component with multiple instances
  713. * @param {Object} component
  714. * @param {Object} hosts
  715. * @returns {string[]}
  716. * @method getHostsForComponent
  717. */
  718. getHostsForComponent: function (component, hosts) {
  719. var defaultNoOfMasterHosts = component.get('defaultNoOfMasterHosts');
  720. var masterHosts = [];
  721. if (hosts.length < defaultNoOfMasterHosts) {
  722. defaultNoOfMasterHosts = hosts.length;
  723. }
  724. for (var index = 0; index < defaultNoOfMasterHosts; index++) {
  725. masterHosts.push(hosts[index]);
  726. }
  727. return masterHosts;
  728. },
  729. /**
  730. * Return hostName of masterNode for specified service
  731. * @param componentName
  732. * @return {string|string[]}
  733. * @method selectHostLocally
  734. */
  735. selectHostLocally: function (componentName) {
  736. var component = App.StackServiceComponent.find().findProperty('componentName', componentName);
  737. var hostNames = this.get('hosts').mapProperty('host_name');
  738. if (hostNames.length > 1 && App.StackServiceComponent.find().filterProperty('isNotPreferableOnAmbariServerHost').mapProperty('componentName').contains(componentName)) {
  739. hostNames = this.get('hosts').mapProperty('host_name').filter(function (item) {
  740. return item !== location.hostname;
  741. }, this);
  742. }
  743. if (this.get('multipleComponents').contains(componentName)) {
  744. if (component.get('defaultNoOfMasterHosts') > 1) {
  745. return this.getHostsForComponent(component, hostNames);
  746. } else {
  747. return [this.getHostForComponent(componentName, hostNames)];
  748. }
  749. } else {
  750. return this.getHostForComponent(componentName, hostNames);
  751. }
  752. },
  753. /**
  754. * On change callback for inputs
  755. * @param {string} componentName
  756. * @param {string} selectedHost
  757. * @param {number} serviceComponentId
  758. * @method assignHostToMaster
  759. */
  760. assignHostToMaster: function (componentName, selectedHost, serviceComponentId) {
  761. var flag = this.isHostNameValid(componentName, selectedHost);
  762. this.updateIsHostNameValidFlag(componentName, serviceComponentId, flag);
  763. if (serviceComponentId) {
  764. this.get('selectedServicesMasters').filterProperty('component_name', componentName).findProperty("serviceComponentId", serviceComponentId).set("selectedHost", selectedHost);
  765. }
  766. else {
  767. this.get('selectedServicesMasters').findProperty("component_name", componentName).set("selectedHost", selectedHost);
  768. }
  769. },
  770. /**
  771. * Determines if hostName is valid for component:
  772. * <ul>
  773. * <li>host name shouldn't be empty</li>
  774. * <li>host should exist</li>
  775. * <li>host should have only one component with <code>componentName</code></li>
  776. * </ul>
  777. * @param {string} componentName
  778. * @param {string} selectedHost
  779. * @returns {boolean} true - valid, false - invalid
  780. * @method isHostNameValid
  781. */
  782. isHostNameValid: function (componentName, selectedHost) {
  783. return (selectedHost.trim() !== '') &&
  784. this.get('hosts').mapProperty('host_name').contains(selectedHost) &&
  785. (this.get('selectedServicesMasters').
  786. filterProperty('component_name', componentName).
  787. mapProperty('selectedHost').
  788. filter(function (h) {
  789. return h === selectedHost;
  790. }).length <= 1);
  791. },
  792. /**
  793. * Update <code>isHostNameValid</code> property with <code>flag</code> value
  794. * for component with name <code>componentName</code> and
  795. * <code>serviceComponentId</code>-property equal to <code>serviceComponentId</code>-parameter value
  796. * @param {string} componentName
  797. * @param {number} serviceComponentId
  798. * @param {bool} flag
  799. * @method updateIsHostNameValidFlag
  800. */
  801. updateIsHostNameValidFlag: function (componentName, serviceComponentId, flag) {
  802. if (componentName) {
  803. if (serviceComponentId) {
  804. this.get('selectedServicesMasters').filterProperty('component_name', componentName).findProperty("serviceComponentId", serviceComponentId).set("isHostNameValid", flag);
  805. } else {
  806. this.get('selectedServicesMasters').findProperty("component_name", componentName).set("isHostNameValid", flag);
  807. }
  808. }
  809. },
  810. /**
  811. * Returns last component of selected type
  812. * @param {string} componentName
  813. * @return {Em.Object|null}
  814. * @method last
  815. */
  816. last: function (componentName) {
  817. return this.get("selectedServicesMasters").filterProperty("component_name", componentName).get("lastObject");
  818. },
  819. /**
  820. * Add new component to ZooKeeper Server and Hbase master
  821. * @param {string} componentName
  822. * @return {bool} true - added, false - not added
  823. * @method addComponent
  824. */
  825. addComponent: function (componentName) {
  826. /*
  827. * Logic: If ZooKeeper or Hbase service is selected then there can be
  828. * minimum 1 ZooKeeper or Hbase master in total, and
  829. * maximum 1 ZooKeeper or Hbase on every host
  830. */
  831. var maxNumMasters = this.get("hosts.length"),
  832. currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName),
  833. newMaster = null,
  834. masterHosts = null,
  835. suggestedHost = null,
  836. i = 0,
  837. lastMaster = null;
  838. if (!currentMasters.length) {
  839. console.log('ALERT: Zookeeper service was not selected');
  840. return false;
  841. }
  842. if (currentMasters.get("length") < maxNumMasters) {
  843. currentMasters.set("lastObject.showAddControl", false);
  844. currentMasters.set("lastObject.showRemoveControl", true);
  845. //create a new master component host based on an existing one
  846. newMaster = Em.Object.create({});
  847. lastMaster = currentMasters.get("lastObject");
  848. newMaster.set("display_name", lastMaster.get("display_name"));
  849. newMaster.set("component_name", lastMaster.get("component_name"));
  850. newMaster.set("selectedHost", lastMaster.get("selectedHost"));
  851. newMaster.set("serviceId", lastMaster.get("serviceId"));
  852. newMaster.set("isInstalled", false);
  853. if (currentMasters.get("length") === (maxNumMasters - 1)) {
  854. newMaster.set("showAddControl", false);
  855. } else {
  856. newMaster.set("showAddControl", true);
  857. }
  858. newMaster.set("showRemoveControl", true);
  859. //get recommended host for the new Zookeeper server
  860. masterHosts = currentMasters.mapProperty("selectedHost").uniq();
  861. for (i = 0; i < this.get("hosts.length"); i++) {
  862. if (!(masterHosts.contains(this.get("hosts")[i].get("host_name")))) {
  863. suggestedHost = this.get("hosts")[i].get("host_name");
  864. break;
  865. }
  866. }
  867. newMaster.set("selectedHost", suggestedHost);
  868. newMaster.set("serviceComponentId", (currentMasters.get("lastObject.serviceComponentId") + 1));
  869. this.get("selectedServicesMasters").insertAt(this.get("selectedServicesMasters").indexOf(lastMaster) + 1, newMaster);
  870. this.set('componentToRebalance', componentName);
  871. this.incrementProperty('rebalanceComponentHostsCounter');
  872. this.toggleProperty('hostNameCheckTrigger');
  873. return true;
  874. }
  875. return false;//if no more zookeepers can be added
  876. },
  877. /**
  878. * Remove component from ZooKeeper server or Hbase Master
  879. * @param {string} componentName
  880. * @param {number} serviceComponentId
  881. * @return {bool} true - removed, false - no
  882. * @method removeComponent
  883. */
  884. removeComponent: function (componentName, serviceComponentId) {
  885. var currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName);
  886. //work only if the multiple master service is selected in previous step
  887. if (currentMasters.length <= 1) {
  888. return false;
  889. }
  890. this.get("selectedServicesMasters").removeAt(this.get("selectedServicesMasters").indexOf(currentMasters.findProperty("serviceComponentId", serviceComponentId)));
  891. currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName);
  892. if (currentMasters.get("length") < this.get("hosts.length")) {
  893. currentMasters.set("lastObject.showAddControl", true);
  894. }
  895. if (currentMasters.get("length") === 1) {
  896. currentMasters.set("lastObject.showRemoveControl", false);
  897. }
  898. this.set('componentToRebalance', componentName);
  899. this.incrementProperty('rebalanceComponentHostsCounter');
  900. this.toggleProperty('hostNameCheckTrigger');
  901. return true;
  902. },
  903. recommendAndValidate: function(callback) {
  904. var self = this;
  905. // load recommendations with partial request
  906. self.loadComponentsRecommendationsFromServer(function() {
  907. // For validation use latest received recommendations because ir contains current master layout and recommended slave/client layout
  908. self.validate(App.router.get('installerController.recommendations'), function() {
  909. if (callback) {
  910. callback();
  911. }
  912. });
  913. }, true);
  914. },
  915. /**
  916. * Submit button click handler
  917. * @metohd submit
  918. */
  919. submit: function () {
  920. var self = this;
  921. var primary = function() {
  922. var goNextStepIfValid = function() {
  923. if (!self.get('submitDisabled')) {
  924. App.router.send('next');
  925. }
  926. };
  927. if (App.supports.serverRecommendValidate ) {
  928. self.recommendAndValidate(function() {
  929. goNextStepIfValid();
  930. });
  931. } else {
  932. self.updateIsSubmitDisabled();
  933. goNextStepIfValid();
  934. }
  935. }
  936. if (self.get('anyWarning')) {
  937. App.ModalPopup.show({
  938. primary: Em.I18n.t('common.continueAnyway'),
  939. header: Em.I18n.t('installer.step5.warningsAttention.header'),
  940. body: Em.I18n.t('installer.step5.warningsAttention'),
  941. onPrimary: function () {
  942. this.hide();
  943. primary();
  944. }
  945. });
  946. } else {
  947. primary();
  948. }
  949. }
  950. });