step5_controller.js 33 KB

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