step5_controller.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  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. loadHostInfo: function () {
  43. var hostInfo = [];
  44. hostInfo = App.db.getHosts();
  45. var hosts = new Ember.Set();
  46. for (var index in hostInfo) {
  47. hosts.add(hostInfo[index]);
  48. console.log("TRACE: host name is: " + hostInfo[index].name);
  49. }
  50. return hosts.filterProperty('bootStatus', 'success');
  51. },
  52. renderHostInfo: function (hostsInfo) {
  53. //wrap the model data into
  54. hostsInfo.forEach(function (_host) {
  55. var hostObj = Ember.Object.create({
  56. host_name: _host.name,
  57. cpu: _host.cpu,
  58. memory: _host.memory
  59. });
  60. console.log('pushing ' + hostObj.host_name);
  61. hostObj.set("host_info", "" + hostObj.get("host_name") + " ( " + hostObj.get("memory") + "GB" + " " + hostObj.get("cpu") + "cores )");
  62. this.get("hosts").pushObject(hostObj);
  63. }, this);
  64. },
  65. loadServices: function () {
  66. var serviceInfo = App.db.getService();
  67. var services = serviceInfo.filterProperty('isSelected', true).mapProperty('serviceName');
  68. services.forEach(function (item) {
  69. console.log("TRACE: service name is: " + item);
  70. this.get("selectedServices").pushObject(Ember.Object.create({service_name: item}));
  71. }, this);
  72. return services;
  73. },
  74. loadComponents: function (services) {
  75. var components = new Ember.Set();
  76. if (App.db.getMasterComponentHosts() === undefined) {
  77. var masterComponents = this.components.filterProperty('isMaster', true);
  78. for (var index in services) {
  79. var componentInfo = masterComponents.filterProperty('service_name', services[index]);
  80. componentInfo.forEach(function (_componentInfo) {
  81. console.log("TRACE: master component name is: " + _componentInfo.display_name);
  82. var componentObj = {};
  83. componentObj.component_name = _componentInfo.display_name;
  84. componentObj.selectedHost = this.selectHost(_componentInfo.component_name); // call the method that plays selectNode algorithm or fetches from server
  85. componentObj.availableHosts = [];
  86. components.add(componentObj);
  87. }, this);
  88. }
  89. } else {
  90. var masterComponentHosts = App.db.getMasterComponentHosts();
  91. masterComponentHosts.forEach(function (_masterComponentHost) {
  92. var componentObj = {};
  93. componentObj.component_name =_masterComponentHost.component;
  94. componentObj.selectedHost = _masterComponentHost.hostName; // call the method that plays selectNode algorithm or fetches from server
  95. componentObj.availableHosts = [];
  96. components.add(componentObj);
  97. }, this);
  98. }
  99. return components;
  100. },
  101. getMasterComponents: function () {
  102. return (this.get('selectedServicesMasters').slice(0));
  103. },
  104. renderComponents: function (masterComponents) {
  105. var zookeeperComponent = null, componentObj = null;
  106. var services = [];
  107. services = this.getMasterComponents();
  108. if (services.length) {
  109. this.set('selectedServicesMasters', []);
  110. }
  111. masterComponents.forEach(function (item) {
  112. //add the zookeeper component at the end if exists
  113. if (item.component_name === "ZooKeeper") {
  114. if (services.length) {
  115. services.forEach(function (_service) {
  116. this.get('selectedServicesMasters').pushObject(_service);
  117. }, this);
  118. }
  119. this.set('zId', parseInt(this.get('zId')) + 1);
  120. zookeeperComponent = Ember.Object.create(item);
  121. zookeeperComponent.set('zId', this.get('zId'));
  122. zookeeperComponent.set("showRemoveControl", true);
  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. lastZooKeeper: function () {
  370. var currentZooKeepers = this.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper");
  371. var lastZooKeeper = currentZooKeepers.get("lastObject");
  372. return lastZooKeeper;
  373. },
  374. addZookeepers: function () {
  375. /*
  376. *Logic: If ZooKeeper service is selected then there can be
  377. * minimum 1 ZooKeeper master in total, and
  378. * maximum 1 ZooKeeper on every host
  379. */
  380. var maxNumZooKeepers = this.get("hosts.length"),
  381. currentZooKeepers = this.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper"),
  382. newZookeeper = null,
  383. zookeeperHosts = null,
  384. suggestedHost = null,
  385. i = 0,
  386. lastZoo = null;
  387. console.log('hosts legth is: ' + maxNumZooKeepers);
  388. //work only if the Zookeeper service is selected in previous step
  389. if (!this.get("selectedServices").mapProperty("service_name").contains("ZOOKEEPER")) {
  390. console.log('ALERT: Zookeeper service was not selected');
  391. return false;
  392. }
  393. if (currentZooKeepers.get("length") < maxNumZooKeepers) {
  394. console.log('currentZookeeper length less than maximum. Its: ' + currentZooKeepers.get("length"))
  395. currentZooKeepers.set("lastObject.showAddControl", false);
  396. if (currentZooKeepers.get("length") >= 1) {
  397. currentZooKeepers.set("lastObject.showRemoveControl", true);
  398. }
  399. //create a new zookeeper based on an existing one
  400. newZookeeper = Ember.Object.create({});
  401. lastZoo = currentZooKeepers.get("lastObject");
  402. newZookeeper.set("component_name", lastZoo.get("component_name"));
  403. newZookeeper.set("selectedHost", lastZoo.get("selectedHost"));
  404. newZookeeper.set("availableHosts", this.getAvailableHosts("ZooKeeper"));
  405. if (currentZooKeepers.get("length") === (maxNumZooKeepers - 1)) {
  406. newZookeeper.set("showAddControl", false);
  407. } else {
  408. newZookeeper.set("showAddControl", true);
  409. }
  410. newZookeeper.set("showRemoveControl", true);
  411. //get recommended host for the new Zookeeper server
  412. zookeeperHosts = currentZooKeepers.mapProperty("selectedHost").uniq();
  413. for (i = 0; i < this.get("hosts.length"); i++) {
  414. if (!(zookeeperHosts.contains(this.get("hosts")[i].get("host_name")))) {
  415. suggestedHost = this.get("hosts")[i].get("host_name");
  416. break;
  417. }
  418. }
  419. newZookeeper.set("selectedHost", suggestedHost);
  420. newZookeeper.set("zId", (currentZooKeepers.get("lastObject.zId") + 1));
  421. this.set('zId', parseInt(this.get('zId')) + 1);
  422. this.get("selectedServicesMasters").pushObject(newZookeeper);
  423. this.rebalanceZookeeperHosts();
  424. return true;
  425. }
  426. return false;//if no more zookeepers can be added
  427. },
  428. removeZookeepers: function (zId) {
  429. var currentZooKeepers;
  430. //work only if the Zookeeper service is selected in previous step
  431. if (!this.get("selectedServices").mapProperty("service_name").contains("ZOOKEEPER")) {
  432. return false;
  433. }
  434. currentZooKeepers = this.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper");
  435. if (currentZooKeepers.get("length") > 1) {
  436. this.get("selectedServicesMasters").removeAt(this.get("selectedServicesMasters").indexOf(this.get("selectedServicesMasters").findProperty("zId", zId)));
  437. currentZooKeepers = this.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper");
  438. if (currentZooKeepers.get("length") < this.get("hosts.length")) {
  439. currentZooKeepers.set("lastObject.showAddControl", true);
  440. }
  441. if (currentZooKeepers.get("length") === 1) {
  442. currentZooKeepers.set("lastObject.showRemoveControl", false);
  443. }
  444. this.set('zId', parseInt(this.get('zId')) - 1);
  445. this.rebalanceZookeeperHosts();
  446. return true;
  447. }
  448. return false;
  449. },
  450. rebalanceZookeeperHosts: function () {
  451. //for a zookeeper update the available hosts for the other zookeepers
  452. var currentZooKeepers = this.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper"),
  453. zooHosts = currentZooKeepers.mapProperty("selectedHost"),
  454. availableZooHosts = [],
  455. preparedAvailableHosts = null;
  456. //get all hosts available for zookeepers
  457. this.get("hosts").forEach(function (item) {
  458. if (!zooHosts.contains(item.get("host_name"))) {
  459. availableZooHosts.pushObject(item);
  460. }
  461. }, this);
  462. currentZooKeepers.forEach(function (item) {
  463. preparedAvailableHosts = availableZooHosts.slice(0);
  464. preparedAvailableHosts.pushObject(this.get("hosts").findProperty("host_name", item.get("selectedHost")))
  465. preparedAvailableHosts.sort(this.sortHostsByConfig, this);
  466. item.set("availableHosts", preparedAvailableHosts);
  467. }, this);
  468. },
  469. sortHostsByConfig: function (a, b) {
  470. //currently handling only total memory on the host
  471. if (a.memory < b.memory) {
  472. return 1;
  473. }
  474. else {
  475. return -1;
  476. }
  477. },
  478. sortHostsByName: function (a, b) {
  479. if (a.host_name > b.host_name) {
  480. return 1;
  481. }
  482. else {
  483. return -1;
  484. }
  485. },
  486. saveComponentHostsToDb: function () {
  487. var obj = this.get('selectedServicesMasters');
  488. var masterComponentHosts = [];
  489. var inc = 0;
  490. var array = [];
  491. obj.forEach(function (_component) {
  492. var hostArr = [];
  493. masterComponentHosts.push({
  494. component: _component.component_name,
  495. hostName: _component.selectedHost
  496. });
  497. });
  498. App.db.setMasterComponentHosts(masterComponentHosts);
  499. },
  500. submit: function () {
  501. this.saveComponentHostsToDb();
  502. App.router.send('next');
  503. }
  504. });