Skip to content

Commit

Permalink
address zone
Browse files Browse the repository at this point in the history
  • Loading branch information
saimu.msm committed May 9, 2024
1 parent 75c8f19 commit 0cabe6d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ public class EnvironmentProperties {
private String userCenter;
private String location;
private String gptUrl;
private String zone;
}
5 changes: 5 additions & 0 deletions server/extension/extension-storage-ceresdbx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,10 @@
<artifactId>common-dao</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.holoinsight.server</groupId>
<artifactId>common-service</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,10 +39,14 @@ public class CeresdbxClientManager {

private TenantOpsMapper tenantOpsMapper;

private EnvironmentProperties environmentProperties;

private Map<String, CeresDBxClientInstance> instances = new ConcurrentHashMap<>();

public CeresdbxClientManager(TenantOpsMapper tenantOpsMapper) {
public CeresdbxClientManager(TenantOpsMapper tenantOpsMapper,
EnvironmentProperties environmentProperties) {
this.tenantOpsMapper = tenantOpsMapper;
this.environmentProperties = environmentProperties;
}

@PostConstruct
Expand All @@ -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)) {
Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 0cabe6d

Please sign in to comment.