step5_controller.js 17 KB

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