host.js 26 KB

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