item.js 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579
  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. /**
  641. * On click handler for rebalance Hdfs command from items menu
  642. */
  643. rebalanceHdfsNodes: function () {
  644. var controller = this;
  645. App.ModalPopup.show({
  646. classNames: ['fourty-percent-width-modal'],
  647. header: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.context'),
  648. primary: Em.I18n.t('common.start'),
  649. secondary: Em.I18n.t('common.cancel'),
  650. inputValue: 10,
  651. errorMessage: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.promptError'),
  652. isInvalid: function () {
  653. var intValue = Number(this.get('inputValue'));
  654. return this.get('inputValue')!=='DEBUG' && (isNaN(intValue) || intValue < 1 || intValue > 100);
  655. }.property('inputValue'),
  656. disablePrimary: Em.computed.alias('isInvalid'),
  657. onPrimary: function () {
  658. if (this.get('isInvalid')) {
  659. return;
  660. }
  661. App.ajax.send({
  662. name : 'service.item.rebalanceHdfsNodes',
  663. sender: controller,
  664. data : {
  665. hosts : App.Service.find('HDFS').get('hostComponents').findProperty('componentName', 'NAMENODE').get('hostName'),
  666. threshold: this.get('inputValue')
  667. },
  668. success : 'rebalanceHdfsNodesSuccessCallback',
  669. error : 'rebalanceHdfsNodesErrorCallback'
  670. });
  671. this.hide();
  672. },
  673. bodyClass: Ember.View.extend({
  674. templateName: require('templates/common/modal_popups/prompt_popup'),
  675. text: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.prompt'),
  676. didInsertElement: function () {
  677. App.tooltip(this.$(".prompt-input"), {
  678. placement: "bottom",
  679. title: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.promptTooltip')
  680. });
  681. }
  682. })
  683. });
  684. },
  685. rebalanceHdfsNodesSuccessCallback: function (data) {
  686. if (data.Requests.id) {
  687. App.router.get('backgroundOperationsController').showPopup();
  688. }
  689. },
  690. rebalanceHdfsNodesErrorCallback : function(data) {
  691. var error = Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.error');
  692. if(data && data.responseText){
  693. try {
  694. var json = $.parseJSON(data.responseText);
  695. error += json.message;
  696. } catch (err) {
  697. }
  698. }
  699. App.showAlertPopup(Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.error'), error);
  700. },
  701. /**
  702. * On click callback for <code>run compaction</code> button
  703. * @param event
  704. */
  705. runCompaction: function (event) {
  706. var self = this;
  707. return App.showConfirmationPopup(function() {
  708. self.set("content.runCompaction", true);
  709. // load data (if we need to show this background operations popup) from persist
  710. App.router.get('userSettingsController').dataLoading('show_bg').done(function (initValue) {
  711. if (initValue) {
  712. App.router.get('backgroundOperationsController').showPopup();
  713. }
  714. });
  715. });
  716. },
  717. /**
  718. * On click callback for <code>run smoke test</code> button
  719. * @param event
  720. */
  721. runSmokeTest: function (event) {
  722. var self = this;
  723. if (this.get('content.serviceName') === 'MAPREDUCE2' && !App.Service.find('YARN').get('isStarted')) {
  724. return App.showAlertPopup(Em.I18n.t('common.error'), Em.I18n.t('services.mapreduce2.smokeTest.requirement'));
  725. }
  726. return App.showConfirmationFeedBackPopup(function(query) {
  727. self.runSmokeTestPrimary(query);
  728. });
  729. },
  730. restartAllHostComponents : function(serviceName) {
  731. var serviceDisplayName = this.get('content.displayName');
  732. var bodyMessage = Em.Object.create({
  733. putInMaintenance: this.get('content.passiveState') === 'OFF',
  734. turnOnMmMsg: Em.I18n.t('passiveState.turnOnFor').format(serviceDisplayName),
  735. confirmMsg: Em.I18n.t('services.service.restartAll.confirmMsg').format(serviceDisplayName),
  736. confirmButton: Em.I18n.t('services.service.restartAll.confirmButton'),
  737. additionalWarningMsg: this.get('content.passiveState') === 'OFF' ? Em.I18n.t('services.service.restartAll.warningMsg.turnOnMM').format(serviceDisplayName): null
  738. });
  739. // check HDFS NameNode checkpoint before stop service
  740. if (this.get('content.serviceName') == 'HDFS' &&
  741. this.get('content.hostComponents').filterProperty('componentName', 'NAMENODE').someProperty('workStatus', App.HostComponentStatus.started)) {
  742. this.checkNnLastCheckpointTime(function () {
  743. return App.showConfirmationFeedBackPopup(function(query, runMmOperation) {
  744. batchUtils.restartAllServiceHostComponents(serviceDisplayName, serviceName, false, query, runMmOperation);
  745. }, bodyMessage);
  746. });
  747. } else {
  748. return App.showConfirmationFeedBackPopup(function(query, runMmOperation) {
  749. batchUtils.restartAllServiceHostComponents(serviceDisplayName, serviceName, false, query, runMmOperation);
  750. }, bodyMessage);
  751. }
  752. },
  753. turnOnOffPassive: function(label) {
  754. var self = this;
  755. var state = this.get('content.passiveState') == 'OFF' ? 'ON' : 'OFF';
  756. var onOff = state === 'ON' ? "On" : "Off";
  757. return App.showConfirmationPopup(function() {
  758. batchUtils.turnOnOffPassiveRequest(state, label, self.get('content.serviceName').toUpperCase(), function(data, opt, params) {
  759. self.set('content.passiveState', params.passive_state);
  760. batchUtils.infoPassiveState(params.passive_state);})
  761. },
  762. Em.I18n.t('hosts.passiveMode.popup').format(onOff,self.get('content.displayName'))
  763. );
  764. },
  765. rollingRestart: function(hostComponentName) {
  766. batchUtils.launchHostComponentRollingRestart(hostComponentName, this.get('content.displayName'), this.get('content.passiveState') === "ON", false, this.get('content.passiveState') === "ON");
  767. },
  768. runSmokeTestPrimary: function(query) {
  769. var clusterLevelRequired = ['KERBEROS'];
  770. var requestData = {
  771. 'serviceName': this.get('content.serviceName'),
  772. 'displayName': this.get('content.displayName'),
  773. 'actionName': this.get('content.serviceName') === 'ZOOKEEPER' ? 'ZOOKEEPER_QUORUM_SERVICE_CHECK' : this.get('content.serviceName') + '_SERVICE_CHECK',
  774. 'query': query
  775. };
  776. if (clusterLevelRequired.contains(this.get('content.serviceName'))) {
  777. requestData.operationLevel = {
  778. "level": "CLUSTER",
  779. "cluster_name": App.get('clusterName')
  780. };
  781. }
  782. App.ajax.send({
  783. 'name': 'service.item.smoke',
  784. 'sender': this,
  785. 'success':'runSmokeTestSuccessCallBack',
  786. 'error':'runSmokeTestErrorCallBack',
  787. 'data': requestData
  788. });
  789. },
  790. runSmokeTestSuccessCallBack: function (data, ajaxOptions, params) {
  791. if (data.Requests.id) {
  792. // load data (if we need to show this background operations popup) from persist
  793. App.router.get('userSettingsController').dataLoading('show_bg').done(function (initValue) {
  794. params.query.set('status', 'SUCCESS');
  795. if (initValue) {
  796. App.router.get('backgroundOperationsController').showPopup();
  797. }
  798. });
  799. }
  800. else {
  801. params.query.set('status', 'FAIL');
  802. }
  803. },
  804. runSmokeTestErrorCallBack: function (request, ajaxOptions, error, opt, params) {
  805. params.query.set('status', 'FAIL');
  806. },
  807. /**
  808. * On click callback for <code>Reassign <master component></code> button
  809. * @param hostComponent
  810. */
  811. reassignMaster: function (hostComponent) {
  812. var component = App.HostComponent.find().findProperty('componentName', hostComponent);
  813. if (component) {
  814. var reassignMasterController = App.router.get('reassignMasterController');
  815. reassignMasterController.saveComponentToReassign(component);
  816. reassignMasterController.setCurrentStep('1');
  817. App.router.transitionTo('reassign');
  818. }
  819. },
  820. /**
  821. * On click callback for <code>action</code> dropdown menu
  822. * Calls runSmokeTest, runRebalancer, runCompaction or reassignMaster depending on context
  823. * @param event
  824. */
  825. doAction: function (event) {
  826. if ($(event.target).hasClass('disabled') || $(event.target.parentElement).hasClass('disabled')) {
  827. return;
  828. }
  829. var methodName = event.context.action;
  830. var context = event.context.context;
  831. if (methodName) {
  832. this[methodName](context);
  833. }
  834. },
  835. /**
  836. * Restart clients host components to apply config changes
  837. */
  838. refreshConfigs: function () {
  839. var self = this;
  840. if (this.get('isClientsOnlyService') || this.get('content.serviceName') == "FLUME") {
  841. return App.showConfirmationFeedBackPopup(function (query) {
  842. batchUtils.getComponentsFromServer({
  843. services: [self.get('content.serviceName')]
  844. }, function (data) {
  845. var hostComponents = [];
  846. data.items.forEach(function (host) {
  847. host.host_components.forEach(function (hostComponent) {
  848. hostComponents.push(Em.Object.create({
  849. componentName: hostComponent.HostRoles.component_name,
  850. hostName: host.Hosts.host_name
  851. }))
  852. });
  853. });
  854. batchUtils.restartHostComponents(hostComponents, Em.I18n.t('rollingrestart.context.allForSelectedService').format(self.get('content.serviceName')), "SERVICE", query);
  855. })
  856. });
  857. }
  858. },
  859. /**
  860. * Send command to server to install client on selected host
  861. * @param componentName
  862. */
  863. addComponent: function (componentName) {
  864. var self = this;
  865. var component = App.StackServiceComponent.find().findProperty('componentName', componentName);
  866. var componentDisplayName = component.get('displayName');
  867. App.get('router.mainAdminKerberosController').getKDCSessionState(function () {
  868. return App.ModalPopup.show({
  869. primary: Em.computed.ifThenElse('anyHostsWithoutComponent', Em.I18n.t('hosts.host.addComponent.popup.confirm'), undefined),
  870. header: Em.I18n.t('popup.confirmation.commonHeader'),
  871. addComponentMsg: Em.I18n.t('hosts.host.addComponent.msg').format(componentDisplayName),
  872. selectHostMsg: Em.computed.i18nFormat('services.summary.selectHostForComponent', 'componentDisplayName'),
  873. thereIsNoHostsMsg: Em.computed.i18nFormat('services.summary.allHostsAlreadyRunComponent', 'componentDisplayName'),
  874. hostsWithoutComponent: function () {
  875. var hostsWithComponent = App.HostComponent.find().filterProperty('componentName', componentName).mapProperty('hostName');
  876. var result = App.get('allHostNames');
  877. hostsWithComponent.forEach(function (host) {
  878. result = result.without(host);
  879. });
  880. return result;
  881. }.property(),
  882. anyHostsWithoutComponent: Em.computed.gt('hostsWithoutComponent.length', 0),
  883. selectedHost: null,
  884. componentName: componentName,
  885. componentDisplayName: componentDisplayName,
  886. bodyClass: Em.View.extend({
  887. templateName: require('templates/main/service/add_host_popup')
  888. }),
  889. onPrimary: function () {
  890. var selectedHost = this.get('selectedHost');
  891. // Install
  892. if (['HIVE_METASTORE', 'RANGER_KMS_SERVER', 'NIMBUS'].contains(component.get('componentName')) && !!selectedHost) {
  893. App.router.get('mainHostDetailsController').addComponentWithCheck(
  894. {
  895. context: component,
  896. selectedHost: selectedHost
  897. }
  898. );
  899. } else {
  900. self.installHostComponentCall(selectedHost, component);
  901. }
  902. this.hide();
  903. }
  904. });
  905. });
  906. },
  907. /**
  908. * set property isPending (if this property is true - means that service has task in BGO)
  909. * and this makes start/stop button disabled
  910. */
  911. setStartStopState: function () {
  912. var serviceName = this.get('content.serviceName');
  913. var backgroundOperations = App.router.get('backgroundOperationsController.services');
  914. if (backgroundOperations && backgroundOperations.length > 0) {
  915. for (var i = 0; i < backgroundOperations.length; i++) {
  916. if (backgroundOperations[i].isRunning &&
  917. (backgroundOperations[i].dependentService === "ALL_SERVICES" ||
  918. backgroundOperations[i].dependentService === serviceName)) {
  919. this.set('isPending', true);
  920. return;
  921. }
  922. }
  923. this.set('isPending', false);
  924. } else {
  925. this.set('isPending', true);
  926. }
  927. }.observes('App.router.backgroundOperationsController.serviceTimestamp'),
  928. isStartDisabled: function () {
  929. if(this.get('isPending')) return true;
  930. return !(this.get('content.healthStatus') == 'red');
  931. }.property('content.healthStatus','isPending'),
  932. isStopDisabled: function () {
  933. if(this.get('isPending')) return true;
  934. if (App.get('isHaEnabled') && this.get('content.serviceName') == 'HDFS' && this.get('content.hostComponents').filterProperty('componentName', 'NAMENODE').someProperty('workStatus', App.HostComponentStatus.started)) {
  935. return false;
  936. }
  937. if (this.get('content.serviceName') == 'HAWQ' && this.get('content.hostComponents').filterProperty('componentName', 'HAWQMASTER').someProperty('workStatus', App.HostComponentStatus.started)) {
  938. return false;
  939. }
  940. if (this.get('content.serviceName') == 'PXF' && App.HostComponent.find().filterProperty('componentName', 'PXF').someProperty('workStatus', App.HostComponentStatus.started)) {
  941. return false;
  942. }
  943. return (this.get('content.healthStatus') != 'green');
  944. }.property('content.healthStatus','isPending', 'App.isHaEnabled'),
  945. isSmokeTestDisabled: function () {
  946. if (this.get('isClientsOnlyService')) return false;
  947. // Disable PXF service check if at least one PXF is down
  948. if (this.get('content.serviceName') === 'PXF')
  949. return App.HostComponent.find().filterProperty('componentName', 'PXF').someProperty('workStatus','INSTALLED');
  950. return this.get('isStopDisabled');
  951. }.property('content.serviceName'),
  952. /**
  953. * Determine if service has than one service client components
  954. */
  955. isSeveralClients: function () {
  956. return App.StackServiceComponent.find().filterProperty('serviceName', this.get('content.serviceName')).filterProperty('isClient').length > 1;
  957. }.property('content.serviceName'),
  958. enableHighAvailability: function() {
  959. var highAvailabilityController = App.router.get('mainAdminHighAvailabilityController');
  960. highAvailabilityController.enableHighAvailability();
  961. },
  962. disableHighAvailability: function() {
  963. var highAvailabilityController = App.router.get('mainAdminHighAvailabilityController');
  964. highAvailabilityController.disableHighAvailability();
  965. },
  966. enableRMHighAvailability: function() {
  967. var highAvailabilityController = App.router.get('mainAdminHighAvailabilityController');
  968. highAvailabilityController.enableRMHighAvailability();
  969. },
  970. addHawqStandby: function() {
  971. var highAvailabilityController = App.router.get('mainAdminHighAvailabilityController');
  972. highAvailabilityController.addHawqStandby();
  973. },
  974. removeHawqStandby: function() {
  975. var highAvailabilityController = App.router.get('mainAdminHighAvailabilityController');
  976. highAvailabilityController.removeHawqStandby();
  977. },
  978. activateHawqStandby: function() {
  979. var highAvailabilityController = App.router.get('mainAdminHighAvailabilityController');
  980. highAvailabilityController.activateHawqStandby();
  981. },
  982. enableRAHighAvailability: function() {
  983. var highAvailabilityController = App.router.get('mainAdminHighAvailabilityController');
  984. highAvailabilityController.enableRAHighAvailability();
  985. },
  986. downloadClientConfigs: function (event) {
  987. var component = this.get('content.clientComponents').rejectProperty('totalCount', 0)[0];
  988. this.downloadClientConfigsCall({
  989. serviceName: this.get('content.serviceName'),
  990. componentName: (event && event.name) || component.get('componentName'),
  991. displayName: (event && event.label) || component.get('displayName')
  992. });
  993. },
  994. /**
  995. * On click handler for custom hawq command from items menu
  996. * @param context
  997. */
  998. executeHawqCustomCommand: function(context) {
  999. var controller = this;
  1000. return App.showConfirmationPopup(function() {
  1001. App.ajax.send({
  1002. name : 'service.item.executeCustomCommand',
  1003. sender: controller,
  1004. data : {
  1005. command : context.command,
  1006. context : context.label,
  1007. hosts : App.Service.find(context.service).get('hostComponents').findProperty('componentName', context.component).get('hostName'),
  1008. serviceName : context.service,
  1009. componentName : context.component
  1010. },
  1011. success : 'executeCustomCommandSuccessCallback',
  1012. error : 'executeCustomCommandErrorCallback'
  1013. });
  1014. });
  1015. },
  1016. /**
  1017. * On click handler for custom command from items menu
  1018. * @param context
  1019. */
  1020. executeCustomCommand: function(context) {
  1021. var controller = this;
  1022. return App.showConfirmationPopup(function() {
  1023. App.ajax.send({
  1024. name : 'service.item.executeCustomCommand',
  1025. sender: controller,
  1026. data : {
  1027. command : context.command,
  1028. context : 'Execute ' + context.command,
  1029. hosts : App.Service.find(context.service).get('hostComponents').findProperty('componentName', context.component).get('hostName'),
  1030. serviceName : context.service,
  1031. componentName : context.component,
  1032. forceRefreshConfigTags : "capacity-scheduler"
  1033. },
  1034. success : 'executeCustomCommandSuccessCallback',
  1035. error : 'executeCustomCommandErrorCallback'
  1036. });
  1037. });
  1038. },
  1039. executeCustomCommandSuccessCallback : function(data, ajaxOptions, params) {
  1040. if (data.Requests.id) {
  1041. App.router.get('backgroundOperationsController').showPopup();
  1042. }
  1043. },
  1044. executeCustomCommandErrorCallback : function(data) {
  1045. var error = Em.I18n.t('services.service.actions.run.executeCustomCommand.error');
  1046. if(data && data.responseText){
  1047. try {
  1048. var json = $.parseJSON(data.responseText);
  1049. error += json.message;
  1050. } catch (err) {}
  1051. }
  1052. App.showAlertPopup(Em.I18n.t('services.service.actions.run.executeCustomCommand.error'), error);
  1053. },
  1054. /**
  1055. * find dependent services
  1056. * @param {string[]} serviceNamesToDelete
  1057. * @returns {Array}
  1058. */
  1059. findDependentServices: function (serviceNamesToDelete) {
  1060. var dependentServices = [];
  1061. App.Service.find().forEach(function (service) {
  1062. if (!serviceNamesToDelete.contains(service.get('serviceName'))) {
  1063. var requiredServices = App.StackService.find(service.get('serviceName')).get('requiredServices');
  1064. serviceNamesToDelete.forEach(function (dependsOnService) {
  1065. if (requiredServices.contains(dependsOnService)) {
  1066. dependentServices.push(service.get('serviceName'));
  1067. }
  1068. });
  1069. }
  1070. }, this);
  1071. return dependentServices;
  1072. },
  1073. /**
  1074. * @param serviceNames
  1075. * @returns {string}
  1076. */
  1077. servicesDisplayNames: function(serviceNames) {
  1078. return serviceNames.map(function(serviceName) {
  1079. return App.format.role(serviceName, true);
  1080. }).join(',');
  1081. },
  1082. /**
  1083. * Is services can be removed based on work status
  1084. * @param serviceNames
  1085. */
  1086. allowUninstallServices: function(serviceNames) {
  1087. return App.Service.find().filter(function (service) {
  1088. return serviceNames.contains(service.get('serviceName'));
  1089. }).everyProperty('allowToDelete');
  1090. },
  1091. /**
  1092. * delete service action
  1093. * @param {string} serviceName
  1094. */
  1095. deleteService: function(serviceName) {
  1096. var self = this,
  1097. interDependentServices = this.get('interDependentServices'),
  1098. serviceNamesToDelete = this.get('serviceNamesToDelete'),
  1099. dependentServices = this.findDependentServices(serviceNamesToDelete),
  1100. displayName = App.format.role(serviceName, true),
  1101. popupHeader = Em.I18n.t('services.service.delete.popup.header'),
  1102. dependentServicesToDeleteFmt = this.servicesDisplayNames(interDependentServices);
  1103. if (serviceName === 'KERBEROS') {
  1104. this.kerberosDeleteWarning(popupHeader);
  1105. return;
  1106. }
  1107. if (serviceName === 'RANGER' && this.isRangerPluginEnabled()) {
  1108. App.ModalPopup.show({
  1109. secondary: null,
  1110. header: popupHeader,
  1111. encodeBody: false,
  1112. body: Em.I18n.t('services.service.delete.popup.ranger')
  1113. });
  1114. return;
  1115. }
  1116. if (App.Service.find().get('length') === 1) {
  1117. //at least one service should be installed
  1118. App.ModalPopup.show({
  1119. secondary: null,
  1120. header: popupHeader,
  1121. encodeBody: false,
  1122. body: Em.I18n.t('services.service.delete.lastService.popup.body').format(displayName)
  1123. });
  1124. } else if (dependentServices.length > 0) {
  1125. this.dependentServicesWarning(serviceName, dependentServices);
  1126. } else {
  1127. var isServiceInRemovableState = this.allowUninstallServices(serviceNamesToDelete);
  1128. if (isServiceInRemovableState) {
  1129. if (serviceName === 'RANGER_KMS') {
  1130. App.showConfirmationPopup(
  1131. function () {
  1132. self.showLastWarning(serviceName, interDependentServices, dependentServicesToDeleteFmt)
  1133. },
  1134. Em.I18n.t('services.service.delete.popup.warning.ranger_kms'),
  1135. null,
  1136. popupHeader,
  1137. Em.I18n.t('common.delete'),
  1138. true
  1139. );
  1140. } else {
  1141. this.showLastWarning(serviceName, interDependentServices, dependentServicesToDeleteFmt);
  1142. }
  1143. } else {
  1144. var body = Em.I18n.t('services.service.delete.popup.mustBeStopped').format(displayName);
  1145. if (interDependentServices.length) {
  1146. body += Em.I18n.t('services.service.delete.popup.mustBeStopped.dependent').format(dependentServicesToDeleteFmt)
  1147. }
  1148. App.ModalPopup.show({
  1149. secondary: null,
  1150. header: popupHeader,
  1151. encodeBody: false,
  1152. body: body
  1153. });
  1154. }
  1155. }
  1156. },
  1157. /**
  1158. * show dialog with Kerberos warning prior to service delete
  1159. * @param {string} header
  1160. * @returns {App.ModalPopup}
  1161. */
  1162. kerberosDeleteWarning: function(header) {
  1163. return App.ModalPopup.show({
  1164. primary: Em.I18n.t('ok'),
  1165. secondary: Em.I18n.t('services.alerts.goTo').format('Kerberos'),
  1166. header: header,
  1167. encodeBody: false,
  1168. body: Em.I18n.t('services.service.delete.popup.kerberos'),
  1169. onSecondary: function() {
  1170. this._super();
  1171. App.router.transitionTo('main.admin.adminKerberos.index');
  1172. }
  1173. });
  1174. },
  1175. /**
  1176. * @returns {Boolean}
  1177. */
  1178. isRangerPluginEnabled: function() {
  1179. return App.router.get('mainServiceInfoSummaryController.rangerPlugins')
  1180. .filterProperty('isDisplayed').someProperty('status', 'Enabled');
  1181. },
  1182. /**
  1183. * warning that show dependent services which must be deleted prior to chosen service deletion
  1184. * @param {string} origin
  1185. * @param {string[]} dependent
  1186. * @returns {App.ModalPopup}
  1187. */
  1188. dependentServicesWarning: function(origin, dependent) {
  1189. return App.ModalPopup.show({
  1190. secondary: null,
  1191. header: Em.I18n.t('services.service.delete.popup.header'),
  1192. dependentMessage: Em.I18n.t('services.service.delete.popup.dependentServices').format(App.format.role(origin, true)),
  1193. dependentServices: dependent,
  1194. bodyClass: Em.View.extend({
  1195. templateName: require('templates/main/service/info/dependent_services_warning')
  1196. })
  1197. });
  1198. },
  1199. showLastWarning: function (serviceName, interDependentServices, dependentServicesToDeleteFmt) {
  1200. var self = this,
  1201. displayName = App.format.role(serviceName, true),
  1202. popupHeader = Em.I18n.t('services.service.delete.popup.header');
  1203. return App.showConfirmationPopup(
  1204. function() {self.confirmDeleteService(serviceName, interDependentServices, dependentServicesToDeleteFmt)},
  1205. Em.I18n.t('services.service.delete.popup.warning').format(displayName) +
  1206. (interDependentServices.length ? Em.I18n.t('services.service.delete.popup.warning.dependent').format(dependentServicesToDeleteFmt) : ''),
  1207. null,
  1208. popupHeader,
  1209. Em.I18n.t('common.delete'),
  1210. true
  1211. );
  1212. },
  1213. /**
  1214. * Confirmation popup of service deletion
  1215. * @param {string} serviceName
  1216. * @param {string[]} [dependentServiceNames]
  1217. * @param {string} [servicesToDeleteFmt]
  1218. */
  1219. confirmDeleteService: function (serviceName, dependentServiceNames, servicesToDeleteFmt) {
  1220. var confirmKey = 'delete',
  1221. self = this,
  1222. message = Em.I18n.t('services.service.confirmDelete.popup.body').format(App.format.role(serviceName, true), confirmKey);
  1223. if (dependentServiceNames.length > 0) {
  1224. message = Em.I18n.t('services.service.confirmDelete.popup.body.dependent')
  1225. .format(App.format.role(serviceName, true), servicesToDeleteFmt, confirmKey);
  1226. }
  1227. App.ModalPopup.show({
  1228. /**
  1229. * @function onPrimary
  1230. */
  1231. onPrimary: function() {
  1232. var serviceNames = [serviceName].concat(dependentServiceNames),
  1233. serviceDisplayNames = serviceNames.map(function (serviceName) {
  1234. return App.Service.find(serviceName).get('displayName');
  1235. }),
  1236. progressPopup = App.ModalPopup.show({
  1237. classNames: ['delete-service-progress'],
  1238. header: Em.I18n.t('services.service.delete.popup.header'),
  1239. showFooter: false,
  1240. message: Em.I18n.t('services.service.delete.progressPopup.message').format(stringUtils.getFormattedStringFromArray(serviceDisplayNames)),
  1241. bodyClass: Em.View.extend({
  1242. classNames: ['delete-service-progress-body'],
  1243. template: Em.Handlebars.compile('{{view App.SpinnerView}}<div class="progress-message">{{message}}</div>')
  1244. }),
  1245. onClose: function () {
  1246. self.set('deleteServiceProgressPopup', null);
  1247. this._super();
  1248. }
  1249. });
  1250. self.set('deleteServiceProgressPopup', progressPopup);
  1251. self.deleteServiceCall(serviceNames);
  1252. this._super();
  1253. },
  1254. /**
  1255. * @type {string}
  1256. */
  1257. primary: Em.I18n.t('common.delete'),
  1258. /**
  1259. * @type {string}
  1260. */
  1261. primaryClass: 'btn-danger',
  1262. /**
  1263. * @type {string}
  1264. */
  1265. header: Em.I18n.t('services.service.confirmDelete.popup.header'),
  1266. /**
  1267. * @type {string}
  1268. */
  1269. confirmInput: '',
  1270. /**
  1271. * @type {boolean}
  1272. */
  1273. disablePrimary: Em.computed.notEqual('confirmInput', confirmKey),
  1274. message: message,
  1275. /**
  1276. * @type {Em.View}
  1277. */
  1278. bodyClass: Em.View.extend({
  1279. confirmKey: confirmKey,
  1280. typeMessage: Em.I18n.t('services.service.confirmDelete.popup.body.type').format(confirmKey),
  1281. templateName: require('templates/main/service/info/confirm_delete_service')
  1282. }),
  1283. enterKeyPressed: function() {
  1284. if (this.get('disablePrimary')) return;
  1285. this.onPrimary();
  1286. }
  1287. });
  1288. },
  1289. /**
  1290. * All host names
  1291. * This property required for request for recommendations
  1292. *
  1293. * @type {String[]}
  1294. * @override
  1295. */
  1296. hostNames: Em.computed.alias('App.allHostNames'),
  1297. /**
  1298. * Recommendation object
  1299. * This property required for request for recommendations
  1300. *
  1301. * @type {Object}
  1302. * @override
  1303. */
  1304. hostGroups: function() {
  1305. var hostGroup = blueprintUtils.generateHostGroups(App.get('allHostNames'));
  1306. return blueprintUtils.removeDeletedComponents(hostGroup, [this.get('serviceNamesToDelete')]);
  1307. }.property('serviceNamesToDelete', 'App.allHostNames', 'App.componentToBeAdded', 'App.componentToBeDeleted'),
  1308. /**
  1309. * List of services without removed
  1310. * This property required for request for recommendations
  1311. *
  1312. * @type {String[]}
  1313. * @override
  1314. */
  1315. serviceNames: function() {
  1316. return App.Service.find().filter(function(s) {
  1317. return !this.get('serviceNamesToDelete').contains(s.get('serviceName'));
  1318. }, this).mapProperty('serviceName');
  1319. }.property('serviceNamesToDelete'),
  1320. /**
  1321. * This property required for request for recommendations
  1322. *
  1323. * @return {Boolean}
  1324. * @override
  1325. */
  1326. isConfigHasInitialState: function() { return false; },
  1327. /**
  1328. * Describes condition when recommendation should be applied
  1329. * Unfortunately for removing services it's not always true
  1330. * Property should be updated only if it depends on service that will be removed
  1331. * (similar as on add service)
  1332. *
  1333. * @return {Boolean}
  1334. * @override
  1335. */
  1336. allowUpdateProperty: function (parentProperties, name, fileName) {
  1337. var stackProperty = App.configsCollection.getConfigByName(name, fileName);
  1338. if (!stackProperty || (stackProperty.serviceName === this.get('content.serviceName'))) {
  1339. /**
  1340. * update properties for current service (in case will be used not only for removing service)
  1341. * and properties that are not defined in stack
  1342. */
  1343. return true;
  1344. }
  1345. if (stackProperty.propertyDependsOn.length) {
  1346. /**
  1347. * update properties that depends on current service
  1348. */
  1349. return !!stackProperty.propertyDependsOn.filter(function (p) {
  1350. var service = App.config.get('serviceByConfigTypeMap')[p.type];
  1351. return service && (this.get('content.serviceName') === service.get('serviceName'));
  1352. }, this).length;
  1353. }
  1354. return false;
  1355. },
  1356. /**
  1357. * Just config version note
  1358. *
  1359. * @type {String}
  1360. */
  1361. serviceConfigVersionNote: function() {
  1362. var services = this.get('serviceNamesToDelete').join(',');
  1363. if (this.get('serviceNamesToDelete.length') === 1) {
  1364. return Em.I18n.t('services.service.delete.configVersionNote').format(services);
  1365. }
  1366. return Em.I18n.t('services.service.delete.configVersionNote.plural').format(services);
  1367. }.property('serviceNamesToDelete'),
  1368. /**
  1369. * Method ot save configs after service have been removed
  1370. * @override
  1371. */
  1372. saveConfigs: function() {
  1373. var data = [],
  1374. progressPopup = this.get('deleteServiceProgressPopup');
  1375. this.get('stepConfigs').forEach(function(stepConfig) {
  1376. var serviceConfig = this.getServiceConfigToSave(stepConfig.get('serviceName'), stepConfig.get('configs'));
  1377. if (serviceConfig) {
  1378. data.push(serviceConfig);
  1379. }
  1380. }, this);
  1381. if (Em.isArray(data) && data.length) {
  1382. this.putChangedConfigurations(data, 'confirmServiceDeletion', function () {
  1383. if (progressPopup) {
  1384. progressPopup.onClose();
  1385. }
  1386. });
  1387. } else {
  1388. this.confirmServiceDeletion();
  1389. }
  1390. },
  1391. confirmServiceDeletion: function() {
  1392. var progressPopup = this.get('deleteServiceProgressPopup'),
  1393. msg = this.get('interDependentServices.length')
  1394. ? Em.I18n.t('services.service.delete.service.success.confirmation.plural').format(this.get('serviceNamesToDelete').join(','))
  1395. : Em.I18n.t('services.service.delete.service.success.confirmation').format(this.get('content.serviceName'));
  1396. if (progressPopup) {
  1397. progressPopup.onClose();
  1398. }
  1399. return App.showAlertPopup(Em.I18n.t('popup.confirmation.commonHeader'), msg, function() {
  1400. window.location.reload();
  1401. })
  1402. },
  1403. /**
  1404. * Ajax call to delete service
  1405. * @param {string[]} serviceNames
  1406. * @returns {$.ajax}
  1407. */
  1408. deleteServiceCall: function(serviceNames) {
  1409. var serviceToDeleteNow = serviceNames[0];
  1410. if (serviceNames.length > 1) {
  1411. var servicesToDeleteNext = serviceNames.slice(1);
  1412. }
  1413. App.Service.find().findProperty('serviceName', serviceToDeleteNow).set('deleteInProgress', true);
  1414. return App.ajax.send({
  1415. name : 'common.delete.service',
  1416. sender: this,
  1417. data : {
  1418. serviceName : serviceToDeleteNow,
  1419. servicesToDeleteNext: servicesToDeleteNext
  1420. },
  1421. success : 'deleteServiceCallSuccessCallback',
  1422. error: 'deleteServiceCallErrorCallback'
  1423. });
  1424. },
  1425. deleteServiceCallSuccessCallback: function(data, ajaxOptions, params) {
  1426. if (params.servicesToDeleteNext) {
  1427. this.deleteServiceCall(params.servicesToDeleteNext);
  1428. } else {
  1429. this.loadConfigRecommendations(null, this.saveConfigs.bind(this));
  1430. }
  1431. },
  1432. deleteServiceCallErrorCallback: function (jqXHR, ajaxOptions, error, opt) {
  1433. var progressPopup = this.get('deleteServiceProgressPopup');
  1434. if (progressPopup) {
  1435. progressPopup.onClose();
  1436. }
  1437. App.ajax.defaultErrorHandler(jqXHR, opt.url, opt.type, jqXHR.status);
  1438. }
  1439. });