step5_controller.js 23 KB

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