step5_controller.js 23 KB

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