fix: fall back to tool pods when redis is unavailable
All checks were successful
Deploy to OCIWP / deploy (push) Successful in 2m14s

This commit is contained in:
jade
2026-08-10 10:29:53 +09:00
parent dd36247bf7
commit 906e7e206d
2 changed files with 48 additions and 5 deletions

View File

@@ -113,11 +113,16 @@ public class McpRouterController {
}
private List<ToolMetadata> fetchAllActiveTools() {
List<ToolMetadata> activeTools = redisRegistryService.getAllTools()
.stream()
.filter(ToolMetadata::getVisible)
.collect(Collectors.toList());
List<ToolMetadata> activeTools = new ArrayList<>();
try {
activeTools.addAll(redisRegistryService.getAllTools()
.stream()
.filter(ToolMetadata::getVisible)
.collect(Collectors.toList()));
} catch (org.springframework.data.redis.RedisConnectionFailureException exception) {
log.warn("Redis is unavailable. Fetching tools from configured fallback Tool Pods instead.");
}
Set<String> knownTools = activeTools.stream()
.map(ToolMetadata::getUid)
.collect(Collectors.toSet());

View File

@@ -0,0 +1,38 @@
package io.shinhanlife.dap.mcg.presentation;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.shinhanlife.dap.lib.mcp.security.SecurityProperties;
import io.shinhanlife.dap.lib.adapter.dto.JsonRpcResponse;
import io.shinhanlife.dap.mcg.config.GatewayFallbackProperties;
import io.shinhanlife.dap.mcg.registry.RedisRegistryService;
import io.shinhanlife.dap.mcg.service.ExecuteService;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.http.ResponseEntity;
class McpRouterControllerTest {
@Test
void returnsEmptyToolListWhenRedisIsUnavailableAndNoFallbackIsConfigured() {
RedisRegistryService registryService = org.mockito.Mockito.mock(RedisRegistryService.class);
when(registryService.getAllTools()).thenThrow(new RedisConnectionFailureException("Redis unavailable"));
McpRouterController controller = new McpRouterController(
registryService,
org.mockito.Mockito.mock(ExecuteService.class),
org.mockito.Mockito.mock(SecurityProperties.class),
new ObjectMapper(),
new GatewayFallbackProperties());
ResponseEntity<JsonRpcResponse> response = assertDoesNotThrow(() -> controller.listTools(null));
Map<?, ?> result = (Map<?, ?>) response.getBody().getResult();
assertEquals(List.of(), result.get("tools"));
}
}