host.js 25 KB

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