step5_controller.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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.renderComponents(this.loadComponents());
  192. this.get('addableComponents').forEach(function (componentName) {
  193. this.updateComponent(componentName);
  194. }, this);
  195. if (!this.get("selectedServicesMasters").filterProperty('isInstalled', false).length) {
  196. console.log('no master components to add');
  197. App.router.send('next');
  198. }
  199. },
  200. /**
  201. * Used to set showAddControl flag for installer wizard
  202. * @method updateComponent
  203. */
  204. updateComponent: function (componentName) {
  205. var component = this.last(componentName);
  206. if (!component) {
  207. return;
  208. }
  209. var services = App.StackService.find().filterProperty('isInstalled', true).mapProperty('serviceName');
  210. var currentService = componentName.split('_')[0];
  211. var showControl = !services.contains(currentService);
  212. if (showControl) {
  213. if (this.get("selectedServicesMasters").filterProperty("component_name", componentName).length < this.get("hosts.length") && !this.get('isReassignWizard') && !this.get('isHighAvailabilityWizard')) {
  214. component.set('showAddControl', true);
  215. } else {
  216. component.set('showRemoveControl', false);
  217. }
  218. }
  219. },
  220. /**
  221. * Load active host list to <code>hosts</code> variable
  222. * @method renderHostInfo
  223. */
  224. renderHostInfo: function () {
  225. var hostInfo = this.get('content.hosts');
  226. var result = [];
  227. for (var index in hostInfo) {
  228. var _host = hostInfo[index];
  229. if (_host.bootStatus === 'REGISTERED') {
  230. result.push(Em.Object.create({
  231. host_name: _host.name,
  232. cpu: _host.cpu,
  233. memory: _host.memory,
  234. disk_info: _host.disk_info,
  235. host_info: Em.I18n.t('installer.step5.hostInfo').fmt(_host.name, numberUtils.bytesToSize(_host.memory, 1, 'parseFloat', 1024), _host.cpu)
  236. }));
  237. }
  238. }
  239. this.set("hosts", result);
  240. this.sortHosts(this.get('hosts'));
  241. this.set('isLoaded', true);
  242. },
  243. /**
  244. * Sort list of host-objects by properties (memory - desc, cpu - desc, hostname - asc)
  245. * @param {object[]} hosts
  246. */
  247. sortHosts: function (hosts) {
  248. hosts.sort(function (a, b) {
  249. if (a.get('memory') == b.get('memory')) {
  250. if (a.get('cpu') == b.get('cpu')) {
  251. return a.get('host_name').localeCompare(b.get('host_name')); // hostname asc
  252. }
  253. return b.get('cpu') - a.get('cpu'); // cores desc
  254. }
  255. return b.get('memory') - a.get('memory'); // ram desc
  256. });
  257. },
  258. /**
  259. * Load services info to appropriate variable and return masterComponentHosts
  260. * @return {Object[]}
  261. */
  262. loadComponents: function () {
  263. var selectedServices = App.StackService.find().filterProperty('isSelected').mapProperty('serviceName');
  264. var installedServices = App.StackService.find().filterProperty('isInstalled').mapProperty('serviceName');
  265. var services = installedServices.concat(selectedServices).uniq();
  266. var selectedNotInstalledServices = this.get('content.services').filterProperty('isSelected').filterProperty('isInstalled', false).mapProperty('serviceName');
  267. var masterComponents = [];
  268. //get full list from mock data
  269. if (this.get('isAddServiceWizard')) {
  270. masterComponents = App.StackServiceComponent.find().filterProperty('isShownOnAddServiceAssignMasterPage');
  271. } else {
  272. masterComponents = App.StackServiceComponent.find().filterProperty('isShownOnInstallerAssignMasterPage');
  273. }
  274. var masterHosts = this.get('content.masterComponentHosts'); //saved to local storage info
  275. var resultComponents = [];
  276. for (var index = 0; index < services.length; index++) {
  277. var componentInfo = masterComponents.filterProperty('serviceName', services[index]);
  278. // If service is already installed and not being added as a new service then render on UI only those master components
  279. // that have already installed hostComponents.
  280. // NOTE: On upgrade there might be a prior installed service with non-installed newly introduced serviceComponent
  281. var isNotSelectedService = !selectedNotInstalledServices.contains(services[index]);
  282. if (isNotSelectedService) {
  283. componentInfo = componentInfo.filter(function (_component) {
  284. return App.HostComponent.find().someProperty('componentName',_component.get('componentName'));
  285. });
  286. }
  287. componentInfo.forEach(function (_componentInfo) {
  288. if (this.get('multipleComponents').contains(_componentInfo.get('componentName'))) {
  289. var savedComponents = masterHosts.filterProperty('component', _componentInfo.get('componentName'));
  290. if (savedComponents.length) {
  291. savedComponents.forEach(function (item) {
  292. var multipleMasterHost = {};
  293. multipleMasterHost.component_name = _componentInfo.get('componentName');
  294. multipleMasterHost.display_name = _componentInfo.get('displayName');
  295. multipleMasterHost.selectedHost = item.hostName;
  296. multipleMasterHost.serviceId = services[index];
  297. multipleMasterHost.isInstalled = item.isInstalled;
  298. multipleMasterHost.isServiceCoHost = false;
  299. resultComponents.push(multipleMasterHost);
  300. })
  301. } else {
  302. var multipleMasterHosts = this.selectHost(_componentInfo.get('componentName'));
  303. multipleMasterHosts.forEach(function (_host) {
  304. var multipleMasterHost = {};
  305. multipleMasterHost.component_name = _componentInfo.get('componentName');
  306. multipleMasterHost.display_name = _componentInfo.get('displayName');
  307. multipleMasterHost.selectedHost = _host;
  308. multipleMasterHost.serviceId = services[index];
  309. multipleMasterHost.isInstalled = false;
  310. multipleMasterHost.isServiceCoHost = false;
  311. resultComponents.push(multipleMasterHost);
  312. });
  313. }
  314. } else {
  315. var savedComponent = masterHosts.findProperty('component', _componentInfo.get('componentName'));
  316. var componentObj = {};
  317. componentObj.component_name = _componentInfo.get('componentName');
  318. componentObj.display_name = _componentInfo.get('displayName');
  319. componentObj.selectedHost = savedComponent ? savedComponent.hostName : this.selectHost(_componentInfo.get('componentName')); // call the method that plays selectNode algorithm or fetches from server
  320. componentObj.isInstalled = savedComponent ? savedComponent.isInstalled : false;
  321. componentObj.serviceId = services[index];
  322. componentObj.isServiceCoHost = App.StackServiceComponent.find().findProperty('componentName', _componentInfo.get('componentName')).get('isCoHostedComponent') && !this.get('isReassignWizard');
  323. resultComponents.push(componentObj);
  324. }
  325. }, this);
  326. }
  327. return resultComponents;
  328. },
  329. /**
  330. * @param {string} componentName
  331. * @returns {bool}
  332. * @private
  333. * @method _isHiveCoHost
  334. */
  335. _isHiveCoHost: function (componentName) {
  336. return ['HIVE_METASTORE', 'WEBHCAT_SERVER'].contains(componentName) && !this.get('isReassignWizard');
  337. },
  338. /**
  339. * Put master components to <code>selectedServicesMasters</code>, which will be automatically rendered in template
  340. * @param {Ember.Enumerable} masterComponents
  341. * @method renderComponents
  342. */
  343. renderComponents: function (masterComponents) {
  344. var installedServices = App.StackService.find().filterProperty('isSelected').filterProperty('isInstalled', false).mapProperty('serviceName'); //list of shown services
  345. var result = [];
  346. var serviceComponentId, previousComponentName;
  347. masterComponents.forEach(function (item) {
  348. var serviceComponent = App.StackServiceComponent.find().findProperty('componentName', item.component_name);
  349. var showRemoveControl = installedServices.contains(serviceComponent.get('stackService.serviceName')) &&
  350. (masterComponents.filterProperty('component_name', item.component_name).length > 1);
  351. var componentObj = Em.Object.create(item);
  352. console.log("TRACE: render master component name is: " + item.component_name);
  353. var masterComponent = App.StackServiceComponent.find().findProperty('componentName', item.component_name);
  354. if (masterComponent.get('isMasterWithMultipleInstances')) {
  355. previousComponentName = item.component_name;
  356. componentObj.set('serviceComponentId', result.filterProperty('component_name', item.component_name).length + 1);
  357. componentObj.set("showRemoveControl", showRemoveControl);
  358. }
  359. componentObj.set('isHostNameValid', true);
  360. result.push(componentObj);
  361. }, this);
  362. this.set("selectedServicesMasters", result);
  363. if (this.get('isReassignWizard')) {
  364. var components = result.filterProperty('component_name', this.get('content.reassign.component_name'));
  365. components.setEach('isInstalled', false);
  366. this.set('servicesMasters', components);
  367. } else {
  368. this.set('servicesMasters', result);
  369. }
  370. },
  371. /**
  372. * Update dependent co-hosted components according to the change in the component host
  373. * @method updateCoHosts
  374. */
  375. updateCoHosts: function () {
  376. var components = App.StackServiceComponent.find().filterProperty('isOtherComponentCoHosted');
  377. var selectedServicesMasters = this.get('selectedServicesMasters');
  378. components.forEach(function (component) {
  379. var componentName = component.get('componentName');
  380. var hostComponent = selectedServicesMasters.findProperty('component_name', componentName);
  381. var dependentCoHosts = component.get('coHostedComponents');
  382. dependentCoHosts.forEach(function (coHostedComponent) {
  383. var dependentHostComponent = selectedServicesMasters.findProperty('component_name', coHostedComponent);
  384. if (hostComponent && dependentHostComponent) dependentHostComponent.set('selectedHost', hostComponent.get('selectedHost'));
  385. }, this);
  386. }, this);
  387. }.observes('selectedServicesMasters.@each.selectedHost'),
  388. /**
  389. * select and return host for component by scheme
  390. * Scheme is an object that has keys which compared to number of hosts,
  391. * if key more that number of hosts, then return value of that key.
  392. * Value is index of host in hosts array.
  393. *
  394. * @param {object} componentName
  395. * @param {object} hosts
  396. * @return {string}
  397. * @method getHostForComponent
  398. */
  399. getHostForComponent: function (componentName, hosts) {
  400. var component = App.StackServiceComponent.find().findProperty('componentName', componentName);
  401. if (component) {
  402. var selectionScheme = App.StackServiceComponent.find().findProperty('componentName', componentName).get('selectionSchemeForMasterComponent');
  403. } else {
  404. return hosts[0];
  405. }
  406. if (hosts.length === 1 || $.isEmptyObject(selectionScheme)) {
  407. return hosts[0];
  408. } else {
  409. for (var i in selectionScheme) {
  410. if (window.isFinite(i)) {
  411. if (hosts.length < window.parseInt(i)) {
  412. return hosts[selectionScheme[i]];
  413. }
  414. }
  415. }
  416. return hosts[selectionScheme['else']]
  417. }
  418. },
  419. /**
  420. * Get list of host names for master component with multiple instances
  421. * @param {Object} component
  422. * @param {Object} hosts
  423. * @returns {string[]}
  424. * @method getHostsForComponent
  425. */
  426. getHostsForComponent: function (component, hosts) {
  427. var defaultNoOfMasterHosts = component.get('defaultNoOfMasterHosts');
  428. var masterHosts = [];
  429. if (hosts.length < defaultNoOfMasterHosts) {
  430. defaultNoOfMasterHosts = hosts.length;
  431. }
  432. for (var index = 0; index < defaultNoOfMasterHosts; index++) {
  433. masterHosts.push(hosts[index]);
  434. }
  435. return masterHosts;
  436. },
  437. /**
  438. * Return hostName of masterNode for specified service
  439. * @param componentName
  440. * @return {string|string[]}
  441. * @method selectHost
  442. */
  443. selectHost: function (componentName) {
  444. var component = App.StackServiceComponent.find().findProperty('componentName', componentName);
  445. var hostNames = this.get('hosts').mapProperty('host_name');
  446. if (hostNames.length > 1 && App.StackServiceComponent.find().filterProperty('isNotPreferableOnAmbariServerHost').mapProperty('componentName').contains(componentName)) {
  447. hostNames = this.get('hosts').mapProperty('host_name').filter(function (item) {
  448. return item !== location.hostname;
  449. }, this);
  450. }
  451. if (this.get('multipleComponents').contains(componentName)) {
  452. if (component.get('defaultNoOfMasterHosts') > 1) {
  453. return this.getHostsForComponent(component, hostNames);
  454. } else {
  455. return [this.getHostForComponent(componentName, hostNames)];
  456. }
  457. } else {
  458. return this.getHostForComponent(componentName, hostNames);
  459. }
  460. },
  461. /**
  462. * On change callback for inputs
  463. * @param {string} componentName
  464. * @param {string} selectedHost
  465. * @param {number} serviceComponentId
  466. * @method assignHostToMaster
  467. */
  468. assignHostToMaster: function (componentName, selectedHost, serviceComponentId) {
  469. var flag = this.isHostNameValid(componentName, selectedHost);
  470. this.updateIsHostNameValidFlag(componentName, serviceComponentId, flag);
  471. if (serviceComponentId) {
  472. this.get('selectedServicesMasters').filterProperty('component_name', componentName).findProperty("serviceComponentId", serviceComponentId).set("selectedHost", selectedHost);
  473. }
  474. else {
  475. this.get('selectedServicesMasters').findProperty("component_name", componentName).set("selectedHost", selectedHost);
  476. }
  477. },
  478. /**
  479. * Determines if hostName is valid for component:
  480. * <ul>
  481. * <li>host name shouldn't be empty</li>
  482. * <li>host should exist</li>
  483. * <li>host should have only one component with <code>componentName</code></li>
  484. * </ul>
  485. * @param {string} componentName
  486. * @param {string} selectedHost
  487. * @returns {boolean} true - valid, false - invalid
  488. * @method isHostNameValid
  489. */
  490. isHostNameValid: function (componentName, selectedHost) {
  491. return (selectedHost.trim() !== '') &&
  492. this.get('hosts').mapProperty('host_name').contains(selectedHost) &&
  493. (this.get('selectedServicesMasters').
  494. filterProperty('component_name', componentName).
  495. mapProperty('selectedHost').
  496. filter(function (h) {
  497. return h === selectedHost;
  498. }).length <= 1);
  499. },
  500. /**
  501. * Update <code>isHostNameValid</code> property with <code>flag</code> value
  502. * for component with name <code>componentName</code> and
  503. * <code>serviceComponentId</code>-property equal to <code>serviceComponentId</code>-parameter value
  504. * @param {string} componentName
  505. * @param {number} serviceComponentId
  506. * @param {bool} flag
  507. * @method updateIsHostNameValidFlag
  508. */
  509. updateIsHostNameValidFlag: function (componentName, serviceComponentId, flag) {
  510. if (componentName) {
  511. if (serviceComponentId) {
  512. this.get('selectedServicesMasters').filterProperty('component_name', componentName).findProperty("serviceComponentId", serviceComponentId).set("isHostNameValid", flag);
  513. } else {
  514. this.get('selectedServicesMasters').findProperty("component_name", componentName).set("isHostNameValid", flag);
  515. }
  516. }
  517. },
  518. /**
  519. * Returns last component of selected type
  520. * @param {string} componentName
  521. * @return {Em.Object|null}
  522. * @method last
  523. */
  524. last: function (componentName) {
  525. return this.get("selectedServicesMasters").filterProperty("component_name", componentName).get("lastObject");
  526. },
  527. /**
  528. * Add new component to ZooKeeper Server and Hbase master
  529. * @param {string} componentName
  530. * @return {bool} true - added, false - not added
  531. * @method addComponent
  532. */
  533. addComponent: function (componentName) {
  534. /*
  535. * Logic: If ZooKeeper or Hbase service is selected then there can be
  536. * minimum 1 ZooKeeper or Hbase master in total, and
  537. * maximum 1 ZooKeeper or Hbase on every host
  538. */
  539. var maxNumMasters = this.get("hosts.length"),
  540. currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName),
  541. newMaster = null,
  542. masterHosts = null,
  543. suggestedHost = null,
  544. i = 0,
  545. lastMaster = null;
  546. if (!currentMasters.length) {
  547. console.log('ALERT: Zookeeper service was not selected');
  548. return false;
  549. }
  550. if (currentMasters.get("length") < maxNumMasters) {
  551. currentMasters.set("lastObject.showAddControl", false);
  552. currentMasters.set("lastObject.showRemoveControl", true);
  553. //create a new master component host based on an existing one
  554. newMaster = Em.Object.create({});
  555. lastMaster = currentMasters.get("lastObject");
  556. newMaster.set("display_name", lastMaster.get("display_name"));
  557. newMaster.set("component_name", lastMaster.get("component_name"));
  558. newMaster.set("selectedHost", lastMaster.get("selectedHost"));
  559. newMaster.set("isInstalled", false);
  560. if (currentMasters.get("length") === (maxNumMasters - 1)) {
  561. newMaster.set("showAddControl", false);
  562. } else {
  563. newMaster.set("showAddControl", true);
  564. }
  565. newMaster.set("showRemoveControl", true);
  566. //get recommended host for the new Zookeeper server
  567. masterHosts = currentMasters.mapProperty("selectedHost").uniq();
  568. for (i = 0; i < this.get("hosts.length"); i++) {
  569. if (!(masterHosts.contains(this.get("hosts")[i].get("host_name")))) {
  570. suggestedHost = this.get("hosts")[i].get("host_name");
  571. break;
  572. }
  573. }
  574. newMaster.set("selectedHost", suggestedHost);
  575. newMaster.set("serviceComponentId", (currentMasters.get("lastObject.serviceComponentId") + 1));
  576. this.get("selectedServicesMasters").insertAt(this.get("selectedServicesMasters").indexOf(lastMaster) + 1, newMaster);
  577. this.set('componentToRebalance', componentName);
  578. this.incrementProperty('rebalanceComponentHostsCounter');
  579. this.toggleProperty('hostNameCheckTrigger');
  580. return true;
  581. }
  582. return false;//if no more zookeepers can be added
  583. },
  584. /**
  585. * Remove component from ZooKeeper server or Hbase Master
  586. * @param {string} componentName
  587. * @param {number} serviceComponentId
  588. * @return {bool} true - removed, false - no
  589. * @method removeComponent
  590. */
  591. removeComponent: function (componentName, serviceComponentId) {
  592. var currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName);
  593. //work only if the multiple master service is selected in previous step
  594. if (currentMasters.length <= 1) {
  595. return false;
  596. }
  597. this.get("selectedServicesMasters").removeAt(this.get("selectedServicesMasters").indexOf(currentMasters.findProperty("serviceComponentId", serviceComponentId)));
  598. currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName);
  599. if (currentMasters.get("length") < this.get("hosts.length")) {
  600. currentMasters.set("lastObject.showAddControl", true);
  601. }
  602. if (currentMasters.get("length") === 1) {
  603. currentMasters.set("lastObject.showRemoveControl", false);
  604. }
  605. this.set('componentToRebalance', componentName);
  606. this.incrementProperty('rebalanceComponentHostsCounter');
  607. this.toggleProperty('hostNameCheckTrigger');
  608. return true;
  609. },
  610. /**
  611. * Submit button click handler
  612. * @metohd submit
  613. */
  614. submit: function () {
  615. this.getIsSubmitDisabled();
  616. if (!this.get('submitDisabled')) {
  617. App.router.send('next');
  618. }
  619. }
  620. });