details.js 51 KB

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