refactor: 클라이언트 버킷 상태 모니터링 custom.inflow 패키지로 분리

- InflowTargetBucketService/Controller에서 클라이언트 관련 메서드/엔드포인트 제거
- ClientInflowTargetBucketService/Controller를 custom.inflow 패키지에 신규 생성
  (ClientInflowTargetMetricService/Controller 패턴과 일치)
- 관련 단위 테스트 추가 및 기존 테스트에서 클라이언트 케이스 제거

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
curry772
2026-05-08 10:22:15 +09:00
parent 31171d0187
commit d46fa8bd1a
9 changed files with 460 additions and 236 deletions
@@ -0,0 +1,63 @@
package com.eactive.eai.custom.inflow;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.eactive.eai.manage.inflow.TargetBucketStatusDTO;
/**
* 클라이언트 버킷 상태 모니터링 API.
*
* ClientDualInflowControlManager 가 활성화된 환경에서만 정상 응답한다.
*
* GET /manage/inflow/client/bucket-status → 전체 클라이언트 버킷 상태
* GET /manage/inflow/client/{clientId}/bucket-status → 특정 클라이언트 버킷 상태
*/
@RestController
@RequestMapping("/manage/inflow")
public class ClientInflowTargetBucketController {
@Autowired
private ClientInflowTargetBucketService bucketService;
@GetMapping("/client/bucket-status")
public ResponseEntity<?> getAllClientBucketStatus() {
List<TargetBucketStatusDTO> list = bucketService.getAllClientBucketStatus();
return ok(list);
}
@GetMapping("/client/{clientId}/bucket-status")
public ResponseEntity<?> getClientBucketStatus(@PathVariable String clientId) {
TargetBucketStatusDTO dto = bucketService.getClientBucketStatus(clientId);
return single(dto, "클라이언트를 찾을 수 없습니다: " + clientId);
}
private ResponseEntity<?> ok(List<TargetBucketStatusDTO> list) {
Map<String, Object> result = new HashMap<>();
result.put("success", true);
result.put("data", list);
result.put("count", list.size());
return ResponseEntity.ok(result);
}
private ResponseEntity<?> single(TargetBucketStatusDTO dto, String notFoundMsg) {
if (dto == null) {
Map<String, Object> error = new HashMap<>();
error.put("success", false);
error.put("message", notFoundMsg);
return ResponseEntity.ok(error);
}
Map<String, Object> result = new HashMap<>();
result.put("success", true);
result.put("data", dto);
return ResponseEntity.ok(result);
}
}
@@ -0,0 +1,79 @@
package com.eactive.eai.custom.inflow;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;
import com.eactive.eai.common.inflow.AbstractInflowControlManager;
import com.eactive.eai.common.inflow.InflowControlUtil;
import com.eactive.eai.common.inflow.InflowTargetVO;
import com.eactive.eai.common.inflow.dual.ClientDualInflowControlManager;
import com.eactive.eai.common.inflow.dual.DualCustomBucket;
import com.eactive.eai.manage.inflow.GroupBucketStatusDTO;
import com.eactive.eai.manage.inflow.TargetBucketStatusDTO;
/**
* 클라이언트 버킷 상태 조회 서비스.
*
* ClientDualInflowControlManager 가 활성화된 경우에만 동작한다.
*/
@Service
public class ClientInflowTargetBucketService {
public TargetBucketStatusDTO getClientBucketStatus(String clientId) {
ClientDualInflowControlManager manager = getClientDualManager();
if (manager == null) return null;
DualCustomBucket bucket = manager.getClientBucket(clientId);
if (bucket == null) return null;
return toDto(clientId, "CLIENT", bucket);
}
public List<TargetBucketStatusDTO> getAllClientBucketStatus() {
ClientDualInflowControlManager manager = getClientDualManager();
if (manager == null) return new ArrayList<>();
return toDtoList("CLIENT", manager.getClientBucketMap());
}
protected ClientDualInflowControlManager getClientDualManager() {
AbstractInflowControlManager base = InflowControlUtil.getInflowControlManager();
return (base instanceof ClientDualInflowControlManager) ? (ClientDualInflowControlManager) base : null;
}
private TargetBucketStatusDTO toDto(String targetId, String targetType, DualCustomBucket bucket) {
InflowTargetVO vo = bucket.getInflowTargetVo();
List<GroupBucketStatusDTO.BucketInfo> buckets = new ArrayList<>();
if (vo.getThresholdPerSecond() > 0) {
long capacity = vo.getThresholdPerSecond();
long available = bucket.getPerSecondAvailableTokens();
if (available < 0) available = capacity;
buckets.add(new GroupBucketStatusDTO.BucketInfo(
"perSecond", capacity, Math.min(available, capacity), "SEC"));
}
if (vo.getThreshold() > 0) {
long capacity = vo.getThreshold();
long available = bucket.getThresholdAvailableTokens();
if (available < 0) available = capacity;
buckets.add(new GroupBucketStatusDTO.BucketInfo(
"threshold", capacity, Math.min(available, capacity), vo.getThresholdTimeUnit()));
}
TargetBucketStatusDTO dto = new TargetBucketStatusDTO();
dto.setTargetId(targetId);
dto.setTargetType(targetType);
dto.setActivate(vo.isActivate());
dto.setBuckets(buckets);
return dto;
}
private List<TargetBucketStatusDTO> toDtoList(String targetType, Map<String, DualCustomBucket> bucketMap) {
List<TargetBucketStatusDTO> result = new ArrayList<>();
for (Map.Entry<String, DualCustomBucket> entry : bucketMap.entrySet()) {
result.add(toDto(entry.getKey(), targetType, entry.getValue()));
}
return result;
}
}