step5_controller.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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. var lazyLoading = require('utils/lazy_loading');
  21. App.WizardStep5Controller = Em.Controller.extend({
  22. name: "wizardStep5Controller",
  23. /**
  24. * Step title
  25. * Custom if <code>App.ReassignMasterController</code> is used
  26. * @type {string}
  27. */
  28. title: function () {
  29. if (this.get('content.controllerName') == 'reassignMasterController') {
  30. return Em.I18n.t('installer.step5.reassign.header');
  31. }
  32. return Em.I18n.t('installer.step5.header');
  33. }.property('content.controllerName'),
  34. /**
  35. * Is ReassignWizard used
  36. * @type {bool}
  37. */
  38. isReassignWizard: function () {
  39. return this.get('content.controllerName') == 'reassignMasterController';
  40. }.property('content.controllerName'),
  41. /**
  42. * Is AddServiceWizard used
  43. * @type {bool}
  44. */
  45. isAddServiceWizard: function () {
  46. return this.get('content.controllerName') == 'addServiceController';
  47. }.property('content.controllerName'),
  48. /**
  49. * Is Hive reassigning
  50. * @type {bool}
  51. */
  52. isReassignHive: function () {
  53. return this.get('servicesMasters').objectAt(0) && this.get('servicesMasters').objectAt(0).component_name == 'HIVE_SERVER' && this.get('isReassignWizard');
  54. }.property('isReassignWizard', 'servicesMasters'),
  55. /**
  56. * Master components which could be assigned to multiple hosts
  57. * @type {string[]}
  58. */
  59. multipleComponents: ['ZOOKEEPER_SERVER', 'HBASE_MASTER'],
  60. submitDisabled: false,
  61. /**
  62. * Define state for submit button. Return true only for Reassign Master Wizard and if more than one master component was reassigned.
  63. * @type {bool}
  64. */
  65. isSubmitDisabled: function () {
  66. if (!this.get('isReassignWizard')) {
  67. this.set('submitDisabled', false);
  68. } else {
  69. App.ajax.send({
  70. name: 'host_components.all',
  71. sender: this,
  72. data: {
  73. clusterName: App.get('clusterName')
  74. },
  75. success: 'isSubmitDisabledSuccessCallBack'
  76. });
  77. }
  78. }.observes('servicesMasters.@each.selectedHost'),
  79. isSubmitDisabledSuccessCallBack: function (response) {
  80. var reassigned = 0;
  81. var arr1 = response.items.mapProperty('HostRoles').filterProperty('component_name', this.get('content.reassign.component_name')).mapProperty('host_name');
  82. var arr2 = this.get('servicesMasters').mapProperty('selectedHost');
  83. arr1.forEach(function (host) {
  84. if (!arr2.contains(host)) {
  85. reassigned++;
  86. }
  87. }, this);
  88. this.set('submitDisabled', reassigned !== 1);
  89. },
  90. /**
  91. * List of hosts
  92. * @type {Array}
  93. */
  94. hosts: [],
  95. /**
  96. * @type {Object|null}
  97. */
  98. componentToRebalance: null,
  99. /**
  100. * @type {number}
  101. */
  102. rebalanceComponentHostsCounter: 0,
  103. /**
  104. * @type {Ember.Enumerable}
  105. */
  106. servicesMasters: [],
  107. /**
  108. * @type {Ember.Enumerable}
  109. */
  110. selectedServicesMasters: [],
  111. /**
  112. * Check if HIVE_SERVER component exist (also checks if this is not reassign)
  113. * @type {bool}
  114. */
  115. hasHiveServer: function () {
  116. return this.get('selectedServicesMasters').someProperty('component_name', 'HIVE_SERVER') && !this.get('isReassignWizard');
  117. }.property('selectedServicesMasters'),
  118. /**
  119. * List of host with assigned masters
  120. * Format:
  121. * <code>
  122. * [
  123. * {
  124. * host_name: '',
  125. * hostInfo: {},
  126. * masterServices: []
  127. * },
  128. * ....
  129. * ]
  130. * </code>
  131. * @type {Ember.Enumerable}
  132. */
  133. masterHostMapping: [],
  134. isLoaded: false,
  135. /**
  136. * Check if HIVE_SERVER component exist (also checks if this is not reassign)
  137. * @type {bool}
  138. */
  139. hasHiveServer: function () {
  140. return this.get('selectedServicesMasters').someProperty('component_name', 'HIVE_SERVER') && !this.get('isReassignWizard');
  141. }.property('selectedServicesMasters'),
  142. masterHostMappingObserver: function () {
  143. var requestName = this.get('content.controllerName') == 'installerController' ? 'hosts.confirmed.install' : 'hosts.confirmed'
  144. App.ajax.send({
  145. name: requestName,
  146. sender: this,
  147. data: {
  148. clusterName: App.get('clusterName')
  149. },
  150. success: 'masterHostMappingSuccessCallback'
  151. });
  152. }.observes('selectedServicesMasters', 'selectedServicesMasters.@each.selectedHost'),
  153. masterHostMappingSuccessCallback: function (response) {
  154. var mapping = [], mappingObject, mappedHosts, hostObj;
  155. //get the unique assigned hosts and find the master services assigned to them
  156. mappedHosts = this.get("selectedServicesMasters").mapProperty("selectedHost").uniq().without(undefined);
  157. mappedHosts.forEach(function (item) {
  158. var host = response.items.mapProperty('Hosts').findProperty('host_name', item);
  159. hostObj = {
  160. name: host.host_name,
  161. memory: host.total_mem,
  162. cpu: host.cpu_count
  163. };
  164. mappingObject = Em.Object.create({
  165. host_name: item,
  166. hostInfo: Em.I18n.t('installer.step5.hostInfo').fmt(hostObj.name, numberUtils.bytesToSize(hostObj.memory, 1, 'parseFloat', 1024), hostObj.cpu),
  167. masterServices: this.get("selectedServicesMasters").filterProperty("selectedHost", item)
  168. });
  169. mapping.pushObject(mappingObject);
  170. }, this);
  171. this.set('masterHostMapping', []);
  172. lazyLoading.run({
  173. initSize: 20,
  174. chunkSize: 50,
  175. delay: 50,
  176. destination: this.get('masterHostMapping'),
  177. source: mapping.sortProperty('host_name'),
  178. context: Em.Object.create()
  179. });
  180. },
  181. /**
  182. * Count of hosts without masters
  183. * @type {number}
  184. */
  185. remainingHosts: function () {
  186. if (this.get('content.controllerName') === 'installerController') {
  187. return 0;
  188. } else {
  189. return (this.get("hosts.length") - this.get("masterHostMapping.length"));
  190. };
  191. }.property('masterHostMapping.length', 'selectedServicesMasters.@each.selectedHost'),
  192. /**
  193. * Clear controller data (hosts, masters etc)
  194. * @method clearStep
  195. */
  196. clearStep: function () {
  197. this.set('hosts', []);
  198. this.set('selectedServicesMasters', []);
  199. this.set('servicesMasters', []);
  200. },
  201. /**
  202. * Load controller data (hosts, host components etc)
  203. * @method loadStep
  204. */
  205. loadStep: function () {
  206. console.log("WizardStep5Controller: Loading step5: Assign Masters");
  207. this.clearStep();
  208. this.renderHostInfo();
  209. this.renderComponents(this.loadComponents());
  210. this.updateComponent('ZOOKEEPER_SERVER');
  211. if (App.supports.multipleHBaseMasters) {
  212. this.updateComponent('HBASE_MASTER');
  213. }
  214. if (!this.get("selectedServicesMasters").filterProperty('isInstalled', false).length) {
  215. console.log('no master components to add');
  216. App.router.send('next');
  217. }
  218. },
  219. /**
  220. * Used to set showAddControl flag for ZOOKEEPER_SERVER and HBASE_SERVER
  221. * @method updateComponent
  222. */
  223. updateComponent: function (componentName) {
  224. var component = this.last(componentName);
  225. if(!component) {
  226. return;
  227. }
  228. var services = this.get('content.services').filterProperty('isInstalled', true).mapProperty('serviceName');
  229. var currentService = componentName.split('_')[0];
  230. var showControl = !services.contains(currentService);
  231. if (showControl) {
  232. if (this.get("selectedServicesMasters").filterProperty("component_name", componentName).length < this.get("hosts.length") && !this.get('isReassignWizard')) {
  233. component.set('showAddControl', true);
  234. } else {
  235. component.set('showRemoveControl', false);
  236. }
  237. }
  238. },
  239. /**
  240. * Load active host list to <code>hosts</code> variable
  241. * @method renderHostInfo
  242. */
  243. renderHostInfo: function () {
  244. var hostInfo = this.get('content.hosts');
  245. var result = [];
  246. for (var index in hostInfo) {
  247. var _host = hostInfo[index];
  248. if (_host.bootStatus === 'REGISTERED') {
  249. result.push(Em.Object.create({
  250. host_name: _host.name,
  251. cpu: _host.cpu,
  252. memory: _host.memory,
  253. disk_info: _host.disk_info,
  254. host_info: Em.I18n.t('installer.step5.hostInfo').fmt(_host.name, numberUtils.bytesToSize(_host.memory, 1, 'parseFloat', 1024), _host.cpu)
  255. }));
  256. }
  257. }
  258. this.set("hosts", []);
  259. lazyLoading.run({
  260. initSize: 20,
  261. chunkSize: 50,
  262. delay: 50,
  263. destination: this.get('hosts'),
  264. source: result,
  265. context: Em.Object.create()
  266. });
  267. this.sortHosts(this.get('hosts'));
  268. this.set('isLoaded', true);
  269. },
  270. /**
  271. * Sort list of host-objects by properties (memory - desc, cpu - desc, hostname - asc)
  272. * @param {object[]} hosts
  273. */
  274. sortHosts: function (hosts) {
  275. hosts.sort(function (a, b) {
  276. if (a.get('memory') == b.get('memory')) {
  277. if (a.get('cpu') == b.get('cpu')) {
  278. return a.get('host_name').localeCompare(b.get('host_name')); // hostname asc
  279. }
  280. return b.get('cpu') - a.get('cpu'); // cores desc
  281. }
  282. return b.get('memory') - a.get('memory'); // ram desc
  283. });
  284. },
  285. /**
  286. * Load services info to appropriate variable and return masterComponentHosts
  287. * @return {Object[]}
  288. */
  289. loadComponents: function () {
  290. var services = this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName'); //list of shown services
  291. var masterComponents = App.StackServiceComponent.find().filterProperty('isShownOnInstallerAssignMasterPage', true); //get full list from mock data
  292. var masterHosts = this.get('content.masterComponentHosts'); //saved to local storage info
  293. var resultComponents = [];
  294. var servicesLength = services.length;
  295. for (var index = 0; index < servicesLength; index++) {
  296. var componentInfo = masterComponents.filterProperty('serviceName', services[index]);
  297. componentInfo.forEach(function (_componentInfo) {
  298. if (_componentInfo.get('componentName') == 'ZOOKEEPER_SERVER' || _componentInfo.get('componentName') == 'HBASE_MASTER') {
  299. var savedComponents = masterHosts.filterProperty('component', _componentInfo.get('componentName'));
  300. if (savedComponents.length) {
  301. savedComponents.forEach(function (item) {
  302. var multipleMasterHost = {};
  303. multipleMasterHost.display_name = _componentInfo.get('displayName');
  304. multipleMasterHost.component_name = _componentInfo.get('componentName');
  305. multipleMasterHost.selectedHost = item.hostName;
  306. multipleMasterHost.serviceId = services[index];
  307. multipleMasterHost.isInstalled = item.isInstalled;
  308. multipleMasterHost.isHiveCoHost = false;
  309. resultComponents.push(multipleMasterHost);
  310. })
  311. } else {
  312. var zooHosts = this.selectHost(_componentInfo.get('componentName'));
  313. zooHosts.forEach(function (_host) {
  314. var multipleMasterHost = {};
  315. multipleMasterHost.display_name = _componentInfo.get('displayName');
  316. multipleMasterHost.component_name = _componentInfo.get('componentName');
  317. multipleMasterHost.selectedHost = _host;
  318. multipleMasterHost.serviceId = services[index];
  319. multipleMasterHost.isInstalled = false;
  320. multipleMasterHost.isHiveCoHost = false;
  321. resultComponents.push(multipleMasterHost);
  322. });
  323. }
  324. } else {
  325. var savedComponent = masterHosts.findProperty('component', _componentInfo.get('componentName'));
  326. var componentObj = {};
  327. componentObj.component_name = _componentInfo.get('componentName');
  328. componentObj.display_name = _componentInfo.get('displayName');
  329. componentObj.selectedHost = savedComponent ? savedComponent.hostName : this.selectHost(_componentInfo.get('componentName')); // call the method that plays selectNode algorithm or fetches from server
  330. componentObj.isInstalled = savedComponent ? savedComponent.isInstalled : false;
  331. componentObj.serviceId = services[index];
  332. componentObj.isHiveCoHost = this._isHiveCoHost(_componentInfo.get('componentName'));
  333. resultComponents.push(componentObj);
  334. }
  335. }, this);
  336. }
  337. return resultComponents;
  338. },
  339. /**
  340. * @param {string} componentName
  341. * @returns {bool}
  342. * @private
  343. * @method _isHiveCoHost
  344. */
  345. _isHiveCoHost: function(componentName) {
  346. return ['HIVE_METASTORE', 'WEBHCAT_SERVER'].contains(componentName) && !this.get('isReassignWizard');
  347. },
  348. /**
  349. * Put master components to <code>selectedServicesMasters</code>, which will be automatically rendered in template
  350. * @param {Ember.Enumerable} masterComponents
  351. * @method renderComponents
  352. */
  353. renderComponents: function (masterComponents) {
  354. var services = this.get('content.services').filterProperty('isInstalled', true).mapProperty('serviceName'); //list of shown services
  355. var showRemoveControlZk = !services.contains('ZOOKEEPER') && masterComponents.filterProperty('component_name', 'ZOOKEEPER_SERVER').length > 1;
  356. var showRemoveControlHb = !services.contains('HBASE') && masterComponents.filterProperty('component_name', 'HBASE_MASTER').length > 1;
  357. var zid = 1, hid = 1, nid = 1, result = [], self = this;
  358. masterComponents.forEach(function (item) {
  359. if (item.component_name == 'SECONDARY_NAMENODE') {
  360. if (self.get('isAddServiceWizard')) {
  361. if (App.get('isHaEnabled')) {
  362. return;
  363. }
  364. }
  365. }
  366. var componentObj = Em.Object.create(item);
  367. console.log("TRACE: render master component name is: " + item.component_name);
  368. if (item.component_name === "ZOOKEEPER_SERVER") {
  369. componentObj.set('zId', zid++);
  370. componentObj.set("showRemoveControl", showRemoveControlZk);
  371. }
  372. else {
  373. if (App.supports.multipleHBaseMasters && item.component_name === "HBASE_MASTER") {
  374. componentObj.set('zId', hid++);
  375. componentObj.set("showRemoveControl", showRemoveControlHb);
  376. }
  377. else {
  378. if (item.component_name === "NAMENODE") {
  379. componentObj.set('zId', nid++);
  380. }
  381. }
  382. }
  383. result.push(componentObj);
  384. }, this);
  385. this.set("selectedServicesMasters", result);
  386. if (this.get('isReassignWizard')) {
  387. var components = result.filterProperty('component_name', this.get('content.reassign.component_name'));
  388. components.setEach('isInstalled', false);
  389. this.set('servicesMasters', components);
  390. }
  391. else {
  392. this.set('servicesMasters', result);
  393. }
  394. },
  395. /**
  396. * Update host for components HIVE_METASTORE and WEBHCAT_SERVER according to host with HIVE_SERVER
  397. * @method updateHiveCoHosts
  398. */
  399. updateHiveCoHosts: function () {
  400. var hiveServer = this.get('selectedServicesMasters').findProperty('component_name', 'HIVE_SERVER'),
  401. hiveMetastore = this.get('selectedServicesMasters').findProperty('component_name', 'HIVE_METASTORE'),
  402. webHCatServer = this.get('selectedServicesMasters').findProperty('component_name', 'WEBHCAT_SERVER');
  403. if (hiveServer && hiveMetastore && webHCatServer) {
  404. if (!this.get('isReassignHive') && this.get('servicesMasters').objectAt(0) && !(this.get('servicesMasters').objectAt(0).component_name == 'HIVE_METASTORE')) {
  405. hiveMetastore.set('selectedHost', hiveServer.get('selectedHost'))
  406. }
  407. webHCatServer.set('selectedHost', hiveServer.get('selectedHost'));
  408. }
  409. }.observes('selectedServicesMasters.@each.selectedHost'),
  410. /**
  411. * select and return host for component by scheme
  412. * Scheme is an object that has keys which compared to number of hosts,
  413. * if key more that number of hosts, then return value of that key.
  414. * Value is index of host in hosts array.
  415. *
  416. * @param {number} noOfHosts
  417. * @param {object} selectionScheme
  418. * @return {string}
  419. * @method getHostForComponent
  420. */
  421. getHostForComponent: function (noOfHosts, selectionScheme) {
  422. var hosts = this.get('hosts');
  423. if (hosts.length === 1 || $.isEmptyObject(selectionScheme)) {
  424. return hosts[0];
  425. } else {
  426. for (var i in selectionScheme) {
  427. if (window.isFinite(i)) {
  428. if (noOfHosts < window.parseInt(i)) {
  429. return hosts[selectionScheme[i]];
  430. }
  431. }
  432. }
  433. return hosts[selectionScheme['else']]
  434. }
  435. },
  436. /**
  437. * Get list of hostnames for ZK Server
  438. * @param {number} noOfHosts
  439. * @returns {string[]}
  440. * @method getZooKeeperServer
  441. */
  442. getZooKeeperServer: function (noOfHosts) {
  443. var hosts = this.get('hosts');
  444. if (noOfHosts < 3) {
  445. return [hosts[0].host_name];
  446. } else {
  447. return [hosts[0].host_name, hosts[1].host_name, hosts[2].host_name];
  448. }
  449. },
  450. /**
  451. * Get hostname based on number of available hosts
  452. * @param {number} noOfHosts
  453. * @returns {string}
  454. * @method getServerHost
  455. */
  456. getServerHost: function (noOfHosts) {
  457. var hostNames = this.get('hosts').mapProperty('host_name');
  458. var hostExcAmbari = hostNames.without(location.hostname);
  459. if (noOfHosts > 1) {
  460. return hostExcAmbari[0];
  461. } else {
  462. return hostNames[0];
  463. }
  464. },
  465. /**
  466. * Return hostName of masterNode for specified service
  467. * @param componentName
  468. * @return {string|string[]}
  469. * @method selectHost
  470. */
  471. selectHost: function (componentName) {
  472. var noOfHosts = this.get('hosts').length;
  473. if (componentName === 'KERBEROS_SERVER')
  474. return this.getHostForComponent(noOfHosts, {"3": 1, "6": 1, "31": 3, "else": 5}).host_name;
  475. if (componentName === 'NAMENODE')
  476. return this.getHostForComponent(noOfHosts, {"else": 0}).host_name;
  477. if (componentName === 'SECONDARY_NAMENODE')
  478. return this.getHostForComponent(noOfHosts, {"else": 1}).host_name;
  479. if (componentName === 'HBASE_MASTER')
  480. return [this.getHostForComponent(noOfHosts, {"3": 0, "6": 0, "31": 2, "else": 3}).host_name];
  481. if (componentName === 'ZOOKEEPER_SERVER')
  482. return this.getZooKeeperServer(noOfHosts);
  483. if (['JOBTRACKER', 'HISTORYSERVER', 'RESOURCEMANAGER', 'APP_TIMELINE_SERVER'].contains(componentName))
  484. return this.getHostForComponent(noOfHosts, {"3": 1, "6": 1, "31": 1, "else": 2}).host_name;
  485. if (['OOZIE_SERVER', 'FALCON_SERVER'].contains(componentName))
  486. return this.getHostForComponent(noOfHosts, {"3": 1, "6": 1, "31": 2, "else": 3}).host_name;
  487. if (['HIVE_SERVER', 'HIVE_METASTORE', 'WEBHCAT_SERVER'].contains(componentName))
  488. return this.getHostForComponent(noOfHosts, {"3": 1, "6": 1, "31": 2, "else": 4}).host_name;
  489. if (['STORM_UI_SERVER', 'DRPC_SERVER', 'STORM_REST_API', 'NIMBUS', 'GANGLIA_SERVER', 'NAGIOS_SERVER', 'HUE_SERVER'].contains(componentName))
  490. return this.getServerHost(noOfHosts);
  491. return '';
  492. },
  493. /**
  494. * On change callback for selects
  495. * @param {string} componentName
  496. * @param {string} selectedHost
  497. * @param {number} zId
  498. * @method assignHostToMaster
  499. */
  500. assignHostToMaster: function (componentName, selectedHost, zId) {
  501. if (selectedHost && componentName) {
  502. if (zId) {
  503. this.get('selectedServicesMasters').filterProperty('component_name', componentName).findProperty("zId", zId).set("selectedHost", selectedHost);
  504. } else {
  505. this.get('selectedServicesMasters').findProperty("component_name", componentName).set("selectedHost", selectedHost);
  506. }
  507. }
  508. },
  509. /**
  510. * Returns last component of selected type
  511. * @param {string} componentName
  512. * @return {Em.Object|null}
  513. * @method last
  514. */
  515. last: function (componentName) {
  516. return this.get("selectedServicesMasters").filterProperty("component_name", componentName).get("lastObject");
  517. },
  518. /**
  519. * Add new component to ZooKeeper Server and Hbase master
  520. * @param {string} componentName
  521. * @return {bool} true - added, false - not added
  522. * @method addComponent
  523. */
  524. addComponent: function (componentName) {
  525. /*
  526. * Logic: If ZooKeeper or Hbase service is selected then there can be
  527. * minimum 1 ZooKeeper or Hbase master in total, and
  528. * maximum 1 ZooKeeper or Hbase on every host
  529. */
  530. var maxNumMasters = this.get("hosts.length"),
  531. currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName),
  532. newMaster = null,
  533. masterHosts = null,
  534. suggestedHost = null,
  535. i = 0,
  536. lastMaster = null;
  537. if (!currentMasters.length) {
  538. console.log('ALERT: Zookeeper service was not selected');
  539. return false;
  540. }
  541. if (currentMasters.get("length") < maxNumMasters) {
  542. currentMasters.set("lastObject.showAddControl", false);
  543. currentMasters.set("lastObject.showRemoveControl", true);
  544. //create a new zookeeper based on an existing one
  545. newMaster = Em.Object.create({});
  546. lastMaster = currentMasters.get("lastObject");
  547. newMaster.set("display_name", lastMaster.get("display_name"));
  548. newMaster.set("component_name", lastMaster.get("component_name"));
  549. newMaster.set("selectedHost", lastMaster.get("selectedHost"));
  550. newMaster.set("isInstalled", false);
  551. if (currentMasters.get("length") === (maxNumMasters - 1)) {
  552. newMaster.set("showAddControl", false);
  553. } else {
  554. newMaster.set("showAddControl", true);
  555. }
  556. newMaster.set("showRemoveControl", true);
  557. //get recommended host for the new Zookeeper server
  558. masterHosts = currentMasters.mapProperty("selectedHost").uniq();
  559. for (i = 0; i < this.get("hosts.length"); i++) {
  560. if (!(masterHosts.contains(this.get("hosts")[i].get("host_name")))) {
  561. suggestedHost = this.get("hosts")[i].get("host_name");
  562. break;
  563. }
  564. }
  565. newMaster.set("selectedHost", suggestedHost);
  566. newMaster.set("zId", (currentMasters.get("lastObject.zId") + 1));
  567. this.get("selectedServicesMasters").insertAt(this.get("selectedServicesMasters").indexOf(lastMaster) + 1, newMaster);
  568. this.set('componentToRebalance', componentName);
  569. this.incrementProperty('rebalanceComponentHostsCounter');
  570. return true;
  571. }
  572. return false;//if no more zookeepers can be added
  573. },
  574. /**
  575. * Remove component from ZooKeeper server or Hbase Master
  576. * @param {string} componentName
  577. * @param {number} zId
  578. * @return {bool} true - removed, false - no
  579. * @method removeComponent
  580. */
  581. removeComponent: function (componentName, zId) {
  582. var currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName);
  583. //work only if the Zookeeper service is selected in previous step
  584. if (currentMasters.length <= 1) {
  585. return false;
  586. }
  587. this.get("selectedServicesMasters").removeAt(this.get("selectedServicesMasters").indexOf(currentMasters.findProperty("zId", zId)));
  588. currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName);
  589. if (currentMasters.get("length") < this.get("hosts.length")) {
  590. currentMasters.set("lastObject.showAddControl", true);
  591. }
  592. if (currentMasters.get("length") === 1) {
  593. currentMasters.set("lastObject.showRemoveControl", false);
  594. }
  595. this.set('componentToRebalance', componentName);
  596. this.incrementProperty('rebalanceComponentHostsCounter');
  597. return true;
  598. },
  599. /**
  600. * Submit button click handler
  601. * @metohd submit
  602. */
  603. submit: function () {
  604. this.isSubmitDisabled();
  605. if (!this.get('submitDisabled')) {
  606. App.router.send('next');
  607. }
  608. }
  609. });