Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/services/cloudformation.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ cross-resource references.
| ECS | `Cluster`, `TaskDefinition`, `Service`, `CapacityProvider`, `ClusterCapacityProviderAssociations` |
| EKS | `Cluster`, `Nodegroup` |
| RDS | `DBInstance` (starts a real container), `DBCluster` (starts a real container), `DBSubnetGroup`, `DBParameterGroup`, `DBClusterParameterGroup`, `DBProxy`, `DBProxyTargetGroup` |
| ElastiCache | `CacheCluster` (starts a real container; modifying an existing cluster in place is not supported), `SubnetGroup` |
| Redshift | `Cluster` (single-node container; Port and non-dev DBName ignored; ManageMasterPassword unsupported), `ClusterParameterGroup`, `ClusterSubnetGroup`, `ClusterSecurityGroup` (accepted; no EC2-Classic security group model) |
| Redshift Serverless | `Namespace` (ManageAdminPassword is accepted and not applied; GetAtt uses the dotted Namespace.* form), `Workgroup` (starts a real container; one workgroup per namespace; capacity, VPC and price-performance settings are stored only; snapshot restore properties are ignored; GetAtt uses the dotted Workgroup.* form) |
| EC2 | `VPC`, `Subnet`, `SecurityGroup` (inline `SecurityGroupIngress`/`SecurityGroupEgress` supported), `SecurityGroupIngress`, `SecurityGroupEgress`, `InternetGateway`, `RouteTable`, `SubnetRouteTableAssociation`, `Route`, `NatGateway`, `EIP`, `Instance`, `LaunchTemplate`, `VPCGatewayAttachment`, `VPCEndpoint`, `NetworkAcl`, `NetworkAclEntry`, `SubnetNetworkAclAssociation`, `FlowLog` |
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@
</dependency>

<!-- Testing -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>elasticache</artifactId>
<version>2.55.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit</artifactId>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.github.hectorvent.floci.services.elasticache.container.ElastiCacheMemcachedContainerManager;
import io.github.hectorvent.floci.services.elasticache.model.CacheCluster;
import io.github.hectorvent.floci.services.elasticache.model.CacheClusterStatus;
import io.github.hectorvent.floci.services.elasticache.model.CacheSubnetGroup;
import io.github.hectorvent.floci.services.elasticache.model.Endpoint;
import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroup;
import jakarta.enterprise.context.ApplicationScoped;
Expand Down Expand Up @@ -45,6 +46,7 @@ public class ElastiCacheMemcachedService {
*/
private final StorageBackend<String, CacheCluster> redisClusters;
private final StorageBackend<String, ReplicationGroup> groups;
private final StorageBackend<String, CacheSubnetGroup> subnetGroups;
private final ElastiCacheMemcachedContainerManager containerManager;
private final EmulatorConfig config;
/** Shared with {@link ElastiCacheService}: one namespace, one set of in-flight claims. */
Expand All @@ -68,6 +70,8 @@ public ElastiCacheMemcachedService(ElastiCacheMemcachedContainerManager containe
new TypeReference<Map<String, CacheCluster>>() {});
this.groups = storageFactory.create("elasticache", "elasticache-groups.json",
new TypeReference<Map<String, ReplicationGroup>>() {});
this.subnetGroups = storageFactory.create("elasticache", "elasticache-subnet-groups.json",
new TypeReference<Map<String, CacheSubnetGroup>>() {});
}

