From b755d1ddbab5a91e23d7a154a0ef936a8f595f97 Mon Sep 17 00:00:00 2001 From: Radoslav Husar Date: Wed, 15 Jan 2025 11:46:34 +0100 Subject: [PATCH 1/3] Suppress deprecation for testing legacy NATIVE_S3_PING protocol name. --- src/main/java/org/jgroups/protocols/aws/S3_PING.java | 1 + .../jgroups/protocols/aws/AbstractS3_PINGDiscoveryTestCase.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/java/org/jgroups/protocols/aws/S3_PING.java b/src/main/java/org/jgroups/protocols/aws/S3_PING.java index 0355f29..91d9668 100644 --- a/src/main/java/org/jgroups/protocols/aws/S3_PING.java +++ b/src/main/java/org/jgroups/protocols/aws/S3_PING.java @@ -99,6 +99,7 @@ public class S3_PING extends FILE_PING { + " to short. Using default magic number " + JGROUPS_PROTOCOL_DEFAULT_MAGIC_NUMBER); } } + //noinspection deprecation ClassConfigurator.addProtocol(magicNumber, NATIVE_S3_PING.class); ClassConfigurator.addProtocol(++magicNumber, S3_PING.class); } diff --git a/src/test/java/org/jgroups/protocols/aws/AbstractS3_PINGDiscoveryTestCase.java b/src/test/java/org/jgroups/protocols/aws/AbstractS3_PINGDiscoveryTestCase.java index eb90128..3f4f797 100644 --- a/src/test/java/org/jgroups/protocols/aws/AbstractS3_PINGDiscoveryTestCase.java +++ b/src/test/java/org/jgroups/protocols/aws/AbstractS3_PINGDiscoveryTestCase.java @@ -58,6 +58,7 @@ public void testDiscoveryObscureClusterName() throws Exception { /** * Test for legacy protocol name (NATIVE_S3_PING). */ + @SuppressWarnings("deprecation") @Test public void testLegacyDiscovery() throws Exception { discover(RANDOM_CLUSTER_NAME, NATIVE_S3_PING.class.getSimpleName()); From 746d7b50d9e757fe87ae0e45ad82affd803d7753 Mon Sep 17 00:00:00 2001 From: Radoslav Husar Date: Wed, 15 Jan 2025 12:23:11 +0100 Subject: [PATCH 2/3] Update README's example configuration with JGroups 5.x compatible stack #231 --- README.adoc | 58 ++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/README.adoc b/README.adoc index 711f91a..1a87add 100644 --- a/README.adoc +++ b/README.adoc @@ -16,7 +16,7 @@ The benefit is a more stable connection as well as usage of IAM server profiles org.jgroups.aws jgroups-aws - 3.0.0.Final + 3.0.1.Final ---- @@ -96,42 +96,40 @@ NOTE: System properties are supported since JGroups AWS release version 3.0.1.Fi [source,xml] ---- - - - - - - - - - - - + + + + + + + + + - - - - + + + ---- @@ -165,7 +163,7 @@ https://github.com/jgroups-extras/jgroups-aws/issues |=== |Version (branch) |JGroups version |AWS SDK -|`main` |5.2.x - 5.3.x |2.x +|`3.x` (`main`) |5.2.x - 5.3.x |2.x |`2.x` |5.2.x |1.x |`1.x` |4.2.x |1.x |=== From 580c30b713c48f5de3c97a54c5d81aaa51363f6f Mon Sep 17 00:00:00 2001 From: Radoslav Husar Date: Wed, 15 Jan 2025 13:30:34 +0100 Subject: [PATCH 3/3] Also support all S3_PING configuration options as environment variables #374; update stacks to the latest jgroups template tcp.xml stack Update tests to leverage properties instead of hard-coded values. --- README.adoc | 31 ++++++++++++------- .../org/jgroups/protocols/aws/S3_PING.java | 16 +++++----- .../aws/MockS3_PINGDiscoveryTestCase.java | 9 ++++-- .../protocols/aws/tcp-NATIVE_S3_PING.xml | 27 +++++++--------- .../org/jgroups/protocols/aws/tcp-S3_PING.xml | 27 +++++++--------- 5 files changed, 58 insertions(+), 52 deletions(-) diff --git a/README.adoc b/README.adoc index 1a87add..cd7e4f6 100644 --- a/README.adoc +++ b/README.adoc @@ -39,48 +39,57 @@ You can overwrite this by setting the system property `s3ping.magic_number` to d [align="left",cols="3,1,10",options="header"] |=== | Attribute Name + -System Property +System Property + +Environment variable | Default | Description | `region_name` + -System property: `jgroups.aws.s3.region_name` +System property: `jgroups.aws.s3.region_name` + +Environment variable: `JGROUPS_AWS_S3_REGION_NAME` | *required* | The S3 region to use. | `bucket_name` + -System property: `jgroups.aws.s3.bucket_name` +System property: `jgroups.aws.s3.bucket_name` + +Environment variable: `JGROUPS_AWS_S3_BUCKET_NAME` | *required* | The S3 bucket to use. | `bucket_prefix` + -System property: `jgroups.aws.s3.bucket_prefix` +System property: `jgroups.aws.s3.bucket_prefix` + +Environment variable: `JGROUPS_AWS_S3_BUCKET_PREFIX` | | The S3 bucket prefix to use (optional e.g. 'jgroups/'). | `check_if_bucket_exists` + -System property: `jgroups.aws.s3.check_if_bucket_exists` +System property: `jgroups.aws.s3.check_if_bucket_exists` + +Environment variable: `JGROUPS_AWS_S3_CHECK_IF_BUCKET_EXISTS` | `true` | Checks if the bucket exists in S3 and creates a new one if missing | `endpoint` + -System property: `jgroups.aws.s3.endpoint` +System property: `jgroups.aws.s3.endpoint` + +Environment variable: `JGROUPS_AWS_S3_ENDPOINT` | | The S3 endpoint to use (optional). | `path_style_access_enabled` + -System property: `jgroups.aws.s3.path_style_access_enabled` +System property: `jgroups.aws.s3.path_style_access_enabled` + +Environment variable: `JGROUPS_AWS_S3_PATH_STYLE_ACCESS_ENABLED` | `false` | The S3 path-style enable (optional). | `kms_key_id` + -System property: `jgroups.aws.s3.kms_key_id` +System property: `jgroups.aws.s3.kms_key_id` + +Environment variable: `JGROUPS_AWS_S3_KMS_KEY_ID` | | Use kms encryption with s3 with the given kms key (optionally - enables KMS Server side encryption (SSE-KMS) using the given kms key) | `acl_grant_bucket_owner_full_control` + -System property: `jgroups.aws.s3.acl_grant_bucket_owner_full_control` +System property: `jgroups.aws.s3.acl_grant_bucket_owner_full_control` + +Environment variable: `JGROUPS_AWS_S3_ACL_GRANT_BUCKET_OWNER_FULL_CONTROL` | `false` | Flag indicating whether or not to grant the bucket owner full control over the bucket on each update. This is useful in multi-region deployments where each region exists in its own AWS account. @@ -142,8 +151,8 @@ along with setting the region name and a bucket name. ---- declare -x AWS_ACCESS_KEY_ID="qF7ujVAaYUp3Tx7m" declare -x AWS_SECRET_ACCESS_KEY="WzbG3R2KGtx5rsHQUx2PKQPS2f6WzMtf" -declare -x S3_PING_REGION_NAME="eu-central-1" -declare -x S3_PING_BUCKET_NAME="jgroups" +declare -x JGROUPS_AWS_S3_REGION_NAME="eu-central-1" +declare -x JGROUPS_AWS_S3_BUCKET_NAME="jgroups" mvn verify ---- diff --git a/src/main/java/org/jgroups/protocols/aws/S3_PING.java b/src/main/java/org/jgroups/protocols/aws/S3_PING.java index 91d9668..60dfd9d 100644 --- a/src/main/java/org/jgroups/protocols/aws/S3_PING.java +++ b/src/main/java/org/jgroups/protocols/aws/S3_PING.java @@ -47,42 +47,42 @@ public class S3_PING extends FILE_PING { protected static final String MAGIC_NUMBER_SYSTEM_PROPERTY="s3ping.magic_number"; @Property(description = "The S3 path-style enable (optional).", - systemProperty = "jgroups.aws.s3.path_style_access_enabled", + systemProperty = {"jgroups.aws.s3.path_style_access_enabled", "JGROUPS_AWS_S3_PATH_STYLE_ACCESS_ENABLED"}, writable = false) protected boolean path_style_access_enabled; @Property(description = "The S3 endpoint to use (optional).", - systemProperty = "jgroups.aws.s3.endpoint", + systemProperty = {"jgroups.aws.s3.endpoint", "JGROUPS_AWS_S3_ENDPOINT"}, writable = false) protected String endpoint; @Property(description = "The S3 region to use.", - systemProperty = "jgroups.aws.s3.region_name", + systemProperty = {"jgroups.aws.s3.region_name", "JGROUPS_AWS_S3_REGION_NAME"}, writable = false) protected String region_name; @Property(description = "The S3 bucket to use.", - systemProperty = "jgroups.aws.s3.bucket_name", + systemProperty = {"jgroups.aws.s3.bucket_name", "JGROUPS_AWS_S3_BUCKET_NAME"}, writable = false) protected String bucket_name; @Property(description = "The S3 bucket prefix to use (optional e.g. 'jgroups/').", - systemProperty = "jgroups.aws.s3.bucket_prefix", + systemProperty = {"jgroups.aws.s3.bucket_prefix", "JGROUPS_AWS_S3_BUCKET_PREFIX"}, writable = false) protected String bucket_prefix; @Property(description = "Checks if the bucket exists in S3 and creates a new one if missing", - systemProperty = "jgroups.aws.s3.check_if_bucket_exists", + systemProperty = {"jgroups.aws.s3.check_if_bucket_exists", "JGROUPS_AWS_S3_CHECK_IF_BUCKET_EXISTS"}, writable = false) protected boolean check_if_bucket_exists = true; @Property(description = "Flag indicating whether or not to grant the bucket owner full control over the bucket on each update. This is useful in multi-region deployments where each region exists in its own AWS account.", - systemProperty = "jgroups.aws.s3.acl_grant_bucket_owner_full_control", + systemProperty = {"jgroups.aws.s3.acl_grant_bucket_owner_full_control", "JGROUPS_AWS_S3_ACL_GRANT_BUCKET_OWNER_FULL_CONTROL"}, writable = false) protected boolean acl_grant_bucket_owner_full_control; @Property(description = "KMS key to use for enabling KMS server-side encryption (SSE-KMS) for S3 (optional).", - systemProperty = "jgroups.aws.s3.kms_key_id", + systemProperty = {"jgroups.aws.s3.kms_key_id", "JGROUPS_AWS_S3_KMS_KEY_ID"}, exposeAsManagedAttribute = false) protected String kms_key_id; diff --git a/src/test/java/org/jgroups/protocols/aws/MockS3_PINGDiscoveryTestCase.java b/src/test/java/org/jgroups/protocols/aws/MockS3_PINGDiscoveryTestCase.java index 6c034af..2c3a483 100644 --- a/src/test/java/org/jgroups/protocols/aws/MockS3_PINGDiscoveryTestCase.java +++ b/src/test/java/org/jgroups/protocols/aws/MockS3_PINGDiscoveryTestCase.java @@ -49,13 +49,16 @@ public static void setUp() { s3Mock = new S3MockContainer("latest"); s3Mock.start(); - // TODO workaround using S3MockContainer#getHttpEndpoint() by an IP address so it doesn't rely on spoofing DNS records - System.setProperty("org.jgroups.aws.endpoint", "http://127.0.0.1:" + s3Mock.getHttpServerPort()); + // Configure the protocol - it has no hardcoded values in the stack xml file, so we can set all values using properties + // TODO workaround using S3MockContainer#getHttpsEndpoint() by an IP address so it doesn't rely on spoofing DNS records + // TODO switch to TLS + System.setProperty("jgroups.aws.s3.endpoint", "http://127.0.0.1:" + s3Mock.getHttpServerPort()); + System.setProperty("jgroups.aws.s3.region_name", "ping-testing-region"); + System.setProperty("jgroups.aws.s3.bucket_name", "ping-test-bucket"); // Setup fake credentials against the mock service System.setProperty("aws.accessKeyId", "foo"); System.setProperty("aws.secretAccessKey", "bar"); - System.setProperty("S3_PING_BUCKET_NAME", "testing-ping"); } @AfterClass diff --git a/src/test/resources/org/jgroups/protocols/aws/tcp-NATIVE_S3_PING.xml b/src/test/resources/org/jgroups/protocols/aws/tcp-NATIVE_S3_PING.xml index 0ff1e31..8ef155f 100644 --- a/src/test/resources/org/jgroups/protocols/aws/tcp-NATIVE_S3_PING.xml +++ b/src/test/resources/org/jgroups/protocols/aws/tcp-NATIVE_S3_PING.xml @@ -15,7 +15,7 @@ -->