step5_controller.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  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.InstallerStep5Controller = Em.Controller.extend({
  20. //properties
  21. name: "installerStep5Controller",
  22. hosts: [],
  23. selectedServices: [],
  24. selectedServicesMasters: [],
  25. zId: 0,
  26. components: require('data/service_components'),
  27. /*
  28. Below function retrieves host information from local storage
  29. */
  30. clearStep: function () {
  31. this.set('hosts', []);
  32. this.set('selectedServices', []);
  33. this.set('selectedServicesMasters', []);
  34. this.set('zId', 0);
  35. },
  36. loadStep: function () {
  37. console.log("TRACE: Loading step5: Assign Masters");
  38. this.clearStep();
  39. this.renderHostInfo(this.loadHostInfo());
  40. this.renderComponents(this.loadComponents(this.loadServices()));
  41. },
  42. navigateStep: function () {
  43. if (App.router.get('isFwdNavigation') === true) {
  44. this.loadStep();
  45. }
  46. },
  47. loadHostInfo: function () {
  48. //this.clear();
  49. var hostInfo = [];
  50. hostInfo = App.db.getHosts();
  51. var hosts = new Ember.Set();
  52. for (var index in hostInfo) {
  53. hosts.add(hostInfo[index]);
  54. console.log("TRACE: host name is: " + hostInfo[index].name);
  55. }
  56. return hosts.filterProperty('bootStatus','success');
  57. },
  58. renderHostInfo: function (hostsInfo) {
  59. //wrap the model data into
  60. hostsInfo.forEach(function (_host) {
  61. var hostObj = Ember.Object.create({
  62. host_name: _host.name,
  63. cpu: _host.cpu,
  64. memory: _host.memory
  65. });
  66. console.log('pushing ' + hostObj.host_name);
  67. hostObj.set("host_info", "" + hostObj.get("host_name") + " ( " + hostObj.get("memory") + "GB" + " " + hostObj.get("cpu") + "cores )");
  68. this.get("hosts").pushObject(hostObj);
  69. }, this);
  70. },
  71. loadServices: function () {
  72. var services = App.db.getSelectedServiceNames();
  73. services.forEach(function (item) {
  74. console.log("TRACE: service name is: " + item);
  75. this.get("selectedServices").pushObject(Ember.Object.create({service_name: item}));
  76. }, this);
  77. return services;
  78. },
  79. loadComponents: function (services) {
  80. var self = this;
  81. var components = new Ember.Set();
  82. var masterComponents = self.components.filterProperty('isMaster', true);
  83. for (var index in services) {
  84. var componentInfo = masterComponents.filterProperty('service_name', services[index]);
  85. componentInfo.forEach(function (_componentInfo) {
  86. console.log("TRACE: master component name is: " + _componentInfo.display_name);
  87. var componentObj = {};
  88. componentObj.component_name = _componentInfo.display_name;
  89. componentObj.selectedHost = this.selectHost(_componentInfo.component_name); // call the method that plays selectNode algorithm or fetches from server
  90. componentObj.availableHosts = [];
  91. components.add(componentObj);
  92. }, this);
  93. }
  94. return components;
  95. },
  96. getMasterComponents: function () {
  97. return (this.get('selectedServicesMasters').slice(0));
  98. },
  99. renderComponents: function (masterComponents) {
  100. var zookeeperComponent = null, componentObj = null;
  101. var services = [];
  102. services = this.getMasterComponents();
  103. if (services.length) {
  104. this.set('selectedServicesMasters', []);
  105. }
  106. masterComponents.forEach(function (item) {
  107. //add the zookeeper component at the end if exists
  108. if (item.component_name === "ZooKeeper") {
  109. if (services.length) {
  110. services.forEach(function (_service) {
  111. this.get('selectedServicesMasters').pushObject(_service);
  112. }, this);
  113. }
  114. this.set('zId', this.get('zId') + 1);
  115. zookeeperComponent = Ember.Object.create(item);
  116. zookeeperComponent.set('zId', this.get('zId'));
  117. zookeeperComponent.set("showAddControl", true);
  118. if (zookeeperComponent.get('zId') === 1) {
  119. zookeeperComponent.set("showRemoveControl", false);
  120. } else {
  121. zookeeperComponent.set("showRemoveControl", true);
  122. }
  123. zookeeperComponent.set("availableHosts", this.get("hosts").slice(0));
  124. this.get("selectedServicesMasters").pushObject(Ember.Object.create(zookeeperComponent));
  125. } else {
  126. componentObj = Ember.Object.create(item);
  127. componentObj.set("availableHosts", this.get("hosts").slice(0));
  128. this.get("selectedServicesMasters").pushObject(componentObj);
  129. }
  130. }, this);
  131. },
  132. getKerberosServer: function (noOfHosts) {
  133. var hosts = this.get('hosts');
  134. if (noOfHosts === 1) {
  135. return hosts[0];
  136. } else if (noOfHosts < 3) {
  137. return hosts[1];
  138. } else if (noOfHosts <= 5) {
  139. return hosts[1];
  140. } else if (noOfHosts <= 30) {
  141. return hosts[3];
  142. } else {
  143. return hosts[5];
  144. }
  145. },
  146. getNameNode: function (noOfHosts) {
  147. var hosts = this.get('hosts');
  148. return hosts[0];
  149. },
  150. getSNameNode: function (noOfHosts) {
  151. var hosts = this.get('hosts');
  152. if (noOfHosts === 1) {
  153. return hosts[0];
  154. } else {
  155. return hosts[1];
  156. }
  157. },
  158. getJobTracker: function (noOfHosts) {
  159. var hosts = this.get('hosts');
  160. if (noOfHosts === 1) {
  161. return hosts[0];
  162. } else if (noOfHosts < 3) {
  163. return hosts[1];
  164. } else if (noOfHosts <= 5) {
  165. return hosts[1];
  166. } else if (noOfHosts <= 30) {
  167. return hosts[1];
  168. } else {
  169. return hosts[2];
  170. }
  171. },
  172. getHBaseMaster: function (noOfHosts) {
  173. var hosts = this.get('hosts');
  174. if (noOfHosts === 1) {
  175. return hosts[0];
  176. } else if (noOfHosts < 3) {
  177. return hosts[0];
  178. } else if (noOfHosts <= 5) {
  179. return hosts[0];
  180. } else if (noOfHosts <= 30) {
  181. return hosts[2];
  182. } else {
  183. return hosts[3];
  184. }
  185. },
  186. getOozieServer: function (noOfHosts) {
  187. var hosts = this.get('hosts');
  188. if (noOfHosts === 1) {
  189. return hosts[0];
  190. } else if (noOfHosts < 3) {
  191. return hosts[1];
  192. } else if (noOfHosts <= 5) {
  193. return hosts[1];
  194. } else if (noOfHosts <= 30) {
  195. return hosts[2];
  196. } else {
  197. return hosts[3];
  198. }
  199. },
  200. getOozieServer: function (noOfHosts) {
  201. var hosts = this.get('hosts');
  202. if (noOfHosts === 1) {
  203. return hosts[0];
  204. } else if (noOfHosts < 3) {
  205. return hosts[1];
  206. } else if (noOfHosts <= 5) {
  207. return hosts[1];
  208. } else if (noOfHosts <= 30) {
  209. return hosts[2];
  210. } else {
  211. return hosts[3];
  212. }
  213. },
  214. getHiveServer: function (noOfHosts) {
  215. var hosts = this.get('hosts');
  216. if (noOfHosts === 1) {
  217. return hosts[0];
  218. } else if (noOfHosts < 3) {
  219. return hosts[1];
  220. } else if (noOfHosts <= 5) {
  221. return hosts[1];
  222. } else if (noOfHosts <= 30) {
  223. return hosts[2];
  224. } else {
  225. return hosts[4];
  226. }
  227. },
  228. getTempletonServer: function (noOfHosts) {
  229. var hosts = this.get('hosts');
  230. if (noOfHosts === 1) {
  231. return hosts[0];
  232. } else if (noOfHosts < 3) {
  233. return hosts[1];
  234. } else if (noOfHosts <= 5) {
  235. return hosts[1];
  236. } else if (noOfHosts <= 30) {
  237. return hosts[2];
  238. } else {
  239. return hosts[4];
  240. }
  241. },
  242. getZooKeeperServer: function (noOfHosts) {
  243. var hosts = this.get('hosts');
  244. if (noOfHosts < 3) {
  245. return [hosts[0].host_name];
  246. } else {
  247. return [hosts[0].host_name, hosts[1].host_name, hosts[2].host_name];
  248. }
  249. },
  250. getGangliaServer: function (noOfHosts) {
  251. var hosts = this.get('hosts');
  252. var hostnames = [];
  253. var inc = 0;
  254. hosts.forEach(function (_hostname) {
  255. hostnames[inc] = _hostname.host_name;
  256. inc++;
  257. });
  258. var hostExcAmbari = hostnames.without(location.hostname);
  259. if (hostExcAmbari !== null || hostExcAmbari !== undefined || hostExcAmbari.length !== 0) {
  260. return hostExcAmbari[0];
  261. } else {
  262. return hostnames[0];
  263. }
  264. },
  265. getNagiosServer: function (noOfHosts) {
  266. var hosts = this.get('hosts');
  267. var hostnames = [];
  268. var inc = 0;
  269. hosts.forEach(function (_hostname) {
  270. hostnames[inc] = _hostname.host_name;
  271. inc++;
  272. });
  273. var hostExcAmbari = hostnames.without(location.hostname);
  274. if (hostExcAmbari !== null || hostExcAmbari !== undefined || hostExcAmbari.length !== 0) {
  275. return hostExcAmbari[0];
  276. } else {
  277. return hostnames[0];
  278. }
  279. },
  280. selectHost: function (componentName) {
  281. var noOfHosts = this.get('hosts').length;
  282. if (componentName === 'KERBEROS_SERVER') {
  283. return this.getKerberosServer(noOfHosts).host_name;
  284. } else if (componentName === 'NAMENODE') {
  285. return this.getNameNode(noOfHosts).host_name;
  286. } else if (componentName === 'SNAMENODE') {
  287. return this.getSNameNode(noOfHosts).host_name;
  288. } else if (componentName === 'JOBTRACKER') {
  289. return this.getJobTracker(noOfHosts).host_name;
  290. } else if (componentName === 'HBASE_MASTER') {
  291. return this.getHBaseMaster(noOfHosts).host_name;
  292. } else if (componentName === 'OOZIE_SERVER') {
  293. return this.getOozieServer(noOfHosts).host_name;
  294. } else if (componentName === 'HIVE_SERVER') {
  295. return this.getHiveServer(noOfHosts).host_name;
  296. } else if (componentName === 'TEMPLETON_SERVER') {
  297. return this.getTempletonServer(noOfHosts).host_name;
  298. } else if (componentName === 'ZOOKEEPER_SERVER') {
  299. var zhosts = this.getZooKeeperServer(noOfHosts);
  300. var extraHosts = zhosts.slice(0, zhosts.length - 1);
  301. var zooKeeperHosts = new Ember.Set();
  302. extraHosts.forEach(function (_host) {
  303. var zooKeeperHost = {};
  304. zooKeeperHost.component_name = 'ZooKeeper';
  305. zooKeeperHost.selectedHost = _host;
  306. zooKeeperHost.availableHosts = [];
  307. zooKeeperHosts.add(zooKeeperHost);
  308. });
  309. this.renderComponents(zooKeeperHosts);
  310. var lastHost = zhosts[zhosts.length - 1];
  311. return lastHost;
  312. } else if (componentName === 'GANGLIA_MONITOR_SERVER') {
  313. return this.getGangliaServer(noOfHosts);
  314. } else if (componentName === 'NAGIOS_SERVER') {
  315. return this.getNagiosServer(noOfHosts);
  316. }
  317. },
  318. masterHostMapping: function () {
  319. var mapping = [], mappingObject, self = this, mappedHosts, hostObj, hostInfo;
  320. //get the unique assigned hosts and find the master services assigned to them
  321. mappedHosts = this.get("selectedServicesMasters").mapProperty("selectedHost").uniq();
  322. mappedHosts.forEach(function (item) {
  323. hostObj = self.get("hosts").findProperty("host_name", item);
  324. console.log("Name of the host is: " + hostObj.host_name);
  325. hostInfo = " ( " + hostObj.get("memory") + "GB" + " " + hostObj.get("cpu") + "cores )";
  326. mappingObject = Ember.Object.create({
  327. host_name: item,
  328. hostInfo: hostInfo,
  329. masterServices: self.get("selectedServicesMasters").filterProperty("selectedHost", item)
  330. });
  331. mapping.pushObject(mappingObject);
  332. }, this);
  333. mapping.sort(this.sortHostsByName);
  334. return mapping;
  335. }.property("selectedServicesMasters.@each.selectedHost"),
  336. remainingHosts: function () {
  337. return (this.get("hosts.length") - this.get("masterHostMapping.length"));
  338. }.property("selectedServicesMasters.@each.selectedHost"),
  339. hasZookeeper: function () {
  340. return this.selectedServices.findProperty("service_name", "ZooKeeper");
  341. }.property("selectedServices"),
  342. //methods
  343. getAvailableHosts: function (componentName) {
  344. var assignableHosts = [],
  345. zookeeperHosts = null;
  346. if (componentName === "ZooKeeper") {
  347. zookeeperHosts = this.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper").mapProperty("selectedHost").uniq();
  348. this.get("hosts").forEach(function (item) {
  349. if (!(zookeeperHosts.contains(item.get("host_name")))) {
  350. assignableHosts.pushObject(item);
  351. }
  352. }, this);
  353. return assignableHosts;
  354. } else {
  355. return this.get("hosts");
  356. }
  357. },
  358. assignHostToMaster: function (masterService, selectedHost, zId) {
  359. if (selectedHost && masterService) {
  360. if ((masterService === "ZooKeeper") && zId) {
  361. this.get('selectedServicesMasters').findProperty("zId", zId).set("selectedHost", selectedHost);
  362. this.rebalanceZookeeperHosts();
  363. }
  364. else {
  365. this.get('selectedServicesMasters').findProperty("component_name", masterService).set("selectedHost", selectedHost);
  366. }
  367. }
  368. },
  369. addZookeepers: function () {
  370. /*
  371. *Logic: If ZooKeeper service is selected then there can be
  372. * minimum 1 ZooKeeper master in total, and
  373. * maximum 1 ZooKeeper on every host
  374. */
  375. var maxNumZooKeepers = this.get("hosts.length"),
  376. currentZooKeepers = this.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper"),
  377. newZookeeper = null,
  378. zookeeperHosts = null,
  379. suggestedHost = null,
  380. i = 0,
  381. lastZoo = null;
  382. console.log('hosts legth is: ' + maxNumZooKeepers);
  383. //work only if the Zookeeper service is selected in previous step
  384. if (!this.get("selectedServices").mapProperty("service_name").contains("ZOOKEEPER")) {
  385. console.log('ALERT: Zookeeper service was not selected');
  386. return false;
  387. }
  388. if (currentZooKeepers.get("length") < maxNumZooKeepers) {
  389. console.log('currentZookeeper length less than maximum. Its: ' + currentZooKeepers.get("length"))
  390. currentZooKeepers.set("lastObject.showAddControl", false);
  391. if (currentZooKeepers.get("length") > 1) {
  392. currentZooKeepers.set("lastObject.showRemoveControl", true);
  393. }
  394. //create a new zookeeper based on an existing one
  395. newZookeeper = Ember.Object.create({});
  396. lastZoo = currentZooKeepers.get("lastObject");
  397. newZookeeper.set("component_name", lastZoo.get("component_name"));
  398. newZookeeper.set("selectedHost", lastZoo.get("selectedHost"));
  399. newZookeeper.set("availableHosts", this.getAvailableHosts("ZooKeeper"));
  400. if (currentZooKeepers.get("length") === (maxNumZooKeepers - 1)) {
  401. newZookeeper.set("showAddControl", false);
  402. } else {
  403. newZookeeper.set("showAddControl", true);
  404. }
  405. newZookeeper.set("showRemoveControl", true);
  406. //get recommended host for the new Zookeeper server
  407. zookeeperHosts = currentZooKeepers.mapProperty("selectedHost").uniq();
  408. for (i = 0; i < this.get("hosts.length"); i++) {
  409. if (!(zookeeperHosts.contains(this.get("hosts")[i].get("host_name")))) {
  410. suggestedHost = this.get("hosts")[i].get("host_name");
  411. break;
  412. }
  413. }
  414. newZookeeper.set("selectedHost", suggestedHost);
  415. newZookeeper.set("zId", (currentZooKeepers.get("lastObject.zId") + 1));
  416. this.get("selectedServicesMasters").pushObject(newZookeeper);
  417. this.rebalanceZookeeperHosts();
  418. return true;
  419. }
  420. return false;//if no more zookeepers can be added
  421. },
  422. removeZookeepers: function (zId) {
  423. var currentZooKeepers;
  424. //work only if the Zookeeper service is selected in previous step
  425. if (!this.get("selectedServices").mapProperty("service_name").contains("ZOOKEEPER")) {
  426. return false;
  427. }
  428. currentZooKeepers = this.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper");
  429. if (currentZooKeepers.get("length") > 1) {
  430. this.get("selectedServicesMasters").removeAt(this.get("selectedServicesMasters").indexOf(this.get("selectedServicesMasters").findProperty("zId", zId)));
  431. currentZooKeepers = this.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper");
  432. if (currentZooKeepers.get("length") < this.get("hosts.length")) {
  433. currentZooKeepers.set("lastObject.showAddControl", true);
  434. }
  435. this.rebalanceZookeeperHosts();
  436. return true;
  437. }
  438. return false;
  439. },
  440. rebalanceZookeeperHosts: function () {
  441. //for a zookeeper update the available hosts for the other zookeepers
  442. var currentZooKeepers = this.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper"),
  443. zooHosts = currentZooKeepers.mapProperty("selectedHost"),
  444. availableZooHosts = [],
  445. preparedAvailableHosts = null;
  446. //get all hosts available for zookeepers
  447. this.get("hosts").forEach(function (item) {
  448. if (!zooHosts.contains(item.get("host_name"))) {
  449. availableZooHosts.pushObject(item);
  450. }
  451. }, this);
  452. currentZooKeepers.forEach(function (item) {
  453. preparedAvailableHosts = availableZooHosts.slice(0);
  454. preparedAvailableHosts.pushObject(this.get("hosts").findProperty("host_name", item.get("selectedHost")))
  455. preparedAvailableHosts.sort(this.sortHostsByConfig, this);
  456. item.set("availableHosts", preparedAvailableHosts);
  457. }, this);
  458. },
  459. sortHostsByConfig: function (a, b) {
  460. //currently handling only total memory on the host
  461. if (a.memory < b.memory) {
  462. return 1;
  463. }
  464. else {
  465. return -1;
  466. }
  467. },
  468. sortHostsByName: function (a, b) {
  469. if (a.host_name > b.host_name) {
  470. return 1;
  471. }
  472. else {
  473. return -1;
  474. }
  475. },
  476. saveComponentHostsToDb: function () {
  477. var obj = this.get('selectedServicesMasters');
  478. var masterComponentHosts = [];
  479. var inc = 0;
  480. var array = [];
  481. obj.forEach(function (_component) {
  482. var hostArr = [];
  483. masterComponentHosts.push({
  484. component: _component.component_name,
  485. hostName: _component.selectedHost
  486. });
  487. });
  488. App.db.setMasterComponentHosts(masterComponentHosts);
  489. },
  490. submit: function () {
  491. this.saveComponentHostsToDb();
  492. App.router.send('next');
  493. }
  494. });