step5_controller.js 18 KB

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