step5_controller.js 22 KB

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