step5_controller.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982
  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 (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. this.loadComponentsRecommendationsFromServer(this.loadStepCallback);
  365. },
  366. /**
  367. * Callback after load controller data (hosts, host components etc)
  368. * @method loadStepCallback
  369. */
  370. loadStepCallback: function(components, self) {
  371. self.renderComponents(components);
  372. self.get('addableComponents').forEach(function (componentName) {
  373. self.updateComponent(componentName);
  374. }, self);
  375. if (self.thereIsNoMasters()) {
  376. console.log('no master components to add');
  377. App.router.send('next');
  378. }
  379. },
  380. /**
  381. * Returns true if there is no new master components which need assigment to host
  382. */
  383. thereIsNoMasters: function() {
  384. return !this.get("selectedServicesMasters").filterProperty('isInstalled', false).length;
  385. },
  386. /**
  387. * Used to set showAddControl flag for installer wizard
  388. * @method updateComponent
  389. */
  390. updateComponent: function (componentName) {
  391. var component = this.last(componentName);
  392. if (!component) {
  393. return;
  394. }
  395. var services = App.StackService.find().filterProperty('isInstalled', true).mapProperty('serviceName');
  396. var currentService = componentName.split('_')[0];
  397. var showControl = !services.contains(currentService);
  398. if (showControl) {
  399. var mastersLength = this.get("selectedServicesMasters").filterProperty("component_name", componentName).length;
  400. if (mastersLength < this.get("hosts.length") && !this.get('isReassignWizard') && !this.get('isHighAvailabilityWizard')) {
  401. component.set('showAddControl', true);
  402. } else if (mastersLength == 1 || this.get('isReassignWizard') || this.get('isHighAvailabilityWizard')) {
  403. component.set('showRemoveControl', false);
  404. }
  405. }
  406. },
  407. /**
  408. * Load active host list to <code>hosts</code> variable
  409. * @method renderHostInfo
  410. */
  411. renderHostInfo: function () {
  412. var hostInfo = this.get('content.hosts');
  413. var result = [];
  414. for (var index in hostInfo) {
  415. var _host = hostInfo[index];
  416. if (_host.bootStatus === 'REGISTERED') {
  417. result.push(Em.Object.create({
  418. host_name: _host.name,
  419. cpu: _host.cpu,
  420. memory: _host.memory,
  421. disk_info: _host.disk_info,
  422. host_info: Em.I18n.t('installer.step5.hostInfo').fmt(_host.name, numberUtils.bytesToSize(_host.memory, 1, 'parseFloat', 1024), _host.cpu)
  423. }));
  424. }
  425. }
  426. this.set("hosts", result);
  427. this.sortHosts(this.get('hosts'));
  428. this.set('isLoaded', true);
  429. },
  430. /**
  431. * Sort list of host-objects by properties (memory - desc, cpu - desc, hostname - asc)
  432. * @param {object[]} hosts
  433. */
  434. sortHosts: function (hosts) {
  435. hosts.sort(function (a, b) {
  436. if (a.get('memory') == b.get('memory')) {
  437. if (a.get('cpu') == b.get('cpu')) {
  438. return a.get('host_name').localeCompare(b.get('host_name')); // hostname asc
  439. }
  440. return b.get('cpu') - a.get('cpu'); // cores desc
  441. }
  442. return b.get('memory') - a.get('memory'); // ram desc
  443. });
  444. },
  445. /**
  446. * Get recommendations info from API
  447. * @return {undefined}
  448. * @param function(componentInstallationobjects, this) callback
  449. * @param bool includeMasters
  450. */
  451. loadComponentsRecommendationsFromServer: function(callback, includeMasters) {
  452. var self = this;
  453. if (this.get('content.recommendations')) {
  454. // Don't do AJAX call if recommendations has been already received
  455. // 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
  456. callback(self.createComponentInstallationObjects(), self);
  457. } else {
  458. var selectedServices = App.StackService.find().filterProperty('isSelected').mapProperty('serviceName');
  459. var installedServices = App.StackService.find().filterProperty('isInstalled').mapProperty('serviceName');
  460. var services = installedServices.concat(selectedServices).uniq();
  461. var hostNames = self.get('hosts').mapProperty('host_name');
  462. var data = {
  463. stackVersionUrl: App.get('stackVersionURL'),
  464. hosts: hostNames,
  465. services: services,
  466. recommend: 'host_groups'
  467. };
  468. if (includeMasters) {
  469. // Made partial recommendation request for reflect in blueprint host-layout changes which were made by user in UI
  470. data.recommendations = self.getCurrentBlueprint();
  471. } else if (!self.get('isInstallerWizard')) {
  472. data.recommendations = self.getCurrentMasterSlaveBlueprint();
  473. }
  474. return App.ajax.send({
  475. name: 'wizard.loadrecommendations',
  476. sender: self,
  477. data: data,
  478. success: 'loadRecommendationsSuccessCallback',
  479. error: 'loadRecommendationsErrorCallback'
  480. }).
  481. then(function () {
  482. callback(self.createComponentInstallationObjects(), self);
  483. });
  484. }
  485. },
  486. /**
  487. * Create components for displaying component-host comboboxes in UI assign dialog
  488. * expects content.recommendations will be filled with recommendations API call result
  489. * @return {Object[]}
  490. */
  491. createComponentInstallationObjects: function() {
  492. var self = this;
  493. var masterComponents = [];
  494. if (self.get('isAddServiceWizard')) {
  495. masterComponents = App.StackServiceComponent.find().filterProperty('isShownOnAddServiceAssignMasterPage');
  496. } else {
  497. masterComponents = App.StackServiceComponent.find().filterProperty('isShownOnInstallerAssignMasterPage');
  498. }
  499. var masterHosts = self.get('content.masterComponentHosts'); //saved to local storage info
  500. var selectedNotInstalledServices = self.get('content.services').filterProperty('isSelected').filterProperty('isInstalled', false).mapProperty('serviceName');
  501. var recommendations = this.get('content.recommendations');
  502. var resultComponents = [];
  503. var multipleComponentHasBeenAdded = {};
  504. recommendations.blueprint.host_groups.forEach(function(host_group) {
  505. var hosts = recommendations.blueprint_cluster_binding.host_groups.findProperty('name', host_group.name).hosts;
  506. hosts.forEach(function(host) {
  507. host_group.components.forEach(function(component) {
  508. var willBeAdded = true;
  509. var fullComponent = masterComponents.findProperty('componentName', component.name);
  510. // If it's master component which should be shown
  511. if (fullComponent) {
  512. // If service is already installed and not being added as a new service then render on UI only those master components
  513. // that have already installed hostComponents.
  514. // NOTE: On upgrade there might be a prior installed service with non-installed newly introduced serviceComponent
  515. var isNotSelectedService = !selectedNotInstalledServices.contains(fullComponent.get('serviceName'));
  516. if (isNotSelectedService) {
  517. willBeAdded = App.HostComponent.find().someProperty('componentName', component.name);
  518. }
  519. if (willBeAdded) {
  520. var savedComponents = masterHosts.filterProperty('component', component.name);
  521. if (self.get('multipleComponents').contains(component.name) && savedComponents.length > 0) {
  522. if (!multipleComponentHasBeenAdded[component.name]) {
  523. multipleComponentHasBeenAdded[component.name] = true;
  524. savedComponents.forEach(function(saved) {
  525. resultComponents.push(self.createComponentInstallationObject(fullComponent, host.fqdn, saved));
  526. });
  527. }
  528. } else {
  529. var savedComponent = masterHosts.findProperty('component', component.name);
  530. resultComponents.push(self.createComponentInstallationObject(fullComponent, host.fqdn, savedComponent));
  531. }
  532. }
  533. }
  534. });
  535. });
  536. });
  537. return resultComponents;
  538. },
  539. /**
  540. * Create component for displaying component-host comboboxes in UI assign dialog
  541. * @param fullComponent - full component description
  542. * @param hostName - host fqdn where component will be installed
  543. * @param savedComponent - the same object which function returns but created before
  544. * @return {Object}
  545. */
  546. createComponentInstallationObject: function(fullComponent, hostName, savedComponent) {
  547. var componentName = fullComponent.get('componentName');
  548. var componentObj = {};
  549. componentObj.component_name = componentName;
  550. componentObj.display_name = App.format.role(fullComponent.get('componentName'));
  551. componentObj.serviceId = fullComponent.get('serviceName');
  552. componentObj.isServiceCoHost = App.StackServiceComponent.find().findProperty('componentName', componentName).get('isCoHostedComponent') && !this.get('isReassignWizard');
  553. if (savedComponent) {
  554. componentObj.selectedHost = savedComponent.hostName;
  555. componentObj.isInstalled = savedComponent.isInstalled;
  556. } else {
  557. componentObj.selectedHost = hostName;
  558. componentObj.isInstalled = false;
  559. }
  560. return componentObj;
  561. },
  562. /**
  563. * Success-callback for recommendations request
  564. * @param {object} data
  565. * @method loadRecommendationsSuccessCallback
  566. */
  567. loadRecommendationsSuccessCallback: function (data) {
  568. this.set('content.recommendations', data.resources[0].recommendations);
  569. },
  570. /**
  571. * Error-callback for recommendations request
  572. * @param {object} jqXHR
  573. * @param {object} ajaxOptions
  574. * @param {string} error
  575. * @param {object} opt
  576. * @method loadRecommendationsErrorCallback
  577. */
  578. loadRecommendationsErrorCallback: function (jqXHR, ajaxOptions, error, opt) {
  579. App.ajax.defaultErrorHandler(jqXHR, opt.url, opt.method, jqXHR.status);
  580. console.log('Load recommendations failed');
  581. },
  582. /**
  583. * @param {string} componentName
  584. * @returns {bool}
  585. * @private
  586. * @method _isHiveCoHost
  587. */
  588. _isHiveCoHost: function (componentName) {
  589. return ['HIVE_METASTORE', 'WEBHCAT_SERVER'].contains(componentName) && !this.get('isReassignWizard');
  590. },
  591. /**
  592. * Put master components to <code>selectedServicesMasters</code>, which will be automatically rendered in template
  593. * @param {Ember.Enumerable} masterComponents
  594. * @method renderComponents
  595. */
  596. renderComponents: function (masterComponents) {
  597. var installedServices = App.StackService.find().filterProperty('isSelected').filterProperty('isInstalled', false).mapProperty('serviceName'); //list of shown services
  598. var result = [];
  599. var serviceComponentId, previousComponentName;
  600. masterComponents.forEach(function (item) {
  601. var serviceComponent = App.StackServiceComponent.find().findProperty('componentName', item.component_name);
  602. var showRemoveControl = installedServices.contains(serviceComponent.get('stackService.serviceName')) &&
  603. (masterComponents.filterProperty('component_name', item.component_name).length > 1);
  604. var componentObj = Em.Object.create(item);
  605. console.log("TRACE: render master component name is: " + item.component_name);
  606. var masterComponent = App.StackServiceComponent.find().findProperty('componentName', item.component_name);
  607. if (masterComponent.get('isMasterWithMultipleInstances')) {
  608. previousComponentName = item.component_name;
  609. componentObj.set('serviceComponentId', result.filterProperty('component_name', item.component_name).length + 1);
  610. componentObj.set("showRemoveControl", showRemoveControl);
  611. }
  612. componentObj.set('isHostNameValid', true);
  613. result.push(componentObj);
  614. }, this);
  615. result = this.sortComponentsByServiceName(result);
  616. this.set("selectedServicesMasters", result);
  617. if (this.get('isReassignWizard')) {
  618. var components = result.filterProperty('component_name', this.get('content.reassign.component_name'));
  619. components.setEach('isInstalled', false);
  620. this.set('servicesMasters', components);
  621. } else {
  622. this.set('servicesMasters', result);
  623. }
  624. },
  625. sortComponentsByServiceName: function(components) {
  626. var displayOrder = App.StackService.displayOrder;
  627. return components.sort(function (a, b) {
  628. var aValue = displayOrder.indexOf(a.serviceId) != -1 ? displayOrder.indexOf(a.serviceId) : components.length;
  629. var bValue = displayOrder.indexOf(b.serviceId) != -1 ? displayOrder.indexOf(b.serviceId) : components.length;
  630. return aValue - bValue;
  631. });
  632. },
  633. /**
  634. * Update dependent co-hosted components according to the change in the component host
  635. * @method updateCoHosts
  636. */
  637. updateCoHosts: function () {
  638. // reassign wizard has no co-host constraints
  639. if (this.get('isReassignWizard')) {
  640. return false;
  641. }
  642. var components = App.StackServiceComponent.find().filterProperty('isOtherComponentCoHosted');
  643. var selectedServicesMasters = this.get('selectedServicesMasters');
  644. components.forEach(function (component) {
  645. var componentName = component.get('componentName');
  646. var hostComponent = selectedServicesMasters.findProperty('component_name', componentName);
  647. var dependentCoHosts = component.get('coHostedComponents');
  648. dependentCoHosts.forEach(function (coHostedComponent) {
  649. var dependentHostComponent = selectedServicesMasters.findProperty('component_name', coHostedComponent);
  650. if (hostComponent && dependentHostComponent) dependentHostComponent.set('selectedHost', hostComponent.get('selectedHost'));
  651. }, this);
  652. }, this);
  653. }.observes('selectedServicesMasters.@each.selectedHost'),
  654. /**
  655. * On change callback for inputs
  656. * @param {string} componentName
  657. * @param {string} selectedHost
  658. * @param {number} serviceComponentId
  659. * @method assignHostToMaster
  660. */
  661. assignHostToMaster: function (componentName, selectedHost, serviceComponentId) {
  662. var flag = this.isHostNameValid(componentName, selectedHost);
  663. this.updateIsHostNameValidFlag(componentName, serviceComponentId, flag);
  664. if (serviceComponentId) {
  665. this.get('selectedServicesMasters').filterProperty('component_name', componentName).findProperty("serviceComponentId", serviceComponentId).set("selectedHost", selectedHost);
  666. }
  667. else {
  668. this.get('selectedServicesMasters').findProperty("component_name", componentName).set("selectedHost", selectedHost);
  669. }
  670. },
  671. /**
  672. * Determines if hostName is valid for component:
  673. * <ul>
  674. * <li>host name shouldn't be empty</li>
  675. * <li>host should exist</li>
  676. * <li>host should have only one component with <code>componentName</code></li>
  677. * </ul>
  678. * @param {string} componentName
  679. * @param {string} selectedHost
  680. * @returns {boolean} true - valid, false - invalid
  681. * @method isHostNameValid
  682. */
  683. isHostNameValid: function (componentName, selectedHost) {
  684. return (selectedHost.trim() !== '') &&
  685. this.get('hosts').mapProperty('host_name').contains(selectedHost) &&
  686. (this.get('selectedServicesMasters').
  687. filterProperty('component_name', componentName).
  688. mapProperty('selectedHost').
  689. filter(function (h) {
  690. return h === selectedHost;
  691. }).length <= 1);
  692. },
  693. /**
  694. * Update <code>isHostNameValid</code> property with <code>flag</code> value
  695. * for component with name <code>componentName</code> and
  696. * <code>serviceComponentId</code>-property equal to <code>serviceComponentId</code>-parameter value
  697. * @param {string} componentName
  698. * @param {number} serviceComponentId
  699. * @param {bool} flag
  700. * @method updateIsHostNameValidFlag
  701. */
  702. updateIsHostNameValidFlag: function (componentName, serviceComponentId, flag) {
  703. if (componentName) {
  704. if (serviceComponentId) {
  705. this.get('selectedServicesMasters').filterProperty('component_name', componentName).findProperty("serviceComponentId", serviceComponentId).set("isHostNameValid", flag);
  706. } else {
  707. this.get('selectedServicesMasters').findProperty("component_name", componentName).set("isHostNameValid", flag);
  708. }
  709. }
  710. },
  711. /**
  712. * Returns last component of selected type
  713. * @param {string} componentName
  714. * @return {Em.Object|null}
  715. * @method last
  716. */
  717. last: function (componentName) {
  718. return this.get("selectedServicesMasters").filterProperty("component_name", componentName).get("lastObject");
  719. },
  720. /**
  721. * Add new component to ZooKeeper Server and Hbase master
  722. * @param {string} componentName
  723. * @return {bool} true - added, false - not added
  724. * @method addComponent
  725. */
  726. addComponent: function (componentName) {
  727. /*
  728. * Logic: If ZooKeeper or Hbase service is selected then there can be
  729. * minimum 1 ZooKeeper or Hbase master in total, and
  730. * maximum 1 ZooKeeper or Hbase on every host
  731. */
  732. var maxNumMasters = this.get("hosts.length"),
  733. currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName),
  734. newMaster = null,
  735. masterHosts = null,
  736. suggestedHost = null,
  737. i = 0,
  738. lastMaster = null;
  739. if (!currentMasters.length) {
  740. console.log('ALERT: Zookeeper service was not selected');
  741. return false;
  742. }
  743. if (currentMasters.get("length") < maxNumMasters) {
  744. currentMasters.set("lastObject.showAddControl", false);
  745. currentMasters.set("lastObject.showRemoveControl", true);
  746. //create a new master component host based on an existing one
  747. newMaster = Em.Object.create({});
  748. lastMaster = currentMasters.get("lastObject");
  749. newMaster.set("display_name", lastMaster.get("display_name"));
  750. newMaster.set("component_name", lastMaster.get("component_name"));
  751. newMaster.set("selectedHost", lastMaster.get("selectedHost"));
  752. newMaster.set("serviceId", lastMaster.get("serviceId"));
  753. newMaster.set("isInstalled", false);
  754. if (currentMasters.get("length") === (maxNumMasters - 1)) {
  755. newMaster.set("showAddControl", false);
  756. } else {
  757. newMaster.set("showAddControl", true);
  758. }
  759. newMaster.set("showRemoveControl", true);
  760. //get recommended host for the new Zookeeper server
  761. masterHosts = currentMasters.mapProperty("selectedHost").uniq();
  762. for (i = 0; i < this.get("hosts.length"); i++) {
  763. if (!(masterHosts.contains(this.get("hosts")[i].get("host_name")))) {
  764. suggestedHost = this.get("hosts")[i].get("host_name");
  765. break;
  766. }
  767. }
  768. newMaster.set("selectedHost", suggestedHost);
  769. newMaster.set("serviceComponentId", (currentMasters.get("lastObject.serviceComponentId") + 1));
  770. this.get("selectedServicesMasters").insertAt(this.get("selectedServicesMasters").indexOf(lastMaster) + 1, newMaster);
  771. this.set('componentToRebalance', componentName);
  772. this.incrementProperty('rebalanceComponentHostsCounter');
  773. this.toggleProperty('hostNameCheckTrigger');
  774. return true;
  775. }
  776. return false;//if no more zookeepers can be added
  777. },
  778. /**
  779. * Remove component from ZooKeeper server or Hbase Master
  780. * @param {string} componentName
  781. * @param {number} serviceComponentId
  782. * @return {bool} true - removed, false - no
  783. * @method removeComponent
  784. */
  785. removeComponent: function (componentName, serviceComponentId) {
  786. var currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName);
  787. //work only if the multiple master service is selected in previous step
  788. if (currentMasters.length <= 1) {
  789. return false;
  790. }
  791. this.get("selectedServicesMasters").removeAt(this.get("selectedServicesMasters").indexOf(currentMasters.findProperty("serviceComponentId", serviceComponentId)));
  792. currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName);
  793. if (currentMasters.get("length") < this.get("hosts.length")) {
  794. currentMasters.set("lastObject.showAddControl", true);
  795. }
  796. if (currentMasters.get("length") === 1) {
  797. currentMasters.set("lastObject.showRemoveControl", false);
  798. }
  799. this.set('componentToRebalance', componentName);
  800. this.incrementProperty('rebalanceComponentHostsCounter');
  801. this.toggleProperty('hostNameCheckTrigger');
  802. return true;
  803. },
  804. recommendAndValidate: function(callback) {
  805. var self = this;
  806. // load recommendations with partial request
  807. self.loadComponentsRecommendationsFromServer(function() {
  808. // For validation use latest received recommendations because ir contains current master layout and recommended slave/client layout
  809. self.validate(self.get('content.recommendations'), function() {
  810. if (callback) {
  811. callback();
  812. }
  813. });
  814. }, true);
  815. },
  816. /**
  817. * Submit button click handler
  818. * @method submit
  819. */
  820. submit: function () {
  821. var self = this;
  822. if (!this.get('submitButtonClicked')) {
  823. this.set('submitButtonClicked', true);
  824. var goNextStepIfValid = function () {
  825. if (!self.get('submitDisabled')) {
  826. App.router.send('next');
  827. }
  828. self.set('submitButtonClicked', false);
  829. };
  830. if (this.get('useServerValidation')) {
  831. self.recommendAndValidate(function () {
  832. self.showValidationIssuesAcceptBox(goNextStepIfValid);
  833. });
  834. } else {
  835. self.updateIsSubmitDisabled();
  836. goNextStepIfValid();
  837. }
  838. }
  839. },
  840. /**
  841. * In case of any validation issues shows accept dialog box for user which allow cancel and fix issues or continue anyway
  842. * @method showValidationIssuesAcceptBox
  843. */
  844. showValidationIssuesAcceptBox: function(callback) {
  845. var self = this;
  846. if (self.get('anyWarning') || self.get('anyError')) {
  847. App.ModalPopup.show({
  848. primary: Em.I18n.t('common.continueAnyway'),
  849. header: Em.I18n.t('installer.step5.validationIssuesAttention.header'),
  850. body: Em.I18n.t('installer.step5.validationIssuesAttention'),
  851. onPrimary: function () {
  852. this.hide();
  853. callback();
  854. }
  855. });
  856. } else {
  857. callback();
  858. }
  859. }
  860. });