item.js 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556
  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 blueprintUtils = require('utils/blueprint');
  21. var stringUtils = require('utils/string_utils');
  22. App.MainServiceItemController = Em.Controller.extend(App.SupportClientConfigsDownload, App.InstallComponent, App.ConfigsSaverMixin, App.EnhancedConfigsMixin, {
  23. name: 'mainServiceItemController',
  24. /**
  25. * Callback functions for start and stop service have few differences
  26. *
  27. * Used with currentCallBack property
  28. */
  29. callBackConfig: {
  30. 'STARTED': {
  31. 'c': 'STARTING',
  32. 'f': 'starting',
  33. 'c2': 'live',
  34. 'hs': 'started',
  35. 's': 'start'
  36. },
  37. 'INSTALLED': {
  38. 'c': 'STOPPING',
  39. 'f': 'stopping',
  40. 'c2': 'dead',
  41. 'hs': 'stopped',
  42. 's': 'stop'
  43. }
  44. },
  45. /**
  46. * Map of service names and lists of sites they need to load
  47. */
  48. serviceConfigsMap: {
  49. 'OOZIE': ['oozie-env']
  50. },
  51. /**
  52. * Configs loaded to use for service actions menu
  53. *
  54. * format: {config-type: {property-name1: property-value1, property-name2: property-value2, ...}}
  55. */
  56. configs: {},
  57. /**
  58. * @type {boolean}
  59. * @default true
  60. */
  61. isPending: true,
  62. /**
  63. * @type {boolean}
  64. * @default false
  65. */
  66. isServicesInfoLoaded: false,
  67. /**
  68. * Define whether configs for service actions menu were loaded
  69. * @type {Boolean}
  70. */
  71. isServiceConfigsLoaded: false,
  72. /**
  73. * flag to control router switch between service summary and configs
  74. * @type {boolean}
  75. */
  76. routeToConfigs: false,
  77. deleteServiceProgressPopup: null,
  78. isClientsOnlyService: function() {
  79. return App.get('services.clientOnly').contains(this.get('content.serviceName'));
  80. }.property('content.serviceName'),
  81. isConfigurable: function () {
  82. return !App.get('services.noConfigTypes').contains(this.get('content.serviceName'));
  83. }.property('App.services.noConfigTypes','content.serviceName'),
  84. clientComponents: function () {
  85. var clientNames = [];
  86. var clients = App.StackServiceComponent.find().filterProperty('serviceName', this.get('content.serviceName')).filterProperty('isClient');
  87. clients.forEach(function (item) {
  88. clientNames.push({
  89. action: 'downloadClientConfigs',
  90. context: {
  91. name: item.get('componentName'),
  92. label: item.get('displayName')
  93. }
  94. });
  95. });
  96. return clientNames;
  97. }.property('content.serviceName'),
  98. /**
  99. * Returns interdependent services
  100. *
  101. * @returns {string[]}
  102. */
  103. interDependentServices: function() {
  104. var serviceName = this.get('content.serviceName'), interDependentServices = [];
  105. App.StackService.find(serviceName).get('requiredServices').forEach(function(requiredService) {
  106. if (App.StackService.find(requiredService).get('requiredServices').contains(serviceName)) {
  107. interDependentServices.push(requiredService);
  108. }
  109. });
  110. return interDependentServices;
  111. }.property('content.serviceName'),
  112. /**
  113. * collection of serviceConfigs
  114. *
  115. * @type {Object[]}
  116. */
  117. stepConfigs: [],
  118. /**
  119. * List of service names that have configs dependent on current service configs
  120. *
  121. * @type {String[]}
  122. */
  123. dependentServiceNames: function() {
  124. return App.StackService.find(this.get('content.serviceName')).get('dependentServiceNames');
  125. }.property('content.serviceName'),
  126. /**
  127. * List of service names that could be deleted
  128. * Common case when there is only current service should be removed
  129. * But for some services there is <code>interDependentServices<code> services
  130. * Like 'YARN' depends on 'MAPREDUCE2' and 'MAPREDUCE2' depends on 'YARN'
  131. * So these services can be removed only together
  132. *
  133. * @type {String[]}
  134. */
  135. serviceNamesToDelete: function() {
  136. return [this.get('content.serviceName')].concat(this.get('interDependentServices'));
  137. }.property('content.serviceName'),
  138. /**
  139. * List of config types that should be loaded
  140. * Includes
  141. * 1. Dependent services config-types
  142. * 2. Some special cases from <code>serviceConfigsMap<code>
  143. * 3. 'cluster-env'
  144. *
  145. * @type {String[]}
  146. */
  147. sitesToLoad: function() {
  148. var services = this.get('dependentServiceNames'), configTypeList = [];
  149. if (services.length) {
  150. configTypeList = App.StackService.find().filter(function(s) {
  151. return services.contains(s.get('serviceName'));
  152. }).mapProperty('configTypeList').reduce(function(p, v) {
  153. return p.concat(v);
  154. });
  155. }
  156. if (this.get('serviceConfigsMap')[this.get('content.serviceName')]) {
  157. configTypeList = configTypeList.concat(this.get('serviceConfigsMap')[this.get('content.serviceName')]);
  158. }
  159. configTypeList.push('cluster-env');
  160. return configTypeList.uniq();
  161. }.property('content.serviceName'),
  162. /**
  163. * Load all config tags for loading configs
  164. */
  165. loadConfigs: function(){
  166. this.set('isServiceConfigsLoaded', false);
  167. App.ajax.send({
  168. name: 'config.tags',
  169. sender: this,
  170. success: 'onLoadConfigsTags',
  171. error: 'onTaskError'
  172. });
  173. },
  174. /**
  175. * Load all configs for sites from <code>serviceConfigsMap</code> for current service
  176. * @param data
  177. */
  178. onLoadConfigsTags: function (data) {
  179. var self = this;
  180. var sitesToLoad = this.get('sitesToLoad'), allConfigs = [];
  181. var loadedSites = data.Clusters.desired_configs;
  182. var siteTagsToLoad = [];
  183. for (var site in loadedSites) {
  184. if (sitesToLoad.contains(site)) {
  185. siteTagsToLoad.push({
  186. siteName: site,
  187. tagName: loadedSites[site].tag
  188. });
  189. }
  190. }
  191. App.router.get('configurationController').getConfigsByTags(siteTagsToLoad).done(function (configs) {
  192. configs.forEach(function (site) {
  193. self.get('configs')[site.type] = site.properties;
  194. allConfigs = allConfigs.concat(App.config.getConfigsFromJSON(site, true));
  195. });
  196. self.get('dependentServiceNames').forEach(function(serviceName) {
  197. var configTypes = App.StackService.find(serviceName).get('configTypeList');
  198. var configsByService = allConfigs.filter(function (c) {
  199. return configTypes.contains(App.config.getConfigTagFromFileName(c.get('filename')));
  200. });
  201. self.get('stepConfigs').pushObject(App.config.createServiceConfig(serviceName, [], configsByService));
  202. });
  203. self.set('isServiceConfigsLoaded', true);
  204. });
  205. },
  206. /**
  207. * Common method for ajax (start/stop service) responses
  208. * @param data
  209. * @param ajaxOptions
  210. * @param params
  211. */
  212. startStopPopupSuccessCallback: function (data, ajaxOptions, params) {
  213. if (data && data.Requests) {
  214. params.query.set('status', 'SUCCESS');
  215. var config = this.get('callBackConfig')[(JSON.parse(ajaxOptions.data)).Body.ServiceInfo.state];
  216. var self = this;
  217. if (App.get('testMode')) {
  218. self.set('content.workStatus', App.Service.Health[config.f]);
  219. self.get('content.hostComponents').setEach('workStatus', App.HostComponentStatus[config.f]);
  220. setTimeout(function () {
  221. self.set('content.workStatus', App.Service.Health[config.c2]);
  222. self.get('content.hostComponents').setEach('workStatus', App.HostComponentStatus[config.hs]);
  223. }, App.get('testModeDelayForActions'));
  224. }
  225. // load data (if we need to show this background operations popup) from persist
  226. App.router.get('userSettingsController').dataLoading('show_bg').done(function (initValue) {
  227. if (initValue) {
  228. App.router.get('backgroundOperationsController').showPopup();
  229. }
  230. });
  231. } else {
  232. params.query.set('status', 'FAIL');
  233. }
  234. },
  235. startStopPopupErrorCallback: function(request, ajaxOptions, error, opt, params){
  236. params.query.set('status', 'FAIL');
  237. },
  238. /**
  239. * Confirmation popup for start/stop services
  240. * @param event
  241. * @param serviceHealth - 'STARTED' or 'INSTALLED'
  242. */
  243. startStopPopup: function(event, serviceHealth) {
  244. if ($(event.target).hasClass('disabled') || $(event.target.parentElement).hasClass('disabled')) {
  245. return;
  246. }
  247. var self = this;
  248. var serviceDisplayName = this.get('content.displayName');
  249. var isMaintenanceOFF = this.get('content.passiveState') === 'OFF';
  250. var msg = isMaintenanceOFF && serviceHealth == 'INSTALLED'? Em.I18n.t('services.service.stop.warningMsg.turnOnMM').format(serviceDisplayName) : null;
  251. msg = self.addAdditionalWarningMessage(serviceHealth, msg, serviceDisplayName);
  252. var bodyMessage = Em.Object.create({
  253. putInMaintenance: (serviceHealth == 'INSTALLED' && isMaintenanceOFF) || (serviceHealth == 'STARTED' && !isMaintenanceOFF),
  254. turnOnMmMsg: serviceHealth == 'INSTALLED' ? Em.I18n.t('passiveState.turnOnFor').format(serviceDisplayName) : Em.I18n.t('passiveState.turnOffFor').format(serviceDisplayName),
  255. confirmMsg: serviceHealth == 'INSTALLED'? Em.I18n.t('services.service.stop.confirmMsg').format(serviceDisplayName) : Em.I18n.t('services.service.start.confirmMsg').format(serviceDisplayName),
  256. confirmButton: serviceHealth == 'INSTALLED'? Em.I18n.t('services.service.stop.confirmButton') : Em.I18n.t('services.service.start.confirmButton'),
  257. additionalWarningMsg: msg
  258. });
  259. // check HDFS NameNode checkpoint before stop service
  260. if (this.get('content.serviceName') == 'HDFS' && serviceHealth == 'INSTALLED' &&
  261. this.get('content.hostComponents').filterProperty('componentName', 'NAMENODE').someProperty('workStatus', App.HostComponentStatus.started)) {
  262. this.checkNnLastCheckpointTime(function () {
  263. return App.showConfirmationFeedBackPopup(function(query, runMmOperation) {
  264. self.set('isPending', true);
  265. self.startStopWithMmode(serviceHealth, query, runMmOperation);
  266. }, bodyMessage);
  267. });
  268. } else {
  269. return App.showConfirmationFeedBackPopup(function(query, runMmOperation) {
  270. self.set('isPending', true);
  271. self.startStopWithMmode(serviceHealth, query, runMmOperation);
  272. }, bodyMessage);
  273. }
  274. },
  275. /**
  276. * this function will be called from :1) stop HDFS 2) restart all for HDFS 3) restart all affected for HDFS
  277. * @param callback - callback function to continue next operation
  278. */
  279. checkNnLastCheckpointTime: function(callback) {
  280. var self = this;
  281. this.pullNnCheckPointTime().complete(function () {
  282. var isNNCheckpointTooOld = self.get('isNNCheckpointTooOld');
  283. self.set('isNNCheckpointTooOld', null);
  284. if (isNNCheckpointTooOld) {
  285. // too old
  286. self.getHdfsUser().done(function() {
  287. var msg = Em.Object.create({
  288. confirmMsg: Em.I18n.t('services.service.stop.HDFS.warningMsg.checkPointTooOld').format(App.nnCheckpointAgeAlertThreshold) +
  289. Em.I18n.t('services.service.stop.HDFS.warningMsg.checkPointTooOld.instructions').format(isNNCheckpointTooOld, self.get('hdfsUser')),
  290. confirmButton: Em.I18n.t('common.next')
  291. });
  292. return App.showConfirmationFeedBackPopup(callback, msg);
  293. });
  294. } else if (isNNCheckpointTooOld == null) {
  295. // not available
  296. return App.showConfirmationPopup(
  297. callback, Em.I18n.t('services.service.stop.HDFS.warningMsg.checkPointNA'), null,
  298. Em.I18n.t('common.warning'), Em.I18n.t('common.proceedAnyway'), true
  299. );
  300. } else {
  301. // still young
  302. callback();
  303. }
  304. });
  305. },
  306. pullNnCheckPointTime: function () {
  307. return App.ajax.send({
  308. name: 'common.service.hdfs.getNnCheckPointTime',
  309. sender: this,
  310. success: 'parseNnCheckPointTime'
  311. });
  312. },
  313. parseNnCheckPointTime: function (data) {
  314. var nameNodesStatus = [];
  315. var lastCheckpointTime, hostName;
  316. if (data.host_components.length <= 1) {
  317. lastCheckpointTime = Em.get(data.host_components[0], 'metrics.dfs.FSNamesystem.LastCheckpointTime');
  318. hostName = Em.get(data.host_components[0], 'HostRoles.host_name');
  319. } else {
  320. // HA enabled
  321. data.host_components.forEach(function(namenode) {
  322. nameNodesStatus.pushObject( Em.Object.create({
  323. LastCheckpointTime: Em.get(namenode, 'metrics.dfs.FSNamesystem.LastCheckpointTime'),
  324. HAState: Em.get(namenode, 'metrics.dfs.FSNamesystem.HAState'),
  325. hostName: Em.get(namenode, 'HostRoles.host_name')
  326. }));
  327. });
  328. if (nameNodesStatus.someProperty('HAState', 'active')) {
  329. if (nameNodesStatus.findProperty('HAState', 'active').get('LastCheckpointTime')) {
  330. lastCheckpointTime = nameNodesStatus.findProperty('HAState', 'active').get('LastCheckpointTime');
  331. hostName = nameNodesStatus.findProperty('HAState', 'active').get('hostName');
  332. } else if (nameNodesStatus.someProperty('LastCheckpointTime')) {
  333. lastCheckpointTime = nameNodesStatus.findProperty('LastCheckpointTime').get('LastCheckpointTime');
  334. hostName = nameNodesStatus.findProperty('LastCheckpointTime').get('hostName');
  335. }
  336. } else if (nameNodesStatus.someProperty('HAState', 'standby')) {
  337. lastCheckpointTime = nameNodesStatus.findProperty('HAState', 'standby').get('LastCheckpointTime');
  338. hostName = nameNodesStatus.findProperty('HAState', 'standby').get('hostName')
  339. }
  340. }
  341. if (!lastCheckpointTime) {
  342. this.set("isNNCheckpointTooOld", null);
  343. } else {
  344. var time_criteria = App.nnCheckpointAgeAlertThreshold; // time in hours to define how many hours ago is too old
  345. var time_ago = (Math.round(App.dateTime() / 1000) - (time_criteria * 3600)) *1000;
  346. if (lastCheckpointTime <= time_ago) {
  347. // too old, set the effected hostName
  348. this.set("isNNCheckpointTooOld", hostName);
  349. } else {
  350. // still young
  351. this.set("isNNCheckpointTooOld", false);
  352. }
  353. }
  354. },
  355. /**
  356. * Return true if hdfs user data is loaded via App.MainServiceInfoConfigsController
  357. */
  358. getHdfsUser: function () {
  359. var self = this;
  360. var dfd = $.Deferred();
  361. var miscController = App.MainAdminServiceAccountsController.create();
  362. miscController.loadUsers();
  363. var interval = setInterval(function () {
  364. if (miscController.get('dataIsLoaded') && miscController.get('users')) {
  365. self.set('hdfsUser', miscController.get('users').findProperty('name', 'hdfs_user').get('value'));
  366. dfd.resolve();
  367. clearInterval(interval);
  368. }
  369. }, 10);
  370. return dfd.promise();
  371. },
  372. addAdditionalWarningMessage: function(serviceHealth, msg, serviceDisplayName){
  373. var servicesAffectedDisplayNames = [];
  374. var servicesAffected = [];
  375. if(serviceHealth == 'INSTALLED'){
  376. //To stop a service, display dependencies message...
  377. var currentService = this.get('content.serviceName');
  378. var stackServices = App.StackService.find();
  379. stackServices.forEach(function(service){
  380. if(service.get('isInstalled') || service.get('isSelected')){ //only care about services installed...
  381. var stackServiceDisplayName = service.get("displayName");
  382. var requiredServices = service.get('requiredServices'); //services required in order to have the current service be functional...
  383. if (!!requiredServices && requiredServices.length) { //only care about services with a non-empty requiredServices list.
  384. requiredServices.forEach(function(_requiredService){
  385. if (currentService === _requiredService) { //the service to be stopped is a required service by some other services...
  386. if(servicesAffected.indexOf(service) == -1 ) {
  387. servicesAffected.push(service);
  388. servicesAffectedDisplayNames.push(stackServiceDisplayName);
  389. }
  390. }
  391. },this);
  392. }
  393. }
  394. },this);
  395. var names = servicesAffectedDisplayNames.join();
  396. if(names){
  397. //only display this line with a non-empty dependency list
  398. var dependenciesMsg = Em.I18n.t('services.service.stop.warningMsg.dependent.services').format(serviceDisplayName, names);
  399. msg = msg ? msg + " " + dependenciesMsg : dependenciesMsg;
  400. }
  401. }
  402. return msg;
  403. },
  404. startStopWithMmode: function(serviceHealth, query, runMmOperation) {
  405. var self = this;
  406. if (runMmOperation) {
  407. if (serviceHealth == "STARTED") {
  408. this.startStopPopupPrimary(serviceHealth, query).complete(function() {
  409. batchUtils.turnOnOffPassiveRequest("OFF", Em.I18n.t('passiveState.turnOff'), self.get('content.serviceName').toUpperCase());
  410. });
  411. } else {
  412. batchUtils.turnOnOffPassiveRequest("ON", Em.I18n.t('passiveState.turnOn'), this.get('content.serviceName').toUpperCase()).complete(function() {
  413. self.startStopPopupPrimary(serviceHealth, query);
  414. })
  415. }
  416. } else {
  417. this.startStopPopupPrimary(serviceHealth, query);
  418. }
  419. },
  420. startStopPopupPrimary: function (serviceHealth, query) {
  421. var requestInfo = (serviceHealth == "STARTED")
  422. ? App.BackgroundOperationsController.CommandContexts.START_SERVICE.format(this.get('content.serviceName'))
  423. : App.BackgroundOperationsController.CommandContexts.STOP_SERVICE.format(this.get('content.serviceName'));
  424. var data = {
  425. 'context': requestInfo,
  426. 'serviceName': this.get('content.serviceName').toUpperCase(),
  427. 'ServiceInfo': {
  428. 'state': serviceHealth
  429. },
  430. 'query': query
  431. };
  432. return App.ajax.send({
  433. 'name': 'common.service.update',
  434. 'sender': this,
  435. 'success': 'startStopPopupSuccessCallback',
  436. 'error': 'startStopPopupErrorCallback',
  437. 'data': data
  438. });
  439. },
  440. /**
  441. * On click callback for <code>start service</code> button
  442. * @param event
  443. */
  444. startService: function (event) {
  445. this.startStopPopup(event, App.HostComponentStatus.started);
  446. },
  447. /**
  448. * On click callback for <code>stop service</code> button
  449. * @param event
  450. */
  451. stopService: function (event) {
  452. this.startStopPopup(event, App.HostComponentStatus.stopped);
  453. },
  454. /**
  455. * On click callback for <code>run rebalancer</code> button
  456. * @param event
  457. */
  458. runRebalancer: function (event) {
  459. var self = this;
  460. return App.showConfirmationPopup(function() {
  461. self.set("content.runRebalancer", true);
  462. // load data (if we need to show this background operations popup) from persist
  463. App.router.get('userSettingsController').dataLoading('show_bg').done(function (initValue) {
  464. if (initValue) {
  465. App.router.get('backgroundOperationsController').showPopup();
  466. }
  467. });
  468. });
  469. },
  470. /**
  471. * On click handler for Yarn Refresh Queues command from items menu
  472. * @param event
  473. */
  474. refreshYarnQueues : function (event) {
  475. var controller = this;
  476. var hosts = App.Service.find('YARN').get('hostComponents').filterProperty('componentName', 'RESOURCEMANAGER').mapProperty('hostName');
  477. return App.showConfirmationPopup(function() {
  478. App.ajax.send({
  479. name : 'service.item.refreshQueueYarnRequest',
  480. sender: controller,
  481. data : {
  482. command : "REFRESHQUEUES",
  483. context : Em.I18n.t('services.service.actions.run.yarnRefreshQueues.context') ,
  484. hosts : hosts.join(','),
  485. serviceName : "YARN",
  486. componentName : "RESOURCEMANAGER",
  487. forceRefreshConfigTags : "capacity-scheduler"
  488. },
  489. success : 'refreshYarnQueuesSuccessCallback',
  490. error : 'refreshYarnQueuesErrorCallback'
  491. });
  492. });
  493. },
  494. refreshYarnQueuesSuccessCallback : function(data, ajaxOptions, params) {
  495. if (data.Requests.id) {
  496. App.router.get('backgroundOperationsController').showPopup();
  497. }
  498. },
  499. refreshYarnQueuesErrorCallback : function(data) {
  500. var error = Em.I18n.t('services.service.actions.run.yarnRefreshQueues.error');
  501. if(data && data.responseText){
  502. try {
  503. var json = $.parseJSON(data.responseText);
  504. error += json.message;
  505. } catch (err) {}
  506. }
  507. App.showAlertPopup(Em.I18n.t('services.service.actions.run.yarnRefreshQueues.error'), error);
  508. },
  509. startLdapKnox: function(event) {
  510. var context = Em.I18n.t('services.service.actions.run.startLdapKnox.context');
  511. this.startStopLdapKnox('STARTDEMOLDAP',context);
  512. },
  513. stopLdapKnox: function(event) {
  514. var context = Em.I18n.t('services.service.actions.run.stopLdapKnox.context');
  515. this.startStopLdapKnox('STOPDEMOLDAP',context);
  516. },
  517. startStopLdapKnox: function(command,context) {
  518. var controller = this;
  519. var host = App.HostComponent.find().findProperty('componentName', 'KNOX_GATEWAY').get('hostName');
  520. return App.showConfirmationPopup(function() {
  521. App.ajax.send({
  522. name: 'service.item.startStopLdapKnox',
  523. sender: controller,
  524. data: {
  525. command: command,
  526. context: context,
  527. host: host,
  528. serviceName: "KNOX",
  529. componentName: "KNOX_GATEWAY"
  530. },
  531. success: 'startStopLdapKnoxSuccessCallback',
  532. error: 'startStopLdapKnoxErrorCallback'
  533. });
  534. });
  535. },
  536. startStopLdapKnoxSuccessCallback : function(data, ajaxOptions, params) {
  537. if (data.Requests.id) {
  538. App.router.get('backgroundOperationsController').showPopup();
  539. }
  540. },
  541. startStopLdapKnoxErrorCallback : function(data) {
  542. var error = Em.I18n.t('services.service.actions.run.startStopLdapKnox.error');
  543. if(data && data.responseText){
  544. try {
  545. var json = $.parseJSON(data.responseText);
  546. error += json.message;
  547. } catch (err) {}
  548. }
  549. App.showAlertPopup(Em.I18n.t('services.service.actions.run.yarnRefreshQueues.error'), error);
  550. },
  551. restartLLAP: function () {
  552. var isRefreshQueueRequired, self = this;
  553. return App.showConfirmationPopup(function () {
  554. // regresh queue request is sending only if YARN service has stale configs
  555. isRefreshQueueRequired = App.Service.find().findProperty('serviceName', 'YARN').get('isRestartRequired');
  556. if (isRefreshQueueRequired) {
  557. self.restartLLAPAndRefreshQueueRequest();
  558. } else {
  559. self.restartLLAPRequest();
  560. }
  561. });
  562. },
  563. restartLLAPRequest: function () {
  564. var host = App.HostComponent.find().findProperty('componentName', 'HIVE_SERVER_INTERACTIVE').get('hostName');
  565. App.ajax.send({
  566. name: 'service.item.executeCustomCommand',
  567. sender: this,
  568. data: {
  569. command: 'RESTART_LLAP',
  570. context: Em.I18n.t('services.service.actions.run.restartLLAP'),
  571. hosts: host,
  572. serviceName: "HIVE",
  573. componentName: "HIVE_SERVER_INTERACTIVE"
  574. },
  575. success: 'requestSuccessCallback',
  576. error: 'requestErrorCallback'
  577. });
  578. },
  579. restartLLAPAndRefreshQueueRequest: function () {
  580. var hiveServerInteractiveHost = App.HostComponent.find().findProperty('componentName', 'HIVE_SERVER_INTERACTIVE').get('hostName');
  581. var resourceManagerHost = App.HostComponent.find().findProperty('componentName', 'RESOURCEMANAGER').get('hostName');
  582. var batches = [{
  583. "order_id": 1,
  584. "type": "POST",
  585. "uri": App.apiPrefix + "/clusters/" + App.get('clusterName') + "/requests",
  586. "RequestBodyInfo": {
  587. "RequestInfo": {
  588. "context": "Refresh YARN Capacity Scheduler",
  589. "command": "REFRESHQUEUES",
  590. "parameters/forceRefreshConfigTags": "capacity-scheduler"
  591. },
  592. "Requests/resource_filters": [{
  593. "service_name": "YARN",
  594. "component_name": "RESOURCEMANAGER",
  595. "hosts": resourceManagerHost
  596. }]
  597. }
  598. }, {
  599. "order_id": 2,
  600. "type": "POST",
  601. "uri": App.apiPrefix + "/clusters/" + App.get('clusterName') + "/requests",
  602. "RequestBodyInfo": {
  603. "RequestInfo": {"context": "Restart LLAP", "command": "RESTART_LLAP"},
  604. "Requests/resource_filters": [{
  605. "service_name": "HIVE",
  606. "component_name": "HIVE_SERVER_INTERACTIVE",
  607. "hosts": hiveServerInteractiveHost
  608. }]
  609. }
  610. }];
  611. App.ajax.send({
  612. name: 'common.batch.request_schedules',
  613. sender: this,
  614. data: {
  615. intervalTimeSeconds: 1,
  616. tolerateSize: 0,
  617. batches: batches
  618. },
  619. success: 'requestSuccessCallback',
  620. error: 'requestErrorCallback'
  621. });
  622. },
  623. requestSuccessCallback: function () {
  624. App.router.get('userSettingsController').dataLoading('show_bg').done(function (initValue) {
  625. if (initValue) {
  626. App.router.get('backgroundOperationsController').showPopup();
  627. }
  628. });
  629. },
  630. requestErrorCallback : function(data) {
  631. var error = Em.I18n.t('services.service.actions.run.executeCustomCommand.error');
  632. if (data && data.responseText) {
  633. try {
  634. var json = $.parseJSON(data.responseText);
  635. error += json.message;
  636. } catch (err) {}
  637. }
  638. App.showAlertPopup(Em.I18n.t('common.error'), error);
  639. },
  640. createYARNDirectories: function(event) {
  641. var context = Em.I18n.t('services.service.actions.run.createYARNDirectories');
  642. var command = "CREATE_YARN_DIRECTORIES";
  643. var component = "NODEMANAGER";
  644. var controller = this;
  645. var hosts = App.Service.find('YARN').get('hostComponents').filterProperty('componentName', component).mapProperty('hostName');
  646. return App.showConfirmationPopup(function() {
  647. App.ajax.send({
  648. name: 'service.item.executeCustomCommand',
  649. sender: controller,
  650. data: {
  651. command: command,
  652. context: context,
  653. hosts: hosts.join(','),
  654. serviceName: "YARN",
  655. componentName: component
  656. },
  657. success: 'createYARNDirectoriesSuccessCallback',
  658. error: 'createYARNDirectoriesErrorCallback'
  659. });
  660. }, Em.I18n.t('services.service.actions.run.createYARNDirectories.confirmation'), null, Em.I18n.t('popup.confirmation.commonHeader'), Em.I18n.t('ok'), false);
  661. },
  662. createYARNDirectoriesSuccessCallback : function(data, ajaxOptions, params) {
  663. if (data.Requests.id) {
  664. App.router.get('backgroundOperationsController').showPopup();
  665. }
  666. },
  667. createYARNDirectoriesErrorCallback : function(data) {
  668. var error = Em.I18n.t('services.service.actions.run.executeCustomCommand.error');
  669. if (data && data.responseText) {
  670. try {
  671. var json = $.parseJSON(data.responseText);
  672. error += json.message;
  673. } catch (err) {}
  674. }
  675. App.showAlertPopup(Em.I18n.t('common.error'), error);
  676. },
  677. /**
  678. * On click handler for rebalance Hdfs command from items menu
  679. */
  680. rebalanceHdfsNodes: function () {
  681. var controller = this;
  682. App.ModalPopup.show({
  683. classNames: ['fourty-percent-width-modal'],
  684. header: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.context'),
  685. primary: Em.I18n.t('common.start'),
  686. secondary: Em.I18n.t('common.cancel'),
  687. inputValue: 10,
  688. errorMessage: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.promptError'),
  689. isInvalid: function () {
  690. var intValue = Number(this.get('inputValue'));
  691. return this.get('inputValue')!=='DEBUG' && (isNaN(intValue) || intValue < 1 || intValue > 100);
  692. }.property('inputValue'),
  693. disablePrimary: Em.computed.alias('isInvalid'),
  694. onPrimary: function () {
  695. if (this.get('isInvalid')) {
  696. return;
  697. }
  698. App.ajax.send({
  699. name : 'service.item.rebalanceHdfsNodes',
  700. sender: controller,
  701. data : {
  702. hosts : App.Service.find('HDFS').get('hostComponents').findProperty('componentName', 'NAMENODE').get('hostName'),
  703. threshold: this.get('inputValue')
  704. },
  705. success : 'rebalanceHdfsNodesSuccessCallback',
  706. error : 'rebalanceHdfsNodesErrorCallback'
  707. });
  708. this.hide();
  709. },
  710. bodyClass: Ember.View.extend({
  711. templateName: require('templates/common/modal_popups/prompt_popup'),
  712. text: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.prompt'),
  713. didInsertElement: function () {
  714. App.tooltip(this.$(".prompt-input"), {
  715. placement: "bottom",
  716. title: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.promptTooltip')
  717. });
  718. }
  719. })
  720. });
  721. },
  722. rebalanceHdfsNodesSuccessCallback: function (data) {
  723. if (data.Requests.id) {
  724. App.router.get('backgroundOperationsController').showPopup();
  725. }
  726. },
  727. rebalanceHdfsNodesErrorCallback : function(data) {
  728. var error = Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.error');
  729. if(data && data.responseText){
  730. try {
  731. var json = $.parseJSON(data.responseText);
  732. error += json.message;
  733. } catch (err) {
  734. }
  735. }
  736. App.showAlertPopup(Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.error'), error);
  737. },
  738. /**
  739. * On click callback for <code>run compaction</code> button
  740. * @param event
  741. */
  742. runCompaction: function (event) {
  743. var self = this;
  744. return App.showConfirmationPopup(function() {
  745. self.set("content.runCompaction", true);
  746. // load data (if we need to show this background operations popup) from persist
  747. App.router.get('userSettingsController').dataLoading('show_bg').done(function (initValue) {
  748. if (initValue) {
  749. App.router.get('backgroundOperationsController').showPopup();
  750. }
  751. });
  752. });
  753. },
  754. /**
  755. * On click callback for <code>run smoke test</code> button
  756. * @param event
  757. */
  758. runSmokeTest: function (event) {
  759. var self = this;
  760. if (this.get('content.serviceName') === 'MAPREDUCE2' && !App.Service.find('YARN').get('isStarted')) {
  761. return App.showAlertPopup(Em.I18n.t('common.error'), Em.I18n.t('services.mapreduce2.smokeTest.requirement'));
  762. }
  763. return App.showConfirmationFeedBackPopup(function(query) {
  764. self.runSmokeTestPrimary(query);
  765. });
  766. },
  767. restartAllHostComponents : function(serviceName) {
  768. var serviceDisplayName = this.get('content.displayName');
  769. var bodyMessage = Em.Object.create({
  770. putInMaintenance: this.get('content.passiveState') === 'OFF',
  771. turnOnMmMsg: Em.I18n.t('passiveState.turnOnFor').format(serviceDisplayName),
  772. confirmMsg: Em.I18n.t('services.service.restartAll.confirmMsg').format(serviceDisplayName),
  773. confirmButton: Em.I18n.t('services.service.restartAll.confirmButton'),
  774. additionalWarningMsg: this.get('content.passiveState') === 'OFF' ? Em.I18n.t('services.service.restartAll.warningMsg.turnOnMM').format(serviceDisplayName): null
  775. });
  776. // check HDFS NameNode checkpoint before stop service
  777. if (this.get('content.serviceName') == 'HDFS' &&
  778. this.get('content.hostComponents').filterProperty('componentName', 'NAMENODE').someProperty('workStatus', App.HostComponentStatus.started)) {
  779. this.checkNnLastCheckpointTime(function () {
  780. return App.showConfirmationFeedBackPopup(function(query, runMmOperation) {
  781. batchUtils.restartAllServiceHostComponents(serviceDisplayName, serviceName, false, query, runMmOperation);
  782. }, bodyMessage);
  783. });
  784. } else {
  785. return App.showConfirmationFeedBackPopup(function(query, runMmOperation) {
  786. batchUtils.restartAllServiceHostComponents(serviceDisplayName, serviceName, false, query, runMmOperation);
  787. }, bodyMessage);
  788. }
  789. },
  790. turnOnOffPassive: function(label) {
  791. var self = this;
  792. var state = this.get('content.passiveState') == 'OFF' ? 'ON' : 'OFF';
  793. var onOff = state === 'ON' ? "On" : "Off";
  794. return App.showConfirmationPopup(function() {
  795. batchUtils.turnOnOffPassiveRequest(state, label, self.get('content.serviceName').toUpperCase(), function(data, opt, params) {
  796. self.set('content.passiveState', params.passive_state);
  797. batchUtils.infoPassiveState(params.passive_state);})
  798. },
  799. Em.I18n.t('hosts.passiveMode.popup').format(onOff,self.get('content.displayName'))
  800. );
  801. },
  802. rollingRestart: function(hostComponentName) {
  803. batchUtils.launchHostComponentRollingRestart(hostComponentName, this.get('content.displayName'), this.get('content.passiveState') === "ON", false, this.get('content.passiveState') === "ON");
  804. },
  805. runSmokeTestPrimary: function(query) {
  806. var clusterLevelRequired = ['KERBEROS'];
  807. var requestData = {
  808. 'serviceName': this.get('content.serviceName'),
  809. 'displayName': this.get('content.displayName'),
  810. 'actionName': this.get('content.serviceName') === 'ZOOKEEPER' ? 'ZOOKEEPER_QUORUM_SERVICE_CHECK' : this.get('content.serviceName') + '_SERVICE_CHECK',
  811. 'query': query
  812. };
  813. if (clusterLevelRequired.contains(this.get('content.serviceName'))) {
  814. requestData.operationLevel = {
  815. "level": "CLUSTER",
  816. "cluster_name": App.get('clusterName')
  817. };
  818. }
  819. App.ajax.send({
  820. 'name': 'service.item.smoke',
  821. 'sender': this,
  822. 'success':'runSmokeTestSuccessCallBack',
  823. 'error':'runSmokeTestErrorCallBack',
  824. 'data': requestData
  825. });
  826. },
  827. runSmokeTestSuccessCallBack: function (data, ajaxOptions, params) {
  828. if (data.Requests.id) {
  829. // load data (if we need to show this background operations popup) from persist
  830. App.router.get('userSettingsController').dataLoading('show_bg').done(function (initValue) {
  831. params.query.set('status', 'SUCCESS');
  832. if (initValue) {
  833. App.router.get('backgroundOperationsController').showPopup();
  834. }
  835. });
  836. }
  837. else {
  838. params.query.set('status', 'FAIL');
  839. }
  840. },
  841. runSmokeTestErrorCallBack: function (request, ajaxOptions, error, opt, params) {
  842. params.query.set('status', 'FAIL');
  843. },
  844. /**
  845. * On click callback for <code>Reassign <master component></code> button
  846. * @param hostComponent
  847. */
  848. reassignMaster: function (hostComponent) {
  849. var component = App.HostComponent.find().findProperty('componentName', hostComponent);
  850. if (component) {
  851. var reassignMasterController = App.router.get('reassignMasterController');
  852. reassignMasterController.saveComponentToReassign(component);
  853. reassignMasterController.setCurrentStep('1');
  854. App.router.transitionTo('reassign');
  855. }
  856. },
  857. /**
  858. * On click callback for <code>action</code> dropdown menu
  859. * Calls runSmokeTest, runRebalancer, runCompaction or reassignMaster depending on context
  860. * @param event
  861. */
  862. doAction: function (event) {
  863. if ($(event.target).hasClass('disabled') || $(event.target.parentElement).hasClass('disabled')) {
  864. return;
  865. }
  866. var methodName = event.context.action;
  867. var context = event.context.context;
  868. if (methodName) {
  869. this[methodName](context);
  870. }
  871. },
  872. /**
  873. * Restart clients host components to apply config changes
  874. */
  875. refreshConfigs: function () {
  876. var self = this;
  877. if (this.get('isClientsOnlyService') || this.get('content.serviceName') == "FLUME") {
  878. return App.showConfirmationFeedBackPopup(function (query) {
  879. batchUtils.getComponentsFromServer({
  880. services: [self.get('content.serviceName')]
  881. }, function (data) {
  882. var hostComponents = [];
  883. data.items.forEach(function (host) {
  884. host.host_components.forEach(function (hostComponent) {
  885. hostComponents.push(Em.Object.create({
  886. componentName: hostComponent.HostRoles.component_name,
  887. hostName: host.Hosts.host_name
  888. }))
  889. });
  890. });
  891. batchUtils.restartHostComponents(hostComponents, Em.I18n.t('rollingrestart.context.allForSelectedService').format(self.get('content.serviceName')), "SERVICE", query);
  892. })
  893. });
  894. }
  895. },
  896. /**
  897. * Send command to server to install client on selected host
  898. * @param componentName
  899. */
  900. addComponent: function (componentName) {
  901. var self = this;
  902. var component = App.StackServiceComponent.find().findProperty('componentName', componentName);
  903. var componentDisplayName = component.get('displayName');
  904. App.get('router.mainAdminKerberosController').getKDCSessionState(function () {
  905. return App.ModalPopup.show({
  906. primary: Em.computed.ifThenElse('anyHostsWithoutComponent', Em.I18n.t('hosts.host.addComponent.popup.confirm'), undefined),
  907. header: Em.I18n.t('popup.confirmation.commonHeader'),
  908. addComponentMsg: Em.I18n.t('hosts.host.addComponent.msg').format(componentDisplayName),
  909. selectHostMsg: Em.computed.i18nFormat('services.summary.selectHostForComponent', 'componentDisplayName'),
  910. thereIsNoHostsMsg: Em.computed.i18nFormat('services.summary.allHostsAlreadyRunComponent', 'componentDisplayName'),
  911. hostsWithoutComponent: function () {
  912. var hostsWithComponent = App.HostComponent.find().filterProperty('componentName', componentName).mapProperty('hostName');
  913. var result = App.get('allHostNames');
  914. hostsWithComponent.forEach(function (host) {
  915. result = result.without(host);
  916. });
  917. return result;
  918. }.property(),
  919. anyHostsWithoutComponent: Em.computed.gt('hostsWithoutComponent.length', 0),
  920. selectedHost: null,
  921. componentName: componentName,
  922. componentDisplayName: componentDisplayName,
  923. bodyClass: Em.View.extend({
  924. templateName: require('templates/main/service/add_host_popup')
  925. }),
  926. onPrimary: function () {
  927. var selectedHost = this.get('selectedHost');
  928. // Install
  929. if (['HIVE_METASTORE', 'RANGER_KMS_SERVER', 'NIMBUS'].contains(component.get('componentName')) && !!selectedHost) {
  930. App.router.get('mainHostDetailsController').addComponentWithCheck(
  931. {
  932. context: component,
  933. selectedHost: selectedHost
  934. }
  935. );
  936. } else {
  937. self.installHostComponentCall(selectedHost, component);
  938. }
  939. this.hide();
  940. }
  941. });
  942. });
  943. },
  944. /**
  945. * set property isPending (if this property is true - means that service has task in BGO)
  946. * and this makes start/stop button disabled
  947. */
  948. setStartStopState: function () {
  949. var serviceName = this.get('content.serviceName');
  950. var backgroundOperations = App.router.get('backgroundOperationsController.services');
  951. if (backgroundOperations && backgroundOperations.length > 0) {
  952. for (var i = 0; i < backgroundOperations.length; i++) {
  953. if (backgroundOperations[i].isRunning &&
  954. (backgroundOperations[i].dependentService === "ALL_SERVICES" ||
  955. backgroundOperations[i].dependentService === serviceName)) {
  956. this.set('isPending', true);
  957. return;
  958. }
  959. }
  960. this.set('isPending', false);
  961. } else {
  962. this.set('isPending', true);
  963. }
  964. }.observes('App.router.backgroundOperationsController.serviceTimestamp'),
  965. isStartDisabled: function () {
  966. if(this.get('isPending')) return true;
  967. return !(this.get('content.healthStatus') == 'red');
  968. }.property('content.healthStatus','isPending'),
  969. isStopDisabled: function () {
  970. if(this.get('isPending')) return true;
  971. if (App.get('isHaEnabled') && this.get('content.serviceName') == 'HDFS' && this.get('content.hostComponents').filterProperty('componentName', 'NAMENODE').someProperty('workStatus', App.HostComponentStatus.started)) {
  972. return false;
  973. }
  974. if (this.get('content.serviceName') == 'HAWQ' && this.get('content.hostComponents').filterProperty('componentName', 'HAWQMASTER').someProperty('workStatus', App.HostComponentStatus.started)) {
  975. return false;
  976. }
  977. if (this.get('content.serviceName') == 'PXF' && App.HostComponent.find().filterProperty('componentName', 'PXF').someProperty('workStatus', App.HostComponentStatus.started)) {
  978. return false;
  979. }
  980. return (this.get('content.healthStatus') != 'green');
  981. }.property('content.healthStatus','isPending', 'App.isHaEnabled'),
  982. isSmokeTestDisabled: function () {
  983. if (this.get('isClientsOnlyService')) return false;
  984. // Disable PXF service check if at least one PXF is down
  985. if (this.get('content.serviceName') === 'PXF')
  986. return App.HostComponent.find().filterProperty('componentName', 'PXF').someProperty('workStatus','INSTALLED');
  987. return this.get('isStopDisabled');
  988. }.property('content.serviceName'),
  989. /**
  990. * Determine if service has than one service client components
  991. */
  992. isSeveralClients: function () {
  993. return App.StackServiceComponent.find().filterProperty('serviceName', this.get('content.serviceName')).filterProperty('isClient').length > 1;
  994. }.property('content.serviceName'),
  995. enableHighAvailability: function() {
  996. var highAvailabilityController = App.router.get('mainAdminHighAvailabilityController');
  997. highAvailabilityController.enableHighAvailability();
  998. },
  999. disableHighAvailability: function() {
  1000. var highAvailabilityController = App.router.get('mainAdminHighAvailabilityController');
  1001. highAvailabilityController.disableHighAvailability();
  1002. },
  1003. enableRMHighAvailability: function() {
  1004. var highAvailabilityController = App.router.get('mainAdminHighAvailabilityController');
  1005. highAvailabilityController.enableRMHighAvailability();
  1006. },
  1007. addHawqStandby: function() {
  1008. var highAvailabilityController = App.router.get('mainAdminHighAvailabilityController');
  1009. highAvailabilityController.addHawqStandby();
  1010. },
  1011. removeHawqStandby: function() {
  1012. var highAvailabilityController = App.router.get('mainAdminHighAvailabilityController');
  1013. highAvailabilityController.removeHawqStandby();
  1014. },
  1015. activateHawqStandby: function() {
  1016. var highAvailabilityController = App.router.get('mainAdminHighAvailabilityController');
  1017. highAvailabilityController.activateHawqStandby();
  1018. },
  1019. enableRAHighAvailability: function() {
  1020. var highAvailabilityController = App.router.get('mainAdminHighAvailabilityController');
  1021. highAvailabilityController.enableRAHighAvailability();
  1022. },
  1023. downloadClientConfigs: function (event) {
  1024. var component = this.get('content.clientComponents').rejectProperty('totalCount', 0)[0];
  1025. this.downloadClientConfigsCall({
  1026. serviceName: this.get('content.serviceName'),
  1027. componentName: (event && event.name) || component.get('componentName'),
  1028. displayName: (event && event.label) || component.get('displayName')
  1029. });
  1030. },
  1031. /**
  1032. * On click handler for custom hawq command from items menu
  1033. * @param context
  1034. */
  1035. executeHawqCustomCommand: function(context) {
  1036. var controller = this;
  1037. return App.showConfirmationPopup(function() {
  1038. App.ajax.send({
  1039. name : 'service.item.executeCustomCommand',
  1040. sender: controller,
  1041. data : {
  1042. command : context.command,
  1043. context : context.label,
  1044. hosts : App.Service.find(context.service).get('hostComponents').findProperty('componentName', context.component).get('hostName'),
  1045. serviceName : context.service,
  1046. componentName : context.component
  1047. },
  1048. success : 'executeCustomCommandSuccessCallback',
  1049. error : 'executeCustomCommandErrorCallback'
  1050. });
  1051. });
  1052. },
  1053. /**
  1054. * On click handler for custom command from items menu
  1055. * @param context
  1056. */
  1057. executeCustomCommand: function(context) {
  1058. var controller = this;
  1059. return App.showConfirmationPopup(function() {
  1060. App.ajax.send({
  1061. name : 'service.item.executeCustomCommand',
  1062. sender: controller,
  1063. data : {
  1064. command : context.command,
  1065. context : 'Execute ' + context.command,
  1066. hosts : App.Service.find(context.service).get('hostComponents').findProperty('componentName', context.component).get('hostName'),
  1067. serviceName : context.service,
  1068. componentName : context.component,
  1069. forceRefreshConfigTags : "capacity-scheduler"
  1070. },
  1071. success : 'executeCustomCommandSuccessCallback',
  1072. error : 'executeCustomCommandErrorCallback'
  1073. });
  1074. });
  1075. },
  1076. executeCustomCommandSuccessCallback : function(data, ajaxOptions, params) {
  1077. if (data.Requests.id) {
  1078. App.router.get('backgroundOperationsController').showPopup();
  1079. }
  1080. },
  1081. executeCustomCommandErrorCallback : function(data) {
  1082. var error = Em.I18n.t('services.service.actions.run.executeCustomCommand.error');
  1083. if(data && data.responseText){
  1084. try {
  1085. var json = $.parseJSON(data.responseText);
  1086. error += json.message;
  1087. } catch (err) {}
  1088. }
  1089. App.showAlertPopup(Em.I18n.t('services.service.actions.run.executeCustomCommand.error'), error);
  1090. },
  1091. /**
  1092. * find dependent services
  1093. * @param {string[]} serviceNamesToDelete
  1094. * @returns {Array}
  1095. */
  1096. findDependentServices: function (serviceNamesToDelete) {
  1097. var dependentServices = [];
  1098. App.Service.find().forEach(function (service) {
  1099. if (!serviceNamesToDelete.contains(service.get('serviceName'))) {
  1100. var requiredServices = App.StackService.find(service.get('serviceName')).get('requiredServices');
  1101. serviceNamesToDelete.forEach(function (dependsOnService) {
  1102. if (requiredServices.contains(dependsOnService)) {
  1103. dependentServices.push(service.get('serviceName'));
  1104. }
  1105. });
  1106. }
  1107. }, this);
  1108. return dependentServices;
  1109. },
  1110. /**
  1111. * @param serviceNames
  1112. * @returns {string}
  1113. */
  1114. servicesDisplayNames: function(serviceNames) {
  1115. return serviceNames.map(function(serviceName) {
  1116. return App.format.role(serviceName, true);
  1117. }).join(',');
  1118. },
  1119. /**
  1120. * Is services can be removed based on work status
  1121. * @param serviceNames
  1122. */
  1123. allowUninstallServices: function(serviceNames) {
  1124. return App.Service.find().filter(function (service) {
  1125. return serviceNames.contains(service.get('serviceName'));
  1126. }).everyProperty('allowToDelete');
  1127. },
  1128. /**
  1129. * delete service action
  1130. * @param {string} serviceName
  1131. */
  1132. deleteService: function(serviceName) {
  1133. var self = this,
  1134. interDependentServices = this.get('interDependentServices'),
  1135. serviceNamesToDelete = this.get('serviceNamesToDelete'),
  1136. dependentServices = this.findDependentServices(serviceNamesToDelete),
  1137. displayName = App.format.role(serviceName, true),
  1138. popupHeader = Em.I18n.t('services.service.delete.popup.header'),
  1139. dependentServicesToDeleteFmt = this.servicesDisplayNames(interDependentServices);
  1140. if (serviceName === 'KERBEROS') {
  1141. this.kerberosDeleteWarning(popupHeader);
  1142. return;
  1143. }
  1144. if (App.Service.find().get('length') === 1) {
  1145. //at least one service should be installed
  1146. App.ModalPopup.show({
  1147. secondary: null,
  1148. header: popupHeader,
  1149. encodeBody: false,
  1150. body: Em.I18n.t('services.service.delete.lastService.popup.body').format(displayName)
  1151. });
  1152. } else if (dependentServices.length > 0) {
  1153. this.dependentServicesWarning(serviceName, dependentServices);
  1154. } else if (this.allowUninstallServices(serviceNamesToDelete)) {
  1155. App.showConfirmationPopup(
  1156. function() {self.confirmDeleteService(serviceName, interDependentServices, dependentServicesToDeleteFmt)},
  1157. Em.I18n.t('services.service.delete.popup.warning').format(displayName) +
  1158. (interDependentServices.length ? Em.I18n.t('services.service.delete.popup.warning.dependent').format(dependentServicesToDeleteFmt) : ''),
  1159. null,
  1160. popupHeader,
  1161. Em.I18n.t('common.delete'),
  1162. true
  1163. );
  1164. } else {
  1165. var body = Em.I18n.t('services.service.delete.popup.mustBeStopped').format(displayName);
  1166. if (interDependentServices.length) {
  1167. body += Em.I18n.t('services.service.delete.popup.mustBeStopped.dependent').format(dependentServicesToDeleteFmt)
  1168. }
  1169. App.ModalPopup.show({
  1170. secondary: null,
  1171. header: popupHeader,
  1172. encodeBody: false,
  1173. body: body
  1174. });
  1175. }
  1176. },
  1177. /**
  1178. * show dialog with Kerberos warning prior to service delete
  1179. * @param {string} header
  1180. * @returns {App.ModalPopup}
  1181. */
  1182. kerberosDeleteWarning: function(header) {
  1183. return App.ModalPopup.show({
  1184. primary: Em.I18n.t('ok'),
  1185. secondary: Em.I18n.t('services.alerts.goTo').format('Kerberos'),
  1186. header: header,
  1187. encodeBody: false,
  1188. body: Em.I18n.t('services.service.delete.popup.kerberos'),
  1189. onSecondary: function() {
  1190. this._super();
  1191. App.router.transitionTo('main.admin.adminKerberos.index');
  1192. }
  1193. });
  1194. },
  1195. /**
  1196. * warning that show dependent services which must be deleted prior to chosen service deletion
  1197. * @param {string} origin
  1198. * @param {string[]} dependent
  1199. * @returns {App.ModalPopup}
  1200. */
  1201. dependentServicesWarning: function(origin, dependent) {
  1202. return App.ModalPopup.show({
  1203. secondary: null,
  1204. header: Em.I18n.t('services.service.delete.popup.header'),
  1205. dependentMessage: Em.I18n.t('services.service.delete.popup.dependentServices').format(App.format.role(origin, true)),
  1206. dependentServices: dependent,
  1207. bodyClass: Em.View.extend({
  1208. templateName: require('templates/main/service/info/dependent_services_warning')
  1209. })
  1210. });
  1211. },
  1212. /**
  1213. * Confirmation popup of service deletion
  1214. * @param {string} serviceName
  1215. * @param {string[]} [dependentServiceNames]
  1216. * @param {string} [servicesToDeleteFmt]
  1217. */
  1218. confirmDeleteService: function (serviceName, dependentServiceNames, servicesToDeleteFmt) {
  1219. var confirmKey = 'delete',
  1220. self = this,
  1221. message = Em.I18n.t('services.service.confirmDelete.popup.body').format(App.format.role(serviceName, true), confirmKey);
  1222. if (dependentServiceNames.length > 0) {
  1223. message = Em.I18n.t('services.service.confirmDelete.popup.body.dependent')
  1224. .format(App.format.role(serviceName, true), servicesToDeleteFmt, confirmKey);
  1225. }
  1226. App.ModalPopup.show({
  1227. /**
  1228. * @function onPrimary
  1229. */
  1230. onPrimary: function() {
  1231. var serviceNames = [serviceName].concat(dependentServiceNames),
  1232. serviceDisplayNames = serviceNames.map(function (serviceName) {
  1233. return App.Service.find(serviceName).get('displayName');
  1234. }),
  1235. progressPopup = App.ModalPopup.show({
  1236. classNames: ['delete-service-progress'],
  1237. header: Em.I18n.t('services.service.delete.popup.header'),
  1238. showFooter: false,
  1239. message: Em.I18n.t('services.service.delete.progressPopup.message').format(stringUtils.getFormattedStringFromArray(serviceDisplayNames)),
  1240. bodyClass: Em.View.extend({
  1241. classNames: ['delete-service-progress-body'],
  1242. template: Em.Handlebars.compile('{{view App.SpinnerView}}<div class="progress-message">{{message}}</div>')
  1243. }),
  1244. onClose: function () {
  1245. self.set('deleteServiceProgressPopup', null);
  1246. this._super();
  1247. }
  1248. });
  1249. self.set('deleteServiceProgressPopup', progressPopup);
  1250. self.deleteServiceCall(serviceNames);
  1251. this._super();
  1252. },
  1253. /**
  1254. * @type {string}
  1255. */
  1256. primary: Em.I18n.t('common.delete'),
  1257. /**
  1258. * @type {string}
  1259. */
  1260. primaryClass: 'btn-danger',
  1261. /**
  1262. * @type {string}
  1263. */
  1264. header: Em.I18n.t('services.service.confirmDelete.popup.header'),
  1265. /**
  1266. * @type {string}
  1267. */
  1268. confirmInput: '',
  1269. /**
  1270. * @type {boolean}
  1271. */
  1272. disablePrimary: Em.computed.notEqual('confirmInput', confirmKey),
  1273. message: message,
  1274. /**
  1275. * @type {Em.View}
  1276. */
  1277. bodyClass: Em.View.extend({
  1278. confirmKey: confirmKey,
  1279. typeMessage: Em.I18n.t('services.service.confirmDelete.popup.body.type').format(confirmKey),
  1280. templateName: require('templates/main/service/info/confirm_delete_service')
  1281. }),
  1282. enterKeyPressed: function() {
  1283. if (this.get('disablePrimary')) return;
  1284. this.onPrimary();
  1285. }
  1286. });
  1287. },
  1288. /**
  1289. * All host names
  1290. * This property required for request for recommendations
  1291. *
  1292. * @type {String[]}
  1293. * @override
  1294. */
  1295. hostNames: Em.computed.alias('App.allHostNames'),
  1296. /**
  1297. * Recommendation object
  1298. * This property required for request for recommendations
  1299. *
  1300. * @type {Object}
  1301. * @override
  1302. */
  1303. hostGroups: function() {
  1304. var hostGroup = blueprintUtils.generateHostGroups(App.get('allHostNames'));
  1305. return blueprintUtils.removeDeletedComponents(hostGroup, [this.get('serviceNamesToDelete')]);
  1306. }.property('serviceNamesToDelete', 'App.allHostNames', 'App.componentToBeAdded', 'App.componentToBeDeleted'),
  1307. /**
  1308. * List of services without removed
  1309. * This property required for request for recommendations
  1310. *
  1311. * @type {String[]}
  1312. * @override
  1313. */
  1314. serviceNames: function() {
  1315. return App.Service.find().filter(function(s) {
  1316. return !this.get('serviceNamesToDelete').contains(s.get('serviceName'));
  1317. }, this).mapProperty('serviceName');
  1318. }.property('serviceNamesToDelete'),
  1319. /**
  1320. * This property required for request for recommendations
  1321. *
  1322. * @return {Boolean}
  1323. * @override
  1324. */
  1325. isConfigHasInitialState: function() { return false; },
  1326. /**
  1327. * Describes condition when recommendation should be applied
  1328. * For removing services it's always true
  1329. * This property required for request for recommendations
  1330. *
  1331. * @return {Boolean}
  1332. * @override
  1333. */
  1334. allowUpdateProperty: function() { return true; },
  1335. /**
  1336. * Just config version note
  1337. *
  1338. * @type {String}
  1339. */
  1340. serviceConfigVersionNote: function() {
  1341. var services = this.get('serviceNamesToDelete').join(',');
  1342. if (this.get('serviceNamesToDelete.length') === 1) {
  1343. return Em.I18n.t('services.service.delete.configVersionNote').format(services);
  1344. }
  1345. return Em.I18n.t('services.service.delete.configVersionNote.plural').format(services);
  1346. }.property('serviceNamesToDelete'),
  1347. /**
  1348. * Method ot save configs after service have been removed
  1349. * @override
  1350. */
  1351. saveConfigs: function() {
  1352. var data = [],
  1353. progressPopup = this.get('deleteServiceProgressPopup');
  1354. this.get('stepConfigs').forEach(function(stepConfig) {
  1355. var serviceConfig = this.getServiceConfigToSave(stepConfig.get('serviceName'), stepConfig.get('configs'));
  1356. if (serviceConfig) {
  1357. data.push(serviceConfig);
  1358. }
  1359. }, this);
  1360. if (Em.isArray(data) && data.length) {
  1361. this.putChangedConfigurations(data, 'confirmServiceDeletion', function () {
  1362. if (progressPopup) {
  1363. progressPopup.onClose();
  1364. }
  1365. });
  1366. } else {
  1367. this.confirmServiceDeletion();
  1368. }
  1369. },
  1370. confirmServiceDeletion: function() {
  1371. var progressPopup = this.get('deleteServiceProgressPopup'),
  1372. msg = this.get('interDependentServices.length')
  1373. ? Em.I18n.t('services.service.delete.service.success.confirmation.plural').format(this.get('serviceNamesToDelete').join(','))
  1374. : Em.I18n.t('services.service.delete.service.success.confirmation').format(this.get('content.serviceName'));
  1375. if (progressPopup) {
  1376. progressPopup.onClose();
  1377. }
  1378. return App.showAlertPopup(Em.I18n.t('popup.confirmation.commonHeader'), msg, function() {
  1379. window.location.reload();
  1380. })
  1381. },
  1382. /**
  1383. * Ajax call to delete service
  1384. * @param {string[]} serviceNames
  1385. * @returns {$.ajax}
  1386. */
  1387. deleteServiceCall: function(serviceNames) {
  1388. var serviceToDeleteNow = serviceNames[0];
  1389. if (serviceNames.length > 1) {
  1390. var servicesToDeleteNext = serviceNames.slice(1);
  1391. }
  1392. App.Service.find().findProperty('serviceName', serviceToDeleteNow).set('deleteInProgress', true);
  1393. return App.ajax.send({
  1394. name : 'common.delete.service',
  1395. sender: this,
  1396. data : {
  1397. serviceName : serviceToDeleteNow,
  1398. servicesToDeleteNext: servicesToDeleteNext
  1399. },
  1400. success : 'deleteServiceCallSuccessCallback',
  1401. error: 'deleteServiceCallErrorCallback'
  1402. });
  1403. },
  1404. deleteServiceCallSuccessCallback: function(data, ajaxOptions, params) {
  1405. if (params.servicesToDeleteNext) {
  1406. this.deleteServiceCall(params.servicesToDeleteNext);
  1407. } else {
  1408. this.loadConfigRecommendations(null, this.saveConfigs.bind(this));
  1409. }
  1410. },
  1411. deleteServiceCallErrorCallback: function (jqXHR, ajaxOptions, error, opt) {
  1412. var progressPopup = this.get('deleteServiceProgressPopup');
  1413. if (progressPopup) {
  1414. progressPopup.onClose();
  1415. }
  1416. App.ajax.defaultErrorHandler(jqXHR, opt.url, opt.type, jqXHR.status);
  1417. }
  1418. });