step5_controller.js 33 KB

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