|
| 1 | +package com.navercorp.pinpoint.metric.web.authorization.controller; |
| 2 | + |
| 3 | +import com.navercorp.pinpoint.metric.web.service.SystemMetricHostExclusionService; |
| 4 | +import com.navercorp.pinpoint.pinot.tenant.TenantProvider; |
| 5 | +import org.apache.logging.log4j.LogManager; |
| 6 | +import org.apache.logging.log4j.Logger; |
| 7 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 8 | +import org.springframework.web.bind.annotation.RequestParam; |
| 9 | +import org.springframework.web.bind.annotation.RestController; |
| 10 | + |
| 11 | +@RestController |
| 12 | +@RequestMapping(value = "/admin/systemMetric") |
| 13 | +public class SystemMetricHostExclusionController { |
| 14 | + private final Logger logger = LogManager.getLogger(this.getClass()); |
| 15 | + |
| 16 | + private final SystemMetricHostExclusionService systemMetricHostExclusionService; |
| 17 | + private final TenantProvider tenantProvider; |
| 18 | + |
| 19 | + public SystemMetricHostExclusionController(SystemMetricHostExclusionService systemMetricHostExclusionService, TenantProvider tenantProvider) { |
| 20 | + this.systemMetricHostExclusionService = systemMetricHostExclusionService; |
| 21 | + this.tenantProvider = tenantProvider; |
| 22 | + } |
| 23 | + |
| 24 | + @RequestMapping(value = "/hostGroup/addExclusion") |
| 25 | + public String excludeHostGroup(@RequestParam("hostGroupName") String hostGroupName) { |
| 26 | + logger.info("add hostGroup exclusion - hostGroupName: [{}]", hostGroupName); |
| 27 | + try { |
| 28 | + String tenantId = tenantProvider.getTenantId(); |
| 29 | + systemMetricHostExclusionService.insertHostGroupExclusion(tenantId, hostGroupName); |
| 30 | + return "OK"; |
| 31 | + } catch (Exception e) { |
| 32 | + logger.error("error while excluding hostGroupName", e); |
| 33 | + return e.getMessage(); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + @RequestMapping(value = "/hostGroup/host/addExclusion") |
| 38 | + public String excludeHostGroup(@RequestParam("hostGroupName") String hostGroupName, |
| 39 | + @RequestParam("hostName") String hostName) { |
| 40 | + logger.info("add host exclusion - hostGroupName: [{}], hostName: [{}]", hostGroupName, hostName); |
| 41 | + try { |
| 42 | + String tenantId = tenantProvider.getTenantId(); |
| 43 | + systemMetricHostExclusionService.insertHostExclusion(tenantId, hostGroupName, hostName); |
| 44 | + return "OK"; |
| 45 | + } catch (Exception e) { |
| 46 | + logger.error("error while excluding hostName", e); |
| 47 | + return e.getMessage(); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + @RequestMapping(value = "/hostGroup/removeExclusion") |
| 52 | + public String acceptHostGroup(@RequestParam("hostGroupName") String hostGroupName) { |
| 53 | + logger.info("remove host group exclusion - hostGroupName: [{}]", hostGroupName); |
| 54 | + try { |
| 55 | + String tenantId = tenantProvider.getTenantId(); |
| 56 | + systemMetricHostExclusionService.deleteHostGroupExclusion(tenantId, hostGroupName); |
| 57 | + return "OK"; |
| 58 | + } catch (Exception e) { |
| 59 | + logger.error("error while accepting hostGroupName", e); |
| 60 | + return e.getMessage(); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + @RequestMapping(value = "/hostGroup/host/removeExclusion") |
| 65 | + public String acceptHostGroup(@RequestParam("hostGroupName") String hostGroupName, |
| 66 | + @RequestParam("hostName") String hostName) { |
| 67 | + logger.info("remove host exclusion - hostGroupName: [{}], hostName: [{}]", hostGroupName, hostName); |
| 68 | + try { |
| 69 | + String tenantId = tenantProvider.getTenantId(); |
| 70 | + systemMetricHostExclusionService.deleteHostExclusion(tenantId, hostGroupName, hostName); |
| 71 | + return "OK"; |
| 72 | + } catch (Exception e) { |
| 73 | + logger.error("error while accepting hostName", e); |
| 74 | + return e.getMessage(); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + @RequestMapping(value = "/hostGroup/removeUnusedExclusions") |
| 79 | + public String cleanupUnusedExclusions(@RequestParam("hostGroupName") String hostGroupName) { |
| 80 | + logger.info("remove unused hostGroup exclusion and host exclusions - hostGroupName: [{}]", hostGroupName); |
| 81 | + try { |
| 82 | + String tenantId = tenantProvider.getTenantId(); |
| 83 | + systemMetricHostExclusionService.deleteUnusedHostExclusion(tenantId, hostGroupName); |
| 84 | + return "OK"; |
| 85 | + } catch (Exception e) { |
| 86 | + logger.error("error while removing unused exclusions", e); |
| 87 | + return e.getMessage(); |
| 88 | + } |
| 89 | + } |
| 90 | +} |
0 commit comments