step5_controller.js 21 KB

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