details.js 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500
  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 hostsManagement = require('utils/hosts');
  21. var stringUtils = require('utils/string_utils');
  22. require('utils/configs/add_component_config_initializer');
  23. App.MainHostDetailsController = Em.Controller.extend(App.SupportClientConfigsDownload, App.InstallComponent, App.InstallNewVersion, {
  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. * Are we adding hive server2 component
  37. * @type {bool}
  38. */
  39. addHiveServer: false,
  40. /**
  41. * path to page visited before
  42. * @type {string}
  43. */
  44. referer: '',
  45. /**
  46. * Host on which Hive Metastore will be added
  47. * @type {string}
  48. */
  49. hiveMetastoreHost: '',
  50. /**
  51. * Deferred object will be resolved when Oozie configs are downloaded
  52. * @type {object}
  53. */
  54. isOozieConfigLoaded: $.Deferred(),
  55. /**
  56. * @type {bool}
  57. */
  58. isOozieServerAddable: true,
  59. /**
  60. * Open dashboard page
  61. * @method routeHome
  62. */
  63. routeHome: function () {
  64. App.router.transitionTo('main.dashboard.index');
  65. },
  66. /**
  67. * List of active (not in passive state) host components
  68. * @type {Ember.Enumerable}
  69. */
  70. serviceActiveComponents: function () {
  71. return this.get('content.hostComponents').filterProperty('service.isInPassive', false);
  72. }.property('content.hostComponents'),
  73. /**
  74. * List of active host components which aren't clients
  75. * @type {Ember.Enumerable}
  76. */
  77. serviceNonClientActiveComponents: Em.computed.filterBy('serviceActiveComponents', 'isClient', false),
  78. /**
  79. * send command to server to start selected host component
  80. * @param {object} event
  81. * @method startComponent
  82. */
  83. startComponent: function (event) {
  84. var self = this;
  85. return App.showConfirmationPopup(function () {
  86. var component = event.context;
  87. var context = Em.I18n.t('requestInfo.startHostComponent') + " " + component.get('displayName');
  88. self.sendComponentCommand(component, context, App.HostComponentStatus.started);
  89. });
  90. },
  91. /**
  92. * send command to server to stop selected host component
  93. * @param {object} event
  94. * @method startComponent
  95. */
  96. stopComponent: function (event) {
  97. var self = this;
  98. if (event.context.get('componentName') == 'NAMENODE' ) {
  99. this.checkNnLastCheckpointTime(function () {
  100. return App.showConfirmationPopup(function () {
  101. var component = event.context;
  102. var context = Em.I18n.t('requestInfo.stopHostComponent') + " " + component.get('displayName');
  103. self.sendComponentCommand(component, context, App.HostComponentStatus.stopped);
  104. });
  105. });
  106. } else {
  107. return App.showConfirmationPopup(function () {
  108. var component = event.context;
  109. var context = Em.I18n.t('requestInfo.stopHostComponent') + " " + component.get('displayName');
  110. self.sendComponentCommand(component, context, App.HostComponentStatus.stopped);
  111. });
  112. }
  113. },
  114. /**
  115. * PUTs a command to server to start/stop a component. If no
  116. * specific component is provided, all components are started.
  117. * @param {object} component When <code>null</code> all startable components are started.
  118. * @param {String} context Context under which this command is beign sent.
  119. * @param {String} state - desired state of component can be 'STARTED' or 'STOPPED'
  120. * @method sendComponentCommand
  121. */
  122. sendComponentCommand: function (component, context, state) {
  123. var data = {
  124. hostName: this.get('content.hostName'),
  125. context: context,
  126. component: component,
  127. HostRoles: {
  128. state: state
  129. }
  130. };
  131. if (Array.isArray(component)) {
  132. data.query = "HostRoles/component_name.in(" + component.mapProperty('componentName').join(',') + ")";
  133. } else {
  134. data.componentName = component.get('componentName');
  135. data.serviceName = component.get('service.serviceName');
  136. }
  137. App.ajax.send({
  138. name: (Array.isArray(component)) ? 'common.host.host_components.update' : 'common.host.host_component.update',
  139. sender: this,
  140. data: data,
  141. success: 'sendComponentCommandSuccessCallback',
  142. error: 'ajaxErrorCallback'
  143. });
  144. },
  145. /**
  146. * Success callback for stop/start host component request
  147. * @param {object} data
  148. * @param {object} opt
  149. * @param {object} params
  150. * @method stopComponentSuccessCallback
  151. */
  152. sendComponentCommandSuccessCallback: function (data, opt, params) {
  153. var running = (params.HostRoles.state === App.HostComponentStatus.stopped) ? App.HostComponentStatus.stopping : App.HostComponentStatus.starting;
  154. params.component.set('workStatus', running);
  155. if (App.get('testMode')) {
  156. this.mimicWorkStatusChange(params.component, running, params.HostRoles.state);
  157. }
  158. this.showBackgroundOperationsPopup();
  159. },
  160. /**
  161. * Return true if hdfs user data is loaded via App.MainServiceInfoConfigsController
  162. */
  163. getHdfsUser: function () {
  164. var self = this;
  165. var dfd = $.Deferred();
  166. var miscController = App.MainAdminServiceAccountsController.create();
  167. miscController.loadUsers();
  168. var interval = setInterval(function () {
  169. if (miscController.get('dataIsLoaded') && miscController.get('users')) {
  170. self.set('hdfsUser', miscController.get('users').findProperty('name', 'hdfs_user').get('value'));
  171. dfd.resolve();
  172. clearInterval(interval);
  173. }
  174. }, 10);
  175. return dfd.promise();
  176. },
  177. /**
  178. * this function will be called from :1) stop NN 2) restart NN 3) stop all components
  179. * @param callback - callback function to continue next operation
  180. * @param hostname - namenode host (by default is current host)
  181. */
  182. checkNnLastCheckpointTime: function(callback, hostName) {
  183. var self = this;
  184. this.pullNnCheckPointTime(hostName).complete(function () {
  185. var isNNCheckpointTooOld = self.get('isNNCheckpointTooOld');
  186. self.set('isNNCheckpointTooOld', null);
  187. if (isNNCheckpointTooOld) {
  188. // too old
  189. self.getHdfsUser().done(function() {
  190. var msg = Em.Object.create({
  191. confirmMsg: Em.I18n.t('services.service.stop.HDFS.warningMsg.checkPointTooOld').format(App.nnCheckpointAgeAlertThreshold) +
  192. Em.I18n.t('services.service.stop.HDFS.warningMsg.checkPointTooOld.instructions').format(isNNCheckpointTooOld, self.get('hdfsUser')),
  193. confirmButton: Em.I18n.t('common.next')
  194. });
  195. return App.showConfirmationFeedBackPopup(callback, msg);
  196. });
  197. } else if (isNNCheckpointTooOld == null) {
  198. // not available
  199. return App.showConfirmationPopup(
  200. callback, Em.I18n.t('services.service.stop.HDFS.warningMsg.checkPointNA'), null,
  201. Em.I18n.t('common.warning'), Em.I18n.t('common.proceedAnyway'), true
  202. );
  203. } else {
  204. // still young
  205. callback();
  206. }
  207. });
  208. },
  209. pullNnCheckPointTime: function (hostName) {
  210. return App.ajax.send({
  211. name: 'common.host_component.getNnCheckPointTime',
  212. sender: this,
  213. data: {
  214. host: hostName || this.get('content.hostName')
  215. },
  216. success: 'parseNnCheckPointTime'
  217. });
  218. },
  219. parseNnCheckPointTime: function (data) {
  220. var lastCheckpointTime = Em.get(data, 'metrics.dfs.FSNamesystem.LastCheckpointTime');
  221. var hostName = Em.get(data, 'HostRoles.host_name');
  222. if (Em.get(data, 'metrics.dfs.FSNamesystem.HAState') == 'active') {
  223. if (!lastCheckpointTime) {
  224. this.set("isNNCheckpointTooOld", null);
  225. } else {
  226. var time_criteria = App.nnCheckpointAgeAlertThreshold; // time in hours to define how many hours ago is too old
  227. var time_ago = (Math.round(App.dateTime() / 1000) - (time_criteria * 3600)) *1000;
  228. if (lastCheckpointTime <= time_ago) {
  229. // too old, set the effected hostName
  230. this.set("isNNCheckpointTooOld", hostName);
  231. } else {
  232. // still young
  233. this.set("isNNCheckpointTooOld", false);
  234. }
  235. }
  236. } else if (Em.get(data, 'metrics.dfs.FSNamesystem.HAState') == 'standby') {
  237. this.set("isNNCheckpointTooOld", false);
  238. }
  239. },
  240. /**
  241. * mimic status transition in test mode
  242. * @param entity
  243. * @param transitionalState
  244. * @param finalState
  245. */
  246. mimicWorkStatusChange: function (entity, transitionalState, finalState) {
  247. if (Em.isArray(entity)) {
  248. entity.forEach(function (item) {
  249. item.set('workStatus', transitionalState);
  250. setTimeout(function () {
  251. item.set('workStatus', finalState);
  252. }, App.testModeDelayForActions);
  253. });
  254. } else {
  255. entity.set('workStatus', transitionalState);
  256. setTimeout(function () {
  257. entity.set('workStatus', finalState);
  258. }, App.testModeDelayForActions);
  259. }
  260. },
  261. /**
  262. * load data (if we need to show this background operations popup) from persist
  263. * @param callback
  264. */
  265. showBackgroundOperationsPopup: function (callback) {
  266. App.router.get('userSettingsController').dataLoading('show_bg').done(function (initValue) {
  267. if (initValue) {
  268. App.router.get('backgroundOperationsController').showPopup();
  269. }
  270. if (typeof callback === 'function') {
  271. callback();
  272. }
  273. });
  274. },
  275. /**
  276. * Send command to server to delete selected host component
  277. * @param {object} event
  278. * @method deleteComponent
  279. */
  280. deleteComponent: function (event) {
  281. if ($(event.target).closest('li').hasClass('disabled')) {
  282. return;
  283. }
  284. var self = this;
  285. var component = event.context;
  286. var componentName = component.get('componentName');
  287. var displayName = component.get('displayName');
  288. var isLastComponent = (this.getTotalComponent(component) === 1);
  289. return App.ModalPopup.show({
  290. header: Em.I18n.t('popup.confirmation.commonHeader'),
  291. primary: Em.I18n.t('hosts.host.deleteComponent.popup.confirm'),
  292. bodyClass: Em.View.extend({
  293. templateName: require('templates/main/host/details/deleteComponentPopup')
  294. }),
  295. isHiveMetastore: componentName == 'HIVE_METASTORE',
  296. isWebHCatServer: componentName == 'WEBHCAT_SERVER',
  297. isNimbus: componentName == 'NIMBUS',
  298. isRangerKMSServer: componentName == 'RANGER_KMS_SERVER',
  299. isZkServer: componentName == 'ZOOKEEPER_SERVER',
  300. deleteHiveMetastoreMsg: Em.I18n.t('hosts.host.deleteComponent.popup.deleteHiveMetastore'),
  301. deleteWebHCatServerMsg: Em.I18n.t('hosts.host.deleteComponent.popup.deleteWebHCatServer'),
  302. deleteNimbusMsg: Em.I18n.t('hosts.host.deleteComponent.popup.deleteNimbus'),
  303. deleteRangerKMSServereMsg: Em.I18n.t('hosts.host.deleteComponent.popup.deleteRangerKMSServer'),
  304. lastComponentError: Em.I18n.t('hosts.host.deleteComponent.popup.warning').format(displayName),
  305. deleteComponentMsg: Em.I18n.t('hosts.host.deleteComponent.popup.msg1').format(displayName),
  306. deleteZkServerMsg: Em.I18n.t('hosts.host.deleteComponent.popup.deleteZooKeeperServer'),
  307. isChecked: false,
  308. disablePrimary: Em.computed.not('isChecked'),
  309. lastComponent: function () {
  310. this.set('isChecked', !isLastComponent);
  311. return isLastComponent;
  312. }.property(),
  313. onPrimary: function () {
  314. var popup = this;
  315. self._doDeleteHostComponent(component, function () {
  316. self.set('redrawComponents', true);
  317. popup.hide();
  318. });
  319. }
  320. });
  321. },
  322. /**
  323. * get total count of host-components
  324. * @method getTotalComponent
  325. * @param component
  326. * @return {Number}
  327. */
  328. getTotalComponent: function (component) {
  329. var count;
  330. if (component.get('isSlave')) {
  331. count = App.SlaveComponent.find(component.get('componentName')).get('totalCount');
  332. } else if (component.get('isClient')) {
  333. count = App.ClientComponent.find(component.get('componentName')).get('totalCount');
  334. } else {
  335. count = App.HostComponent.find().filterProperty('componentName', component.get('componentName')).get('length');
  336. }
  337. return count || 0;
  338. },
  339. /**
  340. * Trigger to reset list of master/slaves components on the view
  341. * @type {bool}
  342. */
  343. redrawComponents: false,
  344. /**
  345. * Deletes the given host component, or all host components.
  346. *
  347. * @param {object|null} component When <code>null</code> all host components are deleted.
  348. * @return <code>null</code> when components get deleted.
  349. * <code>{xhr: XhrObj, url: "http://", method: "DELETE"}</code>
  350. * when components failed to get deleted.
  351. * @method _doDeleteHostComponent
  352. */
  353. _doDeleteHostComponent: function (component, callback) {
  354. callback = callback || Em.K;
  355. App.ajax.send({
  356. name: (Em.isNone(component)) ? 'common.delete.host' : 'common.delete.host_component',
  357. sender: this,
  358. data: {
  359. componentName: (component) ? component.get('componentName') : '',
  360. hostName: this.get('content.hostName')
  361. },
  362. success: '_doDeleteHostComponentSuccessCallback',
  363. error: '_doDeleteHostComponentErrorCallback'
  364. }).then(callback, callback);
  365. },
  366. /**
  367. * Result of delete component(s) request
  368. * @type {object}
  369. */
  370. _deletedHostComponentResult: null,
  371. /**
  372. * Success callback for delete host component request
  373. * @method _doDeleteHostComponentSuccessCallback
  374. */
  375. _doDeleteHostComponentSuccessCallback: function (response, request, data) {
  376. var self = this;
  377. this.set('_deletedHostComponentResult', null);
  378. this.removeHostComponentModel(data.componentName, data.hostName);
  379. if (data.componentName == 'ZOOKEEPER_SERVER') {
  380. this.set('fromDeleteZkServer', true);
  381. this.updateStormConfigs();
  382. self.isServiceMetricsLoaded(function () {
  383. self.loadConfigs();
  384. });
  385. } else if (data.componentName == 'HIVE_METASTORE') {
  386. this.set('deleteHiveMetaStore', true);
  387. this.loadConfigs('loadHiveConfigs');
  388. } else if (data.componentName == 'WEBHCAT_SERVER') {
  389. this.set('deleteWebHCatServer', true);
  390. this.loadConfigs('loadWebHCatConfigs');
  391. } else if (data.componentName == 'HIVE_SERVER') {
  392. this.set('deleteHiveServer', true);
  393. this.loadConfigs('loadHiveConfigs');
  394. } else if (data.componentName == 'NIMBUS') {
  395. this.set('deleteNimbusHost', true);
  396. this.loadConfigs('loadStormConfigs');
  397. } else if (data.componentName == 'RANGER_KMS_SERVER') {
  398. this.set('deleteRangerKMSServer', true);
  399. this.loadConfigs('loadRangerConfigs');
  400. }
  401. },
  402. /**
  403. * Error-callback for delete host component request
  404. * @param {object} xhr
  405. * @param {string} textStatus
  406. * @param {object} errorThrown
  407. * @method _doDeleteHostComponentErrorCallback
  408. */
  409. _doDeleteHostComponentErrorCallback: function (xhr, textStatus, errorThrown, data) {
  410. this.set('_deletedHostComponentResult', {xhr: xhr, url: data.url, method: 'DELETE'});
  411. },
  412. /**
  413. * Remove host component data from App.HostComponent model.
  414. *
  415. * @param {String} componentName
  416. * @param {String} hostName
  417. */
  418. removeHostComponentModel: function (componentName, hostName) {
  419. var component = App.HostComponent.find().filterProperty('componentName', componentName).findProperty('hostName', hostName);
  420. var serviceInCache = App.cache['services'].findProperty('ServiceInfo.service_name', component.get('service.serviceName'));
  421. serviceInCache.host_components = serviceInCache.host_components.without(component.get('id'));
  422. App.serviceMapper.deleteRecord(component);
  423. },
  424. /**
  425. * Send command to server to upgrade selected host component
  426. * @param {object} event
  427. * @method upgradeComponent
  428. */
  429. upgradeComponent: function (event) {
  430. var self = this;
  431. var component = event.context;
  432. return App.showConfirmationPopup(function () {
  433. App.ajax.send({
  434. name: 'host.host_component.upgrade',
  435. sender: self,
  436. data: {
  437. component: component,
  438. hostName: self.get('content.hostName'),
  439. componentName: component.get('componentName'),
  440. data: JSON.stringify({
  441. RequestInfo: {
  442. "context": Em.I18n.t('requestInfo.upgradeHostComponent') + " " + component.get('displayName')
  443. },
  444. Body: {
  445. HostRoles: {
  446. stack_id: 'HDP-1.2.2',
  447. state: 'INSTALLED'
  448. }
  449. }
  450. })
  451. },
  452. success: 'upgradeComponentSuccessCallback',
  453. error: 'ajaxErrorCallback'
  454. });
  455. });
  456. },
  457. /**
  458. * Success callback for upgrade host component request
  459. * @param {object} data
  460. * @param {object} opt
  461. * @param {object} params
  462. * @method upgradeComponentSuccessCallback
  463. */
  464. upgradeComponentSuccessCallback: function (data, opt, params) {
  465. if (App.get('testMode')) {
  466. this.mimicWorkStatusChange(params.component, App.HostComponentStatus.starting, App.HostComponentStatus.started);
  467. }
  468. this.showBackgroundOperationsPopup();
  469. },
  470. /**
  471. * Send command to server to restart selected components
  472. * @param {object} event
  473. * @method restartComponent
  474. */
  475. restartComponent: function (event) {
  476. var component = event.context;
  477. if (event.context.get('componentName') == 'NAMENODE') {
  478. this.checkNnLastCheckpointTime(function () {
  479. return App.showConfirmationPopup(function () {
  480. batchUtils.restartHostComponents([component], Em.I18n.t('rollingrestart.context.selectedComponentOnSelectedHost').format(component.get('displayName')), "HOST_COMPONENT");
  481. });
  482. });
  483. } else {
  484. return App.showConfirmationPopup(function () {
  485. batchUtils.restartHostComponents([component], Em.I18n.t('rollingrestart.context.selectedComponentOnSelectedHost').format(component.get('displayName')), "HOST_COMPONENT");
  486. });
  487. }
  488. },
  489. /**
  490. * add component as <code>addComponent<code> method but perform
  491. * kdc sessionstate if cluster is secure;
  492. * @param event
  493. */
  494. addComponentWithCheck: function (event) {
  495. var componentName = event.context ? event.context.get('componentName') : "";
  496. event.hiveMetastoreHost = (componentName == "HIVE_METASTORE" && !!this.get('content.hostName')) ? this.get('content.hostName') : null;
  497. App.get('router.mainAdminKerberosController').getSecurityType(function (event) {
  498. App.get('router.mainAdminKerberosController').getKDCSessionState(this.addComponent.bind(this, event));
  499. }.bind(this, event));
  500. },
  501. /**
  502. * Send command to server to install selected host component
  503. * @param {object} event
  504. * @method addComponent
  505. */
  506. addComponent: function (event) {
  507. var
  508. returnFunc,
  509. self = this,
  510. component = event.context,
  511. hostName = event.selectedHost || this.get('content.hostName'),
  512. componentName = component.get('componentName'),
  513. missedComponents = event.selectedHost ? [] : this.checkComponentDependencies(componentName, {
  514. scope: 'host',
  515. installedComponents: this.get('content.hostComponents').mapProperty('componentName')
  516. }),
  517. isManualKerberos = App.get('router.mainAdminKerberosController.isManualKerberos'),
  518. manualKerberosWarning = isManualKerberos ? Em.I18n.t('hosts.host.manualKerberosWarning') : '';
  519. if (!!missedComponents.length) {
  520. var popupMessage = Em.I18n.t('host.host.addComponent.popup.dependedComponents.body').format(component.get('displayName'),
  521. stringUtils.getFormattedStringFromArray(missedComponents.map(function (cName) {
  522. return App.StackServiceComponent.find(cName).get('displayName');
  523. })));
  524. return App.showAlertPopup(Em.I18n.t('host.host.addComponent.popup.dependedComponents.header'), popupMessage);
  525. }
  526. switch (componentName) {
  527. case 'ZOOKEEPER_SERVER':
  528. returnFunc = App.showConfirmationPopup(function () {
  529. self.installHostComponentCall(self.get('content.hostName'), component)
  530. }, Em.I18n.t('hosts.host.addComponent.' + componentName) + manualKerberosWarning);
  531. break;
  532. case 'HIVE_METASTORE':
  533. returnFunc = App.showConfirmationPopup(function () {
  534. self.set('hiveMetastoreHost', hostName);
  535. self.loadConfigs("loadHiveConfigs");
  536. }, Em.I18n.t('hosts.host.addComponent.' + componentName) + manualKerberosWarning);
  537. break;
  538. case 'WEBHCAT_SERVER':
  539. returnFunc = App.showConfirmationPopup(function () {
  540. self.set('webhcatServerHost', hostName);
  541. self.loadConfigs("loadWebHCatConfigs");
  542. }, Em.I18n.t('hosts.host.addComponent.' + componentName) + manualKerberosWarning);
  543. break;
  544. case 'NIMBUS':
  545. returnFunc = App.showConfirmationPopup(function () {
  546. self.set('nimbusHost', hostName);
  547. self.loadConfigs("loadStormConfigs");
  548. }, Em.I18n.t('hosts.host.addComponent.' + componentName) + manualKerberosWarning);
  549. break;
  550. case 'RANGER_KMS_SERVER':
  551. returnFunc = App.showConfirmationPopup(function () {
  552. self.set('rangerKMSServerHost', hostName);
  553. self.loadConfigs("loadRangerConfigs");
  554. }, Em.I18n.t('hosts.host.addComponent.' + componentName) + manualKerberosWarning);
  555. break;
  556. default:
  557. returnFunc = this.addClientComponent(component, isManualKerberos);
  558. }
  559. return returnFunc;
  560. },
  561. /**
  562. * Send command to server to install client on selected host
  563. * @param component
  564. */
  565. addClientComponent: function (component, isManualKerberos) {
  566. var self = this;
  567. var message = this.formatClientsMessage(component);
  568. return this.showAddComponentPopup(message, isManualKerberos, function () {
  569. self.installHostComponentCall(self.get('content.hostName'), component);
  570. });
  571. },
  572. showAddComponentPopup: function (message, isManualKerberos, primary) {
  573. isManualKerberos = isManualKerberos || false;
  574. return App.ModalPopup.show({
  575. primary: Em.I18n.t('hosts.host.addComponent.popup.confirm'),
  576. header: Em.I18n.t('popup.confirmation.commonHeader'),
  577. addComponentMsg: Em.I18n.t('hosts.host.addComponent.msg').format(message),
  578. manualKerberosWarning: isManualKerberos ? Em.I18n.t('hosts.host.manualKerberosWarning') : '',
  579. bodyClass: Em.View.extend({
  580. templateName: require('templates/main/host/details/addComponentPopup')
  581. }),
  582. onPrimary: function () {
  583. this.hide();
  584. primary();
  585. }
  586. });
  587. },
  588. /**
  589. * format message for operation of adding clients
  590. * @param client
  591. */
  592. formatClientsMessage: function (client) {
  593. var displayName = Em.isNone(client.get('displayName')) ? '' : client.get('displayName');
  594. var subComponentNames = client.get('subComponentNames');
  595. if (subComponentNames && subComponentNames.length > 0) {
  596. var dns = [];
  597. subComponentNames.forEach(function (scn) {
  598. dns.push(App.format.role(scn, false));
  599. });
  600. displayName += " (" + dns.join(", ") + ")";
  601. }
  602. return displayName;
  603. },
  604. /**
  605. * Success callback for install host component request (sent in <code>addNewComponentSuccessCallback</code>)
  606. * @param {object} data
  607. * @param {object} opt
  608. * @param {object} params
  609. * @method installNewComponentSuccessCallback
  610. */
  611. installNewComponentSuccessCallback: function (data, opt, params) {
  612. if (!data || !data.Requests || !data.Requests.id) {
  613. return false;
  614. }
  615. var self = this;
  616. if (App.get('testMode')) {
  617. this.mimicWorkStatusChange(params.component, App.HostComponentStatus.installing, App.HostComponentStatus.stopped);
  618. }
  619. this.showBackgroundOperationsPopup(function () {
  620. if (params.componentName === 'ZOOKEEPER_SERVER' || params.componentName === 'HIVE_SERVER') {
  621. self.set(params.componentName === 'ZOOKEEPER_SERVER' ? 'zkRequestId' : 'hiveRequestId', data.Requests.id);
  622. self.addObserver(
  623. 'App.router.backgroundOperationsController.serviceTimestamp',
  624. self,
  625. (params.componentName === 'ZOOKEEPER_SERVER' ? self.checkZkConfigs : self.checkHiveDone)
  626. );
  627. params.componentName === 'ZOOKEEPER_SERVER' ? self.checkZkConfigs() : self.checkHiveDone();
  628. }
  629. });
  630. return true;
  631. },
  632. /**
  633. * Call <code>setRackInfo</code> function to show Set Rack Id popup
  634. * @param data
  635. */
  636. setRackId: function (data) {
  637. var rack = data.context.get('rack');
  638. var hosts = [data.context];
  639. var operationData = {message: Em.I18n.t('hosts.host.details.setRackId')};
  640. hostsManagement.setRackInfo(operationData, hosts, rack);
  641. },
  642. /**
  643. * Call load tags
  644. * @method checkHiveDone
  645. */
  646. checkHiveDone: function () {
  647. var bg = App.router.get('backgroundOperationsController.services').findProperty('id', this.get('hiveRequestId'));
  648. if (bg && !bg.get('isRunning')) {
  649. var self = this;
  650. this.removeObserver('App.router.backgroundOperationsController.serviceTimestamp', this, this.checkHiveDone);
  651. setTimeout(function () {
  652. self.set('addHiveServer', true);
  653. self.loadConfigs("loadHiveConfigs");
  654. }, App.get('componentsUpdateInterval'));
  655. }
  656. },
  657. /**
  658. * Success callback for load configs request
  659. * @param {object} data
  660. * @method loadOozieConfigs
  661. */
  662. loadOozieConfigs: function (data) {
  663. return App.ajax.send({
  664. name: 'admin.get.all_configurations',
  665. sender: this,
  666. data: {
  667. urlParams: '(type=oozie-env&tag=' + data.Clusters.desired_configs['oozie-env'].tag + ')'
  668. },
  669. success: 'onLoadOozieConfigs',
  670. error: 'onLoadConfigsErrorCallback'
  671. });
  672. },
  673. /**
  674. * get Oozie database config and set databaseType
  675. * @param {object} data
  676. * @method onLoadHiveConfigs
  677. */
  678. onLoadOozieConfigs: function (data) {
  679. var configs = {};
  680. data.items.forEach(function (item) {
  681. $.extend(configs, item.properties);
  682. });
  683. this.set('isOozieServerAddable', !(Em.isEmpty(configs["oozie_database"]) || configs["oozie_database"] === 'New Derby Database'));
  684. this.get('isOozieConfigLoaded').resolve();
  685. },
  686. /**
  687. * Success callback for Storm load configs request
  688. * @param {object} data
  689. * @method loadStormConfigs
  690. */
  691. loadStormConfigs: function (data) {
  692. App.ajax.send({
  693. name: 'admin.get.all_configurations',
  694. sender: this,
  695. data: {
  696. urlParams: '(type=storm-site&tag=' + data.Clusters.desired_configs['storm-site'].tag + ')'
  697. },
  698. success: 'onLoadStormConfigs'
  699. });
  700. },
  701. /**
  702. * Update zk configs
  703. * @param {object} configs
  704. * @method updateZkConfigs
  705. */
  706. updateZkConfigs: function (configs) {
  707. var portValue = configs['zoo.cfg'] && Em.get(configs['zoo.cfg'], 'clientPort');
  708. var zkPort = typeof portValue === 'undefined' ? '2181' : portValue;
  709. var initializer = App.AddZooKeeperComponentsInitializer;
  710. var hostComponentsTopology = {
  711. masterComponentHosts: []
  712. };
  713. var masterComponents = this.bootstrapHostsMapping('ZOOKEEPER_SERVER');
  714. if (this.get('fromDeleteHost') || this.get('fromDeleteZkServer')) {
  715. this.set('fromDeleteHost', false);
  716. this.set('fromDeleteZkServer', false);
  717. var removedHost = masterComponents.findProperty('hostName', this.get('content.hostName'));
  718. if (!Em.isNone(removedHost)) {
  719. Em.set(removedHost, 'isInstalled', false);
  720. }
  721. }
  722. var dependencies = {
  723. zkClientPort: zkPort
  724. };
  725. hostComponentsTopology.masterComponentHosts = masterComponents;
  726. Em.keys(configs).forEach(function(fileName) {
  727. var properties = configs[fileName];
  728. Em.keys(properties).forEach(function(propertyName) {
  729. var propertyDef = {
  730. fileName: fileName,
  731. name: propertyName,
  732. value: properties[propertyName]
  733. };
  734. var configProperty = initializer.initialValue(propertyDef, hostComponentsTopology, dependencies);
  735. initializer.updateSiteObj(configs[fileName], configProperty);
  736. });
  737. });
  738. },
  739. /**
  740. *
  741. * @param {string} componentName
  742. * @param {string[]} [hostNames]
  743. * @returns {}
  744. */
  745. bootstrapHostsMapping: function(componentName, hostNames) {
  746. if (Em.isNone(hostNames)) {
  747. hostNames = App.HostComponent.find().filterProperty('componentName', componentName).mapProperty('hostName');
  748. }
  749. return hostNames.map(function(hostName) {
  750. return {
  751. component: componentName,
  752. hostName: hostName,
  753. isInstalled: true
  754. };
  755. });
  756. },
  757. /**
  758. * update and save Storm related configs to server
  759. * @param {object} data
  760. * @method onLoadStormConfigs
  761. */
  762. onLoadStormConfigs: function (data) {
  763. var nimbusHost = this.get('nimbusHost'),
  764. stormNimbusHosts = this.getStormNimbusHosts(),
  765. configs = {},
  766. attributes = {};
  767. data.items.forEach(function (item) {
  768. configs[item.type] = item.properties;
  769. attributes[item.type] = item.properties_attributes || {};
  770. }, this);
  771. this.updateZkConfigs(configs);
  772. configs['storm-site']['nimbus.seeds'] = JSON.stringify(stormNimbusHosts).replace(/"/g, "'");
  773. var groups = [
  774. {
  775. properties: {
  776. 'storm-site': configs['storm-site']
  777. },
  778. properties_attributes: {
  779. 'storm-site': attributes['storm-site']
  780. }
  781. }
  782. ];
  783. this.saveConfigsBatch(groups, 'NIMBUS', nimbusHost);
  784. },
  785. /**
  786. * Success callback for load configs request
  787. * @param {object} data
  788. * @method loadHiveConfigs
  789. */
  790. loadWebHCatConfigs: function (data) {
  791. return App.ajax.send({
  792. name: 'admin.get.all_configurations',
  793. sender: this,
  794. data: {
  795. webHCat: true,
  796. urlParams: [
  797. '(type=hive-site&tag=' + data.Clusters.desired_configs['hive-site'].tag + ')',
  798. '(type=webhcat-site&tag=' + data.Clusters.desired_configs['webhcat-site'].tag + ')',
  799. '(type=hive-env&tag=' + data.Clusters.desired_configs['hive-env'].tag + ')',
  800. '(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')'
  801. ].join('|')
  802. },
  803. success: 'onLoadHiveConfigs'
  804. });
  805. },
  806. /**
  807. * Success callback for load configs request
  808. * @param {object} data
  809. * @method loadHiveConfigs
  810. */
  811. loadHiveConfigs: function (data) {
  812. return App.ajax.send({
  813. name: 'admin.get.all_configurations',
  814. sender: this,
  815. data: {
  816. urlParams: [
  817. '(type=hive-site&tag=' + data.Clusters.desired_configs['hive-site'].tag + ')',
  818. '(type=webhcat-site&tag=' + data.Clusters.desired_configs['webhcat-site'].tag + ')',
  819. '(type=hive-env&tag=' + data.Clusters.desired_configs['hive-env'].tag + ')',
  820. '(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')'
  821. ].join('|')
  822. },
  823. success: 'onLoadHiveConfigs'
  824. });
  825. },
  826. /**
  827. * update and save Hive related configs to server
  828. * @param {object} data
  829. * @param {object} opt
  830. * @param {object} params
  831. * @method onLoadHiveConfigs
  832. */
  833. onLoadHiveConfigs: function (data, opt, params) {
  834. var hiveMetastoreHost = this.get('hiveMetastoreHost');
  835. var webhcatServerHost = this.get('webhcatServerHost');
  836. var port = "";
  837. var configs = {};
  838. var attributes = {};
  839. var userSetup = {};
  840. var localDB = {
  841. masterComponentHosts: this.getHiveHosts()
  842. };
  843. var dependencies = {
  844. hiveMetastorePort: ""
  845. };
  846. var initializer = params.webHCat ? App.AddWebHCatComponentsInitializer : App.AddHiveComponentsInitializer;
  847. data.items.forEach(function (item) {
  848. configs[item.type] = item.properties;
  849. attributes[item.type] = item.properties_attributes || {};
  850. }, this);
  851. port = configs['hive-site']['hive.metastore.uris'].match(/:[0-9]{2,4}/);
  852. port = port ? port[0].slice(1) : "9083";
  853. dependencies.hiveMetastorePort = port;
  854. if (params.webHCat) {
  855. userSetup.webhcatUser = configs['hive-env']['webhcat_user'];
  856. } else {
  857. userSetup.hiveUser = configs['hive-env']['hive_user'];
  858. }
  859. initializer.setup(userSetup);
  860. ['hive-site', 'webhcat-site', 'hive-env', 'core-site'].forEach(function(fileName) {
  861. if (configs[fileName]) {
  862. Em.keys(configs[fileName]).forEach(function(propertyName) {
  863. var propertyDef = {
  864. fileName: fileName,
  865. name: propertyName,
  866. value: configs[fileName][propertyName]
  867. };
  868. configs[fileName][propertyName] = Em.get(initializer.initialValue(propertyDef, localDB, dependencies), 'value');
  869. });
  870. }
  871. });
  872. initializer.cleanup();
  873. var groups = [
  874. {
  875. properties: {
  876. 'hive-site': configs['hive-site'],
  877. 'webhcat-site': configs['webhcat-site'],
  878. 'hive-env': configs['hive-env']
  879. },
  880. properties_attributes: {
  881. 'hive-site': attributes['hive-site'],
  882. 'webhcat-site': attributes['webhcat-site'],
  883. 'hive-env': attributes['hive-env']
  884. }
  885. },
  886. {
  887. properties: {
  888. 'core-site': configs['core-site']
  889. },
  890. properties_attributes: {
  891. 'core-site': attributes['core-site']
  892. }
  893. }
  894. ];
  895. var params = [groups];
  896. var componentName = this.get('addHiveServer') ? 'HIVE_SERVER' : (hiveMetastoreHost ? 'HIVE_METASTORE' : 'WEBHCAT_SERVER');
  897. var host = webhcatServerHost || hiveMetastoreHost;
  898. params.pushObjects([componentName, host]);
  899. this.saveConfigsBatch.apply(this, params);
  900. this.set('addHiveServer', false);
  901. },
  902. /**
  903. * save configs' sites in batch
  904. * @param groups
  905. * @param componentName
  906. * @param host
  907. */
  908. saveConfigsBatch: function (groups, componentName, host) {
  909. groups.forEach(function (group) {
  910. var desiredConfigs = [],
  911. tag = 'version' + (new Date).getTime(),
  912. properties = group.properties;
  913. for (var site in properties) {
  914. if (!properties.hasOwnProperty(site) || Em.isNone(properties[site])) continue;
  915. desiredConfigs.push({
  916. "type": site,
  917. "tag": tag,
  918. "properties": properties[site],
  919. "properties_attributes": group.properties_attributes[site],
  920. "service_config_version_note": Em.I18n.t('hosts.host.configs.save.note').format(App.format.role(componentName, false))
  921. });
  922. }
  923. if (desiredConfigs.length > 0) {
  924. App.ajax.send({
  925. name: 'common.service.configurations',
  926. sender: this,
  927. data: {
  928. desired_config: desiredConfigs,
  929. componentName: componentName,
  930. host: host
  931. },
  932. success: 'installHostComponent'
  933. });
  934. }
  935. //clear hive metastore host not to send second request to install component
  936. host = null;
  937. }, this);
  938. },
  939. /**
  940. * success callback for saveConfigsBatch method
  941. * @param data
  942. * @param opt
  943. * @param params
  944. */
  945. installHostComponent: function (data, opt, params) {
  946. if (App.router.get('location.location.hash').contains('configs')) {
  947. App.router.get('mainServiceInfoConfigsController').loadStep();
  948. }
  949. if (params.host) {
  950. this.installHostComponentCall(params.host, App.StackServiceComponent.find(params.componentName));
  951. }
  952. },
  953. /**
  954. * Delete Hive Metastore is performed
  955. * @type {bool}
  956. */
  957. deleteHiveMetaStore: false,
  958. /**
  959. * Delete WebHCat Server is performed
  960. *
  961. * @type {bool}
  962. */
  963. deleteWebHCatServer: false,
  964. getHiveHosts: function () {
  965. var self = this;
  966. var removePerformed = this.get('fromDeleteHost') || this.get('deleteHiveMetaStore') || this.get('deleteHiveServer') || this.get('deleteWebHCatServer');
  967. var hiveMasterComponents = ['WEBHCAT_SERVER', 'HIVE_METASTORE', 'HIVE_SERVER'];
  968. var masterComponentsMap = hiveMasterComponents.map(function(componentName) {
  969. return self.bootstrapHostsMapping(componentName);
  970. }).reduce(function(p,c) {
  971. return p.concat(c);
  972. });
  973. if (removePerformed) {
  974. self.setProperties({
  975. deleteHiveMetaStore: false,
  976. deleteHiveServer: false,
  977. deleteWebHCatServer: false,
  978. fromDeleteHost: false
  979. });
  980. masterComponentsMap = masterComponentsMap.map(function(masterComponent) {
  981. masterComponent.isInstalled = masterComponent.hostName !== self.get('content.hostName');
  982. return masterComponent;
  983. });
  984. }
  985. if (!!this.get('hiveMetastoreHost')) {
  986. masterComponentsMap.push({
  987. component: 'HIVE_METASTORE',
  988. hostName: this.get('hiveMetastoreHost'),
  989. isInstalled: !removePerformed
  990. });
  991. this.set('hiveMetastoreHost', '');
  992. }
  993. if (!!this.get('webhcatServerHost')) {
  994. masterComponentsMap.push({
  995. component: 'WEBHCAT_SERVER',
  996. hostName: this.get('webhcatServerHost'),
  997. isInstalled: !removePerformed
  998. });
  999. this.set('webhcatServerHost', '');
  1000. }
  1001. return masterComponentsMap;
  1002. },
  1003. /**
  1004. * Success callback for load configs request
  1005. * @param {object} data
  1006. * @method loadHiveConfigs
  1007. */
  1008. loadRangerConfigs: function (data) {
  1009. App.ajax.send({
  1010. name: 'admin.get.all_configurations',
  1011. sender: this,
  1012. data: {
  1013. urlParams: '(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')|(type=hdfs-site&tag=' + data.Clusters.desired_configs['hdfs-site'].tag + ')|(type=kms-env&tag=' + data.Clusters.desired_configs['kms-env'].tag + ')'
  1014. },
  1015. success: 'onLoadRangerConfigs'
  1016. });
  1017. },
  1018. /**
  1019. * update and save Hive hive.metastore.uris config to server
  1020. * @param {object} data
  1021. * @method onLoadHiveConfigs
  1022. */
  1023. onLoadRangerConfigs: function (data) {
  1024. var hostToInstall = this.get('rangerKMSServerHost');
  1025. var rkmsHosts = this.getRangerKMSServerHosts();
  1026. var rkmsPort = data.items.findProperty('type', 'kms-env').properties['kms_port'];
  1027. var coreSiteConfigs = data.items.findProperty('type', 'core-site');
  1028. var hdfsSiteConfigs = data.items.findProperty('type', 'hdfs-site');
  1029. var groups = [
  1030. {
  1031. properties: {
  1032. 'core-site': coreSiteConfigs.properties,
  1033. 'hdfs-site': hdfsSiteConfigs.properties
  1034. },
  1035. properties_attributes: {
  1036. 'core-site': coreSiteConfigs.properties_attributes,
  1037. 'hdfs-site': hdfsSiteConfigs.properties_attributes
  1038. }
  1039. }
  1040. ];
  1041. coreSiteConfigs.properties['hadoop.security.key.provider.path'] = 'kms://http@' + rkmsHosts.join(';') + ':' + rkmsPort + '/kms';
  1042. hdfsSiteConfigs.properties['dfs.encryption.key.provider.uri'] = 'kms://http@' + rkmsHosts.join(';') + ':' + rkmsPort + '/kms';
  1043. this.saveConfigsBatch(groups, 'RANGER_KMS_SERVER', hostToInstall);
  1044. },
  1045. /**
  1046. * Delete Hive Metastore is performed
  1047. * @type {bool}
  1048. */
  1049. deleteRangerKMSServer: false,
  1050. getRangerKMSServerHosts: function () {
  1051. var rkmsHosts = App.HostComponent.find().filterProperty('componentName', 'RANGER_KMS_SERVER').mapProperty('hostName');
  1052. var rangerKMSServerHost = this.get('rangerKMSServerHost');
  1053. if (!!rangerKMSServerHost) {
  1054. rkmsHosts.push(rangerKMSServerHost);
  1055. this.set('rangerKMSServerHost', '');
  1056. }
  1057. if (this.get('fromDeleteHost') || this.get('deleteRangerKMSServer')) {
  1058. this.set('deleteRangerKMSServer', false);
  1059. this.set('fromDeleteHost', false);
  1060. return rkmsHosts.without(this.get('content.hostName'));
  1061. }
  1062. return rkmsHosts.sort();
  1063. },
  1064. /**
  1065. * Delete Storm Nimbus is performed
  1066. * @type {bool}
  1067. */
  1068. deleteNimbusHost: false,
  1069. getStormNimbusHosts: function () {
  1070. var
  1071. stormNimbusHosts = App.HostComponent.find().filterProperty('componentName', 'NIMBUS').mapProperty('hostName'),
  1072. nimbusHost = this.get('nimbusHost');
  1073. if (!!nimbusHost) {
  1074. stormNimbusHosts.push(nimbusHost);
  1075. this.set('nimbusHost', '');
  1076. }
  1077. if (this.get('fromDeleteHost') || this.get('deleteNimbusHost')) {
  1078. this.set('deleteNimbusHost', false);
  1079. this.set('fromDeleteHost', false);
  1080. return stormNimbusHosts.without(this.get('content.hostName'));
  1081. }
  1082. return stormNimbusHosts.sort();
  1083. },
  1084. /**
  1085. * Send command to server to resfresh configs of selected component
  1086. * @param {object} event
  1087. * @method refreshComponentConfigs
  1088. */
  1089. refreshComponentConfigs: function (event) {
  1090. var self = this;
  1091. return App.showConfirmationPopup(function () {
  1092. var component = event.context;
  1093. var context = Em.I18n.t('requestInfo.refreshComponentConfigs').format(component.get('displayName'));
  1094. self.sendRefreshComponentConfigsCommand(component, context);
  1095. });
  1096. },
  1097. /**
  1098. * PUTs a command to server to refresh configs of host component.
  1099. * @param {object} component
  1100. * @param {object} context Context under which this command is beign sent.
  1101. * @method sendRefreshComponentConfigsCommand
  1102. */
  1103. sendRefreshComponentConfigsCommand: function (component, context) {
  1104. var resource_filters = [
  1105. {
  1106. service_name: component.get('service.serviceName'),
  1107. component_name: component.get('componentName'),
  1108. hosts: component.get('host.hostName')
  1109. }
  1110. ];
  1111. App.ajax.send({
  1112. name: 'host.host_component.refresh_configs',
  1113. sender: this,
  1114. data: {
  1115. resource_filters: resource_filters,
  1116. context: context
  1117. },
  1118. success: 'refreshComponentConfigsSuccessCallback'
  1119. });
  1120. },
  1121. /**
  1122. * Success callback for refresh host component configs request
  1123. * @method refreshComponentConfigsSuccessCallback
  1124. */
  1125. refreshComponentConfigsSuccessCallback: function () {
  1126. this.showBackgroundOperationsPopup();
  1127. },
  1128. /**
  1129. * Update storm config
  1130. * @method updateStormConfigs
  1131. */
  1132. updateStormConfigs: function () {
  1133. if (App.Service.find('STORM').get('isLoaded') && App.get('isHadoop23Stack')) {
  1134. this.loadConfigs("loadStormConfigs");
  1135. }
  1136. },
  1137. /**
  1138. * Load tags
  1139. * @method checkZkConfigs
  1140. */
  1141. checkZkConfigs: function () {
  1142. var bg = App.router.get('backgroundOperationsController.services').findProperty('id', this.get('zkRequestId'));
  1143. if (bg && !bg.get('isRunning')) {
  1144. var self = this;
  1145. this.removeObserver('App.router.backgroundOperationsController.serviceTimestamp', this, this.checkZkConfigs);
  1146. setTimeout(function () {
  1147. self.updateStormConfigs();
  1148. var callback = function () {
  1149. self.loadConfigs();
  1150. };
  1151. self.isServiceMetricsLoaded(callback);
  1152. }, App.get('componentsUpdateInterval'));
  1153. }
  1154. },
  1155. /**
  1156. * Load configs
  1157. * This function when used without a callback should be always used from successcallback function of the promise `App.router.get('mainController').isLoading.call(App.router.get('clusterController'), 'isServiceContentFullyLoaded').done(promise)`
  1158. * This is required to make sure that service metrics API determining the HA state of components is loaded
  1159. * @method loadConfigs
  1160. */
  1161. loadConfigs: function (callback) {
  1162. App.ajax.send({
  1163. name: 'config.tags',
  1164. sender: this,
  1165. success: callback ? callback : 'loadConfigsSuccessCallback',
  1166. error: 'onLoadConfigsErrorCallback'
  1167. });
  1168. },
  1169. /**
  1170. * onLoadConfigsErrorCallback
  1171. * @method onLoadConfigsErrorCallback
  1172. */
  1173. onLoadConfigsErrorCallback: function () {
  1174. this.get('isOozieConfigLoaded').reject();
  1175. },
  1176. /**
  1177. * Success callback for load configs request
  1178. * @param {object} data
  1179. * @method adConfigsSuccessCallback
  1180. */
  1181. loadConfigsSuccessCallback: function (data) {
  1182. var urlParams = this.constructConfigUrlParams(data);
  1183. if (urlParams.length > 0) {
  1184. App.ajax.send({
  1185. name: 'reassign.load_configs',
  1186. sender: this,
  1187. data: {
  1188. urlParams: urlParams.join('|')
  1189. },
  1190. success: 'saveZkConfigs'
  1191. });
  1192. return true;
  1193. }
  1194. return false;
  1195. },
  1196. /**
  1197. * construct URL params for query, that load configs
  1198. * @param data {Object}
  1199. * @return {Array}
  1200. */
  1201. constructConfigUrlParams: function (data) {
  1202. var urlParams = [];
  1203. var services = App.Service.find();
  1204. if (App.get('isHaEnabled')) {
  1205. urlParams.push('(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')');
  1206. }
  1207. if (services.someProperty('serviceName', 'HBASE')) {
  1208. urlParams.push('(type=hbase-site&tag=' + data.Clusters.desired_configs['hbase-site'].tag + ')');
  1209. }
  1210. if (services.someProperty('serviceName', 'HIVE')) {
  1211. urlParams.push('(type=webhcat-site&tag=' + data.Clusters.desired_configs['webhcat-site'].tag + ')');
  1212. urlParams.push('(type=hive-site&tag=' + data.Clusters.desired_configs['hive-site'].tag + ')');
  1213. }
  1214. if (services.someProperty('serviceName', 'STORM')) {
  1215. urlParams.push('(type=storm-site&tag=' + data.Clusters.desired_configs['storm-site'].tag + ')');
  1216. }
  1217. if (services.someProperty('serviceName', 'YARN')) {
  1218. urlParams.push('(type=yarn-site&tag=' + data.Clusters.desired_configs['yarn-site'].tag + ')');
  1219. urlParams.push('(type=zoo.cfg&tag=' + data.Clusters.desired_configs['zoo.cfg'].tag + ')');
  1220. }
  1221. if (services.someProperty('serviceName', 'ACCUMULO')) {
  1222. urlParams.push('(type=accumulo-site&tag=' + data.Clusters.desired_configs['accumulo-site'].tag + ')');
  1223. }
  1224. if (services.someProperty('serviceName', 'KAFKA')) {
  1225. urlParams.push('(type=kafka-broker&tag=' + data.Clusters.desired_configs['kafka-broker'].tag + ')');
  1226. }
  1227. return urlParams;
  1228. },
  1229. /**
  1230. * save new ZooKeeper configs to server
  1231. * @param {object} data
  1232. * @method saveZkConfigs
  1233. */
  1234. saveZkConfigs: function (data) {
  1235. var configs = {};
  1236. var attributes = {};
  1237. data.items.forEach(function (item) {
  1238. configs[item.type] = item.properties;
  1239. attributes[item.type] = item.properties_attributes || {};
  1240. }, this);
  1241. this.updateZkConfigs(configs);
  1242. var groups = [
  1243. {
  1244. properties: {
  1245. 'hive-site': configs['hive-site'],
  1246. 'webhcat-site': configs['webhcat-site']
  1247. },
  1248. properties_attributes: {
  1249. 'hive-site': attributes['hive-site'],
  1250. 'webhcat-site': attributes['webhcat-site']
  1251. }
  1252. }
  1253. ];
  1254. var installedServiceNames = App.Service.find().mapProperty('serviceName');
  1255. if (installedServiceNames.contains('YARN')) {
  1256. groups.push(
  1257. {
  1258. properties: {
  1259. 'yarn-site': configs['yarn-site']
  1260. },
  1261. properties_attributes: {
  1262. 'yarn-site': attributes['yarn-site']
  1263. }
  1264. }
  1265. );
  1266. }
  1267. if (installedServiceNames.contains('HBASE')) {
  1268. groups.push(
  1269. {
  1270. properties: {
  1271. 'hbase-site': configs['hbase-site']
  1272. },
  1273. properties_attributes: {
  1274. 'hbase-site': attributes['hbase-site']
  1275. }
  1276. }
  1277. );
  1278. }
  1279. if (installedServiceNames.contains('ACCUMULO')) {
  1280. groups.push(
  1281. {
  1282. properties: {
  1283. 'accumulo-site': configs['accumulo-site']
  1284. },
  1285. properties_attributes: {
  1286. 'accumulo-site': attributes['accumulo-site']
  1287. }
  1288. }
  1289. );
  1290. }
  1291. if (installedServiceNames.contains('KAFKA')) {
  1292. groups.push(
  1293. {
  1294. properties: {
  1295. 'kafka-broker': configs['kafka-broker']
  1296. },
  1297. properties_attributes: {
  1298. 'kafka-broker': attributes['kafka-broker']
  1299. }
  1300. }
  1301. );
  1302. }
  1303. this.saveConfigsBatch(groups, 'ZOOKEEPER_SERVER');
  1304. },
  1305. /**
  1306. * Is deleteHost action id fired
  1307. * @type {bool}
  1308. */
  1309. fromDeleteHost: false,
  1310. /**
  1311. * Is ZooKeeper Server being deleted from host
  1312. * @type {bool}
  1313. */
  1314. fromDeleteZkServer: false,
  1315. /**
  1316. * Send command to server to install selected host component
  1317. * @param {Object} event
  1318. * @method installComponent
  1319. */
  1320. installComponent: function (event) {
  1321. var self = this;
  1322. var component = event.context;
  1323. var componentName = component.get('componentName');
  1324. var displayName = component.get('displayName');
  1325. return App.ModalPopup.show({
  1326. primary: Em.I18n.t('hosts.host.installComponent.popup.confirm'),
  1327. header: Em.I18n.t('popup.confirmation.commonHeader'),
  1328. installComponentMessage: Em.I18n.t('hosts.host.installComponent.msg').format(displayName),
  1329. bodyClass: Em.View.extend({
  1330. templateName: require('templates/main/host/details/installComponentPopup')
  1331. }),
  1332. onPrimary: function () {
  1333. var _this = this;
  1334. App.get('router.mainAdminKerberosController').getSecurityType(function () {
  1335. App.get('router.mainAdminKerberosController').getKDCSessionState(function () {
  1336. _this.hide();
  1337. App.ajax.send({
  1338. name: 'common.host.host_component.update',
  1339. sender: self,
  1340. data: {
  1341. hostName: self.get('content.hostName'),
  1342. serviceName: component.get('service.serviceName'),
  1343. componentName: componentName,
  1344. component: component,
  1345. context: Em.I18n.t('requestInfo.installHostComponent') + " " + displayName,
  1346. HostRoles: {
  1347. state: 'INSTALLED'
  1348. }
  1349. },
  1350. success: 'installComponentSuccessCallback',
  1351. error: 'ajaxErrorCallback'
  1352. });
  1353. })
  1354. });
  1355. }
  1356. });
  1357. },
  1358. /**
  1359. * Success callback for install component request
  1360. * @param {object} data
  1361. * @param {object} opt
  1362. * @param {object} params
  1363. * @method installComponentSuccessCallback
  1364. */
  1365. installComponentSuccessCallback: function (data, opt, params) {
  1366. if (App.get('testMode')) {
  1367. this.mimicWorkStatusChange(params.component, App.HostComponentStatus.installing, App.HostComponentStatus.stopped);
  1368. }
  1369. this.showBackgroundOperationsPopup();
  1370. },
  1371. /**
  1372. * Send command to server to run decommission on DATANODE, TASKTRACKER, NODEMANAGER, REGIONSERVER
  1373. * @param {App.HostComponent} component
  1374. * @method decommission
  1375. */
  1376. decommission: function (component) {
  1377. var self = this;
  1378. return App.showConfirmationPopup(function () {
  1379. self.runDecommission.call(self, self.get('content.hostName'), component.get('service.serviceName'));
  1380. });
  1381. },
  1382. /**
  1383. * identify correct component to run decommission on them by service name,
  1384. * in result run proper decommission method
  1385. * @param hostName
  1386. * @param svcName
  1387. */
  1388. runDecommission: function (hostName, svcName) {
  1389. switch (svcName) {
  1390. case 'HDFS':
  1391. this.doDecommission(hostName, svcName, "NAMENODE", "DATANODE");
  1392. break;
  1393. case 'YARN':
  1394. this.doDecommission(hostName, svcName, "RESOURCEMANAGER", "NODEMANAGER");
  1395. break;
  1396. case 'HBASE':
  1397. this.warnBeforeDecommission(hostName);
  1398. }
  1399. },
  1400. /**
  1401. * Send command to server to run recommission on DATANODE, TASKTRACKER, NODEMANAGER
  1402. * @param {App.HostComponent} component
  1403. * @method recommission
  1404. */
  1405. recommission: function (component) {
  1406. var self = this;
  1407. return App.showConfirmationPopup(function () {
  1408. self.runRecommission.call(self, self.get('content.hostName'), component.get('service.serviceName'));
  1409. });
  1410. },
  1411. /**
  1412. * identify correct component to run recommission on them by service name,
  1413. * in result run proper recommission method
  1414. * @param hostName
  1415. * @param svcName
  1416. */
  1417. runRecommission: function (hostName, svcName) {
  1418. switch (svcName) {
  1419. case 'HDFS':
  1420. this.doRecommissionAndStart(hostName, svcName, "NAMENODE", "DATANODE");
  1421. break;
  1422. case 'YARN':
  1423. this.doRecommissionAndStart(hostName, svcName, "RESOURCEMANAGER", "NODEMANAGER");
  1424. break;
  1425. case 'HBASE':
  1426. this.doRecommissionAndStart(hostName, svcName, "HBASE_MASTER", "HBASE_REGIONSERVER");
  1427. }
  1428. this.showBackgroundOperationsPopup();
  1429. },
  1430. /**
  1431. * Performs Decommission (for DN, TT and NM)
  1432. * @param {string} hostName
  1433. * @param {string} serviceName
  1434. * @param {string} componentName
  1435. * @param {string} slaveType
  1436. * @method doDecommission
  1437. */
  1438. doDecommission: function (hostName, serviceName, componentName, slaveType) {
  1439. var contextNameString = 'hosts.host.' + slaveType.toLowerCase() + '.decommission';
  1440. var context = Em.I18n.t(contextNameString);
  1441. App.ajax.send({
  1442. name: 'host.host_component.decommission_slave',
  1443. sender: this,
  1444. data: {
  1445. context: context,
  1446. command: 'DECOMMISSION',
  1447. hostName: hostName,
  1448. serviceName: serviceName,
  1449. componentName: componentName,
  1450. slaveType: slaveType
  1451. },
  1452. success: 'decommissionSuccessCallback',
  1453. error: 'decommissionErrorCallback'
  1454. });
  1455. },
  1456. /**
  1457. * check is hbase regionserver in mm. If so - run decommission
  1458. * otherwise shows warning
  1459. * @method warnBeforeDecommission
  1460. * @param {string} hostNames - list of host when run from bulk operations or current host
  1461. */
  1462. warnBeforeDecommission: function (hostNames) {
  1463. if (this.get('content.hostComponents').findProperty('componentName', 'HBASE_REGIONSERVER').get('passiveState') == "OFF") {
  1464. this.showHbaseActiveWarning();
  1465. } else {
  1466. this.checkRegionServerState(hostNames);
  1467. }
  1468. },
  1469. /**
  1470. * send call to check is this regionserver last in cluster which has desired_admin_state property "INSERVICE"
  1471. * @method checkRegionServerState
  1472. * @param hostNames
  1473. */
  1474. checkRegionServerState: function (hostNames) {
  1475. return App.ajax.send({
  1476. name: 'host.region_servers.in_inservice',
  1477. sender: this,
  1478. data: {
  1479. hostNames: hostNames
  1480. },
  1481. success: 'checkRegionServerStateSuccessCallback'
  1482. });
  1483. },
  1484. /**
  1485. * check is this regionserver last in cluster which has desired_admin_state property "INSERVICE"
  1486. * @method checkRegionServerStateSuccessCallback
  1487. * @param data
  1488. * @param opt
  1489. * @param params
  1490. */
  1491. checkRegionServerStateSuccessCallback: function (data, opt, params) {
  1492. var hostArray = params.hostNames.split(",");
  1493. var decommissionPossible = (data.items.mapProperty('HostRoles.host_name').filter(function (hostName) {
  1494. return !hostArray.contains(hostName);
  1495. }, this).length >= 1);
  1496. if (decommissionPossible) {
  1497. this.doDecommissionRegionServer(params.hostNames, "HBASE", "HBASE_MASTER", "HBASE_REGIONSERVER");
  1498. } else {
  1499. this.showRegionServerWarning();
  1500. }
  1501. },
  1502. /**
  1503. * show warning that regionserver is last in cluster which has desired_admin_state property "INSERVICE"
  1504. * @method showRegionServerWarning
  1505. * @param hostNames
  1506. */
  1507. showRegionServerWarning: function () {
  1508. return App.ModalPopup.show({
  1509. header: Em.I18n.t('common.warning'),
  1510. message: Em.I18n.t('hosts.host.hbase_regionserver.decommission.warning'),
  1511. bodyClass: Ember.View.extend({
  1512. template: Em.Handlebars.compile('<div class="alert alert-warning">{{message}}</div>')
  1513. }),
  1514. secondary: false
  1515. });
  1516. },
  1517. /**
  1518. * shows warning: put hbase regionserver in passive state
  1519. * @method showHbaseActiveWarning
  1520. * @return {App.ModalPopup}
  1521. */
  1522. showHbaseActiveWarning: function () {
  1523. return App.ModalPopup.show({
  1524. header: Em.I18n.t('common.warning'),
  1525. message: Em.I18n.t('hostPopup.recommendation.beforeDecommission').format(App.format.components["HBASE_REGIONSERVER"]),
  1526. bodyClass: Ember.View.extend({
  1527. template: Em.Handlebars.compile('<div class="alert alert-warning">{{message}}</div>')
  1528. }),
  1529. secondary: false
  1530. });
  1531. },
  1532. /**
  1533. * Performs Decommission (for RegionServer)
  1534. * @method doDecommissionRegionServer
  1535. * @param {string} hostNames - list of host when run from bulk operations or current host
  1536. * @param {string} serviceName - serviceName
  1537. * @param {string} componentName - master compoent name
  1538. * @param {string} slaveType - slave component name
  1539. */
  1540. doDecommissionRegionServer: function (hostNames, serviceName, componentName, slaveType) {
  1541. var batches = [
  1542. {
  1543. "order_id": 1,
  1544. "type": "POST",
  1545. "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName') + "/requests",
  1546. "RequestBodyInfo": {
  1547. "RequestInfo": {
  1548. "context": Em.I18n.t('hosts.host.regionserver.decommission.batch1'),
  1549. "command": "DECOMMISSION",
  1550. "exclusive": "true",
  1551. "parameters": {
  1552. "slave_type": slaveType,
  1553. "excluded_hosts": hostNames
  1554. },
  1555. 'operation_level': {
  1556. level: "HOST_COMPONENT",
  1557. cluster_name: App.get('clusterName'),
  1558. host_name: hostNames,
  1559. service_name: serviceName
  1560. }
  1561. },
  1562. "Requests/resource_filters": [
  1563. {"service_name": serviceName, "component_name": componentName}
  1564. ]
  1565. }
  1566. }];
  1567. var id = 2;
  1568. var hAray = hostNames.split(",");
  1569. for (var i = 0; i < hAray.length; i++) {
  1570. batches.push({
  1571. "order_id": id,
  1572. "type": "PUT",
  1573. "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName') + "/hosts/" + hAray[i] + "/host_components/" + slaveType,
  1574. "RequestBodyInfo": {
  1575. "RequestInfo": {
  1576. context: Em.I18n.t('hosts.host.regionserver.decommission.batch2'),
  1577. exclusive: true,
  1578. operation_level: {
  1579. level: "HOST_COMPONENT",
  1580. cluster_name: App.get('clusterName'),
  1581. host_name: hostNames,
  1582. service_name: serviceName || null
  1583. }
  1584. },
  1585. "Body": {
  1586. HostRoles: {
  1587. state: "INSTALLED"
  1588. }
  1589. }
  1590. }
  1591. });
  1592. id++;
  1593. }
  1594. batches.push({
  1595. "order_id": id,
  1596. "type": "POST",
  1597. "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName') + "/requests",
  1598. "RequestBodyInfo": {
  1599. "RequestInfo": {
  1600. "context": Em.I18n.t('hosts.host.regionserver.decommission.batch3'),
  1601. "command": "DECOMMISSION",
  1602. "service_name": serviceName,
  1603. "component_name": componentName,
  1604. "parameters": {
  1605. "slave_type": slaveType,
  1606. "excluded_hosts": hostNames,
  1607. "mark_draining_only": true
  1608. },
  1609. 'operation_level': {
  1610. level: "HOST_COMPONENT",
  1611. cluster_name: App.get('clusterName'),
  1612. host_name: hostNames,
  1613. service_name: serviceName
  1614. }
  1615. },
  1616. "Requests/resource_filters": [
  1617. {"service_name": serviceName, "component_name": componentName}
  1618. ]
  1619. }
  1620. });
  1621. App.ajax.send({
  1622. name: 'host.host_component.recommission_and_restart',
  1623. sender: this,
  1624. data: {
  1625. intervalTimeSeconds: 1,
  1626. tolerateSize: 0,
  1627. batches: batches
  1628. },
  1629. success: 'decommissionSuccessCallback',
  1630. error: 'decommissionErrorCallback'
  1631. });
  1632. },
  1633. /**
  1634. * Error callback for decommission requests
  1635. * @param {object} request
  1636. * @param {object} ajaxOptions
  1637. * @param {string} error
  1638. * @method decommissionErrorCallback
  1639. */
  1640. decommissionErrorCallback: function (request, ajaxOptions, error) {
  1641. },
  1642. /**
  1643. * Success ajax response for Recommission/Decommission slaves
  1644. * @param {object} data
  1645. * @method decommissionSuccessCallback
  1646. * @return {Boolean}
  1647. */
  1648. decommissionSuccessCallback: function (data) {
  1649. if (data && (data.Requests || data.resources[0].RequestSchedule)) {
  1650. this.showBackgroundOperationsPopup();
  1651. return true;
  1652. } else {
  1653. return false;
  1654. }
  1655. },
  1656. /**
  1657. * Performs Recommission and Start
  1658. * @param {string} hostNames
  1659. * @param {string} serviceName
  1660. * @param {string} componentName
  1661. * @param {string} slaveType
  1662. * @method doRecommissionAndStart
  1663. */
  1664. doRecommissionAndStart: function (hostNames, serviceName, componentName, slaveType) {
  1665. var contextNameString_1 = 'hosts.host.' + slaveType.toLowerCase() + '.recommission';
  1666. var context_1 = Em.I18n.t(contextNameString_1);
  1667. var contextNameString_2 = 'requestInfo.startHostComponent.' + slaveType.toLowerCase();
  1668. var startContext = Em.I18n.t(contextNameString_2);
  1669. var params = {
  1670. "slave_type": slaveType,
  1671. "included_hosts": hostNames
  1672. };
  1673. if (serviceName == "HBASE") {
  1674. params.mark_draining_only = true;
  1675. }
  1676. var batches = [
  1677. {
  1678. "order_id": 1,
  1679. "type": "POST",
  1680. "uri": App.apiPrefix + "/clusters/" + App.get('clusterName') + "/requests",
  1681. "RequestBodyInfo": {
  1682. "RequestInfo": {
  1683. "context": context_1,
  1684. "command": "DECOMMISSION",
  1685. "exclusive": "true",
  1686. "parameters": params,
  1687. 'operation_level': {
  1688. level: "HOST_COMPONENT",
  1689. cluster_name: App.get('clusterName'),
  1690. host_name: hostNames,
  1691. service_name: serviceName
  1692. }
  1693. },
  1694. "Requests/resource_filters": [
  1695. {"service_name": serviceName, "component_name": componentName}
  1696. ]
  1697. }
  1698. }];
  1699. var id = 2;
  1700. var hAray = hostNames.split(",");
  1701. for (var i = 0; i < hAray.length; i++) {
  1702. batches.push({
  1703. "order_id": id,
  1704. "type": "PUT",
  1705. "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName') + "/hosts/" + hAray[i] + "/host_components/" + slaveType,
  1706. "RequestBodyInfo": {
  1707. "RequestInfo": {
  1708. context: startContext,
  1709. operation_level: {
  1710. level: "HOST_COMPONENT",
  1711. cluster_name: App.get('clusterName'),
  1712. host_name: hostNames,
  1713. service_name: serviceName || null
  1714. }
  1715. },
  1716. "Body": {
  1717. HostRoles: {
  1718. state: "STARTED"
  1719. }
  1720. }
  1721. }
  1722. });
  1723. id++;
  1724. }
  1725. App.ajax.send({
  1726. name: 'host.host_component.recommission_and_restart',
  1727. sender: this,
  1728. data: {
  1729. intervalTimeSeconds: 1,
  1730. tolerateSize: 1,
  1731. batches: batches
  1732. },
  1733. success: 'decommissionSuccessCallback',
  1734. error: 'decommissionErrorCallback'
  1735. });
  1736. },
  1737. /**
  1738. * Handler for host-menu items actions
  1739. * @param {object} option
  1740. * @method doAction
  1741. */
  1742. doAction: function (option) {
  1743. switch (option.context.action) {
  1744. case "deleteHost":
  1745. this.validateAndDeleteHost();
  1746. break;
  1747. case "startAllComponents":
  1748. if (!this.get('content.isNotHeartBeating')) this.doStartAllComponents();
  1749. break;
  1750. case "stopAllComponents":
  1751. if (!this.get('content.isNotHeartBeating')) this.doStopAllComponents();
  1752. break;
  1753. case "restartAllComponents":
  1754. if (!this.get('content.isNotHeartBeating')) this.doRestartAllComponents();
  1755. break;
  1756. case "onOffPassiveModeForHost":
  1757. this.onOffPassiveModeForHost(option.context);
  1758. break;
  1759. case "setRackId":
  1760. this.setRackIdForHost();
  1761. break;
  1762. }
  1763. },
  1764. /**
  1765. * Turn On/Off Passive Mode for host
  1766. * @param {object} context
  1767. * @method onOffPassiveModeForHost
  1768. */
  1769. onOffPassiveModeForHost: function (context) {
  1770. var state = context.active ? 'ON' : 'OFF';
  1771. var self = this;
  1772. var message = Em.I18n.t('hosts.host.details.for.postfix').format(context.label);
  1773. var popupInfo = Em.I18n.t('hosts.passiveMode.popup').format(context.active ? 'On' : 'Off', this.get('content.hostName'));
  1774. if (state === 'OFF') {
  1775. var hostVersion = this.get('content.stackVersions') && this.get('content.stackVersions').findProperty('isCurrent').get('repoVersion'),
  1776. currentVersion = App.StackVersion.find().findProperty('isCurrent'),
  1777. clusterVersion = currentVersion && currentVersion.get('repositoryVersion.repositoryVersion');
  1778. if (hostVersion !== clusterVersion) {
  1779. var msg = Em.I18n.t("hosts.passiveMode.popup.version.mismatch").format(this.get('content.hostName'), clusterVersion);
  1780. popupInfo += '<br/><div class="alert alert-warning">' + msg + '</div>';
  1781. }
  1782. }
  1783. return App.showConfirmationPopup(function () {
  1784. self.hostPassiveModeRequest(state, message);
  1785. }, popupInfo);
  1786. },
  1787. /**
  1788. * Set rack id for host
  1789. * @method setRackIdForHost
  1790. */
  1791. setRackIdForHost: function () {
  1792. var hostNames = [{hostName: this.get('content.hostName')}];
  1793. var rack = this.get('content.rack');
  1794. var operationData = {message: Em.I18n.t('hosts.host.details.setRackId')};
  1795. hostsManagement.setRackInfo(operationData, hostNames, rack);
  1796. },
  1797. /**
  1798. * Send request to get passive state for host
  1799. * @param {string} state
  1800. * @param {string} message
  1801. * @method hostPassiveModeRequest
  1802. */
  1803. hostPassiveModeRequest: function (state, message) {
  1804. App.ajax.send({
  1805. name: 'bulk_request.hosts.passive_state',
  1806. sender: this,
  1807. data: {
  1808. hostNames: this.get('content.hostName'),
  1809. passive_state: state,
  1810. requestInfo: message
  1811. },
  1812. success: 'updateHost'
  1813. });
  1814. },
  1815. /**
  1816. * Success callback for receiving host passive state
  1817. * @param {object} data
  1818. * @param {object} opt
  1819. * @param {object} params
  1820. * @method updateHost
  1821. */
  1822. updateHost: function (data, opt, params) {
  1823. this.set('content.passiveState', params.passive_state);
  1824. batchUtils.infoPassiveState(params.passive_state);
  1825. },
  1826. /**
  1827. * Send request to get passive state for hostComponent
  1828. * @param {object} component - hostComponentn object
  1829. * @param {string} state
  1830. * @param {string} message
  1831. * @method hostPassiveModeRequest
  1832. */
  1833. updateComponentPassiveState: function (component, state, message) {
  1834. App.ajax.send({
  1835. name: 'common.host.host_component.passive',
  1836. sender: this,
  1837. data: {
  1838. hostName: this.get('content.hostName'),
  1839. componentName: component.get('componentName'),
  1840. component: component,
  1841. passive_state: state,
  1842. context: message
  1843. },
  1844. success: 'updateHostComponent'
  1845. });
  1846. },
  1847. /**
  1848. * Success callback for receiving hostComponent passive state
  1849. * @param {object} data
  1850. * @param {object} opt
  1851. * @param {object} params
  1852. * @method updateHost
  1853. */
  1854. updateHostComponent: function (data, opt, params) {
  1855. params.component.set('passiveState', params.passive_state);
  1856. batchUtils.infoPassiveState(params.passive_state);
  1857. },
  1858. /**
  1859. * Show confirmation popup for action "start all components"
  1860. * @method doStartAllComponents
  1861. */
  1862. doStartAllComponents: function () {
  1863. var self = this;
  1864. var components = this.get('serviceNonClientActiveComponents');
  1865. if (components && components.get('length')) {
  1866. return App.showConfirmationPopup(function () {
  1867. self.sendComponentCommand(components, Em.I18n.t('hosts.host.maintainance.startAllComponents.context'), App.HostComponentStatus.started);
  1868. });
  1869. }
  1870. },
  1871. /**
  1872. * Show confirmation popup for action "stop all components"
  1873. * @method doStopAllComponents
  1874. */
  1875. doStopAllComponents: function () {
  1876. var self = this;
  1877. var components = this.get('serviceNonClientActiveComponents');
  1878. if (components && components.get('length')) {
  1879. if (components.someProperty('componentName', 'NAMENODE') &&
  1880. this.get('content.hostComponents').filterProperty('componentName', 'NAMENODE').someProperty('workStatus', App.HostComponentStatus.started)) {
  1881. this.checkNnLastCheckpointTime(function () {
  1882. App.showConfirmationPopup(function () {
  1883. self.sendComponentCommand(components, Em.I18n.t('hosts.host.maintainance.stopAllComponents.context'), App.HostComponentStatus.stopped);
  1884. });
  1885. });
  1886. } else {
  1887. return App.showConfirmationPopup(function () {
  1888. self.sendComponentCommand(components, Em.I18n.t('hosts.host.maintainance.stopAllComponents.context'), App.HostComponentStatus.stopped);
  1889. });
  1890. }
  1891. }
  1892. },
  1893. /**
  1894. * Show confirmation popup for action "restart all components"
  1895. * @method doRestartAllComponents
  1896. */
  1897. doRestartAllComponents: function () {
  1898. var self = this;
  1899. var components = this.get('serviceActiveComponents');
  1900. if (components && components.get('length')) {
  1901. if (components.someProperty('componentName', 'NAMENODE') &&
  1902. this.get('content.hostComponents').filterProperty('componentName', 'NAMENODE').someProperty('workStatus', App.HostComponentStatus.started)) {
  1903. this.checkNnLastCheckpointTime(function () {
  1904. App.showConfirmationPopup(function () {
  1905. batchUtils.restartHostComponents(components, Em.I18n.t('rollingrestart.context.allOnSelectedHost').format(self.get('content.hostName')), "HOST");
  1906. });
  1907. });
  1908. } else {
  1909. return App.showConfirmationPopup(function () {
  1910. batchUtils.restartHostComponents(components, Em.I18n.t('rollingrestart.context.allOnSelectedHost').format(self.get('content.hostName')), "HOST");
  1911. });
  1912. }
  1913. }
  1914. },
  1915. /**
  1916. * get info about host-components, exactly:
  1917. * - host-components grouped by status, features
  1918. * - flag, that indicate whether ZooKeeper Server is installed
  1919. * @return {Object}
  1920. */
  1921. getHostComponentsInfo: function () {
  1922. var componentsOnHost = this.get('content.hostComponents');
  1923. var allComponents = App.HostComponent.find();
  1924. var stoppedStates = [App.HostComponentStatus.stopped,
  1925. App.HostComponentStatus.install_failed,
  1926. App.HostComponentStatus.upgrade_failed,
  1927. App.HostComponentStatus.init,
  1928. App.HostComponentStatus.unknown];
  1929. var container = {
  1930. zkServerInstalled: false,
  1931. lastComponents: [],
  1932. masterComponents: [],
  1933. runningComponents: [],
  1934. nonDeletableComponents: [],
  1935. unknownComponents: [],
  1936. toDecommissionComponents: []
  1937. };
  1938. var self = this;
  1939. if (componentsOnHost && componentsOnHost.get('length') > 0) {
  1940. componentsOnHost.forEach(function (cInstance) {
  1941. if (cInstance.get('componentName') === 'ZOOKEEPER_SERVER') {
  1942. container.zkServerInstalled = true;
  1943. }
  1944. if (allComponents.filterProperty('componentName', cInstance.get('componentName')).get('length') === 1) {
  1945. container.lastComponents.push(cInstance.get('displayName'));
  1946. }
  1947. var workStatus = cInstance.get('workStatus');
  1948. if (cInstance.get('isMaster') && !cInstance.get('isDeletable')) {
  1949. container.masterComponents.push(cInstance.get('displayName'));
  1950. }
  1951. if (stoppedStates.indexOf(workStatus) < 0) {
  1952. container.runningComponents.push(cInstance.get('displayName'));
  1953. }
  1954. if (!cInstance.get('isDeletable')) {
  1955. container.nonDeletableComponents.push(cInstance.get('displayName'));
  1956. }
  1957. if (workStatus === App.HostComponentStatus.unknown) {
  1958. container.unknownComponents.push(cInstance.get('displayName'));
  1959. }
  1960. if (App.get('components.decommissionAllowed').contains(cInstance.get('componentName')) && !cInstance.get('view.isComponentRecommissionAvailable')) {
  1961. container.toDecommissionComponents.push(cInstance.get('displayName'));
  1962. }
  1963. });
  1964. }
  1965. return container;
  1966. },
  1967. /**
  1968. * Deletion of hosts not supported for this version
  1969. * @method validateAndDeleteHost
  1970. */
  1971. validateAndDeleteHost: function () {
  1972. var container = this.getHostComponentsInfo();
  1973. if (container.masterComponents.length > 0) {
  1974. this.raiseDeleteComponentsError(container, 'masterList');
  1975. return;
  1976. } else if (container.nonDeletableComponents.length > 0) {
  1977. this.raiseDeleteComponentsError(container, 'nonDeletableList');
  1978. return;
  1979. } else if (container.runningComponents.length > 0) {
  1980. this.raiseDeleteComponentsError(container, 'runningList');
  1981. return;
  1982. }
  1983. if (container.zkServerInstalled) {
  1984. var self = this;
  1985. return App.showConfirmationPopup(function () {
  1986. self.confirmDeleteHost(container);
  1987. }, Em.I18n.t('hosts.host.addComponent.deleteHostWithZooKeeper'));
  1988. } else {
  1989. this.confirmDeleteHost(container);
  1990. }
  1991. },
  1992. /**
  1993. * Show popup with info about reasons why host can't be deleted
  1994. * @param {string[]} components
  1995. * @param {string} type
  1996. * @method raiseDeleteComponentsError
  1997. */
  1998. raiseDeleteComponentsError: function (container, type) {
  1999. App.ModalPopup.show({
  2000. header: Em.I18n.t('hosts.cant.do.popup.title'),
  2001. type: type,
  2002. showBodyEnd: Em.computed.existsIn('type', ['runningList', 'masterList']),
  2003. container: container,
  2004. components: function(){
  2005. var container = this.get('container');
  2006. switch (this.get('type')) {
  2007. case 'masterList':
  2008. return container.masterComponents;
  2009. case 'nonDeletableList':
  2010. return container.nonDeletableComponents;
  2011. case 'runningList':
  2012. return container.runningComponents;
  2013. }
  2014. }.property('type'),
  2015. componentsStr: function () {
  2016. return this.get('components').join(", ");
  2017. }.property('components.[]'),
  2018. componentsBody: Em.computed.i18nFormat('hosts.cant.do.popup.' + type + '.body', 'components.length'),
  2019. componentsBodyEnd: function () {
  2020. if (this.get('showBodyEnd')) {
  2021. return Em.I18n.t('hosts.cant.do.popup.' + type + '.body.end').format(App.get('components.decommissionAllowed').map(function(c){return App.format.role(c, false)}).join(", "));
  2022. }
  2023. return '';
  2024. }.property(),
  2025. bodyClass: Em.View.extend({
  2026. templateName: require('templates/main/host/details/raiseDeleteComponentErrorPopup')
  2027. }),
  2028. secondary: null
  2029. });
  2030. },
  2031. /**
  2032. * Show confirmation popup to delete host
  2033. * @param {Object} container
  2034. * @method confirmDeleteHost
  2035. */
  2036. confirmDeleteHost: function (container) {
  2037. var self = this;
  2038. return App.ModalPopup.show({
  2039. header: Em.I18n.t('hosts.delete.popup.title'),
  2040. deletePopupBody: Em.I18n.t('hosts.delete.popup.body').format(self.get('content.publicHostName')),
  2041. lastComponent: function () {
  2042. if (container.lastComponents && container.lastComponents.length) {
  2043. this.set('isChecked', false);
  2044. return true;
  2045. } else {
  2046. this.set('isChecked', true);
  2047. return false;
  2048. }
  2049. }.property(),
  2050. disablePrimary: Em.computed.not('isChecked'),
  2051. isChecked: false,
  2052. lastComponentError: Em.View.extend({
  2053. template: Em.Handlebars.compile(Em.I18n.t('hosts.delete.popup.body.msg4').format(container.lastComponents))
  2054. }),
  2055. unknownComponents: function () {
  2056. if (container.unknownComponents && container.unknownComponents.length) {
  2057. return container.unknownComponents.join(", ");
  2058. }
  2059. return '';
  2060. }.property(),
  2061. decommissionWarning: Em.View.extend({
  2062. template: Em.Handlebars.compile(Em.I18n.t('hosts.delete.popup.body.msg7').format(container.toDecommissionComponents.join(', ')))
  2063. }),
  2064. toDecommissionComponents: container.toDecommissionComponents,
  2065. bodyClass: Em.View.extend({
  2066. templateName: require('templates/main/host/details/doDeleteHostPopup')
  2067. }),
  2068. onPrimary: function () {
  2069. var popup = this;
  2070. var completeCallback = function () {
  2071. var remainingHosts = App.db.getSelectedHosts('mainHostController').removeObject(self.get('content.hostName'));
  2072. App.db.setSelectedHosts('mainHostController', remainingHosts);
  2073. popup.hide();
  2074. };
  2075. self.doDeleteHost(completeCallback);
  2076. }
  2077. });
  2078. },
  2079. /**
  2080. * send DELETE calls to components of host and after delete host itself
  2081. * @param completeCallback
  2082. * @method doDeleteHost
  2083. */
  2084. doDeleteHost: function (completeCallback) {
  2085. this.set('fromDeleteHost', true);
  2086. var allComponents = this.get('content.hostComponents');
  2087. var deleteError = null;
  2088. var dfd = $.Deferred();
  2089. var self = this;
  2090. if (allComponents.get('length') > 0) {
  2091. allComponents.forEach(function (component, index) {
  2092. var length = allComponents.get('length');
  2093. if (!deleteError) {
  2094. this._doDeleteHostComponent(component, function () {
  2095. deleteError = self.get('_deletedHostComponentResult');
  2096. if (index == length - 1) {
  2097. dfd.resolve();
  2098. }
  2099. });
  2100. }
  2101. }, this);
  2102. } else {
  2103. dfd.resolve();
  2104. }
  2105. dfd.done(function () {
  2106. if (!deleteError) {
  2107. App.ajax.send({
  2108. name: 'common.delete.host',
  2109. sender: self,
  2110. data: {
  2111. hostName: self.get('content.hostName')
  2112. },
  2113. callback: completeCallback,
  2114. success: 'deleteHostSuccessCallback',
  2115. error: 'deleteHostErrorCallback'
  2116. });
  2117. }
  2118. else {
  2119. completeCallback();
  2120. deleteError.xhr.responseText = "{\"message\": \"" + deleteError.xhr.statusText + "\"}";
  2121. App.ajax.defaultErrorHandler(deleteError.xhr, deleteError.url, deleteError.method, deleteError.xhr.status);
  2122. }
  2123. });
  2124. },
  2125. deleteHostSuccessCallback: function (data, rq, requestBody) {
  2126. var self = this;
  2127. App.router.get('updateController').updateHost(function () {
  2128. App.router.transitionTo('hosts.index');
  2129. });
  2130. if (!!(requestBody && requestBody.hostName))
  2131. App.hostsMapper.deleteRecord(App.Host.find().findProperty('hostName', requestBody.hostName));
  2132. App.router.get('clusterController').getAllHostNames();
  2133. },
  2134. deleteHostErrorCallback: function (xhr, textStatus, errorThrown, opt) {
  2135. xhr.responseText = "{\"message\": \"" + xhr.statusText + "\"}";
  2136. var self = this;
  2137. var callback = function () {
  2138. self.loadConfigs();
  2139. };
  2140. self.isServiceMetricsLoaded(callback);
  2141. App.ajax.defaultErrorHandler(xhr, opt.url, 'DELETE', xhr.status);
  2142. },
  2143. /**
  2144. * Send command to server to restart all host components with stale configs
  2145. * @method restartAllStaleConfigComponents
  2146. */
  2147. restartAllStaleConfigComponents: function () {
  2148. var self = this;
  2149. var staleComponents = self.get('content.componentsWithStaleConfigs');
  2150. if (staleComponents.someProperty('componentName', 'NAMENODE') &&
  2151. this.get('content.hostComponents').filterProperty('componentName', 'NAMENODE').someProperty('workStatus', App.HostComponentStatus.started)) {
  2152. this.checkNnLastCheckpointTime(function () {
  2153. App.showConfirmationPopup(function () {
  2154. batchUtils.restartHostComponents(staleComponents, Em.I18n.t('rollingrestart.context.allWithStaleConfigsOnSelectedHost').format(self.get('content.hostName')), "HOST");
  2155. });
  2156. });
  2157. } else {
  2158. return App.showConfirmationPopup(function () {
  2159. batchUtils.restartHostComponents(staleComponents, Em.I18n.t('rollingrestart.context.allWithStaleConfigsOnSelectedHost').format(self.get('content.hostName')), "HOST");
  2160. });
  2161. }
  2162. },
  2163. /**
  2164. * open Reassign Master Wizard with selected component
  2165. * @param {object} event
  2166. * @method moveComponent
  2167. */
  2168. moveComponent: function (event) {
  2169. if ($(event.target).closest('li').hasClass('disabled')) {
  2170. return;
  2171. }
  2172. return App.showConfirmationPopup(function () {
  2173. var component = event.context;
  2174. var reassignMasterController = App.router.get('reassignMasterController');
  2175. reassignMasterController.saveComponentToReassign(component);
  2176. reassignMasterController.setCurrentStep('1');
  2177. App.router.transitionTo('reassign');
  2178. });
  2179. },
  2180. /**
  2181. * Restart clients host components to apply config changes
  2182. * @param {object} event
  2183. * @method refreshConfigs
  2184. */
  2185. refreshConfigs: function (event) {
  2186. var self = this;
  2187. var components = event.context;
  2188. if (components.get('length') > 0) {
  2189. return App.showConfirmationPopup(function () {
  2190. batchUtils.restartHostComponents(components, Em.I18n.t('rollingrestart.context.allClientsOnSelectedHost').format(self.get('content.hostName')), "HOST");
  2191. });
  2192. }
  2193. },
  2194. toggleMaintenanceMode: function (event) {
  2195. var state, message, self = this;
  2196. if (event.context.get('isImpliedState')) return null;
  2197. state = event.context.get('passiveState') === "ON" ? "OFF" : "ON";
  2198. message = Em.I18n.t('passiveState.turn' + state.toCapital() + 'For').format(event.context.get('displayName'));
  2199. return App.showConfirmationPopup(function () {
  2200. self.updateComponentPassiveState(event.context, state, message);
  2201. });
  2202. },
  2203. downloadClientConfigs: function (event) {
  2204. this.downloadClientConfigsCall({
  2205. hostName: event.context.get('hostName'),
  2206. componentName: event.context.get('componentName'),
  2207. displayName: event.context.get('displayName')
  2208. });
  2209. },
  2210. installClients: function (event) {
  2211. var clientsToInstall = [],
  2212. clientsToAdd = [],
  2213. missedComponents = [],
  2214. dependentComponents = [],
  2215. self = this;
  2216. event.context.forEach(function (component) {
  2217. if (['INIT', 'INSTALL_FAILED'].contains(component.get('workStatus'))) {
  2218. clientsToInstall.push(component);
  2219. } else if (typeof component.get('workStatus') == 'undefined') {
  2220. clientsToAdd.push(component);
  2221. }
  2222. });
  2223. clientsToAdd.forEach(function (component, index, array) {
  2224. var dependencies = this.checkComponentDependencies(component.get('componentName'), {
  2225. scope: 'host',
  2226. installedComponents: this.get('content.hostComponents').mapProperty('componentName')
  2227. }).reject(function (componentName) {
  2228. return array.mapProperty('componentName').contains(componentName);
  2229. });
  2230. if (dependencies.length) {
  2231. missedComponents.pushObjects(dependencies);
  2232. dependentComponents.push(component.get('displayName'));
  2233. }
  2234. }, this);
  2235. missedComponents = missedComponents.uniq();
  2236. if (missedComponents.length) {
  2237. var popupMessage = Em.I18n.t('host.host.addComponent.popup.clients.dependedComponents.body').format(stringUtils.getFormattedStringFromArray(dependentComponents),
  2238. stringUtils.getFormattedStringFromArray(missedComponents.map(function (componentName) {
  2239. return App.StackServiceComponent.find(componentName).get('displayName');
  2240. })));
  2241. App.showAlertPopup(Em.I18n.t('host.host.addComponent.popup.dependedComponents.header'), popupMessage);
  2242. } else {
  2243. App.get('router.mainAdminKerberosController').getSecurityType(function () {
  2244. App.get('router.mainAdminKerberosController').getKDCSessionState(function () {
  2245. var sendInstallCommand = function () {
  2246. if (clientsToInstall.length) {
  2247. self.sendComponentCommand(clientsToInstall, Em.I18n.t('host.host.details.installClients'), 'INSTALLED');
  2248. }
  2249. };
  2250. if (clientsToAdd.length) {
  2251. var message = stringUtils.getFormattedStringFromArray(clientsToAdd.mapProperty('displayName'));
  2252. var isManualKerberos = App.get('router.mainAdminKerberosController.isManualKerberos');
  2253. self.showAddComponentPopup(message, isManualKerberos, function () {
  2254. sendInstallCommand();
  2255. clientsToAdd.forEach(function (component) {
  2256. self.installHostComponentCall(self.get('content.hostName'), component);
  2257. });
  2258. });
  2259. } else {
  2260. sendInstallCommand();
  2261. }
  2262. });
  2263. }.bind(this));
  2264. }
  2265. },
  2266. /**
  2267. * Check if all required components are installed on host.
  2268. * Available options:
  2269. * scope: 'host' - dependency level `host`,`cluster` or `*`.
  2270. * hostName: 'example.com' - host name to search installed components
  2271. * installedComponents: ['A', 'B'] - names of installed components
  2272. *
  2273. * By default scope level is `*`
  2274. * For host level dependency you should specify at least `hostName` or `installedComponents` attribute.
  2275. *
  2276. * @param {String} componentName
  2277. * @param {Object} opt - options. Allowed options are `hostName`, `installedComponents`, `scope`.
  2278. * @return {Array} - names of missed components
  2279. */
  2280. checkComponentDependencies: function (componentName, opt) {
  2281. opt = opt || {};
  2282. opt.scope = opt.scope || '*';
  2283. var installedComponents;
  2284. var dependencies = App.StackServiceComponent.find(componentName).get('dependencies');
  2285. dependencies = opt.scope === '*' ? dependencies : dependencies.filterProperty('scope', opt.scope);
  2286. if (dependencies.length == 0) return [];
  2287. switch (opt.scope) {
  2288. case 'host':
  2289. Em.assert("You should pass at least `hostName` or `installedComponents` to options.", opt.hostName || opt.installedComponents);
  2290. installedComponents = opt.installedComponents || App.HostComponent.find().filterProperty('hostName', opt.hostName).mapProperty('componentName').uniq();
  2291. break;
  2292. default:
  2293. // @todo: use more appropriate value regarding installed components
  2294. installedComponents = opt.installedComponents || App.HostComponent.find().mapProperty('componentName').uniq();
  2295. break;
  2296. }
  2297. return dependencies.filter(function (dependency) {
  2298. return !installedComponents.contains(dependency.componentName);
  2299. }).mapProperty('componentName');
  2300. },
  2301. /**
  2302. * On click handler for custom command from items menu
  2303. * @param context
  2304. */
  2305. executeCustomCommand: function(event) {
  2306. var controller = this;
  2307. var context = event.context;
  2308. return App.showConfirmationPopup(function() {
  2309. App.ajax.send({
  2310. name : 'service.item.executeCustomCommand',
  2311. sender: controller,
  2312. data : {
  2313. command : context.command,
  2314. context : context.context || Em.I18n.t('services.service.actions.run.executeCustomCommand.context').format(context.command),
  2315. hosts : context.hosts,
  2316. serviceName : context.service,
  2317. componentName : context.component
  2318. },
  2319. success : 'executeCustomCommandSuccessCallback',
  2320. error : 'executeCustomCommandErrorCallback'
  2321. });
  2322. });
  2323. },
  2324. executeCustomCommandSuccessCallback : function(data, ajaxOptions, params) {
  2325. if (data.Requests.id) {
  2326. App.router.get('backgroundOperationsController').showPopup();
  2327. }
  2328. },
  2329. executeCustomCommandErrorCallback : function(data) {
  2330. var error = Em.I18n.t('services.service.actions.run.executeCustomCommand.error');
  2331. if(data && data.responseText){
  2332. try {
  2333. var json = $.parseJSON(data.responseText);
  2334. error += json.message;
  2335. } catch (err) {}
  2336. }
  2337. App.showAlertPopup(Em.I18n.t('services.service.actions.run.executeCustomCommand.error'), error);
  2338. },
  2339. /**
  2340. * Call callback after loading service metrics
  2341. * @param callback
  2342. */
  2343. isServiceMetricsLoaded: function(callback) {
  2344. App.router.get('mainController').isLoading.call(App.router.get('clusterController'), 'isServiceContentFullyLoaded').done(callback);
  2345. }
  2346. });