mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
feat(globalaccelerator): add the Global Accelerator management plane (#3378)
* feat(globalaccelerator): add the Global Accelerator management plane Emulates the AWS Global Accelerator management plane over JSON 1.1 under the GlobalAccelerator_V20180706 target prefix, signing name globalaccelerator: accelerators, listeners, endpoint groups, accelerator attributes and resource tags, 22 actions in all. Global Accelerator is a global service, so ARNs carry an empty region segment and listener and endpoint group ARNs extend the accelerator ARN. Nothing is keyed by the signing region, so a caller that signs outside us-west-2 sees the same accelerators. Accelerators report DEPLOYED and endpoints HEALTHY from the first read, so SDK and Terraform waiters complete on their first poll. Enum and range members are validated against the API model, and UpdateAcceleratorAttributes rejects an update that would leave FlowLogsEnabled true with no destination bucket. * fix(globalaccelerator): enforce the list caps and HealthCheckPath format from the API model The scalar ranges were already checked against globalaccelerator/2018-08-08, but the array-count caps were not. PortRanges, EndpointConfigurations and PortOverrides each declare max 10, and IpAddresses declares max 2 for the BYOIP case. All four were unbounded. HealthCheckPath declares max 255 and the pattern ^/[-a-zA-Z0-9@:%_\+.~#?&/=]*$, which was not checked at all. The new failures reuse InvalidArgumentException and the message shape the existing scalar validations already use, so they are indistinguishable in kind from those. * test(globalaccelerator): add the SDK compatibility test Adds the globalaccelerator SDK module, a TestFixtures client factory and a GlobalAcceleratorTest that drives accelerator, listener and endpoint group lifecycles through the AWS SDK v2 client, including the new PortRanges cap. --------- Co-authored-by: lex00 <artigues.dev@gmail.com>
This commit is contained in:
1 parent
a91d7becd1
commit
2e79f5c766
26 files changed
+3084
-1
No files matched your search
@@ -233,7 +233,7 @@ Floci supports local emulation for application services, data services, eventing
|
||||
|---|---|
|
||||
| Core app services | S3, SQS, SNS, DynamoDB, Lambda, IAM, KMS, Secrets Manager, SSM |
|
||||
| Events and workflows | EventBridge, EventBridge Pipes, EventBridge Scheduler, Step Functions, SWF, CloudWatch Logs, CloudWatch Metrics, CloudWatch RUM, Managed Prometheus (AMP) |
|
||||
| API and identity | API Gateway REST, API Gateway v2, AppSync, Cognito, ACM, Route53, Route 53 Resolver, Cloud Map |
|
||||
| API and identity | API Gateway REST, API Gateway v2, AppSync, Cognito, ACM, Route53, Route 53 Resolver, Cloud Map, Global Accelerator |
|
||||
| Containers and compute | ECS, EC2, Lightsail, EKS, MWAA, ECR, EFS, CodeBuild, CodeDeploy, CodePipeline, CodeGuru Reviewer, AWS Batch, Auto Scaling, Application Auto Scaling, Elastic Beanstalk, ELB v2, ELB Classic |
|
||||
| Data, analytics, and AI | Athena, Glue, Lake Formation, EMR, EMR Serverless, Redshift, Redshift Data API, Firehose, Managed Service for Apache Flink, OpenSearch, S3 Tables, S3 Vectors, Textract, Transcribe, Comprehend, Rekognition, Translate, Bedrock Runtime, Bedrock AgentCore |
|
||||
| Databases and caching | RDS, RDS Data API, Neptune, DocumentDB, MemoryDB, ElastiCache |
|
||||
|
||||
@@ -453,6 +453,11 @@
|
||||
<groupId>software.amazon.awssdk</groupId>
|
||||
<artifactId>elasticloadbalancingv2</artifactId>
|
||||
</dependency>
|
||||
<!-- Global Accelerator client -->
|
||||
<dependency>
|
||||
<groupId>software.amazon.awssdk</groupId>
|
||||
<artifactId>globalaccelerator</artifactId>
|
||||
</dependency>
|
||||
<!-- EventBridge Scheduler client -->
|
||||
<dependency>
|
||||
<groupId>software.amazon.awssdk</groupId>
|
||||
|
||||
@@ -50,6 +50,7 @@ import software.amazon.awssdk.services.marketplacemetering.MarketplaceMeteringCl
|
||||
import software.amazon.awssdk.services.inspector2.Inspector2Client;
|
||||
import software.amazon.awssdk.services.securityhub.SecurityHubClient;
|
||||
import software.amazon.awssdk.services.detective.DetectiveClient;
|
||||
import software.amazon.awssdk.services.globalaccelerator.GlobalAcceleratorClient;
|
||||
import software.amazon.awssdk.services.rum.RumClient;
|
||||
import software.amazon.awssdk.services.resourceexplorer2.ResourceExplorer2Client;
|
||||
import software.amazon.awssdk.services.ram.RamClient;
|
||||
@@ -1314,6 +1315,14 @@ public final class TestFixtures {
|
||||
.build();
|
||||
}
|
||||
|
||||
public static GlobalAcceleratorClient globalAcceleratorClient() {
|
||||
return GlobalAcceleratorClient.builder()
|
||||
.endpointOverride(ENDPOINT)
|
||||
.region(REGION)
|
||||
.credentialsProvider(CREDENTIALS)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static EfsClient efsClient() {
|
||||
return EfsClient.builder()
|
||||
.endpointOverride(ENDPOINT)
|
||||
|
||||
+268
@@ -0,0 +1,268 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import software.amazon.awssdk.services.globalaccelerator.GlobalAcceleratorClient;
|
||||
import software.amazon.awssdk.services.globalaccelerator.model.AcceleratorNotFoundException;
|
||||
import software.amazon.awssdk.services.globalaccelerator.model.CreateAcceleratorResponse;
|
||||
import software.amazon.awssdk.services.globalaccelerator.model.CreateEndpointGroupResponse;
|
||||
import software.amazon.awssdk.services.globalaccelerator.model.CreateListenerResponse;
|
||||
import software.amazon.awssdk.services.globalaccelerator.model.DescribeAcceleratorAttributesResponse;
|
||||
import software.amazon.awssdk.services.globalaccelerator.model.DescribeAcceleratorResponse;
|
||||
import software.amazon.awssdk.services.globalaccelerator.model.DescribeEndpointGroupResponse;
|
||||
import software.amazon.awssdk.services.globalaccelerator.model.HealthState;
|
||||
import software.amazon.awssdk.services.globalaccelerator.model.InvalidArgumentException;
|
||||
import software.amazon.awssdk.services.globalaccelerator.model.IpAddressType;
|
||||
import software.amazon.awssdk.services.globalaccelerator.model.ListAcceleratorsRequest;
|
||||
import software.amazon.awssdk.services.globalaccelerator.model.ListAcceleratorsResponse;
|
||||
import software.amazon.awssdk.services.globalaccelerator.model.ListEndpointGroupsResponse;
|
||||
import software.amazon.awssdk.services.globalaccelerator.model.ListListenersResponse;
|
||||
import software.amazon.awssdk.services.globalaccelerator.model.ListTagsForResourceResponse;
|
||||
import software.amazon.awssdk.services.globalaccelerator.model.PortRange;
|
||||
import software.amazon.awssdk.services.globalaccelerator.model.Protocol;
|
||||
import software.amazon.awssdk.services.globalaccelerator.model.Tag;
|
||||
import software.amazon.awssdk.services.globalaccelerator.model.UpdateAcceleratorAttributesResponse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
@DisplayName("Global Accelerator")
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class GlobalAcceleratorTest {
|
||||
|
||||
private static GlobalAcceleratorClient globalAccelerator;
|
||||
private static String acceleratorName;
|
||||
private static String acceleratorArn;
|
||||
private static String listenerArn;
|
||||
private static String endpointGroupArn;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
globalAccelerator = TestFixtures.globalAcceleratorClient();
|
||||
acceleratorName = "sdk-test-accelerator-" + System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
if (globalAccelerator == null) {
|
||||
return;
|
||||
}
|
||||
if (acceleratorArn != null) {
|
||||
try {
|
||||
globalAccelerator.updateAccelerator(r -> r.acceleratorArn(acceleratorArn).enabled(false));
|
||||
globalAccelerator.deleteAccelerator(r -> r.acceleratorArn(acceleratorArn));
|
||||
} catch (RuntimeException e) {
|
||||
System.out.println("Global Accelerator cleanup skipped: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
globalAccelerator.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createAccelerator() {
|
||||
CreateAcceleratorResponse response = globalAccelerator.createAccelerator(r -> r
|
||||
.name(acceleratorName)
|
||||
.ipAddressType(IpAddressType.IPV4)
|
||||
.enabled(true)
|
||||
.tags(Tag.builder().key("team").value("platform").build()));
|
||||
|
||||
acceleratorArn = response.accelerator().acceleratorArn();
|
||||
|
||||
assertThat(acceleratorArn).contains(":globalaccelerator::").contains(":accelerator/");
|
||||
assertThat(response.accelerator().name()).isEqualTo(acceleratorName);
|
||||
assertThat(response.accelerator().enabled()).isTrue();
|
||||
assertThat(response.accelerator().dnsName()).endsWith(".awsglobalaccelerator.com");
|
||||
assertThat(response.accelerator().ipSets()).hasSize(1);
|
||||
assertThat(response.accelerator().ipSets().get(0).ipAddresses()).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void describeAcceleratorReportsDeployed() {
|
||||
DescribeAcceleratorResponse response = globalAccelerator.describeAccelerator(r -> r
|
||||
.acceleratorArn(acceleratorArn));
|
||||
|
||||
// The SDK and Terraform waiters poll until DEPLOYED, so the first read must already say so.
|
||||
assertThat(response.accelerator().status().toString()).isEqualTo("DEPLOYED");
|
||||
assertThat(response.accelerator().createdTime()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void listAcceleratorsIncludesTheNewAccelerator() {
|
||||
ListAcceleratorsResponse response = globalAccelerator.listAccelerators(ListAcceleratorsRequest.builder().build());
|
||||
|
||||
assertThat(response.accelerators())
|
||||
.anySatisfy(a -> assertThat(a.acceleratorArn()).isEqualTo(acceleratorArn));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void acceleratorAttributesRoundTrip() {
|
||||
UpdateAcceleratorAttributesResponse updated = globalAccelerator.updateAcceleratorAttributes(r -> r
|
||||
.acceleratorArn(acceleratorArn)
|
||||
.flowLogsEnabled(true)
|
||||
.flowLogsS3Bucket("floci-flow-logs")
|
||||
.flowLogsS3Prefix("globalaccelerator/"));
|
||||
|
||||
assertThat(updated.acceleratorAttributes().flowLogsEnabled()).isTrue();
|
||||
|
||||
DescribeAcceleratorAttributesResponse described = globalAccelerator.describeAcceleratorAttributes(r -> r
|
||||
.acceleratorArn(acceleratorArn));
|
||||
|
||||
assertThat(described.acceleratorAttributes().flowLogsS3Bucket()).isEqualTo("floci-flow-logs");
|
||||
assertThat(described.acceleratorAttributes().flowLogsS3Prefix()).isEqualTo("globalaccelerator/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void createListener() {
|
||||
CreateListenerResponse response = globalAccelerator.createListener(r -> r
|
||||
.acceleratorArn(acceleratorArn)
|
||||
.protocol(Protocol.TCP)
|
||||
.clientAffinity("SOURCE_IP")
|
||||
.portRanges(PortRange.builder().fromPort(80).toPort(80).build(),
|
||||
PortRange.builder().fromPort(443).toPort(443).build()));
|
||||
|
||||
listenerArn = response.listener().listenerArn();
|
||||
|
||||
assertThat(listenerArn).startsWith(acceleratorArn + "/listener/");
|
||||
assertThat(response.listener().protocol()).isEqualTo(Protocol.TCP);
|
||||
assertThat(response.listener().portRanges()).hasSize(2);
|
||||
|
||||
ListListenersResponse listed = globalAccelerator.listListeners(r -> r.acceleratorArn(acceleratorArn));
|
||||
assertThat(listed.listeners())
|
||||
.anySatisfy(l -> assertThat(l.listenerArn()).isEqualTo(listenerArn));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void createEndpointGroup() {
|
||||
CreateEndpointGroupResponse response = globalAccelerator.createEndpointGroup(r -> r
|
||||
.listenerArn(listenerArn)
|
||||
.endpointGroupRegion("us-west-2")
|
||||
.trafficDialPercentage(80.0f)
|
||||
.healthCheckProtocol("HTTP")
|
||||
.healthCheckPath("/health")
|
||||
.healthCheckIntervalSeconds(30)
|
||||
.thresholdCount(3)
|
||||
.endpointConfigurations(c -> c.endpointId("i-0123456789abcdef0").weight(128)));
|
||||
|
||||
endpointGroupArn = response.endpointGroup().endpointGroupArn();
|
||||
|
||||
assertThat(endpointGroupArn).startsWith(listenerArn + "/endpoint-group/");
|
||||
assertThat(response.endpointGroup().endpointGroupRegion()).isEqualTo("us-west-2");
|
||||
assertThat(response.endpointGroup().healthCheckPath()).isEqualTo("/health");
|
||||
assertThat(response.endpointGroup().trafficDialPercentage()).isEqualTo(80.0f);
|
||||
assertThat(response.endpointGroup().endpointDescriptions()).hasSize(1);
|
||||
assertThat(response.endpointGroup().endpointDescriptions().get(0).healthState())
|
||||
.isEqualTo(HealthState.HEALTHY);
|
||||
|
||||
ListEndpointGroupsResponse listed = globalAccelerator.listEndpointGroups(r -> r.listenerArn(listenerArn));
|
||||
assertThat(listed.endpointGroups())
|
||||
.anySatisfy(g -> assertThat(g.endpointGroupArn()).isEqualTo(endpointGroupArn));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void addAndRemoveEndpoints() {
|
||||
globalAccelerator.addEndpoints(r -> r
|
||||
.endpointGroupArn(endpointGroupArn)
|
||||
.endpointConfigurations(c -> c.endpointId("i-00000000000000002").weight(32)));
|
||||
|
||||
DescribeEndpointGroupResponse described = globalAccelerator.describeEndpointGroup(r -> r
|
||||
.endpointGroupArn(endpointGroupArn));
|
||||
|
||||
assertThat(described.endpointGroup().endpointDescriptions())
|
||||
.anySatisfy(e -> assertThat(e.endpointId()).isEqualTo("i-00000000000000002"));
|
||||
|
||||
globalAccelerator.removeEndpoints(r -> r
|
||||
.endpointGroupArn(endpointGroupArn)
|
||||
.endpointIdentifiers(i -> i.endpointId("i-00000000000000002")));
|
||||
|
||||
assertThat(globalAccelerator.describeEndpointGroup(r -> r.endpointGroupArn(endpointGroupArn))
|
||||
.endpointGroup().endpointDescriptions())
|
||||
.noneSatisfy(e -> assertThat(e.endpointId()).isEqualTo("i-00000000000000002"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void updateEndpointGroupHealthCheck() {
|
||||
globalAccelerator.updateEndpointGroup(r -> r
|
||||
.endpointGroupArn(endpointGroupArn)
|
||||
.healthCheckPath("/ready")
|
||||
.thresholdCount(5));
|
||||
|
||||
assertThat(globalAccelerator.describeEndpointGroup(r -> r.endpointGroupArn(endpointGroupArn))
|
||||
.endpointGroup())
|
||||
.satisfies(group -> {
|
||||
assertThat(group.healthCheckPath()).isEqualTo("/ready");
|
||||
assertThat(group.thresholdCount()).isEqualTo(5);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void tagResourceRoundTrip() {
|
||||
globalAccelerator.tagResource(r -> r
|
||||
.resourceArn(acceleratorArn)
|
||||
.tags(Tag.builder().key("env").value("test").build()));
|
||||
|
||||
ListTagsForResourceResponse tagged = globalAccelerator.listTagsForResource(r -> r
|
||||
.resourceArn(acceleratorArn));
|
||||
|
||||
assertThat(tagged.tags()).anySatisfy(tag -> {
|
||||
assertThat(tag.key()).isEqualTo("env");
|
||||
assertThat(tag.value()).isEqualTo("test");
|
||||
});
|
||||
|
||||
globalAccelerator.untagResource(r -> r.resourceArn(acceleratorArn).tagKeys("env"));
|
||||
|
||||
assertThat(globalAccelerator.listTagsForResource(r -> r.resourceArn(acceleratorArn)).tags())
|
||||
.noneSatisfy(tag -> assertThat(tag.key()).isEqualTo("env"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void listenerRejectsMoreThanTenPortRanges() {
|
||||
List<PortRange> portRanges = new ArrayList<>();
|
||||
for (int i = 0; i < 11; i++) {
|
||||
portRanges.add(PortRange.builder().fromPort(1000 + i).toPort(1000 + i).build());
|
||||
}
|
||||
|
||||
assertThatThrownBy(() -> globalAccelerator.createListener(r -> r
|
||||
.acceleratorArn(acceleratorArn)
|
||||
.protocol(Protocol.TCP)
|
||||
.portRanges(portRanges)))
|
||||
.isInstanceOf(InvalidArgumentException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void deleteTheAcceleratorAndItsChildren() {
|
||||
globalAccelerator.deleteEndpointGroup(r -> r.endpointGroupArn(endpointGroupArn));
|
||||
endpointGroupArn = null;
|
||||
|
||||
globalAccelerator.deleteListener(r -> r.listenerArn(listenerArn));
|
||||
listenerArn = null;
|
||||
|
||||
// AWS refuses to delete an enabled accelerator, so the provider disables it first.
|
||||
globalAccelerator.updateAccelerator(r -> r.acceleratorArn(acceleratorArn).enabled(false));
|
||||
globalAccelerator.deleteAccelerator(r -> r.acceleratorArn(acceleratorArn));
|
||||
|
||||
String deleted = acceleratorArn;
|
||||
acceleratorArn = null;
|
||||
|
||||
assertThatThrownBy(() -> globalAccelerator.describeAccelerator(r -> r.acceleratorArn(deleted)))
|
||||
.isInstanceOf(AcceleratorNotFoundException.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
# AWS Global Accelerator
|
||||
|
||||
**Protocol:** JSON 1.1 (`X-Amz-Target: GlobalAccelerator_V20180706.<Action>`)
|
||||
**Endpoint:** `http://localhost:4566/` (SigV4 service `globalaccelerator`)
|
||||
|
||||
Floci emulates the Global Accelerator management plane: standard accelerators, listeners,
|
||||
endpoint groups, accelerator attributes and resource tags. The anycast data plane is not
|
||||
emulated, so the static IP addresses and DNS names Floci hands out route no traffic.
|
||||
|
||||
## Supported Actions
|
||||
|
||||
<!-- floci:actions:start -->
|
||||
| Action | Description |
|
||||
| --- | --- |
|
||||
| `CreateAccelerator` | Create a standard accelerator; it reports `DEPLOYED` immediately |
|
||||
| `DescribeAccelerator` | Read an accelerator with its static IP sets and DNS name |
|
||||
| `UpdateAccelerator` | Rename an accelerator, enable or disable it, or change its IP address type |
|
||||
| `DeleteAccelerator` | Delete a disabled accelerator that has no listeners |
|
||||
| `ListAccelerators` | List every accelerator in the calling account |
|
||||
| `DescribeAcceleratorAttributes` | Read an accelerator's flow log attributes |
|
||||
| `UpdateAcceleratorAttributes` | Set an accelerator's flow log attributes |
|
||||
| `CreateListener` | Create a TCP or UDP listener on an accelerator |
|
||||
| `DescribeListener` | Read a listener |
|
||||
| `UpdateListener` | Change a listener's port ranges, protocol or client affinity |
|
||||
| `DeleteListener` | Delete a listener that has no endpoint groups |
|
||||
| `ListListeners` | List an accelerator's listeners |
|
||||
| `CreateEndpointGroup` | Create one Region's endpoint group on a listener |
|
||||
| `DescribeEndpointGroup` | Read an endpoint group and its endpoint health |
|
||||
| `UpdateEndpointGroup` | Replace an endpoint group's endpoints or change its health check settings |
|
||||
| `DeleteEndpointGroup` | Delete an endpoint group |
|
||||
| `ListEndpointGroups` | List a listener's endpoint groups |
|
||||
| `AddEndpoints` | Add endpoints to an endpoint group |
|
||||
| `RemoveEndpoints` | Remove endpoints from an endpoint group |
|
||||
| `TagResource` | Tag an accelerator, listener or endpoint group |
|
||||
| `UntagResource` | Remove tags from an accelerator, listener or endpoint group |
|
||||
| `ListTagsForResource` | List the tags on an accelerator, listener or endpoint group |
|
||||
<!-- floci:actions:end -->
|
||||
|
||||
## ARNs and Regions
|
||||
|
||||
Global Accelerator is a global service, so its ARNs carry an empty region segment and child
|
||||
ARNs extend the parent:
|
||||
|
||||
```
|
||||
arn:aws:globalaccelerator::000000000000:accelerator/{acceleratorId}
|
||||
arn:aws:globalaccelerator::000000000000:accelerator/{acceleratorId}/listener/{listenerId}
|
||||
arn:aws:globalaccelerator::000000000000:accelerator/{acceleratorId}/listener/{listenerId}/endpoint-group/{groupId}
|
||||
```
|
||||
|
||||
`ListListeners` and `ListEndpointGroups` are scoped by that ARN prefix, which is why a
|
||||
listener created under one accelerator is never visible under another.
|
||||
|
||||
The AWS SDK homes the service in `us-west-2` and signs there. Nothing in Floci is keyed by
|
||||
the signing region, so a caller that signs under a different Region sees the same
|
||||
accelerators. Only the account partitions the state. `EndpointGroupRegion` is stored as
|
||||
given and is unrelated to the signing region.
|
||||
|
||||
## State and Health
|
||||
|
||||
`Accelerator.Status` is `DEPLOYED` and every `EndpointDescription.HealthState` is `HEALTHY`
|
||||
from the first read, so SDK and Terraform waiters complete on their first poll. No state
|
||||
transition is modelled.
|
||||
|
||||
Each accelerator is assigned two static IPv4 addresses from the ranges Global Accelerator
|
||||
advertises, exposed in `IpSets`, plus a `DnsName` of the documented form
|
||||
`a{16 hex}.awsglobalaccelerator.com`. A `DUAL_STACK` accelerator additionally carries an IPv6
|
||||
`IpSet` and a `DualStackDnsName`. Passing `IpAddresses` on `CreateAccelerator` (the BYOIP
|
||||
case) pins those addresses instead.
|
||||
|
||||
## Constraints
|
||||
|
||||
- **DeleteAccelerator** returns `AcceleratorNotDisabledException` while `Enabled` is true, and
|
||||
`AssociatedListenerFoundException` while the accelerator still has listeners. Terraform
|
||||
disables the accelerator before deleting it, which is the documented order.
|
||||
- **DeleteListener** returns `AssociatedEndpointGroupFoundException` while the listener still
|
||||
has endpoint groups.
|
||||
- **CreateEndpointGroup** returns `EndpointGroupAlreadyExistsException` when the listener
|
||||
already has an endpoint group in that Region. A listener has at most one group per Region.
|
||||
- **CreateListener** and **UpdateListener** return `InvalidPortRangeException` for a port
|
||||
range outside 1 to 65535 or with `FromPort` greater than `ToPort`.
|
||||
- **UpdateAcceleratorAttributes** returns `InvalidArgumentException` when the update would
|
||||
leave `FlowLogsEnabled` true with no `FlowLogsS3Bucket`.
|
||||
- Enum and range members are validated against the API model: `IpAddressType`, `Protocol`,
|
||||
`ClientAffinity`, `HealthCheckProtocol`, `TrafficDialPercentage` (0 to 100),
|
||||
`HealthCheckIntervalSeconds` (10 to 30), `ThresholdCount` (1 to 10) and `Weight` (0 to 255).
|
||||
A value outside its range returns `InvalidArgumentException`.
|
||||
- List members are capped at the maximums the API model declares. `PortRanges`,
|
||||
`EndpointConfigurations` and `PortOverrides` accept at most 10 entries per request, and
|
||||
`IpAddresses` at most 2. A longer list returns `InvalidArgumentException`.
|
||||
- `HealthCheckPath` must match the model's pattern. It begins with `/`, is at most 255
|
||||
characters, and carries only URL path characters. Anything else returns
|
||||
`InvalidArgumentException`.
|
||||
|
||||
## Defaults
|
||||
|
||||
| Field | Default |
|
||||
|---|---|
|
||||
| `Accelerator.Enabled` | `true` |
|
||||
| `Accelerator.IpAddressType` | `IPV4` |
|
||||
| `Listener.ClientAffinity` | `NONE` |
|
||||
| `EndpointGroup.TrafficDialPercentage` | `100.0` |
|
||||
| `EndpointGroup.HealthCheckPort` | the listener's first `FromPort` |
|
||||
| `EndpointGroup.HealthCheckProtocol` | `TCP` |
|
||||
| `EndpointGroup.HealthCheckPath` | `/` |
|
||||
| `EndpointGroup.HealthCheckIntervalSeconds` | `30` |
|
||||
| `EndpointGroup.ThresholdCount` | `3` |
|
||||
| `EndpointConfiguration.Weight` | `128` |
|
||||
| `EndpointConfiguration.ClientIPPreservationEnabled` | `true` for an Application Load Balancer endpoint, `false` otherwise |
|
||||
|
||||
## Configuration
|
||||
|
||||
| Variable | Default | Description |
|
||||
|---|---|---|
|
||||
| `FLOCI_SERVICES_GLOBALACCELERATOR_ENABLED` | `true` | Enable or disable the service |
|
||||
|
||||
## Not Yet Supported
|
||||
|
||||
These operations return `UnknownOperationException` rather than a stub success:
|
||||
|
||||
- Custom routing accelerators (`CreateCustomRoutingAccelerator`, `CreateCustomRoutingListener`,
|
||||
`CreateCustomRoutingEndpointGroup`, `AddCustomRoutingEndpoints`, `AllowCustomRoutingTraffic`,
|
||||
`ListCustomRoutingPortMappings`, and the rest of that family)
|
||||
- BYOIP address pools (`ProvisionByoipCidr`, `AdvertiseByoipCidr`, `DeprovisionByoipCidr`,
|
||||
`WithdrawByoipCidr`, `ListByoipCidrs`). `CreateAccelerator` still honours an `IpAddresses`
|
||||
list, so a BYOIP address can be pinned without provisioning a pool.
|
||||
- Cross-account attachments (`CreateCrossAccountAttachment` and friends)
|
||||
|
||||
Two more gaps are worth calling out:
|
||||
|
||||
- `IdempotencyToken` is accepted but not deduplicated, so repeating a create produces a
|
||||
second resource.
|
||||
- The list operations ignore `MaxResults` and return every resource in one page with no
|
||||
`NextToken`. A paginator terminates after the first call.
|
||||
- `AddEndpoints` returns the endpoint group's whole endpoint list rather than only the
|
||||
endpoints the call added.
|
||||
|
||||
## Examples
|
||||
|
||||
```bash
|
||||
export AWS_ENDPOINT_URL=http://localhost:4566
|
||||
|
||||
aws globalaccelerator create-accelerator --name edge-accelerator
|
||||
|
||||
aws globalaccelerator create-listener \
|
||||
--accelerator-arn arn:aws:globalaccelerator::000000000000:accelerator/... \
|
||||
--protocol TCP \
|
||||
--port-ranges FromPort=80,ToPort=80
|
||||
|
||||
aws globalaccelerator create-endpoint-group \
|
||||
--listener-arn arn:aws:globalaccelerator::000000000000:accelerator/.../listener/... \
|
||||
--endpoint-group-region us-west-2 \
|
||||
--endpoint-configurations EndpointId=i-0123456789abcdef0,Weight=128
|
||||
|
||||
aws globalaccelerator list-tags-for-resource \
|
||||
--resource-arn arn:aws:globalaccelerator::000000000000:accelerator/...
|
||||
```
|
||||
@@ -28,6 +28,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac
|
||||
| [Organizations](organizations.md) | `POST /` + `X-Amz-Target: AWSOrganizationsV20161128.*` | JSON 1.1 | 55 |
|
||||
| [Cognito](cognito.md) | `POST /` + `X-Amz-Target: AWSCognitoIdentityProviderService.*` | JSON 1.1 | 43 |
|
||||
| [Cognito Identity](cognitoidentity.md) | `POST /` + `X-Amz-Target: AWSCognitoIdentityService.*` | JSON 1.1 | 13 |
|
||||
| [Global Accelerator](globalaccelerator.md) | `POST /` + `X-Amz-Target: GlobalAccelerator_V20180706.*` | JSON 1.1 | 22 |
|
||||
| [KMS](kms.md) | `POST /` + `X-Amz-Target: TrentService.*` | JSON 1.1 | 34 |
|
||||
| [CloudHSM v2](cloudhsmv2.md) | `POST /` + `X-Amz-Target: BaldrApiService.*` | JSON 1.1 | 18 |
|
||||
| [Kinesis](kinesis.md) | `POST /` + `X-Amz-Target: Kinesis_20131202.*` | JSON 1.1 | 24 |
|
||||
|
||||
@@ -107,6 +107,7 @@ nav:
|
||||
- API Gateway: services/api-gateway.md
|
||||
- Cognito: services/cognito.md
|
||||
- Cognito Identity: services/cognitoidentity.md
|
||||
- Global Accelerator: services/globalaccelerator.md
|
||||
- KMS: services/kms.md
|
||||
- CloudHSM v2: services/cloudhsmv2.md
|
||||
- Kinesis: services/kinesis.md
|
||||
|
||||
@@ -740,6 +740,7 @@ public interface EmulatorConfig {
|
||||
ControlTowerServiceConfig controltower();
|
||||
ConnectServiceConfig connect();
|
||||
CognitoIdentityServiceConfig cognitoidentity();
|
||||
GlobalAcceleratorServiceConfig globalaccelerator();
|
||||
|
||||
ApsServiceConfig aps();
|
||||
|
||||
@@ -759,6 +760,11 @@ public interface EmulatorConfig {
|
||||
boolean enabled();
|
||||
}
|
||||
|
||||
interface GlobalAcceleratorServiceConfig {
|
||||
@WithDefault("true")
|
||||
boolean enabled();
|
||||
}
|
||||
|
||||
interface SsoAdminServiceConfig {
|
||||
@WithDefault("true")
|
||||
boolean enabled();
|
||||
|
||||
@@ -51,6 +51,7 @@ import io.github.hectorvent.floci.services.kms.KmsJsonHandler;
|
||||
import io.github.hectorvent.floci.services.secretsmanager.SecretsManagerJsonHandler;
|
||||
import io.github.hectorvent.floci.services.organizations.OrganizationsJsonHandler;
|
||||
import io.github.hectorvent.floci.services.cognitoidentity.CognitoIdentityJsonHandler;
|
||||
import io.github.hectorvent.floci.services.globalaccelerator.GlobalAcceleratorJsonHandler;
|
||||
import io.github.hectorvent.floci.services.route53resolver.Route53ResolverJsonHandler;
|
||||
import io.github.hectorvent.floci.services.networkfirewall.NetworkFirewallJsonHandler;
|
||||
import io.github.hectorvent.floci.services.servicecatalog.ServiceCatalogJsonHandler;
|
||||
@@ -123,6 +124,7 @@ public class AwsJson11Controller {
|
||||
private final LightsailJsonHandler lightsailJsonHandler;
|
||||
private final Route53ResolverJsonHandler route53ResolverJsonHandler;
|
||||
private final CognitoIdentityJsonHandler cognitoIdentityJsonHandler;
|
||||
private final GlobalAcceleratorJsonHandler globalAcceleratorJsonHandler;
|
||||
private final NetworkFirewallJsonHandler networkFirewallJsonHandler;
|
||||
private final ServiceCatalogJsonHandler serviceCatalogJsonHandler;
|
||||
private final CloudControlJsonHandler cloudControlJsonHandler;
|
||||
@@ -175,6 +177,7 @@ public class AwsJson11Controller {
|
||||
LightsailJsonHandler lightsailJsonHandler,
|
||||
Route53ResolverJsonHandler route53ResolverJsonHandler,
|
||||
CognitoIdentityJsonHandler cognitoIdentityJsonHandler,
|
||||
GlobalAcceleratorJsonHandler globalAcceleratorJsonHandler,
|
||||
NetworkFirewallJsonHandler networkFirewallJsonHandler,
|
||||
ServiceCatalogJsonHandler serviceCatalogJsonHandler,
|
||||
CloudControlJsonHandler cloudControlJsonHandler,
|
||||
@@ -231,6 +234,7 @@ public class AwsJson11Controller {
|
||||
this.lightsailJsonHandler = lightsailJsonHandler;
|
||||
this.route53ResolverJsonHandler = route53ResolverJsonHandler;
|
||||
this.cognitoIdentityJsonHandler = cognitoIdentityJsonHandler;
|
||||
this.globalAcceleratorJsonHandler = globalAcceleratorJsonHandler;
|
||||
this.networkFirewallJsonHandler = networkFirewallJsonHandler;
|
||||
this.serviceCatalogJsonHandler = serviceCatalogJsonHandler;
|
||||
this.cloudControlJsonHandler = cloudControlJsonHandler;
|
||||
@@ -319,6 +323,10 @@ public class AwsJson11Controller {
|
||||
case "lightsail" -> lightsailJsonHandler.handle(action, request, region);
|
||||
case "route53resolver" -> route53ResolverJsonHandler.handle(action, request, region, regionResolver.getAccountId());
|
||||
case "cognito-identity" -> cognitoIdentityJsonHandler.handle(action, request, region);
|
||||
// Global Accelerator is a global service: its resources carry an empty ARN region
|
||||
// segment and are never partitioned by the region the caller signed with, so the
|
||||
// handler takes no region.
|
||||
case "globalaccelerator" -> globalAcceleratorJsonHandler.handle(action, request);
|
||||
case "network-firewall" -> networkFirewallJsonHandler.handle(
|
||||
action, request, region, regionResolver.getAccountId());
|
||||
case "servicecatalog" -> serviceCatalogJsonHandler.handle(
|
||||
|
||||
@@ -612,6 +612,11 @@ public class ResolvedServiceCatalog {
|
||||
"cognitoidentity", config.storage().mode(), 5000L, null, ServiceProtocol.JSON,
|
||||
protocols(ServiceProtocol.JSON),
|
||||
Set.of("AWSCognitoIdentityService."), Set.of("cognito-identity"), Set.of(), Set.of()),
|
||||
descriptor("globalaccelerator", "globalaccelerator",
|
||||
config.services().globalaccelerator().enabled(), true,
|
||||
"globalaccelerator", config.storage().mode(), 5000L, null, ServiceProtocol.JSON,
|
||||
protocols(ServiceProtocol.JSON),
|
||||
Set.of("GlobalAccelerator_V20180706."), Set.of("globalaccelerator"), Set.of(), Set.of()),
|
||||
descriptor("network-firewall", "networkfirewall", config.services().networkfirewall().enabled(), true,
|
||||
"networkfirewall", config.storage().mode(), 5000L, null, ServiceProtocol.JSON,
|
||||
protocols(ServiceProtocol.JSON),
|
||||
|
||||
+229
@@ -0,0 +1,229 @@
|
||||
package io.github.hectorvent.floci.services.globalaccelerator;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.services.globalaccelerator.model.EndpointGroup;
|
||||
import io.github.hectorvent.floci.services.globalaccelerator.model.PortOverride;
|
||||
import io.github.hectorvent.floci.services.globalaccelerator.model.PortRange;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Global Accelerator management plane, JSON 1.1 under the
|
||||
* {@code GlobalAccelerator_V20180706} target prefix.
|
||||
*
|
||||
* <p>An operation that is not implemented falls through to {@code UnknownOperationException}
|
||||
* rather than a stub success, so a caller fails fast instead of stranding a waiter.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class GlobalAcceleratorJsonHandler {
|
||||
|
||||
private final GlobalAcceleratorService service;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
@Inject
|
||||
public GlobalAcceleratorJsonHandler(GlobalAcceleratorService service, ObjectMapper mapper) {
|
||||
this.service = service;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
public Response handle(String action, JsonNode request) {
|
||||
return switch (action) {
|
||||
case "CreateAccelerator" -> Response.ok(Map.of("Accelerator", service.createAccelerator(
|
||||
text(request, "Name"),
|
||||
text(request, "IpAddressType"),
|
||||
stringList(request.path("IpAddresses")),
|
||||
bool(request, "Enabled"),
|
||||
tagMap(request.path("Tags"))))).build();
|
||||
case "DescribeAccelerator" -> Response.ok(Map.of("Accelerator",
|
||||
service.describeAccelerator(text(request, "AcceleratorArn")))).build();
|
||||
case "UpdateAccelerator" -> Response.ok(Map.of("Accelerator", service.updateAccelerator(
|
||||
text(request, "AcceleratorArn"),
|
||||
text(request, "Name"),
|
||||
text(request, "IpAddressType"),
|
||||
stringList(request.path("IpAddresses")),
|
||||
bool(request, "Enabled")))).build();
|
||||
case "DeleteAccelerator" -> {
|
||||
service.deleteAccelerator(text(request, "AcceleratorArn"));
|
||||
yield Response.ok(Map.of()).build();
|
||||
}
|
||||
case "ListAccelerators" -> Response.ok(Map.of("Accelerators", service.listAccelerators())).build();
|
||||
case "DescribeAcceleratorAttributes" -> Response.ok(Map.of("AcceleratorAttributes",
|
||||
service.describeAcceleratorAttributes(text(request, "AcceleratorArn")))).build();
|
||||
case "UpdateAcceleratorAttributes" -> Response.ok(Map.of("AcceleratorAttributes",
|
||||
service.updateAcceleratorAttributes(
|
||||
text(request, "AcceleratorArn"),
|
||||
bool(request, "FlowLogsEnabled"),
|
||||
text(request, "FlowLogsS3Bucket"),
|
||||
text(request, "FlowLogsS3Prefix")))).build();
|
||||
|
||||
case "CreateListener" -> Response.ok(Map.of("Listener", service.createListener(
|
||||
text(request, "AcceleratorArn"),
|
||||
portRanges(request.path("PortRanges")),
|
||||
text(request, "Protocol"),
|
||||
text(request, "ClientAffinity")))).build();
|
||||
case "DescribeListener" -> Response.ok(Map.of("Listener",
|
||||
service.describeListener(text(request, "ListenerArn")))).build();
|
||||
case "UpdateListener" -> Response.ok(Map.of("Listener", service.updateListener(
|
||||
text(request, "ListenerArn"),
|
||||
portRanges(request.path("PortRanges")),
|
||||
text(request, "Protocol"),
|
||||
text(request, "ClientAffinity")))).build();
|
||||
case "DeleteListener" -> {
|
||||
service.deleteListener(text(request, "ListenerArn"));
|
||||
yield Response.ok(Map.of()).build();
|
||||
}
|
||||
case "ListListeners" -> Response.ok(Map.of("Listeners",
|
||||
service.listListeners(text(request, "AcceleratorArn")))).build();
|
||||
|
||||
case "CreateEndpointGroup" -> Response.ok(Map.of("EndpointGroup", service.createEndpointGroup(
|
||||
text(request, "ListenerArn"),
|
||||
text(request, "EndpointGroupRegion"),
|
||||
nodeOrNull(request, "EndpointConfigurations"),
|
||||
floatValue(request, "TrafficDialPercentage"),
|
||||
integer(request, "HealthCheckPort"),
|
||||
text(request, "HealthCheckProtocol"),
|
||||
text(request, "HealthCheckPath"),
|
||||
integer(request, "HealthCheckIntervalSeconds"),
|
||||
integer(request, "ThresholdCount"),
|
||||
portOverrides(request.path("PortOverrides"))))).build();
|
||||
case "DescribeEndpointGroup" -> Response.ok(Map.of("EndpointGroup",
|
||||
service.describeEndpointGroup(text(request, "EndpointGroupArn")))).build();
|
||||
case "UpdateEndpointGroup" -> Response.ok(Map.of("EndpointGroup", service.updateEndpointGroup(
|
||||
text(request, "EndpointGroupArn"),
|
||||
nodeOrNull(request, "EndpointConfigurations"),
|
||||
floatValue(request, "TrafficDialPercentage"),
|
||||
integer(request, "HealthCheckPort"),
|
||||
text(request, "HealthCheckProtocol"),
|
||||
text(request, "HealthCheckPath"),
|
||||
integer(request, "HealthCheckIntervalSeconds"),
|
||||
integer(request, "ThresholdCount"),
|
||||
portOverrides(request.path("PortOverrides"))))).build();
|
||||
case "DeleteEndpointGroup" -> {
|
||||
service.deleteEndpointGroup(text(request, "EndpointGroupArn"));
|
||||
yield Response.ok(Map.of()).build();
|
||||
}
|
||||
case "ListEndpointGroups" -> Response.ok(Map.of("EndpointGroups",
|
||||
service.listEndpointGroups(text(request, "ListenerArn")))).build();
|
||||
case "AddEndpoints" -> {
|
||||
String endpointGroupArn = text(request, "EndpointGroupArn");
|
||||
EndpointGroup group = service.addEndpoints(endpointGroupArn,
|
||||
nodeOrNull(request, "EndpointConfigurations"));
|
||||
yield Response.ok(Map.of(
|
||||
"EndpointDescriptions", group.getEndpointDescriptions(),
|
||||
"EndpointGroupArn", endpointGroupArn)).build();
|
||||
}
|
||||
case "RemoveEndpoints" -> {
|
||||
service.removeEndpoints(text(request, "EndpointGroupArn"),
|
||||
endpointIdentifiers(request.path("EndpointIdentifiers")));
|
||||
yield Response.ok(Map.of()).build();
|
||||
}
|
||||
|
||||
case "TagResource" -> {
|
||||
service.tagResource(text(request, "ResourceArn"), tagMap(request.path("Tags")));
|
||||
yield Response.ok(Map.of()).build();
|
||||
}
|
||||
case "UntagResource" -> {
|
||||
service.untagResource(text(request, "ResourceArn"), stringList(request.path("TagKeys")));
|
||||
yield Response.ok(Map.of()).build();
|
||||
}
|
||||
case "ListTagsForResource" -> Response.ok(Map.of("Tags",
|
||||
tagList(service.listTagsForResource(text(request, "ResourceArn"))))).build();
|
||||
|
||||
default -> throw new AwsException("UnknownOperationException",
|
||||
"Operation " + action + " is not supported by floci", 400);
|
||||
};
|
||||
}
|
||||
|
||||
private static String text(JsonNode request, String field) {
|
||||
JsonNode node = request.path(field);
|
||||
return node.isMissingNode() || node.isNull() ? null : node.asText();
|
||||
}
|
||||
|
||||
private static Boolean bool(JsonNode request, String field) {
|
||||
JsonNode node = request.path(field);
|
||||
return node.isMissingNode() || node.isNull() ? null : node.asBoolean();
|
||||
}
|
||||
|
||||
private static Integer integer(JsonNode request, String field) {
|
||||
JsonNode node = request.path(field);
|
||||
return node.isMissingNode() || node.isNull() ? null : node.asInt();
|
||||
}
|
||||
|
||||
private static Float floatValue(JsonNode request, String field) {
|
||||
JsonNode node = request.path(field);
|
||||
return node.isMissingNode() || node.isNull() ? null : (float) node.asDouble();
|
||||
}
|
||||
|
||||
private static JsonNode nodeOrNull(JsonNode request, String field) {
|
||||
JsonNode node = request.path(field);
|
||||
return node.isMissingNode() || node.isNull() ? null : node;
|
||||
}
|
||||
|
||||
private static List<String> stringList(JsonNode node) {
|
||||
if (node == null || !node.isArray()) {
|
||||
return null;
|
||||
}
|
||||
List<String> values = new ArrayList<>();
|
||||
node.forEach(element -> values.add(element.asText()));
|
||||
return values;
|
||||
}
|
||||
|
||||
private static List<String> endpointIdentifiers(JsonNode node) {
|
||||
if (node == null || !node.isArray()) {
|
||||
return null;
|
||||
}
|
||||
List<String> endpointIds = new ArrayList<>();
|
||||
node.forEach(element -> endpointIds.add(element.path("EndpointId").asText()));
|
||||
return endpointIds;
|
||||
}
|
||||
|
||||
private List<PortRange> portRanges(JsonNode node) {
|
||||
if (node == null || !node.isArray()) {
|
||||
return null;
|
||||
}
|
||||
return mapper.convertValue(node, new TypeReference<List<PortRange>>() {});
|
||||
}
|
||||
|
||||
private List<PortOverride> portOverrides(JsonNode node) {
|
||||
if (node == null || !node.isArray()) {
|
||||
return null;
|
||||
}
|
||||
return mapper.convertValue(node, new TypeReference<List<PortOverride>>() {});
|
||||
}
|
||||
|
||||
private static Map<String, String> tagMap(JsonNode node) {
|
||||
if (node == null || !node.isArray()) {
|
||||
return null;
|
||||
}
|
||||
Map<String, String> tags = new LinkedHashMap<>();
|
||||
for (JsonNode tag : node) {
|
||||
String key = tag.path("Key").asText(null);
|
||||
if (key == null) {
|
||||
throw new AwsException("InvalidArgumentException", "Every tag must carry a Key.", 400);
|
||||
}
|
||||
tags.put(key, tag.path("Value").asText(""));
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
private ArrayNode tagList(Map<String, String> tags) {
|
||||
ArrayNode list = mapper.createArrayNode();
|
||||
tags.forEach((key, value) -> {
|
||||
ObjectNode tag = list.addObject();
|
||||
tag.put("Key", key);
|
||||
tag.put("Value", value);
|
||||
});
|
||||
return list;
|
||||
}
|
||||
}
|
||||
+672
@@ -0,0 +1,672 @@
|
||||
package io.github.hectorvent.floci.services.globalaccelerator;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.globalaccelerator.model.Accelerator;
|
||||
import io.github.hectorvent.floci.services.globalaccelerator.model.AcceleratorAttributes;
|
||||
import io.github.hectorvent.floci.services.globalaccelerator.model.EndpointDescription;
|
||||
import io.github.hectorvent.floci.services.globalaccelerator.model.EndpointGroup;
|
||||
import io.github.hectorvent.floci.services.globalaccelerator.model.IpSet;
|
||||
import io.github.hectorvent.floci.services.globalaccelerator.model.Listener;
|
||||
import io.github.hectorvent.floci.services.globalaccelerator.model.PortOverride;
|
||||
import io.github.hectorvent.floci.services.globalaccelerator.model.PortRange;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* AWS Global Accelerator management plane.
|
||||
*
|
||||
* <p>Global Accelerator is a global service. Its ARNs carry an empty region segment
|
||||
* ({@code arn:aws:globalaccelerator::<account>:accelerator/<id>}) and listener and endpoint
|
||||
* group ARNs extend the accelerator ARN, which is how the real service expresses the
|
||||
* parent/child relationship. Parent lookups therefore need no back-reference field: an
|
||||
* accelerator's listeners are the stored ARNs prefixed by it. Nothing is keyed by region,
|
||||
* so the signing region the SDK happens to use does not partition the state.
|
||||
*
|
||||
* <p>Accelerators are {@code DEPLOYED} and endpoints are {@code HEALTHY} as soon as a create
|
||||
* returns, so provider waiters complete on their first poll. The static IP addresses come
|
||||
* from the address ranges Global Accelerator advertises but route no traffic.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class GlobalAcceleratorService {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(GlobalAcceleratorService.class);
|
||||
private static final String ID_ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
private static final String HEX = "0123456789abcdef";
|
||||
|
||||
private static final String STATUS_DEPLOYED = "DEPLOYED";
|
||||
private static final String HEALTH_STATE_HEALTHY = "HEALTHY";
|
||||
private static final String LISTENER_SEGMENT = "/listener/";
|
||||
private static final String ENDPOINT_GROUP_SEGMENT = "/endpoint-group/";
|
||||
private static final String DNS_SUFFIX = ".awsglobalaccelerator.com";
|
||||
private static final String DUAL_STACK_DNS_SUFFIX = ".dualstack.awsglobalaccelerator.com";
|
||||
|
||||
private static final Set<String> IP_ADDRESS_TYPES = Set.of("IPV4", "DUAL_STACK");
|
||||
private static final Set<String> PROTOCOLS = Set.of("TCP", "UDP");
|
||||
private static final Set<String> CLIENT_AFFINITIES = Set.of("NONE", "SOURCE_IP");
|
||||
private static final Set<String> HEALTH_CHECK_PROTOCOLS = Set.of("TCP", "HTTP", "HTTPS");
|
||||
|
||||
private static final int MAX_PORT_RANGES = 10;
|
||||
private static final int MAX_ENDPOINT_CONFIGURATIONS = 10;
|
||||
private static final int MAX_PORT_OVERRIDES = 10;
|
||||
private static final int MAX_IP_ADDRESSES = 2;
|
||||
private static final int MAX_HEALTH_CHECK_PATH_LENGTH = 255;
|
||||
private static final Pattern HEALTH_CHECK_PATH_PATTERN =
|
||||
Pattern.compile("^/[-a-zA-Z0-9@:%_\\+.~#?&/=]*$");
|
||||
|
||||
private final StorageBackend<String, Accelerator> accelerators;
|
||||
private final StorageBackend<String, AcceleratorAttributes> acceleratorAttributes;
|
||||
private final StorageBackend<String, Listener> listeners;
|
||||
private final StorageBackend<String, EndpointGroup> endpointGroups;
|
||||
private final StorageBackend<String, Map<String, String>> tags;
|
||||
private final RegionResolver regionResolver;
|
||||
|
||||
@Inject
|
||||
public GlobalAcceleratorService(StorageFactory storageFactory, RegionResolver regionResolver) {
|
||||
this.accelerators = storageFactory.create("globalaccelerator", "globalaccelerator-accelerators.json",
|
||||
new TypeReference<Map<String, Accelerator>>() {});
|
||||
this.acceleratorAttributes = storageFactory.create("globalaccelerator",
|
||||
"globalaccelerator-accelerator-attributes.json",
|
||||
new TypeReference<Map<String, AcceleratorAttributes>>() {});
|
||||
this.listeners = storageFactory.create("globalaccelerator", "globalaccelerator-listeners.json",
|
||||
new TypeReference<Map<String, Listener>>() {});
|
||||
this.endpointGroups = storageFactory.create("globalaccelerator", "globalaccelerator-endpoint-groups.json",
|
||||
new TypeReference<Map<String, EndpointGroup>>() {});
|
||||
this.tags = storageFactory.create("globalaccelerator", "globalaccelerator-tags.json",
|
||||
new TypeReference<Map<String, Map<String, String>>>() {});
|
||||
this.regionResolver = regionResolver;
|
||||
}
|
||||
|
||||
public Accelerator createAccelerator(String name, String ipAddressType, List<String> ipAddresses,
|
||||
Boolean enabled, Map<String, String> requestTags) {
|
||||
requireArgument(name, "Name");
|
||||
String resolvedIpAddressType = ipAddressType != null ? ipAddressType : "IPV4";
|
||||
requireIpAddressType(resolvedIpAddressType);
|
||||
validateIpAddresses(ipAddresses);
|
||||
|
||||
long now = Instant.now().getEpochSecond();
|
||||
String dnsPrefix = "a" + randomHex(16);
|
||||
|
||||
Accelerator accelerator = new Accelerator();
|
||||
accelerator.setAcceleratorArn(regionResolver.buildArn("globalaccelerator", "",
|
||||
"accelerator/" + UUID.randomUUID()));
|
||||
accelerator.setName(name);
|
||||
accelerator.setIpAddressType(resolvedIpAddressType);
|
||||
accelerator.setEnabled(enabled == null || enabled);
|
||||
accelerator.setIpSets(buildIpSets(resolvedIpAddressType, ipAddresses));
|
||||
accelerator.setDnsName(dnsPrefix + DNS_SUFFIX);
|
||||
if ("DUAL_STACK".equals(resolvedIpAddressType)) {
|
||||
accelerator.setDualStackDnsName(dnsPrefix + DUAL_STACK_DNS_SUFFIX);
|
||||
}
|
||||
accelerator.setStatus(STATUS_DEPLOYED);
|
||||
accelerator.setCreatedTime(now);
|
||||
accelerator.setLastModifiedTime(now);
|
||||
|
||||
accelerators.put(accelerator.getAcceleratorArn(), accelerator);
|
||||
acceleratorAttributes.put(accelerator.getAcceleratorArn(), defaultAttributes());
|
||||
tags.put(accelerator.getAcceleratorArn(),
|
||||
requestTags != null ? new LinkedHashMap<>(requestTags) : new LinkedHashMap<>());
|
||||
LOG.infov("Created Global Accelerator accelerator: {0}", accelerator.getAcceleratorArn());
|
||||
return accelerator;
|
||||
}
|
||||
|
||||
public Accelerator describeAccelerator(String acceleratorArn) {
|
||||
requireArgument(acceleratorArn, "AcceleratorArn");
|
||||
return accelerators.get(acceleratorArn)
|
||||
.orElseThrow(() -> new AwsException("AcceleratorNotFoundException",
|
||||
"Accelerator " + acceleratorArn + " does not exist.", 400));
|
||||
}
|
||||
|
||||
public Accelerator updateAccelerator(String acceleratorArn, String name, String ipAddressType,
|
||||
List<String> ipAddresses, Boolean enabled) {
|
||||
Accelerator accelerator = describeAccelerator(acceleratorArn);
|
||||
if (ipAddressType != null) {
|
||||
requireIpAddressType(ipAddressType);
|
||||
}
|
||||
validateIpAddresses(ipAddresses);
|
||||
if (name != null) {
|
||||
accelerator.setName(name);
|
||||
}
|
||||
if (ipAddressType != null) {
|
||||
accelerator.setIpAddressType(ipAddressType);
|
||||
accelerator.setIpSets(buildIpSets(ipAddressType, ipAddresses != null
|
||||
? ipAddresses
|
||||
: firstIpv4Addresses(accelerator)));
|
||||
if ("DUAL_STACK".equals(ipAddressType)) {
|
||||
if (accelerator.getDualStackDnsName() == null) {
|
||||
accelerator.setDualStackDnsName(
|
||||
accelerator.getDnsName().replace(DNS_SUFFIX, DUAL_STACK_DNS_SUFFIX));
|
||||
}
|
||||
} else {
|
||||
accelerator.setDualStackDnsName(null);
|
||||
}
|
||||
} else if (ipAddresses != null && !ipAddresses.isEmpty()) {
|
||||
accelerator.setIpSets(buildIpSets(accelerator.getIpAddressType(), ipAddresses));
|
||||
}
|
||||
if (enabled != null) {
|
||||
accelerator.setEnabled(enabled);
|
||||
}
|
||||
accelerator.setStatus(STATUS_DEPLOYED);
|
||||
accelerator.setLastModifiedTime(Instant.now().getEpochSecond());
|
||||
accelerators.put(acceleratorArn, accelerator);
|
||||
return accelerator;
|
||||
}
|
||||
|
||||
public void deleteAccelerator(String acceleratorArn) {
|
||||
Accelerator accelerator = describeAccelerator(acceleratorArn);
|
||||
if (Boolean.TRUE.equals(accelerator.getEnabled())) {
|
||||
throw new AwsException("AcceleratorNotDisabledException",
|
||||
"The accelerator must be disabled before it can be deleted.", 400);
|
||||
}
|
||||
if (!listenersOf(acceleratorArn).isEmpty()) {
|
||||
throw new AwsException("AssociatedListenerFoundException",
|
||||
"The accelerator has associated listeners and cannot be deleted.", 400);
|
||||
}
|
||||
accelerators.delete(acceleratorArn);
|
||||
acceleratorAttributes.delete(acceleratorArn);
|
||||
tags.delete(acceleratorArn);
|
||||
LOG.infov("Deleted Global Accelerator accelerator: {0}", acceleratorArn);
|
||||
}
|
||||
|
||||
public List<Accelerator> listAccelerators() {
|
||||
return accelerators.scan(key -> true);
|
||||
}
|
||||
|
||||
public AcceleratorAttributes describeAcceleratorAttributes(String acceleratorArn) {
|
||||
describeAccelerator(acceleratorArn);
|
||||
return acceleratorAttributes.get(acceleratorArn).orElseGet(GlobalAcceleratorService::defaultAttributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flow logs need a destination bucket. AWS rejects an update that leaves
|
||||
* {@code FlowLogsEnabled} true with no {@code FlowLogsS3Bucket}, so the emulator does too:
|
||||
* accepting it would persist an attribute set the real service cannot produce.
|
||||
*/
|
||||
public AcceleratorAttributes updateAcceleratorAttributes(String acceleratorArn, Boolean flowLogsEnabled,
|
||||
String flowLogsS3Bucket, String flowLogsS3Prefix) {
|
||||
AcceleratorAttributes stored = describeAcceleratorAttributes(acceleratorArn);
|
||||
AcceleratorAttributes updated = new AcceleratorAttributes();
|
||||
updated.setFlowLogsEnabled(flowLogsEnabled != null ? flowLogsEnabled : stored.getFlowLogsEnabled());
|
||||
updated.setFlowLogsS3Bucket(flowLogsS3Bucket != null ? flowLogsS3Bucket : stored.getFlowLogsS3Bucket());
|
||||
updated.setFlowLogsS3Prefix(flowLogsS3Prefix != null ? flowLogsS3Prefix : stored.getFlowLogsS3Prefix());
|
||||
if (Boolean.TRUE.equals(updated.getFlowLogsEnabled())
|
||||
&& (updated.getFlowLogsS3Bucket() == null || updated.getFlowLogsS3Bucket().isBlank())) {
|
||||
throw new AwsException("InvalidArgumentException",
|
||||
"FlowLogsS3Bucket is required when FlowLogsEnabled is true.", 400);
|
||||
}
|
||||
acceleratorAttributes.put(acceleratorArn, updated);
|
||||
return updated;
|
||||
}
|
||||
|
||||
public Listener createListener(String acceleratorArn, List<PortRange> portRanges, String protocol,
|
||||
String clientAffinity) {
|
||||
describeAccelerator(acceleratorArn);
|
||||
validatePortRanges(portRanges);
|
||||
requireArgument(protocol, "Protocol");
|
||||
requireProtocol(protocol);
|
||||
requireClientAffinity(clientAffinity);
|
||||
|
||||
Listener listener = new Listener();
|
||||
listener.setListenerArn(acceleratorArn + LISTENER_SEGMENT + randomId(8));
|
||||
listener.setPortRanges(portRanges);
|
||||
listener.setProtocol(protocol);
|
||||
listener.setClientAffinity(clientAffinity != null ? clientAffinity : "NONE");
|
||||
|
||||
listeners.put(listener.getListenerArn(), listener);
|
||||
LOG.infov("Created Global Accelerator listener: {0}", listener.getListenerArn());
|
||||
return listener;
|
||||
}
|
||||
|
||||
public Listener describeListener(String listenerArn) {
|
||||
requireArgument(listenerArn, "ListenerArn");
|
||||
return listeners.get(listenerArn)
|
||||
.orElseThrow(() -> new AwsException("ListenerNotFoundException",
|
||||
"Listener " + listenerArn + " does not exist.", 400));
|
||||
}
|
||||
|
||||
public Listener updateListener(String listenerArn, List<PortRange> portRanges, String protocol,
|
||||
String clientAffinity) {
|
||||
Listener listener = describeListener(listenerArn);
|
||||
if (portRanges != null && !portRanges.isEmpty()) {
|
||||
validatePortRanges(portRanges);
|
||||
listener.setPortRanges(portRanges);
|
||||
}
|
||||
if (protocol != null) {
|
||||
requireProtocol(protocol);
|
||||
listener.setProtocol(protocol);
|
||||
}
|
||||
if (clientAffinity != null) {
|
||||
requireClientAffinity(clientAffinity);
|
||||
listener.setClientAffinity(clientAffinity);
|
||||
}
|
||||
listeners.put(listenerArn, listener);
|
||||
return listener;
|
||||
}
|
||||
|
||||
public void deleteListener(String listenerArn) {
|
||||
describeListener(listenerArn);
|
||||
if (!endpointGroupsOf(listenerArn).isEmpty()) {
|
||||
throw new AwsException("AssociatedEndpointGroupFoundException",
|
||||
"The listener has associated endpoint groups and cannot be deleted.", 400);
|
||||
}
|
||||
listeners.delete(listenerArn);
|
||||
tags.delete(listenerArn);
|
||||
LOG.infov("Deleted Global Accelerator listener: {0}", listenerArn);
|
||||
}
|
||||
|
||||
public List<Listener> listListeners(String acceleratorArn) {
|
||||
describeAccelerator(acceleratorArn);
|
||||
return listenersOf(acceleratorArn);
|
||||
}
|
||||
|
||||
public EndpointGroup createEndpointGroup(String listenerArn, String endpointGroupRegion,
|
||||
JsonNode endpointConfigurations, Float trafficDialPercentage,
|
||||
Integer healthCheckPort, String healthCheckProtocol,
|
||||
String healthCheckPath, Integer healthCheckIntervalSeconds,
|
||||
Integer thresholdCount, List<PortOverride> portOverrides) {
|
||||
Listener listener = describeListener(listenerArn);
|
||||
requireArgument(endpointGroupRegion, "EndpointGroupRegion");
|
||||
validateHealthCheck(healthCheckProtocol, healthCheckPort, healthCheckIntervalSeconds, thresholdCount);
|
||||
validateHealthCheckPath(healthCheckPath);
|
||||
validateTrafficDial(trafficDialPercentage);
|
||||
validatePortOverrides(portOverrides);
|
||||
boolean regionTaken = endpointGroupsOf(listenerArn).stream()
|
||||
.anyMatch(group -> endpointGroupRegion.equals(group.getEndpointGroupRegion()));
|
||||
if (regionTaken) {
|
||||
throw new AwsException("EndpointGroupAlreadyExistsException",
|
||||
"An endpoint group for Region " + endpointGroupRegion + " already exists on this listener.", 400);
|
||||
}
|
||||
|
||||
EndpointGroup group = new EndpointGroup();
|
||||
group.setEndpointGroupArn(listenerArn + ENDPOINT_GROUP_SEGMENT + randomId(12));
|
||||
group.setEndpointGroupRegion(endpointGroupRegion);
|
||||
group.setEndpointDescriptions(toEndpointDescriptions(endpointConfigurations));
|
||||
group.setTrafficDialPercentage(trafficDialPercentage != null ? trafficDialPercentage : 100.0f);
|
||||
group.setHealthCheckPort(healthCheckPort != null ? healthCheckPort : defaultHealthCheckPort(listener));
|
||||
group.setHealthCheckProtocol(healthCheckProtocol != null ? healthCheckProtocol : "TCP");
|
||||
group.setHealthCheckPath(healthCheckPath != null ? healthCheckPath : "/");
|
||||
group.setHealthCheckIntervalSeconds(healthCheckIntervalSeconds != null ? healthCheckIntervalSeconds : 30);
|
||||
group.setThresholdCount(thresholdCount != null ? thresholdCount : 3);
|
||||
group.setPortOverrides(portOverrides != null ? portOverrides : new ArrayList<>());
|
||||
|
||||
endpointGroups.put(group.getEndpointGroupArn(), group);
|
||||
LOG.infov("Created Global Accelerator endpoint group: {0}", group.getEndpointGroupArn());
|
||||
return group;
|
||||
}
|
||||
|
||||
public EndpointGroup describeEndpointGroup(String endpointGroupArn) {
|
||||
requireArgument(endpointGroupArn, "EndpointGroupArn");
|
||||
return endpointGroups.get(endpointGroupArn)
|
||||
.orElseThrow(() -> new AwsException("EndpointGroupNotFoundException",
|
||||
"Endpoint group " + endpointGroupArn + " does not exist.", 400));
|
||||
}
|
||||
|
||||
public EndpointGroup updateEndpointGroup(String endpointGroupArn, JsonNode endpointConfigurations,
|
||||
Float trafficDialPercentage, Integer healthCheckPort,
|
||||
String healthCheckProtocol, String healthCheckPath,
|
||||
Integer healthCheckIntervalSeconds, Integer thresholdCount,
|
||||
List<PortOverride> portOverrides) {
|
||||
EndpointGroup group = describeEndpointGroup(endpointGroupArn);
|
||||
validateHealthCheck(healthCheckProtocol, healthCheckPort, healthCheckIntervalSeconds, thresholdCount);
|
||||
validateHealthCheckPath(healthCheckPath);
|
||||
validateTrafficDial(trafficDialPercentage);
|
||||
validatePortOverrides(portOverrides);
|
||||
if (endpointConfigurations != null && endpointConfigurations.isArray()) {
|
||||
group.setEndpointDescriptions(toEndpointDescriptions(endpointConfigurations));
|
||||
}
|
||||
if (trafficDialPercentage != null) {
|
||||
group.setTrafficDialPercentage(trafficDialPercentage);
|
||||
}
|
||||
if (healthCheckPort != null) {
|
||||
group.setHealthCheckPort(healthCheckPort);
|
||||
}
|
||||
if (healthCheckProtocol != null) {
|
||||
group.setHealthCheckProtocol(healthCheckProtocol);
|
||||
}
|
||||
if (healthCheckPath != null) {
|
||||
group.setHealthCheckPath(healthCheckPath);
|
||||
}
|
||||
if (healthCheckIntervalSeconds != null) {
|
||||
group.setHealthCheckIntervalSeconds(healthCheckIntervalSeconds);
|
||||
}
|
||||
if (thresholdCount != null) {
|
||||
group.setThresholdCount(thresholdCount);
|
||||
}
|
||||
if (portOverrides != null) {
|
||||
group.setPortOverrides(portOverrides);
|
||||
}
|
||||
endpointGroups.put(endpointGroupArn, group);
|
||||
return group;
|
||||
}
|
||||
|
||||
public void deleteEndpointGroup(String endpointGroupArn) {
|
||||
describeEndpointGroup(endpointGroupArn);
|
||||
endpointGroups.delete(endpointGroupArn);
|
||||
tags.delete(endpointGroupArn);
|
||||
LOG.infov("Deleted Global Accelerator endpoint group: {0}", endpointGroupArn);
|
||||
}
|
||||
|
||||
public List<EndpointGroup> listEndpointGroups(String listenerArn) {
|
||||
describeListener(listenerArn);
|
||||
return endpointGroupsOf(listenerArn);
|
||||
}
|
||||
|
||||
public EndpointGroup addEndpoints(String endpointGroupArn, JsonNode endpointConfigurations) {
|
||||
EndpointGroup group = describeEndpointGroup(endpointGroupArn);
|
||||
if (endpointConfigurations == null || !endpointConfigurations.isArray()) {
|
||||
throw new AwsException("InvalidArgumentException", "EndpointConfigurations is required.", 400);
|
||||
}
|
||||
List<EndpointDescription> merged = new ArrayList<>(group.getEndpointDescriptions());
|
||||
for (EndpointDescription added : toEndpointDescriptions(endpointConfigurations)) {
|
||||
merged.removeIf(existing -> existing.getEndpointId() != null
|
||||
&& existing.getEndpointId().equals(added.getEndpointId()));
|
||||
merged.add(added);
|
||||
}
|
||||
group.setEndpointDescriptions(merged);
|
||||
endpointGroups.put(endpointGroupArn, group);
|
||||
return group;
|
||||
}
|
||||
|
||||
public void removeEndpoints(String endpointGroupArn, List<String> endpointIds) {
|
||||
EndpointGroup group = describeEndpointGroup(endpointGroupArn);
|
||||
if (endpointIds == null || endpointIds.isEmpty()) {
|
||||
throw new AwsException("InvalidArgumentException", "EndpointIdentifiers is required.", 400);
|
||||
}
|
||||
List<EndpointDescription> remaining = new ArrayList<>(group.getEndpointDescriptions());
|
||||
remaining.removeIf(endpoint -> endpointIds.contains(endpoint.getEndpointId()));
|
||||
group.setEndpointDescriptions(remaining);
|
||||
endpointGroups.put(endpointGroupArn, group);
|
||||
}
|
||||
|
||||
public Map<String, String> listTagsForResource(String resourceArn) {
|
||||
requireResourceExists(resourceArn);
|
||||
return tags.get(resourceArn).orElseGet(LinkedHashMap::new);
|
||||
}
|
||||
|
||||
public void tagResource(String resourceArn, Map<String, String> newTags) {
|
||||
requireResourceExists(resourceArn);
|
||||
if (newTags == null || newTags.isEmpty()) {
|
||||
throw new AwsException("InvalidArgumentException", "Tags is required.", 400);
|
||||
}
|
||||
Map<String, String> existing = new LinkedHashMap<>(tags.get(resourceArn).orElseGet(LinkedHashMap::new));
|
||||
existing.putAll(newTags);
|
||||
tags.put(resourceArn, existing);
|
||||
}
|
||||
|
||||
public void untagResource(String resourceArn, List<String> tagKeys) {
|
||||
requireResourceExists(resourceArn);
|
||||
if (tagKeys == null || tagKeys.isEmpty()) {
|
||||
throw new AwsException("InvalidArgumentException", "TagKeys is required.", 400);
|
||||
}
|
||||
Map<String, String> existing = new LinkedHashMap<>(tags.get(resourceArn).orElseGet(LinkedHashMap::new));
|
||||
tagKeys.forEach(existing::remove);
|
||||
tags.put(resourceArn, existing);
|
||||
}
|
||||
|
||||
private List<Listener> listenersOf(String acceleratorArn) {
|
||||
return listeners.scan(key -> key.startsWith(acceleratorArn + LISTENER_SEGMENT));
|
||||
}
|
||||
|
||||
private List<EndpointGroup> endpointGroupsOf(String listenerArn) {
|
||||
return endpointGroups.scan(key -> key.startsWith(listenerArn + ENDPOINT_GROUP_SEGMENT));
|
||||
}
|
||||
|
||||
private void requireResourceExists(String resourceArn) {
|
||||
requireArgument(resourceArn, "ResourceArn");
|
||||
if (resourceArn.contains(ENDPOINT_GROUP_SEGMENT)) {
|
||||
describeEndpointGroup(resourceArn);
|
||||
} else if (resourceArn.contains(LISTENER_SEGMENT)) {
|
||||
describeListener(resourceArn);
|
||||
} else {
|
||||
describeAccelerator(resourceArn);
|
||||
}
|
||||
}
|
||||
|
||||
private static Integer defaultHealthCheckPort(Listener listener) {
|
||||
for (PortRange range : listener.getPortRanges()) {
|
||||
if (range.getFromPort() != null) {
|
||||
return range.getFromPort();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<EndpointDescription> toEndpointDescriptions(JsonNode endpointConfigurations) {
|
||||
List<EndpointDescription> descriptions = new ArrayList<>();
|
||||
if (endpointConfigurations == null || !endpointConfigurations.isArray()) {
|
||||
return descriptions;
|
||||
}
|
||||
requireAtMost(endpointConfigurations.size(), MAX_ENDPOINT_CONFIGURATIONS, "EndpointConfigurations");
|
||||
for (JsonNode configuration : endpointConfigurations) {
|
||||
EndpointDescription description = new EndpointDescription();
|
||||
String endpointId = configuration.path("EndpointId").asText(null);
|
||||
if (endpointId == null || endpointId.isBlank()) {
|
||||
throw new AwsException("InvalidArgumentException",
|
||||
"EndpointId is required on every endpoint configuration.", 400);
|
||||
}
|
||||
description.setEndpointId(endpointId);
|
||||
description.setWeight(configuration.has("Weight")
|
||||
? requireWeight(configuration.get("Weight").asInt())
|
||||
: 128);
|
||||
description.setClientIpPreservationEnabled(configuration.has("ClientIPPreservationEnabled")
|
||||
? configuration.get("ClientIPPreservationEnabled").asBoolean()
|
||||
: endpointId.contains(":loadbalancer/app/"));
|
||||
description.setHealthState(HEALTH_STATE_HEALTHY);
|
||||
descriptions.add(description);
|
||||
}
|
||||
return descriptions;
|
||||
}
|
||||
|
||||
private static int requireWeight(int weight) {
|
||||
if (weight < 0 || weight > 255) {
|
||||
throw new AwsException("InvalidArgumentException", "Weight must be between 0 and 255.", 400);
|
||||
}
|
||||
return weight;
|
||||
}
|
||||
|
||||
private static void validatePortRanges(List<PortRange> portRanges) {
|
||||
if (portRanges == null || portRanges.isEmpty()) {
|
||||
throw new AwsException("InvalidArgumentException", "PortRanges is required.", 400);
|
||||
}
|
||||
requireAtMost(portRanges.size(), MAX_PORT_RANGES, "PortRanges");
|
||||
for (PortRange range : portRanges) {
|
||||
Integer from = range.getFromPort();
|
||||
Integer to = range.getToPort();
|
||||
if (from == null || to == null || from < 1 || to > 65535 || from > to) {
|
||||
throw new AwsException("InvalidPortRangeException",
|
||||
"The port range is not valid. FromPort must be between 1 and ToPort, "
|
||||
+ "and ToPort must not exceed 65535.", 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void validatePortOverrides(List<PortOverride> portOverrides) {
|
||||
if (portOverrides == null) {
|
||||
return;
|
||||
}
|
||||
requireAtMost(portOverrides.size(), MAX_PORT_OVERRIDES, "PortOverrides");
|
||||
for (PortOverride override : portOverrides) {
|
||||
if (!isPort(override.getListenerPort()) || !isPort(override.getEndpointPort())) {
|
||||
throw new AwsException("InvalidPortRangeException",
|
||||
"A port override must carry a ListenerPort and an EndpointPort between 1 and 65535.", 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isPort(Integer port) {
|
||||
return port != null && port >= 1 && port <= 65535;
|
||||
}
|
||||
|
||||
private static void validateHealthCheck(String healthCheckProtocol, Integer healthCheckPort,
|
||||
Integer healthCheckIntervalSeconds, Integer thresholdCount) {
|
||||
if (healthCheckProtocol != null && !HEALTH_CHECK_PROTOCOLS.contains(healthCheckProtocol)) {
|
||||
throw new AwsException("InvalidArgumentException",
|
||||
"HealthCheckProtocol must be TCP, HTTP or HTTPS.", 400);
|
||||
}
|
||||
if (healthCheckPort != null && !isPort(healthCheckPort)) {
|
||||
throw new AwsException("InvalidArgumentException",
|
||||
"HealthCheckPort must be between 1 and 65535.", 400);
|
||||
}
|
||||
if (healthCheckIntervalSeconds != null
|
||||
&& (healthCheckIntervalSeconds < 10 || healthCheckIntervalSeconds > 30)) {
|
||||
throw new AwsException("InvalidArgumentException",
|
||||
"HealthCheckIntervalSeconds must be between 10 and 30.", 400);
|
||||
}
|
||||
if (thresholdCount != null && (thresholdCount < 1 || thresholdCount > 10)) {
|
||||
throw new AwsException("InvalidArgumentException",
|
||||
"ThresholdCount must be between 1 and 10.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateHealthCheckPath(String healthCheckPath) {
|
||||
if (healthCheckPath == null) {
|
||||
return;
|
||||
}
|
||||
if (healthCheckPath.length() > MAX_HEALTH_CHECK_PATH_LENGTH) {
|
||||
throw new AwsException("InvalidArgumentException",
|
||||
"HealthCheckPath must not exceed " + MAX_HEALTH_CHECK_PATH_LENGTH + " characters.", 400);
|
||||
}
|
||||
if (!HEALTH_CHECK_PATH_PATTERN.matcher(healthCheckPath).matches()) {
|
||||
throw new AwsException("InvalidArgumentException",
|
||||
"HealthCheckPath must begin with / and contain only URL path characters.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateIpAddresses(List<String> ipAddresses) {
|
||||
if (ipAddresses == null) {
|
||||
return;
|
||||
}
|
||||
requireAtMost(ipAddresses.size(), MAX_IP_ADDRESSES, "IpAddresses");
|
||||
}
|
||||
|
||||
private static void requireAtMost(int size, int max, String field) {
|
||||
if (size > max) {
|
||||
throw new AwsException("InvalidArgumentException",
|
||||
field + " must not contain more than " + max + " members.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateTrafficDial(Float trafficDialPercentage) {
|
||||
if (trafficDialPercentage != null && (trafficDialPercentage < 0f || trafficDialPercentage > 100f)) {
|
||||
throw new AwsException("InvalidArgumentException",
|
||||
"TrafficDialPercentage must be between 0 and 100.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static void requireIpAddressType(String ipAddressType) {
|
||||
if (!IP_ADDRESS_TYPES.contains(ipAddressType)) {
|
||||
throw new AwsException("InvalidArgumentException", "IpAddressType must be IPV4 or DUAL_STACK.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static void requireProtocol(String protocol) {
|
||||
if (!PROTOCOLS.contains(protocol)) {
|
||||
throw new AwsException("InvalidArgumentException", "Protocol must be TCP or UDP.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static void requireClientAffinity(String clientAffinity) {
|
||||
if (clientAffinity != null && !CLIENT_AFFINITIES.contains(clientAffinity)) {
|
||||
throw new AwsException("InvalidArgumentException", "ClientAffinity must be NONE or SOURCE_IP.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<IpSet> buildIpSets(String ipAddressType, List<String> requestedIpv4Addresses) {
|
||||
List<IpSet> ipSets = new ArrayList<>();
|
||||
IpSet ipv4 = new IpSet();
|
||||
ipv4.setIpFamily("IPv4");
|
||||
ipv4.setIpAddressFamily("IPv4");
|
||||
ipv4.setIpAddresses(staticIpv4Addresses(requestedIpv4Addresses));
|
||||
ipSets.add(ipv4);
|
||||
|
||||
if ("DUAL_STACK".equals(ipAddressType)) {
|
||||
IpSet ipv6 = new IpSet();
|
||||
ipv6.setIpFamily("IPv6");
|
||||
ipv6.setIpAddressFamily("IPv6");
|
||||
ipv6.setIpAddresses(List.of(randomIpv6(), randomIpv6()));
|
||||
ipSets.add(ipv6);
|
||||
}
|
||||
return ipSets;
|
||||
}
|
||||
|
||||
private static List<String> firstIpv4Addresses(Accelerator accelerator) {
|
||||
return accelerator.getIpSets().stream()
|
||||
.filter(set -> "IPv4".equals(set.getIpAddressFamily()))
|
||||
.findFirst()
|
||||
.map(IpSet::getIpAddresses)
|
||||
.orElseGet(ArrayList::new);
|
||||
}
|
||||
|
||||
/**
|
||||
* Global Accelerator assigns two static IPv4 addresses per accelerator, drawn from the
|
||||
* ranges it advertises. A caller that brought its own address pool (BYOIP) may pin one or
|
||||
* both, in which case the request wins and any shortfall is filled from the service pool.
|
||||
*/
|
||||
private static List<String> staticIpv4Addresses(List<String> requested) {
|
||||
List<String> addresses = new ArrayList<>();
|
||||
if (requested != null) {
|
||||
requested.stream().filter(address -> address != null && !address.isBlank()).forEach(addresses::add);
|
||||
}
|
||||
String[] pools = {"75.2", "99.83"};
|
||||
int poolIndex = 0;
|
||||
while (addresses.size() < 2) {
|
||||
addresses.add(pools[poolIndex % pools.length] + "."
|
||||
+ ThreadLocalRandom.current().nextInt(256) + "."
|
||||
+ ThreadLocalRandom.current().nextInt(256));
|
||||
poolIndex++;
|
||||
}
|
||||
return addresses;
|
||||
}
|
||||
|
||||
private static String randomIpv6() {
|
||||
StringBuilder address = new StringBuilder("2600:9000:a400");
|
||||
for (int group = 0; group < 5; group++) {
|
||||
address.append(':').append(randomHex(4));
|
||||
}
|
||||
return address.toString();
|
||||
}
|
||||
|
||||
private static AcceleratorAttributes defaultAttributes() {
|
||||
AcceleratorAttributes attributes = new AcceleratorAttributes();
|
||||
attributes.setFlowLogsEnabled(false);
|
||||
return attributes;
|
||||
}
|
||||
|
||||
private static void requireArgument(String value, String field) {
|
||||
if (value == null || value.isBlank()) {
|
||||
throw new AwsException("InvalidArgumentException", field + " is required.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static String randomId(int length) {
|
||||
StringBuilder id = new StringBuilder(length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
id.append(ID_ALPHABET.charAt(ThreadLocalRandom.current().nextInt(ID_ALPHABET.length())));
|
||||
}
|
||||
return id.toString();
|
||||
}
|
||||
|
||||
private static String randomHex(int length) {
|
||||
StringBuilder hex = new StringBuilder(length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
hex.append(HEX.charAt(ThreadLocalRandom.current().nextInt(HEX.length())));
|
||||
}
|
||||
return hex.toString().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package io.github.hectorvent.floci.services.globalaccelerator.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class Accelerator {
|
||||
|
||||
@JsonProperty("AcceleratorArn")
|
||||
private String acceleratorArn;
|
||||
|
||||
@JsonProperty("Name")
|
||||
private String name;
|
||||
|
||||
@JsonProperty("IpAddressType")
|
||||
private String ipAddressType;
|
||||
|
||||
@JsonProperty("Enabled")
|
||||
private Boolean enabled;
|
||||
|
||||
@JsonProperty("IpSets")
|
||||
private List<IpSet> ipSets = new ArrayList<>();
|
||||
|
||||
@JsonProperty("DnsName")
|
||||
private String dnsName;
|
||||
|
||||
@JsonProperty("DualStackDnsName")
|
||||
private String dualStackDnsName;
|
||||
|
||||
@JsonProperty("Status")
|
||||
private String status;
|
||||
|
||||
@JsonProperty("CreatedTime")
|
||||
private Long createdTime;
|
||||
|
||||
@JsonProperty("LastModifiedTime")
|
||||
private Long lastModifiedTime;
|
||||
|
||||
@JsonProperty("Events")
|
||||
private List<AcceleratorEvent> events = new ArrayList<>();
|
||||
|
||||
public Accelerator() {}
|
||||
|
||||
public String getAcceleratorArn() { return acceleratorArn; }
|
||||
public void setAcceleratorArn(String acceleratorArn) { this.acceleratorArn = acceleratorArn; }
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
public String getIpAddressType() { return ipAddressType; }
|
||||
public void setIpAddressType(String ipAddressType) { this.ipAddressType = ipAddressType; }
|
||||
|
||||
public Boolean getEnabled() { return enabled; }
|
||||
public void setEnabled(Boolean enabled) { this.enabled = enabled; }
|
||||
|
||||
public List<IpSet> getIpSets() { return ipSets; }
|
||||
public void setIpSets(List<IpSet> ipSets) { this.ipSets = ipSets != null ? ipSets : new ArrayList<>(); }
|
||||
|
||||
public String getDnsName() { return dnsName; }
|
||||
public void setDnsName(String dnsName) { this.dnsName = dnsName; }
|
||||
|
||||
public String getDualStackDnsName() { return dualStackDnsName; }
|
||||
public void setDualStackDnsName(String dualStackDnsName) { this.dualStackDnsName = dualStackDnsName; }
|
||||
|
||||
public String getStatus() { return status; }
|
||||
public void setStatus(String status) { this.status = status; }
|
||||
|
||||
public Long getCreatedTime() { return createdTime; }
|
||||
public void setCreatedTime(Long createdTime) { this.createdTime = createdTime; }
|
||||
|
||||
public Long getLastModifiedTime() { return lastModifiedTime; }
|
||||
public void setLastModifiedTime(Long lastModifiedTime) { this.lastModifiedTime = lastModifiedTime; }
|
||||
|
||||
public List<AcceleratorEvent> getEvents() { return events; }
|
||||
public void setEvents(List<AcceleratorEvent> events) {
|
||||
this.events = events != null ? events : new ArrayList<>();
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package io.github.hectorvent.floci.services.globalaccelerator.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class AcceleratorAttributes {
|
||||
|
||||
@JsonProperty("FlowLogsEnabled")
|
||||
private Boolean flowLogsEnabled;
|
||||
|
||||
@JsonProperty("FlowLogsS3Bucket")
|
||||
private String flowLogsS3Bucket;
|
||||
|
||||
@JsonProperty("FlowLogsS3Prefix")
|
||||
private String flowLogsS3Prefix;
|
||||
|
||||
public AcceleratorAttributes() {}
|
||||
|
||||
public Boolean getFlowLogsEnabled() { return flowLogsEnabled; }
|
||||
public void setFlowLogsEnabled(Boolean flowLogsEnabled) { this.flowLogsEnabled = flowLogsEnabled; }
|
||||
|
||||
public String getFlowLogsS3Bucket() { return flowLogsS3Bucket; }
|
||||
public void setFlowLogsS3Bucket(String flowLogsS3Bucket) { this.flowLogsS3Bucket = flowLogsS3Bucket; }
|
||||
|
||||
public String getFlowLogsS3Prefix() { return flowLogsS3Prefix; }
|
||||
public void setFlowLogsS3Prefix(String flowLogsS3Prefix) { this.flowLogsS3Prefix = flowLogsS3Prefix; }
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package io.github.hectorvent.floci.services.globalaccelerator.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class AcceleratorEvent {
|
||||
|
||||
@JsonProperty("Message")
|
||||
private String message;
|
||||
|
||||
@JsonProperty("Timestamp")
|
||||
private Long timestamp;
|
||||
|
||||
public AcceleratorEvent() {}
|
||||
|
||||
public String getMessage() { return message; }
|
||||
public void setMessage(String message) { this.message = message; }
|
||||
|
||||
public Long getTimestamp() { return timestamp; }
|
||||
public void setTimestamp(Long timestamp) { this.timestamp = timestamp; }
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package io.github.hectorvent.floci.services.globalaccelerator.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class EndpointDescription {
|
||||
|
||||
@JsonProperty("EndpointId")
|
||||
private String endpointId;
|
||||
|
||||
@JsonProperty("Weight")
|
||||
private Integer weight;
|
||||
|
||||
@JsonProperty("HealthState")
|
||||
private String healthState;
|
||||
|
||||
@JsonProperty("ClientIPPreservationEnabled")
|
||||
private Boolean clientIpPreservationEnabled;
|
||||
|
||||
public EndpointDescription() {}
|
||||
|
||||
public String getEndpointId() { return endpointId; }
|
||||
public void setEndpointId(String endpointId) { this.endpointId = endpointId; }
|
||||
|
||||
public Integer getWeight() { return weight; }
|
||||
public void setWeight(Integer weight) { this.weight = weight; }
|
||||
|
||||
public String getHealthState() { return healthState; }
|
||||
public void setHealthState(String healthState) { this.healthState = healthState; }
|
||||
|
||||
public Boolean getClientIpPreservationEnabled() { return clientIpPreservationEnabled; }
|
||||
public void setClientIpPreservationEnabled(Boolean clientIpPreservationEnabled) {
|
||||
this.clientIpPreservationEnabled = clientIpPreservationEnabled;
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package io.github.hectorvent.floci.services.globalaccelerator.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class EndpointGroup {
|
||||
|
||||
@JsonProperty("EndpointGroupArn")
|
||||
private String endpointGroupArn;
|
||||
|
||||
@JsonProperty("EndpointGroupRegion")
|
||||
private String endpointGroupRegion;
|
||||
|
||||
@JsonProperty("EndpointDescriptions")
|
||||
private List<EndpointDescription> endpointDescriptions = new ArrayList<>();
|
||||
|
||||
@JsonProperty("TrafficDialPercentage")
|
||||
private Float trafficDialPercentage;
|
||||
|
||||
@JsonProperty("HealthCheckPort")
|
||||
private Integer healthCheckPort;
|
||||
|
||||
@JsonProperty("HealthCheckProtocol")
|
||||
private String healthCheckProtocol;
|
||||
|
||||
@JsonProperty("HealthCheckPath")
|
||||
private String healthCheckPath;
|
||||
|
||||
@JsonProperty("HealthCheckIntervalSeconds")
|
||||
private Integer healthCheckIntervalSeconds;
|
||||
|
||||
@JsonProperty("ThresholdCount")
|
||||
private Integer thresholdCount;
|
||||
|
||||
@JsonProperty("PortOverrides")
|
||||
private List<PortOverride> portOverrides = new ArrayList<>();
|
||||
|
||||
public EndpointGroup() {}
|
||||
|
||||
public String getEndpointGroupArn() { return endpointGroupArn; }
|
||||
public void setEndpointGroupArn(String endpointGroupArn) { this.endpointGroupArn = endpointGroupArn; }
|
||||
|
||||
public String getEndpointGroupRegion() { return endpointGroupRegion; }
|
||||
public void setEndpointGroupRegion(String endpointGroupRegion) { this.endpointGroupRegion = endpointGroupRegion; }
|
||||
|
||||
public List<EndpointDescription> getEndpointDescriptions() { return endpointDescriptions; }
|
||||
public void setEndpointDescriptions(List<EndpointDescription> endpointDescriptions) {
|
||||
this.endpointDescriptions = endpointDescriptions != null ? endpointDescriptions : new ArrayList<>();
|
||||
}
|
||||
|
||||
public Float getTrafficDialPercentage() { return trafficDialPercentage; }
|
||||
public void setTrafficDialPercentage(Float trafficDialPercentage) { this.trafficDialPercentage = trafficDialPercentage; }
|
||||
|
||||
public Integer getHealthCheckPort() { return healthCheckPort; }
|
||||
public void setHealthCheckPort(Integer healthCheckPort) { this.healthCheckPort = healthCheckPort; }
|
||||
|
||||
public String getHealthCheckProtocol() { return healthCheckProtocol; }
|
||||
public void setHealthCheckProtocol(String healthCheckProtocol) { this.healthCheckProtocol = healthCheckProtocol; }
|
||||
|
||||
public String getHealthCheckPath() { return healthCheckPath; }
|
||||
public void setHealthCheckPath(String healthCheckPath) { this.healthCheckPath = healthCheckPath; }
|
||||
|
||||
public Integer getHealthCheckIntervalSeconds() { return healthCheckIntervalSeconds; }
|
||||
public void setHealthCheckIntervalSeconds(Integer healthCheckIntervalSeconds) {
|
||||
this.healthCheckIntervalSeconds = healthCheckIntervalSeconds;
|
||||
}
|
||||
|
||||
public Integer getThresholdCount() { return thresholdCount; }
|
||||
public void setThresholdCount(Integer thresholdCount) { this.thresholdCount = thresholdCount; }
|
||||
|
||||
public List<PortOverride> getPortOverrides() { return portOverrides; }
|
||||
public void setPortOverrides(List<PortOverride> portOverrides) {
|
||||
this.portOverrides = portOverrides != null ? portOverrides : new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package io.github.hectorvent.floci.services.globalaccelerator.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class IpSet {
|
||||
|
||||
@JsonProperty("IpFamily")
|
||||
private String ipFamily;
|
||||
|
||||
@JsonProperty("IpAddresses")
|
||||
private List<String> ipAddresses = new ArrayList<>();
|
||||
|
||||
@JsonProperty("IpAddressFamily")
|
||||
private String ipAddressFamily;
|
||||
|
||||
public IpSet() {}
|
||||
|
||||
public String getIpFamily() { return ipFamily; }
|
||||
public void setIpFamily(String ipFamily) { this.ipFamily = ipFamily; }
|
||||
|
||||
public List<String> getIpAddresses() { return ipAddresses; }
|
||||
public void setIpAddresses(List<String> ipAddresses) {
|
||||
this.ipAddresses = ipAddresses != null ? ipAddresses : new ArrayList<>();
|
||||
}
|
||||
|
||||
public String getIpAddressFamily() { return ipAddressFamily; }
|
||||
public void setIpAddressFamily(String ipAddressFamily) { this.ipAddressFamily = ipAddressFamily; }
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package io.github.hectorvent.floci.services.globalaccelerator.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class Listener {
|
||||
|
||||
@JsonProperty("ListenerArn")
|
||||
private String listenerArn;
|
||||
|
||||
@JsonProperty("PortRanges")
|
||||
private List<PortRange> portRanges = new ArrayList<>();
|
||||
|
||||
@JsonProperty("Protocol")
|
||||
private String protocol;
|
||||
|
||||
@JsonProperty("ClientAffinity")
|
||||
private String clientAffinity;
|
||||
|
||||
public Listener() {}
|
||||
|
||||
public String getListenerArn() { return listenerArn; }
|
||||
public void setListenerArn(String listenerArn) { this.listenerArn = listenerArn; }
|
||||
|
||||
public List<PortRange> getPortRanges() { return portRanges; }
|
||||
public void setPortRanges(List<PortRange> portRanges) {
|
||||
this.portRanges = portRanges != null ? portRanges : new ArrayList<>();
|
||||
}
|
||||
|
||||
public String getProtocol() { return protocol; }
|
||||
public void setProtocol(String protocol) { this.protocol = protocol; }
|
||||
|
||||
public String getClientAffinity() { return clientAffinity; }
|
||||
public void setClientAffinity(String clientAffinity) { this.clientAffinity = clientAffinity; }
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package io.github.hectorvent.floci.services.globalaccelerator.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class PortOverride {
|
||||
|
||||
@JsonProperty("ListenerPort")
|
||||
private Integer listenerPort;
|
||||
|
||||
@JsonProperty("EndpointPort")
|
||||
private Integer endpointPort;
|
||||
|
||||
public PortOverride() {}
|
||||
|
||||
public Integer getListenerPort() { return listenerPort; }
|
||||
public void setListenerPort(Integer listenerPort) { this.listenerPort = listenerPort; }
|
||||
|
||||
public Integer getEndpointPort() { return endpointPort; }
|
||||
public void setEndpointPort(Integer endpointPort) { this.endpointPort = endpointPort; }
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package io.github.hectorvent.floci.services.globalaccelerator.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class PortRange {
|
||||
|
||||
@JsonProperty("FromPort")
|
||||
private Integer fromPort;
|
||||
|
||||
@JsonProperty("ToPort")
|
||||
private Integer toPort;
|
||||
|
||||
public PortRange() {}
|
||||
|
||||
public Integer getFromPort() { return fromPort; }
|
||||
public void setFromPort(Integer fromPort) { this.fromPort = fromPort; }
|
||||
|
||||
public Integer getToPort() { return toPort; }
|
||||
public void setToPort(Integer toPort) { this.toPort = toPort; }
|
||||
}
|
||||
@@ -683,6 +683,8 @@ floci:
|
||||
enabled: true
|
||||
cognitoidentity:
|
||||
enabled: true
|
||||
globalaccelerator:
|
||||
enabled: true
|
||||
aps:
|
||||
enabled: true
|
||||
lakeformation:
|
||||
|
||||
+728
@@ -0,0 +1,728 @@
|
||||
package io.github.hectorvent.floci.services.globalaccelerator;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class GlobalAcceleratorIntegrationTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String TARGET = "GlobalAccelerator_V20180706.";
|
||||
|
||||
/** The AWS SDK homes Global Accelerator in us-west-2 and signs every request there. */
|
||||
private static final String AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260215/us-west-2/globalaccelerator/aws4_request";
|
||||
private static final String AUTH_OTHER_REGION =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260215/eu-west-1/globalaccelerator/aws4_request";
|
||||
|
||||
private static String acceleratorArn;
|
||||
private static String listenerArn;
|
||||
private static String endpointGroupArn;
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static RequestSpecification call(String action, String body) {
|
||||
return signedCall(AUTH, action, body);
|
||||
}
|
||||
|
||||
private static RequestSpecification signedCall(String authorization, String action, String body) {
|
||||
return given()
|
||||
.header("Authorization", authorization)
|
||||
.header("X-Amz-Target", TARGET + action)
|
||||
.contentType(CONTENT_TYPE)
|
||||
.body(body);
|
||||
}
|
||||
|
||||
// Accelerator
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void createAcceleratorIsDeployedWithStaticIps() {
|
||||
acceleratorArn = call("CreateAccelerator", """
|
||||
{
|
||||
"Name": "edge-accelerator",
|
||||
"IdempotencyToken": "token-create-accelerator",
|
||||
"Enabled": true,
|
||||
"Tags": [{ "Key": "env", "Value": "test" }]
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Accelerator.Name", equalTo("edge-accelerator"))
|
||||
.body("Accelerator.Status", equalTo("DEPLOYED"))
|
||||
.body("Accelerator.Enabled", equalTo(true))
|
||||
.body("Accelerator.IpAddressType", equalTo("IPV4"))
|
||||
.body("Accelerator.DnsName", endsWith(".awsglobalaccelerator.com"))
|
||||
.body("Accelerator.IpSets", hasSize(1))
|
||||
.body("Accelerator.IpSets[0].IpFamily", equalTo("IPv4"))
|
||||
.body("Accelerator.IpSets[0].IpAddressFamily", equalTo("IPv4"))
|
||||
.body("Accelerator.IpSets[0].IpAddresses", hasSize(2))
|
||||
.body("Accelerator.CreatedTime", notNullValue())
|
||||
.body("Accelerator.Events", hasSize(0))
|
||||
.extract().path("Accelerator.AcceleratorArn");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void acceleratorArnIsGlobalWithEmptyRegionSegment() {
|
||||
assertTrue(acceleratorArn.startsWith("arn:aws:globalaccelerator::"),
|
||||
"Global Accelerator ARNs carry an empty region segment, got: " + acceleratorArn);
|
||||
assertTrue(acceleratorArn.contains(":accelerator/"),
|
||||
"Accelerator ARN should carry an accelerator/ resource segment, got: " + acceleratorArn);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void describeAcceleratorReturnsTerminalStatus() {
|
||||
call("DescribeAccelerator", "{\"AcceleratorArn\":\"" + acceleratorArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Accelerator.AcceleratorArn", equalTo(acceleratorArn))
|
||||
.body("Accelerator.Status", equalTo("DEPLOYED"))
|
||||
.body("Accelerator.Name", equalTo("edge-accelerator"))
|
||||
.body("Accelerator.IpSets[0].IpAddresses", hasSize(2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Global Accelerator is a global service, so a caller that signs under another Region sees
|
||||
* the same accelerators. Only the account partitions the state.
|
||||
*/
|
||||
@Test
|
||||
@Order(13)
|
||||
void anotherSigningRegionSeesTheSameAccelerator() {
|
||||
signedCall(AUTH_OTHER_REGION, "DescribeAccelerator",
|
||||
"{\"AcceleratorArn\":\"" + acceleratorArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Accelerator.AcceleratorArn", equalTo(acceleratorArn));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(14)
|
||||
void listAcceleratorsIncludesCreatedAccelerator() {
|
||||
call("ListAccelerators", "{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Accelerators.AcceleratorArn", hasItem(acceleratorArn));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(15)
|
||||
void createAcceleratorTagsAreReadableWithListTagsForResource() {
|
||||
call("ListTagsForResource", "{\"ResourceArn\":\"" + acceleratorArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags", hasSize(1))
|
||||
.body("Tags[0].Key", equalTo("env"))
|
||||
.body("Tags[0].Value", equalTo("test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(16)
|
||||
void describeAcceleratorAttributesDefaultsToFlowLogsDisabled() {
|
||||
call("DescribeAcceleratorAttributes", "{\"AcceleratorArn\":\"" + acceleratorArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("AcceleratorAttributes.FlowLogsEnabled", equalTo(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(17)
|
||||
void enablingFlowLogsWithoutABucketIsRejected() {
|
||||
call("UpdateAcceleratorAttributes", """
|
||||
{ "AcceleratorArn": "%s", "FlowLogsEnabled": true }
|
||||
""".formatted(acceleratorArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidArgumentException"));
|
||||
|
||||
call("DescribeAcceleratorAttributes", "{\"AcceleratorArn\":\"" + acceleratorArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("AcceleratorAttributes.FlowLogsEnabled", equalTo(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(18)
|
||||
void updateAcceleratorAttributesPersists() {
|
||||
call("UpdateAcceleratorAttributes", """
|
||||
{
|
||||
"AcceleratorArn": "%s",
|
||||
"FlowLogsEnabled": true,
|
||||
"FlowLogsS3Bucket": "flow-logs-bucket",
|
||||
"FlowLogsS3Prefix": "gax/"
|
||||
}
|
||||
""".formatted(acceleratorArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("AcceleratorAttributes.FlowLogsEnabled", equalTo(true))
|
||||
.body("AcceleratorAttributes.FlowLogsS3Bucket", equalTo("flow-logs-bucket"));
|
||||
|
||||
call("DescribeAcceleratorAttributes", "{\"AcceleratorArn\":\"" + acceleratorArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("AcceleratorAttributes.FlowLogsS3Prefix", equalTo("gax/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(19)
|
||||
void updateAcceleratorRenamesAndStaysDeployed() {
|
||||
call("UpdateAccelerator", """
|
||||
{ "AcceleratorArn": "%s", "Name": "edge-accelerator-v2" }
|
||||
""".formatted(acceleratorArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Accelerator.Name", equalTo("edge-accelerator-v2"))
|
||||
.body("Accelerator.Status", equalTo("DEPLOYED"));
|
||||
}
|
||||
|
||||
// Listener
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
void createListenerEchoesPortRanges() {
|
||||
listenerArn = call("CreateListener", """
|
||||
{
|
||||
"AcceleratorArn": "%s",
|
||||
"IdempotencyToken": "token-create-listener",
|
||||
"Protocol": "TCP",
|
||||
"PortRanges": [{ "FromPort": 80, "ToPort": 81 }]
|
||||
}
|
||||
""".formatted(acceleratorArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Listener.Protocol", equalTo("TCP"))
|
||||
.body("Listener.ClientAffinity", equalTo("NONE"))
|
||||
.body("Listener.PortRanges", hasSize(1))
|
||||
.body("Listener.PortRanges[0].FromPort", equalTo(80))
|
||||
.body("Listener.PortRanges[0].ToPort", equalTo(81))
|
||||
.extract().path("Listener.ListenerArn");
|
||||
|
||||
assertTrue(listenerArn.startsWith(acceleratorArn + "/listener/"),
|
||||
"Listener ARN extends the accelerator ARN, got: " + listenerArn);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(21)
|
||||
void describeListenerReturnsCreatedListener() {
|
||||
call("DescribeListener", "{\"ListenerArn\":\"" + listenerArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Listener.ListenerArn", equalTo(listenerArn))
|
||||
.body("Listener.Protocol", equalTo("TCP"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(22)
|
||||
void listListenersIsScopedToTheAccelerator() {
|
||||
call("ListListeners", "{\"AcceleratorArn\":\"" + acceleratorArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Listeners", hasSize(1))
|
||||
.body("Listeners[0].ListenerArn", equalTo(listenerArn));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(23)
|
||||
void updateListenerChangesClientAffinity() {
|
||||
call("UpdateListener", """
|
||||
{ "ListenerArn": "%s", "ClientAffinity": "SOURCE_IP" }
|
||||
""".formatted(listenerArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Listener.ClientAffinity", equalTo("SOURCE_IP"))
|
||||
.body("Listener.PortRanges[0].FromPort", equalTo(80));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(24)
|
||||
void createListenerWithInvalidPortRangeIsRejected() {
|
||||
call("CreateListener", """
|
||||
{
|
||||
"AcceleratorArn": "%s",
|
||||
"IdempotencyToken": "token-bad-ports",
|
||||
"Protocol": "TCP",
|
||||
"PortRanges": [{ "FromPort": 900, "ToPort": 80 }]
|
||||
}
|
||||
""".formatted(acceleratorArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidPortRangeException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(25)
|
||||
void createListenerWithAnUnknownProtocolIsRejected() {
|
||||
call("CreateListener", """
|
||||
{
|
||||
"AcceleratorArn": "%s",
|
||||
"IdempotencyToken": "token-bad-protocol",
|
||||
"Protocol": "QUIC",
|
||||
"PortRanges": [{ "FromPort": 80, "ToPort": 80 }]
|
||||
}
|
||||
""".formatted(acceleratorArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidArgumentException"));
|
||||
}
|
||||
|
||||
// Endpoint group
|
||||
|
||||
@Test
|
||||
@Order(30)
|
||||
void createEndpointGroupReportsHealthyEndpointsAndDefaults() {
|
||||
endpointGroupArn = call("CreateEndpointGroup", """
|
||||
{
|
||||
"ListenerArn": "%s",
|
||||
"EndpointGroupRegion": "us-west-2",
|
||||
"IdempotencyToken": "token-create-endpoint-group",
|
||||
"EndpointConfigurations": [
|
||||
{ "EndpointId": "i-0123456789abcdef0", "Weight": 50 }
|
||||
]
|
||||
}
|
||||
""".formatted(listenerArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("EndpointGroup.EndpointGroupRegion", equalTo("us-west-2"))
|
||||
.body("EndpointGroup.TrafficDialPercentage", equalTo(100.0f))
|
||||
.body("EndpointGroup.HealthCheckProtocol", equalTo("TCP"))
|
||||
.body("EndpointGroup.HealthCheckPath", equalTo("/"))
|
||||
.body("EndpointGroup.HealthCheckIntervalSeconds", equalTo(30))
|
||||
.body("EndpointGroup.HealthCheckPort", equalTo(80))
|
||||
.body("EndpointGroup.ThresholdCount", equalTo(3))
|
||||
.body("EndpointGroup.PortOverrides", hasSize(0))
|
||||
.body("EndpointGroup.EndpointDescriptions", hasSize(1))
|
||||
.body("EndpointGroup.EndpointDescriptions[0].EndpointId", equalTo("i-0123456789abcdef0"))
|
||||
.body("EndpointGroup.EndpointDescriptions[0].Weight", equalTo(50))
|
||||
.body("EndpointGroup.EndpointDescriptions[0].HealthState", equalTo("HEALTHY"))
|
||||
.extract().path("EndpointGroup.EndpointGroupArn");
|
||||
|
||||
assertTrue(endpointGroupArn.startsWith(listenerArn + "/endpoint-group/"),
|
||||
"Endpoint group ARN extends the listener ARN, got: " + endpointGroupArn);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(31)
|
||||
void describeEndpointGroupReturnsCreatedGroup() {
|
||||
call("DescribeEndpointGroup", "{\"EndpointGroupArn\":\"" + endpointGroupArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("EndpointGroup.EndpointGroupArn", equalTo(endpointGroupArn))
|
||||
.body("EndpointGroup.EndpointDescriptions[0].HealthState", equalTo("HEALTHY"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(32)
|
||||
void listEndpointGroupsIsScopedToTheListener() {
|
||||
call("ListEndpointGroups", "{\"ListenerArn\":\"" + listenerArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("EndpointGroups", hasSize(1))
|
||||
.body("EndpointGroups[0].EndpointGroupArn", equalTo(endpointGroupArn));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(33)
|
||||
void secondEndpointGroupInSameRegionIsRejected() {
|
||||
call("CreateEndpointGroup", """
|
||||
{
|
||||
"ListenerArn": "%s",
|
||||
"EndpointGroupRegion": "us-west-2",
|
||||
"IdempotencyToken": "token-duplicate-region"
|
||||
}
|
||||
""".formatted(listenerArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("EndpointGroupAlreadyExistsException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(34)
|
||||
void updateEndpointGroupChangesHealthCheckAndTrafficDial() {
|
||||
call("UpdateEndpointGroup", """
|
||||
{
|
||||
"EndpointGroupArn": "%s",
|
||||
"TrafficDialPercentage": 50,
|
||||
"HealthCheckProtocol": "HTTP",
|
||||
"HealthCheckPath": "/healthz",
|
||||
"HealthCheckIntervalSeconds": 10,
|
||||
"ThresholdCount": 2,
|
||||
"PortOverrides": [{ "ListenerPort": 80, "EndpointPort": 8080 }]
|
||||
}
|
||||
""".formatted(endpointGroupArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("EndpointGroup.TrafficDialPercentage", equalTo(50.0f))
|
||||
.body("EndpointGroup.HealthCheckProtocol", equalTo("HTTP"))
|
||||
.body("EndpointGroup.HealthCheckPath", equalTo("/healthz"))
|
||||
.body("EndpointGroup.HealthCheckIntervalSeconds", equalTo(10))
|
||||
.body("EndpointGroup.ThresholdCount", equalTo(2))
|
||||
.body("EndpointGroup.PortOverrides[0].EndpointPort", equalTo(8080));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(35)
|
||||
void healthCheckIntervalBelowTheModelMinimumIsRejected() {
|
||||
call("UpdateEndpointGroup", """
|
||||
{ "EndpointGroupArn": "%s", "HealthCheckIntervalSeconds": 5 }
|
||||
""".formatted(endpointGroupArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidArgumentException"));
|
||||
|
||||
call("DescribeEndpointGroup", "{\"EndpointGroupArn\":\"" + endpointGroupArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("EndpointGroup.HealthCheckIntervalSeconds", equalTo(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(36)
|
||||
void addEndpointsAppendsToTheGroup() {
|
||||
call("AddEndpoints", """
|
||||
{
|
||||
"EndpointGroupArn": "%s",
|
||||
"EndpointConfigurations": [
|
||||
{ "EndpointId": "i-abcdef01234567890", "Weight": 10, "ClientIPPreservationEnabled": true }
|
||||
]
|
||||
}
|
||||
""".formatted(endpointGroupArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("EndpointGroupArn", equalTo(endpointGroupArn))
|
||||
.body("EndpointDescriptions", hasSize(2))
|
||||
.body("EndpointDescriptions.EndpointId", hasItem("i-abcdef01234567890"))
|
||||
.body("EndpointDescriptions.HealthState", contains("HEALTHY", "HEALTHY"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(37)
|
||||
void removeEndpointsDropsTheEndpoint() {
|
||||
call("RemoveEndpoints", """
|
||||
{
|
||||
"EndpointGroupArn": "%s",
|
||||
"EndpointIdentifiers": [{ "EndpointId": "i-abcdef01234567890" }]
|
||||
}
|
||||
""".formatted(endpointGroupArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
call("DescribeEndpointGroup", "{\"EndpointGroupArn\":\"" + endpointGroupArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("EndpointGroup.EndpointDescriptions", hasSize(1))
|
||||
.body("EndpointGroup.EndpointDescriptions.EndpointId", not(hasItem("i-abcdef01234567890")));
|
||||
}
|
||||
|
||||
// Tags
|
||||
|
||||
@Test
|
||||
@Order(40)
|
||||
void tagAndUntagListener() {
|
||||
call("TagResource", """
|
||||
{ "ResourceArn": "%s", "Tags": [{ "Key": "team", "Value": "platform" }] }
|
||||
""".formatted(listenerArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
call("ListTagsForResource", "{\"ResourceArn\":\"" + listenerArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags[0].Key", equalTo("team"))
|
||||
.body("Tags[0].Value", equalTo("platform"));
|
||||
|
||||
call("UntagResource", """
|
||||
{ "ResourceArn": "%s", "TagKeys": ["team"] }
|
||||
""".formatted(listenerArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
call("ListTagsForResource", "{\"ResourceArn\":\"" + listenerArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags", hasSize(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(41)
|
||||
void listTagsForUnknownAcceleratorReturnsAcceleratorNotFound() {
|
||||
call("ListTagsForResource",
|
||||
"{\"ResourceArn\":\"arn:aws:globalaccelerator::000000000000:accelerator/does-not-exist\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("AcceleratorNotFoundException"));
|
||||
}
|
||||
|
||||
// Dual stack and BYOIP
|
||||
|
||||
@Test
|
||||
@Order(50)
|
||||
void dualStackAcceleratorCarriesTwoIpSetsAndADualStackDnsName() {
|
||||
String dualStackArn = call("CreateAccelerator", """
|
||||
{
|
||||
"Name": "dual-stack-accelerator",
|
||||
"IdempotencyToken": "token-dual-stack",
|
||||
"IpAddressType": "DUAL_STACK",
|
||||
"Enabled": false
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Accelerator.IpAddressType", equalTo("DUAL_STACK"))
|
||||
.body("Accelerator.IpSets", hasSize(2))
|
||||
.body("Accelerator.IpSets[1].IpAddressFamily", equalTo("IPv6"))
|
||||
.body("Accelerator.IpSets[1].IpAddresses", hasSize(2))
|
||||
.body("Accelerator.DualStackDnsName", endsWith(".dualstack.awsglobalaccelerator.com"))
|
||||
.extract().path("Accelerator.AcceleratorArn");
|
||||
|
||||
call("DeleteAccelerator", "{\"AcceleratorArn\":\"" + dualStackArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(51)
|
||||
void byoipAddressesArePinnedOnTheAccelerator() {
|
||||
String byoipArn = call("CreateAccelerator", """
|
||||
{
|
||||
"Name": "byoip-accelerator",
|
||||
"IdempotencyToken": "token-byoip",
|
||||
"Enabled": false,
|
||||
"IpAddresses": ["198.51.100.10", "198.51.100.11"]
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Accelerator.IpSets[0].IpAddresses", contains("198.51.100.10", "198.51.100.11"))
|
||||
.extract().path("Accelerator.AcceleratorArn");
|
||||
|
||||
call("DeleteAccelerator", "{\"AcceleratorArn\":\"" + byoipArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
// Teardown, exercising the delete guards on the way out
|
||||
|
||||
@Test
|
||||
@Order(60)
|
||||
void deleteEnabledAcceleratorIsRejected() {
|
||||
call("DeleteAccelerator", "{\"AcceleratorArn\":\"" + acceleratorArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("AcceleratorNotDisabledException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(61)
|
||||
void deleteListenerWithEndpointGroupIsRejected() {
|
||||
call("DeleteListener", "{\"ListenerArn\":\"" + listenerArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("AssociatedEndpointGroupFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(62)
|
||||
void deleteEndpointGroupThenDescribeReturnsNotFound() {
|
||||
call("DeleteEndpointGroup", "{\"EndpointGroupArn\":\"" + endpointGroupArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
call("DescribeEndpointGroup", "{\"EndpointGroupArn\":\"" + endpointGroupArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("EndpointGroupNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(63)
|
||||
void deleteAcceleratorWithListenerIsRejected() {
|
||||
call("UpdateAccelerator", """
|
||||
{ "AcceleratorArn": "%s", "Enabled": false }
|
||||
""".formatted(acceleratorArn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Accelerator.Enabled", equalTo(false));
|
||||
|
||||
call("DeleteAccelerator", "{\"AcceleratorArn\":\"" + acceleratorArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("AssociatedListenerFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(64)
|
||||
void deleteListenerThenDescribeReturnsNotFound() {
|
||||
call("DeleteListener", "{\"ListenerArn\":\"" + listenerArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
call("DescribeListener", "{\"ListenerArn\":\"" + listenerArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ListenerNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(65)
|
||||
void deleteAcceleratorThenDescribeReturnsNotFound() {
|
||||
call("DeleteAccelerator", "{\"AcceleratorArn\":\"" + acceleratorArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
call("DescribeAccelerator", "{\"AcceleratorArn\":\"" + acceleratorArn + "\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("AcceleratorNotFoundException"))
|
||||
.body("message", containsString(acceleratorArn));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(66)
|
||||
void unsupportedOperationFailsFast() {
|
||||
call("ProvisionByoipCidr", "{\"Cidr\":\"198.51.100.0/24\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("UnknownOperationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(67)
|
||||
void listAcceleratorsStillRespondsAfterTeardown() {
|
||||
call("ListAccelerators", "{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Accelerators", hasSize(greaterThanOrEqualTo(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(68)
|
||||
void createAcceleratorRejectsAMissingName() {
|
||||
call("CreateAccelerator", "{\"IdempotencyToken\":\"token-no-name\"}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidArgumentException"))
|
||||
.body("message", startsWith("Name"));
|
||||
}
|
||||
}
|
||||
+589
@@ -0,0 +1,589 @@
|
||||
package io.github.hectorvent.floci.services.globalaccelerator;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.globalaccelerator.model.Accelerator;
|
||||
import io.github.hectorvent.floci.services.globalaccelerator.model.AcceleratorAttributes;
|
||||
import io.github.hectorvent.floci.services.globalaccelerator.model.EndpointGroup;
|
||||
import io.github.hectorvent.floci.services.globalaccelerator.model.Listener;
|
||||
import io.github.hectorvent.floci.services.globalaccelerator.model.PortOverride;
|
||||
import io.github.hectorvent.floci.services.globalaccelerator.model.PortRange;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class GlobalAcceleratorServiceTest {
|
||||
|
||||
private static final String ACCOUNT = "000000000000";
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private GlobalAcceleratorService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
StorageFactory storageFactory = mock(StorageFactory.class);
|
||||
RegionResolver regionResolver = mock(RegionResolver.class);
|
||||
when(regionResolver.getAccountId()).thenReturn(ACCOUNT);
|
||||
when(regionResolver.buildArn(anyString(), anyString(), anyString())).thenAnswer(invocation ->
|
||||
AwsArnUtils.Arn.of(invocation.getArgument(0), invocation.getArgument(1),
|
||||
ACCOUNT, invocation.getArgument(2)).toString());
|
||||
when(storageFactory.create(anyString(), anyString(), any()))
|
||||
.thenAnswer(invocation -> AccountAwareStorageBackend.inMemory(ACCOUNT));
|
||||
|
||||
service = new GlobalAcceleratorService(storageFactory, regionResolver);
|
||||
}
|
||||
|
||||
@Test
|
||||
void acceleratorArnCarriesAnEmptyRegionSegment() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, Map.of());
|
||||
|
||||
assertTrue(accelerator.getAcceleratorArn().startsWith("arn:aws:globalaccelerator::" + ACCOUNT + ":accelerator/"),
|
||||
"unexpected ARN: " + accelerator.getAcceleratorArn());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAcceleratorAppliesAwsDefaults() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, null);
|
||||
|
||||
assertEquals("IPV4", accelerator.getIpAddressType());
|
||||
assertEquals(Boolean.TRUE, accelerator.getEnabled());
|
||||
assertEquals("DEPLOYED", accelerator.getStatus());
|
||||
assertEquals(1, accelerator.getIpSets().size());
|
||||
assertEquals("IPv4", accelerator.getIpSets().get(0).getIpAddressFamily());
|
||||
assertEquals(2, accelerator.getIpSets().get(0).getIpAddresses().size());
|
||||
assertTrue(accelerator.getDnsName().endsWith(".awsglobalaccelerator.com"));
|
||||
assertNull(accelerator.getDualStackDnsName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void dualStackAcceleratorGetsAnIpv6SetAndADualStackDnsName() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", "DUAL_STACK", null, null, null);
|
||||
|
||||
assertEquals(2, accelerator.getIpSets().size());
|
||||
assertEquals("IPv6", accelerator.getIpSets().get(1).getIpAddressFamily());
|
||||
assertTrue(accelerator.getDualStackDnsName().endsWith(".dualstack.awsglobalaccelerator.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void byoipAddressesArePinnedAndShortfallIsFilled() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, List.of("198.51.100.10"), null, null);
|
||||
|
||||
List<String> addresses = accelerator.getIpSets().get(0).getIpAddresses();
|
||||
assertEquals(2, addresses.size());
|
||||
assertEquals("198.51.100.10", addresses.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAcceleratorRejectsAnUnknownIpAddressType() {
|
||||
AwsException failure = assertThrows(AwsException.class,
|
||||
() -> service.createAccelerator("edge", "IPV6", null, null, null));
|
||||
|
||||
assertEquals("InvalidArgumentException", failure.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeUnknownAcceleratorReportsAcceleratorNotFound() {
|
||||
AwsException failure = assertThrows(AwsException.class,
|
||||
() -> service.describeAccelerator("arn:aws:globalaccelerator::" + ACCOUNT + ":accelerator/missing"));
|
||||
|
||||
assertEquals("AcceleratorNotFoundException", failure.getErrorCode());
|
||||
assertEquals(400, failure.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void switchingBackToIpv4ClearsTheDualStackDnsName() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", "DUAL_STACK", null, null, null);
|
||||
|
||||
Accelerator updated = service.updateAccelerator(accelerator.getAcceleratorArn(),
|
||||
null, "IPV4", null, null);
|
||||
|
||||
assertEquals(1, updated.getIpSets().size());
|
||||
assertNull(updated.getDualStackDnsName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void enabledAcceleratorCannotBeDeleted() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, true, null);
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class,
|
||||
() -> service.deleteAccelerator(accelerator.getAcceleratorArn()));
|
||||
|
||||
assertEquals("AcceleratorNotDisabledException", failure.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void acceleratorWithListenersCannotBeDeleted() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, false, null);
|
||||
service.createListener(accelerator.getAcceleratorArn(), portRange(80, 80), "TCP", null);
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class,
|
||||
() -> service.deleteAccelerator(accelerator.getAcceleratorArn()));
|
||||
|
||||
assertEquals("AssociatedListenerFoundException", failure.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void flowLogsCannotBeEnabledWithoutABucket() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, null);
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class, () ->
|
||||
service.updateAcceleratorAttributes(accelerator.getAcceleratorArn(), true, null, null));
|
||||
|
||||
assertEquals("InvalidArgumentException", failure.getErrorCode());
|
||||
assertFalse(service.describeAcceleratorAttributes(accelerator.getAcceleratorArn()).getFlowLogsEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
void acceleratorAttributesDefaultToFlowLogsDisabled() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, null);
|
||||
|
||||
AcceleratorAttributes attributes =
|
||||
service.describeAcceleratorAttributes(accelerator.getAcceleratorArn());
|
||||
|
||||
assertEquals(Boolean.FALSE, attributes.getFlowLogsEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listenerArnExtendsTheAcceleratorArnAndListingIsScopedByIt() {
|
||||
Accelerator first = service.createAccelerator("first", null, null, null, null);
|
||||
Accelerator second = service.createAccelerator("second", null, null, null, null);
|
||||
Listener listener = service.createListener(first.getAcceleratorArn(), portRange(80, 81), "TCP", null);
|
||||
|
||||
assertTrue(listener.getListenerArn().startsWith(first.getAcceleratorArn() + "/listener/"));
|
||||
assertEquals("NONE", listener.getClientAffinity());
|
||||
assertEquals(List.of(listener.getListenerArn()),
|
||||
service.listListeners(first.getAcceleratorArn()).stream().map(Listener::getListenerArn).toList());
|
||||
assertTrue(service.listListeners(second.getAcceleratorArn()).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void invertedPortRangeReportsInvalidPortRange() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, null);
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class,
|
||||
() -> service.createListener(accelerator.getAcceleratorArn(), portRange(900, 80), "TCP", null));
|
||||
|
||||
assertEquals("InvalidPortRangeException", failure.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createListenerRejectsAnUnknownClientAffinity() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, null);
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class, () ->
|
||||
service.createListener(accelerator.getAcceleratorArn(), portRange(80, 80), "TCP", "SOURCE"));
|
||||
|
||||
assertEquals("InvalidArgumentException", failure.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointGroupDefaultsFollowTheListenerAndTheAwsDefaults() {
|
||||
EndpointGroup group = endpointGroup("us-west-2", "[{\"EndpointId\":\"i-0123456789abcdef0\"}]");
|
||||
|
||||
assertEquals(100.0f, group.getTrafficDialPercentage());
|
||||
assertEquals(80, group.getHealthCheckPort());
|
||||
assertEquals("TCP", group.getHealthCheckProtocol());
|
||||
assertEquals("/", group.getHealthCheckPath());
|
||||
assertEquals(30, group.getHealthCheckIntervalSeconds());
|
||||
assertEquals(3, group.getThresholdCount());
|
||||
assertEquals(128, group.getEndpointDescriptions().get(0).getWeight());
|
||||
assertEquals("HEALTHY", group.getEndpointDescriptions().get(0).getHealthState());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aSecondEndpointGroupInTheSameRegionIsRejected() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, null);
|
||||
Listener listener = service.createListener(accelerator.getAcceleratorArn(), portRange(80, 80), "TCP", null);
|
||||
service.createEndpointGroup(listener.getListenerArn(), "us-west-2", null,
|
||||
null, null, null, null, null, null, null);
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class, () ->
|
||||
service.createEndpointGroup(listener.getListenerArn(), "us-west-2", null,
|
||||
null, null, null, null, null, null, null));
|
||||
|
||||
assertEquals("EndpointGroupAlreadyExistsException", failure.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void healthCheckIntervalOutsideTheModelRangeIsRejected() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, null);
|
||||
Listener listener = service.createListener(accelerator.getAcceleratorArn(), portRange(80, 80), "TCP", null);
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class, () ->
|
||||
service.createEndpointGroup(listener.getListenerArn(), "us-west-2", null,
|
||||
null, null, null, null, 5, null, null));
|
||||
|
||||
assertEquals("InvalidArgumentException", failure.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void trafficDialAboveOneHundredIsRejected() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, null);
|
||||
Listener listener = service.createListener(accelerator.getAcceleratorArn(), portRange(80, 80), "TCP", null);
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class, () ->
|
||||
service.createEndpointGroup(listener.getListenerArn(), "us-west-2", null,
|
||||
101.0f, null, null, null, null, null, null));
|
||||
|
||||
assertEquals("InvalidArgumentException", failure.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listenerWithEndpointGroupsCannotBeDeleted() {
|
||||
EndpointGroup group = endpointGroup("us-west-2", "[]");
|
||||
String listenerArn = group.getEndpointGroupArn().substring(0,
|
||||
group.getEndpointGroupArn().indexOf("/endpoint-group/"));
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class, () -> service.deleteListener(listenerArn));
|
||||
|
||||
assertEquals("AssociatedEndpointGroupFoundException", failure.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listEndpointGroupsOnAnUnknownListenerReportsListenerNotFound() {
|
||||
AwsException failure = assertThrows(AwsException.class,
|
||||
() -> service.listEndpointGroups("arn:aws:globalaccelerator::" + ACCOUNT
|
||||
+ ":accelerator/missing/listener/abcd1234"));
|
||||
|
||||
assertEquals("ListenerNotFoundException", failure.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void addEndpointsReplacesAnEndpointWithTheSameId() {
|
||||
EndpointGroup group = endpointGroup("us-west-2", "[{\"EndpointId\":\"i-aaaa\",\"Weight\":10}]");
|
||||
|
||||
EndpointGroup merged = service.addEndpoints(group.getEndpointGroupArn(),
|
||||
json("[{\"EndpointId\":\"i-aaaa\",\"Weight\":200},{\"EndpointId\":\"i-bbbb\"}]"));
|
||||
|
||||
assertEquals(2, merged.getEndpointDescriptions().size());
|
||||
assertEquals(200, merged.getEndpointDescriptions().get(0).getWeight());
|
||||
assertEquals("i-bbbb", merged.getEndpointDescriptions().get(1).getEndpointId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void removeEndpointsDropsOnlyTheNamedEndpoints() {
|
||||
EndpointGroup group = endpointGroup("us-west-2",
|
||||
"[{\"EndpointId\":\"i-aaaa\"},{\"EndpointId\":\"i-bbbb\"}]");
|
||||
|
||||
service.removeEndpoints(group.getEndpointGroupArn(), List.of("i-aaaa"));
|
||||
|
||||
EndpointGroup reloaded = service.describeEndpointGroup(group.getEndpointGroupArn());
|
||||
assertEquals(1, reloaded.getEndpointDescriptions().size());
|
||||
assertEquals("i-bbbb", reloaded.getEndpointDescriptions().get(0).getEndpointId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void clientIpPreservationDefaultsToTrueForApplicationLoadBalancers() {
|
||||
EndpointGroup group = endpointGroup("us-west-2",
|
||||
"[{\"EndpointId\":\"arn:aws:elasticloadbalancing:us-west-2:" + ACCOUNT
|
||||
+ ":loadbalancer/app/web/abc\"},{\"EndpointId\":\"i-aaaa\"}]");
|
||||
|
||||
assertEquals(Boolean.TRUE, group.getEndpointDescriptions().get(0).getClientIpPreservationEnabled());
|
||||
assertEquals(Boolean.FALSE, group.getEndpointDescriptions().get(1).getClientIpPreservationEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
void portOverrideWithNoEndpointPortIsRejected() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, null);
|
||||
Listener listener = service.createListener(accelerator.getAcceleratorArn(), portRange(80, 80), "TCP", null);
|
||||
PortOverride override = new PortOverride();
|
||||
override.setListenerPort(80);
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class, () ->
|
||||
service.createEndpointGroup(listener.getListenerArn(), "us-west-2", null,
|
||||
null, null, null, null, null, null, List.of(override)));
|
||||
|
||||
assertEquals("InvalidPortRangeException", failure.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagsAreScopedToTheResourceArn() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, Map.of("env", "test"));
|
||||
Listener listener = service.createListener(accelerator.getAcceleratorArn(), portRange(80, 80), "TCP", null);
|
||||
|
||||
service.tagResource(listener.getListenerArn(), Map.of("team", "platform"));
|
||||
|
||||
assertEquals(Map.of("env", "test"), service.listTagsForResource(accelerator.getAcceleratorArn()));
|
||||
assertEquals(Map.of("team", "platform"), service.listTagsForResource(listener.getListenerArn()));
|
||||
|
||||
service.untagResource(listener.getListenerArn(), List.of("team"));
|
||||
assertTrue(service.listTagsForResource(listener.getListenerArn()).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagResourceOnAnUnknownAcceleratorReportsAcceleratorNotFound() {
|
||||
AwsException failure = assertThrows(AwsException.class, () ->
|
||||
service.tagResource("arn:aws:globalaccelerator::" + ACCOUNT + ":accelerator/missing",
|
||||
Map.of("env", "test")));
|
||||
|
||||
assertEquals("AcceleratorNotFoundException", failure.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagResourceWithoutTagsIsRejected() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, null);
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class,
|
||||
() -> service.tagResource(accelerator.getAcceleratorArn(), null));
|
||||
|
||||
assertEquals("InvalidArgumentException", failure.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listenerAcceptsTenPortRanges() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, null);
|
||||
|
||||
Listener listener = service.createListener(accelerator.getAcceleratorArn(), portRanges(10), "TCP", null);
|
||||
|
||||
assertEquals(10, listener.getPortRanges().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listenerRejectsMoreThanTenPortRanges() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, null);
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class, () ->
|
||||
service.createListener(accelerator.getAcceleratorArn(), portRanges(11), "TCP", null));
|
||||
|
||||
assertEquals("InvalidArgumentException", failure.getErrorCode());
|
||||
assertTrue(failure.getMessage().contains("PortRanges"), failure.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateListenerRejectsMoreThanTenPortRanges() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, null);
|
||||
Listener listener = service.createListener(accelerator.getAcceleratorArn(), portRange(80, 80), "TCP", null);
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class, () ->
|
||||
service.updateListener(listener.getListenerArn(), portRanges(11), null, null));
|
||||
|
||||
assertEquals("InvalidArgumentException", failure.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointGroupAcceptsTenEndpointConfigurations() {
|
||||
EndpointGroup group = endpointGroup("us-west-2", endpointConfigurations(10));
|
||||
|
||||
assertEquals(10, group.getEndpointDescriptions().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointGroupRejectsMoreThanTenEndpointConfigurations() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, null);
|
||||
Listener listener = service.createListener(accelerator.getAcceleratorArn(), portRange(80, 80), "TCP", null);
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class, () ->
|
||||
service.createEndpointGroup(listener.getListenerArn(), "us-west-2",
|
||||
json(endpointConfigurations(11)), null, null, null, null, null, null, null));
|
||||
|
||||
assertEquals("InvalidArgumentException", failure.getErrorCode());
|
||||
assertTrue(failure.getMessage().contains("EndpointConfigurations"), failure.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void addEndpointsRejectsMoreThanTenEndpointConfigurations() {
|
||||
EndpointGroup group = endpointGroup("us-west-2", "[]");
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class, () ->
|
||||
service.addEndpoints(group.getEndpointGroupArn(), json(endpointConfigurations(11))));
|
||||
|
||||
assertEquals("InvalidArgumentException", failure.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointGroupAcceptsTenPortOverrides() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, null);
|
||||
Listener listener = service.createListener(accelerator.getAcceleratorArn(), portRange(80, 80), "TCP", null);
|
||||
|
||||
EndpointGroup group = service.createEndpointGroup(listener.getListenerArn(), "us-west-2", null,
|
||||
null, null, null, null, null, null, portOverrides(10));
|
||||
|
||||
assertEquals(10, group.getPortOverrides().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointGroupRejectsMoreThanTenPortOverrides() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, null);
|
||||
Listener listener = service.createListener(accelerator.getAcceleratorArn(), portRange(80, 80), "TCP", null);
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class, () ->
|
||||
service.createEndpointGroup(listener.getListenerArn(), "us-west-2", null,
|
||||
null, null, null, null, null, null, portOverrides(11)));
|
||||
|
||||
assertEquals("InvalidArgumentException", failure.getErrorCode());
|
||||
assertTrue(failure.getMessage().contains("PortOverrides"), failure.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAcceleratorAcceptsTwoByoipAddresses() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null,
|
||||
List.of("192.0.2.1", "192.0.2.2"), null, null);
|
||||
|
||||
assertEquals(List.of("192.0.2.1", "192.0.2.2"), accelerator.getIpSets().get(0).getIpAddresses());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAcceleratorRejectsMoreThanTwoByoipAddresses() {
|
||||
AwsException failure = assertThrows(AwsException.class, () -> service.createAccelerator("edge", null,
|
||||
List.of("192.0.2.1", "192.0.2.2", "192.0.2.3"), null, null));
|
||||
|
||||
assertEquals("InvalidArgumentException", failure.getErrorCode());
|
||||
assertTrue(failure.getMessage().contains("IpAddresses"), failure.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAcceleratorRejectsMoreThanTwoByoipAddresses() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, null);
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class, () ->
|
||||
service.updateAccelerator(accelerator.getAcceleratorArn(), null, null,
|
||||
List.of("192.0.2.1", "192.0.2.2", "192.0.2.3"), null));
|
||||
|
||||
assertEquals("InvalidArgumentException", failure.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointGroupAcceptsAHealthCheckPathOfTwoHundredFiftyFiveCharacters() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, null);
|
||||
Listener listener = service.createListener(accelerator.getAcceleratorArn(), portRange(80, 80), "TCP", null);
|
||||
String path = "/" + "a".repeat(254);
|
||||
|
||||
EndpointGroup group = service.createEndpointGroup(listener.getListenerArn(), "us-west-2", null,
|
||||
null, null, "HTTP", path, null, null, null);
|
||||
|
||||
assertEquals(path, group.getHealthCheckPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointGroupRejectsAHealthCheckPathLongerThanTwoHundredFiftyFiveCharacters() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, null);
|
||||
Listener listener = service.createListener(accelerator.getAcceleratorArn(), portRange(80, 80), "TCP", null);
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class, () ->
|
||||
service.createEndpointGroup(listener.getListenerArn(), "us-west-2", null,
|
||||
null, null, "HTTP", "/" + "a".repeat(255), null, null, null));
|
||||
|
||||
assertEquals("InvalidArgumentException", failure.getErrorCode());
|
||||
assertTrue(failure.getMessage().contains("HealthCheckPath"), failure.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointGroupRejectsAHealthCheckPathThatDoesNotStartWithASlash() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, null);
|
||||
Listener listener = service.createListener(accelerator.getAcceleratorArn(), portRange(80, 80), "TCP", null);
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class, () ->
|
||||
service.createEndpointGroup(listener.getListenerArn(), "us-west-2", null,
|
||||
null, null, "HTTP", "health", null, null, null));
|
||||
|
||||
assertEquals("InvalidArgumentException", failure.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointGroupRejectsAHealthCheckPathWithCharactersOutsideTheModelPattern() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, null);
|
||||
Listener listener = service.createListener(accelerator.getAcceleratorArn(), portRange(80, 80), "TCP", null);
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class, () ->
|
||||
service.createEndpointGroup(listener.getListenerArn(), "us-west-2", null,
|
||||
null, null, "HTTP", "/health check", null, null, null));
|
||||
|
||||
assertEquals("InvalidArgumentException", failure.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointGroupAcceptsTheUrlPathCharactersTheModelAllows() {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, null);
|
||||
Listener listener = service.createListener(accelerator.getAcceleratorArn(), portRange(80, 80), "TCP", null);
|
||||
String path = "/health-check_v2/status.json?deep=1&x=a+b~c#frag@host:8080%20";
|
||||
|
||||
EndpointGroup group = service.createEndpointGroup(listener.getListenerArn(), "us-west-2", null,
|
||||
null, null, "HTTP", path, null, null, null);
|
||||
|
||||
assertEquals(path, group.getHealthCheckPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateEndpointGroupRejectsAnInvalidHealthCheckPath() {
|
||||
EndpointGroup group = endpointGroup("us-west-2", "[]");
|
||||
|
||||
AwsException failure = assertThrows(AwsException.class, () ->
|
||||
service.updateEndpointGroup(group.getEndpointGroupArn(), null, null, null,
|
||||
null, "health", null, null, null));
|
||||
|
||||
assertEquals("InvalidArgumentException", failure.getErrorCode());
|
||||
}
|
||||
|
||||
private EndpointGroup endpointGroup(String region, String endpointConfigurations) {
|
||||
Accelerator accelerator = service.createAccelerator("edge", null, null, null, null);
|
||||
Listener listener = service.createListener(accelerator.getAcceleratorArn(), portRange(80, 80), "TCP", null);
|
||||
return service.createEndpointGroup(listener.getListenerArn(), region, json(endpointConfigurations),
|
||||
null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
private static List<PortRange> portRanges(int count) {
|
||||
List<PortRange> ranges = new ArrayList<>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
PortRange range = new PortRange();
|
||||
range.setFromPort(1000 + i);
|
||||
range.setToPort(1000 + i);
|
||||
ranges.add(range);
|
||||
}
|
||||
return ranges;
|
||||
}
|
||||
|
||||
private static List<PortOverride> portOverrides(int count) {
|
||||
List<PortOverride> overrides = new ArrayList<>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
PortOverride override = new PortOverride();
|
||||
override.setListenerPort(1000 + i);
|
||||
override.setEndpointPort(2000 + i);
|
||||
overrides.add(override);
|
||||
}
|
||||
return overrides;
|
||||
}
|
||||
|
||||
private static String endpointConfigurations(int count) {
|
||||
StringBuilder builder = new StringBuilder("[");
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (i > 0) {
|
||||
builder.append(',');
|
||||
}
|
||||
builder.append("{\"EndpointId\":\"i-").append(i).append("\"}");
|
||||
}
|
||||
return builder.append(']').toString();
|
||||
}
|
||||
|
||||
private static List<PortRange> portRange(int from, int to) {
|
||||
PortRange range = new PortRange();
|
||||
range.setFromPort(from);
|
||||
range.setToPort(to);
|
||||
return List.of(range);
|
||||
}
|
||||
|
||||
private static JsonNode json(String raw) {
|
||||
try {
|
||||
return MAPPER.readTree(raw);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("test fixture is not valid JSON: " + raw, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -420,6 +420,8 @@ floci:
|
||||
enabled: true
|
||||
cognitoidentity:
|
||||
enabled: true
|
||||
globalaccelerator:
|
||||
enabled: true
|
||||
aps:
|
||||
enabled: true
|
||||
lakeformation:
|
||||
|
||||
@@ -267,6 +267,10 @@ services:
|
||||
doc: docs/services/cognitoidentity.md
|
||||
sources:
|
||||
- { path: src/main/java/io/github/hectorvent/floci/services/cognitoidentity/CognitoIdentityJsonHandler.java, mode: switch }
|
||||
- service: globalaccelerator
|
||||
doc: docs/services/globalaccelerator.md
|
||||
sources:
|
||||
- { path: src/main/java/io/github/hectorvent/floci/services/globalaccelerator/GlobalAcceleratorJsonHandler.java, mode: switch }
|
||||
- service: route53
|
||||
doc: docs/services/route53.md
|
||||
sources:
|
||||
|
||||
Reference in new issue
Block a user