diff --git a/.github/workflows/branch-ci.yml b/.github/workflows/branch-ci.yml index b6399688..5787348a 100644 --- a/.github/workflows/branch-ci.yml +++ b/.github/workflows/branch-ci.yml @@ -14,22 +14,23 @@ jobs: name: Branch CI runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/cache@v1 + - uses: actions/checkout@v4 + - uses: actions/cache@v3 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} restore-keys: | ${{ runner.os }}-maven- - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 + - name: Set up JDK + uses: actions/setup-java@v4 with: - java-version: 1.8 + java-version: 17 + distribution: zulu server-id: github server-username: GITHUB_ACTOR server-password: GITHUB_TOKEN - name: Maven Build - run: mvn clean install -DskipTests=true -Dmaven.javadoc.skip=true -Ddockerfile.skip=true -B -V + run: mvn clean install -DskipTests=true -Dmaven.javadoc.skip=true -B -V env: GITHUB_TOKEN: ${{ secrets.ORGANIZATION_TOKEN }} - name: Maven Verify diff --git a/.github/workflows/pre-release-ci.yml b/.github/workflows/pre-release-ci.yml index a7f35887..245e4d48 100644 --- a/.github/workflows/pre-release-ci.yml +++ b/.github/workflows/pre-release-ci.yml @@ -9,17 +9,18 @@ jobs: name: Pre-release CI runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/cache@v1 + - uses: actions/checkout@v4 + - uses: actions/cache@v3 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} restore-keys: | ${{ runner.os }}-maven- - name: Set up Java for publishing to GitHub Packages - uses: actions/setup-java@v1 + uses: actions/setup-java@v4 with: - java-version: 1.8 + java-version: 17 + distribution: zulu server-id: github server-username: GITHUB_ACTOR server-password: GITHUB_TOKEN @@ -33,9 +34,10 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.ORGANIZATION_TOKEN }} - name: Set up Java for publishing to Maven Central Repository - uses: actions/setup-java@v1 + uses: actions/setup-java@v4 with: - java-version: 1.8 + java-version: 17 + distribution: zulu server-id: ossrh server-username: MAVEN_USERNAME server-password: MAVEN_PASSWORD diff --git a/.github/workflows/release-ci.yml b/.github/workflows/release-ci.yml index a4f92667..4924f526 100644 --- a/.github/workflows/release-ci.yml +++ b/.github/workflows/release-ci.yml @@ -9,25 +9,26 @@ jobs: name: Release CI runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 - run: git checkout ${{ github.event.release.target_commitish }} - - uses: actions/cache@v1 + - uses: actions/cache@v3 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} restore-keys: | ${{ runner.os }}-maven- - name: Set up Java for publishing to GitHub Packages - uses: actions/setup-java@v1 + uses: actions/setup-java@v4 with: - java-version: 1.8 + java-version: 17 + distribution: zulu server-id: github server-username: GITHUB_ACTOR server-password: GITHUB_TOKEN - name: Maven Build - run: mvn clean install -DskipTests=true -Ddockerfile.skip=true -B -V + run: mvn clean install -DskipTests=true -B -V env: GITHUB_TOKEN: ${{ secrets.ORGANIZATION_TOKEN }} - name: Maven Verify @@ -41,17 +42,18 @@ jobs: run: | mvn -B build-helper:parse-version release:prepare \ -DreleaseVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.incrementalVersion} \ - -Darguments="-DskipTests=true -Ddockerfile.skip=true" + -Darguments="-DskipTests=true" echo release_tag=$(git describe --tags --abbrev=0) >> $GITHUB_OUTPUT - name: Perform release - run: mvn -B release:perform -Pdeploy2Github -Darguments="-DskipTests=true -Ddockerfile.skip=true -Pdeploy2Github" + run: mvn -B release:perform -Pdeploy2Github -Darguments="-DskipTests=true -Pdeploy2Github" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_REPOSITORY: ${{ secrets.GITHUB_REPOSITORY }} - name: Set up Java for publishing to Maven Central Repository - uses: actions/setup-java@v1 + uses: actions/setup-java@v4 with: - java-version: 1.8 + java-version: 17 + distribution: zulu server-id: ossrh server-username: MAVEN_USERNAME server-password: MAVEN_PASSWORD diff --git a/checkstyle-suppressions.xml b/checkstyle-suppressions.xml new file mode 100644 index 00000000..dbd0fdb1 --- /dev/null +++ b/checkstyle-suppressions.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + diff --git a/config-examples/pom.xml b/config-examples/pom.xml index 5616a0d6..3d511e89 100644 --- a/config-examples/pom.xml +++ b/config-examples/pom.xml @@ -1,12 +1,14 @@ - + + 4.0.0 io.scalecube scalecube-config-parent 0.4.21-SNAPSHOT - 4.0.0 scalecube-config-examples @@ -16,6 +18,14 @@ scalecube-config ${project.version} + + org.apache.logging.log4j + log4j-core + + + org.apache.logging.log4j + log4j-jpl + diff --git a/config-examples/src/main/java/io/scalecube/config/examples/ConfigRegistryExample.java b/config-examples/src/main/java/io/scalecube/config/examples/ConfigRegistryExample.java index 5a2b1111..1d3c19b1 100644 --- a/config-examples/src/main/java/io/scalecube/config/examples/ConfigRegistryExample.java +++ b/config-examples/src/main/java/io/scalecube/config/examples/ConfigRegistryExample.java @@ -3,7 +3,7 @@ import io.scalecube.config.ConfigRegistry; import io.scalecube.config.ConfigRegistrySettings; import io.scalecube.config.StringConfigProperty; -import io.scalecube.config.audit.Slf4JConfigEventListener; +import io.scalecube.config.audit.LoggingConfigEventListener; import io.scalecube.config.source.ClassPathConfigSource; import io.scalecube.config.source.FileDirectoryConfigSource; import java.nio.file.Path; @@ -28,7 +28,7 @@ public static void main(String[] args) { .addLastSource("classpath", new ClassPathConfigSource(propsPredicate)) .addLastSource( "configDirectory", new FileDirectoryConfigSource(basePath, propsPredicate)) - .addListener(new Slf4JConfigEventListener()) + .addListener(new LoggingConfigEventListener()) .jmxEnabled(true) .jmxMBeanName("config.exporter:name=ConfigRegistry") .build()); diff --git a/config-examples/src/main/java/io/scalecube/config/examples/DemoConfig.java b/config-examples/src/main/java/io/scalecube/config/examples/DemoConfig.java index 5e35a7cd..3b53b5e4 100644 --- a/config-examples/src/main/java/io/scalecube/config/examples/DemoConfig.java +++ b/config-examples/src/main/java/io/scalecube/config/examples/DemoConfig.java @@ -3,7 +3,7 @@ import io.scalecube.config.ConfigRegistry; import io.scalecube.config.ConfigRegistrySettings; import io.scalecube.config.StringConfigProperty; -import io.scalecube.config.audit.Slf4JConfigEventListener; +import io.scalecube.config.audit.LoggingConfigEventListener; import io.scalecube.config.source.FileDirectoryConfigSource; import java.nio.file.Path; import java.util.function.Predicate; @@ -33,7 +33,7 @@ public static void main(String[] args) { ConfigRegistrySettings.builder() .addLastSource( "ConfigDirectory", new FileDirectoryConfigSource(basePath, propsPredicate)) - .addListener(new Slf4JConfigEventListener()) + .addListener(new LoggingConfigEventListener()) .keepRecentConfigEvents(10) .reloadIntervalSec(3) .jmxEnabled(true) diff --git a/config-examples/src/main/java/io/scalecube/config/examples/ReloadableLocalResourceConfigExample.java b/config-examples/src/main/java/io/scalecube/config/examples/ReloadableLocalResourceConfigExample.java index 688cbbc1..8e479cba 100644 --- a/config-examples/src/main/java/io/scalecube/config/examples/ReloadableLocalResourceConfigExample.java +++ b/config-examples/src/main/java/io/scalecube/config/examples/ReloadableLocalResourceConfigExample.java @@ -6,7 +6,7 @@ import io.scalecube.config.ListConfigProperty; import io.scalecube.config.ObjectConfigProperty; import io.scalecube.config.StringConfigProperty; -import io.scalecube.config.audit.Slf4JConfigEventListener; +import io.scalecube.config.audit.LoggingConfigEventListener; import io.scalecube.config.source.FileDirectoryConfigSource; import java.io.BufferedWriter; import java.io.File; @@ -45,7 +45,7 @@ public static void main(String[] args) throws Exception { basePath, Stream.of(reloadablePropsPredicate, propsPredicate) .collect(Collectors.toList()))) - .addListener(new Slf4JConfigEventListener()) + .addListener(new LoggingConfigEventListener()) .reloadIntervalSec(1) .build()); diff --git a/config-vault/pom.xml b/config-vault/pom.xml index c14afed9..ba67de3a 100644 --- a/config-vault/pom.xml +++ b/config-vault/pom.xml @@ -1,5 +1,7 @@ - + 4.0.0 @@ -20,12 +22,6 @@ com.bettercloud vault-java-driver - - - org.testcontainers - vault - test - diff --git a/config-vault/src/main/java/io/scalecube/config/vault/KubernetesVaultTokenSupplier.java b/config-vault/src/main/java/io/scalecube/config/vault/KubernetesVaultTokenSupplier.java index b3877eaf..85ef8817 100644 --- a/config-vault/src/main/java/io/scalecube/config/vault/KubernetesVaultTokenSupplier.java +++ b/config-vault/src/main/java/io/scalecube/config/vault/KubernetesVaultTokenSupplier.java @@ -15,38 +15,19 @@ public class KubernetesVaultTokenSupplier implements VaultTokenSupplier { private static final EnvironmentLoader ENVIRONMENT_LOADER = new EnvironmentLoader(); - private String vaultRole = ENVIRONMENT_LOADER.loadVariable("VAULT_ROLE"); + private final String vaultRole; + private final String vaultJwtProvider; + private final String serviceAccountTokenPath; - private String vaultJwtProvider = - Optional.ofNullable( - Optional.ofNullable(ENVIRONMENT_LOADER.loadVariable("VAULT_JWT_PROVIDER")) - .orElse(ENVIRONMENT_LOADER.loadVariable("VAULT_MOUNT_POINT"))) - .orElse("kubernetes"); - - private String serviceAccountTokenPath = - Optional.ofNullable(ENVIRONMENT_LOADER.loadVariable("SERVICE_ACCOUNT_TOKEN_PATH")) - .orElse("/var/run/secrets/kubernetes.io/serviceaccount/token"); - - public KubernetesVaultTokenSupplier vaultRole(String vaultRole) { - this.vaultRole = vaultRole; - return this; - } - - public KubernetesVaultTokenSupplier vaultJwtProvider(String vaultJwtProvider) { - this.vaultJwtProvider = vaultJwtProvider; - return this; - } - - public KubernetesVaultTokenSupplier serviceAccountTokenPath(String serviceAccountTokenPath) { - this.serviceAccountTokenPath = serviceAccountTokenPath; - return this; + private KubernetesVaultTokenSupplier(Builder builder) { + this.vaultRole = Objects.requireNonNull(builder.vaultRole, "vault role"); + this.vaultJwtProvider = Objects.requireNonNull(builder.vaultJwtProvider, "jwt provider"); + this.serviceAccountTokenPath = + Objects.requireNonNull(builder.serviceAccountTokenPath, "k8s service account token path"); } @Override public String getToken(VaultConfig config) { - Objects.requireNonNull(vaultRole, "vault role"); - Objects.requireNonNull(vaultJwtProvider, "jwt provider"); - Objects.requireNonNull(serviceAccountTokenPath, "k8s service account token path"); try (Stream stream = Files.lines(Paths.get(serviceAccountTokenPath))) { String jwt = stream.collect(Collectors.joining()); return Objects.requireNonNull( @@ -59,4 +40,40 @@ public String getToken(VaultConfig config) { throw ThrowableUtil.propagate(e); } } + + public static class Builder { + + private String vaultRole = ENVIRONMENT_LOADER.loadVariable("VAULT_ROLE"); + + private String vaultJwtProvider = + Optional.ofNullable( + Optional.ofNullable(ENVIRONMENT_LOADER.loadVariable("VAULT_JWT_PROVIDER")) + .orElse(ENVIRONMENT_LOADER.loadVariable("VAULT_MOUNT_POINT"))) + .orElse("kubernetes"); + + private String serviceAccountTokenPath = + Optional.ofNullable(ENVIRONMENT_LOADER.loadVariable("SERVICE_ACCOUNT_TOKEN_PATH")) + .orElse("/var/run/secrets/kubernetes.io/serviceaccount/token"); + + public Builder() {} + + public Builder vaultRole(String vaultRole) { + this.vaultRole = vaultRole; + return this; + } + + public Builder vaultJwtProvider(String vaultJwtProvider) { + this.vaultJwtProvider = vaultJwtProvider; + return this; + } + + public Builder serviceAccountTokenPath(String serviceAccountTokenPath) { + this.serviceAccountTokenPath = serviceAccountTokenPath; + return this; + } + + public KubernetesVaultTokenSupplier build() { + return new KubernetesVaultTokenSupplier(this); + } + } } diff --git a/config-vault/src/main/java/io/scalecube/config/vault/VaultClientTokenSupplier.java b/config-vault/src/main/java/io/scalecube/config/vault/VaultClientTokenSupplier.java new file mode 100644 index 00000000..67bbf7c3 --- /dev/null +++ b/config-vault/src/main/java/io/scalecube/config/vault/VaultClientTokenSupplier.java @@ -0,0 +1,103 @@ +package io.scalecube.config.vault; + +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; + +public class VaultClientTokenSupplier { + + private static final Logger LOGGER = System.getLogger(VaultClientTokenSupplier.class.getName()); + + private final String vaultAddress; + private final String vaultToken; + private final String vaultRole; + + /** + * Constructor. + * + * @param vaultAddress vaultAddress + * @param vaultToken vaultToken (must not set be together with vaultRole) + * @param vaultRole vaultRole (must not set be together with vaultToken) + */ + public VaultClientTokenSupplier(String vaultAddress, String vaultToken, String vaultRole) { + this.vaultAddress = vaultAddress; + this.vaultToken = vaultToken; + this.vaultRole = vaultRole; + if (isNullOrNoneOrEmpty(vaultAddress)) { + throw new IllegalArgumentException("Vault address is required"); + } + if (isNullOrNoneOrEmpty(vaultToken) && isNullOrNoneOrEmpty(vaultRole)) { + throw new IllegalArgumentException( + "Vault auth scheme is required (specify either vaultToken or vaultRole)"); + } + } + + /** + * Returns new instance of {@link VaultClientTokenSupplier}. + * + * @param vaultAddress vaultAddress + * @param vaultToken vaultToken + * @return new instance of {@link VaultClientTokenSupplier} + */ + public static VaultClientTokenSupplier supplierByToken(String vaultAddress, String vaultToken) { + return new VaultClientTokenSupplier(vaultAddress, vaultToken, null); + } + + /** + * Returns new instance of {@link VaultClientTokenSupplier}. + * + * @param vaultAddress vaultAddress + * @param vaultRole vaultRole + * @return new instance of {@link VaultClientTokenSupplier} + */ + public static VaultClientTokenSupplier supplierByRole(String vaultAddress, String vaultRole) { + return new VaultClientTokenSupplier(vaultAddress, null, vaultRole); + } + + /** + * Obtains vault client token. + * + * @return future result + */ + public Future getToken() { + return CompletableFuture.supplyAsync(this::getToken0); + } + + private String getToken0() { + try { + VaultTokenSupplier vaultTokenSupplier; + VaultConfig vaultConfig; + + if (!isNullOrNoneOrEmpty(vaultRole)) { + if (!isNullOrNoneOrEmpty(vaultToken)) { + LOGGER.log( + Level.WARNING, + "Taking KubernetesVaultTokenSupplier by precedence rule, " + + "ignoring EnvironmentVaultTokenSupplier " + + "(specify either vaultToken or vaultRole, not both)"); + } + vaultTokenSupplier = + new KubernetesVaultTokenSupplier.Builder().vaultRole(vaultRole).build(); + vaultConfig = new VaultConfig().address(vaultAddress).build(); + } else { + vaultTokenSupplier = new EnvironmentVaultTokenSupplier(); + vaultConfig = new VaultConfig().address(vaultAddress).token(vaultToken).build(); + } + + return vaultTokenSupplier.getToken(vaultConfig); + } catch (VaultException e) { + throw new RuntimeException(e); + } + } + + private static boolean isNullOrNoneOrEmpty(String value) { + return Objects.isNull(value) + || "none".equalsIgnoreCase(value) + || "null".equals(value) + || value.isEmpty(); + } +} diff --git a/config-vault/src/main/java/io/scalecube/config/vault/VaultConfigSource.java b/config-vault/src/main/java/io/scalecube/config/vault/VaultConfigSource.java index c4524eb4..afb54ffc 100644 --- a/config-vault/src/main/java/io/scalecube/config/vault/VaultConfigSource.java +++ b/config-vault/src/main/java/io/scalecube/config/vault/VaultConfigSource.java @@ -8,6 +8,8 @@ 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; @@ -20,8 +22,6 @@ 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. @@ -30,7 +30,7 @@ */ public class VaultConfigSource implements ConfigSource { - private static final Logger LOGGER = LoggerFactory.getLogger(VaultConfigSource.class); + private static final Logger LOGGER = System.getLogger(VaultConfigSource.class.getName()); private static final EnvironmentLoader ENVIRONMENT_LOADER = new EnvironmentLoader(); @@ -58,22 +58,18 @@ public Map loadConfig() { result.putAll(pathProps); } catch (VaultException ex) { if (ex.getHttpStatusCode() == 404) { - LOGGER.warn("Unable to load config properties from: {}", path); + LOGGER.log(Level.ERROR, "Unable to load config properties from: " + path); } else { throw new ConfigSourceNotAvailableException(ex); } } catch (Exception ex) { - LOGGER.error("Unable to load config properties from: {}, cause:", path, ex); + LOGGER.log(Level.ERROR, "Unable to load config properties from: " + path, ex); throw new ConfigSourceNotAvailableException(ex); } } return result; } - public static Builder builder() { - return new Builder(); - } - public static final class Builder { private Function builderFunction = @@ -90,7 +86,7 @@ public static final class Builder { .map(HashSet::new) .orElseGet(HashSet::new); - private Builder() {} + public Builder() {} /** * Appends {@code secretsPath} to {@code secretsPaths}. diff --git a/config-vault/src/main/java/io/scalecube/config/vault/VaultInvoker.java b/config-vault/src/main/java/io/scalecube/config/vault/VaultInvoker.java index a6615d23..57938f8f 100644 --- a/config-vault/src/main/java/io/scalecube/config/vault/VaultInvoker.java +++ b/config-vault/src/main/java/io/scalecube/config/vault/VaultInvoker.java @@ -9,6 +9,8 @@ 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; @@ -17,12 +19,10 @@ 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 = LoggerFactory.getLogger(VaultInvoker.class); + private static final Logger LOGGER = System.getLogger(VaultInvoker.class.getName()); private static final int STATUS_CODE_FORBIDDEN = 403; public static final int STATUS_CODE_HEALTH_OK = 200; @@ -36,10 +36,6 @@ public class VaultInvoker { private Vault vault; private Timer timer; - public static Builder builder() { - return new Builder(); - } - private VaultInvoker(Builder builder) { this.builder = builder; } @@ -62,7 +58,10 @@ public T invoke(VaultCall 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.warn("Authentication details are incorrect, occurred during invoking Vault", e); + LOGGER.log( + Level.WARNING, + "Authentication failed (error message: {0}), now trying to recreate vault", + e.getMessage()); vault = recreateVault(vault); return call.apply(vault); } @@ -90,22 +89,18 @@ private synchronized Vault recreateVault(Vault prev) throws VaultException { Vault vault = new Vault(vaultConfig.token(token)); checkVault(vault); LookupResponse lookupSelf = vault.auth().lookupSelf(); - LOGGER.info("Initialized new Vault"); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("More Vault details: {}", bodyAsString(lookupSelf.getRestResponse())); - } if (lookupSelf.isRenewable()) { long ttl = lookupSelf.getTTL(); long delay = TimeUnit.SECONDS.toMillis(suggestedRefreshInterval(ttl)); timer = new Timer("VaultScheduler", true); timer.schedule(new RenewTokenTask(), delay); - LOGGER.info("Renew token timer was set to {}s, (TTL = {}s)", delay, ttl); + LOGGER.log(Level.INFO, "Renew token timer was set to {0}sec, (TTL = {1}sec)", delay, ttl); } else { - LOGGER.warn("Vault token is not renewable"); + LOGGER.log(Level.WARNING, "Vault token is not renewable"); } this.vault = vault; } catch (VaultException e) { - LOGGER.error("Could not initialize and validate the vault", e); + LOGGER.log(Level.ERROR, "Could not initialize and validate the vault", e); throw e; } return vault; @@ -119,27 +114,24 @@ private void renewToken() throws VaultException { try { AuthResponse response = vault.auth().renewSelf(); long ttl = response.getAuthLeaseDuration(); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug( - "Token was successfully renewed (new TTL = {} seconds), response: {}", - ttl, - bodyAsString(response.getRestResponse())); + if (LOGGER.isLoggable(Level.DEBUG)) { + LOGGER.log(Level.DEBUG, "Token was successfully renewed (new TTL = {0}sec)", ttl); } if (response.isAuthRenewable()) { if (ttl > 1) { long delay = TimeUnit.SECONDS.toMillis(suggestedRefreshInterval(ttl)); timer.schedule(new RenewTokenTask(), delay); } else { - LOGGER.warn("Token TTL ({}) is not enough for scheduling", ttl); + LOGGER.log(Level.WARNING, "Token TTL ({0}sec) is not enough for scheduling", ttl); vault = recreateVault(vault); } } else { - LOGGER.warn("Vault token is not renewable now"); + LOGGER.log(Level.WARNING, "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.warn("Could not renew the Vault token", e); + LOGGER.log(Level.WARNING, "Could not renew the Vault token", e); //noinspection UnusedAssignment vault = recreateVault(vault); } @@ -175,9 +167,8 @@ private void checkResponse(RestResponse restResponse) throws VaultException { case STATUS_CODE_RESPONSE_NO_DATA: return; default: - String body = bodyAsString(restResponse); - LOGGER.warn("Vault responded with code: {}, message: {}", status, body); - throw new VaultException(body, status); + LOGGER.log(Level.WARNING, "Vault responded with code: " + status); + throw new VaultException(bodyAsString(restResponse), status); } } @@ -223,6 +214,8 @@ public static class Builder { private VaultTokenSupplier tokenSupplier = new EnvironmentVaultTokenSupplier(); + public Builder() {} + public Builder options(UnaryOperator config) { this.options = this.options.andThen(config); return this; diff --git a/config-vault/src/main/java/io/scalecube/config/vault/VaultInvokers.java b/config-vault/src/main/java/io/scalecube/config/vault/VaultInvokers.java new file mode 100644 index 00000000..f32444e1 --- /dev/null +++ b/config-vault/src/main/java/io/scalecube/config/vault/VaultInvokers.java @@ -0,0 +1,86 @@ +package io.scalecube.config.vault; + +import java.lang.System.Logger; +import java.lang.System.Logger.Level; +import java.util.Map; +import java.util.Objects; + +public class VaultInvokers { + + public static final Logger LOGGER = System.getLogger(VaultInvokers.class.getName()); + + public static final String VAULT_MOUNT_POINT_ENV = "VAULT_MOUNT_POINT"; + public static final String VAULT_ADDR_ENV = "VAULT_ADDR"; + public static final String VAULT_TOKEN_ENV = "VAULT_TOKEN"; + public static final String VAULT_ROLE_ENV = "VAULT_ROLE"; + public static final String VAULT_JWT_PROVIDER_ENV = "VAULT_JWT_PROVIDER"; + public static final String VAULT_ENGINE_VERSION_ENV = "VAULT_ENGINE_VERSION"; + + public static final String DEFAULT_VAULT_ENGINE_VERSION = "1"; + + private VaultInvokers() { + // Do not instantiate + } + + /** + * Creates {@link VaultInvoker}, or throws error if {@link VaultInvoker} instance cannot be + * created. + * + * @return new {@code VaultInvoker} instance, or throws error + */ + public static VaultInvoker newVaultInvokerOrThrow() { + final VaultInvoker vaultInvoker = newVaultInvoker(); + if (vaultInvoker == null) { + throw new IllegalStateException("Cannot create vaultInvoker"); + } + return vaultInvoker; + } + + /** + * Creates and returns new {@link VaultInvoker} instance. + * + * @return new {@code VaultInvoker} instance + */ + public static VaultInvoker newVaultInvoker() { + Map env = System.getenv(); + + final String vaultAddr = env.get(VAULT_ADDR_ENV); + final int vaultEngineVersion = + Integer.parseInt(env.getOrDefault(VAULT_ENGINE_VERSION_ENV, DEFAULT_VAULT_ENGINE_VERSION)); + + if (isNullOrNone(vaultAddr)) { + return null; + } + + String vaultToken = env.get(VAULT_TOKEN_ENV); + String vaultRole = env.get(VAULT_ROLE_ENV); + + if (isNullOrNone(vaultToken) && isNullOrNone(vaultRole)) { + throw new IllegalArgumentException( + "Vault auth scheme is required (specify either VAULT_ROLE or VAULT_TOKEN)"); + } + + final VaultInvoker.Builder builder = + new VaultInvoker.Builder() + .options(config -> config.address(vaultAddr).engineVersion(vaultEngineVersion)); + + if (!isNullOrNone(vaultRole)) { + if (!isNullOrNone(vaultToken)) { + LOGGER.log( + Level.WARNING, + "Taking KubernetesVaultTokenSupplier by precedence rule, " + + "ignoring EnvironmentVaultTokenSupplier " + + "(specify either VAULT_ROLE or VAULT_TOKEN, not both)"); + } + builder.tokenSupplier(new KubernetesVaultTokenSupplier.Builder().build()); + } else { + builder.tokenSupplier(new EnvironmentVaultTokenSupplier()); + } + + return builder.build(); + } + + private static boolean isNullOrNone(String value) { + return Objects.isNull(value) || "none".equalsIgnoreCase(value); + } +} diff --git a/config-vault/src/test/java/io/scalecube/config/vault/VaultConfigSourceTest.java b/config-vault/src/test/java/io/scalecube/config/vault/VaultConfigSourceTest.java index 2d16cd8a..3dad413c 100644 --- a/config-vault/src/test/java/io/scalecube/config/vault/VaultConfigSourceTest.java +++ b/config-vault/src/test/java/io/scalecube/config/vault/VaultConfigSourceTest.java @@ -53,7 +53,7 @@ static void beforeAll() { @Test void testFirstTenant() { VaultConfigSource vaultConfigSource = - VaultConfigSource.builder() + new VaultConfigSource.Builder() .config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken())) .config(c -> c.address(vaultContainerExtension.vaultInstance().address())) .addSecretsPath(VAULT_SECRETS_PATH1) @@ -70,7 +70,7 @@ void testFirstTenant() { @Test void testSecondTenant() { VaultConfigSource vaultConfigSource = - VaultConfigSource.builder() + new VaultConfigSource.Builder() .config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken())) .config(c -> c.address(vaultContainerExtension.vaultInstance().address())) .addSecretsPath(VAULT_SECRETS_PATH2) @@ -87,7 +87,7 @@ void testSecondTenant() { @Test void testMultiplePathsEnv() { VaultConfigSource vaultConfigSource = - VaultConfigSource.builder() + new VaultConfigSource.Builder() .config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken())) .config(c -> c.address(vaultContainerExtension.vaultInstance().address())) .addSecretsPath(VAULT_SECRETS_PATH1 + ":" + VAULT_SECRETS_PATH2) @@ -120,7 +120,7 @@ void testMultiplePathsEnv() { @Test void testMissingProperty() { VaultConfigSource vaultConfigSource = - VaultConfigSource.builder() + new VaultConfigSource.Builder() .config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken())) .config(c -> c.address(vaultContainerExtension.vaultInstance().address())) .addSecretsPath(VAULT_SECRETS_PATH3) @@ -135,7 +135,7 @@ void testMissingProperty() { @Test void testMissingTenant() { - VaultConfigSource.builder() + new VaultConfigSource.Builder() .config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken())) .config(c -> c.address(vaultContainerExtension.vaultInstance().address())) .addSecretsPath("secrets/unknown/path") @@ -145,7 +145,7 @@ void testMissingTenant() { @Test void testInvalidAddress() { VaultConfigSource vaultConfigSource = - VaultConfigSource.builder() + new VaultConfigSource.Builder() .config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken())) .config(c -> c.address("http://invalid.host.local:8200")) .addSecretsPath(VAULT_SECRETS_PATH1) @@ -157,7 +157,7 @@ void testInvalidAddress() { @Test void testInvalidToken() { VaultConfigSource vaultConfigSource = - VaultConfigSource.builder() + new VaultConfigSource.Builder() .config(c -> c.token("zzzzzz")) .config(c -> c.address("http://invalid.host.local:8200")) .addSecretsPath("secrets/unknown/path") @@ -178,7 +178,7 @@ void shouldWorkWhenRegistryIsReloadedAndVaultIsRunning() throws InterruptedExcep ConfigRegistrySettings.builder() .addLastSource( "vault", - VaultConfigSource.builder() + new VaultConfigSource.Builder() .config(vaultConfig -> vaultConfig.address(address).token(rootToken)) .addSecretsPath(VAULT_SECRETS_PATH1) .build()) @@ -212,7 +212,7 @@ void shouldWorkWhenRegistryIsReloadedAndVaultIsDown() { ConfigRegistrySettings.builder() .addLastSource( "vault", - VaultConfigSource.builder() + new VaultConfigSource.Builder() .config(vaultConfig -> vaultConfig.address(address).token(rootToken)) .addSecretsPath(VAULT_SECRETS_PATH1) .build()) @@ -244,7 +244,7 @@ void testSealed() throws Throwable { vault.seal().seal(); assumeTrue(vault.seal().sealStatus().getSealed(), "vault seal status"); - VaultConfigSource.builder() + new VaultConfigSource.Builder() .config(c -> c.token("ROOT")) .config(c -> c.address(vaultInstance.address())) .addSecretsPath(VAULT_SECRETS_PATH1) @@ -271,7 +271,7 @@ void shouldWorkWhenRegistryIsReloadedAndVaultIsUnSealed() throws InterruptedExce ConfigRegistrySettings.builder() .addLastSource( "vault", - VaultConfigSource.builder() + new VaultConfigSource.Builder() .config(vaultConfig -> vaultConfig.address(address).token(rootToken)) .secretsPath(VAULT_SECRETS_PATH1) .build()) @@ -319,7 +319,7 @@ void testRenewableToken() throws InterruptedException { .getAuthClientToken(); VaultConfigSource vaultConfigSource = - VaultConfigSource.builder() + new VaultConfigSource.Builder() .config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken())) .config(c -> c.address(vaultContainerExtension.vaultInstance().address())) .addSecretsPath(VAULT_SECRETS_PATH1) @@ -347,7 +347,7 @@ void testNonrenewableToken() { .getAuthClientToken(); VaultConfigSource vaultConfigSource = - VaultConfigSource.builder() + new VaultConfigSource.Builder() .config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken())) .config(c -> c.address(vaultContainerExtension.vaultInstance().address())) .addSecretsPath(VAULT_SECRETS_PATH1) @@ -385,7 +385,7 @@ void testRenewableTokenWithExplicitMaxTtl() { .getAuthClientToken(); VaultConfigSource vaultConfigSource = - VaultConfigSource.builder() + new VaultConfigSource.Builder() .config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken())) .config(c -> c.address(vaultContainerExtension.vaultInstance().address())) .addSecretsPath(VAULT_SECRETS_PATH1) @@ -423,7 +423,7 @@ void testRenewableTokenWithUseLimit() { .getAuthClientToken(); VaultConfigSource vaultConfigSource = - VaultConfigSource.builder() + new VaultConfigSource.Builder() .config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken())) .config(c -> c.address(vaultContainerExtension.vaultInstance().address())) .addSecretsPath(VAULT_SECRETS_PATH1) @@ -449,7 +449,7 @@ void testRenewableTokenWithUseLimit() { @Test void testTokenSupplierGeneratesNewRenewableTokenWithExplicitMaxTtl() throws Exception { VaultConfigSource vaultConfigSource = - VaultConfigSource.builder() + new VaultConfigSource.Builder() .config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken())) .config(c -> c.address(vaultContainerExtension.vaultInstance().address())) .addSecretsPath(VAULT_SECRETS_PATH1) @@ -482,7 +482,7 @@ void testRenewableTokenWhichWillBeRevoked() { .getAuthClientToken(); VaultConfigSource vaultConfigSource = - VaultConfigSource.builder() + new VaultConfigSource.Builder() .config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken())) .config(c -> c.address(vaultContainerExtension.vaultInstance().address())) .addSecretsPath(VAULT_SECRETS_PATH1) @@ -515,7 +515,7 @@ void testRenewableTokenWhichWillBeRevoked() { void testTokenSupplierGeneratesNewRenewableTokenWhichWillBeRevoked() throws Exception { AtomicReference tokenRef = new AtomicReference<>(); VaultConfigSource vaultConfigSource = - VaultConfigSource.builder() + new VaultConfigSource.Builder() .config(c -> c.token(vaultContainerExtension.vaultInstance().rootToken())) .config(c -> c.address(vaultContainerExtension.vaultInstance().address())) .addSecretsPath(VAULT_SECRETS_PATH1) diff --git a/config-vault/src/test/java/io/scalecube/config/vault/VaultInstance.java b/config-vault/src/test/java/io/scalecube/config/vault/VaultInstance.java index cafc10c6..d74153da 100644 --- a/config-vault/src/test/java/io/scalecube/config/vault/VaultInstance.java +++ b/config-vault/src/test/java/io/scalecube/config/vault/VaultInstance.java @@ -17,8 +17,6 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Predicate; import java.util.function.UnaryOperator; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.testcontainers.DockerClientFactory; import org.testcontainers.containers.Container.ExecResult; import org.testcontainers.containers.ContainerLaunchException; @@ -30,8 +28,6 @@ public class VaultInstance implements AutoCloseable { - private static final Logger LOGGER = LoggerFactory.getLogger(VaultInstance.class); - private static final String VAULT_IMAGE_NAME = "vault:1.6.1"; private static final int VAULT_PORT = 8200; private static final AtomicInteger PORT_COUNTER = new AtomicInteger(VAULT_PORT); @@ -115,10 +111,8 @@ public AuthResponse createToken(String... options) { } public String execInContainer(String command) { - LOGGER.debug("execInContainer command: {}", command); ExecResult execResult = invoke(() -> container.execInContainer("/bin/sh", "-c", command)); assertEquals(0, execResult.getExitCode(), execResult.toString()); - LOGGER.debug("execInContainer result: {}", execResult.getStdout()); return execResult.getStdout(); } diff --git a/config/pom.xml b/config/pom.xml index 255819c4..a7d34e24 100644 --- a/config/pom.xml +++ b/config/pom.xml @@ -1,26 +1,15 @@ - + + 4.0.0 io.scalecube scalecube-config-parent 0.4.21-SNAPSHOT - 4.0.0 scalecube-config - - - org.slf4j - slf4j-api - - - - com.google.guava - guava - test - - - diff --git a/config/src/main/java/io/scalecube/config/AbstractConfigProperty.java b/config/src/main/java/io/scalecube/config/AbstractConfigProperty.java index eb0eb3d0..e2e1e182 100644 --- a/config/src/main/java/io/scalecube/config/AbstractConfigProperty.java +++ b/config/src/main/java/io/scalecube/config/AbstractConfigProperty.java @@ -1,6 +1,8 @@ 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; @@ -11,8 +13,6 @@ 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 @@ -24,10 +24,11 @@ * @param type of the property value */ abstract class AbstractConfigProperty { - private static final Logger LOGGER = LoggerFactory.getLogger(AbstractConfigProperty.class); + + private static final Logger LOGGER = System.getLogger(AbstractConfigProperty.class.getName()); private static final String ERROR_VALIDATION_FAILED = - "Validation failed on config property: '%s', failed value: %s"; + "Validation failed on config property: %s, failed value: %s"; final String name; final Class propertyClass; @@ -132,14 +133,14 @@ private void invokeCallback(BiConsumer callback, T t1, T t2) { try { callback.accept(t1, t2); } catch (Exception e) { - LOGGER.error( - "Exception occurred on property-change callback: {}, " - + "property name: '{}', oldValue: {}, newValue: {}, cause: {}", + LOGGER.log( + Level.ERROR, + "Exception occurred on property-change callback: " + + "{0}, property name: {1}, oldValue: {2}, newValue: {3}", callback, name, t1, t2, - e, e); } } @@ -154,14 +155,12 @@ private boolean isInputsEqual(List inputList1) { } Map> inputMap = - inputList - .stream() + inputList.stream() .collect( Collectors.toMap(LoadedConfigProperty::name, LoadedConfigProperty::valueAsString)); Map> inputMap1 = - inputList1 - .stream() + inputList1.stream() .collect( Collectors.toMap(LoadedConfigProperty::name, LoadedConfigProperty::valueAsString)); diff --git a/config/src/main/java/io/scalecube/config/ConfigRegistryImpl.java b/config/src/main/java/io/scalecube/config/ConfigRegistryImpl.java index 4c686dde..455c1609 100644 --- a/config/src/main/java/io/scalecube/config/ConfigRegistryImpl.java +++ b/config/src/main/java/io/scalecube/config/ConfigRegistryImpl.java @@ -6,6 +6,8 @@ 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; @@ -32,12 +34,10 @@ 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 = LoggerFactory.getLogger(ConfigRegistryImpl.class); + private static final Logger LOGGER = System.getLogger(ConfigRegistryImpl.class.getName()); static final Function STRING_PARSER = str -> str; static final Function DOUBLE_PARSER = Double::parseDouble; @@ -56,7 +56,8 @@ final class ConfigRegistryImpl implements ConfigRegistry { Thread thread = new Thread(r); thread.setDaemon(true); thread.setName("config-registry"); - thread.setUncaughtExceptionHandler((t, e) -> LOGGER.error("Exception occurred: " + e, e)); + thread.setUncaughtExceptionHandler( + (t, e) -> LOGGER.log(Level.ERROR, "Exception occurred", e)); return thread; }; reloadExecutor = Executors.newSingleThreadScheduledExecutor(threadFactory); @@ -96,7 +97,7 @@ void init() { try { loadAndNotify(); } catch (Exception e) { - LOGGER.error("[loadAndNotify] Exception occurred, cause: " + e); + LOGGER.log(Level.ERROR, "[loadAndNotify] Exception occurred, cause: {0}", e); } }, settings.getReloadIntervalSec(), @@ -489,25 +490,24 @@ private void reportChanges(Collection events) { try { eventListener.onEvents(configEvents); } catch (Exception e) { - LOGGER.error( - "Exception on configEventListener: {}, events: {}, cause: {}", + LOGGER.log( + Level.ERROR, + "Exception on configEventListener: {0}, events: {1}", key, configEvents, - e, e); } }); } - private void computeConfigLoadStatus(String sourceName, Throwable throwable) { - int status = throwable != null ? 1 : 0; + private void computeConfigLoadStatus(String sourceName, Throwable ex) { + int status = ex != null ? 1 : 0; Integer status0 = configSourceStatusMap.put(sourceName, status); if (status0 == null || (status0 ^ status) == 1) { if (status == 1) { - LOGGER.error( - "[loadConfig][{}] Exception occurred, cause: {}", sourceName, throwable.toString()); + LOGGER.log(Level.ERROR, "[loadConfig][{0}] Exception occurred", sourceName, ex); } else { - LOGGER.debug("[loadConfig][{}] Loaded config properties", sourceName); + LOGGER.log(Level.DEBUG, "[loadConfig][{0}] Loaded config properties", sourceName); } } } diff --git a/config/src/main/java/io/scalecube/config/PropertyCallback.java b/config/src/main/java/io/scalecube/config/PropertyCallback.java index d3c228c2..6dbf2133 100644 --- a/config/src/main/java/io/scalecube/config/PropertyCallback.java +++ b/config/src/main/java/io/scalecube/config/PropertyCallback.java @@ -2,13 +2,13 @@ import io.scalecube.config.audit.ConfigEvent; 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.concurrent.CopyOnWriteArraySet; import java.util.function.Function; import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Property controller class for config property instances of type {@link T}. Config property @@ -17,7 +17,8 @@ * @param type of the property value */ class PropertyCallback { - private static final Logger LOGGER = LoggerFactory.getLogger(PropertyCallback.class); + + private static final Logger LOGGER = System.getLogger(PropertyCallback.class.getName()); private static final String ERROR_EXCEPTION_ON_VALUE_PARSER = "Exception occurred at valueParser on input: %s, cause: %s"; @@ -57,12 +58,10 @@ void addConfigProperty(AbstractConfigProperty configProperty) { * ConfigEvent}-s. This method is being called from config registry reload process. * * @param events config events computed during config registry reload. - * @see ConfigRegistryImpl#loadAndNotify() */ void computeValue(List events) { List inputList = - events - .stream() + events.stream() .filter( event -> event.getType() @@ -79,17 +78,19 @@ void computeValue(List events) { try { value = applyValueParser(inputList); } catch (Exception e) { - LOGGER.error(e.getMessage(), e.getCause()); + LOGGER.log(Level.ERROR, e); return; // return right away if parser failed } - T value1 = value; // new value + T newValue = value; // new value configProperties.forEach( configProperty -> { try { - configProperty.acceptValue(value1, inputList, true /* invokeCallbacks */); + configProperty.acceptValue(newValue, inputList, true /* invokeCallbacks */); } catch (Exception e) { - LOGGER.error(String.format(ERROR_EXCEPTION_AT_ACCEPT_VALUE, inputList, value1, e)); + LOGGER.log( + Level.ERROR, + String.format(ERROR_EXCEPTION_AT_ACCEPT_VALUE, inputList, newValue, e)); } }); } diff --git a/config/src/main/java/io/scalecube/config/audit/Slf4JConfigEventListener.java b/config/src/main/java/io/scalecube/config/audit/LoggingConfigEventListener.java similarity index 88% rename from config/src/main/java/io/scalecube/config/audit/Slf4JConfigEventListener.java rename to config/src/main/java/io/scalecube/config/audit/LoggingConfigEventListener.java index 1eee36cc..27cc4372 100644 --- a/config/src/main/java/io/scalecube/config/audit/Slf4JConfigEventListener.java +++ b/config/src/main/java/io/scalecube/config/audit/LoggingConfigEventListener.java @@ -1,13 +1,14 @@ package io.scalecube.config.audit; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.Collection; import java.util.Comparator; import java.util.Objects; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -public class Slf4JConfigEventListener implements ConfigEventListener { - private static final Logger LOGGER = LoggerFactory.getLogger(Slf4JConfigEventListener.class); +public class LoggingConfigEventListener implements ConfigEventListener { + + private static final Logger LOGGER = System.getLogger(LoggingConfigEventListener.class.getName()); @Override public void onEvents(Collection events) { @@ -29,7 +30,7 @@ public void onEvents(Collection events) { sb.append(originAsString(event)); }); sb.append("\n").append("]"); - LOGGER.info(sb.toString()); + LOGGER.log(Level.INFO, sb.toString()); } } diff --git a/config/src/main/java/io/scalecube/config/keyvalue/KeyValueConfigSource.java b/config/src/main/java/io/scalecube/config/keyvalue/KeyValueConfigSource.java index a636fca0..83fb1fcc 100644 --- a/config/src/main/java/io/scalecube/config/keyvalue/KeyValueConfigSource.java +++ b/config/src/main/java/io/scalecube/config/keyvalue/KeyValueConfigSource.java @@ -5,6 +5,8 @@ import io.scalecube.config.source.ConfigSource; 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.time.Duration; import java.util.ArrayList; import java.util.Arrays; @@ -24,15 +26,14 @@ import java.util.function.Supplier; import java.util.stream.Collector; import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Generic key-value config source. Communicates with concrete config data source (mongodb, redis, * zookeeper) using injectable {@link #repository}. */ public class KeyValueConfigSource implements ConfigSource { - private static final Logger LOGGER = LoggerFactory.getLogger(KeyValueConfigSource.class); + + private static final Logger LOGGER = System.getLogger(KeyValueConfigSource.class.getName()); private static final ThreadFactory threadFactory; @@ -42,7 +43,8 @@ public class KeyValueConfigSource implements ConfigSource { Thread thread = new Thread(r); thread.setDaemon(true); thread.setName("keyvalue-config-executor"); - thread.setUncaughtExceptionHandler((t, e) -> LOGGER.error("Exception occurred: " + e, e)); + thread.setUncaughtExceptionHandler( + (t, e) -> LOGGER.log(Level.ERROR, "Exception occurred", e)); return thread; }; } @@ -64,8 +66,7 @@ private static List configureConfigNames( List result = new ArrayList<>(); result.addAll(groupList); result.add(null); // by default 'root' group is always added - return result - .stream() + return result.stream() .map(input -> new KeyValueConfigName(input, collectionName)) .collect(Collectors.toList()); } @@ -104,8 +105,7 @@ public Map loadConfig() { throw ThrowableUtil.propagate(e); } - return resultList - .stream() + return resultList.stream() .flatMap(Collection::stream) .filter(i -> !i.getDisabled()) .collect( @@ -129,8 +129,9 @@ private CompletableFuture> loadConfig(KeyValueConfigN try { result = repository.findAll(configName); } catch (Exception e) { - LOGGER.warn( - "Exception at {}.findAll({}), cause: {}", + LOGGER.log( + Level.WARNING, + "Exception at {0}.findAll({1})", repository.getClass().getSimpleName(), configName, e); diff --git a/config/src/test/java/io/scalecube/config/ObjectConfigPropertyTest.java b/config/src/test/java/io/scalecube/config/ObjectConfigPropertyTest.java index 994d5481..c3fe66e7 100644 --- a/config/src/test/java/io/scalecube/config/ObjectConfigPropertyTest.java +++ b/config/src/test/java/io/scalecube/config/ObjectConfigPropertyTest.java @@ -16,6 +16,7 @@ import static org.mockito.Mockito.when; import io.scalecube.config.source.ConfigSource; +import java.lang.System.Logger; import java.time.Duration; import java.util.HashMap; import java.util.List; @@ -30,8 +31,6 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; @ExtendWith(MockitoExtension.class) class ObjectConfigPropertyTest { @@ -532,7 +531,7 @@ public static class NotDefinedObjectPropertyConfig { } public static class ConfigClassWithStaticOrFinalField { - static final Logger LOGGER = LoggerFactory.getLogger("logger"); + static final Logger LOGGER = System.getLogger("logger"); static final ConfigClassWithStaticOrFinalField defaultInstance = new ConfigClassWithStaticOrFinalField(); diff --git a/pom.xml b/pom.xml index fda894c2..dac9118d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,11 +1,13 @@ - + 4.0.0 io.scalecube scalecube-parent - 0.2.20 + 0.3.1 scalecube-config-parent @@ -38,18 +40,19 @@ - 2.0.7 - 2.20.0 + 5.1.0 2.27.0 5.1.1 1.3 - 5.1.0 - 1.17.4 - 32.0.0-jre + 1.20.1 + 33.3.0-jre + 2.20.0 + 1.7.30 https://maven.pkg.github.com/scalecube/scalecube-config + checkstyle-suppressions.xml @@ -67,12 +70,12 @@ org.apache.logging.log4j - log4j-slf4j-impl + log4j-core ${log4j.version} org.apache.logging.log4j - log4j-core + log4j-jpl ${log4j.version} @@ -95,45 +98,69 @@ junit-jupiter-api ${junit-jupiter.version} + + org.junit.jupiter + junit-jupiter-engine + ${junit-jupiter.version} + + + org.junit.jupiter + junit-jupiter-params + ${junit-jupiter.version} + + + org.mockito + mockito-junit-jupiter + ${mockito-junit.version} + + + org.hamcrest + hamcrest-all + ${hamcrest.version} + + + com.google.guava + guava + test + org.junit.jupiter junit-jupiter-engine - ${junit-jupiter.version} test org.junit.jupiter junit-jupiter-params - ${junit-jupiter.version} test org.mockito mockito-junit-jupiter - ${mockito-junit.version} test org.hamcrest hamcrest-all - ${hamcrest.version} test org.apache.logging.log4j - log4j-slf4j-impl - ${log4j.version} + log4j-core test org.apache.logging.log4j - log4j-core - ${log4j.version} + log4j-jpl + test + + + org.testcontainers + vault test