/**
Expand All @@ -87,6 +91,7 @@ public CacheCluster createCacheCluster(ElastiCacheService.CreateCacheClusterRequ
"The request cannot be processed because it would exceed the allowed number "
+ "of cache nodes in a single cluster.", 400);
}
ElastiCacheService.requireCacheSubnetGroup(subnetGroups, request.cacheSubnetGroupName());
// Claimed before the store checks rather than after, because no create here or in
// ElastiCacheService persists its record until its container has started: a store check
// that passes is no promise the id is still free by the time this one writes. The claim
Expand Down Expand Up @@ -136,12 +141,15 @@ private CacheCluster provisionCacheCluster(ElastiCacheService.CreateCacheCluster
? request.cacheNodeType() : DEFAULT_CACHE_NODE_TYPE);
cluster.setCacheParameterGroupName(request.cacheParameterGroupName());
cluster.setCacheSubnetGroupName(request.cacheSubnetGroupName());
cluster.setNetworkType(request.networkType() != null && !request.networkType().isBlank()
? request.networkType() : "ipv4");
cluster.setSecurityGroupIds(request.securityGroupIds() != null
? new ArrayList<>(request.securityGroupIds()) : null);
cluster.setPreferredAvailabilityZone(request.preferredAvailabilityZone() != null
&& !request.preferredAvailabilityZone().isBlank()
? request.preferredAvailabilityZone() : regionResolver.getRegion() + "a");
cluster.setArn(regionResolver.buildArn("elasticache", request.region(), "cluster:" + clusterId));
cluster.setTags(request.tags());
if (handle != null) {
cluster.setContainerId(handle.getContainerId());
cluster.setContainerHost(handle.getHost());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -782,9 +782,12 @@ private Response handleListTagsForResource(MultivaluedMap<String, String> params
}
tags = cluster.getTags();
} else if (service.listMemberCacheClusters(arn[6]).isEmpty()) {
// Memcached clusters and replication group members carry no tags, but they do
// exist. Only an id no source knows is a not-found.
memcachedService.getCacheCluster(arn[6]);
CacheCluster mcCluster = memcachedService.getCacheCluster(arn[6]);
if (mcCluster.getArn() != null && !mcCluster.getArn().equalsIgnoreCase(resourceName)) {
throw new AwsException("CacheClusterNotFound",
"Cache cluster " + arn[6] + " not found.", 404);
}
tags = mcCluster.getTags();
}
}
if ("subnetgroup".equals(arn[5])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ public CacheCluster createCacheCluster(CreateCacheClusterRequest request) {
if (request.preferredMaintenanceWindow() != null && !request.preferredMaintenanceWindow().isBlank()) {
BackupWindows.parseMaintenanceWindow(request.preferredMaintenanceWindow());
}
requireCacheSubnetGroup(request.cacheSubnetGroupName());
requireCacheSubnetGroup(subnetGroups, request.cacheSubnetGroupName());
String parameterGroupReservation = reserveParameterGroup(request.cacheParameterGroupName());
try {
if (cacheClusterIdTaken(clusterId)) {
Expand Down Expand Up @@ -1285,7 +1285,7 @@ private boolean cacheClusterIdTaken(String clusterId) {
* <p>{@code CreateReplicationGroup} does not make this check, so a replication group can
* still be created against a subnet group that is not there.
*/
private void requireCacheSubnetGroup(String name) {
static void requireCacheSubnetGroup(StorageBackend<String, CacheSubnetGroup> subnetGroups, String name) {
if (name == null || name.isBlank()) {
return;
}
Expand Down Expand Up @@ -2185,6 +2185,12 @@ public List<CacheSubnetGroup> describeCacheSubnetGroups(String name) {

/** Replaces the description and, when subnets are given, the whole subnet set. */
public CacheSubnetGroup modifyCacheSubnetGroup(String name, String description, List<String> subnetIds) {
return modifyCacheSubnetGroup(name, description, subnetIds, null);
}

/** As above; a non-null {@code tags} replaces the stored tag map, an empty one clears it. */
public CacheSubnetGroup modifyCacheSubnetGroup(String name, String description, List<String> subnetIds,
Map<String, String> tags) {
validateSubnetGroupName(name);
synchronized (lockFor("sng:" + name)) {
CacheSubnetGroup existing = subnetGroups.get(name)
Expand All @@ -2201,7 +2207,7 @@ public CacheSubnetGroup modifyCacheSubnetGroup(String name, String description,
} else {
updated = buildSubnetGroup(name, effectiveDescription, subnetIds);
}
updated.setTags(existing.getTags());
updated.setTags(tags != null ? tags : existing.getTags());
subnetGroups.put(name, updated);
return updated;
}
Expand All @@ -2214,6 +2220,16 @@ public void deleteCacheSubnetGroup(String name) {
throw new AwsException("CacheSubnetGroupNotFoundFault",
"Cache Subnet Group " + name + " does not exist.", 400);
}
boolean inUse = cacheClusters.scan(k -> true).stream()
.anyMatch(c -> name.equals(c.getCacheSubnetGroupName()))
|| memcachedClusters.scan(k -> true).stream()
.anyMatch(c -> name.equals(c.getCacheSubnetGroupName()))
|| groups.scan(k -> true).stream()
.anyMatch(g -> name.equals(g.getCacheSubnetGroupName()));
if (inUse) {
throw new AwsException("CacheSubnetGroupInUse",
"The requested cache subnet group is currently in use.", 400);
}
subnetGroups.delete(name);
}
LOG.infov("Deleted cache subnet group {0}", name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import io.github.hectorvent.floci.services.cloudformation.provisioners.EcsCapacityCfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.EcsCfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.EksCfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.ElastiCacheCfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.ElbV2CfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.EventsArchiveCfnProvisioner;
import io.github.hectorvent.floci.services.cloudformation.provisioners.EventsCfnProvisioner;
Expand Down Expand Up @@ -114,6 +115,8 @@
import io.github.hectorvent.floci.services.ecr.EcrService;
import io.github.hectorvent.floci.services.ecs.EcsService;
import io.github.hectorvent.floci.services.eks.EksService;
import io.github.hectorvent.floci.services.elasticache.ElastiCacheMemcachedService;
import io.github.hectorvent.floci.services.elasticache.ElastiCacheService;
import io.github.hectorvent.floci.services.elbv2.ElbV2Service;
import io.github.hectorvent.floci.services.eventbridge.EventBridgeService;
import io.github.hectorvent.floci.services.firehose.FirehoseService;
Expand Down Expand Up @@ -223,6 +226,8 @@ static final class Builder {
private SqsService sqsService;
private WafV2Service wafV2Service;
private BackupService backupService;
private ElastiCacheService elastiCacheService;
private ElastiCacheMemcachedService elastiCacheMemcachedService;
private RedshiftService redshiftService;
private RedshiftServerlessService redshiftServerlessService;
private CloudMapService cloudMapService;
Expand Down Expand Up @@ -441,6 +446,9 @@ private List<CfnResourceProvisioner> inferredProvisioners() {
if (transferService != null) {
discovered.add(new TransferCfnProvisioner(transferService));
}
if (elastiCacheService != null && elastiCacheMemcachedService != null) {
discovered.add(new ElastiCacheCfnProvisioner(elastiCacheService, elastiCacheMemcachedService));
}
if (redshiftService != null) {
discovered.add(new RedshiftClusterCfnProvisioner(redshiftService));
}
Expand Down Expand Up @@ -703,6 +711,17 @@ public Builder backup(BackupService v) {
return this;
}

/** The cache cluster provisioner needs both engines' services; name this and elastiCacheMemcached. */
public Builder elastiCache(ElastiCacheService s) {
this.elastiCacheService = s;
return this;
}

public Builder elastiCacheMemcached(ElastiCacheMemcachedService s) {
this.elastiCacheMemcachedService = s;
return this;
}

public Builder redshiftService(RedshiftService s) {
this.redshiftService = s;
return this;
Expand Down
Loading
Loading