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