details.js 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759
  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 batchUtils = require('utils/batch_scheduled_requests');
  20. var componentsUtils = require('utils/components');
  21. var stringUtils = require('utils/string_utils');
  22. App.MainHostDetailsController = Em.Controller.extend({
  23. name: 'mainHostDetailsController',
  24. /**
  25. * Viewed host
  26. * @type {App.Host|null}
  27. */
  28. content: null,
  29. /**
  30. * Does user come from hosts page
  31. * @type {bool}
  32. */
  33. isFromHosts: false,
  34. /**
  35. * path to page visited before
  36. * @type {string}
  37. */
  38. referer: '',
  39. /**
  40. * Open dashboard page
  41. * @method routeHome
  42. */
  43. routeHome: function () {
  44. App.router.transitionTo('main.dashboard.index');
  45. },
  46. /**
  47. * Open summary page of the selected service
  48. * @param {object} event
  49. * @method routeToService
  50. */
  51. routeToService: function (event) {
  52. var service = event.context;
  53. App.router.transitionTo('main.services.service.summary', service);
  54. },
  55. /**
  56. * List of active (not in passive state) host components
  57. * @type {Ember.Enumerable}
  58. */
  59. serviceActiveComponents: function () {
  60. return this.get('content.hostComponents').filterProperty('service.isInPassive', false);
  61. }.property('content.hostComponents'),
  62. /**
  63. * List of active host components which aren't clients
  64. * @type {Ember.Enumerable}
  65. */
  66. serviceNonClientActiveComponents: function () {
  67. return this.get('serviceActiveComponents').filterProperty('isClient', false);
  68. }.property('serviceActiveComponents'),
  69. /**
  70. * send command to server to start selected host component
  71. * @param {object} event
  72. * @method startComponent
  73. */
  74. startComponent: function (event) {
  75. var self = this;
  76. return App.showConfirmationPopup(function () {
  77. var component = event.context;
  78. var context = Em.I18n.t('requestInfo.startHostComponent') + " " + component.get('displayName');
  79. self.sendComponentCommand(component, context, App.HostComponentStatus.started);
  80. });
  81. },
  82. /**
  83. * send command to server to stop selected host component
  84. * @param {object} event
  85. * @method startComponent
  86. */
  87. stopComponent: function (event) {
  88. var self = this;
  89. return App.showConfirmationPopup(function () {
  90. var component = event.context;
  91. var context = Em.I18n.t('requestInfo.stopHostComponent') + " " + component.get('displayName');
  92. self.sendComponentCommand(component, context, App.HostComponentStatus.stopped);
  93. });
  94. },
  95. /**
  96. * PUTs a command to server to start/stop a component. If no
  97. * specific component is provided, all components are started.
  98. * @param {object} component When <code>null</code> all startable components are started.
  99. * @param {String} context Context under which this command is beign sent.
  100. * @param {String} state - desired state of component can be 'STARTED' or 'STOPPED'
  101. * @method sendStartComponentCommand
  102. */
  103. sendComponentCommand: function (component, context, state) {
  104. var data = {
  105. hostName: this.get('content.hostName'),
  106. context: context,
  107. component: component,
  108. HostRoles: {
  109. state: state
  110. }
  111. };
  112. if (Array.isArray(component)) {
  113. data.query = "HostRoles/component_name.in(" + component.mapProperty('componentName').join(',') + ")";
  114. } else {
  115. data.componentName = component.get('componentName');
  116. data.serviceName = component.get('service.serviceName');
  117. }
  118. App.ajax.send({
  119. name: (Array.isArray(component)) ? 'common.host.host_components.update' : 'common.host.host_component.update',
  120. sender: this,
  121. data: data,
  122. success: 'sendComponentCommandSuccessCallback',
  123. error: 'ajaxErrorCallback'
  124. });
  125. },
  126. /**
  127. * Success callback for stop/start host component request
  128. * @param {object} data
  129. * @param {object} opt
  130. * @param {object} params
  131. * @method stopComponentSuccessCallback
  132. */
  133. sendComponentCommandSuccessCallback: function (data, opt, params) {
  134. var running = (params.HostRoles.state === App.HostComponentStatus.stopped) ? App.HostComponentStatus.stopping : App.HostComponentStatus.starting;
  135. console.log('Send request for ' + running + ' successfully');
  136. params.component.set('workStatus', running);
  137. if (App.get('testMode')) {
  138. this.mimicWorkStatusChange(params.component, running, params.HostRoles.state);
  139. }
  140. this.showBackgroundOperationsPopup();
  141. },
  142. /**
  143. * Default error-callback for ajax-requests in current page
  144. * @param {object} request
  145. * @param {object} ajaxOptions
  146. * @param {string} error
  147. * @param {object} opt
  148. * @param {object} params
  149. * @method ajaxErrorCallback
  150. */
  151. ajaxErrorCallback: function (request, ajaxOptions, error, opt, params) {
  152. return componentsUtils.ajaxErrorCallback(request, ajaxOptions, error, opt, params);
  153. },
  154. /**
  155. * mimic status transition in test mode
  156. * @param entity
  157. * @param transitionalState
  158. * @param finalState
  159. */
  160. mimicWorkStatusChange: function (entity, transitionalState, finalState) {
  161. if (Em.isArray(entity)) {
  162. entity.forEach(function (item) {
  163. item.set('workStatus', transitionalState);
  164. setTimeout(function () {
  165. item.set('workStatus', finalState);
  166. }, App.testModeDelayForActions);
  167. });
  168. } else {
  169. entity.set('workStatus', transitionalState);
  170. setTimeout(function () {
  171. entity.set('workStatus', finalState);
  172. }, App.testModeDelayForActions);
  173. }
  174. },
  175. /**
  176. * load data (if we need to show this background operations popup) from persist
  177. * @param callback
  178. */
  179. showBackgroundOperationsPopup: function (callback) {
  180. App.router.get('applicationController').dataLoading().done(function (initValue) {
  181. if (initValue) {
  182. App.router.get('backgroundOperationsController').showPopup();
  183. }
  184. if (typeof callback === 'function') {
  185. callback();
  186. }
  187. });
  188. },
  189. /**
  190. * Send command to server to delete selected host component
  191. * @param {object} event
  192. * @method deleteComponent
  193. */
  194. deleteComponent: function (event) {
  195. var self = this;
  196. var component = event.context;
  197. var componentName = component.get('componentName');
  198. var displayName = component.get('displayName');
  199. var isLastComponent = (this.getTotalComponent(component) === 1);
  200. App.ModalPopup.show({
  201. header: Em.I18n.t('popup.confirmation.commonHeader'),
  202. primary: Em.I18n.t('hosts.host.deleteComponent.popup.confirm'),
  203. bodyClass: Em.View.extend({
  204. templateName: require('templates/main/host/details/deleteComponentPopup')
  205. }),
  206. isChecked: false,
  207. disablePrimary: function () {
  208. return !this.get('isChecked');
  209. }.property('isChecked'),
  210. lastComponent: function () {
  211. this.set('isChecked', !isLastComponent);
  212. return isLastComponent;
  213. }.property(),
  214. isZkServer: function () {
  215. return componentName == 'ZOOKEEPER_SERVER';
  216. }.property(),
  217. lastComponentError: Em.View.extend({
  218. template: Em.Handlebars.compile(Em.I18n.t('hosts.host.deleteComponent.popup.warning').format(displayName))
  219. }),
  220. restartNagiosMsg: Em.View.extend({
  221. template: Em.Handlebars.compile(Em.I18n.t('hosts.host.deleteComponent.popup.msg2').format(displayName))
  222. }),
  223. deleteComponentMsg: function () {
  224. return Em.I18n.t('hosts.host.deleteComponent.popup.msg1').format(displayName);
  225. }.property(),
  226. deleteZkServerMsg: Em.View.extend({
  227. template: Em.Handlebars.compile(Em.I18n.t('hosts.host.deleteComponent.popup.deleteZooKeeperServer'))
  228. }),
  229. onPrimary: function () {
  230. var popup = this;
  231. self._doDeleteHostComponent(component, function () {
  232. self.set('redrawComponents', true);
  233. popup.hide();
  234. });
  235. }
  236. });
  237. },
  238. /**
  239. * get total count of host-components
  240. * @method getTotalComponent
  241. * @param component
  242. * @return {Number}
  243. */
  244. getTotalComponent: function (component) {
  245. var count;
  246. if (component.get('isSlave')) {
  247. count = App.SlaveComponent.find(component.get('componentName')).get('totalCount');
  248. } else if (component.get('isClient')) {
  249. count = App.ClientComponent.find(component.get('componentName')).get('totalCount');
  250. } else {
  251. count = App.HostComponent.find().filterProperty('componentName', component.get('componentName')).get('length')
  252. }
  253. return count || 0;
  254. },
  255. /**
  256. * Trigger to reset list of master/slaves components on the view
  257. * @type {bool}
  258. */
  259. redrawComponents: false,
  260. /**
  261. * Deletes the given host component, or all host components.
  262. *
  263. * @param {object|null} component When <code>null</code> all host components are deleted.
  264. * @return <code>null</code> when components get deleted.
  265. * <code>{xhr: XhrObj, url: "http://", method: "DELETE"}</code>
  266. * when components failed to get deleted.
  267. * @method _doDeleteHostComponent
  268. */
  269. _doDeleteHostComponent: function (component, callback) {
  270. callback = callback || Em.K;
  271. App.ajax.send({
  272. name: (Em.isNone(component)) ? 'common.delete.host' : 'common.delete.host_component',
  273. sender: this,
  274. data: {
  275. componentName: (component) ? component.get('componentName') : '',
  276. hostName: this.get('content.hostName')
  277. },
  278. success: '_doDeleteHostComponentSuccessCallback',
  279. error: '_doDeleteHostComponentErrorCallback'
  280. }).then(callback, callback);
  281. },
  282. /**
  283. * Result of delete component(s) request
  284. * @type {object}
  285. */
  286. _deletedHostComponentResult: null,
  287. /**
  288. * Success callback for delete host component request
  289. * @method _doDeleteHostComponentSuccessCallback
  290. */
  291. _doDeleteHostComponentSuccessCallback: function (response, request, data) {
  292. this.set('_deletedHostComponentResult', null);
  293. if (data.componentName == 'ZOOKEEPER_SERVER') {
  294. this.set('fromDeleteZkServer', true);
  295. this.loadConfigs();
  296. }
  297. },
  298. /**
  299. * Error-callback for delete host component request
  300. * @param {object} xhr
  301. * @param {string} textStatus
  302. * @param {object} errorThrown
  303. * @method _doDeleteHostComponentErrorCallback
  304. */
  305. _doDeleteHostComponentErrorCallback: function (xhr, textStatus, errorThrown, data) {
  306. console.log('Error deleting host component');
  307. console.log(textStatus);
  308. console.log(errorThrown);
  309. this.set('_deletedHostComponentResult', {xhr: xhr, url: data.url, method: 'DELETE'});
  310. },
  311. /**
  312. * Send command to server to upgrade selected host component
  313. * @param {object} event
  314. * @method upgradeComponent
  315. */
  316. upgradeComponent: function (event) {
  317. var self = this;
  318. var component = event.context;
  319. return App.showConfirmationPopup(function () {
  320. App.ajax.send({
  321. name: 'host.host_component.upgrade',
  322. sender: self,
  323. data: {
  324. component: component,
  325. hostName: self.get('content.hostName'),
  326. componentName: component.get('componentName'),
  327. data: JSON.stringify({
  328. RequestInfo: {
  329. "context": Em.I18n.t('requestInfo.upgradeHostComponent') + " " + component.get('displayName')
  330. },
  331. Body: {
  332. HostRoles: {
  333. stack_id: 'HDP-1.2.2',
  334. state: 'INSTALLED'
  335. }
  336. }
  337. })
  338. },
  339. success: 'upgradeComponentSuccessCallback',
  340. error: 'ajaxErrorCallback'
  341. });
  342. });
  343. },
  344. /**
  345. * Success callback for upgrade host component request
  346. * @param {object} data
  347. * @param {object} opt
  348. * @param {object} params
  349. * @method upgradeComponentSuccessCallback
  350. */
  351. upgradeComponentSuccessCallback: function (data, opt, params) {
  352. console.log('Send request for UPGRADE successfully');
  353. if (App.get('testMode')) {
  354. this.mimicWorkStatusChange(params.component, App.HostComponentStatus.starting, App.HostComponentStatus.started);
  355. }
  356. this.showBackgroundOperationsPopup();
  357. },
  358. /**
  359. * Send command to server to restart selected components
  360. * @param {object} event
  361. * @method restartComponent
  362. */
  363. restartComponent: function (event) {
  364. var component = event.context;
  365. return App.showConfirmationPopup(function () {
  366. batchUtils.restartHostComponents([component], Em.I18n.t('rollingrestart.context.selectedComponentOnSelectedHost').format(component.get('displayName')), "HOST_COMPONENT");
  367. });
  368. },
  369. /**
  370. * get current status of security settings,
  371. * if true security is enabled otherwise disabled
  372. * @return {Boolean}
  373. */
  374. securityEnabled: function () {
  375. return App.router.get('mainAdminSecurityController.securityEnabled');
  376. }.property('App.router.mainAdminSecurityController.securityEnabled'),
  377. /**
  378. * Send command to server to install selected host component
  379. * @param {object} event
  380. * @method addComponent
  381. */
  382. addComponent: function (event) {
  383. var self = this;
  384. var component = event.context;
  385. var componentName = component.get('componentName');
  386. var missedComponents = componentsUtils.checkComponentDependencies(componentName, {
  387. scope: 'host',
  388. installedComponents: this.get('content.hostComponents').mapProperty('componentName')
  389. });
  390. if (!!missedComponents.length) {
  391. var popupMessage = Em.I18n.t('host.host.addComponent.popup.dependedComponents.body').format(component.get('displayName'),
  392. stringUtils.getFormattedStringFromArray(missedComponents.map(function(cName) {
  393. return App.StackServiceComponent.find(cName).get('displayName');
  394. })));
  395. return App.showAlertPopup(Em.I18n.t('host.host.addComponent.popup.dependedComponents.header'), popupMessage);
  396. }
  397. if (componentName === 'ZOOKEEPER_SERVER') {
  398. return App.showConfirmationPopup(function () {
  399. self.primary(component);
  400. }, Em.I18n.t('hosts.host.addComponent.addZooKeeper'));
  401. }
  402. else {
  403. if (this.get('securityEnabled') && componentName !== 'CLIENTS') {
  404. return App.showConfirmationPopup(function () {
  405. self.primary(component);
  406. }, Em.I18n.t('hosts.host.addComponent.securityNote').format(componentName, self.get('content.hostName')));
  407. }
  408. else {
  409. return this.addClientComponent(component);
  410. }
  411. }
  412. },
  413. /**
  414. * Send command to server to install client on selected host
  415. * @param component
  416. */
  417. addClientComponent: function (component) {
  418. var self = this;
  419. var message = this.formatClientsMessage(component);
  420. return App.ModalPopup.show({
  421. primary: Em.I18n.t('hosts.host.addComponent.popup.confirm'),
  422. header: Em.I18n.t('popup.confirmation.commonHeader'),
  423. addComponentMsg: function () {
  424. return Em.I18n.t('hosts.host.addComponent.msg').format(message);
  425. }.property(),
  426. bodyClass: Em.View.extend({
  427. templateName: require('templates/main/host/details/addComponentPopup')
  428. }),
  429. restartNagiosMsg: Em.View.extend({
  430. template: Em.Handlebars.compile(Em.I18n.t('hosts.host.addComponent.note').format(message))
  431. }),
  432. onPrimary: function () {
  433. this.hide();
  434. if (component.get('componentName') === 'CLIENTS') {
  435. // Clients component has many sub-components which
  436. // need to be installed.
  437. var scs = component.get('subComponentNames');
  438. scs.forEach(function (sc) {
  439. var c = Em.Object.create({
  440. displayName: App.format.role(sc),
  441. componentName: sc,
  442. serviceName: sc.replace("_CLIENT", "")
  443. });
  444. self.primary(c);
  445. });
  446. } else {
  447. self.primary(component);
  448. }
  449. }
  450. });
  451. },
  452. /**
  453. * format message for operation of adding clients
  454. * @param client
  455. */
  456. formatClientsMessage: function (client) {
  457. var displayName = Em.isNone(client.get('displayName')) ? '' : client.get('displayName');
  458. var subComponentNames = client.get('subComponentNames');
  459. if (subComponentNames && subComponentNames.length > 0) {
  460. var dns = [];
  461. subComponentNames.forEach(function (scn) {
  462. dns.push(App.format.role(scn));
  463. });
  464. displayName += " (" + dns.join(", ") + ")";
  465. }
  466. return displayName;
  467. },
  468. /**
  469. * Send request to add host component
  470. * @param {App.HostComponent} component
  471. * @method primary
  472. */
  473. primary: function (component) {
  474. var self = this;
  475. componentsUtils.installHostComponent(self.get('content.hostName'), component);
  476. },
  477. /**
  478. * Success callback for install host component request (sent in <code>addNewComponentSuccessCallback</code>)
  479. * @param {object} data
  480. * @param {object} opt
  481. * @param {object} params
  482. * @method installNewComponentSuccessCallback
  483. */
  484. installNewComponentSuccessCallback: function (data, opt, params) {
  485. if (!data.Requests || !data.Requests.id) {
  486. return false;
  487. }
  488. var self = this;
  489. console.log('Send request for INSTALLING NEW COMPONENT successfully');
  490. if (App.get('testMode')) {
  491. this.mimicWorkStatusChange(params.component, App.HostComponentStatus.installing, App.HostComponentStatus.stopped);
  492. }
  493. this.showBackgroundOperationsPopup(function () {
  494. if (params.componentName === 'ZOOKEEPER_SERVER') {
  495. self.set('zkRequestId', data.Requests.id);
  496. self.addObserver('App.router.backgroundOperationsController.serviceTimestamp', self, self.checkZkConfigs);
  497. self.checkZkConfigs();
  498. }
  499. });
  500. return true;
  501. },
  502. /**
  503. * Send command to server to resfresh configs of selected component
  504. * @param {object} event
  505. * @method refreshComponentConfigs
  506. */
  507. refreshComponentConfigs: function (event) {
  508. var self = this;
  509. return App.showConfirmationPopup(function () {
  510. var component = event.context;
  511. var context = Em.I18n.t('requestInfo.refreshComponentConfigs').format(component.get('displayName'));
  512. self.sendRefreshComponentConfigsCommand(component, context);
  513. });
  514. },
  515. /**
  516. * PUTs a command to server to refresh configs of host component.
  517. * @param {object} component
  518. * @param {object} context Context under which this command is beign sent.
  519. * @method sendRefreshComponentConfigsCommand
  520. */
  521. sendRefreshComponentConfigsCommand: function (component, context) {
  522. var resource_filters = [
  523. {
  524. service_name: component.get('service.serviceName'),
  525. component_name: component.get('componentName'),
  526. hosts: component.get('host.hostName')
  527. }
  528. ];
  529. App.ajax.send({
  530. name: 'host.host_component.refresh_configs',
  531. sender: this,
  532. data: {
  533. resource_filters: resource_filters,
  534. context: context
  535. },
  536. success: 'refreshComponentConfigsSuccessCallback'
  537. });
  538. },
  539. /**
  540. * Success callback for refresh host component configs request
  541. * @method refreshComponentConfigsSuccessCallback
  542. */
  543. refreshComponentConfigsSuccessCallback: function () {
  544. console.log('Send request for refresh configs successfully');
  545. this.showBackgroundOperationsPopup();
  546. },
  547. /**
  548. * Load tags
  549. * @method checkZkConfigs
  550. */
  551. checkZkConfigs: function () {
  552. var bg = App.router.get('backgroundOperationsController.services').findProperty('id', this.get('zkRequestId'));
  553. if (bg && !bg.get('isRunning')) {
  554. var self = this;
  555. this.removeObserver('App.router.backgroundOperationsController.serviceTimestamp', this, this.checkZkConfigs);
  556. setTimeout(function () {
  557. self.loadConfigs();
  558. }, App.get('componentsUpdateInterval'));
  559. }
  560. },
  561. /**
  562. * Load configs
  563. * @method loadConfigs
  564. */
  565. loadConfigs: function () {
  566. App.ajax.send({
  567. name: 'config.tags',
  568. sender: this,
  569. success: 'loadConfigsSuccessCallback'
  570. });
  571. },
  572. /**
  573. * Success callback for load configs request
  574. * @param {object} data
  575. * @method adConfigsSuccessCallback
  576. */
  577. loadConfigsSuccessCallback: function (data) {
  578. var urlParams = this.constructConfigUrlParams(data);
  579. if (urlParams.length > 0) {
  580. App.ajax.send({
  581. name: 'reassign.load_configs',
  582. sender: this,
  583. data: {
  584. urlParams: urlParams.join('|')
  585. },
  586. success: 'saveZkConfigs'
  587. });
  588. return true;
  589. }
  590. return false;
  591. },
  592. /**
  593. * construct URL params for query, that load configs
  594. * @param data {Object}
  595. * @return {Array}
  596. */
  597. constructConfigUrlParams: function (data) {
  598. var urlParams = [];
  599. var services = App.Service.find();
  600. if (App.get('isHaEnabled')) {
  601. urlParams.push('(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')');
  602. }
  603. if (services.someProperty('serviceName', 'HBASE')) {
  604. urlParams.push('(type=hbase-site&tag=' + data.Clusters.desired_configs['hbase-site'].tag + ')');
  605. }
  606. if (services.someProperty('serviceName', 'HIVE')) {
  607. urlParams.push('(type=webhcat-site&tag=' + data.Clusters.desired_configs['webhcat-site'].tag + ')');
  608. urlParams.push('(type=hive-site&tag=' + data.Clusters.desired_configs['hive-site'].tag + ')');
  609. }
  610. if (services.someProperty('serviceName', 'STORM')) {
  611. urlParams.push('(type=storm-site&tag=' + data.Clusters.desired_configs['storm-site'].tag + ')');
  612. }
  613. if (services.someProperty('serviceName', 'SLIDER')) {
  614. urlParams.push('(type=slider-client&tag=' + data.Clusters.desired_configs['slider-client'].tag + ')');
  615. }
  616. if (App.get('isRMHaEnabled')) {
  617. urlParams.push('(type=yarn-site&tag=' + data.Clusters.desired_configs['yarn-site'].tag + ')');
  618. }
  619. return urlParams;
  620. },
  621. /**
  622. * save new ZooKeeper configs to server
  623. * @param {object} data
  624. * @method saveZkConfigs
  625. */
  626. saveZkConfigs: function (data) {
  627. var configs = {};
  628. data.items.forEach(function (item) {
  629. configs[item.type] = item.properties;
  630. }, this);
  631. var zks = this.getZkServerHosts();
  632. var zksWithPort = this.concatZkNames(zks);
  633. this.setZKConfigs(configs, zksWithPort, zks);
  634. for (var site in configs) {
  635. if (!configs.hasOwnProperty(site)) continue;
  636. App.ajax.send({
  637. name: 'reassign.save_configs',
  638. sender: this,
  639. data: {
  640. siteName: site,
  641. properties: configs[site],
  642. service_config_version_note: Em.I18n.t('hosts.host.zooKeeper.configs.save.note')
  643. }
  644. });
  645. }
  646. },
  647. /**
  648. *
  649. * Set new values for some configs (based on available ZooKeeper Servers)
  650. * @param configs {object}
  651. * @param zksWithPort {string}
  652. * @param zks {array}
  653. * @return {Boolean}
  654. */
  655. setZKConfigs: function (configs, zksWithPort, zks) {
  656. if (typeof configs !== 'object' || !Array.isArray(zks)) return false;
  657. if (App.get('isHaEnabled')) {
  658. configs['core-site']['ha.zookeeper.quorum'] = zksWithPort;
  659. }
  660. if (configs['hbase-site']) {
  661. configs['hbase-site']['hbase.zookeeper.quorum'] = zks.join(',');
  662. }
  663. if (configs['webhcat-site']) {
  664. configs['webhcat-site']['templeton.zookeeper.hosts'] = zksWithPort;
  665. }
  666. if (configs['hive-site']) {
  667. if (App.get('isHadoop22Stack')) {
  668. configs['hive-site']['hive.zookeeper.quorum'] = zksWithPort;
  669. }
  670. configs['hive-site']['hive.cluster.delegation.token.store.zookeeper.connectString'] = zksWithPort;
  671. }
  672. if (configs['storm-site']) {
  673. configs['storm-site']['storm.zookeeper.servers'] = JSON.stringify(zks).replace(/"/g, "'");
  674. }
  675. if (configs['slider-client']) {
  676. configs['slider-client']['slider.zookeeper.quorum'] = zksWithPort;
  677. }
  678. if (App.get('isRMHaEnabled')) {
  679. configs['yarn-site']['yarn.resourcemanager.zk-address'] = zks.join(',');
  680. }
  681. return true;
  682. },
  683. /**
  684. * concatenate URLs to ZOOKEEPER hosts with port "2181",
  685. * as value of config divided by comma
  686. * @param zks {array}
  687. */
  688. concatZkNames: function (zks) {
  689. var zks_with_port = '';
  690. zks.forEach(function (zk) {
  691. zks_with_port += zk + ':2181,';
  692. });
  693. return zks_with_port.slice(0, -1);
  694. },
  695. /**
  696. * Is deleteHost action id fired
  697. * @type {bool}
  698. */
  699. fromDeleteHost: false,
  700. /**
  701. * Is ZooKeeper Server being deleted from host
  702. * @type {bool}
  703. */
  704. fromDeleteZkServer: false,
  705. /**
  706. * Get list of hostnames where ZK Server is installed
  707. * @returns {string[]}
  708. * @method getZkServerHosts
  709. */
  710. getZkServerHosts: function () {
  711. var zks = App.HostComponent.find().filterProperty('componentName', 'ZOOKEEPER_SERVER').mapProperty('hostName');
  712. if (this.get('fromDeleteHost') || this.get('fromDeleteZkServer')) {
  713. this.set('fromDeleteHost', false);
  714. this.set('fromDeleteZkServer', false);
  715. return zks.without(this.get('content.hostName'));
  716. }
  717. return zks;
  718. },
  719. /**
  720. * Send command to server to install selected host component
  721. * @param {Object} event
  722. * @method installComponent
  723. */
  724. installComponent: function (event) {
  725. var self = this;
  726. var component = event.context;
  727. var componentName = component.get('componentName');
  728. var displayName = component.get('displayName');
  729. return App.ModalPopup.show({
  730. primary: Em.I18n.t('hosts.host.installComponent.popup.confirm'),
  731. header: Em.I18n.t('popup.confirmation.commonHeader'),
  732. installComponentMessage: function () {
  733. return Em.I18n.t('hosts.host.installComponent.msg').format(displayName);
  734. }.property(),
  735. restartNagiosMsg: Em.View.extend({
  736. template: Em.Handlebars.compile(Em.I18n.t('hosts.host.addComponent.note').format(displayName))
  737. }),
  738. bodyClass: Em.View.extend({
  739. templateName: require('templates/main/host/details/installComponentPopup')
  740. }),
  741. onPrimary: function () {
  742. this.hide();
  743. App.ajax.send({
  744. name: 'common.host.host_component.update',
  745. sender: self,
  746. data: {
  747. hostName: self.get('content.hostName'),
  748. serviceName: component.get('service.serviceName'),
  749. componentName: componentName,
  750. component: component,
  751. context: Em.I18n.t('requestInfo.installHostComponent') + " " + displayName,
  752. HostRoles: {
  753. state: 'INSTALLED'
  754. }
  755. },
  756. success: 'installComponentSuccessCallback',
  757. error: 'ajaxErrorCallback'
  758. });
  759. }
  760. });
  761. },
  762. /**
  763. * Success callback for install component request
  764. * @param {object} data
  765. * @param {object} opt
  766. * @param {object} params
  767. * @method installComponentSuccessCallback
  768. */
  769. installComponentSuccessCallback: function (data, opt, params) {
  770. console.log('Send request for REINSTALL COMPONENT successfully');
  771. if (App.get('testMode')) {
  772. this.mimicWorkStatusChange(params.component, App.HostComponentStatus.installing, App.HostComponentStatus.stopped);
  773. }
  774. this.showBackgroundOperationsPopup();
  775. },
  776. /**
  777. * Send command to server to run decommission on DATANODE, TASKTRACKER, NODEMANAGER, REGIONSERVER
  778. * @param {App.HostComponent} component
  779. * @method decommission
  780. */
  781. decommission: function (component) {
  782. var self = this;
  783. return App.showConfirmationPopup(function () {
  784. self.runDecommission.call(self, self.get('content.hostName'), component.get('service.serviceName'));
  785. });
  786. },
  787. /**
  788. * identify correct component to run decommission on them by service name,
  789. * in result run proper decommission method
  790. * @param hostName
  791. * @param svcName
  792. */
  793. runDecommission: function (hostName, svcName) {
  794. switch (svcName) {
  795. case 'HDFS':
  796. this.doDecommission(hostName, svcName, "NAMENODE", "DATANODE");
  797. break;
  798. case 'YARN':
  799. this.doDecommission(hostName, svcName, "RESOURCEMANAGER", "NODEMANAGER");
  800. break;
  801. case 'MAPREDUCE':
  802. this.doDecommission(hostName, svcName, "JOBTRACKER", "TASKTRACKER");
  803. break;
  804. case 'HBASE':
  805. this.warnBeforeDecommission(hostName);
  806. }
  807. },
  808. /**
  809. * Send command to server to run recommission on DATANODE, TASKTRACKER, NODEMANAGER
  810. * @param {App.HostComponent} component
  811. * @method recommission
  812. */
  813. recommission: function (component) {
  814. var self = this;
  815. App.showConfirmationPopup(function () {
  816. self.runRecommission.call(self, self.get('content.hostName'), component.get('service.serviceName'));
  817. });
  818. },
  819. /**
  820. * identify correct component to run recommission on them by service name,
  821. * in result run proper recommission method
  822. * @param hostName
  823. * @param svcName
  824. */
  825. runRecommission: function (hostName, svcName) {
  826. switch (svcName) {
  827. case 'HDFS':
  828. this.doRecommissionAndStart(hostName, svcName, "NAMENODE", "DATANODE");
  829. break;
  830. case 'YARN':
  831. this.doRecommissionAndStart(hostName, svcName, "RESOURCEMANAGER", "NODEMANAGER");
  832. break;
  833. case 'MAPREDUCE':
  834. this.doRecommissionAndRestart(hostName, svcName, "JOBTRACKER", "TASKTRACKER");
  835. break;
  836. case 'HBASE':
  837. this.doRecommissionAndStart(hostName, svcName, "HBASE_MASTER", "HBASE_REGIONSERVER");
  838. }
  839. this.showBackgroundOperationsPopup();
  840. },
  841. /**
  842. * Performs Decommission (for DN, TT and NM)
  843. * @param {string} hostName
  844. * @param {string} serviceName
  845. * @param {string} componentName
  846. * @param {string} slaveType
  847. * @method doDecommission
  848. */
  849. doDecommission: function (hostName, serviceName, componentName, slaveType) {
  850. var contextNameString = 'hosts.host.' + slaveType.toLowerCase() + '.decommission';
  851. var context = Em.I18n.t(contextNameString);
  852. App.ajax.send({
  853. name: 'host.host_component.decommission_slave',
  854. sender: this,
  855. data: {
  856. context: context,
  857. command: 'DECOMMISSION',
  858. hostName: hostName,
  859. serviceName: serviceName,
  860. componentName: componentName,
  861. slaveType: slaveType
  862. },
  863. success: 'decommissionSuccessCallback',
  864. error: 'decommissionErrorCallback'
  865. });
  866. },
  867. /**
  868. * check is hbase regionserver in mm. If so - run decommission
  869. * otherwise shows warning
  870. * @method warnBeforeDecommission
  871. * @param {string} hostNames - list of host when run from bulk operations or current host
  872. */
  873. warnBeforeDecommission: function (hostNames) {
  874. if (this.get('content.hostComponents').findProperty('componentName', 'HBASE_REGIONSERVER').get('passiveState') == "OFF") {
  875. this.showHbaseActiveWarning();
  876. } else {
  877. this.checkRegionServerState(hostNames);
  878. }
  879. },
  880. /**
  881. * send call to check is this regionserver last in cluster which has desired_admin_state property "INSERVICE"
  882. * @method checkRegionServerState
  883. * @param hostNames
  884. */
  885. checkRegionServerState: function (hostNames) {
  886. return App.ajax.send({
  887. name: 'host.region_servers.in_inservice',
  888. sender: this,
  889. data: {
  890. hostNames: hostNames
  891. },
  892. success: 'checkRegionServerStateSuccessCallback'
  893. });
  894. },
  895. /**
  896. * check is this regionserver last in cluster which has desired_admin_state property "INSERVICE"
  897. * @method checkRegionServerStateSuccessCallback
  898. * @param data
  899. * @param opt
  900. * @param params
  901. */
  902. checkRegionServerStateSuccessCallback: function (data, opt, params) {
  903. var hostArray = params.hostNames.split(",");
  904. var decommissionPossible = (data.items.mapProperty('HostRoles.host_name').filter(function (hostName) {
  905. return !hostArray.contains(hostName);
  906. }, this).length >= 1);
  907. if (decommissionPossible) {
  908. this.doDecommissionRegionServer(params.hostNames, "HBASE", "HBASE_MASTER", "HBASE_REGIONSERVER");
  909. } else {
  910. this.showRegionServerWarning();
  911. }
  912. },
  913. /**
  914. * show warning that regionserver is last in cluster which has desired_admin_state property "INSERVICE"
  915. * @method showRegionServerWarning
  916. * @param hostNames
  917. */
  918. showRegionServerWarning: function () {
  919. return App.ModalPopup.show({
  920. header: Em.I18n.t('common.warning'),
  921. message: Em.I18n.t('hosts.host.hbase_regionserver.decommission.warning'),
  922. bodyClass: Ember.View.extend({
  923. template: Em.Handlebars.compile('<div class="alert alert-warning">{{message}}</div>')
  924. }),
  925. secondary: false
  926. });
  927. },
  928. /**
  929. * shows warning: put hbase regionserver in passive state
  930. * @method showHbaseActiveWarning
  931. * @return {App.ModalPopup}
  932. */
  933. showHbaseActiveWarning: function () {
  934. return App.ModalPopup.show({
  935. header: Em.I18n.t('common.warning'),
  936. message: function () {
  937. return Em.I18n.t('hostPopup.recommendation.beforeDecommission').format(App.format.components["HBASE_REGIONSERVER"]);
  938. }.property(),
  939. bodyClass: Ember.View.extend({
  940. template: Em.Handlebars.compile('<div class="alert alert-warning">{{message}}</div>')
  941. }),
  942. secondary: false
  943. });
  944. },
  945. /**
  946. * Performs Decommission (for RegionServer)
  947. * @method doDecommissionRegionServer
  948. * @param {string} hostNames - list of host when run from bulk operations or current host
  949. * @param {string} serviceName - serviceName
  950. * @param {string} componentName - master compoent name
  951. * @param {string} slaveType - slave component name
  952. */
  953. doDecommissionRegionServer: function (hostNames, serviceName, componentName, slaveType) {
  954. var batches = [
  955. {
  956. "order_id": 1,
  957. "type": "POST",
  958. "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName') + "/requests",
  959. "RequestBodyInfo": {
  960. "RequestInfo": {
  961. "context": Em.I18n.t('hosts.host.regionserver.decommission.batch1'),
  962. "command": "DECOMMISSION",
  963. "exclusive" :"true",
  964. "parameters": {
  965. "slave_type": slaveType,
  966. "excluded_hosts": hostNames
  967. },
  968. 'operation_level': {
  969. level: "HOST_COMPONENT",
  970. cluster_name: App.get('clusterName'),
  971. host_name: hostNames,
  972. service_name: serviceName
  973. }
  974. },
  975. "Requests/resource_filters": [
  976. {"service_name": serviceName, "component_name": componentName}
  977. ]
  978. }
  979. }];
  980. var id = 2;
  981. var hAray = hostNames.split(",");
  982. for (var i = 0; i < hAray.length; i++) {
  983. batches.push({
  984. "order_id": id,
  985. "type": "PUT",
  986. "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName') + "/hosts/" + hAray[i] + "/host_components/" + slaveType,
  987. "RequestBodyInfo": {
  988. "RequestInfo": {
  989. context: Em.I18n.t('hosts.host.regionserver.decommission.batch2'),
  990. exclusive: true,
  991. operation_level: {
  992. level: "HOST_COMPONENT",
  993. cluster_name: App.get('clusterName'),
  994. host_name: hostNames,
  995. service_name: serviceName || null
  996. }
  997. },
  998. "Body": {
  999. HostRoles: {
  1000. state: "INSTALLED"
  1001. }
  1002. }
  1003. }
  1004. });
  1005. id++
  1006. }
  1007. batches.push({
  1008. "order_id": id,
  1009. "type": "POST",
  1010. "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName') + "/requests",
  1011. "RequestBodyInfo": {
  1012. "RequestInfo": {
  1013. "context": Em.I18n.t('hosts.host.regionserver.decommission.batch3'),
  1014. "command": "DECOMMISSION",
  1015. "service_name": serviceName,
  1016. "component_name": componentName,
  1017. "parameters": {
  1018. "slave_type": slaveType,
  1019. "excluded_hosts": hostNames,
  1020. "mark_draining_only": true
  1021. },
  1022. 'operation_level': {
  1023. level: "HOST_COMPONENT",
  1024. cluster_name: App.get('clusterName'),
  1025. host_name: hostNames,
  1026. service_name: serviceName
  1027. }
  1028. },
  1029. "Requests/resource_filters": [
  1030. {"service_name": serviceName, "component_name": componentName}
  1031. ]
  1032. }
  1033. });
  1034. App.ajax.send({
  1035. name: 'host.host_component.recommission_and_restart',
  1036. sender: this,
  1037. data: {
  1038. intervalTimeSeconds: 1,
  1039. tolerateSize: 0,
  1040. batches: batches
  1041. },
  1042. success: 'decommissionSuccessCallback',
  1043. error: 'decommissionErrorCallback'
  1044. });
  1045. },
  1046. /**
  1047. * Error callback for decommission requests
  1048. * @param {object} request
  1049. * @param {object} ajaxOptions
  1050. * @param {string} error
  1051. * @method decommissionErrorCallback
  1052. */
  1053. decommissionErrorCallback: function (request, ajaxOptions, error) {
  1054. console.log('ERROR: ' + error);
  1055. },
  1056. /**
  1057. * Success ajax response for Recommission/Decommission slaves
  1058. * @param {object} data
  1059. * @method decommissionSuccessCallback
  1060. * @return {Boolean}
  1061. */
  1062. decommissionSuccessCallback: function (data) {
  1063. if (data && (data.Requests || data.resources[0].RequestSchedule)) {
  1064. this.showBackgroundOperationsPopup();
  1065. return true;
  1066. } else {
  1067. console.log('cannot get request id from ', data);
  1068. return false;
  1069. }
  1070. },
  1071. /**
  1072. * Performs Recommission and Start
  1073. * @param {string} hostNames
  1074. * @param {string} serviceName
  1075. * @param {string} componentName
  1076. * @param {string} slaveType
  1077. * @method doRecommissionAndStart
  1078. */
  1079. doRecommissionAndStart: function (hostNames, serviceName, componentName, slaveType) {
  1080. var contextNameString_1 = 'hosts.host.' + slaveType.toLowerCase() + '.recommission';
  1081. var context_1 = Em.I18n.t(contextNameString_1);
  1082. var contextNameString_2 = 'requestInfo.startHostComponent.' + slaveType.toLowerCase();
  1083. var startContext = Em.I18n.t(contextNameString_2);
  1084. var params = {
  1085. "slave_type": slaveType,
  1086. "included_hosts": hostNames
  1087. };
  1088. if (serviceName == "HBASE") {
  1089. params.mark_draining_only = true;
  1090. }
  1091. var batches = [
  1092. {
  1093. "order_id": 1,
  1094. "type": "POST",
  1095. "uri": App.apiPrefix + "/clusters/" + App.get('clusterName') + "/requests",
  1096. "RequestBodyInfo": {
  1097. "RequestInfo": {
  1098. "context": context_1,
  1099. "command": "DECOMMISSION",
  1100. "exclusive":"true",
  1101. "parameters": params,
  1102. 'operation_level': {
  1103. level: "HOST_COMPONENT",
  1104. cluster_name: App.get('clusterName'),
  1105. host_name: hostNames,
  1106. service_name: serviceName
  1107. }
  1108. },
  1109. "Requests/resource_filters": [
  1110. {"service_name": serviceName, "component_name": componentName}
  1111. ]
  1112. }
  1113. }];
  1114. var id = 2;
  1115. var hAray = hostNames.split(",");
  1116. for (var i = 0; i < hAray.length; i++) {
  1117. batches.push( {
  1118. "order_id": id,
  1119. "type": "PUT",
  1120. "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName') + "/hosts/" + hAray[i] + "/host_components/" + slaveType,
  1121. "RequestBodyInfo": {
  1122. "RequestInfo": {
  1123. context: startContext,
  1124. operation_level: {
  1125. level: "HOST_COMPONENT",
  1126. cluster_name: App.get('clusterName'),
  1127. host_name: hostNames,
  1128. service_name: serviceName || null
  1129. }
  1130. },
  1131. "Body": {
  1132. HostRoles: {
  1133. state: "STARTED"
  1134. }
  1135. }
  1136. }
  1137. });
  1138. id++;
  1139. }
  1140. App.ajax.send({
  1141. name: 'host.host_component.recommission_and_restart',
  1142. sender: this,
  1143. data: {
  1144. intervalTimeSeconds: 1,
  1145. tolerateSize: 1,
  1146. batches: batches
  1147. },
  1148. success: 'decommissionSuccessCallback',
  1149. error: 'decommissionErrorCallback'
  1150. });
  1151. },
  1152. /**
  1153. * Performs Recommission and Restart
  1154. * @param {string} hostNames
  1155. * @param {string} serviceName
  1156. * @param {string} componentName
  1157. * @param {string} slaveType
  1158. * @method doRecommissionAndStart
  1159. */
  1160. doRecommissionAndRestart: function (hostNames, serviceName, componentName, slaveType) {
  1161. var contextNameString_1 = 'hosts.host.' + slaveType.toLowerCase() + '.recommission';
  1162. var context_1 = Em.I18n.t(contextNameString_1);
  1163. var contextNameString_2 = 'hosts.host.' + slaveType.toLowerCase() + '.restart';
  1164. var context_2 = Em.I18n.t(contextNameString_2);
  1165. App.ajax.send({
  1166. name: 'host.host_component.recommission_and_restart',
  1167. sender: this,
  1168. data: {
  1169. intervalTimeSeconds: 1,
  1170. tolerateSize: 1,
  1171. batches: [
  1172. {
  1173. "order_id": 1,
  1174. "type": "POST",
  1175. "uri": App.apiPrefix + "/clusters/" + App.get('clusterName') + "/requests",
  1176. "RequestBodyInfo": {
  1177. "RequestInfo": {
  1178. "context": context_1,
  1179. "command": "DECOMMISSION",
  1180. "exclusive":"true",
  1181. "parameters": {
  1182. "slave_type": slaveType,
  1183. "included_hosts": hostNames
  1184. },
  1185. 'operation_level': {
  1186. level: "HOST_COMPONENT",
  1187. cluster_name: App.get('clusterName'),
  1188. host_name: hostNames,
  1189. service_name: serviceName
  1190. }
  1191. },
  1192. "Requests/resource_filters": [
  1193. {"service_name": serviceName, "component_name": componentName}
  1194. ]
  1195. }
  1196. },
  1197. {
  1198. "order_id": 2,
  1199. "type": "POST",
  1200. "uri": App.apiPrefix + "/clusters/" + App.get('clusterName') + "/requests",
  1201. "RequestBodyInfo": {
  1202. "RequestInfo": {
  1203. "context": context_2,
  1204. "command": "RESTART",
  1205. "service_name": serviceName,
  1206. "component_name": slaveType,
  1207. "exclusive":"true",
  1208. "hosts": hostNames
  1209. }
  1210. }
  1211. }
  1212. ]
  1213. },
  1214. success: 'decommissionSuccessCallback',
  1215. error: 'decommissionErrorCallback'
  1216. });
  1217. },
  1218. /**
  1219. * Handler for host-menu items actions
  1220. * @param {object} option
  1221. * @method doAction
  1222. */
  1223. doAction: function (option) {
  1224. switch (option.context.action) {
  1225. case "deleteHost":
  1226. this.validateAndDeleteHost();
  1227. break;
  1228. case "startAllComponents":
  1229. if (!this.get('content.isNotHeartBeating')) this.doStartAllComponents();
  1230. break;
  1231. case "stopAllComponents":
  1232. if (!this.get('content.isNotHeartBeating')) this.doStopAllComponents();
  1233. break;
  1234. case "restartAllComponents":
  1235. if (!this.get('content.isNotHeartBeating')) this.doRestartAllComponents();
  1236. break;
  1237. case "onOffPassiveModeForHost":
  1238. this.onOffPassiveModeForHost(option.context);
  1239. break;
  1240. default:
  1241. break;
  1242. }
  1243. },
  1244. /**
  1245. * Turn On/Off Passive Mode for host
  1246. * @param {object} context
  1247. * @method onOffPassiveModeForHost
  1248. */
  1249. onOffPassiveModeForHost: function (context) {
  1250. var state = context.active ? 'ON' : 'OFF';
  1251. var self = this;
  1252. var message = Em.I18n.t('hosts.host.details.for.postfix').format(context.label);
  1253. return App.showConfirmationPopup(function () {
  1254. self.hostPassiveModeRequest(state, message);
  1255. },
  1256. Em.I18n.t('hosts.passiveMode.popup').format(context.active ? 'On' : 'Off', this.get('content.hostName'))
  1257. );
  1258. },
  1259. /**
  1260. * Send request to get passive state for host
  1261. * @param {string} state
  1262. * @param {string} message
  1263. * @method hostPassiveModeRequest
  1264. */
  1265. hostPassiveModeRequest: function (state, message) {
  1266. App.ajax.send({
  1267. name: 'bulk_request.hosts.passive_state',
  1268. sender: this,
  1269. data: {
  1270. hostNames: this.get('content.hostName'),
  1271. passive_state: state,
  1272. requestInfo: message
  1273. },
  1274. success: 'updateHost'
  1275. });
  1276. },
  1277. /**
  1278. * Success callback for receiving host passive state
  1279. * @param {object} data
  1280. * @param {object} opt
  1281. * @param {object} params
  1282. * @method updateHost
  1283. */
  1284. updateHost: function (data, opt, params) {
  1285. this.set('content.passiveState', params.passive_state);
  1286. batchUtils.infoPassiveState(params.passive_state);
  1287. },
  1288. /**
  1289. * Send request to get passive state for hostComponent
  1290. * @param {object} component - hostComponentn object
  1291. * @param {string} state
  1292. * @param {string} message
  1293. * @method hostPassiveModeRequest
  1294. */
  1295. updateComponentPassiveState: function (component, state, message) {
  1296. App.ajax.send({
  1297. name: 'common.host.host_component.passive',
  1298. sender: this,
  1299. data: {
  1300. hostName: this.get('content.hostName'),
  1301. componentName: component.get('componentName'),
  1302. component: component,
  1303. passive_state: state,
  1304. context: message
  1305. },
  1306. success: 'updateHostComponent'
  1307. });
  1308. },
  1309. /**
  1310. * Success callback for receiving hostComponent passive state
  1311. * @param {object} data
  1312. * @param {object} opt
  1313. * @param {object} params
  1314. * @method updateHost
  1315. */
  1316. updateHostComponent: function (data, opt, params) {
  1317. params.component.set('passiveState', params.passive_state)
  1318. batchUtils.infoPassiveState(params.passive_state);
  1319. },
  1320. /**
  1321. * Show confirmation popup for action "start all components"
  1322. * @method doStartAllComponents
  1323. */
  1324. doStartAllComponents: function () {
  1325. var self = this;
  1326. var components = this.get('serviceNonClientActiveComponents');
  1327. var componentsLength = Em.isNone(components) ? 0 : components.get('length');
  1328. if (componentsLength > 0) {
  1329. return App.showConfirmationPopup(function () {
  1330. self.sendComponentCommand(components, Em.I18n.t('hosts.host.maintainance.startAllComponents.context'), App.HostComponentStatus.started);
  1331. });
  1332. }
  1333. },
  1334. /**
  1335. * Show confirmation popup for action "stop all components"
  1336. * @method doStopAllComponents
  1337. */
  1338. doStopAllComponents: function () {
  1339. var self = this;
  1340. var components = this.get('serviceNonClientActiveComponents');
  1341. var componentsLength = Em.isNone(components) ? 0 : components.get('length');
  1342. if (componentsLength > 0) {
  1343. return App.showConfirmationPopup(function () {
  1344. self.sendComponentCommand(components, Em.I18n.t('hosts.host.maintainance.stopAllComponents.context'), App.HostComponentStatus.stopped);
  1345. });
  1346. }
  1347. },
  1348. /**
  1349. * Show confirmation popup for action "restart all components"
  1350. * @method doRestartAllComponents
  1351. */
  1352. doRestartAllComponents: function () {
  1353. var self = this;
  1354. var components = this.get('serviceActiveComponents');
  1355. var componentsLength = Em.isNone(components) ? 0 : components.get('length');
  1356. if (componentsLength > 0) {
  1357. App.showConfirmationPopup(function () {
  1358. batchUtils.restartHostComponents(components, Em.I18n.t('rollingrestart.context.allOnSelectedHost').format(self.get('content.hostName')), "HOST");
  1359. });
  1360. }
  1361. },
  1362. /**
  1363. * get info about host-components, exactly:
  1364. * - host-components grouped by status, features
  1365. * - flag, that indicate whether ZooKeeper Server is installed
  1366. * @return {Object}
  1367. */
  1368. getHostComponentsInfo: function () {
  1369. var componentsOnHost = this.get('content.hostComponents');
  1370. var allComponents = App.HostComponent.find();
  1371. var stoppedStates = [App.HostComponentStatus.stopped,
  1372. App.HostComponentStatus.install_failed,
  1373. App.HostComponentStatus.upgrade_failed,
  1374. App.HostComponentStatus.init,
  1375. App.HostComponentStatus.unknown];
  1376. var container = {
  1377. zkServerInstalled: false,
  1378. lastComponents: [],
  1379. masterComponents: [],
  1380. runningComponents: [],
  1381. nonDeletableComponents: [],
  1382. unknownComponents: []
  1383. };
  1384. if (componentsOnHost && componentsOnHost.get('length') > 0) {
  1385. componentsOnHost.forEach(function (cInstance) {
  1386. if (cInstance.get('componentName') === 'ZOOKEEPER_SERVER') {
  1387. container.zkServerInstalled = true;
  1388. }
  1389. if (allComponents.filterProperty('componentName', cInstance.get('componentName')).get('length') === 1) {
  1390. container.lastComponents.push(cInstance.get('displayName'));
  1391. }
  1392. var workStatus = cInstance.get('workStatus');
  1393. if (cInstance.get('isMaster') && !cInstance.get('isDeletable')) {
  1394. container.masterComponents.push(cInstance.get('displayName'));
  1395. }
  1396. if (stoppedStates.indexOf(workStatus) < 0) {
  1397. container.runningComponents.push(cInstance.get('displayName'));
  1398. }
  1399. if (!cInstance.get('isDeletable')) {
  1400. container.nonDeletableComponents.push(cInstance.get('displayName'));
  1401. }
  1402. if (workStatus === App.HostComponentStatus.unknown) {
  1403. container.unknownComponents.push(cInstance.get('displayName'));
  1404. }
  1405. });
  1406. }
  1407. return container;
  1408. },
  1409. /**
  1410. * Deletion of hosts not supported for this version
  1411. * @method validateAndDeleteHost
  1412. */
  1413. validateAndDeleteHost: function () {
  1414. if (!App.supports.deleteHost) {
  1415. return false;
  1416. }
  1417. var container = this.getHostComponentsInfo();
  1418. if (container.masterComponents.length > 0) {
  1419. this.raiseDeleteComponentsError(container.masterComponents, 'masterList');
  1420. return;
  1421. } else if (container.nonDeletableComponents.length > 0) {
  1422. this.raiseDeleteComponentsError(container.nonDeletableComponents, 'nonDeletableList');
  1423. return;
  1424. } else if (container.runningComponents.length > 0) {
  1425. this.raiseDeleteComponentsError(container.runningComponents, 'runningList');
  1426. return;
  1427. }
  1428. if (container.zkServerInstalled) {
  1429. var self = this;
  1430. return App.showConfirmationPopup(function () {
  1431. self._doDeleteHost(container.unknownComponents, container.lastComponents);
  1432. }, Em.I18n.t('hosts.host.addComponent.deleteHostWithZooKeeper'));
  1433. } else {
  1434. this._doDeleteHost(container.unknownComponents, container.lastComponents);
  1435. }
  1436. },
  1437. /**
  1438. * Show popup with info about reasons why host can't be deleted
  1439. * @param {string[]} components
  1440. * @param {string} type
  1441. * @method raiseDeleteComponentsError
  1442. */
  1443. raiseDeleteComponentsError: function (components, type) {
  1444. App.ModalPopup.show({
  1445. header: Em.I18n.t('hosts.cant.do.popup.title'),
  1446. type: type,
  1447. showBodyEnd: function () {
  1448. return this.get('type') === 'runningList' || this.get('type') === 'masterList';
  1449. }.property(),
  1450. components: components,
  1451. componentsStr: function () {
  1452. return this.get('components').join(", ");
  1453. }.property(),
  1454. componentsBody: function () {
  1455. return Em.I18n.t('hosts.cant.do.popup.' + type + '.body').format(this.get('components').length);
  1456. }.property(),
  1457. componentsBodyEnd: function () {
  1458. if (this.get('showBodyEnd')) {
  1459. return Em.I18n.t('hosts.cant.do.popup.' + type + '.body.end');
  1460. }
  1461. return '';
  1462. }.property(),
  1463. bodyClass: Em.View.extend({
  1464. templateName: require('templates/main/host/details/raiseDeleteComponentErrorPopup')
  1465. }),
  1466. secondary: null
  1467. })
  1468. },
  1469. /**
  1470. * Show confirmation popup to delete host
  1471. * @param {string[]} unknownComponents
  1472. * @param {string[]} lastComponents
  1473. * @method _doDeleteHost
  1474. */
  1475. _doDeleteHost: function (unknownComponents, lastComponents) {
  1476. var self = this;
  1477. App.ModalPopup.show({
  1478. header: Em.I18n.t('hosts.delete.popup.title'),
  1479. deletePopupBody: function () {
  1480. return Em.I18n.t('hosts.delete.popup.body').format(self.get('content.publicHostName'));
  1481. }.property(),
  1482. lastComponent: function () {
  1483. if (lastComponents && lastComponents.length) {
  1484. this.set('isChecked', false);
  1485. return true;
  1486. } else {
  1487. this.set('isChecked', true);
  1488. return false;
  1489. }
  1490. }.property(),
  1491. disablePrimary: function () {
  1492. return !this.get('isChecked');
  1493. }.property('isChecked'),
  1494. isChecked: false,
  1495. lastComponentError: Em.View.extend({
  1496. template: Em.Handlebars.compile(Em.I18n.t('hosts.delete.popup.body.msg4').format(lastComponents))
  1497. }),
  1498. unknownComponents: function () {
  1499. if (unknownComponents && unknownComponents.length) {
  1500. return unknownComponents.join(", ");
  1501. }
  1502. return '';
  1503. }.property(),
  1504. bodyClass: Em.View.extend({
  1505. templateName: require('templates/main/host/details/doDeleteHostPopup')
  1506. }),
  1507. onPrimary: function () {
  1508. self.set('fromDeleteHost', true);
  1509. var allComponents = self.get('content.hostComponents');
  1510. var deleteError = null;
  1511. var dfd = $.Deferred();
  1512. var popup = this;
  1513. allComponents.forEach(function (component, index) {
  1514. var length = allComponents.get('length');
  1515. if (!deleteError) {
  1516. self._doDeleteHostComponent(component, function () {
  1517. deleteError = self.get('_deletedHostComponentResult');
  1518. if (index == length - 1) {
  1519. dfd.resolve();
  1520. }
  1521. });
  1522. }
  1523. });
  1524. dfd.done(function () {
  1525. if (!deleteError) {
  1526. App.ajax.send({
  1527. name: 'common.delete.host',
  1528. sender: popup,
  1529. data: {
  1530. hostName: self.get('content.hostName')
  1531. },
  1532. success: 'deleteHostSuccessCallback',
  1533. error: 'deleteHostErrorCallback'
  1534. });
  1535. }
  1536. else {
  1537. popup.hide();
  1538. deleteError.xhr.responseText = "{\"message\": \"" + deleteError.xhr.statusText + "\"}";
  1539. App.ajax.defaultErrorHandler(deleteError.xhr, deleteError.url, deleteError.method, deleteError.xhr.status);
  1540. }
  1541. });
  1542. },
  1543. deleteHostSuccessCallback: function (data) {
  1544. var dialogSelf = this;
  1545. App.router.get('updateController').updateHost(function () {
  1546. self.loadConfigs();
  1547. dialogSelf.hide();
  1548. App.router.transitionTo('hosts.index');
  1549. });
  1550. App.router.get('clusterController').getAllHostNames();
  1551. },
  1552. deleteHostErrorCallback: function (xhr, textStatus, errorThrown, opt) {
  1553. console.log('Error deleting host.');
  1554. console.log(textStatus);
  1555. console.log(errorThrown);
  1556. xhr.responseText = "{\"message\": \"" + xhr.statusText + "\"}";
  1557. self.loadConfigs();
  1558. this.hide();
  1559. App.ajax.defaultErrorHandler(xhr, opt.url, 'DELETE', xhr.status);
  1560. }
  1561. })
  1562. },
  1563. /**
  1564. * Send command to server to restart all host components with stale configs
  1565. * @method restartAllStaleConfigComponents
  1566. */
  1567. restartAllStaleConfigComponents: function () {
  1568. var self = this;
  1569. return App.showConfirmationPopup(function () {
  1570. var staleComponents = self.get('content.componentsWithStaleConfigs');
  1571. batchUtils.restartHostComponents(staleComponents, Em.I18n.t('rollingrestart.context.allWithStaleConfigsOnSelectedHost').format(self.get('content.hostName')), "HOST");
  1572. });
  1573. },
  1574. /**
  1575. * open Reassign Master Wizard with selected component
  1576. * @param {object} event
  1577. * @method moveComponent
  1578. */
  1579. moveComponent: function (event) {
  1580. App.showConfirmationPopup(function () {
  1581. var component = event.context;
  1582. var reassignMasterController = App.router.get('reassignMasterController');
  1583. reassignMasterController.saveComponentToReassign(component);
  1584. reassignMasterController.getSecurityStatus();
  1585. reassignMasterController.setCurrentStep('1');
  1586. App.router.transitionTo('reassign');
  1587. });
  1588. },
  1589. /**
  1590. * Restart clients host components to apply config changes
  1591. * @param {object} event
  1592. * @method refreshConfigs
  1593. */
  1594. refreshConfigs: function (event) {
  1595. var self = this;
  1596. var components = event.context.filter(function (component) {
  1597. return component.get('staleConfigs');
  1598. });
  1599. if (components.get('length') > 0) {
  1600. return App.showConfirmationPopup(function () {
  1601. batchUtils.restartHostComponents(components, Em.I18n.t('rollingrestart.context.allClientsOnSelectedHost').format(self.get('content.hostName')), "HOST");
  1602. });
  1603. }
  1604. },
  1605. toggleMaintenanceMode: function (event) {
  1606. var self = this;
  1607. var state = event.context.get('passiveState') === "ON" ? "OFF" : "ON";
  1608. var message = Em.I18n.t('passiveState.turn' + state.toCapital() + 'For').format(event.context.get('displayName'));
  1609. return App.showConfirmationPopup(function () {
  1610. self.updateComponentPassiveState(event.context, state, message);
  1611. });
  1612. },
  1613. downloadClientConfigs: function (event) {
  1614. componentsUtils.downloadClientConfigs.call(this, {
  1615. hostName: event.context.get('hostName'),
  1616. componentName: event.context.get('componentName'),
  1617. displayName: event.context.get('displayName')
  1618. });
  1619. },
  1620. reinstallClients: function(event) {
  1621. var clientsToInstall = event.context.filter(function(component) {
  1622. return ['INIT', 'INSTALL_FAILED'].contains(component.get('workStatus'));
  1623. });
  1624. if (!clientsToInstall.length) return;
  1625. this.sendComponentCommand(clientsToInstall, Em.I18n.t('host.host.details.installClients'), 'INSTALLED');
  1626. },
  1627. /**
  1628. * On click handler for custom command from items menu
  1629. * @param context
  1630. */
  1631. executeCustomCommand: function(event) {
  1632. var controller = this;
  1633. var context = event.context;
  1634. return App.showConfirmationPopup(function() {
  1635. App.ajax.send({
  1636. name : 'service.item.executeCustomCommand',
  1637. sender: controller,
  1638. data : {
  1639. command : context.command,
  1640. context : Em.I18n.t('services.service.actions.run.executeCustomCommand.context').format(context.command),
  1641. hosts : context.hosts,
  1642. serviceName : context.service,
  1643. componentName : context.component
  1644. },
  1645. success : 'executeCustomCommandSuccessCallback',
  1646. error : 'executeCustomCommandErrorCallback'
  1647. });
  1648. });
  1649. },
  1650. executeCustomCommandSuccessCallback : function(data, ajaxOptions, params) {
  1651. if (data.Requests.id) {
  1652. App.router.get('backgroundOperationsController').showPopup();
  1653. } else {
  1654. console.warn('Error during execution of ' + params.command + ' custom command on' + params.componentName);
  1655. }
  1656. },
  1657. executeCustomCommandErrorCallback : function(data) {
  1658. var error = Em.I18n.t('services.service.actions.run.executeCustomCommand.error');
  1659. if(data && data.responseText){
  1660. try {
  1661. var json = $.parseJSON(data.responseText);
  1662. error += json.message;
  1663. } catch (err) {}
  1664. }
  1665. App.showAlertPopup(Em.I18n.t('services.service.actions.run.executeCustomCommand.error'), error);
  1666. console.warn('Error during executing custom command');
  1667. }
  1668. });