host.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  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 validator = require('utils/validator');
  20. var componentHelper = require('utils/component');
  21. var batchUtils = require('utils/batch_scheduled_requests');
  22. App.MainHostController = Em.ArrayController.extend({
  23. name: 'mainHostController',
  24. dataSource: App.Host.find(),
  25. clearFilters: null,
  26. filteredCount: 0,
  27. /**
  28. * flag responsible for updating status counters of hosts
  29. */
  30. isCountersUpdating: false,
  31. hostsCountMap: {},
  32. /**
  33. * Components which will be shown in component filter
  34. * @returns {Array}
  35. */
  36. componentsForFilter: function () {
  37. var installedComponents = App.StackServiceComponent.find().toArray();
  38. installedComponents.setEach('checkedForHostFilter', false);
  39. return installedComponents;
  40. }.property('App.router.clusterController.isLoaded'),
  41. /**
  42. * Master components
  43. * @returns {Array}
  44. */
  45. masterComponents: function () {
  46. return this.get('componentsForFilter').filterProperty('isMaster', true);
  47. }.property('componentsForFilter'),
  48. /**
  49. * Slave components
  50. * @returns {Array}
  51. */
  52. slaveComponents: function () {
  53. return this.get('componentsForFilter').filterProperty('isSlave', true);
  54. }.property('componentsForFilter'),
  55. /**
  56. * Client components
  57. * @returns {Array}
  58. */
  59. clientComponents: function () {
  60. return this.get('componentsForFilter').filterProperty('isClient', true);
  61. }.property('componentsForFilter'),
  62. content: function () {
  63. return this.get('dataSource').filterProperty('isRequested');
  64. }.property('dataSource.@each.isRequested'),
  65. filterProperties: [
  66. {
  67. key: 'publicHostName',
  68. alias: 'Hosts/host_name',
  69. type: 'MATCH'
  70. },
  71. {
  72. key: 'ip',
  73. alias: 'Hosts/ip',
  74. type: 'MATCH'
  75. },
  76. {
  77. key: 'cpu',
  78. alias: 'Hosts/cpu_count',
  79. type: 'PLAIN'
  80. },
  81. {
  82. key: 'memoryFormatted',
  83. alias: 'Hosts/total_mem',
  84. type: 'PLAIN'
  85. },
  86. {
  87. key: 'loadAvg',
  88. alias: 'metrics/load/load_one',
  89. type: 'PLAIN'
  90. },
  91. {
  92. key: 'hostComponents',
  93. alias: 'host_components/HostRoles/component_name',
  94. type: 'MULTIPLE'
  95. },
  96. {
  97. key: 'healthClass',
  98. alias: 'Hosts/host_status',
  99. type: 'PLAIN'
  100. },
  101. {
  102. key: 'criticalAlertsCount',
  103. alias: 'alerts/summary/CRITICAL>0|alerts/summary/WARNING>0',
  104. type: 'CRITICAL_ALERTS'
  105. },
  106. {
  107. key: 'componentsWithStaleConfigsCount',
  108. alias: 'host_components/HostRoles/stale_configs',
  109. type: 'PLAIN'
  110. },
  111. {
  112. key: 'componentsInPassiveStateCount',
  113. alias: 'host_components/HostRoles/maintenance_state',
  114. type: 'PLAIN'
  115. },
  116. {
  117. key: 'selected',
  118. alias: 'Hosts/host_name',
  119. type: 'MULTIPLE'
  120. }
  121. ],
  122. viewProperties: [
  123. Em.Object.create({
  124. key: 'displayLength',
  125. getValue: function (controller) {
  126. var name = controller.get('name');
  127. var dbValue = App.db.getDisplayLength(name);
  128. if (Em.isNone(this.get('viewValue'))) {
  129. this.set('viewValue', dbValue || '25'); //25 is default displayLength value for hosts page
  130. }
  131. return this.get('viewValue');
  132. },
  133. viewValue: null,
  134. alias: 'page_size'
  135. }),
  136. Em.Object.create({
  137. key: 'startIndex',
  138. getValue: function (controller) {
  139. var name = controller.get('name');
  140. var startIndex = App.db.getStartIndex(name);
  141. var value = this.get('viewValue');
  142. if (Em.isNone(value)) {
  143. if (Em.isNone(startIndex)) {
  144. value = 0;
  145. } else {
  146. value = startIndex;
  147. }
  148. }
  149. return (value > 0) ? value - 1 : value;
  150. },
  151. viewValue: null,
  152. alias: 'from'
  153. })
  154. ],
  155. sortProps: [
  156. {
  157. key: 'publicHostName',
  158. alias: 'Hosts/host_name'
  159. },
  160. {
  161. key: 'ip',
  162. alias: 'Hosts/ip'
  163. },
  164. {
  165. key: 'cpu',
  166. alias: 'Hosts/cpu_count'
  167. },
  168. {
  169. key: 'memoryFormatted',
  170. alias: 'Hosts/total_mem'
  171. },
  172. {
  173. key: 'diskUsage',
  174. //TODO disk_usage is relative property and need support from API, metrics/disk/disk_free used temporarily
  175. alias: 'metrics/disk/disk_free'
  176. },
  177. {
  178. key: 'loadAvg',
  179. alias: 'metrics/load/load_one'
  180. }
  181. ],
  182. /**
  183. * get query parameters computed from filter properties, sort properties and custom properties of view
  184. * @return {Array}
  185. */
  186. getQueryParameters: function () {
  187. var queryParams = [];
  188. var savedFilterConditions = App.db.getFilterConditions(this.get('name')) || [];
  189. var savedSortConditions = App.db.getSortingStatuses(this.get('name')) || [];
  190. var colPropAssoc = this.get('colPropAssoc');
  191. var filterProperties = this.get('filterProperties');
  192. var sortProperties = this.get('sortProps');
  193. this.get('viewProperties').forEach(function (property) {
  194. queryParams.push({
  195. key: property.get('alias'),
  196. value: property.getValue(this),
  197. type: 'PLAIN'
  198. })
  199. }, this);
  200. savedFilterConditions.forEach(function (filter) {
  201. var property = filterProperties.findProperty('key', colPropAssoc[filter.iColumn]);
  202. if (property && filter.value.length > 0 && !filter.skipFilter) {
  203. var result = {
  204. key: property.alias,
  205. value: filter.value,
  206. type: property.type
  207. };
  208. if (filter.type === 'number' || filter.type === 'ambari-bandwidth') {
  209. result.type = this.getComparisonType(filter.value);
  210. result.value = this.getProperValue(filter.value);
  211. }
  212. if (filter.type === 'ambari-bandwidth') {
  213. result.value = this.convertMemory(filter.value);
  214. }
  215. if (result.value) {
  216. queryParams.push(result);
  217. }
  218. }
  219. }, this);
  220. savedSortConditions.forEach(function (sort) {
  221. var property = sortProperties.findProperty('key', sort.name);
  222. if (property && (sort.status === 'sorting_asc' || sort.status === 'sorting_desc')) {
  223. queryParams.push({
  224. key: property.alias,
  225. value: sort.status.replace('sorting_', ''),
  226. type: 'SORT'
  227. });
  228. }
  229. });
  230. return queryParams;
  231. },
  232. /**
  233. * update status counters of hosts
  234. */
  235. updateStatusCounters: function () {
  236. var self = this;
  237. if (this.get('isCountersUpdating')) {
  238. App.ajax.send({
  239. name: 'host.status.counters',
  240. sender: this,
  241. data: {},
  242. success: 'updateStatusCountersSuccessCallback',
  243. error: 'updateStatusCountersErrorCallback'
  244. });
  245. setTimeout(function () {
  246. self.updateStatusCounters();
  247. }, App.get('componentsUpdateInterval'));
  248. }
  249. },
  250. /**
  251. * success callback on <code>updateStatusCounters()</code>
  252. * map counters' value to categories
  253. * @param data
  254. */
  255. updateStatusCountersSuccessCallback: function (data) {
  256. var hostsCountMap = {
  257. 'HEALTHY': data.Clusters.health_report['Host/host_status/HEALTHY'],
  258. 'UNHEALTHY': data.Clusters.health_report['Host/host_status/UNHEALTHY'],
  259. 'ALERT': data.Clusters.health_report['Host/host_status/ALERT'],
  260. 'UNKNOWN': data.Clusters.health_report['Host/host_status/UNKNOWN'],
  261. 'health-status-WITH-ALERTS': (data.alerts) ? data.alerts.summary.CRITICAL + data.alerts.summary.WARNING : 0,
  262. 'health-status-RESTART': data.Clusters.health_report['Host/stale_config'],
  263. 'health-status-PASSIVE_STATE': data.Clusters.health_report['Host/maintenance_state'],
  264. 'TOTAL': data.Clusters.total_hosts
  265. };
  266. this.set('hostsCountMap', hostsCountMap);
  267. },
  268. /**
  269. * success callback on <code>updateStatusCounters()</code>
  270. */
  271. updateStatusCountersErrorCallback: function() {
  272. console.warn('ERROR: updateStatusCounters failed')
  273. },
  274. /**
  275. * Return value without predicate
  276. * @param {String} value
  277. * @return {String}
  278. */
  279. getProperValue: function (value) {
  280. return (value.charAt(0) === '>' || value.charAt(0) === '<' || value.charAt(0) === '=') ? value.substr(1, value.length) : value;
  281. },
  282. /**
  283. * Return value converted to kilobytes
  284. * @param {String} value
  285. * @return {*}
  286. */
  287. convertMemory: function (value) {
  288. var scale = value.charAt(value.length - 1);
  289. // first char may be predicate for comparison
  290. value = this.getProperValue(value);
  291. var parsedValue = parseFloat(value);
  292. if (isNaN(parsedValue)) {
  293. return value;
  294. }
  295. switch (scale) {
  296. case 'g':
  297. parsedValue *= 1048576;
  298. break;
  299. case 'm':
  300. parsedValue *= 1024;
  301. break;
  302. case 'k':
  303. break;
  304. default:
  305. //default value in GB
  306. parsedValue *= 1048576;
  307. }
  308. return Math.round(parsedValue);
  309. },
  310. /**
  311. * Return comparison type depending on populated predicate
  312. * @param value
  313. * @return {String}
  314. */
  315. getComparisonType: function (value) {
  316. var comparisonChar = value.charAt(0);
  317. var result = 'PLAIN';
  318. if (isNaN(comparisonChar)) {
  319. switch (comparisonChar) {
  320. case '>':
  321. result = 'MORE';
  322. break;
  323. case '<':
  324. result = 'LESS';
  325. break;
  326. }
  327. }
  328. return result;
  329. },
  330. /**
  331. * Filter hosts by componentName of <code>component</code>
  332. * @param {App.HostComponent} component
  333. */
  334. filterByComponent: function (component) {
  335. if (!component)
  336. return;
  337. var id = component.get('componentName');
  338. var column = 6;
  339. this.get('componentsForFilter').setEach('checkedForHostFilter', false);
  340. var filterForComponent = {
  341. iColumn: column,
  342. value: [id],
  343. type: 'multiple'
  344. };
  345. App.db.setFilterConditions(this.get('name'), [filterForComponent]);
  346. },
  347. /**
  348. * On click callback for delete button
  349. */
  350. deleteButtonPopup: function () {
  351. var self = this;
  352. App.showConfirmationPopup(function () {
  353. self.removeHosts();
  354. });
  355. },
  356. showAlertsPopup: function (event) {
  357. var host = event.context;
  358. App.router.get('mainAlertsController').loadAlerts(host.get('hostName'), "HOST");
  359. App.ModalPopup.show({
  360. header: this.t('services.alerts.headingOfList'),
  361. bodyClass: Ember.View.extend({
  362. templateName: require('templates/main/host/alerts_popup'),
  363. controllerBinding: 'App.router.mainAlertsController',
  364. alerts: function () {
  365. return this.get('controller.alerts');
  366. }.property('controller.alerts'),
  367. closePopup: function () {
  368. this.get('parentView').hide();
  369. }
  370. }),
  371. primary: Em.I18n.t('common.close'),
  372. secondary: null,
  373. didInsertElement: function () {
  374. this.$().find('.modal-footer').addClass('align-center');
  375. this.$().children('.modal').css({'margin-top': '-350px'});
  376. }
  377. });
  378. event.stopPropagation();
  379. },
  380. /**
  381. * remove selected hosts
  382. */
  383. removeHosts: function () {
  384. var hosts = this.get('content');
  385. var selectedHosts = hosts.filterProperty('isChecked', true);
  386. selectedHosts.forEach(function (_hostInfo) {
  387. console.log('Removing: ' + _hostInfo.hostName);
  388. });
  389. this.get('fullContent').removeObjects(selectedHosts);
  390. },
  391. /**
  392. * remove hosts with id equal host_id
  393. * @param {String} host_id
  394. */
  395. checkRemoved: function (host_id) {
  396. var hosts = this.get('content');
  397. var selectedHosts = hosts.filterProperty('id', host_id);
  398. this.get('fullContent').removeObjects(selectedHosts);
  399. },
  400. /**
  401. * Bulk operation wrapper
  402. * @param {Object} operationData - data about bulk operation (action, hosts or hostComponents etc)
  403. * @param {Array} hosts - list of affected hosts
  404. */
  405. bulkOperation: function (operationData, hosts) {
  406. if (operationData.componentNameFormatted) {
  407. if (operationData.action === 'RESTART') {
  408. this.bulkOperationForHostComponentsRestart(operationData, hosts);
  409. }
  410. else {
  411. if (operationData.action.indexOf('DECOMMISSION') != -1) {
  412. this.bulkOperationForHostComponentsDecommission(operationData, hosts);
  413. }
  414. else {
  415. this.bulkOperationForHostComponents(operationData, hosts);
  416. }
  417. }
  418. }
  419. else {
  420. if (operationData.action === 'RESTART') {
  421. this.bulkOperationForHostsRestart(operationData, hosts);
  422. }
  423. else {
  424. if (operationData.action === 'PASSIVE_STATE') {
  425. this.bulkOperationForHostsPassiveState(operationData, hosts);
  426. }
  427. else {
  428. this.bulkOperationForHosts(operationData, hosts);
  429. }
  430. }
  431. }
  432. },
  433. /**
  434. * Bulk operation (start/stop all) for selected hosts
  435. * @param {Object} operationData - data about bulk operation (action, hostComponents etc)
  436. * @param {Array} hosts - list of affected hosts
  437. */
  438. bulkOperationForHosts: function (operationData, hosts) {
  439. var self = this;
  440. batchUtils.getComponentsFromServer({
  441. hosts: hosts.mapProperty('hostName'),
  442. workStatus: operationData.actionToCheck,
  443. passiveState: 'OFF',
  444. displayParams: ['host_components/HostRoles/component_name']
  445. }, function (data) {
  446. self.bulkOperationForHostsCallback(operationData, data);
  447. });
  448. },
  449. /**
  450. * run Bulk operation (start/stop all) for selected hosts
  451. * after host and components are loaded
  452. * @param operationData
  453. * @param data
  454. */
  455. bulkOperationForHostsCallback: function (operationData, data) {
  456. var query = [];
  457. var hostNames = [];
  458. var hostsMap = {};
  459. data.items.forEach(function (host) {
  460. host.host_components.forEach(function (hostComponent) {
  461. if (!App.components.get('clients').contains((hostComponent.HostRoles.component_name))) {
  462. if (hostsMap[host.Hosts.host_name]) {
  463. hostsMap[host.Hosts.host_name].push(hostComponent.HostRoles.component_name);
  464. } else {
  465. hostsMap[host.Hosts.host_name] = [hostComponent.HostRoles.component_name];
  466. }
  467. }
  468. });
  469. });
  470. for (var hostName in hostsMap) {
  471. var subQuery = '(HostRoles/component_name.in(%@)&HostRoles/host_name=' + hostName + ')';
  472. var components = hostsMap[hostName];
  473. if (components.length) {
  474. query.push(subQuery.fmt(components.join(',')));
  475. }
  476. hostNames.push(hostName);
  477. }
  478. hostNames = hostNames.join(",");
  479. if (query.length) {
  480. query = query.join('|');
  481. App.ajax.send({
  482. name: 'bulk_request.hosts.all_components',
  483. sender: this,
  484. data: {
  485. query: query,
  486. state: operationData.action,
  487. requestInfo: operationData.message,
  488. hostName: hostNames
  489. },
  490. success: 'bulkOperationForHostComponentsSuccessCallback'
  491. });
  492. }
  493. else {
  494. App.ModalPopup.show({
  495. header: Em.I18n.t('rolling.nothingToDo.header'),
  496. body: Em.I18n.t('rolling.nothingToDo.body').format(Em.I18n.t('hosts.host.maintainance.allComponents.context')),
  497. secondary: false
  498. });
  499. }
  500. },
  501. /**
  502. * Bulk restart for selected hosts
  503. * @param {Object} operationData - data about bulk operation (action, hostComponents etc)
  504. * @param {Ember.Enumerable} hosts - list of affected hosts
  505. */
  506. bulkOperationForHostsRestart: function (operationData, hosts) {
  507. batchUtils.getComponentsFromServer({
  508. passiveState: 'OFF',
  509. hosts: hosts.mapProperty('hostName'),
  510. displayParams: ['host_components/HostRoles/component_name']
  511. }, function (data) {
  512. var hostComponents = [];
  513. data.items.forEach(function (host) {
  514. host.host_components.forEach(function (hostComponent) {
  515. hostComponents.push(Em.Object.create({
  516. componentName: hostComponent.HostRoles.component_name,
  517. hostName: host.Hosts.host_name
  518. }));
  519. })
  520. });
  521. batchUtils.restartHostComponents(hostComponents, Em.I18n.t('rollingrestart.context.allOnSelectedHosts'), "HOST");
  522. });
  523. },
  524. /**
  525. * Bulk turn on/off passive state for selected hosts
  526. * @param {Object} operationData - data about bulk operation (action, hostComponents etc)
  527. * @param {Array} hosts - list of affected hosts
  528. */
  529. bulkOperationForHostsPassiveState: function (operationData, hosts) {
  530. var self = this;
  531. batchUtils.getComponentsFromServer({
  532. displayParams: ['Hosts/maintenance_state']
  533. }, function (data) {
  534. var hostNames = [];
  535. data.items.forEach(function (host) {
  536. if (host.Hosts.maintenance_state !== operationData.state) {
  537. hostNames.push(host.Hosts.host_name);
  538. }
  539. });
  540. if (hostNames.length) {
  541. App.ajax.send({
  542. name: 'bulk_request.hosts.passive_state',
  543. sender: self,
  544. data: {
  545. hostNames: hostNames.join(','),
  546. passive_state: operationData.state,
  547. requestInfo: operationData.message
  548. },
  549. success: 'updateHostPassiveState'
  550. });
  551. } else {
  552. App.ModalPopup.show({
  553. header: Em.I18n.t('rolling.nothingToDo.header'),
  554. body: Em.I18n.t('hosts.bulkOperation.passiveState.nothingToDo.body'),
  555. secondary: false
  556. });
  557. }
  558. });
  559. },
  560. updateHostPassiveState: function (data, opt, params) {
  561. batchUtils.infoPassiveState(params.passive_state);
  562. },
  563. /**
  564. * Bulk operation for selected hostComponents
  565. * @param {Object} operationData - data about bulk operation (action, hostComponents etc)
  566. * @param {Array} hosts - list of affected hosts
  567. */
  568. bulkOperationForHostComponents: function (operationData, hosts) {
  569. var self = this;
  570. batchUtils.getComponentsFromServer({
  571. components: [operationData.componentName],
  572. hosts: hosts.mapProperty('hostName'),
  573. passiveState: 'OFF'
  574. }, function (data) {
  575. if (data.items.length) {
  576. var hostsWithComponentInProperState = data.items.mapProperty('Hosts.host_name');
  577. App.ajax.send({
  578. name: 'bulk_request.host_components',
  579. sender: self,
  580. data: {
  581. hostNames: hostsWithComponentInProperState.join(','),
  582. state: operationData.action,
  583. requestInfo: operationData.message + ' ' + operationData.componentNameFormatted,
  584. componentName: operationData.componentName
  585. },
  586. success: 'bulkOperationForHostComponentsSuccessCallback'
  587. });
  588. }
  589. else {
  590. App.ModalPopup.show({
  591. header: Em.I18n.t('rolling.nothingToDo.header'),
  592. body: Em.I18n.t('rolling.nothingToDo.body').format(operationData.componentNameFormatted),
  593. secondary: false
  594. });
  595. }
  596. });
  597. },
  598. /**
  599. * Bulk decommission/recommission for selected hostComponents
  600. * @param {Object} operationData
  601. * @param {Array} hosts
  602. */
  603. bulkOperationForHostComponentsDecommission: function (operationData, hosts) {
  604. var self = this;
  605. batchUtils.getComponentsFromServer({
  606. components: [operationData.realComponentName],
  607. hosts: hosts.mapProperty('hostName'),
  608. passiveState: 'OFF',
  609. displayParams: ['host_components/HostRoles/state']
  610. }, function (data) {
  611. self.bulkOperationForHostComponentsDecommissionCallBack(operationData, data)
  612. });
  613. },
  614. /**
  615. * run Bulk decommission/recommission for selected hostComponents
  616. * after host and components are loaded
  617. * @param operationData
  618. * @param data
  619. */
  620. bulkOperationForHostComponentsDecommissionCallBack: function (operationData, data) {
  621. var service = App.Service.find(operationData.serviceName);
  622. var components = [];
  623. data.items.forEach(function (host) {
  624. host.host_components.forEach(function (hostComponent) {
  625. components.push(Em.Object.create({
  626. componentName: hostComponent.HostRoles.component_name,
  627. hostName: host.Hosts.host_name,
  628. workStatus: hostComponent.HostRoles.state
  629. }))
  630. });
  631. });
  632. if (components.length) {
  633. var hostsWithComponentInProperState = components.mapProperty('hostName');
  634. var turn_off = operationData.action.indexOf('OFF') !== -1;
  635. var svcName = operationData.serviceName;
  636. var masterName = operationData.componentName;
  637. var slaveName = operationData.realComponentName;
  638. var hostNames = hostsWithComponentInProperState.join(',');
  639. if (turn_off) {
  640. // For recommession
  641. if (svcName === "YARN" || svcName === "HBASE" || svcName === "HDFS") {
  642. App.router.get('mainHostDetailsController').doRecommissionAndStart(hostNames, svcName, masterName, slaveName);
  643. }
  644. else if (svcName === "MAPREDUCE") {
  645. App.router.get('mainHostDetailsController').doRecommissionAndRestart(hostNames, svcName, masterName, slaveName);
  646. }
  647. } else {
  648. hostsWithComponentInProperState = components.filterProperty('workStatus', 'STARTED').mapProperty('hostName');
  649. //For decommession
  650. if (svcName == "HBASE") {
  651. // HBASE service, decommission RegionServer in batch requests
  652. App.router.get('mainHostDetailsController').doDecommissionRegionServer(hostNames, svcName, masterName, slaveName);
  653. } else {
  654. var parameters = {
  655. "slave_type": slaveName
  656. };
  657. var contextString = turn_off ? 'hosts.host.' + slaveName.toLowerCase() + '.recommission' :
  658. 'hosts.host.' + slaveName.toLowerCase() + '.decommission';
  659. if (turn_off) {
  660. parameters['included_hosts'] = hostsWithComponentInProperState.join(',')
  661. }
  662. else {
  663. parameters['excluded_hosts'] = hostsWithComponentInProperState.join(',');
  664. }
  665. App.ajax.send({
  666. name: 'bulk_request.decommission',
  667. sender: this,
  668. data: {
  669. context: Em.I18n.t(contextString),
  670. serviceName: service.get('serviceName'),
  671. componentName: operationData.componentName,
  672. parameters: parameters
  673. },
  674. success: 'bulkOperationForHostComponentsSuccessCallback'
  675. });
  676. }
  677. }
  678. }
  679. else {
  680. App.ModalPopup.show({
  681. header: Em.I18n.t('rolling.nothingToDo.header'),
  682. body: Em.I18n.t('rolling.nothingToDo.body').format(operationData.componentNameFormatted),
  683. secondary: false
  684. });
  685. }
  686. },
  687. /**
  688. * Bulk restart for selected hostComponents
  689. * @param {Object} operationData
  690. * @param {Array} hosts
  691. */
  692. bulkOperationForHostComponentsRestart: function (operationData, hosts) {
  693. var service = App.Service.find(operationData.serviceName);
  694. batchUtils.getComponentsFromServer({
  695. components: [operationData.componentName],
  696. hosts: hosts.mapProperty('hostName'),
  697. passiveState: 'OFF',
  698. displayParams: ['Hosts/maintenance_state', 'host_components/HostRoles/stale_configs', 'host_components/HostRoles/maintenance_state']
  699. }, function (data) {
  700. var wrappedHostComponents = [];
  701. data.items.forEach(function (host) {
  702. host.host_components.forEach(function (hostComponent) {
  703. wrappedHostComponents.push(Em.Object.create({
  704. componentName: hostComponent.HostRoles.component_name,
  705. hostName: host.Hosts.host_name,
  706. hostPassiveState: host.Hosts.maintenance_state,
  707. staleConfigs: hostComponent.HostRoles.stale_configs,
  708. passiveState: hostComponent.HostRoles.maintenance_state
  709. }))
  710. });
  711. });
  712. if (wrappedHostComponents.length) {
  713. batchUtils.showRollingRestartPopup(wrappedHostComponents.objectAt(0).get('componentName'), service.get('displayName'), service.get('passiveState') === "ON", false, wrappedHostComponents);
  714. } else {
  715. App.ModalPopup.show({
  716. header: Em.I18n.t('rolling.nothingToDo.header'),
  717. body: Em.I18n.t('rolling.nothingToDo.body').format(operationData.componentNameFormatted),
  718. secondary: false
  719. });
  720. }
  721. });
  722. },
  723. updateHostComponentsPassiveState: function (data, opt, params) {
  724. batchUtils.infoPassiveState(params.passive_state);
  725. },
  726. /**
  727. * Show BO popup after bulk request
  728. */
  729. bulkOperationForHostComponentsSuccessCallback: function () {
  730. App.router.get('applicationController').dataLoading().done(function (initValue) {
  731. if (initValue) {
  732. App.router.get('backgroundOperationsController').showPopup();
  733. }
  734. });
  735. },
  736. /**
  737. * associations between host property and column index
  738. * @type {Array}
  739. */
  740. colPropAssoc: function () {
  741. var associations = [];
  742. associations[0] = 'healthClass';
  743. associations[1] = 'publicHostName';
  744. associations[2] = 'ip';
  745. associations[3] = 'cpu';
  746. associations[4] = 'memoryFormatted';
  747. associations[5] = 'loadAvg';
  748. associations[6] = 'hostComponents';
  749. associations[7] = 'criticalAlertsCount';
  750. associations[8] = 'componentsWithStaleConfigsCount';
  751. associations[9] = 'componentsInPassiveStateCount';
  752. associations[10] = 'selected';
  753. return associations;
  754. }.property()
  755. });