step5_controller.js 18 KB

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