step5_controller.js 33 KB

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