details.js 83 KB

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