step5_controller.js 22 KB

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