From c9a3283be2e9f3f67f8d7c3c298af4b58284efe9 Mon Sep 17 00:00:00 2001 From: Melana Hammel <42477256+melanahammel@users.noreply.github.com> Date: Fri, 26 Mar 2021 16:07:01 -0700 Subject: [PATCH] feat: upgrade from java 7 to 8, upgrade to gradle 5.3, remove bintray (#67) --- .github/workflows/release.yml | 48 ------------------- README.md | 14 ++++++ build.gradle | 6 +-- gradle.properties | 2 +- gradle/buildscript.gradle | 2 +- gradle/dependencies.gradle | 14 ++++-- gradle/integration.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle | 8 +++- .../client/ArchaiusCerberusUrlResolver.java | 4 +- .../archaius/client/ClientVersion.java | 36 ++++++++------ .../BaseCerberusConfigurationSource.java | 14 +++--- .../provider/CerberusConfigurationSource.java | 9 ++-- ...NamespacedCerberusConfigurationSource.java | 12 ++--- .../ArchaiusCerberusClientFactoryTest.java | 2 +- .../CerberusConfigurationSourceTest.java | 21 ++++---- ...spacedCerberusConfigurationSourceTest.java | 4 +- 17 files changed, 92 insertions(+), 108 deletions(-) delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 9d46f34..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,48 +0,0 @@ -# This workflow will build a Java project with Gradle -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle - -name: Release - -on: - push: - # Sequence of patterns matched against refs/tags - tags: - - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 -jobs: - Build-and-Release: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 8 - uses: actions/setup-java@v1 - with: - java-version: 8 - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - name: Build with Gradle - run: ./gradlew assemble - - name: Test with Gradle - run: ./gradlew check - - name: Upload coverage report to CodeCov - uses: codecov/codecov-action@v1 - with: - token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos - file: ./build/reports/cobertura/coverage.xml # optional - fail_ci_if_error: true # optional (default = false) - verbose: true - - name: Release artifact to Bintray - env: - BINTRAY_USER: ${{ secrets.BINTRAY_USER }} - BINTRAY_KEY: ${{ secrets.BINTRAY_KEY}} - run: ./gradlew bintrayUpload - - name: Slack notification when release fails - if: ${{ failure() }} - uses: rtCamp/action-slack-notify@v2.1.2 - env: - SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} - SLACK_CHANNEL: cerberus-alerts - SLACK_MESSAGE: 'Cerberus release workflow has failed :build-failed:' - SLACK_ICON: https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png - SLACK_TITLE: Cerberus Archaius Client Release Failure Notification - SLACK_COLOR: '#FF0000' - SLACK_USERNAME: GitHub Actions \ No newline at end of file diff --git a/README.md b/README.md index a9b9af6..67c5e79 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,20 @@ enables dynamic runtime properties from multiple configuration sources such as U To learn more about Cerberus, please visit the [Cerberus website](http://engineering.nike.com/cerberus/). +## Publishing Notice 3/17/2021 +As of spring 2021, JFrog has decided to sunset Bintray and JCenter. +Due to this decision, we are pausing our open source publishing of the Cerberus Archaius Client. +However, we will still be updating the source code and making new GitHub releases. + +In order to build the jar yourself, run this command: +```bash +./gradlew assemble +``` + +The jar will be located in `./build/libs/`. + +For any questions or concerns, create a Github issue [here](https://github.com/Nike-Inc/cerberus-archaius-client/issues/new). + ## Quickstart ### Using the Archaius Provider diff --git a/build.gradle b/build.gradle index adc4477..3b150e6 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,6 @@ buildscript { apply plugin: 'java' apply plugin: 'maven' -apply plugin: 'com.jfrog.bintray' apply plugin: 'maven-publish' apply plugin: "com.diffplug.gradle.spotless" @@ -35,8 +34,8 @@ spotless { } } -sourceCompatibility = 1.7 -targetCompatibility = 1.7 +sourceCompatibility = 1.8 +targetCompatibility = 1.8 task copyProjectVersion() { def releaseVersion = version @@ -49,7 +48,6 @@ tasks.jar.dependsOn copyProjectVersion apply from: 'gradle/dependencies.gradle' apply from: 'gradle/check.gradle' apply from: 'gradle/integration.gradle' -apply from: 'gradle/bintray.gradle' apply from: 'gradle/owasp-dependency-check.gradle' group = groupId diff --git a/gradle.properties b/gradle.properties index 9e70a98..94901ec 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,7 +14,7 @@ # limitations under the License. # -version=7.1.4 +version=8.0.0 groupId=com.nike artifactId=cerberus-archaius-client diff --git a/gradle/buildscript.gradle b/gradle/buildscript.gradle index aa7c905..6e75244 100644 --- a/gradle/buildscript.gradle +++ b/gradle/buildscript.gradle @@ -19,7 +19,7 @@ repositories { } dependencies { - classpath "net.saliman:gradle-cobertura-plugin:2.3.0" + classpath "net.saliman:gradle-cobertura-plugin:2.6.1" classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5' classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.6.3' classpath "com.diffplug.spotless:spotless-plugin-gradle:3.30.0" diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index acd9b38..4b16765 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -16,11 +16,10 @@ repositories { jcenter() - maven { - url "https://dl.bintray.com/nike/maven" - } } +def AWS_SDK_VERSION = '1.11.+' + configurations.all { resolutionStrategy { force "ch.qos.logback:logback-core:1.2.3" @@ -42,9 +41,16 @@ configurations.all { } dependencies { + implementation('com.nike:cerberus-client'){ + version { + branch = 'master' + } + } + compile "com.amazonaws:aws-java-sdk-core:${AWS_SDK_VERSION}" compile 'com.netflix.archaius:archaius-aws:0.7.7' - compile 'com.nike:cerberus-client:7.4.0' + compile 'com.netflix.archaius:archaius-core:0.7.7' + compile 'commons-configuration:commons-configuration:1.10' compile "org.apache.commons:commons-lang3:3.11" compile "com.squareup.okhttp3:okhttp:3.9.0" diff --git a/gradle/integration.gradle b/gradle/integration.gradle index b8119b9..df20ba0 100644 --- a/gradle/integration.gradle +++ b/gradle/integration.gradle @@ -22,7 +22,7 @@ sourceSets { } task integration(type: Test, description: 'Runs integration tests') { - testClassesDir = sourceSets.integration.output.classesDir + testClassesDirs = sourceSets.integration.output.classesDirs classpath = sourceSets.integration.runtimeClasspath } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6c5a722..b88ef8a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -17,6 +17,6 @@ #Tue Aug 09 14:40:45 PDT 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.3.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle index e430f56..4a7bd43 100644 --- a/settings.gradle +++ b/settings.gradle @@ -14,4 +14,10 @@ * limitations under the License. */ -rootProject.name = artifactId \ No newline at end of file +rootProject.name = artifactId + +sourceControl { + gitRepository("https://github.com/Nike-Inc/cerberus-java-client.git") { + producesModule("com.nike:cerberus-client") + } +} \ No newline at end of file diff --git a/src/main/java/com/nike/cerberus/archaius/client/ArchaiusCerberusUrlResolver.java b/src/main/java/com/nike/cerberus/archaius/client/ArchaiusCerberusUrlResolver.java index a5f1767..b74b184 100644 --- a/src/main/java/com/nike/cerberus/archaius/client/ArchaiusCerberusUrlResolver.java +++ b/src/main/java/com/nike/cerberus/archaius/client/ArchaiusCerberusUrlResolver.java @@ -17,7 +17,7 @@ package com.nike.cerberus.archaius.client; import com.amazonaws.regions.Regions; -import javax.annotation.Nullable; +import io.github.resilience4j.core.lang.Nullable; import okhttp3.HttpUrl; import org.apache.commons.configuration.AbstractConfiguration; import org.slf4j.Logger; @@ -36,7 +36,7 @@ public class ArchaiusCerberusUrlResolver { private static final String INVALID_PROPERY_VALUE_TEMPLATE = "Could not find a valid value from the property %s"; - private final Logger logger = LoggerFactory.getLogger(getClass()); + private static final Logger logger = LoggerFactory.getLogger(ArchaiusCerberusUrlResolver.class); /** * Get a valid region name or null given a possible region name diff --git a/src/main/java/com/nike/cerberus/archaius/client/ClientVersion.java b/src/main/java/com/nike/cerberus/archaius/client/ClientVersion.java index dee7206..2f61b6c 100644 --- a/src/main/java/com/nike/cerberus/archaius/client/ClientVersion.java +++ b/src/main/java/com/nike/cerberus/archaius/client/ClientVersion.java @@ -16,6 +16,7 @@ package com.nike.cerberus.archaius.client; +import java.io.IOException; import java.io.InputStream; import java.util.Properties; import org.slf4j.Logger; @@ -36,37 +37,44 @@ public class ClientVersion { public static final String HEADER_VALUE_PREFIX = "CerberusArchaiusClient"; + public static final String UNKNOWN = "unknown"; + public static String getVersion() { - String clientVersion = "unknown"; + InputStream propsStream = null; // NOPMD try { - InputStream propsStream = - ClientVersion.class - .getClassLoader() + propsStream = + Thread.currentThread() + .getContextClassLoader() .getResourceAsStream(CLIENT_VERSION_PROPERTY_FILE); Properties properties = new Properties(); properties.load(propsStream); - - clientVersion = properties.getProperty(ARCHAIUS_CLIENT_VERSION_PROPERTY); + return properties.getProperty(ARCHAIUS_CLIENT_VERSION_PROPERTY); } catch (Exception e) { LOGGER.error("Failed to load client properties file", e); + return UNKNOWN; + } finally { + try { + if (propsStream != null) { + propsStream.close(); + } + } catch (IOException e) { + LOGGER.error("Failed to close input stream", e); + } } - - return clientVersion; } public static String getClientHeaderValue() { - - String cerberusClientHeaderValue = "unknown"; + String version = getVersion(); try { - cerberusClientHeaderValue = + String cerberusClientHeaderValue = com.nike.cerberus.client.ClientVersion.getClientHeaderValue(); + return String.format( + "%s/%s %s", HEADER_VALUE_PREFIX, version, cerberusClientHeaderValue); } catch (Exception e) { LOGGER.error("Failed to get Cerberus Client version", e); + return String.format("%s/%s %s", HEADER_VALUE_PREFIX, version, UNKNOWN); } - - return String.format( - "%s/%s %s", HEADER_VALUE_PREFIX, getVersion(), cerberusClientHeaderValue); } } diff --git a/src/main/java/com/nike/cerberus/archaius/client/provider/BaseCerberusConfigurationSource.java b/src/main/java/com/nike/cerberus/archaius/client/provider/BaseCerberusConfigurationSource.java index f2c33f1..76c2456 100644 --- a/src/main/java/com/nike/cerberus/archaius/client/provider/BaseCerberusConfigurationSource.java +++ b/src/main/java/com/nike/cerberus/archaius/client/provider/BaseCerberusConfigurationSource.java @@ -16,9 +16,10 @@ package com.nike.cerberus.archaius.client.provider; -import com.google.common.collect.Sets; import com.netflix.config.PolledConfigurationSource; import com.nike.cerberus.client.CerberusClient; +import java.util.Arrays; +import java.util.HashSet; import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,7 +31,8 @@ public abstract class BaseCerberusConfigurationSource implements PolledConfigura private final Set paths; - private final Logger logger = LoggerFactory.getLogger(getClass()); + private static final Logger logger = + LoggerFactory.getLogger(BaseCerberusConfigurationSource.class); /** * Constructor that accepts a Set<String> for paths. @@ -48,8 +50,8 @@ public BaseCerberusConfigurationSource(CerberusClient cerberusClient, Set(paths); + logger.info("paths={}", this.paths); } /** @@ -68,8 +70,8 @@ public BaseCerberusConfigurationSource(CerberusClient cerberusClient, String... throw new IllegalArgumentException("paths cannot be null or empty"); } this.cerberusClient = cerberusClient; - this.paths = Sets.newHashSet(paths); - logger.info("paths={}", getPaths()); + this.paths = new HashSet<>(Arrays.asList(paths)); + logger.info("paths={}", this.paths); } public CerberusClient getCerberusClient() { diff --git a/src/main/java/com/nike/cerberus/archaius/client/provider/CerberusConfigurationSource.java b/src/main/java/com/nike/cerberus/archaius/client/provider/CerberusConfigurationSource.java index af3ff7d..fd86c50 100644 --- a/src/main/java/com/nike/cerberus/archaius/client/provider/CerberusConfigurationSource.java +++ b/src/main/java/com/nike/cerberus/archaius/client/provider/CerberusConfigurationSource.java @@ -16,15 +16,14 @@ package com.nike.cerberus.archaius.client.provider; -import com.google.common.collect.Maps; import com.netflix.config.ConcurrentMapConfiguration; import com.netflix.config.PollResult; import com.netflix.config.PolledConfigurationSource; import com.nike.cerberus.client.CerberusClient; import com.nike.cerberus.client.model.CerberusResponse; +import java.util.HashMap; import java.util.Map; import java.util.Set; -import org.apache.commons.configuration.AbstractConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,7 +33,7 @@ */ public class CerberusConfigurationSource extends BaseCerberusConfigurationSource { - private final Logger logger = LoggerFactory.getLogger(getClass()); + private static final Logger logger = LoggerFactory.getLogger(CerberusConfigurationSource.class); /** * Constructor that accepts a Set<String> for paths. @@ -73,12 +72,12 @@ public PollResult poll(final boolean initial, final Object checkPoint) { * * @return Cerberus config */ - public AbstractConfiguration getConfig() { + public ConcurrentMapConfiguration getConfig() { return new ConcurrentMapConfiguration(getMap()); } private Map getMap() { - final Map config = Maps.newHashMap(); + final Map config = new HashMap<>(); for (final String path : getPaths()) { logger.debug("poll: reading cerberus path '{}'...", path); final CerberusResponse cerberusResponse = getCerberusClient().read(path); diff --git a/src/main/java/com/nike/cerberus/archaius/client/provider/NamespacedCerberusConfigurationSource.java b/src/main/java/com/nike/cerberus/archaius/client/provider/NamespacedCerberusConfigurationSource.java index a0e8e66..dffbe76 100644 --- a/src/main/java/com/nike/cerberus/archaius/client/provider/NamespacedCerberusConfigurationSource.java +++ b/src/main/java/com/nike/cerberus/archaius/client/provider/NamespacedCerberusConfigurationSource.java @@ -16,16 +16,15 @@ package com.nike.cerberus.archaius.client.provider; -import com.google.common.collect.Maps; import com.netflix.config.ConcurrentMapConfiguration; import com.netflix.config.PollResult; import com.netflix.config.PolledConfigurationSource; import com.nike.cerberus.client.CerberusClient; import com.nike.cerberus.client.model.CerberusListResponse; import com.nike.cerberus.client.model.CerberusResponse; +import java.util.HashMap; import java.util.Map; import java.util.Set; -import org.apache.commons.configuration.AbstractConfiguration; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,7 +41,8 @@ */ public class NamespacedCerberusConfigurationSource extends BaseCerberusConfigurationSource { - private final Logger logger = LoggerFactory.getLogger(getClass()); + private static final Logger logger = + LoggerFactory.getLogger(NamespacedCerberusConfigurationSource.class); /** * Constructor that accepts a Set<String> for paths @@ -82,7 +82,7 @@ public PollResult poll(final boolean initial, final Object checkPoint) { * * @return Cerberus config */ - public AbstractConfiguration getConfig() { + public ConcurrentMapConfiguration getConfig() { return new ConcurrentMapConfiguration(getMap()); } @@ -126,7 +126,7 @@ private String getPathPrefix(final String path) { * @return - A map containing all the properties contained under the parent path. */ private Map buildEntriesMap(final String path) { - final Map config = Maps.newHashMap(); + final Map config = new HashMap<>(); if (isFolder(path)) { final CerberusListResponse listResponse = getCerberusClient().list(path); for (final String subpath : listResponse.getKeys()) { @@ -144,7 +144,7 @@ private Map buildEntriesMap(final String path) { } private Map getMap() { - final Map config = Maps.newHashMap(); + final Map config = new HashMap<>(); for (final String path : getPaths()) { logger.debug("poll: reading cerberus path '{}'...", path); config.putAll(buildEntriesMap(path)); diff --git a/src/test/java/com/nike/cerberus/archaius/client/ArchaiusCerberusClientFactoryTest.java b/src/test/java/com/nike/cerberus/archaius/client/ArchaiusCerberusClientFactoryTest.java index 7c2f4e8..f678e12 100644 --- a/src/test/java/com/nike/cerberus/archaius/client/ArchaiusCerberusClientFactoryTest.java +++ b/src/test/java/com/nike/cerberus/archaius/client/ArchaiusCerberusClientFactoryTest.java @@ -20,9 +20,9 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import cerberus.okhttp3.HttpUrl; import com.nike.cerberus.client.CerberusClient; import com.nike.cerberus.client.CerberusClientException; +import okhttp3.HttpUrl; import org.apache.commons.configuration.AbstractConfiguration; import org.junit.Before; import org.junit.Test; diff --git a/src/test/java/com/nike/cerberus/archaius/client/provider/CerberusConfigurationSourceTest.java b/src/test/java/com/nike/cerberus/archaius/client/provider/CerberusConfigurationSourceTest.java index 153a04f..1a56c86 100644 --- a/src/test/java/com/nike/cerberus/archaius/client/provider/CerberusConfigurationSourceTest.java +++ b/src/test/java/com/nike/cerberus/archaius/client/provider/CerberusConfigurationSourceTest.java @@ -20,15 +20,11 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; import com.netflix.config.PollResult; import com.nike.cerberus.client.CerberusClient; import com.nike.cerberus.client.CerberusServerException; import com.nike.cerberus.client.model.CerberusResponse; -import java.util.Map; -import java.util.Set; +import java.util.*; import org.apache.commons.configuration.AbstractConfiguration; import org.junit.Before; import org.junit.Test; @@ -61,10 +57,10 @@ public void setup() { @Test public void poll_loads_both_paths_successfully() { // mock dependencies - final Map foobinatorMap = Maps.newHashMap(); + final Map foobinatorMap = new HashMap<>(); foobinatorMap.put(FOOBINATOR_CONFIG_KEY, FOOBINATOR_CONFIG_VALUE); - final Map artemisMap = Maps.newHashMap(); + final Map artemisMap = new HashMap<>(); artemisMap.put(ARTEMIS_CONFIG_KEY, ARTEMIS_CONFIG_VALUE); final CerberusResponse foobinatorResponse = new CerberusResponse().setData(foobinatorMap); @@ -92,13 +88,15 @@ public void poll_loads_both_paths_successfully() { @Test(expected = CerberusServerException.class) public void poll_only_loads_data_for_path1() { // mock dependencies - final Map foobinatorMap = Maps.newHashMap(); + final Map foobinatorMap = new HashMap<>(); foobinatorMap.put(FOOBINATOR_CONFIG_KEY, FOOBINATOR_CONFIG_VALUE); final CerberusResponse foobinatorResponse = new CerberusResponse().setData(foobinatorMap); when(cerberusClient.read(PATH_1)).thenReturn(foobinatorResponse); when(cerberusClient.read(PATH_2)) - .thenThrow(new CerberusServerException(500, Lists.newArrayList("Internal error."))); + .thenThrow( + new CerberusServerException( + 500, Collections.singletonList("Internal error."))); // call the method under test subject.poll(true, null); @@ -106,7 +104,8 @@ public void poll_only_loads_data_for_path1() { @Test(expected = IllegalArgumentException.class) public void test_constructor_validation_cerberus_client_cannot_be_null() { - new CerberusConfigurationSource(null, Sets.newHashSet("/fake/path")); + new CerberusConfigurationSource( + null, new HashSet<>(Collections.singletonList("/fake/path"))); } @Test(expected = IllegalArgumentException.class) @@ -116,6 +115,6 @@ public void test_constructor_validation_paths_cannot_be_null() { @Test(expected = IllegalArgumentException.class) public void test_constructor_validation_paths_cannot_be_empty() { - new CerberusConfigurationSource(cerberusClient, Sets.newHashSet()); + new CerberusConfigurationSource(cerberusClient, new HashSet<>()); } } diff --git a/src/test/java/com/nike/cerberus/archaius/client/provider/NamespacedCerberusConfigurationSourceTest.java b/src/test/java/com/nike/cerberus/archaius/client/provider/NamespacedCerberusConfigurationSourceTest.java index b4e219c..f113cfd 100644 --- a/src/test/java/com/nike/cerberus/archaius/client/provider/NamespacedCerberusConfigurationSourceTest.java +++ b/src/test/java/com/nike/cerberus/archaius/client/provider/NamespacedCerberusConfigurationSourceTest.java @@ -20,6 +20,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import com.netflix.config.ConcurrentMapConfiguration; import com.netflix.config.PollResult; import com.nike.cerberus.client.CerberusClient; import com.nike.cerberus.client.CerberusServerException; @@ -28,7 +29,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.apache.commons.configuration.AbstractConfiguration; import org.junit.Before; import org.junit.Test; @@ -101,7 +101,7 @@ public void poll_successfully_reads_all_paths() { assertThat(result.getComplete()) .containsOnlyKeys(FOOBINATOR_CONFIG_NAMESPACED_KEY, ARTEMIS_CONFIG_NAMESPACED_KEY); - AbstractConfiguration config = subject.getConfig(); + ConcurrentMapConfiguration config = subject.getConfig(); assertThat(config).isNotNull(); assertThat(config.getKeys()) .containsOnly(FOOBINATOR_CONFIG_NAMESPACED_KEY, ARTEMIS_CONFIG_NAMESPACED_KEY);