host.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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. content: App.Host.find(),
  25. clearFilters: null,
  26. /**
  27. * Components which will be shown in component filter
  28. * @returns {Array}
  29. */
  30. componentsForFilter:function() {
  31. var installedComponents = componentHelper.getInstalledComponents();
  32. installedComponents.setEach('checkedForHostFilter', false);
  33. return installedComponents;
  34. }.property('App.router.clusterController.isLoaded'),
  35. /**
  36. * Master components
  37. * @returns {Array}
  38. */
  39. masterComponents:function () {
  40. return this.get('componentsForFilter').filterProperty('isMaster', true);
  41. }.property('componentsForFilter'),
  42. /**
  43. * Slave components
  44. * @returns {Array}
  45. */
  46. slaveComponents:function () {
  47. return this.get('componentsForFilter').filterProperty('isSlave', true);
  48. }.property('componentsForFilter'),
  49. /**
  50. * Client components
  51. * @returns {Array}
  52. */
  53. clientComponents: function() {
  54. return this.get('componentsForFilter').filterProperty('isClient', true);
  55. }.property('componentsForFilter'),
  56. /**
  57. * Filter hosts by componentName of <code>component</code>
  58. * @param {App.HostComponent} component
  59. */
  60. filterByComponent:function (component) {
  61. if(!component)
  62. return;
  63. var id = component.get('componentName');
  64. var column = 6;
  65. this.get('componentsForFilter').setEach('checkedForHostFilter', false);
  66. var filterForComponent = {
  67. iColumn: column,
  68. value: id,
  69. type: 'multiple'
  70. };
  71. App.db.setFilterConditions(this.get('name'), [filterForComponent]);
  72. },
  73. /**
  74. * On click callback for delete button
  75. */
  76. deleteButtonPopup:function () {
  77. var self = this;
  78. App.showConfirmationPopup(function(){
  79. self.removeHosts();
  80. });
  81. },
  82. showAlertsPopup: function (event) {
  83. var host = event.context;
  84. App.router.get('mainAlertsController').loadAlerts(host.get('hostName'), "HOST");
  85. App.ModalPopup.show({
  86. header: this.t('services.alerts.headingOfList'),
  87. bodyClass: Ember.View.extend({
  88. templateName: require('templates/main/host/alerts_popup'),
  89. controllerBinding: 'App.router.mainAlertsController',
  90. alerts: function () {
  91. return this.get('controller.alerts');
  92. }.property('controller.alerts'),
  93. closePopup: function () {
  94. this.get('parentView').hide();
  95. }
  96. }),
  97. primary: Em.I18n.t('common.close'),
  98. secondary : null,
  99. didInsertElement: function () {
  100. this.$().find('.modal-footer').addClass('align-center');
  101. this.$().children('.modal').css({'margin-top': '-350px'});
  102. }
  103. });
  104. event.stopPropagation();
  105. },
  106. /**
  107. * remove selected hosts
  108. */
  109. removeHosts:function () {
  110. var hosts = this.get('content');
  111. var selectedHosts = hosts.filterProperty('isChecked', true);
  112. selectedHosts.forEach(function (_hostInfo) {
  113. console.log('Removing: ' + _hostInfo.hostName);
  114. });
  115. this.get('fullContent').removeObjects(selectedHosts);
  116. },
  117. /**
  118. * remove hosts with id equal host_id
  119. * @param {String} host_id
  120. */
  121. checkRemoved:function (host_id) {
  122. var hosts = this.get('content');
  123. var selectedHosts = hosts.filterProperty('id', host_id);
  124. this.get('fullContent').removeObjects(selectedHosts);
  125. },
  126. /**
  127. * Bulk operation wrapper
  128. * @param {Object} operationData - data about bulk operation (action, hosts or hostComponents etc)
  129. * @param {Array} hosts - list of affected hosts
  130. */
  131. bulkOperation: function(operationData, hosts) {
  132. if (operationData.componentNameFormatted) {
  133. if (operationData.action === 'RESTART') {
  134. this.bulkOperationForHostComponentsRestart(operationData, hosts);
  135. }
  136. else {
  137. if (operationData.action === 'PASSIVE_STATE') {
  138. this.bulkOperationForHostComponentsPassiveState(operationData, hosts);
  139. }
  140. else {
  141. if (operationData.action.indexOf('DECOMMISSION') != -1) {
  142. this.bulkOperationForHostComponentsDecommission(operationData, hosts);
  143. }
  144. else {
  145. this.bulkOperationForHostComponents(operationData, hosts);
  146. }
  147. }
  148. }
  149. }
  150. else {
  151. if (operationData.action === 'RESTART') {
  152. this.bulkOperationForHostsRestart(operationData, hosts);
  153. }
  154. else {
  155. if (operationData.action === 'PASSIVE_STATE') {
  156. this.bulkOperationForHostsPassiveState(operationData, hosts);
  157. }
  158. else {
  159. this.bulkOperationForHosts(operationData, hosts);
  160. }
  161. }
  162. }
  163. },
  164. /**
  165. * Bulk operation (start/stop all) for selected hosts
  166. * @param {Object} operationData - data about bulk operation (action, hostComponents etc)
  167. * @param {Array} hosts - list of affected hosts
  168. */
  169. bulkOperationForHosts: function(operationData, hosts) {
  170. var query = [];
  171. hosts.forEach(function(host) {
  172. var subQuery = '(HostRoles/component_name.in(%@)&HostRoles/host_name=' + host.get('hostName') + ')';
  173. var components = [];
  174. host.get('hostComponents').forEach(function(hostComponent) {
  175. if (hostComponent.get('passiveState') == 'OFF') {
  176. if (hostComponent.get('isMaster') || hostComponent.get('isSlave')) {
  177. if (hostComponent.get('workStatus') === operationData.actionToCheck) {
  178. components.push(hostComponent.get('componentName'));
  179. }
  180. }
  181. }
  182. });
  183. if (components.length) {
  184. query.push(subQuery.fmt(components.join(',')));
  185. }
  186. });
  187. if (query.length) {
  188. query = query.join('|');
  189. App.ajax.send({
  190. name: 'bulk_request.hosts.all_components',
  191. sender: this,
  192. data: {
  193. query: query,
  194. state: operationData.action,
  195. requestInfo: operationData.message
  196. },
  197. success: 'bulkOperationForHostComponentsSuccessCallback'
  198. });
  199. }
  200. else {
  201. App.ModalPopup.show({
  202. header: Em.I18n.t('rolling.nothingToDo.header'),
  203. body: Em.I18n.t('rolling.nothingToDo.body').format(Em.I18n.t('hosts.host.maintainance.allComponents.context')),
  204. secondary: false
  205. });
  206. }
  207. },
  208. /**
  209. * Bulk restart for selected hosts
  210. * @param {Object} operationData - data about bulk operation (action, hostComponents etc)
  211. * @param {Array} hosts - list of affected hosts
  212. */
  213. bulkOperationForHostsRestart: function(operationData, hosts) {
  214. var hostComponents = [];
  215. hosts.forEach(function(host) {
  216. hostComponents.pushObjects(host.get('hostComponents').filterProperty('passiveState','OFF').toArray());
  217. });
  218. batchUtils.restartHostComponents(hostComponents);
  219. },
  220. /**
  221. * Bulk turn on/off passive state for selected hosts
  222. * @param {Object} operationData - data about bulk operation (action, hostComponents etc)
  223. * @param {Array} hosts - list of affected hosts
  224. */
  225. bulkOperationForHostsPassiveState: function(operationData, hosts) {
  226. var affectedHosts = [];
  227. hosts.forEach(function(host) {
  228. if (host.get('passiveState') !== operationData.state) {
  229. affectedHosts.push(host);
  230. }
  231. });
  232. if (affectedHosts.length) {
  233. App.ajax.send({
  234. name: 'bulk_request.hosts.passive_state',
  235. sender: this,
  236. data: {
  237. hosts: affectedHosts,
  238. hostNames: affectedHosts.mapProperty('hostName').join(','),
  239. passive_state: operationData.state,
  240. requestInfo: operationData.message
  241. },
  242. success: 'updateHostPassiveState'
  243. });
  244. }
  245. else {
  246. App.ModalPopup.show({
  247. header: Em.I18n.t('rolling.nothingToDo.header'),
  248. body: Em.I18n.t('hosts.bulkOperation.passiveState.nothingToDo.body'),
  249. secondary: false
  250. });
  251. }
  252. },
  253. updateHostPassiveState: function(data, opt, params) {
  254. params.hosts.setEach('passiveState', params.passive_state);
  255. App.router.get('clusterController').loadUpdatedStatus(function(){});
  256. },
  257. /**
  258. * Bulk operation for selected hostComponents
  259. * @param {Object} operationData - data about bulk operation (action, hostComponents etc)
  260. * @param {Array} hosts - list of affected hosts
  261. */
  262. bulkOperationForHostComponents: function(operationData, hosts) {
  263. var service = App.Service.find(operationData.serviceName);
  264. var components = service.get('hostComponents').filter(function(hc) {
  265. if (hc.get('componentName') != operationData.componentName || hc.get('passiveState') != 'OFF' ) {
  266. return false;
  267. }
  268. if(hc.get('workStatus') == operationData.action) {
  269. return false;
  270. }
  271. return hosts.contains(hc.get('host'));
  272. });
  273. if (components.length) {
  274. var hostsWithComponentInProperState = components.mapProperty('host.hostName');
  275. App.ajax.send({
  276. name: 'bulk_request.host_components',
  277. sender: this,
  278. data: {
  279. hostNames: hostsWithComponentInProperState.join(','),
  280. state: operationData.action,
  281. requestInfo: operationData.message + ' ' + operationData.componentNameFormatted,
  282. componentName: operationData.componentName
  283. },
  284. success: 'bulkOperationForHostComponentsSuccessCallback'
  285. });
  286. }
  287. else {
  288. App.ModalPopup.show({
  289. header: Em.I18n.t('rolling.nothingToDo.header'),
  290. body: Em.I18n.t('rolling.nothingToDo.body').format(operationData.componentNameFormatted),
  291. secondary: false
  292. });
  293. }
  294. },
  295. /**
  296. * Bulk decommission for selected hostComponents
  297. * @param {Object} operationData
  298. * @param {Array} hosts
  299. */
  300. bulkOperationForHostComponentsDecommission: function(operationData, hosts) {
  301. var service = App.Service.find(operationData.serviceName);
  302. var components = service.get('hostComponents').filter(function(hc) {
  303. if (hc.get('componentName') != operationData.realComponentName || hc.get('passiveState') != 'OFF' ) {
  304. return false;
  305. }
  306. return hosts.contains(hc.get('host'));
  307. });
  308. if (components.length) {
  309. var hostsWithComponentInProperState = components.mapProperty('host.hostName');
  310. var turn_off = operationData.action.indexOf('OFF') !== -1;
  311. var parameters = {
  312. "slave_type": operationData.realComponentName
  313. };
  314. var contextString = turn_off? 'hosts.host.' + operationData.realComponentName.toLowerCase() + '.recommission':
  315. 'hosts.host.' + operationData.realComponentName.toLowerCase() + '.decommission';
  316. if (turn_off) {
  317. parameters['included_hosts'] = hostsWithComponentInProperState.join(',')
  318. }
  319. else {
  320. parameters['excluded_hosts'] = hostsWithComponentInProperState.join(',');
  321. }
  322. // HBASE service, decommission RegionServer in batch requests
  323. if (operationData.serviceName == "HBASE") {
  324. var hostNames = hostsWithComponentInProperState.join(',');
  325. App.router.get('mainHostDetailsController').doDecommissionRegionServer(hostNames, operationData.serviceName, "HBASE_MASTER", operationData.realComponentName);
  326. } else {
  327. App.ajax.send({
  328. name: 'bulk_request.decommission',
  329. sender: this,
  330. data: {
  331. context: Em.I18n.t(contextString),
  332. serviceName: service.get('serviceName'),
  333. componentName: operationData.componentName,
  334. parameters: parameters
  335. },
  336. success: 'bulkOperationForHostComponentsSuccessCallback'
  337. });
  338. }
  339. }
  340. else {
  341. App.ModalPopup.show({
  342. header: Em.I18n.t('rolling.nothingToDo.header'),
  343. body: Em.I18n.t('rolling.nothingToDo.body').format(operationData.componentNameFormatted),
  344. secondary: false
  345. });
  346. }
  347. },
  348. /**
  349. * Bulk restart for selected hostComponents
  350. * @param {Object} operationData
  351. * @param {Array} hosts
  352. */
  353. bulkOperationForHostComponentsRestart: function(operationData, hosts) {
  354. var service = App.Service.find(operationData.serviceName);
  355. var components = service.get('hostComponents').filter(function(hc) {
  356. if (hc.get('componentName') != operationData.componentName || hc.get('passiveState') != 'OFF') {
  357. return false;
  358. }
  359. return hosts.contains(hc.get('host'));
  360. });
  361. if (components.length) {
  362. batchUtils.showRollingRestartPopup(components.objectAt(0).get('componentName'), false, components);
  363. }
  364. else {
  365. App.ModalPopup.show({
  366. header: Em.I18n.t('rolling.nothingToDo.header'),
  367. body: Em.I18n.t('rolling.nothingToDo.body').format(operationData.componentNameFormatted),
  368. secondary: false
  369. });
  370. }
  371. },
  372. /**
  373. * Bulk turn on/off passive state for selected hostComponents
  374. * @param {Object} operationData
  375. * @param {Array} hosts
  376. */
  377. bulkOperationForHostComponentsPassiveState: function(operationData, hosts) {
  378. var affectedHosts = [];
  379. hosts.forEach(function(host) {
  380. host.get('hostComponents').forEach(function(hostComponent) {
  381. if (hostComponent.get('componentName') == operationData.componentName) {
  382. if (hostComponent.get('passiveState') !== operationData.state) {
  383. if (hostComponent.get('passiveState') === 'IMPLIED') {
  384. if (operationData.state === 'OFF') {
  385. affectedHosts.push(host.get('hostName'));
  386. }
  387. }
  388. else {
  389. if (hostComponent.get('passiveState') === 'ON') {
  390. if (operationData.state === 'OFF') {
  391. affectedHosts.push(host.get('hostName'));
  392. }
  393. }
  394. else {
  395. if (operationData.state === 'ON') {
  396. affectedHosts.push(host.get('hostName'));
  397. }
  398. }
  399. }
  400. }
  401. }
  402. });
  403. });
  404. if (affectedHosts.length) {
  405. App.ajax.send({
  406. name: 'bulk_request.hosts.all_components.passive_state',
  407. sender: this,
  408. data: {
  409. query: 'HostRoles/component_name=' + operationData.componentName + '&HostRoles/host_name.in(' + affectedHosts.join(',') + ')',
  410. passive_state: operationData.state,
  411. requestInfo: operationData.message
  412. },
  413. success: 'updateHostComponentsPassiveState'
  414. });
  415. }
  416. else {
  417. App.ModalPopup.show({
  418. header: Em.I18n.t('rolling.nothingToDo.header'),
  419. body: Em.I18n.t('hosts.bulkOperation.host_components.passiveState.nothingToDo.body'),
  420. secondary: false
  421. });
  422. }
  423. },
  424. updateHostComponentsPassiveState: function() {
  425. App.router.get('clusterController').loadUpdatedStatus(function(){});
  426. },
  427. /**
  428. * Show BO popup after bulk request
  429. */
  430. bulkOperationForHostComponentsSuccessCallback: function() {
  431. App.router.get('applicationController').dataLoading().done(function (initValue) {
  432. if (initValue) {
  433. App.router.get('backgroundOperationsController').showPopup();
  434. }
  435. });
  436. }
  437. });