step5_controller.js 25 KB

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