step5_controller.js 18 KB

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