details.js 83 KB

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