details.js 66 KB

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