step5_controller.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  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. var numberUtils = require('utils/number_utils');
  20. App.WizardStep5Controller = Em.Controller.extend({
  21. name:"wizardStep5Controller",
  22. title: function () {
  23. if (this.get('content.controllerName') == 'reassignMasterController') {
  24. return Em.I18n.t('installer.step5.reassign.header');
  25. }
  26. return Em.I18n.t('installer.step5.header');
  27. }.property('content.controllerName'),
  28. isReassignWizard: function () {
  29. return this.get('content.controllerName') == 'reassignMasterController';
  30. }.property('content.controllerName'),
  31. isAddServiceWizard: function() {
  32. return this.get('content.controllerName') == 'addServiceController';
  33. }.property('content.controllerName'),
  34. isReassignHive: function () {
  35. return this.get('servicesMasters').objectAt(0) && this.get('servicesMasters').objectAt(0).component_name == 'HIVE_SERVER' && this.get('isReassignWizard');
  36. }.property('isReassignWizard', 'servicesMasters'),
  37. /**
  38. * master components which could be assigned to multiple hosts
  39. */
  40. multipleComponents: ['ZOOKEEPER_SERVER', 'HBASE_MASTER'],
  41. /**
  42. * Define state for submit button. Return true only for Reassign Master Wizard and if more than one master component was reassigned.
  43. */
  44. isSubmitDisabled: function () {
  45. if (!this.get('isReassignWizard')) {
  46. return false;
  47. }
  48. var reassigned = 0;
  49. var arr1 = App.HostComponent.find().filterProperty('componentName', this.get('content.reassign.component_name')).mapProperty('host.hostName');
  50. var arr2 = this.get('servicesMasters').mapProperty('selectedHost');
  51. arr1.forEach(function (host) {
  52. if (!arr2.contains(host)) {
  53. reassigned++;
  54. }
  55. }, this);
  56. return reassigned !== 1;
  57. }.property('servicesMasters.@each.selectedHost'),
  58. hosts:[],
  59. componentToRebalance: null,
  60. rebalanceComponentHostsCounter: 0,
  61. servicesMasters:[],
  62. selectedServicesMasters:[],
  63. components:require('data/service_components'),
  64. clearStep:function () {
  65. this.set('hosts', []);
  66. this.set('selectedServicesMasters', []);
  67. this.set('servicesMasters', []);
  68. },
  69. loadStep:function () {
  70. console.log("WizardStep5Controller: Loading step5: Assign Masters");
  71. this.clearStep();
  72. this.renderHostInfo();
  73. this.renderComponents(this.loadComponents());
  74. this.updateComponent('ZOOKEEPER_SERVER');
  75. if(App.supports.multipleHBaseMasters){
  76. this.updateComponent('HBASE_MASTER');
  77. }
  78. if (!this.get("selectedServicesMasters").filterProperty('isInstalled', false).length) {
  79. console.log('no master components to add');
  80. App.router.send('next');
  81. }
  82. },
  83. /**
  84. * Used to set showAddControl flag for ZOOKEEPER_SERVER and HBASE_SERVER
  85. */
  86. updateComponent: function(componentName){
  87. var component = this.last(componentName);
  88. var services = this.get('content.services').filterProperty('isInstalled', true).mapProperty('serviceName');
  89. var currentService = componentName.split('_')[0];
  90. var showControl = !services.contains(currentService);
  91. if (component) {
  92. if(showControl){
  93. if (this.get("selectedServicesMasters").filterProperty("component_name", componentName).length < this.get("hosts.length") && !this.get('isReassignWizard')) {
  94. component.set('showAddControl', true);
  95. } else {
  96. component.set('showRemoveControl', false);
  97. }
  98. }
  99. }
  100. },
  101. /**
  102. * Load active host list to <code>hosts</code> variable
  103. */
  104. renderHostInfo:function () {
  105. var hostInfo = this.get('content.hosts');
  106. var result = [];
  107. for (var index in hostInfo) {
  108. var _host = hostInfo[index];
  109. if (_host.bootStatus === 'REGISTERED') {
  110. result.push(Ember.Object.create({
  111. host_name:_host.name,
  112. cpu:_host.cpu,
  113. memory:_host.memory,
  114. disk_info:_host.disk_info,
  115. host_info: Em.I18n.t('installer.step5.hostInfo').fmt(_host.name, numberUtils.bytesToSize(_host.memory, 1, 'parseFloat', 1024), _host.cpu)
  116. }));
  117. }
  118. }
  119. this.set("hosts", result);
  120. this.sortHosts(this.get('hosts'));
  121. },
  122. sortHosts: function (hosts) {
  123. hosts.sort(function (a, b) {
  124. if (a.get('memory') == b.get('memory')) {
  125. if (a.get('cpu') == b.get('cpu')) {
  126. return a.get('host_name').localeCompare(b.get('host_name')); // hostname asc
  127. }
  128. return b.get('cpu') - a.get('cpu'); // cores desc
  129. }
  130. return b.get('memory') - a.get('memory'); // ram desc
  131. });
  132. },
  133. /**
  134. * Load services info to appropriate variable and return masterComponentHosts
  135. * @return Array
  136. */
  137. loadComponents:function () {
  138. var services = this.get('content.services')
  139. .filterProperty('isSelected', true).mapProperty('serviceName'); //list of shown services
  140. var masterComponents = this.get('components').filterProperty('isMaster', true); //get full list from mock data
  141. var masterHosts = this.get('content.masterComponentHosts'); //saved to local storage info
  142. var resultComponents = [];
  143. var servicesLength = services.length;
  144. for (var index = 0; index < servicesLength; index++) {
  145. var componentInfo = masterComponents.filterProperty('service_name', services[index]);
  146. componentInfo.forEach(function (_componentInfo) {
  147. if (_componentInfo.component_name == 'ZOOKEEPER_SERVER' || _componentInfo.component_name == 'HBASE_MASTER') {
  148. var savedComponents = masterHosts.filterProperty('component', _componentInfo.component_name);
  149. if (savedComponents.length) {
  150. savedComponents.forEach(function (item) {
  151. var zooKeeperHost = {};
  152. zooKeeperHost.display_name = _componentInfo.display_name;
  153. zooKeeperHost.component_name = _componentInfo.component_name;
  154. zooKeeperHost.selectedHost = item.hostName;
  155. zooKeeperHost.serviceId = services[index];
  156. zooKeeperHost.isInstalled = item.isInstalled;
  157. zooKeeperHost.isHiveCoHost = false;
  158. resultComponents.push(zooKeeperHost);
  159. })
  160. } else {
  161. var zooHosts = this.selectHost(_componentInfo.component_name);
  162. zooHosts.forEach(function (_host) {
  163. var zooKeeperHost = {};
  164. zooKeeperHost.display_name = _componentInfo.display_name;
  165. zooKeeperHost.component_name = _componentInfo.component_name;
  166. zooKeeperHost.selectedHost = _host;
  167. zooKeeperHost.serviceId = services[index];
  168. zooKeeperHost.isInstalled = false;
  169. zooKeeperHost.isHiveCoHost = false;
  170. resultComponents.push(zooKeeperHost);
  171. });
  172. }
  173. } else {
  174. var savedComponent = masterHosts.findProperty('component', _componentInfo.component_name);
  175. var componentObj = {};
  176. componentObj.component_name = _componentInfo.component_name;
  177. componentObj.display_name = _componentInfo.display_name;
  178. componentObj.selectedHost = savedComponent ? savedComponent.hostName : this.selectHost(_componentInfo.component_name); // call the method that plays selectNode algorithm or fetches from server
  179. componentObj.isInstalled = savedComponent ? savedComponent.isInstalled : false;
  180. componentObj.serviceId = services[index];
  181. componentObj.isHiveCoHost = ['HIVE_METASTORE', 'WEBHCAT_SERVER'].contains(_componentInfo.component_name) && !this.get('isReassignWizard');
  182. resultComponents.push(componentObj);
  183. }
  184. }, this);
  185. }
  186. return resultComponents;
  187. },
  188. /**
  189. * Put master components to <code>selectedServicesMasters</code>, which will be automatically rendered in template
  190. * @param masterComponents
  191. */
  192. renderComponents:function (masterComponents) {
  193. var self = this;
  194. var services = this.get('content.services')
  195. .filterProperty('isInstalled', true).mapProperty('serviceName'); //list of shown services
  196. var showRemoveControlZk = !services.contains('ZOOKEEPER') && masterComponents.filterProperty('display_name', 'ZooKeeper').length > 1;
  197. var showRemoveControlHb = !services.contains('HBASE') && masterComponents.filterProperty('component_name', 'HBASE_MASTER').length > 1;
  198. var zid = 1;
  199. var hid = 1;
  200. var nid = 1;
  201. var result = [];
  202. masterComponents.forEach(function (item) {
  203. if (item.component_name == 'SECONDARY_NAMENODE') {
  204. if (self.get('isAddServiceWizard')) {
  205. if (App.get('isHaEnabled')) {
  206. return;
  207. }
  208. }
  209. }
  210. var componentObj = Ember.Object.create(item);
  211. console.log("TRACE: render master component name is: " + item.component_name);
  212. if (item.display_name === "ZooKeeper") {
  213. componentObj.set('zId', zid++);
  214. componentObj.set("showRemoveControl", showRemoveControlZk);
  215. } else if (App.supports.multipleHBaseMasters && item.component_name === "HBASE_MASTER") {
  216. componentObj.set('zId', hid++);
  217. componentObj.set("showRemoveControl", showRemoveControlHb);
  218. } else if (item.component_name === "NAMENODE") {
  219. componentObj.set('zId', nid++);
  220. }
  221. result.push(componentObj);
  222. }, this);
  223. this.set("selectedServicesMasters", result);
  224. if (this.get('isReassignWizard')) {
  225. var components = result.filterProperty('component_name', this.get('content.reassign.component_name'));
  226. components.setEach('isInstalled', false);
  227. this.set('servicesMasters', components);
  228. } else {
  229. this.set('servicesMasters', result);
  230. }
  231. },
  232. hasHiveServer: function () {
  233. return !!this.get('selectedServicesMasters').findProperty('component_name', 'HIVE_SERVER') && !this.get('isReassignWizard');
  234. }.property('selectedServicesMasters'),
  235. updateHiveCoHosts: function () {
  236. var hiveServer = this.get('selectedServicesMasters').findProperty('component_name', 'HIVE_SERVER');
  237. var hiveMetastore = this.get('selectedServicesMasters').findProperty('component_name', 'HIVE_METASTORE');
  238. var webHCatServer = this.get('selectedServicesMasters').findProperty('component_name', 'WEBHCAT_SERVER');
  239. if (hiveServer && hiveMetastore && webHCatServer) {
  240. if (!this.get('isReassignHive') && this.get('servicesMasters').objectAt(0) && !(this.get('servicesMasters').objectAt(0).component_name == 'HIVE_METASTORE')) {
  241. this.get('selectedServicesMasters').findProperty('component_name', 'HIVE_METASTORE').set('selectedHost', hiveServer.get('selectedHost'))
  242. }
  243. this.get('selectedServicesMasters').findProperty('component_name', 'WEBHCAT_SERVER').set('selectedHost', hiveServer.get('selectedHost'));
  244. }
  245. }.observes('selectedServicesMasters.@each.selectedHost'),
  246. /**
  247. * select and return host for component by scheme
  248. * Scheme is an object that has keys which compared to number of hosts,
  249. * if key more that number of hosts, then return value of that key.
  250. * Value is index of host in hosts array.
  251. *
  252. * @param noOfHosts
  253. * @param selectionScheme
  254. * @return {*}
  255. */
  256. getHostForComponent: function(noOfHosts, selectionScheme){
  257. var hosts = this.get('hosts');
  258. if(hosts.length === 1 || $.isEmptyObject(selectionScheme)){
  259. return hosts[0];
  260. } else {
  261. for(var i in selectionScheme){
  262. if(window.isFinite(i)){
  263. if(noOfHosts < window.parseInt(i)){
  264. return hosts[selectionScheme[i]];
  265. }
  266. }
  267. }
  268. return hosts[selectionScheme['else']]
  269. }
  270. },
  271. getZooKeeperServer:function (noOfHosts) {
  272. var hosts = this.get('hosts');
  273. if (noOfHosts < 3) {
  274. return [hosts[0].host_name];
  275. } else {
  276. return [hosts[0].host_name, hosts[1].host_name, hosts[2].host_name];
  277. }
  278. },
  279. getGangliaServer:function (noOfHosts) {
  280. var hostNames = this.get('hosts').mapProperty('host_name');
  281. var hostExcAmbari = hostNames.without(location.hostname);
  282. if (noOfHosts > 1) {
  283. return hostExcAmbari[0];
  284. } else {
  285. return hostNames[0];
  286. }
  287. },
  288. getNagiosServer:function (noOfHosts) {
  289. return this.getGangliaServer(noOfHosts);
  290. },
  291. getHueServer:function (noOfHosts) {
  292. return this.getGangliaServer(noOfHosts);
  293. },
  294. getOozieServer:function(){
  295. return this.selectHost('OOZIE_SERVER');
  296. },
  297. getNimbusServer: function(noOfHosts) {
  298. return this.getGangliaServer(noOfHosts);
  299. },
  300. /**
  301. * Return hostName of masterNode for specified service
  302. * @param componentName
  303. * @return {*}
  304. */
  305. selectHost:function (componentName) {
  306. var noOfHosts = this.get('hosts').length;
  307. switch (componentName) {
  308. case 'KERBEROS_SERVER':
  309. return this.getHostForComponent(noOfHosts, {
  310. "3" : 1,
  311. "6" : 1,
  312. "31" : 3,
  313. "else" : 5
  314. }).host_name;
  315. case 'NAMENODE':
  316. return this.getHostForComponent(noOfHosts, {
  317. "else" : 0
  318. }).host_name;
  319. case 'SECONDARY_NAMENODE':
  320. return this.getHostForComponent(noOfHosts, {
  321. "else" : 1
  322. }).host_name;
  323. case 'JOBTRACKER':
  324. return this.getHostForComponent(noOfHosts, {
  325. "3" : 1,
  326. "6" : 1,
  327. "31" : 1,
  328. "else" : 2
  329. }).host_name;
  330. case 'HISTORYSERVER':
  331. return this.getHostForComponent(noOfHosts, {
  332. "3" : 1,
  333. "6" : 1,
  334. "31" : 1,
  335. "else" : 2
  336. }).host_name;
  337. case 'RESOURCEMANAGER':
  338. return this.getHostForComponent(noOfHosts, {
  339. "3" : 1,
  340. "6" : 1,
  341. "31" : 1,
  342. "else" : 2
  343. }).host_name;
  344. case 'HBASE_MASTER':
  345. return [this.getHostForComponent(noOfHosts, {
  346. "3" : 0,
  347. "6" : 0,
  348. "31" : 2,
  349. "else" : 3
  350. }).host_name];
  351. case 'OOZIE_SERVER':
  352. return this.getHostForComponent(noOfHosts, {
  353. "3" : 1,
  354. "6" : 1,
  355. "31" : 2,
  356. "else" : 3
  357. }).host_name;
  358. case 'HIVE_SERVER':
  359. return this.getHostForComponent(noOfHosts, {
  360. "3" : 1,
  361. "6" : 1,
  362. "31" : 2,
  363. "else" : 4
  364. }).host_name;
  365. case 'HIVE_METASTORE':
  366. return this.getHostForComponent(noOfHosts, {
  367. "3" : 1,
  368. "6" : 1,
  369. "31" : 2,
  370. "else" : 4
  371. }).host_name;
  372. case 'WEBHCAT_SERVER':
  373. return this.getHostForComponent(noOfHosts, {
  374. "3" : 1,
  375. "6" : 1,
  376. "31" : 2,
  377. "else" : 4
  378. }).host_name;
  379. case 'ZOOKEEPER_SERVER':
  380. return this.getZooKeeperServer(noOfHosts);
  381. case 'GANGLIA_SERVER':
  382. return this.getGangliaServer(noOfHosts);
  383. case 'NAGIOS_SERVER':
  384. return this.getNagiosServer(noOfHosts);
  385. case 'HUE_SERVER':
  386. return this.getHueServer(noOfHosts);
  387. case 'APP_TIMELINE_SERVER':
  388. return this.getHostForComponent(noOfHosts, {
  389. "3" : 1,
  390. "6" : 1,
  391. "31" : 1,
  392. "else" : 2
  393. }).host_name;
  394. case 'FALCON_SERVER':
  395. return this.getOozieServer(noOfHosts);
  396. case 'STORM_UI_SERVER':
  397. case 'LOGVIEWER_SERVER':
  398. case 'DRPC_SERVER':
  399. case 'STORM_REST_API':
  400. case 'NIMBUS':
  401. return this.getNimbusServer(noOfHosts);
  402. default:
  403. }
  404. },
  405. masterHostMapping: function () {
  406. var mapping = [], mappingObject, mappedHosts, hostObj;
  407. //get the unique assigned hosts and find the master services assigned to them
  408. mappedHosts = this.get("selectedServicesMasters").mapProperty("selectedHost").uniq();
  409. mappedHosts.forEach(function (item) {
  410. hostObj = this.get("hosts").findProperty("host_name", item);
  411. mappingObject = Ember.Object.create({
  412. host_name: item,
  413. hostInfo: hostObj.host_info,
  414. masterServices: this.get("selectedServicesMasters").filterProperty("selectedHost", item)
  415. });
  416. mapping.pushObject(mappingObject);
  417. }, this);
  418. mapping.sortBy('host_name');
  419. return mapping;
  420. }.property("selectedServicesMasters.@each.selectedHost"),
  421. remainingHosts:function () {
  422. return (this.get("hosts.length") - this.get("masterHostMapping.length"));
  423. }.property("selectedServicesMasters.@each.selectedHost"),
  424. /**
  425. * On change callback for selects
  426. * @param componentName
  427. * @param selectedHost
  428. * @param zId
  429. */
  430. assignHostToMaster:function (componentName, selectedHost, zId) {
  431. if (selectedHost && componentName) {
  432. if (zId) {
  433. this.get('selectedServicesMasters').filterProperty('component_name', componentName).findProperty("zId", zId).set("selectedHost", selectedHost);
  434. } else {
  435. this.get('selectedServicesMasters').findProperty("component_name", componentName).set("selectedHost", selectedHost);
  436. }
  437. }
  438. },
  439. /**
  440. * Returns last component of selected type
  441. * @param componentName
  442. * @return {*}
  443. */
  444. last: function(componentName){
  445. return this.get("selectedServicesMasters").filterProperty("component_name", componentName).get("lastObject");
  446. },
  447. /**
  448. * Add new component to ZooKeeper Server and Hbase master
  449. * @param componentName
  450. * @return {Boolean}
  451. */
  452. addComponent:function (componentName) {
  453. /*
  454. * Logic: If ZooKeeper or Hbase service is selected then there can be
  455. * minimum 1 ZooKeeper or Hbase master in total, and
  456. * maximum 1 ZooKeeper or Hbase on every host
  457. */
  458. var maxNumMasters = this.get("hosts.length"),
  459. currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName),
  460. newMaster = null,
  461. masterHosts = null,
  462. suggestedHost = null,
  463. i = 0,
  464. lastMaster = null;
  465. if (!currentMasters.length) {
  466. console.log('ALERT: Zookeeper service was not selected');
  467. return false;
  468. }
  469. if (currentMasters.get("length") < maxNumMasters) {
  470. currentMasters.set("lastObject.showAddControl", false);
  471. currentMasters.set("lastObject.showRemoveControl", true);
  472. //create a new zookeeper based on an existing one
  473. newMaster = Ember.Object.create({});
  474. lastMaster = currentMasters.get("lastObject");
  475. newMaster.set("display_name", lastMaster.get("display_name"));
  476. newMaster.set("component_name", lastMaster.get("component_name"));
  477. newMaster.set("selectedHost", lastMaster.get("selectedHost"));
  478. newMaster.set("isInstalled", false);
  479. if (currentMasters.get("length") === (maxNumMasters - 1)) {
  480. newMaster.set("showAddControl", false);
  481. } else {
  482. newMaster.set("showAddControl", true);
  483. }
  484. newMaster.set("showRemoveControl", true);
  485. //get recommended host for the new Zookeeper server
  486. masterHosts = currentMasters.mapProperty("selectedHost").uniq();
  487. for (i = 0; i < this.get("hosts.length"); i++) {
  488. if (!(masterHosts.contains(this.get("hosts")[i].get("host_name")))) {
  489. suggestedHost = this.get("hosts")[i].get("host_name");
  490. break;
  491. }
  492. }
  493. newMaster.set("selectedHost", suggestedHost);
  494. newMaster.set("zId", (currentMasters.get("lastObject.zId") + 1));
  495. this.get("selectedServicesMasters").insertAt(this.get("selectedServicesMasters").indexOf(lastMaster) + 1, newMaster);
  496. this.set('componentToRebalance', componentName);
  497. this.incrementProperty('rebalanceComponentHostsCounter');
  498. return true;
  499. }
  500. return false;//if no more zookeepers can be added
  501. },
  502. /**
  503. * Remove component from ZooKeeper server or Hbase Master
  504. * @param componentName
  505. * @param zId
  506. * @return {Boolean}
  507. */
  508. removeComponent:function (componentName, zId) {
  509. var currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName);
  510. //work only if the Zookeeper service is selected in previous step
  511. if (!currentMasters.length) {
  512. return false;
  513. }
  514. if (currentMasters.get("length") > 1) {
  515. this.get("selectedServicesMasters").removeAt(this.get("selectedServicesMasters").indexOf(currentMasters.findProperty("zId", zId)));
  516. currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName);
  517. if (currentMasters.get("length") < this.get("hosts.length")) {
  518. currentMasters.set("lastObject.showAddControl", true);
  519. }
  520. if (currentMasters.get("length") === 1) {
  521. currentMasters.set("lastObject.showRemoveControl", false);
  522. }
  523. this.set('componentToRebalance', componentName);
  524. this.incrementProperty('rebalanceComponentHostsCounter');
  525. return true;
  526. }
  527. return false;
  528. },
  529. submit: function () {
  530. if (!this.get('isSubmitDisabled')){
  531. App.router.send('next');
  532. }
  533. }
  534. });