step5_controller.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  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 numberUtils = require('utils/number_utils');
  20. App.WizardStep5Controller = Em.Controller.extend({
  21. name: "wizardStep5Controller",
  22. /**
  23. * Step title
  24. * Custom if <code>App.ReassignMasterController</code> is used
  25. * @type {string}
  26. */
  27. title: function () {
  28. if (this.get('content.controllerName') == 'reassignMasterController') {
  29. return Em.I18n.t('installer.step5.reassign.header');
  30. }
  31. return Em.I18n.t('installer.step5.header');
  32. }.property('content.controllerName'),
  33. /**
  34. * Is ReassignWizard used
  35. * @type {bool}
  36. */
  37. isReassignWizard: function () {
  38. return this.get('content.controllerName') == 'reassignMasterController';
  39. }.property('content.controllerName'),
  40. /**
  41. * Is isHighAvailabilityWizard used
  42. * @type {bool}
  43. */
  44. isHighAvailabilityWizard: function () {
  45. return this.get('content.controllerName') == 'highAvailabilityWizardController';
  46. }.property('content.controllerName'),
  47. /**
  48. * Is AddServiceWizard used
  49. * @type {bool}
  50. */
  51. isAddServiceWizard: function () {
  52. return this.get('content.controllerName') == 'addServiceController';
  53. }.property('content.controllerName'),
  54. /**
  55. * Master components which could be assigned to multiple hosts
  56. * @type {string[]}
  57. */
  58. multipleComponents: function () {
  59. return App.get('components.multipleMasters');
  60. }.property('App.components.multipleMasters'),
  61. /**
  62. * Master components which could be assigned to multiple hosts
  63. * @type {string[]}
  64. */
  65. addableComponents: function () {
  66. return App.get('components.addableMasterInstallerWizard');
  67. }.property('App.components.addableMasterInstallerWizard'),
  68. /**
  69. * Define state for submit button
  70. * @type {bool}
  71. */
  72. submitDisabled: false,
  73. /**
  74. * Trigger for executing host names check for components
  75. * Should de "triggered" when host changed for some component and when new multiple component is added/removed
  76. * @type {bool}
  77. */
  78. hostNameCheckTrigger: false,
  79. /**
  80. * List of hosts
  81. * @type {Array}
  82. */
  83. hosts: [],
  84. /**
  85. * Name of multiple component which host name was changed last
  86. * @type {Object|null}
  87. */
  88. componentToRebalance: null,
  89. /**
  90. * Name of component which host was changed last
  91. * @type {string}
  92. */
  93. lastChangedComponent: null,
  94. /**
  95. * Flag for rebalance multiple components
  96. * @type {number}
  97. */
  98. rebalanceComponentHostsCounter: 0,
  99. /**
  100. * @type {Ember.Enumerable}
  101. */
  102. servicesMasters: [],
  103. /**
  104. * @type {Ember.Enumerable}
  105. */
  106. selectedServicesMasters: [],
  107. /**
  108. * Is data for current step loaded
  109. * @type {bool}
  110. */
  111. isLoaded: false,
  112. /**
  113. * List of host with assigned masters
  114. * Format:
  115. * <code>
  116. * [
  117. * {
  118. * host_name: '',
  119. * hostInfo: {},
  120. * masterServices: [],
  121. * masterServicesToDisplay: [] // used only in template
  122. * },
  123. * ....
  124. * ]
  125. * </code>
  126. * @type {Ember.Enumerable}
  127. */
  128. masterHostMapping: function () {
  129. var mapping = [], mappingObject, mappedHosts, hostObj;
  130. //get the unique assigned hosts and find the master services assigned to them
  131. mappedHosts = this.get("selectedServicesMasters").mapProperty("selectedHost").uniq();
  132. mappedHosts.forEach(function (item) {
  133. hostObj = this.get("hosts").findProperty("host_name", item);
  134. // User may input invalid host name (this is handled in hostname checker). Here we just skip it
  135. if (!hostObj) return;
  136. var masterServices = this.get("selectedServicesMasters").filterProperty("selectedHost", item),
  137. masterServicesToDisplay = [];
  138. masterServices.mapProperty('display_name').uniq().forEach(function (n) {
  139. masterServicesToDisplay.pushObject(masterServices.findProperty('display_name', n));
  140. });
  141. mappingObject = Em.Object.create({
  142. host_name: item,
  143. hostInfo: hostObj.host_info,
  144. masterServices: masterServices,
  145. masterServicesToDisplay: masterServicesToDisplay
  146. });
  147. mapping.pushObject(mappingObject);
  148. }, this);
  149. return mapping.sortProperty('host_name');
  150. }.property("selectedServicesMasters.@each.selectedHost", 'selectedServicesMasters.@each.isHostNameValid'),
  151. /**
  152. * Count of hosts without masters
  153. * @type {number}
  154. */
  155. remainingHosts: function () {
  156. if (this.get('content.controllerName') === 'installerController') {
  157. return 0;
  158. } else {
  159. return (this.get("hosts.length") - this.get("masterHostMapping.length"));
  160. }
  161. }.property('masterHostMapping.length', 'selectedServicesMasters.@each.selectedHost'),
  162. /**
  163. * Update submit button status
  164. * @metohd getIsSubmitDisabled
  165. */
  166. getIsSubmitDisabled: function () {
  167. var isSubmitDisabled = this.get('servicesMasters').someProperty('isHostNameValid', false);
  168. this.set('submitDisabled', isSubmitDisabled);
  169. return isSubmitDisabled;
  170. }.observes('servicesMasters.@each.selectedHost', 'servicesMasters.@each.isHostNameValid'),
  171. /**
  172. * Clear controller data (hosts, masters etc)
  173. * @method clearStep
  174. */
  175. clearStep: function () {
  176. this.set('hosts', []);
  177. this.set('selectedServicesMasters', []);
  178. this.set('servicesMasters', []);
  179. App.StackServiceComponent.find().forEach(function (stackComponent) {
  180. stackComponent.set('serviceComponentId', 1);
  181. }, this);
  182. },
  183. /**
  184. * Load controller data (hosts, host components etc)
  185. * @method loadStep
  186. */
  187. loadStep: function () {
  188. console.log("WizardStep5Controller: Loading step5: Assign Masters");
  189. this.clearStep();
  190. this.renderHostInfo();
  191. this.loadComponentRecommendations(this.loadStepCallback);
  192. },
  193. /**
  194. * Callback after load controller data (hosts, host components etc)
  195. * @method loadStepCallback
  196. */
  197. loadStepCallback: function(components, self) {
  198. self.renderComponents(components);
  199. self.get('addableComponents').forEach(function (componentName) {
  200. self.updateComponent(componentName);
  201. }, self);
  202. if (!self.get("selectedServicesMasters").filterProperty('isInstalled', false).length) {
  203. console.log('no master components to add');
  204. App.router.send('next');
  205. }
  206. },
  207. /**
  208. * Used to set showAddControl flag for installer wizard
  209. * @method updateComponent
  210. */
  211. updateComponent: function (componentName) {
  212. var component = this.last(componentName);
  213. if (!component) {
  214. return;
  215. }
  216. var services = App.StackService.find().filterProperty('isInstalled', true).mapProperty('serviceName');
  217. var currentService = componentName.split('_')[0];
  218. var showControl = !services.contains(currentService);
  219. if (showControl) {
  220. if (this.get("selectedServicesMasters").filterProperty("component_name", componentName).length < this.get("hosts.length") && !this.get('isReassignWizard') && !this.get('isHighAvailabilityWizard')) {
  221. component.set('showAddControl', true);
  222. } else {
  223. component.set('showRemoveControl', false);
  224. }
  225. }
  226. },
  227. /**
  228. * Load active host list to <code>hosts</code> variable
  229. * @method renderHostInfo
  230. */
  231. renderHostInfo: function () {
  232. var hostInfo = this.get('content.hosts');
  233. var result = [];
  234. for (var index in hostInfo) {
  235. var _host = hostInfo[index];
  236. if (_host.bootStatus === 'REGISTERED') {
  237. result.push(Em.Object.create({
  238. host_name: _host.name,
  239. cpu: _host.cpu,
  240. memory: _host.memory,
  241. disk_info: _host.disk_info,
  242. host_info: Em.I18n.t('installer.step5.hostInfo').fmt(_host.name, numberUtils.bytesToSize(_host.memory, 1, 'parseFloat', 1024), _host.cpu)
  243. }));
  244. }
  245. }
  246. this.set("hosts", result);
  247. this.sortHosts(this.get('hosts'));
  248. this.set('isLoaded', true);
  249. },
  250. /**
  251. * Sort list of host-objects by properties (memory - desc, cpu - desc, hostname - asc)
  252. * @param {object[]} hosts
  253. */
  254. sortHosts: function (hosts) {
  255. hosts.sort(function (a, b) {
  256. if (a.get('memory') == b.get('memory')) {
  257. if (a.get('cpu') == b.get('cpu')) {
  258. return a.get('host_name').localeCompare(b.get('host_name')); // hostname asc
  259. }
  260. return b.get('cpu') - a.get('cpu'); // cores desc
  261. }
  262. return b.get('memory') - a.get('memory'); // ram desc
  263. });
  264. },
  265. /**
  266. * Get recommendations info from API
  267. * @return {undefined}
  268. */
  269. loadComponentRecommendations: function(callback) {
  270. var self = this;
  271. if (App.router.get('installerController.recommendations') !== undefined) {
  272. // Don't do AJAX call if recommendations has been already received
  273. // 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
  274. callback(self.createComponentInstalltationObjects(), self);
  275. } else {
  276. var selectedServices = App.StackService.find().filterProperty('isSelected').mapProperty('serviceName');
  277. var installedServices = App.StackService.find().filterProperty('isInstalled').mapProperty('serviceName');
  278. var services = installedServices.concat(selectedServices).uniq();
  279. var hostNames = self.get('hosts').mapProperty('host_name');
  280. return App.ajax.send({
  281. name: 'wizard.step5.recommendations',
  282. sender: self,
  283. data: {
  284. stackVersionUrl: App.get('stackVersionURL'),
  285. hosts: hostNames,
  286. services: services
  287. },
  288. success: 'loadRecommendationsSuccessCallback'
  289. }).
  290. retry({
  291. times: App.maxRetries,
  292. timeout: App.timeout
  293. }).
  294. then(function () {
  295. callback(self.createComponentInstalltationObjects(), self);
  296. },
  297. function () {
  298. App.showReloadPopup();
  299. console.log('Load recommendations failed');
  300. }
  301. );
  302. }
  303. },
  304. /**
  305. * Create components for displaying component-host comboboxes in UI assign dialog
  306. * expects installerController.recommendations will be filled with recommendations API call result
  307. * @return {Object[]}
  308. */
  309. createComponentInstalltationObjects: function() {
  310. var self = this;
  311. var masterComponents = [];
  312. if (self.get('isAddServiceWizard')) {
  313. masterComponents = App.StackServiceComponent.find().filterProperty('isShownOnAddServiceAssignMasterPage');
  314. } else {
  315. masterComponents = App.StackServiceComponent.find().filterProperty('isShownOnInstallerAssignMasterPage');
  316. }
  317. var masterHosts = self.get('content.masterComponentHosts'); //saved to local storage info
  318. var selectedNotInstalledServices = self.get('content.services').filterProperty('isSelected').filterProperty('isInstalled', false).mapProperty('serviceName');
  319. var recommendations = App.router.get('installerController.recommendations');
  320. var resultComponents = [];
  321. var multipleComponentHasBeenAdded = {};
  322. recommendations.blueprint.host_groups.forEach(function(host_group) {
  323. var hosts = recommendations.blueprint_cluster_binding.host_groups.findProperty('name', host_group.name).hosts;
  324. hosts.forEach(function(host) {
  325. host_group.components.forEach(function(component) {
  326. var willBeAdded = true;
  327. var fullComponent = masterComponents.findProperty('componentName', component.name);
  328. // If it's master component which should be shown
  329. if (fullComponent) {
  330. // If service is already installed and not being added as a new service then render on UI only those master components
  331. // that have already installed hostComponents.
  332. // NOTE: On upgrade there might be a prior installed service with non-installed newly introduced serviceComponent
  333. var isNotSelectedService = !selectedNotInstalledServices.contains(fullComponent.get('serviceName'));
  334. if (isNotSelectedService) {
  335. willBeAdded = App.HostComponent.find().someProperty('componentName', component.name);
  336. }
  337. if (willBeAdded) {
  338. var savedComponents = masterHosts.filterProperty('component', component.name);
  339. if (self.get('multipleComponents').contains(component.name) && savedComponents.length > 0) {
  340. if (!multipleComponentHasBeenAdded[component.name]) {
  341. multipleComponentHasBeenAdded[component.name] = true;
  342. savedComponents.forEach(function(saved) {
  343. resultComponents.push(self.createComponentInstalltationObject(fullComponent, host.fqdn, saved));
  344. });
  345. }
  346. } else {
  347. var savedComponent = masterHosts.findProperty('component', component.name);
  348. resultComponents.push(self.createComponentInstalltationObject(fullComponent, host.fqdn, savedComponent));
  349. }
  350. }
  351. }
  352. });
  353. });
  354. });
  355. return resultComponents;
  356. },
  357. /**
  358. * Create component for displaying component-host comboboxes in UI assign dialog
  359. * @param fullComponent - full component description
  360. * @param hostName - host fqdn where component will be installed
  361. * @param savedComponent - the same object which function returns but created before
  362. * @return {Object}
  363. */
  364. createComponentInstalltationObject: function(fullComponent, hostName, savedComponent) {
  365. var componentName = fullComponent.get('componentName');
  366. var componentObj = {};
  367. componentObj.component_name = componentName;
  368. componentObj.display_name = fullComponent.get('displayName');
  369. componentObj.serviceId = fullComponent.get('serviceName');
  370. componentObj.isServiceCoHost = App.StackServiceComponent.find().findProperty('componentName', componentName).get('isCoHostedComponent') && !this.get('isReassignWizard');
  371. if (savedComponent) {
  372. componentObj.selectedHost = savedComponent.hostName;
  373. componentObj.isInstalled = savedComponent.isInstalled;
  374. } else {
  375. componentObj.selectedHost = hostName;
  376. componentObj.isInstalled = false;
  377. }
  378. return componentObj;
  379. },
  380. /**
  381. * Success-callback for recommendations request
  382. * @param {object} data
  383. * @method loadRecommendationsSuccessCallback
  384. */
  385. loadRecommendationsSuccessCallback: function (data) {
  386. App.router.set('installerController.recommendations', data.resources[0].recommendations);
  387. },
  388. /**
  389. * @param {string} componentName
  390. * @returns {bool}
  391. * @private
  392. * @method _isHiveCoHost
  393. */
  394. _isHiveCoHost: function (componentName) {
  395. return ['HIVE_METASTORE', 'WEBHCAT_SERVER'].contains(componentName) && !this.get('isReassignWizard');
  396. },
  397. /**
  398. * Put master components to <code>selectedServicesMasters</code>, which will be automatically rendered in template
  399. * @param {Ember.Enumerable} masterComponents
  400. * @method renderComponents
  401. */
  402. renderComponents: function (masterComponents) {
  403. var installedServices = App.StackService.find().filterProperty('isSelected').filterProperty('isInstalled', false).mapProperty('serviceName'); //list of shown services
  404. var result = [];
  405. var serviceComponentId, previousComponentName;
  406. masterComponents.forEach(function (item) {
  407. var serviceComponent = App.StackServiceComponent.find().findProperty('componentName', item.component_name);
  408. var showRemoveControl = installedServices.contains(serviceComponent.get('stackService.serviceName')) &&
  409. (masterComponents.filterProperty('component_name', item.component_name).length > 1);
  410. var componentObj = Em.Object.create(item);
  411. console.log("TRACE: render master component name is: " + item.component_name);
  412. var masterComponent = App.StackServiceComponent.find().findProperty('componentName', item.component_name);
  413. if (masterComponent.get('isMasterWithMultipleInstances')) {
  414. previousComponentName = item.component_name;
  415. componentObj.set('serviceComponentId', result.filterProperty('component_name', item.component_name).length + 1);
  416. componentObj.set("showRemoveControl", showRemoveControl);
  417. }
  418. componentObj.set('isHostNameValid', true);
  419. result.push(componentObj);
  420. }, this);
  421. this.set("selectedServicesMasters", result);
  422. if (this.get('isReassignWizard')) {
  423. var components = result.filterProperty('component_name', this.get('content.reassign.component_name'));
  424. components.setEach('isInstalled', false);
  425. this.set('servicesMasters', components);
  426. } else {
  427. this.set('servicesMasters', result);
  428. }
  429. },
  430. /**
  431. * Update dependent co-hosted components according to the change in the component host
  432. * @method updateCoHosts
  433. */
  434. updateCoHosts: function () {
  435. var components = App.StackServiceComponent.find().filterProperty('isOtherComponentCoHosted');
  436. var selectedServicesMasters = this.get('selectedServicesMasters');
  437. components.forEach(function (component) {
  438. var componentName = component.get('componentName');
  439. var hostComponent = selectedServicesMasters.findProperty('component_name', componentName);
  440. var dependentCoHosts = component.get('coHostedComponents');
  441. dependentCoHosts.forEach(function (coHostedComponent) {
  442. var dependentHostComponent = selectedServicesMasters.findProperty('component_name', coHostedComponent);
  443. if (hostComponent && dependentHostComponent) dependentHostComponent.set('selectedHost', hostComponent.get('selectedHost'));
  444. }, this);
  445. }, this);
  446. }.observes('selectedServicesMasters.@each.selectedHost'),
  447. /**
  448. * On change callback for inputs
  449. * @param {string} componentName
  450. * @param {string} selectedHost
  451. * @param {number} serviceComponentId
  452. * @method assignHostToMaster
  453. */
  454. assignHostToMaster: function (componentName, selectedHost, serviceComponentId) {
  455. var flag = this.isHostNameValid(componentName, selectedHost);
  456. this.updateIsHostNameValidFlag(componentName, serviceComponentId, flag);
  457. if (serviceComponentId) {
  458. this.get('selectedServicesMasters').filterProperty('component_name', componentName).findProperty("serviceComponentId", serviceComponentId).set("selectedHost", selectedHost);
  459. }
  460. else {
  461. this.get('selectedServicesMasters').findProperty("component_name", componentName).set("selectedHost", selectedHost);
  462. }
  463. },
  464. /**
  465. * Determines if hostName is valid for component:
  466. * <ul>
  467. * <li>host name shouldn't be empty</li>
  468. * <li>host should exist</li>
  469. * <li>host should have only one component with <code>componentName</code></li>
  470. * </ul>
  471. * @param {string} componentName
  472. * @param {string} selectedHost
  473. * @returns {boolean} true - valid, false - invalid
  474. * @method isHostNameValid
  475. */
  476. isHostNameValid: function (componentName, selectedHost) {
  477. return (selectedHost.trim() !== '') &&
  478. this.get('hosts').mapProperty('host_name').contains(selectedHost) &&
  479. (this.get('selectedServicesMasters').
  480. filterProperty('component_name', componentName).
  481. mapProperty('selectedHost').
  482. filter(function (h) {
  483. return h === selectedHost;
  484. }).length <= 1);
  485. },
  486. /**
  487. * Update <code>isHostNameValid</code> property with <code>flag</code> value
  488. * for component with name <code>componentName</code> and
  489. * <code>serviceComponentId</code>-property equal to <code>serviceComponentId</code>-parameter value
  490. * @param {string} componentName
  491. * @param {number} serviceComponentId
  492. * @param {bool} flag
  493. * @method updateIsHostNameValidFlag
  494. */
  495. updateIsHostNameValidFlag: function (componentName, serviceComponentId, flag) {
  496. if (componentName) {
  497. if (serviceComponentId) {
  498. this.get('selectedServicesMasters').filterProperty('component_name', componentName).findProperty("serviceComponentId", serviceComponentId).set("isHostNameValid", flag);
  499. } else {
  500. this.get('selectedServicesMasters').findProperty("component_name", componentName).set("isHostNameValid", flag);
  501. }
  502. }
  503. },
  504. /**
  505. * Returns last component of selected type
  506. * @param {string} componentName
  507. * @return {Em.Object|null}
  508. * @method last
  509. */
  510. last: function (componentName) {
  511. return this.get("selectedServicesMasters").filterProperty("component_name", componentName).get("lastObject");
  512. },
  513. /**
  514. * Add new component to ZooKeeper Server and Hbase master
  515. * @param {string} componentName
  516. * @return {bool} true - added, false - not added
  517. * @method addComponent
  518. */
  519. addComponent: function (componentName) {
  520. /*
  521. * Logic: If ZooKeeper or Hbase service is selected then there can be
  522. * minimum 1 ZooKeeper or Hbase master in total, and
  523. * maximum 1 ZooKeeper or Hbase on every host
  524. */
  525. var maxNumMasters = this.get("hosts.length"),
  526. currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName),
  527. newMaster = null,
  528. masterHosts = null,
  529. suggestedHost = null,
  530. i = 0,
  531. lastMaster = null;
  532. if (!currentMasters.length) {
  533. console.log('ALERT: Zookeeper service was not selected');
  534. return false;
  535. }
  536. if (currentMasters.get("length") < maxNumMasters) {
  537. currentMasters.set("lastObject.showAddControl", false);
  538. currentMasters.set("lastObject.showRemoveControl", true);
  539. //create a new master component host based on an existing one
  540. newMaster = Em.Object.create({});
  541. lastMaster = currentMasters.get("lastObject");
  542. newMaster.set("display_name", lastMaster.get("display_name"));
  543. newMaster.set("component_name", lastMaster.get("component_name"));
  544. newMaster.set("selectedHost", lastMaster.get("selectedHost"));
  545. newMaster.set("isInstalled", false);
  546. if (currentMasters.get("length") === (maxNumMasters - 1)) {
  547. newMaster.set("showAddControl", false);
  548. } else {
  549. newMaster.set("showAddControl", true);
  550. }
  551. newMaster.set("showRemoveControl", true);
  552. //get recommended host for the new Zookeeper server
  553. masterHosts = currentMasters.mapProperty("selectedHost").uniq();
  554. for (i = 0; i < this.get("hosts.length"); i++) {
  555. if (!(masterHosts.contains(this.get("hosts")[i].get("host_name")))) {
  556. suggestedHost = this.get("hosts")[i].get("host_name");
  557. break;
  558. }
  559. }
  560. newMaster.set("selectedHost", suggestedHost);
  561. newMaster.set("serviceComponentId", (currentMasters.get("lastObject.serviceComponentId") + 1));
  562. this.get("selectedServicesMasters").insertAt(this.get("selectedServicesMasters").indexOf(lastMaster) + 1, newMaster);
  563. this.set('componentToRebalance', componentName);
  564. this.incrementProperty('rebalanceComponentHostsCounter');
  565. this.toggleProperty('hostNameCheckTrigger');
  566. return true;
  567. }
  568. return false;//if no more zookeepers can be added
  569. },
  570. /**
  571. * Remove component from ZooKeeper server or Hbase Master
  572. * @param {string} componentName
  573. * @param {number} serviceComponentId
  574. * @return {bool} true - removed, false - no
  575. * @method removeComponent
  576. */
  577. removeComponent: function (componentName, serviceComponentId) {
  578. var currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName);
  579. //work only if the multiple master service is selected in previous step
  580. if (currentMasters.length <= 1) {
  581. return false;
  582. }
  583. this.get("selectedServicesMasters").removeAt(this.get("selectedServicesMasters").indexOf(currentMasters.findProperty("serviceComponentId", serviceComponentId)));
  584. currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName);
  585. if (currentMasters.get("length") < this.get("hosts.length")) {
  586. currentMasters.set("lastObject.showAddControl", true);
  587. }
  588. if (currentMasters.get("length") === 1) {
  589. currentMasters.set("lastObject.showRemoveControl", false);
  590. }
  591. this.set('componentToRebalance', componentName);
  592. this.incrementProperty('rebalanceComponentHostsCounter');
  593. this.toggleProperty('hostNameCheckTrigger');
  594. return true;
  595. },
  596. /**
  597. * Submit button click handler
  598. * @metohd submit
  599. */
  600. submit: function () {
  601. this.getIsSubmitDisabled();
  602. if (!this.get('submitDisabled')) {
  603. App.router.send('next');
  604. }
  605. }
  606. });