step5_controller.js 40 KB

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