item.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  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. App.MainServiceItemController = Em.Controller.extend(App.SupportClientConfigsDownload, App.InstallComponent, {
  21. name: 'mainServiceItemController',
  22. /**
  23. * Callback functions for start and stop service have few differences
  24. *
  25. * Used with currentCallBack property
  26. */
  27. callBackConfig: {
  28. 'STARTED': {
  29. 'c': 'STARTING',
  30. 'f': 'starting',
  31. 'c2': 'live',
  32. 'hs': 'started',
  33. 's': 'start'
  34. },
  35. 'INSTALLED': {
  36. 'c': 'STOPPING',
  37. 'f': 'stopping',
  38. 'c2': 'dead',
  39. 'hs': 'stopped',
  40. 's': 'stop'
  41. }
  42. },
  43. isServicesInfoLoaded: false,
  44. initHosts: function() {
  45. if (App.get('components.masters').length !== 0) {
  46. ['HBASE_MASTER', 'HIVE_METASTORE', 'ZOOKEEPER_SERVER', 'FLUME_HANDLER', 'HIVE_SERVER', 'RANGER_KMS_SERVER', 'NIMBUS'].forEach(function(componentName) {
  47. this.loadHostsWithoutComponent(componentName);
  48. }, this);
  49. }
  50. }.observes('App.components.masters', 'content.hostComponents.length'),
  51. loadHostsWithoutComponent: function (componentName) {
  52. var self = this;
  53. var hostsWithComponent = App.HostComponent.find().filterProperty('componentName', componentName).mapProperty('hostName');
  54. var hostsWithoutComponent = App.get('allHostNames').filter(function(hostName) {
  55. return !hostsWithComponent.contains(hostName);
  56. });
  57. self.set('add' + componentName, function() {
  58. App.get('router.mainAdminKerberosController').getKDCSessionState(function() {
  59. self.addComponent(componentName);
  60. });
  61. });
  62. Em.defineProperty(self, 'addDisabledTooltip-' + componentName, Em.computed('isAddDisabled-' + componentName, 'addDisabledMsg-' + componentName, function() {
  63. if (self.get('isAddDisabled-' + componentName)) {
  64. return self.get('addDisabledMsg-' + componentName);
  65. }
  66. }));
  67. Em.defineProperty(self, 'isAddDisabled-' + componentName, Em.computed('hostsWithoutComponent-' + componentName, function() {
  68. return self.get('hostsWithoutComponent-' + componentName).length === 0 ? 'disabled' : '';
  69. }));
  70. var disabledMsg = Em.I18n.t('services.summary.allHostsAlreadyRunComponent').format(componentName);
  71. self.set('hostsWithoutComponent-' + componentName, hostsWithoutComponent);
  72. self.set('addDisabledMsg-' + componentName, disabledMsg);
  73. },
  74. /**
  75. * flag to control router switch between service summary and configs
  76. * @type {boolean}
  77. */
  78. routeToConfigs: false,
  79. isClientsOnlyService: function() {
  80. return App.get('services.clientOnly').contains(this.get('content.serviceName'));
  81. }.property('content.serviceName'),
  82. isConfigurable: function () {
  83. return !App.get('services.noConfigTypes').contains(this.get('content.serviceName'));
  84. }.property('App.services.noConfigTypes','content.serviceName'),
  85. clientComponents: function () {
  86. var clientNames = [];
  87. var clients = App.StackServiceComponent.find().filterProperty('serviceName', this.get('content.serviceName')).filterProperty('isClient');
  88. clients.forEach(function (item) {
  89. clientNames.push({
  90. action: 'downloadClientConfigs',
  91. context: {
  92. name: item.get('componentName'),
  93. label: item.get('displayName')
  94. }
  95. });
  96. });
  97. return clientNames;
  98. }.property('content.serviceName'),
  99. /**
  100. * Common method for ajax (start/stop service) responses
  101. * @param data
  102. * @param ajaxOptions
  103. * @param params
  104. */
  105. startStopPopupSuccessCallback: function (data, ajaxOptions, params) {
  106. if (data && data.Requests) {
  107. params.query.set('status', 'SUCCESS');
  108. var config = this.get('callBackConfig')[(JSON.parse(ajaxOptions.data)).Body.ServiceInfo.state];
  109. var self = this;
  110. if (App.get('testMode')) {
  111. self.set('content.workStatus', App.Service.Health[config.f]);
  112. self.get('content.hostComponents').setEach('workStatus', App.HostComponentStatus[config.f]);
  113. setTimeout(function () {
  114. self.set('content.workStatus', App.Service.Health[config.c2]);
  115. self.get('content.hostComponents').setEach('workStatus', App.HostComponentStatus[config.hs]);
  116. }, App.get('testModeDelayForActions'));
  117. }
  118. // load data (if we need to show this background operations popup) from persist
  119. App.router.get('userSettingsController').dataLoading('show_bg').done(function (initValue) {
  120. if (initValue) {
  121. App.router.get('backgroundOperationsController').showPopup();
  122. }
  123. });
  124. } else {
  125. params.query.set('status', 'FAIL');
  126. }
  127. },
  128. startStopPopupErrorCallback: function(request, ajaxOptions, error, opt, params){
  129. params.query.set('status', 'FAIL');
  130. },
  131. /**
  132. * Confirmation popup for start/stop services
  133. * @param event
  134. * @param serviceHealth - 'STARTED' or 'INSTALLED'
  135. */
  136. startStopPopup: function(event, serviceHealth) {
  137. if ($(event.target).hasClass('disabled') || $(event.target.parentElement).hasClass('disabled')) {
  138. return;
  139. }
  140. var self = this;
  141. var serviceDisplayName = this.get('content.displayName');
  142. var isMaintenanceOFF = this.get('content.passiveState') === 'OFF';
  143. var msg = isMaintenanceOFF && serviceHealth == 'INSTALLED'? Em.I18n.t('services.service.stop.warningMsg.turnOnMM').format(serviceDisplayName) : null;
  144. msg = self.addAdditionalWarningMessage(serviceHealth, msg, serviceDisplayName);
  145. var bodyMessage = Em.Object.create({
  146. putInMaintenance: (serviceHealth == 'INSTALLED' && isMaintenanceOFF) || (serviceHealth == 'STARTED' && !isMaintenanceOFF),
  147. turnOnMmMsg: serviceHealth == 'INSTALLED' ? Em.I18n.t('passiveState.turnOnFor').format(serviceDisplayName) : Em.I18n.t('passiveState.turnOffFor').format(serviceDisplayName),
  148. confirmMsg: serviceHealth == 'INSTALLED'? Em.I18n.t('services.service.stop.confirmMsg').format(serviceDisplayName) : Em.I18n.t('services.service.start.confirmMsg').format(serviceDisplayName),
  149. confirmButton: serviceHealth == 'INSTALLED'? Em.I18n.t('services.service.stop.confirmButton') : Em.I18n.t('services.service.start.confirmButton'),
  150. additionalWarningMsg: msg
  151. });
  152. // check HDFS NameNode checkpoint before stop service
  153. if (this.get('content.serviceName') == 'HDFS' && serviceHealth == 'INSTALLED' &&
  154. this.get('content.hostComponents').filterProperty('componentName', 'NAMENODE').someProperty('workStatus', App.HostComponentStatus.started)) {
  155. this.checkNnLastCheckpointTime(function () {
  156. return App.showConfirmationFeedBackPopup(function(query, runMmOperation) {
  157. self.set('isPending', true);
  158. self.startStopWithMmode(serviceHealth, query, runMmOperation);
  159. }, bodyMessage);
  160. });
  161. } else {
  162. return App.showConfirmationFeedBackPopup(function(query, runMmOperation) {
  163. self.set('isPending', true);
  164. self.startStopWithMmode(serviceHealth, query, runMmOperation);
  165. }, bodyMessage);
  166. }
  167. },
  168. /**
  169. * this function will be called from :1) stop HDFS 2) restart all for HDFS 3) restart all affected for HDFS
  170. * @param callback - callback function to continue next operation
  171. */
  172. checkNnLastCheckpointTime: function(callback) {
  173. var self = this;
  174. this.pullNnCheckPointTime().complete(function () {
  175. var isNNCheckpointTooOld = self.get('isNNCheckpointTooOld');
  176. self.set('isNNCheckpointTooOld', null);
  177. if (isNNCheckpointTooOld) {
  178. // too old
  179. self.getHdfsUser().done(function() {
  180. var msg = Em.Object.create({
  181. confirmMsg: Em.I18n.t('services.service.stop.HDFS.warningMsg.checkPointTooOld').format(App.nnCheckpointAgeAlertThreshold) +
  182. Em.I18n.t('services.service.stop.HDFS.warningMsg.checkPointTooOld.instructions').format(isNNCheckpointTooOld, self.get('hdfsUser')),
  183. confirmButton: Em.I18n.t('common.next')
  184. });
  185. return App.showConfirmationFeedBackPopup(callback, msg);
  186. });
  187. } else if (isNNCheckpointTooOld == null) {
  188. // not available
  189. return App.showConfirmationPopup(
  190. callback, Em.I18n.t('services.service.stop.HDFS.warningMsg.checkPointNA'), null,
  191. Em.I18n.t('common.warning'), Em.I18n.t('common.proceedAnyway'), true
  192. );
  193. } else {
  194. // still young
  195. callback();
  196. }
  197. });
  198. },
  199. pullNnCheckPointTime: function () {
  200. return App.ajax.send({
  201. name: 'common.service.hdfs.getNnCheckPointTime',
  202. sender: this,
  203. success: 'parseNnCheckPointTime'
  204. });
  205. },
  206. parseNnCheckPointTime: function (data) {
  207. var nameNodesStatus = [];
  208. var lastCheckpointTime, hostName;
  209. if (data.host_components.length <= 1) {
  210. lastCheckpointTime = Em.get(data.host_components[0], 'metrics.dfs.FSNamesystem.LastCheckpointTime');
  211. hostName = Em.get(data.host_components[0], 'HostRoles.host_name');
  212. } else {
  213. // HA enabled
  214. data.host_components.forEach(function(namenode) {
  215. nameNodesStatus.pushObject( Em.Object.create({
  216. LastCheckpointTime: Em.get(namenode, 'metrics.dfs.FSNamesystem.LastCheckpointTime'),
  217. HAState: Em.get(namenode, 'metrics.dfs.FSNamesystem.HAState'),
  218. hostName: Em.get(namenode, 'HostRoles.host_name')
  219. }));
  220. });
  221. if (nameNodesStatus.someProperty('HAState', 'active')) {
  222. if (nameNodesStatus.findProperty('HAState', 'active').get('LastCheckpointTime')) {
  223. lastCheckpointTime = nameNodesStatus.findProperty('HAState', 'active').get('LastCheckpointTime');
  224. hostName = nameNodesStatus.findProperty('HAState', 'active').get('hostName');
  225. } else if (nameNodesStatus.someProperty('LastCheckpointTime')) {
  226. lastCheckpointTime = nameNodesStatus.findProperty('LastCheckpointTime').get('LastCheckpointTime');
  227. hostName = nameNodesStatus.findProperty('LastCheckpointTime').get('hostName');
  228. }
  229. } else if (nameNodesStatus.someProperty('HAState', 'standby')) {
  230. lastCheckpointTime = nameNodesStatus.findProperty('HAState', 'standby').get('LastCheckpointTime');
  231. hostName = nameNodesStatus.findProperty('HAState', 'standby').get('hostName')
  232. }
  233. }
  234. if (!lastCheckpointTime) {
  235. this.set("isNNCheckpointTooOld", null);
  236. } else {
  237. var time_criteria = App.nnCheckpointAgeAlertThreshold; // time in hours to define how many hours ago is too old
  238. var time_ago = (Math.round(App.dateTime() / 1000) - (time_criteria * 3600)) *1000;
  239. if (lastCheckpointTime <= time_ago) {
  240. // too old, set the effected hostName
  241. this.set("isNNCheckpointTooOld", hostName);
  242. } else {
  243. // still young
  244. this.set("isNNCheckpointTooOld", false);
  245. }
  246. }
  247. },
  248. /**
  249. * Return true if hdfs user data is loaded via App.MainServiceInfoConfigsController
  250. */
  251. getHdfsUser: function () {
  252. var self = this;
  253. var dfd = $.Deferred();
  254. var miscController = App.MainAdminServiceAccountsController.create();
  255. miscController.loadUsers();
  256. var interval = setInterval(function () {
  257. if (miscController.get('dataIsLoaded') && miscController.get('users')) {
  258. self.set('hdfsUser', miscController.get('users').findProperty('name', 'hdfs_user').get('value'));
  259. dfd.resolve();
  260. clearInterval(interval);
  261. }
  262. }, 10);
  263. return dfd.promise();
  264. },
  265. addAdditionalWarningMessage: function(serviceHealth, msg, serviceDisplayName){
  266. var servicesAffectedDisplayNames = [];
  267. var servicesAffected = [];
  268. if(serviceHealth == 'INSTALLED'){
  269. //To stop a service, display dependencies message...
  270. var currentService = this.get('content.serviceName');
  271. var stackServices = App.StackService.find();
  272. stackServices.forEach(function(service){
  273. if(service.get('isInstalled') || service.get('isSelected')){ //only care about services installed...
  274. var stackServiceDisplayName = service.get("displayName");
  275. var requiredServices = service.get('requiredServices'); //services required in order to have the current service be functional...
  276. if (!!requiredServices && requiredServices.length) { //only care about services with a non-empty requiredServices list.
  277. requiredServices.forEach(function(_requiredService){
  278. if (currentService === _requiredService) { //the service to be stopped is a required service by some other services...
  279. if(servicesAffected.indexOf(service) == -1 ) {
  280. servicesAffected.push(service);
  281. servicesAffectedDisplayNames.push(stackServiceDisplayName);
  282. }
  283. }
  284. },this);
  285. }
  286. }
  287. },this);
  288. var names = servicesAffectedDisplayNames.join();
  289. if(names){
  290. //only display this line with a non-empty dependency list
  291. var dependenciesMsg = Em.I18n.t('services.service.stop.warningMsg.dependent.services').format(serviceDisplayName,names);
  292. if(msg)
  293. msg = msg + " " + dependenciesMsg;
  294. else
  295. msg = dependenciesMsg;
  296. }
  297. }
  298. return msg;
  299. },
  300. startStopWithMmode: function(serviceHealth, query, runMmOperation) {
  301. var self = this;
  302. if (runMmOperation) {
  303. if (serviceHealth == "STARTED") {
  304. this.startStopPopupPrimary(serviceHealth, query).complete(function() {
  305. batchUtils.turnOnOffPassiveRequest("OFF", Em.I18n.t('passiveState.turnOff'), self.get('content.serviceName').toUpperCase());
  306. });
  307. } else {
  308. batchUtils.turnOnOffPassiveRequest("ON", Em.I18n.t('passiveState.turnOn'), this.get('content.serviceName').toUpperCase()).complete(function() {
  309. self.startStopPopupPrimary(serviceHealth, query);
  310. })
  311. }
  312. } else {
  313. this.startStopPopupPrimary(serviceHealth, query);
  314. }
  315. },
  316. startStopPopupPrimary: function (serviceHealth, query) {
  317. var requestInfo = (serviceHealth == "STARTED")
  318. ? App.BackgroundOperationsController.CommandContexts.START_SERVICE.format(this.get('content.serviceName'))
  319. : App.BackgroundOperationsController.CommandContexts.STOP_SERVICE.format(this.get('content.serviceName'));
  320. var data = {
  321. 'context': requestInfo,
  322. 'serviceName': this.get('content.serviceName').toUpperCase(),
  323. 'ServiceInfo': {
  324. 'state': serviceHealth
  325. },
  326. 'query': query
  327. };
  328. return App.ajax.send({
  329. 'name': 'common.service.update',
  330. 'sender': this,
  331. 'success': 'startStopPopupSuccessCallback',
  332. 'error': 'startStopPopupErrorCallback',
  333. 'data': data
  334. });
  335. },
  336. /**
  337. * On click callback for <code>start service</code> button
  338. * @param event
  339. */
  340. startService: function (event) {
  341. this.startStopPopup(event, App.HostComponentStatus.started);
  342. },
  343. /**
  344. * On click callback for <code>stop service</code> button
  345. * @param event
  346. */
  347. stopService: function (event) {
  348. this.startStopPopup(event, App.HostComponentStatus.stopped);
  349. },
  350. /**
  351. * On click callback for <code>run rebalancer</code> button
  352. * @param event
  353. */
  354. runRebalancer: function (event) {
  355. var self = this;
  356. return App.showConfirmationPopup(function() {
  357. self.set("content.runRebalancer", true);
  358. // load data (if we need to show this background operations popup) from persist
  359. App.router.get('userSettingsController').dataLoading('show_bg').done(function (initValue) {
  360. if (initValue) {
  361. App.router.get('backgroundOperationsController').showPopup();
  362. }
  363. });
  364. });
  365. },
  366. /**
  367. * On click handler for Yarn Refresh Queues command from items menu
  368. * @param event
  369. */
  370. refreshYarnQueues : function (event) {
  371. var controller = this;
  372. var hosts = App.Service.find('YARN').get('hostComponents').filterProperty('componentName', 'RESOURCEMANAGER').mapProperty('hostName');
  373. return App.showConfirmationPopup(function() {
  374. App.ajax.send({
  375. name : 'service.item.refreshQueueYarnRequest',
  376. sender: controller,
  377. data : {
  378. command : "REFRESHQUEUES",
  379. context : Em.I18n.t('services.service.actions.run.yarnRefreshQueues.context') ,
  380. hosts : hosts.join(','),
  381. serviceName : "YARN",
  382. componentName : "RESOURCEMANAGER",
  383. forceRefreshConfigTags : "capacity-scheduler"
  384. },
  385. success : 'refreshYarnQueuesSuccessCallback',
  386. error : 'refreshYarnQueuesErrorCallback'
  387. });
  388. });
  389. },
  390. refreshYarnQueuesSuccessCallback : function(data, ajaxOptions, params) {
  391. if (data.Requests.id) {
  392. App.router.get('backgroundOperationsController').showPopup();
  393. }
  394. },
  395. refreshYarnQueuesErrorCallback : function(data) {
  396. var error = Em.I18n.t('services.service.actions.run.yarnRefreshQueues.error');
  397. if(data && data.responseText){
  398. try {
  399. var json = $.parseJSON(data.responseText);
  400. error += json.message;
  401. } catch (err) {}
  402. }
  403. App.showAlertPopup(Em.I18n.t('services.service.actions.run.yarnRefreshQueues.error'), error);
  404. },
  405. startLdapKnox: function(event) {
  406. var context = Em.I18n.t('services.service.actions.run.startLdapKnox.context');
  407. this.startStopLdapKnox('STARTDEMOLDAP',context);
  408. },
  409. stopLdapKnox: function(event) {
  410. var context = Em.I18n.t('services.service.actions.run.stopLdapKnox.context');
  411. this.startStopLdapKnox('STOPDEMOLDAP',context);
  412. },
  413. startStopLdapKnox: function(command,context) {
  414. var controller = this;
  415. var host = App.HostComponent.find().findProperty('componentName', 'KNOX_GATEWAY').get('hostName');
  416. return App.showConfirmationPopup(function() {
  417. App.ajax.send({
  418. name: 'service.item.startStopLdapKnox',
  419. sender: controller,
  420. data: {
  421. command: command,
  422. context: context,
  423. host: host,
  424. serviceName: "KNOX",
  425. componentName: "KNOX_GATEWAY"
  426. },
  427. success: 'startStopLdapKnoxSuccessCallback',
  428. error: 'startStopLdapKnoxErrorCallback'
  429. });
  430. });
  431. },
  432. startStopLdapKnoxSuccessCallback : function(data, ajaxOptions, params) {
  433. if (data.Requests.id) {
  434. App.router.get('backgroundOperationsController').showPopup();
  435. }
  436. },
  437. startStopLdapKnoxErrorCallback : function(data) {
  438. var error = Em.I18n.t('services.service.actions.run.startStopLdapKnox.error');
  439. if(data && data.responseText){
  440. try {
  441. var json = $.parseJSON(data.responseText);
  442. error += json.message;
  443. } catch (err) {}
  444. }
  445. App.showAlertPopup(Em.I18n.t('services.service.actions.run.yarnRefreshQueues.error'), error);
  446. },
  447. /**
  448. * On click handler for rebalance Hdfs command from items menu
  449. */
  450. rebalanceHdfsNodes: function () {
  451. var controller = this;
  452. App.ModalPopup.show({
  453. classNames: ['fourty-percent-width-modal'],
  454. header: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.context'),
  455. primary: Em.I18n.t('common.start'),
  456. secondary: Em.I18n.t('common.cancel'),
  457. inputValue: 10,
  458. errorMessage: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.promptError'),
  459. isInvalid: function () {
  460. var intValue = Number(this.get('inputValue'));
  461. return this.get('inputValue')!=='DEBUG' && (isNaN(intValue) || intValue < 1 || intValue > 100);
  462. }.property('inputValue'),
  463. disablePrimary : function() {
  464. return this.get('isInvalid');
  465. }.property('isInvalid'),
  466. onPrimary: function () {
  467. if (this.get('isInvalid')) {
  468. return;
  469. }
  470. App.ajax.send({
  471. name : 'service.item.rebalanceHdfsNodes',
  472. sender: controller,
  473. data : {
  474. hosts : App.Service.find('HDFS').get('hostComponents').findProperty('componentName', 'NAMENODE').get('hostName'),
  475. threshold: this.get('inputValue')
  476. },
  477. success : 'rebalanceHdfsNodesSuccessCallback',
  478. error : 'rebalanceHdfsNodesErrorCallback'
  479. });
  480. this.hide();
  481. },
  482. bodyClass: Ember.View.extend({
  483. templateName: require('templates/common/modal_popups/prompt_popup'),
  484. text: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.prompt'),
  485. didInsertElement: function () {
  486. App.tooltip(this.$(".prompt-input"), {
  487. placement: "bottom",
  488. title: Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.promptTooltip')
  489. });
  490. }
  491. })
  492. });
  493. },
  494. rebalanceHdfsNodesSuccessCallback: function (data) {
  495. if (data.Requests.id) {
  496. App.router.get('backgroundOperationsController').showPopup();
  497. }
  498. },
  499. rebalanceHdfsNodesErrorCallback : function(data) {
  500. var error = Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.error');
  501. if(data && data.responseText){
  502. try {
  503. var json = $.parseJSON(data.responseText);
  504. error += json.message;
  505. } catch (err) {
  506. }
  507. }
  508. App.showAlertPopup(Em.I18n.t('services.service.actions.run.rebalanceHdfsNodes.error'), error);
  509. },
  510. /**
  511. * On click callback for <code>run compaction</code> button
  512. * @param event
  513. */
  514. runCompaction: function (event) {
  515. var self = this;
  516. return App.showConfirmationPopup(function() {
  517. self.set("content.runCompaction", true);
  518. // load data (if we need to show this background operations popup) from persist
  519. App.router.get('userSettingsController').dataLoading('show_bg').done(function (initValue) {
  520. if (initValue) {
  521. App.router.get('backgroundOperationsController').showPopup();
  522. }
  523. });
  524. });
  525. },
  526. /**
  527. * On click callback for <code>run smoke test</code> button
  528. * @param event
  529. */
  530. runSmokeTest: function (event) {
  531. var self = this;
  532. if (this.get('content.serviceName') === 'MAPREDUCE2' && !App.Service.find('YARN').get('isStarted')) {
  533. return App.showAlertPopup(Em.I18n.t('common.error'), Em.I18n.t('services.mapreduce2.smokeTest.requirement'));
  534. }
  535. return App.showConfirmationFeedBackPopup(function(query) {
  536. self.runSmokeTestPrimary(query);
  537. });
  538. },
  539. restartAllHostComponents : function(serviceName) {
  540. var serviceDisplayName = this.get('content.displayName');
  541. var bodyMessage = Em.Object.create({
  542. putInMaintenance: this.get('content.passiveState') === 'OFF',
  543. turnOnMmMsg: Em.I18n.t('passiveState.turnOnFor').format(serviceDisplayName),
  544. confirmMsg: Em.I18n.t('services.service.restartAll.confirmMsg').format(serviceDisplayName),
  545. confirmButton: Em.I18n.t('services.service.restartAll.confirmButton'),
  546. additionalWarningMsg: this.get('content.passiveState') === 'OFF' ? Em.I18n.t('services.service.restartAll.warningMsg.turnOnMM').format(serviceDisplayName): null
  547. });
  548. // check HDFS NameNode checkpoint before stop service
  549. if (this.get('content.serviceName') == 'HDFS' &&
  550. this.get('content.hostComponents').filterProperty('componentName', 'NAMENODE').someProperty('workStatus', App.HostComponentStatus.started)) {
  551. this.checkNnLastCheckpointTime(function () {
  552. return App.showConfirmationFeedBackPopup(function(query, runMmOperation) {
  553. batchUtils.restartAllServiceHostComponents(serviceDisplayName, serviceName, false, query, runMmOperation);
  554. }, bodyMessage);
  555. });
  556. } else {
  557. return App.showConfirmationFeedBackPopup(function(query, runMmOperation) {
  558. batchUtils.restartAllServiceHostComponents(serviceDisplayName, serviceName, false, query, runMmOperation);
  559. }, bodyMessage);
  560. }
  561. },
  562. turnOnOffPassive: function(label) {
  563. var self = this;
  564. var state = this.get('content.passiveState') == 'OFF' ? 'ON' : 'OFF';
  565. var onOff = state === 'ON' ? "On" : "Off";
  566. return App.showConfirmationPopup(function() {
  567. batchUtils.turnOnOffPassiveRequest(state, label, self.get('content.serviceName').toUpperCase(), function(data, opt, params) {
  568. self.set('content.passiveState', params.passive_state);
  569. batchUtils.infoPassiveState(params.passive_state);})
  570. },
  571. Em.I18n.t('hosts.passiveMode.popup').format(onOff,self.get('content.displayName'))
  572. );
  573. },
  574. rollingRestart: function(hostComponentName) {
  575. batchUtils.launchHostComponentRollingRestart(hostComponentName, this.get('content.displayName'), this.get('content.passiveState') === "ON", false, this.get('content.passiveState') === "ON");
  576. },
  577. runSmokeTestPrimary: function(query) {
  578. var clusterLevelRequired = ['KERBEROS'];
  579. var requestData = {
  580. 'serviceName': this.get('content.serviceName'),
  581. 'displayName': this.get('content.displayName'),
  582. 'actionName': this.get('content.serviceName') === 'ZOOKEEPER' ? 'ZOOKEEPER_QUORUM_SERVICE_CHECK' : this.get('content.serviceName') + '_SERVICE_CHECK',
  583. 'query': query
  584. };
  585. if (clusterLevelRequired.contains(this.get('content.serviceName'))) {
  586. requestData.operationLevel = {
  587. "level": "CLUSTER",
  588. "cluster_name": App.get('clusterName')
  589. };
  590. }
  591. App.ajax.send({
  592. 'name': 'service.item.smoke',
  593. 'sender': this,
  594. 'success':'runSmokeTestSuccessCallBack',
  595. 'error':'runSmokeTestErrorCallBack',
  596. 'data': requestData
  597. });
  598. },
  599. runSmokeTestSuccessCallBack: function (data, ajaxOptions, params) {
  600. if (data.Requests.id) {
  601. // load data (if we need to show this background operations popup) from persist
  602. App.router.get('userSettingsController').dataLoading('show_bg').done(function (initValue) {
  603. params.query.set('status', 'SUCCESS');
  604. if (initValue) {
  605. App.router.get('backgroundOperationsController').showPopup();
  606. }
  607. });
  608. }
  609. else {
  610. params.query.set('status', 'FAIL');
  611. }
  612. },
  613. runSmokeTestErrorCallBack: function (request, ajaxOptions, error, opt, params) {
  614. params.query.set('status', 'FAIL');
  615. },
  616. /**
  617. * On click callback for <code>Reassign <master component></code> button
  618. * @param hostComponent
  619. */
  620. reassignMaster: function (hostComponent) {
  621. var component = App.HostComponent.find().findProperty('componentName', hostComponent);
  622. if (component) {
  623. var reassignMasterController = App.router.get('reassignMasterController');
  624. reassignMasterController.saveComponentToReassign(component);
  625. reassignMasterController.setCurrentStep('1');
  626. App.router.transitionTo('reassign');
  627. }
  628. },
  629. /**
  630. * On click callback for <code>action</code> dropdown menu
  631. * Calls runSmokeTest, runRebalancer, runCompaction or reassignMaster depending on context
  632. * @param event
  633. */
  634. doAction: function (event) {
  635. if ($(event.target).hasClass('disabled') || $(event.target.parentElement).hasClass('disabled')) {
  636. return;
  637. }
  638. var methodName = event.context.action;
  639. var context = event.context.context;
  640. if (methodName) {
  641. this[methodName](context);
  642. }
  643. },
  644. /**
  645. * Restart clients host components to apply config changes
  646. */
  647. refreshConfigs: function () {
  648. var self = this;
  649. if (this.get('isClientsOnlyService') || this.get('content.serviceName') == "FLUME") {
  650. return App.showConfirmationFeedBackPopup(function (query) {
  651. batchUtils.getComponentsFromServer({
  652. services: [self.get('content.serviceName')]
  653. }, function (data) {
  654. var hostComponents = [];
  655. data.items.forEach(function (host) {
  656. host.host_components.forEach(function (hostComponent) {
  657. hostComponents.push(Em.Object.create({
  658. componentName: hostComponent.HostRoles.component_name,
  659. hostName: host.Hosts.host_name
  660. }))
  661. });
  662. });
  663. batchUtils.restartHostComponents(hostComponents, Em.I18n.t('rollingrestart.context.allForSelectedService').format(self.get('content.serviceName')), "SERVICE", query);
  664. })
  665. });
  666. }
  667. },
  668. /**
  669. * Send command to server to install client on selected host
  670. * @param componentName
  671. */
  672. addComponent: function (componentName) {
  673. var self = this;
  674. var component = App.StackServiceComponent.find().findProperty('componentName', componentName);
  675. var componentDisplayName = component.get('displayName');
  676. self.loadHostsWithoutComponent(componentName);
  677. return App.ModalPopup.show({
  678. primary: function() {
  679. if (this.get('anyHostsWithoutComponent')) {
  680. return Em.I18n.t('hosts.host.addComponent.popup.confirm')
  681. } else {
  682. return undefined;
  683. }
  684. }.property('anyHostsWithoutComponent'),
  685. header: Em.I18n.t('popup.confirmation.commonHeader'),
  686. addComponentMsg: function () {
  687. return Em.I18n.t('hosts.host.addComponent.msg').format(componentDisplayName);
  688. }.property(),
  689. selectHostMsg: function () {
  690. return Em.I18n.t('services.summary.selectHostForComponent').format(this.get('componentDisplayName'))
  691. }.property('componentDisplayName'),
  692. thereIsNoHostsMsg: function () {
  693. return Em.I18n.t('services.summary.allHostsAlreadyRunComponent').format(this.get('componentDisplayName'))
  694. }.property('componentDisplayName'),
  695. hostsWithoutComponent: function() {
  696. return self.get("hostsWithoutComponent-" + this.get('componentName'));
  697. }.property('componentName', 'self.hostsWithoutComponent-' + this.get('componentName')),
  698. anyHostsWithoutComponent: Em.computed.gt('hostsWithoutComponent.length', 0),
  699. selectedHost: null,
  700. componentName: function() {
  701. return componentName;
  702. }.property(),
  703. componentDisplayName: function() {
  704. return componentDisplayName;
  705. }.property(),
  706. bodyClass: Em.View.extend({
  707. templateName: require('templates/main/service/add_host_popup')
  708. }),
  709. onPrimary: function () {
  710. var selectedHost = this.get('selectedHost');
  711. // Install
  712. if(['HIVE_METASTORE', 'RANGER_KMS_SERVER', 'NIMBUS'].contains(component.get('componentName')) && !!selectedHost){
  713. App.router.get('mainHostDetailsController').addComponentWithCheck(
  714. {
  715. context: component,
  716. selectedHost: selectedHost
  717. }
  718. );
  719. } else {
  720. self.installHostComponentCall(selectedHost, component);
  721. }
  722. // Remove host from 'without' collection to immediate recalculate add menu item state
  723. var hostsWithoutComponent = this.get('hostsWithoutComponent');
  724. var index = hostsWithoutComponent.indexOf(this.get('selectedHost'));
  725. if (index > -1) {
  726. hostsWithoutComponent.splice(index, 1);
  727. }
  728. self.set('hostsWithoutComponent-' + this.get('componentName'), hostsWithoutComponent);
  729. this.hide();
  730. }
  731. });
  732. },
  733. /**
  734. * set property isPending (if this property is true - means that service has task in BGO)
  735. * and this makes start/stop button disabled
  736. */
  737. setStartStopState: function () {
  738. var serviceName = this.get('content.serviceName');
  739. var backgroundOperations = App.router.get('backgroundOperationsController.services');
  740. if (backgroundOperations && backgroundOperations.length > 0) {
  741. for (var i = 0; i < backgroundOperations.length; i++) {
  742. if (backgroundOperations[i].isRunning &&
  743. (backgroundOperations[i].dependentService === "ALL_SERVICES" ||
  744. backgroundOperations[i].dependentService === serviceName)) {
  745. this.set('isPending', true);
  746. return;
  747. }
  748. }
  749. this.set('isPending', false);
  750. } else {
  751. this.set('isPending', true);
  752. }
  753. }.observes('App.router.backgroundOperationsController.serviceTimestamp'),
  754. isStartDisabled: function () {
  755. if(this.get('isPending')) return true;
  756. return !(this.get('content.healthStatus') == 'red');
  757. }.property('content.healthStatus','isPending'),
  758. isStopDisabled: function () {
  759. if(this.get('isPending')) return true;
  760. if (App.get('isHaEnabled') && this.get('content.serviceName') == 'HDFS' && this.get('content.hostComponents').filterProperty('componentName', 'NAMENODE').someProperty('workStatus', App.HostComponentStatus.started)) {
  761. return false;
  762. }
  763. return (this.get('content.healthStatus') != 'green');
  764. }.property('content.healthStatus','isPending', 'App.isHaEnabled'),
  765. /**
  766. * Determine if service has than one service client components
  767. */
  768. isSeveralClients: function () {
  769. return App.StackServiceComponent.find().filterProperty('serviceName', this.get('content.serviceName')).filterProperty('isClient').length > 1;
  770. }.property('content.serviceName'),
  771. enableHighAvailability: function() {
  772. var ability_controller = App.router.get('mainAdminHighAvailabilityController');
  773. ability_controller.enableHighAvailability();
  774. },
  775. disableHighAvailability: function() {
  776. var ability_controller = App.router.get('mainAdminHighAvailabilityController');
  777. ability_controller.disableHighAvailability();
  778. },
  779. enableRMHighAvailability: function() {
  780. var ability_controller = App.router.get('mainAdminHighAvailabilityController');
  781. ability_controller.enableRMHighAvailability();
  782. },
  783. enableRAHighAvailability: function() {
  784. var ability_controller = App.router.get('mainAdminHighAvailabilityController');
  785. ability_controller.enableRAHighAvailability();
  786. },
  787. downloadClientConfigs: function (event) {
  788. var component = this.get('content.clientComponents').rejectProperty('totalCount', 0)[0];
  789. this.downloadClientConfigsCall({
  790. serviceName: this.get('content.serviceName'),
  791. componentName: (event && event.name) || component.get('componentName'),
  792. displayName: (event && event.label) || component.get('displayName')
  793. });
  794. },
  795. /**
  796. * On click handler for custom command from items menu
  797. * @param context
  798. */
  799. executeCustomCommand: function(context) {
  800. var controller = this;
  801. return App.showConfirmationPopup(function() {
  802. App.ajax.send({
  803. name : 'service.item.executeCustomCommand',
  804. sender: controller,
  805. data : {
  806. command : context.command,
  807. context : 'Execute ' + context.command,
  808. hosts : App.Service.find(context.service).get('hostComponents').findProperty('componentName', context.component).get('hostName'),
  809. serviceName : context.service,
  810. componentName : context.component,
  811. forceRefreshConfigTags : "capacity-scheduler"
  812. },
  813. success : 'executeCustomCommandSuccessCallback',
  814. error : 'executeCustomCommandErrorCallback'
  815. });
  816. });
  817. },
  818. executeCustomCommandSuccessCallback : function(data, ajaxOptions, params) {
  819. if (data.Requests.id) {
  820. App.router.get('backgroundOperationsController').showPopup();
  821. }
  822. },
  823. executeCustomCommandErrorCallback : function(data) {
  824. var error = Em.I18n.t('services.service.actions.run.executeCustomCommand.error');
  825. if(data && data.responseText){
  826. try {
  827. var json = $.parseJSON(data.responseText);
  828. error += json.message;
  829. } catch (err) {}
  830. }
  831. App.showAlertPopup(Em.I18n.t('services.service.actions.run.executeCustomCommand.error'), error);
  832. },
  833. isPending:true
  834. });