step5_controller.js 25 KB

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