step5_controller.js 21 KB

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