step5_controller.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  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. /**
  23. * Step title
  24. * Custom if <code>App.ReassignMasterController</code> is used
  25. * @type {string}
  26. */
  27. title: function () {
  28. if (this.get('content.controllerName') == 'reassignMasterController') {
  29. return Em.I18n.t('installer.step5.reassign.header');
  30. }
  31. return Em.I18n.t('installer.step5.header');
  32. }.property('content.controllerName'),
  33. /**
  34. * Is ReassignWizard used
  35. * @type {bool}
  36. */
  37. isReassignWizard: function () {
  38. return this.get('content.controllerName') == 'reassignMasterController';
  39. }.property('content.controllerName'),
  40. /**
  41. * Is AddServiceWizard used
  42. * @type {bool}
  43. */
  44. isAddServiceWizard: function () {
  45. return this.get('content.controllerName') == 'addServiceController';
  46. }.property('content.controllerName'),
  47. /**
  48. * Is Hive reassigning
  49. * @type {bool}
  50. */
  51. isReassignHive: function () {
  52. return this.get('servicesMasters').objectAt(0) && this.get('servicesMasters').objectAt(0).component_name == 'HIVE_SERVER' && this.get('isReassignWizard');
  53. }.property('isReassignWizard', 'servicesMasters'),
  54. /**
  55. * Master components which could be assigned to multiple hosts
  56. * @type {string[]}
  57. */
  58. multipleComponents: ['ZOOKEEPER_SERVER', 'HBASE_MASTER'],
  59. /**
  60. * Define state for submit button
  61. * @type {bool}
  62. */
  63. submitDisabled: false,
  64. /**
  65. * Trigger for executing host names check for components
  66. * Should de "triggered" when host changed for some component and when new multiple component is added/removed
  67. * @type {bool}
  68. */
  69. hostNameCheckTrigger: false,
  70. /**
  71. * List of hosts
  72. * @type {Array}
  73. */
  74. hosts: [],
  75. /**
  76. * Name of multiple component which host name was changed last
  77. * @type {Object|null}
  78. */
  79. componentToRebalance: null,
  80. /**
  81. * Name of component which host was changed last
  82. * @type {string}
  83. */
  84. lastChangedComponent: null,
  85. /**
  86. * Flag for rebalance multiple components
  87. * @type {number}
  88. */
  89. rebalanceComponentHostsCounter: 0,
  90. /**
  91. * @type {Ember.Enumerable}
  92. */
  93. servicesMasters: [],
  94. /**
  95. * @type {Ember.Enumerable}
  96. */
  97. selectedServicesMasters: [],
  98. /**
  99. * Is data for current step loaded
  100. * @type {bool}
  101. */
  102. isLoaded: false,
  103. /**
  104. * Check if HIVE_SERVER component exist (also checks if this is not reassign)
  105. * @type {bool}
  106. */
  107. hasHiveServer: function () {
  108. return this.get('selectedServicesMasters').someProperty('component_name', 'HIVE_SERVER') && !this.get('isReassignWizard');
  109. }.property('selectedServicesMasters'),
  110. /**
  111. * List of host with assigned masters
  112. * Format:
  113. * <code>
  114. * [
  115. * {
  116. * host_name: '',
  117. * hostInfo: {},
  118. * masterServices: [],
  119. * masterServicesToDisplay: [] // used only in template
  120. * },
  121. * ....
  122. * ]
  123. * </code>
  124. * @type {Ember.Enumerable}
  125. */
  126. masterHostMapping: function () {
  127. var mapping = [], mappingObject, mappedHosts, hostObj;
  128. //get the unique assigned hosts and find the master services assigned to them
  129. mappedHosts = this.get("selectedServicesMasters").mapProperty("selectedHost").uniq();
  130. mappedHosts.forEach(function (item) {
  131. hostObj = this.get("hosts").findProperty("host_name", item);
  132. // User may input invalid host name (this is handled in hostname checker). Here we just skip it
  133. if (!hostObj) return;
  134. var masterServices = this.get("selectedServicesMasters").filterProperty("selectedHost", item),
  135. masterServicesToDisplay = [];
  136. masterServices.mapProperty('display_name').uniq().forEach(function (n) {
  137. masterServicesToDisplay.pushObject(masterServices.findProperty('display_name', n));
  138. });
  139. mappingObject = Em.Object.create({
  140. host_name: item,
  141. hostInfo: hostObj.host_info,
  142. masterServices: masterServices,
  143. masterServicesToDisplay: masterServicesToDisplay
  144. });
  145. mapping.pushObject(mappingObject);
  146. }, this);
  147. return mapping.sortProperty('host_name');
  148. }.property("selectedServicesMasters.@each.selectedHost", 'selectedServicesMasters.@each.isHostNameValid'),
  149. /**
  150. * Count of hosts without masters
  151. * @type {number}
  152. */
  153. remainingHosts: function () {
  154. if (this.get('content.controllerName') === 'installerController') {
  155. return 0;
  156. } else {
  157. return (this.get("hosts.length") - this.get("masterHostMapping.length"));
  158. }
  159. }.property('masterHostMapping.length', 'selectedServicesMasters.@each.selectedHost'),
  160. /**
  161. * Update submit button status
  162. * @metohd getIsSubmitDisabled
  163. */
  164. getIsSubmitDisabled: function () {
  165. if (!this.get('isReassignWizard')) {
  166. this.set('submitDisabled', this.get('servicesMasters').someProperty('isHostNameValid', false));
  167. }
  168. else {
  169. App.ajax.send({
  170. name: 'host_components.all',
  171. sender: this,
  172. data: {
  173. clusterName: App.get('clusterName')
  174. },
  175. success: 'getIsSubmitDisabledSuccessCallBack'
  176. });
  177. }
  178. }.observes('servicesMasters.@each.selectedHost', 'servicesMasters.@each.isHostNameValid'),
  179. /**
  180. * Success callback for getIsSubmitDisabled method
  181. * Set true for Reassign Master Wizard and if more than one master component was reassigned.
  182. * For installer, addHost and addService verify that provided host names for components are valid
  183. * @param {object} response
  184. * @method getIsSubmitDisabledSuccessCallBack
  185. */
  186. getIsSubmitDisabledSuccessCallBack: function (response) {
  187. var reassigned = 0;
  188. var arr1 = response.items.mapProperty('HostRoles').filterProperty('component_name', this.get('content.reassign.component_name')).mapProperty('host_name');
  189. var arr2 = this.get('servicesMasters').mapProperty('selectedHost');
  190. arr1.forEach(function (host) {
  191. if (!arr2.contains(host)) {
  192. reassigned++;
  193. }
  194. }, this);
  195. this.set('submitDisabled', reassigned !== 1);
  196. },
  197. /**
  198. * Clear controller data (hosts, masters etc)
  199. * @method clearStep
  200. */
  201. clearStep: function () {
  202. this.set('hosts', []);
  203. this.set('selectedServicesMasters', []);
  204. this.set('servicesMasters', []);
  205. },
  206. /**
  207. * Load controller data (hosts, host components etc)
  208. * @method loadStep
  209. */
  210. loadStep: function () {
  211. console.log("WizardStep5Controller: Loading step5: Assign Masters");
  212. this.clearStep();
  213. this.renderHostInfo();
  214. this.renderComponents(this.loadComponents());
  215. this.updateComponent('ZOOKEEPER_SERVER');
  216. if (App.supports.multipleHBaseMasters) {
  217. this.updateComponent('HBASE_MASTER');
  218. }
  219. if (!this.get("selectedServicesMasters").filterProperty('isInstalled', false).length) {
  220. console.log('no master components to add');
  221. App.router.send('next');
  222. }
  223. },
  224. /**
  225. * Used to set showAddControl flag for ZOOKEEPER_SERVER and HBASE_SERVER
  226. * @method updateComponent
  227. */
  228. updateComponent: function (componentName) {
  229. var component = this.last(componentName);
  230. if (!component) {
  231. return;
  232. }
  233. var services = this.get('content.services').filterProperty('isInstalled', true).mapProperty('serviceName');
  234. var currentService = componentName.split('_')[0];
  235. var showControl = !services.contains(currentService);
  236. if (showControl) {
  237. if (this.get("selectedServicesMasters").filterProperty("component_name", componentName).length < this.get("hosts.length") && !this.get('isReassignWizard')) {
  238. component.set('showAddControl', true);
  239. } else {
  240. component.set('showRemoveControl', false);
  241. }
  242. }
  243. },
  244. /**
  245. * Load active host list to <code>hosts</code> variable
  246. * @method renderHostInfo
  247. */
  248. renderHostInfo: function () {
  249. var hostInfo = this.get('content.hosts');
  250. var result = [];
  251. for (var index in hostInfo) {
  252. var _host = hostInfo[index];
  253. if (_host.bootStatus === 'REGISTERED') {
  254. result.push(Em.Object.create({
  255. host_name: _host.name,
  256. cpu: _host.cpu,
  257. memory: _host.memory,
  258. disk_info: _host.disk_info,
  259. host_info: Em.I18n.t('installer.step5.hostInfo').fmt(_host.name, numberUtils.bytesToSize(_host.memory, 1, 'parseFloat', 1024), _host.cpu)
  260. }));
  261. }
  262. }
  263. this.set("hosts", result);
  264. this.sortHosts(this.get('hosts'));
  265. this.set('isLoaded', true);
  266. },
  267. /**
  268. * Sort list of host-objects by properties (memory - desc, cpu - desc, hostname - asc)
  269. * @param {object[]} hosts
  270. */
  271. sortHosts: function (hosts) {
  272. hosts.sort(function (a, b) {
  273. if (a.get('memory') == b.get('memory')) {
  274. if (a.get('cpu') == b.get('cpu')) {
  275. return a.get('host_name').localeCompare(b.get('host_name')); // hostname asc
  276. }
  277. return b.get('cpu') - a.get('cpu'); // cores desc
  278. }
  279. return b.get('memory') - a.get('memory'); // ram desc
  280. });
  281. },
  282. /**
  283. * Load services info to appropriate variable and return masterComponentHosts
  284. * @return {Object[]}
  285. */
  286. loadComponents: function () {
  287. var services = this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName'); //list of shown services
  288. var selectedServices = this.get('content.services').filterProperty('isSelected').filterProperty('isInstalled', false).mapProperty('serviceName');
  289. var masterComponents = App.StackServiceComponent.find().filterProperty('isShownOnInstallerAssignMasterPage', true); //get full list from mock data
  290. var masterHosts = this.get('content.masterComponentHosts'); //saved to local storage info
  291. var resultComponents = [];
  292. for (var index = 0; index < services.length; index++) {
  293. var componentInfo = masterComponents.filterProperty('serviceName', services[index]);
  294. // If service is already installed and not being added as a new service then render on UI only those master components
  295. // that have already installed hostComponents.
  296. // NOTE: On upgrade there might be a prior installed service with non-installed newly introduced serviceComponent
  297. var isNotSelectedService = !selectedServices.contains(services[index]);
  298. if (isNotSelectedService) {
  299. componentInfo = componentInfo.filter(function (_component) {
  300. return App.HostComponent.find().someProperty('componentName',_component.get('componentName'));
  301. });
  302. }
  303. componentInfo.forEach(function (_componentInfo) {
  304. if (_componentInfo.get('componentName') == 'ZOOKEEPER_SERVER' || _componentInfo.get('componentName') == 'HBASE_MASTER') {
  305. var savedComponents = masterHosts.filterProperty('component', _componentInfo.get('componentName'));
  306. if (savedComponents.length) {
  307. savedComponents.forEach(function (item) {
  308. var multipleMasterHost = {};
  309. multipleMasterHost.display_name = _componentInfo.get('displayName');
  310. multipleMasterHost.component_name = _componentInfo.get('componentName');
  311. multipleMasterHost.selectedHost = item.hostName;
  312. multipleMasterHost.serviceId = services[index];
  313. multipleMasterHost.isInstalled = item.isInstalled;
  314. multipleMasterHost.isHiveCoHost = false;
  315. resultComponents.push(multipleMasterHost);
  316. })
  317. } else {
  318. var zooHosts = this.selectHost(_componentInfo.get('componentName'));
  319. zooHosts.forEach(function (_host) {
  320. var multipleMasterHost = {};
  321. multipleMasterHost.display_name = _componentInfo.get('displayName');
  322. multipleMasterHost.component_name = _componentInfo.get('componentName');
  323. multipleMasterHost.selectedHost = _host;
  324. multipleMasterHost.serviceId = services[index];
  325. multipleMasterHost.isInstalled = false;
  326. multipleMasterHost.isHiveCoHost = false;
  327. resultComponents.push(multipleMasterHost);
  328. });
  329. }
  330. } else {
  331. var savedComponent = masterHosts.findProperty('component', _componentInfo.get('componentName'));
  332. var componentObj = {};
  333. componentObj.component_name = _componentInfo.get('componentName');
  334. componentObj.display_name = _componentInfo.get('displayName');
  335. componentObj.selectedHost = savedComponent ? savedComponent.hostName : this.selectHost(_componentInfo.get('componentName')); // call the method that plays selectNode algorithm or fetches from server
  336. componentObj.isInstalled = savedComponent ? savedComponent.isInstalled : false;
  337. componentObj.serviceId = services[index];
  338. componentObj.isHiveCoHost = this._isHiveCoHost(_componentInfo.get('componentName'));
  339. resultComponents.push(componentObj);
  340. }
  341. }, this);
  342. }
  343. return resultComponents;
  344. },
  345. /**
  346. * @param {string} componentName
  347. * @returns {bool}
  348. * @private
  349. * @method _isHiveCoHost
  350. */
  351. _isHiveCoHost: function (componentName) {
  352. return ['HIVE_METASTORE', 'WEBHCAT_SERVER'].contains(componentName) && !this.get('isReassignWizard');
  353. },
  354. /**
  355. * Put master components to <code>selectedServicesMasters</code>, which will be automatically rendered in template
  356. * @param {Ember.Enumerable} masterComponents
  357. * @method renderComponents
  358. */
  359. renderComponents: function (masterComponents) {
  360. var services = this.get('content.services').filterProperty('isInstalled', true).mapProperty('serviceName'); //list of shown services
  361. var showRemoveControlZk = !services.contains('ZOOKEEPER') && masterComponents.filterProperty('component_name', 'ZOOKEEPER_SERVER').length > 1;
  362. var showRemoveControlHb = !services.contains('HBASE') && masterComponents.filterProperty('component_name', 'HBASE_MASTER').length > 1;
  363. var zid = 1, hid = 1, nid = 1, result = [], self = this;
  364. masterComponents.forEach(function (item) {
  365. if (item.component_name == 'SECONDARY_NAMENODE') {
  366. if (self.get('isAddServiceWizard')) {
  367. if (App.get('isHaEnabled')) {
  368. return;
  369. }
  370. }
  371. }
  372. var componentObj = Em.Object.create(item);
  373. console.log("TRACE: render master component name is: " + item.component_name);
  374. if (item.component_name === "ZOOKEEPER_SERVER") {
  375. componentObj.set('zId', zid++);
  376. componentObj.set("showRemoveControl", showRemoveControlZk);
  377. }
  378. else {
  379. if (App.get('supports.multipleHBaseMasters') && item.component_name === "HBASE_MASTER") {
  380. componentObj.set('zId', hid++);
  381. componentObj.set("showRemoveControl", showRemoveControlHb);
  382. }
  383. else {
  384. if (item.component_name === "NAMENODE") {
  385. componentObj.set('zId', nid++);
  386. }
  387. }
  388. }
  389. componentObj.set('isHostNameValid', true);
  390. result.push(componentObj);
  391. }, this);
  392. this.set("selectedServicesMasters", result);
  393. if (this.get('isReassignWizard')) {
  394. var components = result.filterProperty('component_name', this.get('content.reassign.component_name'));
  395. components.setEach('isInstalled', false);
  396. this.set('servicesMasters', components);
  397. }
  398. else {
  399. this.set('servicesMasters', result);
  400. }
  401. },
  402. /**
  403. * Update host for components HIVE_METASTORE and WEBHCAT_SERVER according to host with HIVE_SERVER
  404. * @method updateHiveCoHosts
  405. */
  406. updateHiveCoHosts: function () {
  407. var hiveServer = this.get('selectedServicesMasters').findProperty('component_name', 'HIVE_SERVER'),
  408. hiveMetastore = this.get('selectedServicesMasters').findProperty('component_name', 'HIVE_METASTORE'),
  409. webHCatServer = this.get('selectedServicesMasters').findProperty('component_name', 'WEBHCAT_SERVER');
  410. if (hiveServer && hiveMetastore && webHCatServer) {
  411. if (!this.get('isReassignHive') && this.get('servicesMasters').objectAt(0) && !(this.get('servicesMasters').objectAt(0).component_name == 'HIVE_METASTORE')) {
  412. hiveMetastore.set('selectedHost', hiveServer.get('selectedHost'))
  413. }
  414. webHCatServer.set('selectedHost', hiveServer.get('selectedHost'));
  415. }
  416. }.observes('selectedServicesMasters.@each.selectedHost'),
  417. /**
  418. * select and return host for component by scheme
  419. * Scheme is an object that has keys which compared to number of hosts,
  420. * if key more that number of hosts, then return value of that key.
  421. * Value is index of host in hosts array.
  422. *
  423. * @param {number} noOfHosts
  424. * @param {object} selectionScheme
  425. * @return {string}
  426. * @method getHostForComponent
  427. */
  428. getHostForComponent: function (noOfHosts, selectionScheme) {
  429. var hosts = this.get('hosts');
  430. if (hosts.length === 1 || $.isEmptyObject(selectionScheme)) {
  431. return hosts[0];
  432. } else {
  433. for (var i in selectionScheme) {
  434. if (window.isFinite(i)) {
  435. if (noOfHosts < window.parseInt(i)) {
  436. return hosts[selectionScheme[i]];
  437. }
  438. }
  439. }
  440. return hosts[selectionScheme['else']]
  441. }
  442. },
  443. /**
  444. * Get list of hostnames for ZK Server
  445. * @param {number} noOfHosts
  446. * @returns {string[]}
  447. * @method getZooKeeperServer
  448. */
  449. getZooKeeperServer: function (noOfHosts) {
  450. var hosts = this.get('hosts');
  451. if (noOfHosts < 3) {
  452. return [hosts[0].host_name];
  453. } else {
  454. return [hosts[0].host_name, hosts[1].host_name, hosts[2].host_name];
  455. }
  456. },
  457. /**
  458. * Get hostname based on number of available hosts
  459. * @param {number} noOfHosts
  460. * @returns {string}
  461. * @method getServerHost
  462. */
  463. getServerHost: function (noOfHosts) {
  464. var hostNames = this.get('hosts').mapProperty('host_name');
  465. var hostExcAmbari = hostNames.without(location.hostname);
  466. if (noOfHosts > 1) {
  467. return hostExcAmbari[0];
  468. } else {
  469. return hostNames[0];
  470. }
  471. },
  472. /**
  473. * Return hostName of masterNode for specified service
  474. * @param componentName
  475. * @return {string|string[]}
  476. * @method selectHost
  477. */
  478. selectHost: function (componentName) {
  479. var noOfHosts = this.get('hosts').length;
  480. if (componentName === 'KERBEROS_SERVER')
  481. return this.getHostForComponent(noOfHosts, {"3": 1, "6": 1, "31": 3, "else": 5}).host_name;
  482. if (componentName === 'NAMENODE')
  483. return this.getHostForComponent(noOfHosts, {"else": 0}).host_name;
  484. if (componentName === 'SECONDARY_NAMENODE')
  485. return this.getHostForComponent(noOfHosts, {"else": 1}).host_name;
  486. if (componentName === 'HBASE_MASTER')
  487. return [this.getHostForComponent(noOfHosts, {"3": 0, "6": 0, "31": 2, "else": 3}).host_name];
  488. if (componentName === 'ZOOKEEPER_SERVER')
  489. return this.getZooKeeperServer(noOfHosts);
  490. if (['JOBTRACKER', 'HISTORYSERVER', 'RESOURCEMANAGER', 'APP_TIMELINE_SERVER'].contains(componentName))
  491. return this.getHostForComponent(noOfHosts, {"3": 1, "6": 1, "31": 1, "else": 2}).host_name;
  492. if (['OOZIE_SERVER', 'FALCON_SERVER'].contains(componentName))
  493. return this.getHostForComponent(noOfHosts, {"3": 1, "6": 1, "31": 2, "else": 3}).host_name;
  494. if (['HIVE_SERVER', 'HIVE_METASTORE', 'WEBHCAT_SERVER'].contains(componentName))
  495. return this.getHostForComponent(noOfHosts, {"3": 1, "6": 1, "31": 2, "else": 4}).host_name;
  496. if (['STORM_UI_SERVER', 'DRPC_SERVER', 'STORM_REST_API', 'NIMBUS', 'GANGLIA_SERVER', 'NAGIOS_SERVER', 'HUE_SERVER'].contains(componentName))
  497. return this.getServerHost(noOfHosts);
  498. return '';
  499. },
  500. /**
  501. * On change callback for inputs
  502. * @param {string} componentName
  503. * @param {string} selectedHost
  504. * @param {number} zId
  505. * @method assignHostToMaster
  506. */
  507. assignHostToMaster: function (componentName, selectedHost, zId) {
  508. var flag = this.isHostNameValid(componentName, selectedHost);
  509. this.updateIsHostNameValidFlag(componentName, zId, flag);
  510. if (zId) {
  511. this.get('selectedServicesMasters').filterProperty('component_name', componentName).findProperty("zId", zId).set("selectedHost", selectedHost);
  512. }
  513. else {
  514. this.get('selectedServicesMasters').findProperty("component_name", componentName).set("selectedHost", selectedHost);
  515. }
  516. },
  517. /**
  518. * Determines if hostName is valid for component:
  519. * <ul>
  520. * <li>host name shouldn't be empty</li>
  521. * <li>host should exist</li>
  522. * <li>host should have only one component with <code>componentName</code></li>
  523. * </ul>
  524. * @param {string} componentName
  525. * @param {string} selectedHost
  526. * @returns {boolean} true - valid, false - invalid
  527. * @method isHostNameValid
  528. */
  529. isHostNameValid: function (componentName, selectedHost) {
  530. return (selectedHost.trim() !== '') &&
  531. this.get('hosts').mapProperty('host_name').contains(selectedHost) &&
  532. (this.get('selectedServicesMasters').
  533. filterProperty('component_name', componentName).
  534. mapProperty('selectedHost').
  535. filter(function (h) {
  536. return h === selectedHost;
  537. }).length <= 1);
  538. },
  539. /**
  540. * Update <code>isHostNameValid</code> property with <code>flag</code> value
  541. * for component with name <code>componentName</code> and
  542. * <code>zId</code>-property equal to <code>zId</code>-parameter value
  543. * @param {string} componentName
  544. * @param {number} zId
  545. * @param {bool} flag
  546. * @method updateIsHostNameValidFlag
  547. */
  548. updateIsHostNameValidFlag: function (componentName, zId, flag) {
  549. if (componentName) {
  550. if (zId) {
  551. this.get('selectedServicesMasters').filterProperty('component_name', componentName).findProperty("zId", zId).set("isHostNameValid", flag);
  552. } else {
  553. this.get('selectedServicesMasters').findProperty("component_name", componentName).set("isHostNameValid", flag);
  554. }
  555. }
  556. },
  557. /**
  558. * Returns last component of selected type
  559. * @param {string} componentName
  560. * @return {Em.Object|null}
  561. * @method last
  562. */
  563. last: function (componentName) {
  564. return this.get("selectedServicesMasters").filterProperty("component_name", componentName).get("lastObject");
  565. },
  566. /**
  567. * Add new component to ZooKeeper Server and Hbase master
  568. * @param {string} componentName
  569. * @return {bool} true - added, false - not added
  570. * @method addComponent
  571. */
  572. addComponent: function (componentName) {
  573. /*
  574. * Logic: If ZooKeeper or Hbase service is selected then there can be
  575. * minimum 1 ZooKeeper or Hbase master in total, and
  576. * maximum 1 ZooKeeper or Hbase on every host
  577. */
  578. var maxNumMasters = this.get("hosts.length"),
  579. currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName),
  580. newMaster = null,
  581. masterHosts = null,
  582. suggestedHost = null,
  583. i = 0,
  584. lastMaster = null;
  585. if (!currentMasters.length) {
  586. console.log('ALERT: Zookeeper service was not selected');
  587. return false;
  588. }
  589. if (currentMasters.get("length") < maxNumMasters) {
  590. currentMasters.set("lastObject.showAddControl", false);
  591. currentMasters.set("lastObject.showRemoveControl", true);
  592. //create a new zookeeper based on an existing one
  593. newMaster = Em.Object.create({});
  594. lastMaster = currentMasters.get("lastObject");
  595. newMaster.set("display_name", lastMaster.get("display_name"));
  596. newMaster.set("component_name", lastMaster.get("component_name"));
  597. newMaster.set("selectedHost", lastMaster.get("selectedHost"));
  598. newMaster.set("isInstalled", false);
  599. if (currentMasters.get("length") === (maxNumMasters - 1)) {
  600. newMaster.set("showAddControl", false);
  601. } else {
  602. newMaster.set("showAddControl", true);
  603. }
  604. newMaster.set("showRemoveControl", true);
  605. //get recommended host for the new Zookeeper server
  606. masterHosts = currentMasters.mapProperty("selectedHost").uniq();
  607. for (i = 0; i < this.get("hosts.length"); i++) {
  608. if (!(masterHosts.contains(this.get("hosts")[i].get("host_name")))) {
  609. suggestedHost = this.get("hosts")[i].get("host_name");
  610. break;
  611. }
  612. }
  613. newMaster.set("selectedHost", suggestedHost);
  614. newMaster.set("zId", (currentMasters.get("lastObject.zId") + 1));
  615. this.get("selectedServicesMasters").insertAt(this.get("selectedServicesMasters").indexOf(lastMaster) + 1, newMaster);
  616. this.set('componentToRebalance', componentName);
  617. this.incrementProperty('rebalanceComponentHostsCounter');
  618. this.toggleProperty('hostNameCheckTrigger');
  619. return true;
  620. }
  621. return false;//if no more zookeepers can be added
  622. },
  623. /**
  624. * Remove component from ZooKeeper server or Hbase Master
  625. * @param {string} componentName
  626. * @param {number} zId
  627. * @return {bool} true - removed, false - no
  628. * @method removeComponent
  629. */
  630. removeComponent: function (componentName, zId) {
  631. var currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName);
  632. //work only if the Zookeeper service is selected in previous step
  633. if (currentMasters.length <= 1) {
  634. return false;
  635. }
  636. this.get("selectedServicesMasters").removeAt(this.get("selectedServicesMasters").indexOf(currentMasters.findProperty("zId", zId)));
  637. currentMasters = this.get("selectedServicesMasters").filterProperty("component_name", componentName);
  638. if (currentMasters.get("length") < this.get("hosts.length")) {
  639. currentMasters.set("lastObject.showAddControl", true);
  640. }
  641. if (currentMasters.get("length") === 1) {
  642. currentMasters.set("lastObject.showRemoveControl", false);
  643. }
  644. this.set('componentToRebalance', componentName);
  645. this.incrementProperty('rebalanceComponentHostsCounter');
  646. this.toggleProperty('hostNameCheckTrigger');
  647. return true;
  648. },
  649. /**
  650. * Submit button click handler
  651. * @metohd submit
  652. */
  653. submit: function () {
  654. this.getIsSubmitDisabled();
  655. if (!this.get('submitDisabled')) {
  656. App.router.send('next');
  657. }
  658. }
  659. });