Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also support all S3_PING configuration options as environment variables #374 #399

Merged
merged 3 commits into from
Jan 16, 2025
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
89 changes: 48 additions & 41 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The benefit is a more stable connection as well as usage of IAM server profiles
<dependency>
<groupId>org.jgroups.aws</groupId>
<artifactId>jgroups-aws</artifactId>
<version>3.0.0.Final</version>
<version>3.0.1.Final</version>
</dependency>
----

Expand All @@ -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.

Expand All @@ -96,42 +105,40 @@ NOTE: System properties are supported since JGroups AWS release version 3.0.1.Fi
[source,xml]
----
<!--
Based on tcp.xml but with new aws.S3_PING.
Based on standard tcp.xml with discovery replaced with aws.S3_PING.
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:org:jgroups"
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd">
<TCP bind_port="7800"
recv_buf_size="${tcp.recv_buf_size:5M}"
send_buf_size="${tcp.send_buf_size:5M}"
max_bundle_size="64K"
thread_pool.enabled="true"
thread_pool.min_threads="2"
thread_pool.max_threads="8"
thread_pool.keep_alive_time="5000"/>

<aws.S3_PING region_name="eu-west-1"
bucket_name="jgroups-s3-test"
bucket_prefix="jgroups"/>

<MERGE3 min_interval="10000"
max_interval="30000"/>

<FD_SOCK/>
<FD_ALL timeout="30000" interval="5000"/>
<VERIFY_SUSPECT timeout="1500"/>
<pbcast.NAKACK2 use_mcast_xmit="false"
discard_delivered_msgs="true"/>

<TCP bind_addr="${jgroups.bind_addr:site_local}"
bind_port="${jgroups.bind_port:7800}"
external_addr="${jgroups.external_addr}"
external_port="${jgroups.external_port}"
thread_pool.min_threads="0"
thread_pool.max_threads="200"
thread_pool.keep_alive_time="30000"
diag.enabled="false"/>
<NON_BLOCKING_SENDS/>
<aws.S3_PING/>
<MERGE3 min_interval="10s"
max_interval="30s"/>
<FD_SOCK2/>
<FD_ALL3 timeout="40s"
interval="5s"/>
<VERIFY_SUSPECT2 timeout="1.5s"/>
<BARRIER/>
<pbcast.NAKACK2 use_mcast_xmit="false"/>
<UNICAST3/>

<pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
<pbcast.STABLE desired_avg_gossip="50s"
max_bytes="4M"/>
<pbcast.GMS print_local_addr="true" join_timeout="2000"
view_bundling="true"/>
<MFC max_credits="2M"
<pbcast.GMS print_local_addr="true"
join_timeout="2s"/>
<MFC max_credits="10M"
min_threshold="0.4"/>
<UFC max_credits="10M"
min_threshold="0.4"/>
<FRAG2 frag_size="60K"/>
<pbcast.STATE_TRANSFER/>
</config>
----

Expand All @@ -144,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
----

Expand All @@ -165,7 +172,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
|===
17 changes: 9 additions & 8 deletions src/main/java/org/jgroups/protocols/aws/S3_PING.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 12 additions & 15 deletions src/test/resources/org/jgroups/protocols/aws/tcp-NATIVE_S3_PING.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
-->

<!--
Formatted copy of the original jgroups-5.2.2.Final.jar!/tcp.xml reconfigured to use NATIVE_S3_PING and disabled diagnostics.
Formatted copy of the original jgroups-5.3.13.Final.jar!/tcp.xml reconfigured to use NATIVE_S3_PING and disabled diagnostics.
-->

<!--
Expand All @@ -36,27 +36,24 @@
thread_pool.max_threads="200"
thread_pool.keep_alive_time="30000"
diag.enabled="false"/>
<RED/>
<org.jgroups.aws.s3.NATIVE_S3_PING region_name="${S3_PING_REGION_NAME:eu-central-1}"
bucket_name="${S3_PING_BUCKET_NAME}"
endpoint="${org.jgroups.aws.endpoint}"
/>
<MERGE3 min_interval="10000"
max_interval="30000"/>
<NON_BLOCKING_SENDS/>
<org.jgroups.aws.s3.NATIVE_S3_PING/>
<MERGE3 min_interval="10s"
max_interval="30s"/>
<FD_SOCK2/>
<FD_ALL3 timeout="40000"
interval="5000"/>
<VERIFY_SUSPECT2 timeout="1500"/>
<FD_ALL3 timeout="40s"
interval="5s"/>
<VERIFY_SUSPECT2 timeout="1.5s"/>
<BARRIER/>
<pbcast.NAKACK2 use_mcast_xmit="false"/>
<UNICAST3/>
<pbcast.STABLE desired_avg_gossip="50000"
<pbcast.STABLE desired_avg_gossip="50s"
max_bytes="4M"/>
<pbcast.GMS print_local_addr="true"
join_timeout="2000"/>
<UFC max_credits="2M"
join_timeout="2s"/>
<MFC max_credits="10M"
min_threshold="0.4"/>
<MFC max_credits="2M"
<UFC max_credits="10M"
min_threshold="0.4"/>
<FRAG2 frag_size="60K"/>
<pbcast.STATE_TRANSFER/>
Expand Down
27 changes: 12 additions & 15 deletions src/test/resources/org/jgroups/protocols/aws/tcp-S3_PING.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
-->

<!--
Formatted copy of the original jgroups-5.2.2.Final.jar!/tcp.xml reconfigured to use S3_PING and disabled diagnostics.
Formatted copy of the original jgroups-5.3.13.Final.jar!/tcp.xml reconfigured to use S3_PING and disabled diagnostics.
-->

<!--
Expand All @@ -36,27 +36,24 @@
thread_pool.max_threads="200"
thread_pool.keep_alive_time="30000"
diag.enabled="false"/>
<RED/>
<aws.S3_PING region_name="${S3_PING_REGION_NAME:eu-central-1}"
bucket_name="${S3_PING_BUCKET_NAME}"
endpoint="${org.jgroups.aws.endpoint}"
/>
<MERGE3 min_interval="10000"
max_interval="30000"/>
<NON_BLOCKING_SENDS/>
<aws.S3_PING/>
<MERGE3 min_interval="10s"
max_interval="30s"/>
<FD_SOCK2/>
<FD_ALL3 timeout="40000"
interval="5000"/>
<VERIFY_SUSPECT2 timeout="1500"/>
<FD_ALL3 timeout="40s"
interval="5s"/>
<VERIFY_SUSPECT2 timeout="1.5s"/>
<BARRIER/>
<pbcast.NAKACK2 use_mcast_xmit="false"/>
<UNICAST3/>
<pbcast.STABLE desired_avg_gossip="50000"
<pbcast.STABLE desired_avg_gossip="50s"
max_bytes="4M"/>
<pbcast.GMS print_local_addr="true"
join_timeout="2000"/>
<UFC max_credits="2M"
join_timeout="2s"/>
<MFC max_credits="10M"
min_threshold="0.4"/>
<MFC max_credits="2M"
<UFC max_credits="10M"
min_threshold="0.4"/>
<FRAG2 frag_size="60K"/>
<pbcast.STATE_TRANSFER/>
Expand Down
Loading