step5_controller.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  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. /**
  309. * Return hostName of masterNode for specified service
  310. * @param componentName
  311. * @return {*}
  312. */
  313. selectHost:function (componentName) {
  314. var noOfHosts = this.get('hosts').length;
  315. switch (componentName) {
  316. case 'KERBEROS_SERVER':
  317. return this.getHostForComponent(noOfHosts, {
  318. "3" : 1,
  319. "6" : 1,
  320. "31" : 3,
  321. "else" : 5
  322. }).host_name;
  323. case 'NAMENODE':
  324. return this.getHostForComponent(noOfHosts, {
  325. "else" : 0
  326. }).host_name;
  327. case 'SECONDARY_NAMENODE':
  328. return this.getHostForComponent(noOfHosts, {
  329. "else" : 1
  330. }).host_name;
  331. case 'JOBTRACKER':
  332. return this.getHostForComponent(noOfHosts, {
  333. "3" : 1,
  334. "6" : 1,
  335. "31" : 1,
  336. "else" : 2
  337. }).host_name;
  338. case 'HISTORYSERVER':
  339. return this.getHostForComponent(noOfHosts, {
  340. "3" : 1,
  341. "6" : 1,
  342. "31" : 1,
  343. "else" : 2
  344. }).host_name;
  345. case 'RESOURCEMANAGER':
  346. return this.getHostForComponent(noOfHosts, {
  347. "3" : 1,
  348. "6" : 1,
  349. "31" : 1,
  350. "else" : 2
  351. }).host_name;
  352. case 'HBASE_MASTER':
  353. return [this.getHostForComponent(noOfHosts, {
  354. "3" : 0,
  355. "6" : 0,
  356. "31" : 2,
  357. "else" : 3
  358. }).host_name];
  359. case 'OOZIE_SERVER':
  360. return this.getHostForComponent(noOfHosts, {
  361. "3" : 1,
  362. "6" : 1,
  363. "31" : 2,
  364. "else" : 3
  365. }).host_name;
  366. case 'HIVE_SERVER':
  367. return this.getHostForComponent(noOfHosts, {
  368. "3" : 1,
  369. "6" : 1,
  370. "31" : 2,
  371. "else" : 4
  372. }).host_name;
  373. case 'HIVE_METASTORE':
  374. return this.getHostForComponent(noOfHosts, {
  375. "3" : 1,
  376. "6" : 1,
  377. "31" : 2,
  378. "else" : 4
  379. }).host_name;
  380. case 'WEBHCAT_SERVER':
  381. return this.getHostForComponent(noOfHosts, {
  382. "3" : 1,
  383. "6" : 1,
  384. "31" : 2,
  385. "else" : 4
  386. }).host_name;
  387. case 'ZOOKEEPER_SERVER':
  388. return this.getZooKeeperServer(noOfHosts);
  389. case 'GANGLIA_SERVER':
  390. return this.getGangliaServer(noOfHosts);
  391. case 'NAGIOS_SERVER':
  392. return this.getNagiosServer(noOfHosts);
  393. case 'HUE_SERVER':
  394. return this.getHueServer(noOfHosts);
  395. }
  396. },
  397. masterHostMapping:function () {
  398. var mapping = [], mappingObject, self = this, mappedHosts, hostObj, hostInfo;
  399. //get the unique assigned hosts and find the master services assigned to them
  400. mappedHosts = this.get("selectedServicesMasters").mapProperty("selectedHost").uniq();
  401. mappedHosts.forEach(function (item) {
  402. hostObj = self.get("hosts").findProperty("host_name", item);
  403. console.log("Name of the host is: " + hostObj.host_name);
  404. mappingObject = Ember.Object.create({
  405. host_name:item,
  406. hostInfo:hostObj.host_info,
  407. masterServices:self.get("selectedServicesMasters").filterProperty("selectedHost", item)
  408. });
  409. mapping.pushObject(mappingObject);
  410. }, this);
  411. mapping.sort(this.sortHostsByName);
  412. return mapping;
  413. }.property("selectedServicesMasters.@each.selectedHost"),
  414. remainingHosts:function () {
  415. return (this.get("hosts.length") - this.get("masterHostMapping.length"));
  416. }.property("selectedServicesMasters.@each.selectedHost"),
  417. //methods
  418. getAvailableHosts:function (componentName) {
  419. var selectedHosts = this.get("selectedServicesMasters").filterProperty("component_name", componentName).mapProperty("selectedHost").uniq();
  420. return this.get('hosts').filter(function(item){
  421. return !selectedHosts.contains(item.get("host_name"));
  422. });
  423. },
  424. /**
  425. * On change callback for selects
  426. * @param componentName
  427. * @param selectedHost
  428. * @param zId
  429. */
  430. assignHostToMaster:function (componentName, selectedHost, zId) {
  431. if (selectedHost && componentName) {
  432. if (zId) {
  433. this.get('selectedServicesMasters').filterProperty('component_name', componentName).findProperty("zId", zId).set("selectedHost", selectedHost);
  434. this.rebalanceComponentHosts(componentName);
  435. } else {
  436. this.get('selectedServicesMasters').findProperty("component_name", componentName).set("selectedHost", selectedHost);
  437. }
  438. }
  439. },
  440. /**
  441. * Returns last component of selected type
  442. * @param componentName
  443. * @return {*}
  444. */
  445. last: function(componentName){
  446. return this.get("selectedServicesMasters").filterProperty("component_name", componentName).get("lastObject");
  447. },
  448. /**
  449. * Add new component to ZooKeeper Server and Hbase master
  450. * @param componentName
  451. * @return {Boolean}
  452. */
  453. addComponent:function (componentName) {
  454. /*
  455. *Logic: If ZooKeeper service is selected then there can be
  456. * minimum 1 ZooKeeper master in total, and
  457. * maximum 1 ZooKeeper on every host
  458. */
  459. var maxNumZooKeepers = this.get("hosts.length"),
  460. currentZooKeepers = this.get("selectedServicesMasters").filterProperty("component_name", componentName),
  461. newZookeeper = null,
  462. zookeeperHosts = null,
  463. suggestedHost = null,
  464. i = 0,
  465. lastZoo = null;
  466. if (!currentZooKeepers.length) {
  467. console.log('ALERT: Zookeeper service was not selected');
  468. return false;
  469. }
  470. if (currentZooKeepers.get("length") < maxNumZooKeepers) {
  471. currentZooKeepers.set("lastObject.showAddControl", false);
  472. currentZooKeepers.set("lastObject.showRemoveControl", true);
  473. //create a new zookeeper based on an existing one
  474. newZookeeper = Ember.Object.create({});
  475. lastZoo = currentZooKeepers.get("lastObject");
  476. newZookeeper.set("display_name", lastZoo.get("display_name"));
  477. newZookeeper.set("component_name", lastZoo.get("component_name"));
  478. newZookeeper.set("selectedHost", lastZoo.get("selectedHost"));
  479. newZookeeper.set("availableHosts", this.getAvailableHosts(componentName));
  480. if (currentZooKeepers.get("length") === (maxNumZooKeepers - 1)) {
  481. newZookeeper.set("showAddControl", false);
  482. } else {
  483. newZookeeper.set("showAddControl", true);
  484. }
  485. newZookeeper.set("showRemoveControl", true);
  486. //get recommended host for the new Zookeeper server
  487. zookeeperHosts = currentZooKeepers.mapProperty("selectedHost").uniq();
  488. for (i = 0; i < this.get("hosts.length"); i++) {
  489. if (!(zookeeperHosts.contains(this.get("hosts")[i].get("host_name")))) {
  490. suggestedHost = this.get("hosts")[i].get("host_name");
  491. break;
  492. }
  493. }
  494. newZookeeper.set("selectedHost", suggestedHost);
  495. newZookeeper.set("zId", (currentZooKeepers.get("lastObject.zId") + 1));
  496. this.get("selectedServicesMasters").insertAt(this.get("selectedServicesMasters").indexOf(lastZoo) + 1, newZookeeper);
  497. if(componentName == 'ZOOKEEPER_SERVER' || componentName == 'HBASE_MASTER'){
  498. this.rebalanceComponentHosts(componentName);
  499. }
  500. return true;
  501. }
  502. return false;//if no more zookeepers can be added
  503. },
  504. /**
  505. * Remove component from ZooKeeper server or Hbase Master
  506. * @param componentName
  507. * @param zId
  508. * @return {Boolean}
  509. */
  510. removeComponent:function (componentName, zId) {
  511. var currentZooKeepers = this.get("selectedServicesMasters").filterProperty("component_name", componentName)
  512. //work only if the Zookeeper service is selected in previous step
  513. if (!currentZooKeepers.length) {
  514. return false;
  515. }
  516. if (currentZooKeepers.get("length") > 1) {
  517. this.get("selectedServicesMasters").removeAt(this.get("selectedServicesMasters").indexOf(currentZooKeepers.findProperty("zId", zId)));
  518. currentZooKeepers = this.get("selectedServicesMasters").filterProperty("component_name", componentName);
  519. if (currentZooKeepers.get("length") < this.get("hosts.length")) {
  520. currentZooKeepers.set("lastObject.showAddControl", true);
  521. }
  522. if (currentZooKeepers.get("length") === 1) {
  523. currentZooKeepers.set("lastObject.showRemoveControl", false);
  524. }
  525. if(componentName == 'ZOOKEEPER_SERVER' || componentName == 'HBASE_MASTER'){
  526. this.rebalanceComponentHosts(componentName);
  527. }
  528. return true;
  529. }
  530. return false;
  531. },
  532. rebalanceComponentHosts:function (componentName) {
  533. //for a zookeeper and hbase update the available hosts for the other zookeepers and hbases
  534. var currentComponents = this.get("selectedServicesMasters").filterProperty("component_name", componentName),
  535. componentHosts = currentComponents.mapProperty("selectedHost"),
  536. availableComponentHosts = [],
  537. preparedAvailableHosts = null;
  538. //get all hosts available for zookeepers
  539. this.get("hosts").forEach(function (item) {
  540. if (!componentHosts.contains(item.get("host_name"))) {
  541. availableComponentHosts.pushObject(item);
  542. }
  543. }, this);
  544. currentComponents.forEach(function (item) {
  545. preparedAvailableHosts = availableComponentHosts.slice(0);
  546. if (this.get('content.controllerName') != 'reassignMasterController') {
  547. preparedAvailableHosts.pushObject(this.get("hosts").findProperty("host_name", item.get("selectedHost")));
  548. } else {
  549. if(item.get("host_name") != this.get('content.currentHostId')) {
  550. preparedAvailableHosts.pushObject(this.get("hosts").findProperty("host_name", item.get("host_name")));
  551. }
  552. item.set("selectedHost", preparedAvailableHosts.objectAt(0).host_name);
  553. }
  554. preparedAvailableHosts.sort(this.sortHostsByName, this);
  555. item.set("availableHosts", preparedAvailableHosts);
  556. }, this);
  557. },
  558. sortHostsByConfig:function (a, b) {
  559. //currently handling only total memory on the host
  560. if (a.memory < b.memory) {
  561. return 1;
  562. }
  563. else {
  564. return -1;
  565. }
  566. },
  567. sortHostsByName:function (a, b) {
  568. if (a.host_name > b.host_name) {
  569. return 1;
  570. }
  571. else {
  572. return -1;
  573. }
  574. },
  575. submit: function () {
  576. if (!this.get('isSubmitDisabled')){
  577. App.router.send('next');
  578. }
  579. }
  580. });