step5_controller.js 24 KB

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