From 32e4170814cd282606ab00ec7ad4cfd710b7bb0a Mon Sep 17 00:00:00 2001 From: "lambert@arch" Date: Thu, 18 Apr 2024 13:09:04 +0800 Subject: [PATCH] fix: let null password not fail health check --- .../health/check/impl/storage/RedisCheck.java | 12 ++++++------ .../health/check/impl/storage/RedisCheckTest.java | 3 ++- .../function/SDK/operation/RedisSDKOperation.java | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/RedisCheck.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/RedisCheck.java index 16da9081..3cad4553 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/RedisCheck.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/RedisCheck.java @@ -40,7 +40,7 @@ @HealthCheckType(type = HealthCheckTypeConstant.HEALTH_CHECK_TYPE_STORAGE, subType = HealthCheckTypeConstant.HEALTH_CHECK_SUBTYPE_REDIS) public class RedisCheck extends AbstractHealthCheckService { - private CreateRedisConfig config; + private CreateRedisConfig sdkConfig; public RedisCheck(HealthCheckObjectConfig healthCheckObjectConfig) { super(healthCheckObjectConfig); @@ -50,7 +50,7 @@ public RedisCheck(HealthCheckObjectConfig healthCheckObjectConfig) { public void doCheck(HealthCheckCallback callback) { try { StatefulRedisConnection connection = (StatefulRedisConnection) SDKManager.getInstance() - .getClient(SDKTypeEnum.STORAGE_REDIS, config.getUniqueKey()); + .getClient(SDKTypeEnum.STORAGE_REDIS, sdkConfig.getUniqueKey()); RedisAsyncCommands commands = connection.async(); commands.ping().thenAccept(result -> { callback.onSuccess(); @@ -71,7 +71,7 @@ public void doCheck(HealthCheckCallback callback) { @Override public void init() { String redisUrl; - config = new CreateRedisConfig(); + sdkConfig = new CreateRedisConfig(); if (Objects.nonNull(getConfig().getConnectUrl()) && !getConfig().getConnectUrl().isEmpty()) { redisUrl = getConfig().getConnectUrl(); } else { @@ -87,12 +87,12 @@ public void init() { } redisUrl = builder.build().toString(); } - config.setRedisUrl(redisUrl); - SDKManager.getInstance().createClient(SDKTypeEnum.STORAGE_REDIS, config); + sdkConfig.setRedisUrl(redisUrl); + SDKManager.getInstance().createClient(SDKTypeEnum.STORAGE_REDIS, sdkConfig); } @Override public void destroy() { - SDKManager.getInstance().deleteClient(SDKTypeEnum.STORAGE_REDIS, config.getUniqueKey()); + SDKManager.getInstance().deleteClient(SDKTypeEnum.STORAGE_REDIS, sdkConfig.getUniqueKey()); } } diff --git a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/RedisCheckTest.java b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/RedisCheckTest.java index 4349b3a4..0e22457a 100644 --- a/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/RedisCheckTest.java +++ b/eventmesh-dashboard-console/src/test/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/RedisCheckTest.java @@ -43,7 +43,8 @@ public void init() { .healthCheckResourceSubType("redis") .simpleClassName("RedisCheck") .clusterId(1L) - .connectUrl("redis://127.0.0.1:6379") + .connectUrl("127.0.0.1:6379") + .password("") .build(); redisCheck = new RedisCheck(config); } catch (RedisException e) { diff --git a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RedisSDKOperation.java b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RedisSDKOperation.java index 1717f54d..aba1807b 100644 --- a/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RedisSDKOperation.java +++ b/eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/function/SDK/operation/RedisSDKOperation.java @@ -39,7 +39,7 @@ public SimpleEntry> createClient RedisURI redisURI = RedisURI.builder() .withHost(clientHost) .withPort(clientPort) - .withPassword(redisConfig.getPassword()) + .withPassword(redisConfig.getPassword() == null ? "" : redisConfig.getPassword()) .withTimeout(Duration.ofSeconds(redisConfig.getTimeOut())) .build(); RedisClient redisClient = RedisClient.create(redisURI);