details.js 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504
  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('userSettingsController').dataLoading('show_bg').done(function (initValue) {
  2327. if (initValue) {
  2328. App.router.get('backgroundOperationsController').showPopup();
  2329. }
  2330. });
  2331. }
  2332. },
  2333. executeCustomCommandErrorCallback : function(data) {
  2334. var error = Em.I18n.t('services.service.actions.run.executeCustomCommand.error');
  2335. if(data && data.responseText){
  2336. try {
  2337. var json = $.parseJSON(data.responseText);
  2338. error += json.message;
  2339. } catch (err) {}
  2340. }
  2341. App.showAlertPopup(Em.I18n.t('services.service.actions.run.executeCustomCommand.error'), error);
  2342. },
  2343. /**
  2344. * Call callback after loading service metrics
  2345. * @param callback
  2346. */
  2347. isServiceMetricsLoaded: function(callback) {
  2348. App.router.get('mainController').isLoading.call(App.router.get('clusterController'), 'isServiceContentFullyLoaded').done(callback);
  2349. }
  2350. });