Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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 @@ -46,6 +46,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 +138,13 @@ public String getValue(String key) {
return environment.getProperty(key);
}

protected 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,7 @@ 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 +131,22 @@ 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));
}

return result;
}

Expand All @@ -163,7 +160,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 +177,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 +225,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 +240,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 +323,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