step5_controller.js 41 KB

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