host.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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('isMaster') || hostComponent.get('isSlave')) {
  176. if (hostComponent.get('workStatus') === operationData.actionToCheck) {
  177. components.push(hostComponent.get('componentName'));
  178. }
  179. }
  180. });
  181. if (components.length) {
  182. query.push(subQuery.fmt(components.join(',')));
  183. }
  184. });
  185. if (query.length) {
  186. query = query.join('|');
  187. App.ajax.send({
  188. name: 'bulk_request.hosts.all_components',
  189. sender: this,
  190. data: {
  191. query: query,
  192. state: operationData.action,
  193. requestInfo: operationData.message
  194. },
  195. success: 'bulkOperationForHostComponentsSuccessCallback'
  196. });
  197. }
  198. else {
  199. App.ModalPopup.show({
  200. header: Em.I18n.t('rolling.nothingToDo.header'),
  201. body: Em.I18n.t('rolling.nothingToDo.body').format(Em.I18n.t('hosts.host.maintainance.allComponents.context')),
  202. secondary: false
  203. });
  204. }
  205. },
  206. /**
  207. * Bulk restart for selected hosts
  208. * @param {Object} operationData - data about bulk operation (action, hostComponents etc)
  209. * @param {Array} hosts - list of affected hosts
  210. */
  211. bulkOperationForHostsRestart: function(operationData, hosts) {
  212. var hostComponents = [];
  213. hosts.forEach(function(host) {
  214. hostComponents.pushObjects(host.get('hostComponents').toArray());
  215. });
  216. batchUtils.restartHostComponents(hostComponents);
  217. },
  218. /**
  219. * Bulk turn on/off passive state for selected hosts
  220. * @param {Object} operationData - data about bulk operation (action, hostComponents etc)
  221. * @param {Array} hosts - list of affected hosts
  222. */
  223. bulkOperationForHostsPassiveState: function(operationData, hosts) {
  224. var affectedHosts = [];
  225. hosts.forEach(function(host) {
  226. if (host.get('passiveState') !== operationData.state) {
  227. affectedHosts.push(host.get('hostName'));
  228. }
  229. });
  230. if (affectedHosts.length) {
  231. App.ajax.send({
  232. name: 'bulk_request.hosts.passive_state',
  233. sender: this,
  234. data: {
  235. hostNames: affectedHosts.join(','),
  236. passive_state: operationData.state,
  237. requestInfo: operationData.message
  238. }
  239. });
  240. }
  241. else {
  242. App.ModalPopup.show({
  243. header: Em.I18n.t('rolling.nothingToDo.header'),
  244. body: Em.I18n.t('hosts.bulkOperation.passiveState.nothingToDo.body'),
  245. secondary: false
  246. });
  247. }
  248. },
  249. /**
  250. * Bulk operation for selected hostComponents
  251. * @param {Object} operationData - data about bulk operation (action, hostComponents etc)
  252. * @param {Array} hosts - list of affected hosts
  253. */
  254. bulkOperationForHostComponents: function(operationData, hosts) {
  255. var service = App.Service.find(operationData.serviceName);
  256. var components = service.get('hostComponents').filter(function(hc) {
  257. if (hc.get('componentName') != operationData.componentName) {
  258. return false;
  259. }
  260. if(hc.get('workStatus') == operationData.action) {
  261. return false;
  262. }
  263. return hosts.contains(hc.get('host'));
  264. });
  265. if (components.length) {
  266. var hostsWithComponentInProperState = components.mapProperty('host.hostName');
  267. App.ajax.send({
  268. name: 'bulk_request.host_components',
  269. sender: this,
  270. data: {
  271. hostNames: hostsWithComponentInProperState.join(','),
  272. state: operationData.action,
  273. requestInfo: operationData.message + ' ' + operationData.componentNameFormatted,
  274. componentName: operationData.componentName
  275. },
  276. success: 'bulkOperationForHostComponentsSuccessCallback'
  277. });
  278. }
  279. else {
  280. App.ModalPopup.show({
  281. header: Em.I18n.t('rolling.nothingToDo.header'),
  282. body: Em.I18n.t('rolling.nothingToDo.body').format(operationData.componentNameFormatted),
  283. secondary: false
  284. });
  285. }
  286. },
  287. /**
  288. * Bulk decommission for selected hostComponents
  289. * @param {Object} operationData
  290. * @param {Array} hosts
  291. */
  292. bulkOperationForHostComponentsDecommission: function(operationData, hosts) {
  293. var service = App.Service.find(operationData.serviceName);
  294. var components = service.get('hostComponents').filter(function(hc) {
  295. if (hc.get('componentName') != operationData.realComponentName) {
  296. return false;
  297. }
  298. return hosts.contains(hc.get('host'));
  299. });
  300. if (components.length) {
  301. var hostsWithComponentInProperState = components.mapProperty('host.hostName');
  302. var turn_off = operationData.action.indexOf('OFF') !== -1;
  303. var parameters = {
  304. "slave_type": operationData.realComponentName
  305. };
  306. if (turn_off) {
  307. parameters['included_hosts'] = hostsWithComponentInProperState.join(',')
  308. }
  309. else {
  310. parameters['excluded_hosts'] = hostsWithComponentInProperState.join(',');
  311. }
  312. App.ajax.send({
  313. name: 'bulk_request.decommission',
  314. sender: this,
  315. data: {
  316. context: turn_off ? Em.I18n.t('hosts.host.datanode.recommission') : Em.I18n.t('hosts.host.datanode.decommission'),
  317. serviceName: service.get('serviceName'),
  318. componentName: operationData.componentName,
  319. parameters: parameters
  320. },
  321. success: 'bulkOperationForHostComponentsSuccessCallback'
  322. });
  323. }
  324. else {
  325. App.ModalPopup.show({
  326. header: Em.I18n.t('rolling.nothingToDo.header'),
  327. body: Em.I18n.t('rolling.nothingToDo.body').format(operationData.componentNameFormatted),
  328. secondary: false
  329. });
  330. }
  331. },
  332. /**
  333. * Bulk restart for selected hostComponents
  334. * @param {Object} operationData
  335. * @param {Array} hosts
  336. */
  337. bulkOperationForHostComponentsRestart: function(operationData, hosts) {
  338. var service = App.Service.find(operationData.serviceName);
  339. var components = service.get('hostComponents').filter(function(hc) {
  340. if (hc.get('componentName') != operationData.componentName) {
  341. return false;
  342. }
  343. return hosts.contains(hc.get('host'));
  344. });
  345. if (components.length) {
  346. batchUtils._doPostBatchRollingRestartRequest(components, components.length, 1, 1);
  347. }
  348. else {
  349. App.ModalPopup.show({
  350. header: Em.I18n.t('rolling.nothingToDo.header'),
  351. body: Em.I18n.t('rolling.nothingToDo.body').format(operationData.componentNameFormatted),
  352. secondary: false
  353. });
  354. }
  355. },
  356. /**
  357. * Bulk turn on/off passive state for selected hostComponents
  358. * @param {Object} operationData
  359. * @param {Array} hosts
  360. */
  361. bulkOperationForHostComponentsPassiveState: function(operationData, hosts) {
  362. var affectedHosts = [];
  363. hosts.forEach(function(host) {
  364. host.get('hostComponents').forEach(function(hostComponent) {
  365. if (hostComponent.get('componentName') == operationData.componentName) {
  366. if (hostComponent.get('passiveState') !== operationData.state) {
  367. if (hostComponent.get('passiveState') === 'IMPLIED') {
  368. if (operationData.state === 'ACTIVE') {
  369. affectedHosts.push(host.get('hostName'));
  370. }
  371. }
  372. else {
  373. if (hostComponent.get('passiveState') === 'PASSIVE') {
  374. if (operationData.state === 'ACTIVE') {
  375. affectedHosts.push(host.get('hostName'));
  376. }
  377. }
  378. else {
  379. if (operationData.state === 'PASSIVE') {
  380. affectedHosts.push(host.get('hostName'));
  381. }
  382. }
  383. }
  384. }
  385. }
  386. });
  387. });
  388. if (affectedHosts.length) {
  389. App.ajax.send({
  390. name: 'bulk_request.hosts.all_components.passive_state',
  391. sender: this,
  392. data: {
  393. query: 'HostRoles/component_name=' + operationData.componentName + '&HostRoles/host_name.in(' + affectedHosts.join(',') + ')',
  394. passive_state: operationData.state,
  395. requestInfo: operationData.message
  396. }
  397. });
  398. }
  399. else {
  400. App.ModalPopup.show({
  401. header: Em.I18n.t('rolling.nothingToDo.header'),
  402. body: Em.I18n.t('hosts.bulkOperation.host_components.passiveState.nothingToDo.body'),
  403. secondary: false
  404. });
  405. }
  406. },
  407. /**
  408. * Show BO popup after bulk request
  409. */
  410. bulkOperationForHostComponentsSuccessCallback: function() {
  411. App.router.get('applicationController').dataLoading().done(function (initValue) {
  412. if (initValue) {
  413. App.router.get('backgroundOperationsController').showPopup();
  414. }
  415. });
  416. }
  417. });