From 0cabe6d1d9c380cc9ad7303020651ff5e957d352 Mon Sep 17 00:00:00 2001 From: "saimu.msm" Date: Thu, 9 May 2024 13:34:38 +0800 Subject: [PATCH] address zone --- .../common/config/EnvironmentProperties.java | 1 + .../extension-storage-ceresdbx/pom.xml | 5 +++++ .../ceresdbx/CeresdbxClientManager.java | 18 ++++++++++++++++-- .../HoloinsightCeresdbxConfiguration.java | 6 ++++-- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/server/common/common-service/src/main/java/io/holoinsight/server/common/config/EnvironmentProperties.java b/server/common/common-service/src/main/java/io/holoinsight/server/common/config/EnvironmentProperties.java index 115c499ce..ad08bdb80 100644 --- a/server/common/common-service/src/main/java/io/holoinsight/server/common/config/EnvironmentProperties.java +++ b/server/common/common-service/src/main/java/io/holoinsight/server/common/config/EnvironmentProperties.java @@ -18,4 +18,5 @@ public class EnvironmentProperties { private String userCenter; private String location; private String gptUrl; + private String zone; } diff --git a/server/extension/extension-storage-ceresdbx/pom.xml b/server/extension/extension-storage-ceresdbx/pom.xml index 1e2c8db96..6d74288b8 100644 --- a/server/extension/extension-storage-ceresdbx/pom.xml +++ b/server/extension/extension-storage-ceresdbx/pom.xml @@ -79,5 +79,10 @@ common-dao ${project.version} + + io.holoinsight.server + common-service + ${project.version} + \ No newline at end of file diff --git a/server/extension/extension-storage-ceresdbx/src/main/java/io/holoinsight/server/extension/ceresdbx/CeresdbxClientManager.java b/server/extension/extension-storage-ceresdbx/src/main/java/io/holoinsight/server/extension/ceresdbx/CeresdbxClientManager.java index a9fef3a80..b755f6534 100644 --- a/server/extension/extension-storage-ceresdbx/src/main/java/io/holoinsight/server/extension/ceresdbx/CeresdbxClientManager.java +++ b/server/extension/extension-storage-ceresdbx/src/main/java/io/holoinsight/server/extension/ceresdbx/CeresdbxClientManager.java @@ -11,6 +11,7 @@ import io.ceresdb.rpc.RpcOptions; import io.ceresdb.rpc.RpcOptions.LimitKind; import io.holoinsight.server.common.J; +import io.holoinsight.server.common.config.EnvironmentProperties; import io.holoinsight.server.common.dao.entity.TenantOps; import io.holoinsight.server.common.dao.mapper.TenantOpsMapper; import org.apache.commons.lang3.StringUtils; @@ -38,10 +39,14 @@ public class CeresdbxClientManager { private TenantOpsMapper tenantOpsMapper; + private EnvironmentProperties environmentProperties; + private Map instances = new ConcurrentHashMap<>(); - public CeresdbxClientManager(TenantOpsMapper tenantOpsMapper) { + public CeresdbxClientManager(TenantOpsMapper tenantOpsMapper, + EnvironmentProperties environmentProperties) { this.tenantOpsMapper = tenantOpsMapper; + this.environmentProperties = environmentProperties; } @PostConstruct @@ -65,7 +70,7 @@ public void refresh() { String database = (String) ceresdbConfig.get("database"); Object portObj = ceresdbConfig.get("port"); int port = Double.valueOf(String.valueOf(portObj)).intValue(); - String newConfigKey = configKey(address, port, accessUser, accessKey); + String newConfigKey = configKey(fixAddress(address), port, accessUser, accessKey); CeresDBxClientInstance clientInstance = instances.get(tenant); if (clientInstance == null || !StringUtils.equals(clientInstance.getConfigKey(), newConfigKey)) { @@ -89,6 +94,15 @@ public void refresh() { } } + private String fixAddress(String address) { + if (StringUtils.indexOfIgnoreCase(address, "${zone}") != -1) { + String zoneAddress = + StringUtils.replaceIgnoreCase(address, "${zone}", this.environmentProperties.getZone()); + return zoneAddress; + } + return address; + } + public CeresDBClient getClient(String tenant) { if (StringUtils.isBlank(tenant)) { tenant = "dev"; diff --git a/server/extension/extension-storage-ceresdbx/src/main/java/io/holoinsight/server/extension/ceresdbx/HoloinsightCeresdbxConfiguration.java b/server/extension/extension-storage-ceresdbx/src/main/java/io/holoinsight/server/extension/ceresdbx/HoloinsightCeresdbxConfiguration.java index 282988ef4..ed0859009 100644 --- a/server/extension/extension-storage-ceresdbx/src/main/java/io/holoinsight/server/extension/ceresdbx/HoloinsightCeresdbxConfiguration.java +++ b/server/extension/extension-storage-ceresdbx/src/main/java/io/holoinsight/server/extension/ceresdbx/HoloinsightCeresdbxConfiguration.java @@ -3,6 +3,7 @@ */ package io.holoinsight.server.extension.ceresdbx; +import io.holoinsight.server.common.config.EnvironmentProperties; import io.holoinsight.server.common.dao.mapper.TenantOpsMapper; import io.holoinsight.server.extension.MetricMeterService; import io.holoinsight.server.extension.MetricStorage; @@ -24,8 +25,9 @@ public class HoloinsightCeresdbxConfiguration { @Bean - public CeresdbxClientManager ceresdbxClientManager(TenantOpsMapper tenantOpsMapper) { - return new CeresdbxClientManager(tenantOpsMapper); + public CeresdbxClientManager ceresdbxClientManager(TenantOpsMapper tenantOpsMapper, + EnvironmentProperties environmentProperties) { + return new CeresdbxClientManager(tenantOpsMapper, environmentProperties); } @Bean