|
| 1 | +package com.navercorp.pinpoint.metric.web.authorization.controller; |
| 2 | + |
| 3 | +import com.navercorp.pinpoint.metric.web.service.SystemMetricHostExclusionService; |
| 4 | +import com.navercorp.pinpoint.metric.web.view.SystemMetricHostGroupInfo; |
| 5 | +import com.navercorp.pinpoint.pinot.tenant.TenantProvider; |
| 6 | +import org.apache.logging.log4j.LogManager; |
| 7 | +import org.apache.logging.log4j.Logger; |
| 8 | +import org.springframework.http.HttpStatus; |
| 9 | +import org.springframework.web.bind.annotation.DeleteMapping; |
| 10 | +import org.springframework.web.bind.annotation.GetMapping; |
| 11 | +import org.springframework.web.bind.annotation.PostMapping; |
| 12 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 13 | +import org.springframework.web.bind.annotation.RequestParam; |
| 14 | +import org.springframework.web.bind.annotation.RestController; |
| 15 | +import org.springframework.web.server.ResponseStatusException; |
| 16 | + |
| 17 | +@RestController |
| 18 | +@RequestMapping(value = "/systemMetric/exclusion") |
| 19 | +public class SystemMetricExclusionController { |
| 20 | + private final Logger logger = LogManager.getLogger(this.getClass()); |
| 21 | + |
| 22 | + private final SystemMetricHostExclusionService systemMetricHostExclusionService; |
| 23 | + private final TenantProvider tenantProvider; |
| 24 | + |
| 25 | + public SystemMetricExclusionController(SystemMetricHostExclusionService systemMetricHostExclusionService, TenantProvider tenantProvider) { |
| 26 | + this.systemMetricHostExclusionService = systemMetricHostExclusionService; |
| 27 | + this.tenantProvider = tenantProvider; |
| 28 | + } |
| 29 | + |
| 30 | + @GetMapping(value = "/hostGroup") |
| 31 | + public SystemMetricHostGroupInfo getHostGroupExclusionInfo(@RequestParam("hostGroupName") String hostGroupName) { |
| 32 | + String tenantId = tenantProvider.getTenantId(); |
| 33 | + return systemMetricHostExclusionService.getHostGroupInfo(tenantId, hostGroupName); |
| 34 | + } |
| 35 | + |
| 36 | + @PostMapping(value = "/hostGroup") |
| 37 | + public String insertHostGroupExclusion(@RequestParam("hostGroupName") String hostGroupName) { |
| 38 | + logger.debug("add hostGroup exclusion - hostGroupName: [{}]", hostGroupName); |
| 39 | + try { |
| 40 | + systemMetricHostExclusionService.insertHostGroupExclusion(hostGroupName); |
| 41 | + return "OK"; |
| 42 | + } catch (Exception e) { |
| 43 | + logger.error("error while excluding hostGroupName", e); |
| 44 | + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage()); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + @DeleteMapping(value = "/hostGroup") |
| 49 | + public String deleteHostGroupExclusion(@RequestParam("hostGroupName") String hostGroupName) { |
| 50 | + logger.debug("delete host group exclusion - hostGroupName: [{}]", hostGroupName); |
| 51 | + try { |
| 52 | + systemMetricHostExclusionService.deleteHostGroupExclusion(hostGroupName); |
| 53 | + return "OK"; |
| 54 | + } catch (Exception e) { |
| 55 | + logger.error("error while accepting hostGroupName", e); |
| 56 | + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage()); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + @PostMapping(value = "/hostGroup/host") |
| 61 | + public String insertHostExclusion(@RequestParam String hostGroupName, |
| 62 | + @RequestParam String hostName) { |
| 63 | + logger.debug("add host exclusion - hostGroupName: [{}], hostName: [{}]", hostGroupName, hostName); |
| 64 | + try { |
| 65 | + systemMetricHostExclusionService.insertHostExclusion(hostGroupName, hostName); |
| 66 | + return "OK"; |
| 67 | + } catch (Exception e) { |
| 68 | + logger.error("error while excluding hostName", e); |
| 69 | + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage()); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + @DeleteMapping(value = "/hostGroup/host") |
| 74 | + public String deleteHostExclusion(@RequestParam("hostGroupName") String hostGroupName, |
| 75 | + @RequestParam("hostName") String hostName) { |
| 76 | + logger.debug("delete host exclusion - hostGroupName: [{}], hostName: [{}]", hostGroupName, hostName); |
| 77 | + try { |
| 78 | + systemMetricHostExclusionService.deleteHostExclusion(hostGroupName, hostName); |
| 79 | + return "OK"; |
| 80 | + } catch (Exception e) { |
| 81 | + logger.error("error while deleting host exclusion", e); |
| 82 | + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage()); |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + @DeleteMapping(value = "/hostGroup/unusedHosts") |
| 87 | + public String deleteUnusedHostExclusions(@RequestParam("hostGroupName") String hostGroupName) { |
| 88 | + logger.debug("delete unused hosts exclusions - hostGroupName: [{}]", hostGroupName); |
| 89 | + String tenantId = tenantProvider.getTenantId(); |
| 90 | + try { |
| 91 | + systemMetricHostExclusionService.deleteUnusedHostExclusions(tenantId, hostGroupName); |
| 92 | + return "OK"; |
| 93 | + } catch (Exception e) { |
| 94 | + logger.error("error while deleting unused host exclusions", e); |
| 95 | + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage()); |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + @DeleteMapping(value = "/cleanupUnusedGroups") |
| 100 | + public String deleteUnusedGroupExclusions() { |
| 101 | + logger.debug("delete exclusions from unused groups"); |
| 102 | + String tenantId = tenantProvider.getTenantId(); |
| 103 | + try { |
| 104 | + systemMetricHostExclusionService.deleteUnusedGroupExclusions(tenantId); |
| 105 | + return "OK"; |
| 106 | + } catch (Exception e) { |
| 107 | + logger.error("error while deleting exclusions from unused groups", e); |
| 108 | + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage()); |
| 109 | + } |
| 110 | + } |
| 111 | +} |
0 commit comments