step5_controller.js 20 KB

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