Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Release Notes.
Apollo 3.0.0

------------------
* [Refactor: extract config constants and methods in BizConfig, PortalConfig, and RefreshableConfig](https://github.com/apolloconfig/apollo/pull/5583)
* [Fix: include super admin in hasAnyPermission semantics](https://github.com/apolloconfig/apollo/pull/5568)
* [Change: official Config/Admin packages now default to database discovery; upgraded Eureka deployments should explicitly keep the `github` profile to preserve legacy behavior](https://github.com/apolloconfig/apollo/pull/5580)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public class BizConfig extends RefreshableConfig {

private static final Gson GSON = new Gson();

private static final TimeUnit INTERVAL_TIME_UNIT = TimeUnit.SECONDS;

private static final Type appIdValueLengthOverrideTypeReference =
new TypeToken<Map<String, Integer>>() {}.getType();
private static final Type namespaceValueLengthOverrideTypeReference =
Expand Down Expand Up @@ -140,7 +142,7 @@ public int namespaceNumLimit() {
}

public Set<String> namespaceNumLimitWhite() {
return Sets.newHashSet(getArrayProperty("namespace.num.limit.white", new String[0]));
return Sets.newHashSet(getArrayProperty("namespace.num.limit.white", EMPTY_STRING_ARRAY));
}

public boolean isItemNumLimitEnabled() {
Expand All @@ -163,7 +165,7 @@ public int appNamespaceCacheScanInterval() {
}

public TimeUnit appNamespaceCacheScanIntervalTimeUnit() {
return TimeUnit.SECONDS;
return INTERVAL_TIME_UNIT;
}

public int appNamespaceCacheRebuildInterval() {
Expand All @@ -173,7 +175,7 @@ public int appNamespaceCacheRebuildInterval() {
}

public TimeUnit appNamespaceCacheRebuildIntervalTimeUnit() {
return TimeUnit.SECONDS;
return INTERVAL_TIME_UNIT;
}

public int accessKeyCacheScanInterval() {
Expand All @@ -183,7 +185,7 @@ public int accessKeyCacheScanInterval() {
}

public TimeUnit accessKeyCacheScanIntervalTimeUnit() {
return TimeUnit.SECONDS;
return INTERVAL_TIME_UNIT;
}

public int accessKeyCacheRebuildInterval() {
Expand All @@ -193,7 +195,7 @@ public int accessKeyCacheRebuildInterval() {
}

public TimeUnit accessKeyCacheRebuildIntervalTimeUnit() {
return TimeUnit.SECONDS;
return INTERVAL_TIME_UNIT;
}

public int accessKeyAuthTimeDiffTolerance() {
Expand Down Expand Up @@ -222,7 +224,7 @@ public int releaseMessageCacheScanInterval() {
}

public TimeUnit releaseMessageCacheScanIntervalTimeUnit() {
return TimeUnit.SECONDS;
return INTERVAL_TIME_UNIT;
}

public int releaseMessageScanIntervalInMilli() {
Expand Down Expand Up @@ -285,13 +287,6 @@ public boolean isConfigServiceIncrementalChangeEnabled() {
return getBooleanProperty("config-service.incremental.change.enabled", false);
}

int checkInt(int value, int min, int max, int defaultValue) {
if (value >= min && value <= max) {
return value;
}
return defaultValue;
}

public boolean isAdminServiceAccessControlEnabled() {
return getBooleanProperty("admin-service.access.control.enabled", false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,22 @@
*/
package com.ctrip.framework.apollo.common.config;

import com.google.common.base.Splitter;
import com.google.common.base.Strings;

import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory;
import com.ctrip.framework.apollo.tracer.Tracer;

import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import jakarta.annotation.PostConstruct;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import jakarta.annotation.PostConstruct;


public abstract class RefreshableConfig implements DisposableBean {

Expand All @@ -46,6 +42,7 @@ public abstract class RefreshableConfig implements DisposableBean {
private static final int CONFIG_REFRESH_INTERVAL = 60;

protected Splitter splitter = Splitter.on(LIST_SEPARATOR).omitEmptyStrings().trimResults();
protected static final String[] EMPTY_STRING_ARRAY = new String[0];

@Autowired
private ConfigurableEnvironment environment;
Expand Down Expand Up @@ -137,4 +134,13 @@ public String getValue(String key) {
return environment.getProperty(key);
}

public int checkInt(int value, int min, int max, int defaultValue) {
if (value >= min && value <= max) {
return value;
}
logger.warn("Configuration value '{}' is out of bounds [{} - {}]. Using default value '{}'.",
value, min, max, defaultValue);
return defaultValue;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public class PortalConfig extends RefreshableConfig {
private static final int DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_OFFLINE_INTERVAL_IN_SECOND =
10; // 10s

private static final int DEFAULT_CONNECT_TIMEOUT = 3000;
private static final int DEFAULT_READ_TIMEOUT = 10000;
private static final int DEFAULT_CONNECTION_TIME_TO_LIVE = -1;
private static final int DEFAULT_CONNECT_POOL_MAX_TOTAL = 20;
private static final int DEFAULT_CONNECT_POOL_MAX_PER_ROUTE = 2;
private static final int DEFAULT_PER_ENV_SEARCH_MAX_RESULTS = 200;

private static final Gson GSON = new Gson();
private static final Type ORGANIZATION = new TypeToken<List<Organization>>() {}.getType();

Expand Down Expand Up @@ -90,7 +97,8 @@ public List<Env> portalSupportedEnvs() {
}

public int getPerEnvSearchMaxResults() {
return getIntProperty("apollo.portal.search.perEnvMaxResults", 200);
return getIntProperty("apollo.portal.search.perEnvMaxResults",
DEFAULT_PER_ENV_SEARCH_MAX_RESULTS);
}

/**
Expand Down Expand Up @@ -124,32 +132,26 @@ public List<String> superAdmins() {
}

public Set<Env> emailSupportedEnvs() {
String[] configurations = getArrayProperty("email.supported.envs", null);

Set<Env> result = Sets.newHashSet();
if (configurations == null) {
return result;
}

for (String env : configurations) {
result.add(Env.valueOf(env));
}

return result;
return getEnvSetProperty("email.supported.envs", null);
}

public Set<Env> webHookSupportedEnvs() {
String[] configurations = getArrayProperty("webhook.supported.envs", null);
return getEnvSetProperty("webhook.supported.envs", null);
}

private Set<Env> getEnvSetProperty(String key, String[] defaultValue) {
String[] configurations = getArrayProperty(key, defaultValue);
Set<Env> result = Sets.newHashSet();
if (configurations == null) {
if (configurations == null || configurations.length == 0) {
return result;
}

for (String env : configurations) {
result.add(Env.valueOf(env));
String envName = env.trim();
if (envName.isEmpty()) {
continue;
}
result.add(Env.valueOf(envName));
}

return result;
}

Expand All @@ -163,7 +165,7 @@ public boolean isConfigViewMemberOnly(String env) {
String normalizedEnv = transformedEnv.getName();

String[] configViewMemberOnlyEnvs =
getArrayProperty("configView.memberOnly.envs", new String[0]);
getArrayProperty("configView.memberOnly.envs", EMPTY_STRING_ARRAY);

for (String memberOnlyEnv : configViewMemberOnlyEnvs) {
// Normalize configured env as well for consistent comparison
Expand All @@ -180,23 +182,23 @@ public boolean isConfigViewMemberOnly(String env) {
* Level: normal
**/
public int connectTimeout() {
return getIntProperty("api.connectTimeout", 3000);
return getIntProperty("api.connectTimeout", DEFAULT_CONNECT_TIMEOUT);
}

public int readTimeout() {
return getIntProperty("api.readTimeout", 10000);
return getIntProperty("api.readTimeout", DEFAULT_READ_TIMEOUT);
}

public int connectionTimeToLive() {
return getIntProperty("api.connectionTimeToLive", -1);
return getIntProperty("api.connectionTimeToLive", DEFAULT_CONNECTION_TIME_TO_LIVE);
}

public int connectPoolMaxTotal() {
return getIntProperty("api.pool.max.total", 20);
return getIntProperty("api.pool.max.total", DEFAULT_CONNECT_POOL_MAX_TOTAL);
}

public int connectPoolMaxPerRoute() {
return getIntProperty("api.pool.max.per.route", 2);
return getIntProperty("api.pool.max.per.route", DEFAULT_CONNECT_POOL_MAX_PER_ROUTE);
}

public List<Organization> organizations() {
Expand Down Expand Up @@ -228,7 +230,7 @@ public boolean isEmergencyPublishAllowed(Env env) {
String targetEnv = env.getName();

String[] emergencyPublishSupportedEnvs =
getArrayProperty("emergencyPublish.supported.envs", new String[0]);
getArrayProperty("emergencyPublish.supported.envs", EMPTY_STRING_ARRAY);

for (String supportedEnv : emergencyPublishSupportedEnvs) {
if (Objects.equals(targetEnv, supportedEnv.toUpperCase().trim())) {
Expand All @@ -243,18 +245,7 @@ public boolean isEmergencyPublishAllowed(Env env) {
* Level: low
**/
public Set<Env> publishTipsSupportedEnvs() {
String[] configurations = getArrayProperty("namespace.publish.tips.supported.envs", null);

Set<Env> result = Sets.newHashSet();
if (configurations == null) {
return result;
}

for (String env : configurations) {
result.add(Env.valueOf(env));
}

return result;
return getEnvSetProperty("namespace.publish.tips.supported.envs", null);
}

public String consumerTokenSalt() {
Expand Down Expand Up @@ -337,12 +328,4 @@ public List<String> getUserPasswordNotAllowList() {
return Arrays.asList(value);
}

private int checkInt(int value, int min, int max, int defaultValue) {
if (value >= min && value <= max) {
return value;
}
logger.warn("Configuration value '{}' is out of bounds [{} - {}]. Using default value '{}'.",
value, min, max, defaultValue);
return defaultValue;
}
}
Loading