host.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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.indexOf('DECOMMISSION') != -1) {
  138. this.bulkOperationForHostComponentsDecommission(operationData, hosts);
  139. }
  140. else {
  141. this.bulkOperationForHostComponents(operationData, hosts);
  142. }
  143. }
  144. }
  145. else {
  146. if (operationData.action === 'RESTART') {
  147. this.bulkOperationForHostsRestart(operationData, hosts);
  148. }
  149. else {
  150. if (operationData.action === 'PASSIVE_STATE') {
  151. this.bulkOperationForHostsPassiveState(operationData, hosts);
  152. }
  153. else {
  154. this.bulkOperationForHosts(operationData, hosts);
  155. }
  156. }
  157. }
  158. },
  159. /**
  160. * Bulk operation (start/stop all) for selected hosts
  161. * @param {Object} operationData - data about bulk operation (action, hostComponents etc)
  162. * @param {Array} hosts - list of affected hosts
  163. */
  164. bulkOperationForHosts: function(operationData, hosts) {
  165. var query = [];
  166. hosts.forEach(function(host) {
  167. var subQuery = '(HostRoles/component_name.in(%@)&HostRoles/host_name=' + host.get('hostName') + ')';
  168. var components = [];
  169. host.get('hostComponents').forEach(function(hostComponent) {
  170. if (hostComponent.get('passiveState') == 'OFF') {
  171. if (hostComponent.get('isMaster') || hostComponent.get('isSlave')) {
  172. if (hostComponent.get('workStatus') === operationData.actionToCheck) {
  173. components.push(hostComponent.get('componentName'));
  174. }
  175. }
  176. }
  177. });
  178. if (components.length) {
  179. query.push(subQuery.fmt(components.join(',')));
  180. }
  181. });
  182. var hostNames = hosts.mapProperty('hostName').join(",");
  183. if (query.length) {
  184. query = query.join('|');
  185. App.ajax.send({
  186. name: 'bulk_request.hosts.all_components',
  187. sender: this,
  188. data: {
  189. query: query,
  190. state: operationData.action,
  191. requestInfo: operationData.message,
  192. hostName: hostNames
  193. },
  194. success: 'bulkOperationForHostComponentsSuccessCallback'
  195. });
  196. }
  197. else {
  198. App.ModalPopup.show({
  199. header: Em.I18n.t('rolling.nothingToDo.header'),
  200. body: Em.I18n.t('rolling.nothingToDo.body').format(Em.I18n.t('hosts.host.maintainance.allComponents.context')),
  201. secondary: false
  202. });
  203. }
  204. },
  205. /**
  206. * Bulk restart for selected hosts
  207. * @param {Object} operationData - data about bulk operation (action, hostComponents etc)
  208. * @param {Ember.Enumerable} hosts - list of affected hosts
  209. */
  210. bulkOperationForHostsRestart: function(operationData, hosts) {
  211. var hostComponents = [];
  212. hosts.forEach(function(host) {
  213. hostComponents.pushObjects(host.get('hostComponents').filterProperty('passiveState','OFF').toArray());
  214. });
  215. batchUtils.restartHostComponents(hostComponents, Em.I18n.t('rollingrestart.context.allOnSelectedHosts'), "HOST");
  216. },
  217. /**
  218. * Bulk turn on/off passive state for selected hosts
  219. * @param {Object} operationData - data about bulk operation (action, hostComponents etc)
  220. * @param {Array} hosts - list of affected hosts
  221. */
  222. bulkOperationForHostsPassiveState: function(operationData, hosts) {
  223. var affectedHosts = [];
  224. hosts.forEach(function(host) {
  225. if (host.get('passiveState') !== operationData.state) {
  226. affectedHosts.push(host);
  227. }
  228. });
  229. if (affectedHosts.length) {
  230. App.ajax.send({
  231. name: 'bulk_request.hosts.passive_state',
  232. sender: this,
  233. data: {
  234. hosts: affectedHosts,
  235. hostNames: affectedHosts.mapProperty('hostName').join(','),
  236. passive_state: operationData.state,
  237. requestInfo: operationData.message
  238. },
  239. success: 'updateHostPassiveState'
  240. });
  241. }
  242. else {
  243. App.ModalPopup.show({
  244. header: Em.I18n.t('rolling.nothingToDo.header'),
  245. body: Em.I18n.t('hosts.bulkOperation.passiveState.nothingToDo.body'),
  246. secondary: false
  247. });
  248. }
  249. },
  250. updateHostPassiveState: function(data, opt, params) {
  251. params.hosts.setEach('passiveState', params.passive_state);
  252. App.router.get('clusterController').loadUpdatedStatus(function(){
  253. batchUtils.infoPassiveState(params.passive_state);
  254. });
  255. },
  256. /**
  257. * Bulk operation for selected hostComponents
  258. * @param {Object} operationData - data about bulk operation (action, hostComponents etc)
  259. * @param {Array} hosts - list of affected hosts
  260. */
  261. bulkOperationForHostComponents: function(operationData, hosts) {
  262. var service = App.Service.find(operationData.serviceName);
  263. var components = service.get('hostComponents').filter(function(hc) {
  264. if (hc.get('componentName') != operationData.componentName || hc.get('passiveState') != 'OFF' ) {
  265. return false;
  266. }
  267. if(hc.get('workStatus') == operationData.action) {
  268. return false;
  269. }
  270. return hosts.contains(hc.get('host'));
  271. });
  272. if (components.length) {
  273. var hostsWithComponentInProperState = components.mapProperty('host.hostName');
  274. App.ajax.send({
  275. name: 'bulk_request.host_components',
  276. sender: this,
  277. data: {
  278. hostNames: hostsWithComponentInProperState.join(','),
  279. state: operationData.action,
  280. requestInfo: operationData.message + ' ' + operationData.componentNameFormatted,
  281. componentName: operationData.componentName
  282. },
  283. success: 'bulkOperationForHostComponentsSuccessCallback'
  284. });
  285. }
  286. else {
  287. App.ModalPopup.show({
  288. header: Em.I18n.t('rolling.nothingToDo.header'),
  289. body: Em.I18n.t('rolling.nothingToDo.body').format(operationData.componentNameFormatted),
  290. secondary: false
  291. });
  292. }
  293. },
  294. /**
  295. * Bulk decommission/recommission for selected hostComponents
  296. * @param {Object} operationData
  297. * @param {Array} hosts
  298. */
  299. bulkOperationForHostComponentsDecommission: function(operationData, hosts) {
  300. var service = App.Service.find(operationData.serviceName);
  301. var components = service.get('hostComponents').filter(function(hc) {
  302. if (hc.get('componentName') != operationData.realComponentName || hc.get('passiveState') != 'OFF' ) {
  303. return false;
  304. }
  305. return hosts.contains(hc.get('host'));
  306. });
  307. if (components.length) {
  308. var hostsWithComponentInProperState = components.mapProperty('host.hostName');
  309. var turn_off = operationData.action.indexOf('OFF') !== -1;
  310. var svcName = operationData.serviceName;
  311. var masterName = operationData.componentName;
  312. var slaveName = operationData.realComponentName;
  313. var hostNames = hostsWithComponentInProperState.join(',');
  314. if (turn_off) {
  315. // For recommession
  316. if (svcName === "YARN" || svcName === "HBASE" || svcName === "HDFS") {
  317. App.router.get('mainHostDetailsController').doRecommissionAndStart(hostNames, svcName, masterName, slaveName);
  318. }
  319. else if (svcName === "MAPREDUCE") {
  320. App.router.get('mainHostDetailsController').doRecommissionAndRestart(hostNames, svcName, masterName, slaveName);
  321. }
  322. } else {
  323. hostsWithComponentInProperState = components.filterProperty('workStatus','STARTED').mapProperty('host.hostName');
  324. //For decommession
  325. var parameters = {
  326. "slave_type": slaveName
  327. };
  328. var contextString = turn_off? 'hosts.host.' + slaveName.toLowerCase() + '.recommission':
  329. 'hosts.host.' + slaveName.toLowerCase() + '.decommission';
  330. if (turn_off) {
  331. parameters['included_hosts'] = hostsWithComponentInProperState.join(',')
  332. }
  333. else {
  334. parameters['excluded_hosts'] = hostsWithComponentInProperState.join(',');
  335. }
  336. App.ajax.send({
  337. name: 'bulk_request.decommission',
  338. sender: this,
  339. data: {
  340. context: Em.I18n.t(contextString),
  341. serviceName: service.get('serviceName'),
  342. componentName: operationData.componentName,
  343. parameters: parameters
  344. },
  345. success: 'bulkOperationForHostComponentsSuccessCallback'
  346. });
  347. }
  348. }
  349. else {
  350. App.ModalPopup.show({
  351. header: Em.I18n.t('rolling.nothingToDo.header'),
  352. body: Em.I18n.t('rolling.nothingToDo.body').format(operationData.componentNameFormatted),
  353. secondary: false
  354. });
  355. }
  356. },
  357. /**
  358. * Bulk restart for selected hostComponents
  359. * @param {Object} operationData
  360. * @param {Array} hosts
  361. */
  362. bulkOperationForHostComponentsRestart: function(operationData, hosts) {
  363. var service = App.Service.find(operationData.serviceName);
  364. var components = service.get('hostComponents').filter(function(hc) {
  365. if (hc.get('componentName') != operationData.componentName || hc.get('passiveState') != 'OFF') {
  366. return false;
  367. }
  368. return hosts.contains(hc.get('host'));
  369. });
  370. if (components.length) {
  371. batchUtils.showRollingRestartPopup(components.objectAt(0).get('componentName'), service.get('displayName'), service.get('passiveState') === "ON", false, components);
  372. }
  373. else {
  374. App.ModalPopup.show({
  375. header: Em.I18n.t('rolling.nothingToDo.header'),
  376. body: Em.I18n.t('rolling.nothingToDo.body').format(operationData.componentNameFormatted),
  377. secondary: false
  378. });
  379. }
  380. },
  381. updateHostComponentsPassiveState: function(data, opt, params) {
  382. App.router.get('clusterController').loadUpdatedStatus(function(){
  383. batchUtils.infoPassiveState(params.passive_state);
  384. });
  385. },
  386. /**
  387. * Show BO popup after bulk request
  388. */
  389. bulkOperationForHostComponentsSuccessCallback: function() {
  390. App.router.get('applicationController').dataLoading().done(function (initValue) {
  391. if (initValue) {
  392. App.router.get('backgroundOperationsController').showPopup();
  393. }
  394. });
  395. }
  396. });