Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions config-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
<artifactId>scalecube-config</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<artifactId>log4j-slf4j-impl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jpl</artifactId>
<artifactId>log4j-core</artifactId>
</dependency>
</dependencies>

Expand Down
4 changes: 4 additions & 0 deletions config-vault/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
<groupId>com.bettercloud</groupId>
<artifactId>vault-java-driver</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import com.bettercloud.vault.VaultConfig;
import com.bettercloud.vault.VaultException;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class VaultClientTokenSupplier {

private static final Logger LOGGER = System.getLogger(VaultClientTokenSupplier.class.getName());
private static final Logger LOGGER = LoggerFactory.getLogger(VaultClientTokenSupplier.class);

private final String vaultAddress;
private final String vaultToken;
Expand Down Expand Up @@ -74,8 +74,7 @@ private String getToken0() {

if (!isNullOrNoneOrEmpty(vaultRole)) {
if (!isNullOrNoneOrEmpty(vaultToken)) {
LOGGER.log(
Level.WARNING,
LOGGER.warn(
"Taking KubernetesVaultTokenSupplier by precedence rule, "
+ "ignoring EnvironmentVaultTokenSupplier "
+ "(specify either vaultToken or vaultRole, not both)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import io.scalecube.config.ConfigSourceNotAvailableException;
import io.scalecube.config.source.ConfigSource;
import io.scalecube.config.source.LoadedConfigProperty;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand All @@ -22,6 +20,8 @@
import java.util.function.Function;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This class is an implementation of {@link ConfigSource} for Vault.
Expand All @@ -30,7 +30,7 @@
*/
public class VaultConfigSource implements ConfigSource {

private static final Logger LOGGER = System.getLogger(VaultConfigSource.class.getName());
private static final Logger LOGGER = LoggerFactory.getLogger(VaultConfigSource.class);

private static final EnvironmentLoader ENVIRONMENT_LOADER = new EnvironmentLoader();

Expand Down Expand Up @@ -58,12 +58,12 @@ public Map<String, ConfigProperty> loadConfig() {
result.putAll(pathProps);
} catch (VaultException ex) {
if (ex.getHttpStatusCode() == 404) {
LOGGER.log(Level.ERROR, "Unable to load config properties from: " + path);
LOGGER.error("Unable to load config properties from: {}", path);
} else {
throw new ConfigSourceNotAvailableException(ex);
}
} catch (Exception ex) {
LOGGER.log(Level.ERROR, "Unable to load config properties from: " + path, ex);
LOGGER.error("Unable to load config properties from: {}", path, ex);
throw new ConfigSourceNotAvailableException(ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import com.bettercloud.vault.response.VaultResponse;
import com.bettercloud.vault.rest.RestResponse;
import io.scalecube.config.utils.ThrowableUtil;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.Optional;
Expand All @@ -19,10 +17,12 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class VaultInvoker {

private static final Logger LOGGER = System.getLogger(VaultInvoker.class.getName());
private static final Logger LOGGER = LoggerFactory.getLogger(VaultInvoker.class);

private static final int STATUS_CODE_FORBIDDEN = 403;
public static final int STATUS_CODE_HEALTH_OK = 200;
Expand Down Expand Up @@ -58,9 +58,8 @@ public <T extends VaultResponse> T invoke(VaultCall<T> call) throws VaultExcepti
} catch (VaultException e) {
// try recreate Vault according to https://www.vaultproject.io/api/overview#http-status-codes
if (e.getHttpStatusCode() == STATUS_CODE_FORBIDDEN) {
LOGGER.log(
Level.WARNING,
"Authentication failed (error message: {0}), now trying to recreate vault",
LOGGER.warn(
"Authentication failed (error message: {}), now trying to recreate vault",
e.getMessage());
vault = recreateVault(vault);
return call.apply(vault);
Expand Down Expand Up @@ -94,17 +93,13 @@ private synchronized Vault recreateVault(Vault prev) throws VaultException {
long delay = TimeUnit.SECONDS.toMillis(suggestedRefreshInterval(ttl));
timer = new Timer("VaultScheduler", true);
timer.schedule(new RenewTokenTask(), delay);
LOGGER.log(
Level.INFO,
"Renew token timer was set to {0,number,#}s, (TTL = {1,number,#}s)",
delay,
ttl);
LOGGER.info("Renew token timer was set to {}s, (TTL = {}s)", delay, ttl);
} else {
LOGGER.log(Level.WARNING, "Vault token is not renewable");
LOGGER.warn("Vault token is not renewable");
}
this.vault = vault;
} catch (VaultException e) {
LOGGER.log(Level.ERROR, "Could not initialize and validate the vault", e);
LOGGER.error("Could not initialize and validate the vault", e);
throw e;
}
return vault;
Expand All @@ -118,22 +113,22 @@ private void renewToken() throws VaultException {
try {
AuthResponse response = vault.auth().renewSelf();
long ttl = response.getAuthLeaseDuration();
LOGGER.log(Level.DEBUG, "Token was successfully renewed (new TTL = {0,number,#}s)", ttl);
LOGGER.debug("Token was successfully renewed (new TTL = {}s)", ttl);
if (response.isAuthRenewable()) {
if (ttl > 1) {
long delay = TimeUnit.SECONDS.toMillis(suggestedRefreshInterval(ttl));
timer.schedule(new RenewTokenTask(), delay);
} else {
LOGGER.log(Level.WARNING, "Token TTL ({0,number,#}s) is not enough for scheduling", ttl);
LOGGER.warn("Token TTL ({}s) is not enough for scheduling", ttl);
vault = recreateVault(vault);
}
} else {
LOGGER.log(Level.WARNING, "Vault token is not renewable now");
LOGGER.warn("Vault token is not renewable now");
}
} catch (VaultException e) {
// try recreate Vault according to https://www.vaultproject.io/api/overview#http-status-codes
if (e.getHttpStatusCode() == STATUS_CODE_FORBIDDEN) {
LOGGER.log(Level.WARNING, "Could not renew the Vault token", e);
LOGGER.warn("Could not renew the Vault token", e);
//noinspection UnusedAssignment
vault = recreateVault(vault);
}
Expand Down Expand Up @@ -169,7 +164,7 @@ private void checkResponse(RestResponse restResponse) throws VaultException {
case STATUS_CODE_RESPONSE_NO_DATA:
return;
default:
LOGGER.log(Level.WARNING, "Vault responded with code: " + status);
LOGGER.warn("Vault responded with code: {}", status);
throw new VaultException(bodyAsString(restResponse), status);
}
}
Expand Down
7 changes: 7 additions & 0 deletions config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@

<artifactId>scalecube-config</artifactId>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package io.scalecube.config;

import io.scalecube.config.source.LoadedConfigProperty;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.util.Collection;
import java.util.List;
import java.util.Map;
Expand All @@ -13,6 +11,8 @@
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Abstract parent class for config property classes. Holds mutable state fields: {@link #value} the
Expand All @@ -25,7 +25,7 @@
*/
abstract class AbstractConfigProperty<T> {

private static final Logger LOGGER = System.getLogger(AbstractConfigProperty.class.getName());
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractConfigProperty.class);

private static final String ERROR_VALIDATION_FAILED =
"Validation failed on config property: %s, failed value: %s";
Expand Down Expand Up @@ -133,10 +133,9 @@ private void invokeCallback(BiConsumer<T, T> callback, T t1, T t2) {
try {
callback.accept(t1, t2);
} catch (Exception e) {
LOGGER.log(
Level.ERROR,
LOGGER.error(
"Exception occurred on property-change callback: "
+ "{0}, property name: {1}, oldValue: {2}, newValue: {3}",
+ "{}, property name: {}, oldValue: {}, newValue: {}",
callback,
name,
t1,
Expand Down
25 changes: 10 additions & 15 deletions config/src/main/java/io/scalecube/config/ConfigRegistryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import io.scalecube.config.source.ConfigSourceInfo;
import io.scalecube.config.source.LoadedConfigProperty;
import io.scalecube.config.utils.ThrowableUtil;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.lang.management.ManagementFactory;
import java.lang.reflect.Field;
import java.time.Duration;
Expand All @@ -34,10 +32,12 @@
import java.util.stream.Stream;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

final class ConfigRegistryImpl implements ConfigRegistry {

private static final Logger LOGGER = System.getLogger(ConfigRegistryImpl.class.getName());
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigRegistryImpl.class);

static final Function<String, String> STRING_PARSER = str -> str;
static final Function<String, Double> DOUBLE_PARSER = Double::parseDouble;
Expand All @@ -56,8 +56,7 @@ final class ConfigRegistryImpl implements ConfigRegistry {
Thread thread = new Thread(r);
thread.setDaemon(true);
thread.setName("config-registry");
thread.setUncaughtExceptionHandler(
(t, e) -> LOGGER.log(Level.ERROR, "Exception occurred", e));
thread.setUncaughtExceptionHandler((t, e) -> LOGGER.error("Exception occurred", e));
return thread;
};
reloadExecutor = Executors.newSingleThreadScheduledExecutor(threadFactory);
Expand All @@ -76,7 +75,7 @@ final class ConfigRegistryImpl implements ConfigRegistry {
new ConcurrentHashMap<>();

private final LinkedHashMap<ConfigEvent, Object> recentConfigEvents =
new LinkedHashMap<ConfigEvent, Object>() {
new LinkedHashMap<>() {
@Override
protected boolean removeEldestEntry(Map.Entry<ConfigEvent, Object> eldest) {
return size() > settings.getRecentConfigEventsNum();
Expand All @@ -97,7 +96,7 @@ void init() {
try {
loadAndNotify();
} catch (Exception e) {
LOGGER.log(Level.ERROR, "[loadAndNotify] Exception occurred, cause: {0}", e);
LOGGER.error("[loadAndNotify] Exception occurred", e);
}
},
settings.getReloadIntervalSec(),
Expand Down Expand Up @@ -490,12 +489,8 @@ private void reportChanges(Collection<ConfigEvent> events) {
try {
eventListener.onEvents(configEvents);
} catch (Exception e) {
LOGGER.log(
Level.ERROR,
"Exception on configEventListener: {0}, events: {1}",
key,
configEvents,
e);
LOGGER.error(
"Exception on configEventListener: {}, events: {}", key, configEvents, e);
}
});
}
Expand All @@ -505,9 +500,9 @@ private void computeConfigLoadStatus(String sourceName, Throwable ex) {
Integer status0 = configSourceStatusMap.put(sourceName, status);
if (status0 == null || (status0 ^ status) == 1) {
if (status == 1) {
LOGGER.log(Level.ERROR, "[loadConfig][{0}] Exception occurred", sourceName, ex);
LOGGER.error("[loadConfig][{}] Exception occurred", sourceName, ex);
} else {
LOGGER.log(Level.DEBUG, "[loadConfig][{0}] Loaded config properties", sourceName);
LOGGER.debug("[loadConfig][{}] Loaded config properties", sourceName);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/**
* Parser for {@link ObjectConfigProperty}. Returns object instance of the given class by the list
* of {@link LoadedConfigProperty}-s and list of {@link ObjectPropertyField}-s. The class must
* of {@link LoadedConfigProperty} objects and list of {@link ObjectPropertyField} . The class must
* contain default constructor.
*/
class ObjectPropertyParser {
Expand All @@ -31,8 +31,7 @@ static <T> T parseObject(
}

Map<String, Optional<String>> inputMap =
inputList
.stream()
inputList.stream()
.collect(
Collectors.toMap(LoadedConfigProperty::name, LoadedConfigProperty::valueAsString));

Expand Down
Loading
Loading