mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(neptune): support the Terraform aws_neptune_cluster read-back contract (#3017)
* feat(neptune): support the Terraform aws_neptune_cluster read-back contract The Terraform AWS provider's aws_neptune_cluster resource reads back every DBCluster field after create and update, and treats a mismatch on a ForceNew attribute as a replacement. Against Floci the resource could not converge: StorageEncrypted was hardcoded to true against the provider's default of false, AvailabilityZones was emitted as a singular element that SDK parsers drop, BackupRetentionPeriod and the other settings were never stored, and tag calls on a Neptune ARN never reached the Neptune store. CreateDBCluster and ModifyDBCluster now store the settings a request carries (NeptuneClusterSettings, modelled on DocDbClusterSettings) and DescribeDBClusters reads them back with the AWS defaults otherwise: AvailabilityZones, BackupRetentionPeriod, PreferredBackupWindow, PreferredMaintenanceWindow, DBSubnetGroup, DBClusterParameterGroup, VpcSecurityGroups, StorageEncrypted, KmsKeyId, StorageType, DeletionProtection, CopyTagsToSnapshot, EnabledCloudwatchLogsExports, ReplicationSourceIdentifier, ServerlessV2ScalingConfiguration, AssociatedRoles and ClusterCreateTime. StorageEncrypted defaults to false as on AWS. Also: - A requested Port is honoured when it is free inside the proxy range, so Terraform's default port of 8182 matches the first cluster. - DeleteDBCluster refuses a cluster with DeletionProtection enabled with InvalidParameterCombination, as on AWS. - DBClusterMembers uses the DBClusterMember element the Neptune API model declares; the previous member element was dropped by SDK parsers. - New actions: AddRoleToDBCluster, RemoveRoleFromDBCluster, DescribeGlobalClusters (empty list), ListTagsForResource, AddTagsToResource and RemoveTagsFromResource. Tags are accepted on CreateDBCluster and CreateDBInstance, and the rds credential scope routes a Neptune ARN ResourceName to the Neptune handler. Verified against hashicorp/aws 6.62.0 with terraform apply, a clean re-plan, an update covering retention, protection, log exports, security groups, iam_roles and tags, a destroy blocked by deletion protection, and a destroy after disabling it. * test(compat): cover aws_neptune_cluster in the Terraform and Java SDK suites Adds a dedicated Terraform fixture and bats test that applies an aws_neptune_cluster, checks the read-back through terraform output and the AWS CLI, checks tags through ListTagsForResource, and asserts a clean re-plan. Extends the Java SDK NeptuneTest with tags, IAM roles, modify settings, deletion protection and cluster members, so a real SDK parser covers the new DBCluster fields. * fix(neptune): infer the rds service for the DBCluster role actions Unsigned Query requests resolve their service from the action name, and AddRoleToDBCluster and RemoveRoleFromDBCluster were missing from the RDS action set, so they fell through to the SQS default instead of reaching the Neptune handler. * feat(neptune): read back the settings Terraform's aws_neptune_cluster_instance manages DescribeDBInstances omitted AutoMinorVersionUpgrade, PromotionTier, PubliclyAccessible, the parameter and subnet groups and the windows, ModifyDBInstance ignored them, StorageEncrypted was hardcoded to true, and every cluster member was reported as the writer, so the provider issued a ModifyDBInstance on every apply. NeptuneInstanceSettings, modelled on NeptuneClusterSettings, stores what a request carries and DescribeDBInstances reads it back with the AWS defaults otherwise; StorageEncrypted, KmsKeyId and StorageType are the cluster's. The first member of a cluster is its writer and deleting it promotes the next. Covered by unit, integration and Java SDK tests and a Terraform compat fixture with a writer and a reader instance. --------- Co-authored-by: kurtmc <2661907+kurtmc@users.noreply.github.com>
This commit is contained in:
1 parent
0c33ef234b
commit
a7be2dd299
19 files changed
+2100
-35
No files matched your search
@@ -302,8 +302,9 @@ public class AwsQueryController {
|
||||
case "elasticache" -> elastiCacheQueryHandler.handle(action, formParams, region);
|
||||
case "rds" -> {
|
||||
// Neptune signs requests with "rds" credential scope (same wire protocol).
|
||||
// Route to Neptune when Engine=neptune (create ops) or when the cluster/instance
|
||||
// already exists in Neptune storage (describe/modify/delete ops).
|
||||
// Route to Neptune when Engine=neptune (create ops), when the cluster/instance
|
||||
// already exists in Neptune storage (describe/modify/delete ops), or when a
|
||||
// tagging ResourceName is a Neptune ARN.
|
||||
String engine = formParams.getFirst("Engine");
|
||||
String clusterId = formParams.getFirst("DBClusterIdentifier");
|
||||
String instanceId = formParams.getFirst("DBInstanceIdentifier");
|
||||
@@ -315,7 +316,8 @@ public class AwsQueryController {
|
||||
|
||||
if ("neptune".equalsIgnoreCase(engine)
|
||||
|| neptuneService.hasCluster(clusterId)
|
||||
|| neptuneService.hasInstance(instanceId)) {
|
||||
|| neptuneService.hasInstance(instanceId)
|
||||
|| neptuneService.hasResourceWithArn(formParams.getFirst("ResourceName"))) {
|
||||
yield neptuneQueryHandler.handle(action, formParams);
|
||||
}
|
||||
|
||||
@@ -518,6 +520,7 @@ public class AwsQueryController {
|
||||
"CreateDBSubnetGroup", "DescribeDBSubnetGroups", "ModifyDBSubnetGroup", "DeleteDBSubnetGroup",
|
||||
"AddTagsToResource", "ListTagsForResource", "RemoveTagsFromResource",
|
||||
"CreateDBCluster", "DescribeDBClusters", "DeleteDBCluster", "ModifyDBCluster",
|
||||
"AddRoleToDBCluster", "RemoveRoleFromDBCluster",
|
||||
"DescribeGlobalClusters",
|
||||
"CreateDBParameterGroup", "DescribeDBParameterGroups",
|
||||
"DeleteDBParameterGroup", "ModifyDBParameterGroup", "DescribeDBParameters",
|
||||
|
||||
+303
-18
@@ -4,17 +4,27 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsNamespaces;
|
||||
import io.github.hectorvent.floci.core.common.AwsQueryResponse;
|
||||
import io.github.hectorvent.floci.core.common.BackupWindows;
|
||||
import io.github.hectorvent.floci.core.common.XmlBuilder;
|
||||
import io.github.hectorvent.floci.services.neptune.model.NeptuneCluster;
|
||||
import io.github.hectorvent.floci.services.neptune.model.NeptuneClusterSettings;
|
||||
import io.github.hectorvent.floci.services.neptune.model.NeptuneInstance;
|
||||
import io.github.hectorvent.floci.services.neptune.model.NeptuneInstanceSettings;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.core.MultivaluedMap;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@ApplicationScoped
|
||||
public class NeptuneQueryHandler {
|
||||
@@ -38,10 +48,16 @@ public class NeptuneQueryHandler {
|
||||
case "DescribeDBClusters" -> handleDescribeDbClusters(params);
|
||||
case "DeleteDBCluster" -> handleDeleteDbCluster(params);
|
||||
case "ModifyDBCluster" -> handleModifyDbCluster(params);
|
||||
case "AddRoleToDBCluster" -> handleAddRoleToDbCluster(params);
|
||||
case "RemoveRoleFromDBCluster" -> handleRemoveRoleFromDbCluster(params);
|
||||
case "DescribeGlobalClusters" -> handleDescribeGlobalClusters(params);
|
||||
case "CreateDBInstance" -> handleCreateDbInstance(params);
|
||||
case "DescribeDBInstances"-> handleDescribeDbInstances(params);
|
||||
case "DeleteDBInstance" -> handleDeleteDbInstance(params);
|
||||
case "ModifyDBInstance" -> handleModifyDbInstance(params);
|
||||
case "ListTagsForResource" -> handleListTagsForResource(params);
|
||||
case "AddTagsToResource" -> handleAddTagsToResource(params);
|
||||
case "RemoveTagsFromResource" -> handleRemoveTagsFromResource(params);
|
||||
default -> AwsQueryResponse.error("UnsupportedOperation",
|
||||
"Operation " + action + " is not supported by Neptune.", AwsNamespaces.RDS, 400);
|
||||
};
|
||||
@@ -64,7 +80,8 @@ public class NeptuneQueryHandler {
|
||||
String engineVersion = params.getFirst("EngineVersion");
|
||||
boolean iamEnabled = "true".equalsIgnoreCase(params.getFirst("EnableIAMDatabaseAuthentication"));
|
||||
|
||||
NeptuneCluster cluster = service.createDbCluster(id, engineVersion, iamEnabled);
|
||||
NeptuneCluster cluster = service.createDbCluster(id, engineVersion, iamEnabled,
|
||||
clusterSettings(params, true), parseTags(params));
|
||||
return Response.ok(AwsQueryResponse.envelope("CreateDBCluster", AwsNamespaces.RDS,
|
||||
clusterXml(cluster))).build();
|
||||
}
|
||||
@@ -143,11 +160,59 @@ public class NeptuneQueryHandler {
|
||||
String iamStr = params.getFirst("EnableIAMDatabaseAuthentication");
|
||||
Boolean iamEnabled = iamStr != null ? Boolean.parseBoolean(iamStr) : null;
|
||||
|
||||
NeptuneCluster cluster = service.modifyDbCluster(id, engineVersion, iamEnabled);
|
||||
NeptuneCluster cluster = service.modifyDbCluster(id, engineVersion, iamEnabled,
|
||||
clusterSettings(params, false));
|
||||
return Response.ok(AwsQueryResponse.envelope("ModifyDBCluster", AwsNamespaces.RDS,
|
||||
clusterXml(cluster))).build();
|
||||
}
|
||||
|
||||
private Response handleAddRoleToDbCluster(MultivaluedMap<String, String> params) {
|
||||
String id = params.getFirst("DBClusterIdentifier");
|
||||
if (id == null || id.isBlank()) {
|
||||
return AwsQueryResponse.error("InvalidParameterValue",
|
||||
"DBClusterIdentifier is required.", AwsNamespaces.RDS, 400);
|
||||
}
|
||||
service.addRoleToDbCluster(id, params.getFirst("RoleArn"));
|
||||
return Response.ok(AwsQueryResponse.envelopeNoResult("AddRoleToDBCluster", AwsNamespaces.RDS)).build();
|
||||
}
|
||||
|
||||
private Response handleRemoveRoleFromDbCluster(MultivaluedMap<String, String> params) {
|
||||
String id = params.getFirst("DBClusterIdentifier");
|
||||
if (id == null || id.isBlank()) {
|
||||
return AwsQueryResponse.error("InvalidParameterValue",
|
||||
"DBClusterIdentifier is required.", AwsNamespaces.RDS, 400);
|
||||
}
|
||||
service.removeRoleFromDbCluster(id, params.getFirst("RoleArn"));
|
||||
return Response.ok(AwsQueryResponse.envelopeNoResult("RemoveRoleFromDBCluster", AwsNamespaces.RDS)).build();
|
||||
}
|
||||
|
||||
private Response handleDescribeGlobalClusters(MultivaluedMap<String, String> params) {
|
||||
String maxRecords = params.getFirst("MaxRecords");
|
||||
if (maxRecords != null && !maxRecords.isBlank()) {
|
||||
int max = -1;
|
||||
try {
|
||||
max = Integer.parseInt(maxRecords.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
LOG.debugv("Non-numeric MaxRecords {0} on DescribeGlobalClusters", maxRecords);
|
||||
}
|
||||
if (max < 20 || max > 100) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Invalid value " + maxRecords + " for MaxRecords. Must be between 20 and 100", 400);
|
||||
}
|
||||
}
|
||||
String identifier = params.getFirst("GlobalClusterIdentifier");
|
||||
if (identifier != null && !identifier.isBlank()) {
|
||||
throw new AwsException("GlobalClusterNotFoundFault",
|
||||
"Global cluster '" + identifier + "' not found", 404);
|
||||
}
|
||||
String marker = params.getFirst("Marker");
|
||||
if (marker != null && !marker.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValue", "The request token is invalid.", 400);
|
||||
}
|
||||
XmlBuilder xml = new XmlBuilder().start("GlobalClusters").end("GlobalClusters");
|
||||
return Response.ok(AwsQueryResponse.envelope("DescribeGlobalClusters", AwsNamespaces.RDS, xml.build())).build();
|
||||
}
|
||||
|
||||
// ── Instances ─────────────────────────────────────────────────────────────
|
||||
|
||||
private Response handleCreateDbInstance(MultivaluedMap<String, String> params) {
|
||||
@@ -166,7 +231,7 @@ public class NeptuneQueryHandler {
|
||||
boolean iamEnabled = "true".equalsIgnoreCase(params.getFirst("EnableIAMDatabaseAuthentication"));
|
||||
|
||||
NeptuneInstance instance = service.createDbInstance(id, dbClusterIdentifier,
|
||||
dbInstanceClass, engineVersion, iamEnabled);
|
||||
dbInstanceClass, engineVersion, iamEnabled, instanceSettings(params, true), parseTags(params));
|
||||
return Response.ok(AwsQueryResponse.envelope("CreateDBInstance", AwsNamespaces.RDS,
|
||||
instanceXml(instance))).build();
|
||||
}
|
||||
@@ -217,11 +282,144 @@ public class NeptuneQueryHandler {
|
||||
String iamStr = params.getFirst("EnableIAMDatabaseAuthentication");
|
||||
Boolean iamEnabled = iamStr != null ? Boolean.parseBoolean(iamStr) : null;
|
||||
|
||||
NeptuneInstance instance = service.modifyDbInstance(id, dbInstanceClass, iamEnabled);
|
||||
NeptuneInstance instance = service.modifyDbInstance(id, dbInstanceClass, iamEnabled,
|
||||
instanceSettings(params, false));
|
||||
return Response.ok(AwsQueryResponse.envelope("ModifyDBInstance", AwsNamespaces.RDS,
|
||||
instanceXml(instance))).build();
|
||||
}
|
||||
|
||||
// ── Tags ──────────────────────────────────────────────────────────────────
|
||||
|
||||
private Response handleListTagsForResource(MultivaluedMap<String, String> params) {
|
||||
Map<String, String> tags = service.listTagsForResource(params.getFirst("ResourceName"));
|
||||
XmlBuilder xml = new XmlBuilder().start("TagList");
|
||||
tags.forEach((key, value) -> xml.start("Tag").elem("Key", key).elem("Value", value).end("Tag"));
|
||||
xml.end("TagList");
|
||||
return Response.ok(AwsQueryResponse.envelope("ListTagsForResource", AwsNamespaces.RDS, xml.build())).build();
|
||||
}
|
||||
|
||||
private Response handleAddTagsToResource(MultivaluedMap<String, String> params) {
|
||||
service.addTagsToResource(params.getFirst("ResourceName"), parseTags(params));
|
||||
return Response.ok(AwsQueryResponse.envelopeNoResult("AddTagsToResource", AwsNamespaces.RDS)).build();
|
||||
}
|
||||
|
||||
private Response handleRemoveTagsFromResource(MultivaluedMap<String, String> params) {
|
||||
service.removeTagsFromResource(params.getFirst("ResourceName"), tagKeys(params));
|
||||
return Response.ok(AwsQueryResponse.envelopeNoResult("RemoveTagsFromResource", AwsNamespaces.RDS)).build();
|
||||
}
|
||||
|
||||
// ── Request parsing ───────────────────────────────────────────────────────
|
||||
|
||||
private static NeptuneClusterSettings clusterSettings(MultivaluedMap<String, String> params, boolean create) {
|
||||
return new NeptuneClusterSettings(
|
||||
create ? listParam(params, "AvailabilityZones", "AvailabilityZone") : null,
|
||||
create ? optionalInt(params.getFirst("Port")) : null,
|
||||
optionalInt(params.getFirst("BackupRetentionPeriod")),
|
||||
params.getFirst("PreferredBackupWindow"),
|
||||
params.getFirst("PreferredMaintenanceWindow"),
|
||||
create ? params.getFirst("DBSubnetGroupName") : null,
|
||||
params.getFirst("DBClusterParameterGroupName"),
|
||||
listParam(params, "VpcSecurityGroupIds", "VpcSecurityGroupId"),
|
||||
create ? optionalBoolean(params.getFirst("StorageEncrypted")) : null,
|
||||
create ? params.getFirst("KmsKeyId") : null,
|
||||
params.getFirst("StorageType"),
|
||||
optionalBoolean(params.getFirst("DeletionProtection")),
|
||||
optionalBoolean(params.getFirst("CopyTagsToSnapshot")),
|
||||
create ? listParam(params, "EnableCloudwatchLogsExports", "member")
|
||||
: listParam(params, "CloudwatchLogsExportConfiguration.EnableLogTypes", "member"),
|
||||
create ? null : listParam(params, "CloudwatchLogsExportConfiguration.DisableLogTypes", "member"),
|
||||
create ? params.getFirst("ReplicationSourceIdentifier") : null,
|
||||
optionalDouble(params.getFirst("ServerlessV2ScalingConfiguration.MinCapacity")),
|
||||
optionalDouble(params.getFirst("ServerlessV2ScalingConfiguration.MaxCapacity")));
|
||||
}
|
||||
|
||||
private static NeptuneInstanceSettings instanceSettings(MultivaluedMap<String, String> params, boolean create) {
|
||||
return new NeptuneInstanceSettings(
|
||||
create ? params.getFirst("AvailabilityZone") : null,
|
||||
optionalBoolean(params.getFirst("AutoMinorVersionUpgrade")),
|
||||
optionalInt(params.getFirst("PromotionTier")),
|
||||
create ? optionalBoolean(params.getFirst("PubliclyAccessible")) : null,
|
||||
params.getFirst("DBParameterGroupName"),
|
||||
create ? params.getFirst("DBSubnetGroupName") : null,
|
||||
params.getFirst("PreferredBackupWindow"),
|
||||
params.getFirst("PreferredMaintenanceWindow"));
|
||||
}
|
||||
|
||||
private static List<String> listParam(MultivaluedMap<String, String> params, String name, String memberName) {
|
||||
Set<String> prefixes = new LinkedHashSet<>(List.of(name + "." + memberName + ".", name + ".member."));
|
||||
for (String prefix : prefixes) {
|
||||
List<String> values = new ArrayList<>();
|
||||
for (int i = 1; ; i++) {
|
||||
String value = params.getFirst(prefix + i);
|
||||
if (value == null) {
|
||||
break;
|
||||
}
|
||||
if (!value.isBlank()) {
|
||||
values.add(value);
|
||||
}
|
||||
}
|
||||
if (!values.isEmpty()) {
|
||||
return values;
|
||||
}
|
||||
}
|
||||
return params.containsKey(name) ? new ArrayList<>() : null;
|
||||
}
|
||||
|
||||
private static Map<String, String> parseTags(MultivaluedMap<String, String> params) {
|
||||
Map<String, String> tags = new LinkedHashMap<>();
|
||||
for (String prefix : List.of("Tags.Tag", "Tags.member", "Tag")) {
|
||||
for (int i = 1; ; i++) {
|
||||
String key = params.getFirst(prefix + "." + i + ".Key");
|
||||
if (key == null) {
|
||||
break;
|
||||
}
|
||||
String value = params.getFirst(prefix + "." + i + ".Value");
|
||||
tags.put(key, value == null ? "" : value);
|
||||
}
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
private static List<String> tagKeys(MultivaluedMap<String, String> params) {
|
||||
List<String> keys = new ArrayList<>();
|
||||
for (String prefix : List.of("TagKeys.member", "TagKeys.TagKey", "TagKeys")) {
|
||||
for (int i = 1; ; i++) {
|
||||
String key = params.getFirst(prefix + "." + i);
|
||||
if (key == null) {
|
||||
break;
|
||||
}
|
||||
keys.add(key);
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
private static Boolean optionalBoolean(String value) {
|
||||
return value == null ? null : !"false".equalsIgnoreCase(value.trim());
|
||||
}
|
||||
|
||||
private static Integer optionalInt(String value) {
|
||||
if (value == null || value.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(value.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
throw new AwsException("InvalidParameterValue", "Value " + value + " is not a valid integer.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static Double optionalDouble(String value) {
|
||||
if (value == null || value.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Double.parseDouble(value.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
throw new AwsException("InvalidParameterValue", "Value " + value + " is not a valid number.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
// ── XML builders ──────────────────────────────────────────────────────────
|
||||
|
||||
private String clusterXml(NeptuneCluster c) {
|
||||
@@ -239,17 +437,72 @@ public class NeptuneQueryHandler {
|
||||
.elem("Port", c.getPort())
|
||||
.elem("IAMDatabaseAuthenticationEnabled", c.isIamDatabaseAuthenticationEnabled())
|
||||
.elem("MultiAZ", false)
|
||||
.elem("StorageEncrypted", true)
|
||||
.elem("AvailabilityZone", config.defaultAvailabilityZone())
|
||||
.elem("StorageEncrypted", c.isStorageEncrypted())
|
||||
.elem("KmsKeyId", c.getKmsKeyId())
|
||||
.elem("StorageType", c.getStorageType())
|
||||
.elem("DBSubnetGroup", c.getDbSubnetGroupName() != null ? c.getDbSubnetGroupName() : "default")
|
||||
.elem("DBClusterParameterGroup", c.getDbClusterParameterGroupName() != null
|
||||
? c.getDbClusterParameterGroupName()
|
||||
: "default." + NeptuneService.parameterGroupFamily(c.getEngineVersion()))
|
||||
.elem("BackupRetentionPeriod", c.getBackupRetentionPeriod())
|
||||
.elem("PreferredBackupWindow", c.getPreferredBackupWindow() != null
|
||||
? c.getPreferredBackupWindow() : BackupWindows.DEFAULT_BACKUP_WINDOW)
|
||||
.elem("PreferredMaintenanceWindow", c.getPreferredMaintenanceWindow() != null
|
||||
? c.getPreferredMaintenanceWindow() : BackupWindows.DEFAULT_MAINTENANCE_WINDOW)
|
||||
.elem("DeletionProtection", c.isDeletionProtection())
|
||||
.elem("CopyTagsToSnapshot", c.isCopyTagsToSnapshot())
|
||||
.elem("ReplicationSourceIdentifier", c.getReplicationSourceIdentifier())
|
||||
.elem("DbClusterResourceId", c.getDbClusterResourceId())
|
||||
.elem("DBClusterArn", c.getDbClusterArn())
|
||||
.start("DBClusterMembers");
|
||||
if (c.getDbClusterMembers() != null) {
|
||||
for (String memberId : c.getDbClusterMembers()) {
|
||||
xml.start("member")
|
||||
.elem("DBClusterArn", c.getDbClusterArn());
|
||||
if (c.getCreatedAt() != null) {
|
||||
xml.elem("ClusterCreateTime",
|
||||
DateTimeFormatter.ISO_INSTANT.format(c.getCreatedAt().truncatedTo(ChronoUnit.MILLIS)));
|
||||
}
|
||||
xml.start("AvailabilityZones");
|
||||
List<String> zones = c.getAvailabilityZones();
|
||||
if (zones.isEmpty()) {
|
||||
xml.elem("AvailabilityZone", config.defaultAvailabilityZone());
|
||||
} else {
|
||||
zones.forEach(zone -> xml.elem("AvailabilityZone", zone));
|
||||
}
|
||||
xml.end("AvailabilityZones")
|
||||
.start("EnabledCloudwatchLogsExports");
|
||||
c.getEnabledCloudwatchLogsExports().forEach(logType -> xml.elem("member", logType));
|
||||
xml.end("EnabledCloudwatchLogsExports")
|
||||
.start("AssociatedRoles");
|
||||
for (String roleArn : c.getAssociatedRoleArns()) {
|
||||
xml.start("DBClusterRole")
|
||||
.elem("RoleArn", roleArn)
|
||||
.elem("Status", "ACTIVE")
|
||||
.end("DBClusterRole");
|
||||
}
|
||||
xml.end("AssociatedRoles")
|
||||
.start("VpcSecurityGroups");
|
||||
for (String groupId : c.getVpcSecurityGroupIds()) {
|
||||
xml.start("VpcSecurityGroupMembership")
|
||||
.elem("VpcSecurityGroupId", groupId)
|
||||
.elem("Status", "active")
|
||||
.end("VpcSecurityGroupMembership");
|
||||
}
|
||||
xml.end("VpcSecurityGroups");
|
||||
if (c.getServerlessV2MinCapacity() != null || c.getServerlessV2MaxCapacity() != null) {
|
||||
xml.start("ServerlessV2ScalingConfiguration");
|
||||
if (c.getServerlessV2MinCapacity() != null) {
|
||||
xml.elem("MinCapacity", String.valueOf(c.getServerlessV2MinCapacity()));
|
||||
}
|
||||
if (c.getServerlessV2MaxCapacity() != null) {
|
||||
xml.elem("MaxCapacity", String.valueOf(c.getServerlessV2MaxCapacity()));
|
||||
}
|
||||
xml.end("ServerlessV2ScalingConfiguration");
|
||||
}
|
||||
xml.start("DBClusterMembers");
|
||||
List<String> members = c.getDbClusterMembers();
|
||||
if (members != null) {
|
||||
for (String memberId : members) {
|
||||
xml.start("DBClusterMember")
|
||||
.elem("DBInstanceIdentifier", memberId)
|
||||
.elem("IsClusterWriter", true)
|
||||
.end("member");
|
||||
.elem("IsClusterWriter", memberId.equals(members.get(0)))
|
||||
.end("DBClusterMember");
|
||||
}
|
||||
}
|
||||
xml.end("DBClusterMembers");
|
||||
@@ -261,7 +514,16 @@ public class NeptuneQueryHandler {
|
||||
}
|
||||
|
||||
private String instanceInnerXml(NeptuneInstance i) {
|
||||
return new XmlBuilder()
|
||||
NeptuneCluster cluster = service.findDbCluster(i.getDbClusterIdentifier()).orElse(null);
|
||||
String backupWindow = i.getPreferredBackupWindow() != null ? i.getPreferredBackupWindow()
|
||||
: cluster != null && cluster.getPreferredBackupWindow() != null ? cluster.getPreferredBackupWindow()
|
||||
: BackupWindows.DEFAULT_BACKUP_WINDOW;
|
||||
String subnetGroup = i.getDbSubnetGroupName() != null ? i.getDbSubnetGroupName()
|
||||
: cluster != null && cluster.getDbSubnetGroupName() != null ? cluster.getDbSubnetGroupName()
|
||||
: "default";
|
||||
String parameterGroup = i.getDbParameterGroupName() != null ? i.getDbParameterGroupName()
|
||||
: "default." + NeptuneService.parameterGroupFamily(i.getEngineVersion());
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.elem("DBInstanceIdentifier", i.getDbInstanceIdentifier())
|
||||
.elem("DBClusterIdentifier", i.getDbClusterIdentifier())
|
||||
.elem("DBInstanceClass", i.getDbInstanceClass())
|
||||
@@ -274,11 +536,34 @@ public class NeptuneQueryHandler {
|
||||
.end("Endpoint")
|
||||
.elem("IAMDatabaseAuthenticationEnabled", i.isIamDatabaseAuthenticationEnabled())
|
||||
.elem("MultiAZ", false)
|
||||
.elem("StorageEncrypted", true)
|
||||
.elem("AvailabilityZone", config.defaultAvailabilityZone())
|
||||
.elem("AutoMinorVersionUpgrade", i.isAutoMinorVersionUpgrade())
|
||||
.elem("PromotionTier", i.getPromotionTier())
|
||||
.elem("PubliclyAccessible", i.isPubliclyAccessible())
|
||||
.elem("StorageEncrypted", cluster != null && cluster.isStorageEncrypted())
|
||||
.elem("KmsKeyId", cluster != null ? cluster.getKmsKeyId() : null)
|
||||
.elem("StorageType", cluster != null ? cluster.getStorageType() : null)
|
||||
.elem("AvailabilityZone", i.getAvailabilityZone() != null
|
||||
? i.getAvailabilityZone() : config.defaultAvailabilityZone())
|
||||
.elem("PreferredBackupWindow", backupWindow)
|
||||
.elem("PreferredMaintenanceWindow", i.getPreferredMaintenanceWindow() != null
|
||||
? i.getPreferredMaintenanceWindow() : BackupWindows.DEFAULT_MAINTENANCE_WINDOW)
|
||||
.elem("DbiResourceId", i.getDbiResourceId())
|
||||
.elem("DBInstanceArn", i.getDbInstanceArn())
|
||||
.build();
|
||||
.elem("DBInstanceArn", i.getDbInstanceArn());
|
||||
if (i.getCreatedAt() != null) {
|
||||
xml.elem("InstanceCreateTime",
|
||||
DateTimeFormatter.ISO_INSTANT.format(i.getCreatedAt().truncatedTo(ChronoUnit.MILLIS)));
|
||||
}
|
||||
xml.start("DBSubnetGroup")
|
||||
.elem("DBSubnetGroupName", subnetGroup)
|
||||
.elem("SubnetGroupStatus", "Complete")
|
||||
.end("DBSubnetGroup")
|
||||
.start("DBParameterGroups")
|
||||
.start("DBParameterGroup")
|
||||
.elem("DBParameterGroupName", parameterGroup)
|
||||
.elem("ParameterApplyStatus", "in-sync")
|
||||
.end("DBParameterGroup")
|
||||
.end("DBParameterGroups");
|
||||
return xml.build();
|
||||
}
|
||||
|
||||
private static String extractFilterValue(MultivaluedMap<String, String> params, String filterName) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.neptune;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
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.StorageBackend;
|
||||
@@ -9,8 +10,10 @@ import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.neptune.container.NeptuneContainerHandle;
|
||||
import io.github.hectorvent.floci.services.neptune.container.NeptuneContainerManager;
|
||||
import io.github.hectorvent.floci.services.neptune.model.NeptuneCluster;
|
||||
import io.github.hectorvent.floci.services.neptune.model.NeptuneClusterSettings;
|
||||
import io.github.hectorvent.floci.services.neptune.model.NeptuneDbType;
|
||||
import io.github.hectorvent.floci.services.neptune.model.NeptuneInstance;
|
||||
import io.github.hectorvent.floci.services.neptune.model.NeptuneInstanceSettings;
|
||||
import io.github.hectorvent.floci.services.neptune.proxy.NeptuneProxyManager;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -19,10 +22,14 @@ import org.jboss.logging.Logger;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@ApplicationScoped
|
||||
public class NeptuneService {
|
||||
@@ -57,13 +64,19 @@ public class NeptuneService {
|
||||
// ── Clusters ──────────────────────────────────────────────────────────────
|
||||
|
||||
public NeptuneCluster createDbCluster(String id, String engineVersion, boolean iamEnabled) {
|
||||
return createDbCluster(id, engineVersion, iamEnabled, NeptuneClusterSettings.defaults(), Map.of());
|
||||
}
|
||||
|
||||
public NeptuneCluster createDbCluster(String id, String engineVersion, boolean iamEnabled,
|
||||
NeptuneClusterSettings settings, Map<String, String> tags) {
|
||||
settings.validate();
|
||||
if (clusters.get(id).isPresent()) {
|
||||
throw new AwsException("DBClusterAlreadyExistsFault",
|
||||
"Neptune cluster " + id + " already exists.", 400);
|
||||
}
|
||||
|
||||
// Open the try immediately after reserving the port so config reads below can't leak it.
|
||||
int proxyPort = allocateProxyPort();
|
||||
int proxyPort = allocateProxyPort(settings.port());
|
||||
NeptuneContainerHandle handle = null;
|
||||
boolean provisioned = false;
|
||||
try {
|
||||
@@ -104,6 +117,10 @@ public class NeptuneService {
|
||||
cluster.setCreatedAt(Instant.now());
|
||||
cluster.setDbClusterMembers(new ArrayList<>());
|
||||
cluster.setProxyPort(proxyPort);
|
||||
settings.applyTo(cluster);
|
||||
if (tags != null && !tags.isEmpty()) {
|
||||
cluster.setTags(tags);
|
||||
}
|
||||
|
||||
if (handle != null) {
|
||||
cluster.setContainerId(handle.getContainerId());
|
||||
@@ -182,6 +199,16 @@ public class NeptuneService {
|
||||
return instances.get(id).isPresent();
|
||||
}
|
||||
|
||||
public boolean hasResourceWithArn(String arn) {
|
||||
if (arn == null || !arn.startsWith("arn:")) {
|
||||
return false;
|
||||
}
|
||||
return clusters.scan(k -> true).stream()
|
||||
.anyMatch(c -> arn.equalsIgnoreCase(c.getDbClusterArn()))
|
||||
|| instances.scan(k -> true).stream()
|
||||
.anyMatch(i -> arn.equalsIgnoreCase(i.getDbInstanceArn()));
|
||||
}
|
||||
|
||||
public Collection<NeptuneCluster> listDbClusters(String filterId) {
|
||||
if (filterId != null && !filterId.isBlank()) {
|
||||
// The db-cluster-id filter accepts ARNs as well as identifiers. Match the
|
||||
@@ -199,6 +226,12 @@ public class NeptuneService {
|
||||
}
|
||||
|
||||
public NeptuneCluster modifyDbCluster(String id, String engineVersion, Boolean iamEnabled) {
|
||||
return modifyDbCluster(id, engineVersion, iamEnabled, NeptuneClusterSettings.unchanged());
|
||||
}
|
||||
|
||||
public NeptuneCluster modifyDbCluster(String id, String engineVersion, Boolean iamEnabled,
|
||||
NeptuneClusterSettings settings) {
|
||||
settings.validate();
|
||||
NeptuneCluster cluster = getDbCluster(id);
|
||||
if (engineVersion != null && !engineVersion.isBlank()) {
|
||||
cluster.setEngineVersion(engineVersion);
|
||||
@@ -206,6 +239,7 @@ public class NeptuneService {
|
||||
if (iamEnabled != null) {
|
||||
cluster.setIamDatabaseAuthenticationEnabled(iamEnabled);
|
||||
}
|
||||
settings.applyTo(cluster);
|
||||
clusters.put(id, cluster);
|
||||
LOG.infov("Neptune cluster {0} modified", id);
|
||||
return cluster;
|
||||
@@ -216,6 +250,10 @@ public class NeptuneService {
|
||||
new AwsException("DBClusterNotFoundFault",
|
||||
"Neptune cluster " + id + " not found.", 404));
|
||||
|
||||
if (cluster.isDeletionProtection()) {
|
||||
throw new AwsException("InvalidParameterCombination",
|
||||
"Cannot delete protected Cluster, please disable deletion protection and try again.", 400);
|
||||
}
|
||||
if (cluster.getDbClusterMembers() != null && !cluster.getDbClusterMembers().isEmpty()) {
|
||||
throw new AwsException("InvalidDBClusterStateFault",
|
||||
"Cannot delete Neptune cluster " + id + " — it still has DB instances.", 400);
|
||||
@@ -237,11 +275,69 @@ public class NeptuneService {
|
||||
LOG.infov("Neptune cluster {0} deleted", id);
|
||||
}
|
||||
|
||||
public NeptuneCluster addRoleToDbCluster(String id, String roleArn) {
|
||||
if (roleArn == null || roleArn.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValue", "RoleArn is required.", 400);
|
||||
}
|
||||
NeptuneCluster cluster = getDbCluster(id);
|
||||
if (cluster.getAssociatedRoleArns().contains(roleArn)) {
|
||||
throw new AwsException("DBClusterRoleAlreadyExists",
|
||||
"Role ARN " + roleArn + " is already associated with Neptune cluster " + id + ".", 400);
|
||||
}
|
||||
cluster.getAssociatedRoleArns().add(roleArn);
|
||||
clusters.put(id, cluster);
|
||||
LOG.infov("Role {0} added to Neptune cluster {1}", roleArn, id);
|
||||
return cluster;
|
||||
}
|
||||
|
||||
public NeptuneCluster removeRoleFromDbCluster(String id, String roleArn) {
|
||||
NeptuneCluster cluster = getDbCluster(id);
|
||||
if (roleArn == null || !cluster.getAssociatedRoleArns().remove(roleArn)) {
|
||||
throw new AwsException("DBClusterRoleNotFound",
|
||||
"Role ARN " + roleArn + " is not associated with Neptune cluster " + id + ".", 404);
|
||||
}
|
||||
clusters.put(id, cluster);
|
||||
LOG.infov("Role {0} removed from Neptune cluster {1}", roleArn, id);
|
||||
return cluster;
|
||||
}
|
||||
|
||||
public static String parameterGroupFamily(String engineVersion) {
|
||||
String version = engineVersion == null || engineVersion.isBlank() ? ENGINE_VERSION_DEFAULT : engineVersion.trim();
|
||||
String[] parts = version.split("\\.");
|
||||
int major;
|
||||
int minor;
|
||||
try {
|
||||
major = Integer.parseInt(parts[0]);
|
||||
minor = parts.length > 1 ? Integer.parseInt(parts[1]) : 0;
|
||||
} catch (NumberFormatException e) {
|
||||
return parameterGroupFamily(ENGINE_VERSION_DEFAULT);
|
||||
}
|
||||
if (major == 1 && minor < 2) {
|
||||
return "neptune1";
|
||||
}
|
||||
return "neptune" + major + "." + minor;
|
||||
}
|
||||
|
||||
// ── Instances ─────────────────────────────────────────────────────────────
|
||||
|
||||
public NeptuneInstance createDbInstance(String id, String dbClusterIdentifier,
|
||||
String dbInstanceClass, String engineVersion,
|
||||
boolean iamEnabled) {
|
||||
return createDbInstance(id, dbClusterIdentifier, dbInstanceClass, engineVersion, iamEnabled, Map.of());
|
||||
}
|
||||
|
||||
public NeptuneInstance createDbInstance(String id, String dbClusterIdentifier,
|
||||
String dbInstanceClass, String engineVersion,
|
||||
boolean iamEnabled, Map<String, String> tags) {
|
||||
return createDbInstance(id, dbClusterIdentifier, dbInstanceClass, engineVersion, iamEnabled,
|
||||
NeptuneInstanceSettings.defaults(), tags);
|
||||
}
|
||||
|
||||
public NeptuneInstance createDbInstance(String id, String dbClusterIdentifier,
|
||||
String dbInstanceClass, String engineVersion,
|
||||
boolean iamEnabled, NeptuneInstanceSettings settings,
|
||||
Map<String, String> tags) {
|
||||
settings.validate();
|
||||
if (instances.get(id).isPresent()) {
|
||||
throw new AwsException("DBInstanceAlreadyExists",
|
||||
"Neptune instance " + id + " already exists.", 400);
|
||||
@@ -263,6 +359,10 @@ public class NeptuneService {
|
||||
instance.setDbiResourceId("db-" + UUID.randomUUID().toString()
|
||||
.replace("-", "").substring(0, 24).toUpperCase());
|
||||
instance.setCreatedAt(Instant.now());
|
||||
settings.applyTo(instance);
|
||||
if (tags != null && !tags.isEmpty()) {
|
||||
instance.setTags(tags);
|
||||
}
|
||||
|
||||
cluster.getDbClusterMembers().add(id);
|
||||
clusters.put(dbClusterIdentifier, cluster);
|
||||
@@ -272,6 +372,10 @@ public class NeptuneService {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public Optional<NeptuneCluster> findDbCluster(String id) {
|
||||
return id == null ? Optional.empty() : clusters.get(id);
|
||||
}
|
||||
|
||||
public NeptuneInstance getDbInstance(String id) {
|
||||
return instances.get(id).orElseThrow(() ->
|
||||
new AwsException("DBInstanceNotFound",
|
||||
@@ -293,6 +397,12 @@ public class NeptuneService {
|
||||
}
|
||||
|
||||
public NeptuneInstance modifyDbInstance(String id, String dbInstanceClass, Boolean iamEnabled) {
|
||||
return modifyDbInstance(id, dbInstanceClass, iamEnabled, NeptuneInstanceSettings.unchanged());
|
||||
}
|
||||
|
||||
public NeptuneInstance modifyDbInstance(String id, String dbInstanceClass, Boolean iamEnabled,
|
||||
NeptuneInstanceSettings settings) {
|
||||
settings.validate();
|
||||
NeptuneInstance instance = getDbInstance(id);
|
||||
if (dbInstanceClass != null && !dbInstanceClass.isBlank()) {
|
||||
instance.setDbInstanceClass(dbInstanceClass);
|
||||
@@ -300,6 +410,7 @@ public class NeptuneService {
|
||||
if (iamEnabled != null) {
|
||||
instance.setIamDatabaseAuthenticationEnabled(iamEnabled);
|
||||
}
|
||||
settings.applyTo(instance);
|
||||
instances.put(id, instance);
|
||||
LOG.infov("Neptune instance {0} modified", id);
|
||||
return instance;
|
||||
@@ -321,15 +432,91 @@ public class NeptuneService {
|
||||
LOG.infov("Neptune instance {0} deleted", id);
|
||||
}
|
||||
|
||||
// ── Tags ──────────────────────────────────────────────────────────────────
|
||||
|
||||
private record TagTarget(Map<String, String> tags, Consumer<Map<String, String>> save) {}
|
||||
|
||||
public Map<String, String> listTagsForResource(String resourceName) {
|
||||
return Collections.unmodifiableMap(new LinkedHashMap<>(resolveTagTarget(resourceName).tags()));
|
||||
}
|
||||
|
||||
public synchronized void addTagsToResource(String resourceName, Map<String, String> tags) {
|
||||
updateTags(resourceName, current -> current.putAll(tags));
|
||||
}
|
||||
|
||||
public synchronized void removeTagsFromResource(String resourceName, Collection<String> tagKeys) {
|
||||
updateTags(resourceName, current -> tagKeys.forEach(current::remove));
|
||||
}
|
||||
|
||||
private void updateTags(String resourceName, Consumer<Map<String, String>> change) {
|
||||
TagTarget target = resolveTagTarget(resourceName);
|
||||
Map<String, String> updated = new LinkedHashMap<>(target.tags());
|
||||
change.accept(updated);
|
||||
target.save().accept(updated);
|
||||
}
|
||||
|
||||
private TagTarget resolveTagTarget(String resourceName) {
|
||||
if (resourceName == null || resourceName.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValue", "ResourceName is required.", 400);
|
||||
}
|
||||
AwsArnUtils.Arn arn;
|
||||
try {
|
||||
arn = AwsArnUtils.parse(resourceName);
|
||||
} catch (IllegalArgumentException malformed) {
|
||||
throw new AwsException("InvalidParameterValue", "Invalid resource name: " + resourceName, 400);
|
||||
}
|
||||
String resource = arn.resource();
|
||||
int separator = resource.indexOf(':');
|
||||
if (separator < 0) {
|
||||
throw new AwsException("InvalidParameterValue", "Invalid resource name: " + resourceName, 400);
|
||||
}
|
||||
String type = resource.substring(0, separator);
|
||||
String id = resource.substring(separator + 1);
|
||||
return switch (type) {
|
||||
case "cluster" -> {
|
||||
NeptuneCluster cluster = clusters.scan(k -> true).stream()
|
||||
.filter(c -> resourceName.equalsIgnoreCase(c.getDbClusterArn()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new AwsException("DBClusterNotFoundFault",
|
||||
"Neptune cluster " + id + " not found.", 404));
|
||||
yield new TagTarget(cluster.getTags(), updated -> {
|
||||
cluster.setTags(updated);
|
||||
clusters.put(cluster.getDbClusterIdentifier(), cluster);
|
||||
});
|
||||
}
|
||||
case "db" -> {
|
||||
NeptuneInstance instance = instances.scan(k -> true).stream()
|
||||
.filter(i -> resourceName.equalsIgnoreCase(i.getDbInstanceArn()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new AwsException("DBInstanceNotFound",
|
||||
"Neptune instance " + id + " not found.", 404));
|
||||
yield new TagTarget(instance.getTags(), updated -> {
|
||||
instance.setTags(updated);
|
||||
instances.put(instance.getDbInstanceIdentifier(), instance);
|
||||
});
|
||||
}
|
||||
default -> throw new AwsException("InvalidParameterValue",
|
||||
"Tagging for resource type '" + type + "' is not supported by Neptune in Floci: " + resourceName, 400);
|
||||
};
|
||||
}
|
||||
|
||||
// ── Helpers ───────────────────────────────────────────────────────────────
|
||||
|
||||
private String resolveEndpointHost() {
|
||||
return config.hostname().orElse("localhost");
|
||||
}
|
||||
|
||||
private int allocateProxyPort() {
|
||||
private int allocateProxyPort(Integer requested) {
|
||||
int base = config.services().neptune().proxyBasePort();
|
||||
int max = config.services().neptune().proxyMaxPort();
|
||||
if (requested != null && requested >= base && requested <= max && usedPorts.add(requested)) {
|
||||
return requested;
|
||||
}
|
||||
if (requested != null) {
|
||||
LOG.infov("Requested Neptune port {0} is outside the proxy range {1}-{2} or already in use; "
|
||||
+ "allocating the next free proxy port instead",
|
||||
String.valueOf(requested), String.valueOf(base), String.valueOf(max));
|
||||
}
|
||||
for (int port = base; port <= max; port++) {
|
||||
if (usedPorts.add(port)) {
|
||||
return port;
|
||||
|
||||
@@ -4,7 +4,9 @@ import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RegisterForReflection
|
||||
public class NeptuneCluster {
|
||||
@@ -19,6 +21,24 @@ public class NeptuneCluster {
|
||||
private String dbClusterArn;
|
||||
private String dbClusterResourceId;
|
||||
private List<String> dbClusterMembers = new ArrayList<>();
|
||||
private List<String> availabilityZones = new ArrayList<>();
|
||||
private int backupRetentionPeriod = 1;
|
||||
private String preferredBackupWindow;
|
||||
private String preferredMaintenanceWindow;
|
||||
private String dbSubnetGroupName;
|
||||
private String dbClusterParameterGroupName;
|
||||
private List<String> vpcSecurityGroupIds = new ArrayList<>();
|
||||
private boolean storageEncrypted;
|
||||
private String kmsKeyId;
|
||||
private String storageType;
|
||||
private boolean deletionProtection;
|
||||
private boolean copyTagsToSnapshot;
|
||||
private List<String> enabledCloudwatchLogsExports = new ArrayList<>();
|
||||
private List<String> associatedRoleArns = new ArrayList<>();
|
||||
private String replicationSourceIdentifier;
|
||||
private Double serverlessV2MinCapacity;
|
||||
private Double serverlessV2MaxCapacity;
|
||||
private Map<String, String> tags = new LinkedHashMap<>();
|
||||
private Instant createdAt;
|
||||
|
||||
// Docker / proxy runtime fields — persisted so cleanup works across restarts
|
||||
@@ -63,6 +83,77 @@ public class NeptuneCluster {
|
||||
this.dbClusterMembers = dbClusterMembers != null ? new ArrayList<>(dbClusterMembers) : new ArrayList<>();
|
||||
}
|
||||
|
||||
public List<String> getAvailabilityZones() { return availabilityZones; }
|
||||
public void setAvailabilityZones(List<String> availabilityZones) {
|
||||
this.availabilityZones = availabilityZones != null ? new ArrayList<>(availabilityZones) : new ArrayList<>();
|
||||
}
|
||||
|
||||
public int getBackupRetentionPeriod() { return backupRetentionPeriod; }
|
||||
public void setBackupRetentionPeriod(int backupRetentionPeriod) { this.backupRetentionPeriod = backupRetentionPeriod; }
|
||||
|
||||
public String getPreferredBackupWindow() { return preferredBackupWindow; }
|
||||
public void setPreferredBackupWindow(String preferredBackupWindow) { this.preferredBackupWindow = preferredBackupWindow; }
|
||||
|
||||
public String getPreferredMaintenanceWindow() { return preferredMaintenanceWindow; }
|
||||
public void setPreferredMaintenanceWindow(String preferredMaintenanceWindow) {
|
||||
this.preferredMaintenanceWindow = preferredMaintenanceWindow;
|
||||
}
|
||||
|
||||
public String getDbSubnetGroupName() { return dbSubnetGroupName; }
|
||||
public void setDbSubnetGroupName(String dbSubnetGroupName) { this.dbSubnetGroupName = dbSubnetGroupName; }
|
||||
|
||||
public String getDbClusterParameterGroupName() { return dbClusterParameterGroupName; }
|
||||
public void setDbClusterParameterGroupName(String dbClusterParameterGroupName) {
|
||||
this.dbClusterParameterGroupName = dbClusterParameterGroupName;
|
||||
}
|
||||
|
||||
public List<String> getVpcSecurityGroupIds() { return vpcSecurityGroupIds; }
|
||||
public void setVpcSecurityGroupIds(List<String> vpcSecurityGroupIds) {
|
||||
this.vpcSecurityGroupIds = vpcSecurityGroupIds != null ? new ArrayList<>(vpcSecurityGroupIds) : new ArrayList<>();
|
||||
}
|
||||
|
||||
public boolean isStorageEncrypted() { return storageEncrypted; }
|
||||
public void setStorageEncrypted(boolean storageEncrypted) { this.storageEncrypted = storageEncrypted; }
|
||||
|
||||
public String getKmsKeyId() { return kmsKeyId; }
|
||||
public void setKmsKeyId(String kmsKeyId) { this.kmsKeyId = kmsKeyId; }
|
||||
|
||||
public String getStorageType() { return storageType; }
|
||||
public void setStorageType(String storageType) { this.storageType = storageType; }
|
||||
|
||||
public boolean isDeletionProtection() { return deletionProtection; }
|
||||
public void setDeletionProtection(boolean deletionProtection) { this.deletionProtection = deletionProtection; }
|
||||
|
||||
public boolean isCopyTagsToSnapshot() { return copyTagsToSnapshot; }
|
||||
public void setCopyTagsToSnapshot(boolean copyTagsToSnapshot) { this.copyTagsToSnapshot = copyTagsToSnapshot; }
|
||||
|
||||
public List<String> getEnabledCloudwatchLogsExports() { return enabledCloudwatchLogsExports; }
|
||||
public void setEnabledCloudwatchLogsExports(List<String> enabledCloudwatchLogsExports) {
|
||||
this.enabledCloudwatchLogsExports = enabledCloudwatchLogsExports != null
|
||||
? new ArrayList<>(enabledCloudwatchLogsExports) : new ArrayList<>();
|
||||
}
|
||||
|
||||
public List<String> getAssociatedRoleArns() { return associatedRoleArns; }
|
||||
public void setAssociatedRoleArns(List<String> associatedRoleArns) {
|
||||
this.associatedRoleArns = associatedRoleArns != null ? new ArrayList<>(associatedRoleArns) : new ArrayList<>();
|
||||
}
|
||||
|
||||
public String getReplicationSourceIdentifier() { return replicationSourceIdentifier; }
|
||||
public void setReplicationSourceIdentifier(String replicationSourceIdentifier) {
|
||||
this.replicationSourceIdentifier = replicationSourceIdentifier;
|
||||
}
|
||||
|
||||
public Double getServerlessV2MinCapacity() { return serverlessV2MinCapacity; }
|
||||
public void setServerlessV2MinCapacity(Double serverlessV2MinCapacity) { this.serverlessV2MinCapacity = serverlessV2MinCapacity; }
|
||||
|
||||
public Double getServerlessV2MaxCapacity() { return serverlessV2MaxCapacity; }
|
||||
public void setServerlessV2MaxCapacity(Double serverlessV2MaxCapacity) { this.serverlessV2MaxCapacity = serverlessV2MaxCapacity; }
|
||||
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) {
|
||||
this.tags = tags != null ? new LinkedHashMap<>(tags) : new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
public Instant getCreatedAt() { return createdAt; }
|
||||
public void setCreatedAt(Instant createdAt) { this.createdAt = createdAt; }
|
||||
|
||||
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
package io.github.hectorvent.floci.services.neptune.model;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.BackupWindows;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* The settings of a Neptune cluster as a request carries them: a null member is one the request
|
||||
* left out, which means the AWS default on create and no change on modify.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
public record NeptuneClusterSettings(List<String> availabilityZones,
|
||||
Integer port,
|
||||
Integer backupRetentionPeriod,
|
||||
String preferredBackupWindow,
|
||||
String preferredMaintenanceWindow,
|
||||
String dbSubnetGroupName,
|
||||
String dbClusterParameterGroupName,
|
||||
List<String> vpcSecurityGroupIds,
|
||||
Boolean storageEncrypted,
|
||||
String kmsKeyId,
|
||||
String storageType,
|
||||
Boolean deletionProtection,
|
||||
Boolean copyTagsToSnapshot,
|
||||
List<String> enableLogTypes,
|
||||
List<String> disableLogTypes,
|
||||
String replicationSourceIdentifier,
|
||||
Double serverlessV2MinCapacity,
|
||||
Double serverlessV2MaxCapacity) {
|
||||
|
||||
public static final Set<String> STORAGE_TYPES = Set.of("standard", "iopt1");
|
||||
public static final Set<String> LOG_TYPES = Set.of("audit", "slowquery");
|
||||
|
||||
public static NeptuneClusterSettings defaults() {
|
||||
return new NeptuneClusterSettings(null, null, null, null, null, null, null, null, null,
|
||||
null, null, null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
public static NeptuneClusterSettings unchanged() {
|
||||
return defaults();
|
||||
}
|
||||
|
||||
public void validate() {
|
||||
if (kmsKeyId != null && !kmsKeyId.isBlank() && !Boolean.TRUE.equals(storageEncrypted)) {
|
||||
throw new AwsException("InvalidParameterCombination",
|
||||
"You cannot specify KMS key for unencrypted clusters.", 400);
|
||||
}
|
||||
if (port != null && (port < 1150 || port > 65535)) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Invalid port: " + port + ". Port must be between 1150 and 65535.", 400);
|
||||
}
|
||||
if (backupRetentionPeriod != null && (backupRetentionPeriod < 1 || backupRetentionPeriod > 35)) {
|
||||
throw new AwsException("InvalidParameterValue", "Invalid backup retention period: "
|
||||
+ backupRetentionPeriod + ". Retention period must be between 1 and 35.", 400);
|
||||
}
|
||||
if (preferredBackupWindow != null) {
|
||||
BackupWindows.parseBackupWindow(preferredBackupWindow);
|
||||
}
|
||||
if (preferredMaintenanceWindow != null) {
|
||||
BackupWindows.parseMaintenanceWindow(preferredMaintenanceWindow);
|
||||
}
|
||||
if (storageType != null && !storageType.isBlank() && !STORAGE_TYPES.contains(storageType)) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Invalid storage type: " + storageType + ". Valid values are standard and iopt1.", 400);
|
||||
}
|
||||
if (serverlessV2MinCapacity != null && serverlessV2MaxCapacity != null
|
||||
&& serverlessV2MinCapacity > serverlessV2MaxCapacity) {
|
||||
throw new AwsException("InvalidParameterCombination",
|
||||
"ServerlessV2ScalingConfiguration MinCapacity must not exceed MaxCapacity.", 400);
|
||||
}
|
||||
requireKnownLogTypes(enableLogTypes);
|
||||
requireKnownLogTypes(disableLogTypes);
|
||||
}
|
||||
|
||||
private static void requireKnownLogTypes(List<String> logTypes) {
|
||||
if (logTypes == null) {
|
||||
return;
|
||||
}
|
||||
for (String logType : logTypes) {
|
||||
if (!LOG_TYPES.contains(logType)) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Invalid log type: " + logType + ". Valid values are audit and slowquery.", 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void applyTo(NeptuneCluster cluster) {
|
||||
if (availabilityZones != null && !availabilityZones.isEmpty()) {
|
||||
cluster.setAvailabilityZones(availabilityZones);
|
||||
}
|
||||
if (backupRetentionPeriod != null) {
|
||||
cluster.setBackupRetentionPeriod(backupRetentionPeriod);
|
||||
}
|
||||
if (preferredBackupWindow != null && !preferredBackupWindow.isBlank()) {
|
||||
cluster.setPreferredBackupWindow(preferredBackupWindow);
|
||||
}
|
||||
if (preferredMaintenanceWindow != null && !preferredMaintenanceWindow.isBlank()) {
|
||||
cluster.setPreferredMaintenanceWindow(BackupWindows.lowerCase(preferredMaintenanceWindow));
|
||||
}
|
||||
if (dbSubnetGroupName != null && !dbSubnetGroupName.isBlank()) {
|
||||
cluster.setDbSubnetGroupName(dbSubnetGroupName);
|
||||
}
|
||||
if (dbClusterParameterGroupName != null && !dbClusterParameterGroupName.isBlank()) {
|
||||
cluster.setDbClusterParameterGroupName(dbClusterParameterGroupName);
|
||||
}
|
||||
if (vpcSecurityGroupIds != null) {
|
||||
cluster.setVpcSecurityGroupIds(vpcSecurityGroupIds);
|
||||
}
|
||||
if (storageEncrypted != null) {
|
||||
cluster.setStorageEncrypted(storageEncrypted);
|
||||
}
|
||||
if (kmsKeyId != null && !kmsKeyId.isBlank()) {
|
||||
cluster.setKmsKeyId(kmsKeyId);
|
||||
}
|
||||
if (storageType != null && !storageType.isBlank()) {
|
||||
cluster.setStorageType(storageType);
|
||||
}
|
||||
if (deletionProtection != null) {
|
||||
cluster.setDeletionProtection(deletionProtection);
|
||||
}
|
||||
if (copyTagsToSnapshot != null) {
|
||||
cluster.setCopyTagsToSnapshot(copyTagsToSnapshot);
|
||||
}
|
||||
if (enableLogTypes != null || disableLogTypes != null) {
|
||||
Set<String> logTypes = new LinkedHashSet<>(cluster.getEnabledCloudwatchLogsExports());
|
||||
if (disableLogTypes != null) {
|
||||
logTypes.removeAll(disableLogTypes);
|
||||
}
|
||||
if (enableLogTypes != null) {
|
||||
logTypes.addAll(enableLogTypes);
|
||||
}
|
||||
cluster.setEnabledCloudwatchLogsExports(new ArrayList<>(logTypes));
|
||||
}
|
||||
if (replicationSourceIdentifier != null && !replicationSourceIdentifier.isBlank()) {
|
||||
cluster.setReplicationSourceIdentifier(replicationSourceIdentifier);
|
||||
}
|
||||
if (serverlessV2MinCapacity != null) {
|
||||
cluster.setServerlessV2MinCapacity(serverlessV2MinCapacity);
|
||||
}
|
||||
if (serverlessV2MaxCapacity != null) {
|
||||
cluster.setServerlessV2MaxCapacity(serverlessV2MaxCapacity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package io.github.hectorvent.floci.services.neptune.model;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RegisterForReflection
|
||||
public class NeptuneInstance {
|
||||
@@ -17,6 +19,15 @@ public class NeptuneInstance {
|
||||
private boolean iamDatabaseAuthenticationEnabled;
|
||||
private String dbInstanceArn;
|
||||
private String dbiResourceId;
|
||||
private String availabilityZone;
|
||||
private boolean autoMinorVersionUpgrade = true;
|
||||
private int promotionTier = 1;
|
||||
private boolean publiclyAccessible;
|
||||
private String dbParameterGroupName;
|
||||
private String dbSubnetGroupName;
|
||||
private String preferredBackupWindow;
|
||||
private String preferredMaintenanceWindow;
|
||||
private Map<String, String> tags = new LinkedHashMap<>();
|
||||
private Instant createdAt;
|
||||
|
||||
public NeptuneInstance() {}
|
||||
@@ -53,6 +64,39 @@ public class NeptuneInstance {
|
||||
public String getDbiResourceId() { return dbiResourceId; }
|
||||
public void setDbiResourceId(String dbiResourceId) { this.dbiResourceId = dbiResourceId; }
|
||||
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) {
|
||||
this.tags = tags != null ? new LinkedHashMap<>(tags) : new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
public Instant getCreatedAt() { return createdAt; }
|
||||
public void setCreatedAt(Instant createdAt) { this.createdAt = createdAt; }
|
||||
|
||||
public String getAvailabilityZone() { return availabilityZone; }
|
||||
public void setAvailabilityZone(String availabilityZone) { this.availabilityZone = availabilityZone; }
|
||||
|
||||
public boolean isAutoMinorVersionUpgrade() { return autoMinorVersionUpgrade; }
|
||||
public void setAutoMinorVersionUpgrade(boolean autoMinorVersionUpgrade) {
|
||||
this.autoMinorVersionUpgrade = autoMinorVersionUpgrade;
|
||||
}
|
||||
|
||||
public int getPromotionTier() { return promotionTier; }
|
||||
public void setPromotionTier(int promotionTier) { this.promotionTier = promotionTier; }
|
||||
|
||||
public boolean isPubliclyAccessible() { return publiclyAccessible; }
|
||||
public void setPubliclyAccessible(boolean publiclyAccessible) { this.publiclyAccessible = publiclyAccessible; }
|
||||
|
||||
public String getDbParameterGroupName() { return dbParameterGroupName; }
|
||||
public void setDbParameterGroupName(String dbParameterGroupName) { this.dbParameterGroupName = dbParameterGroupName; }
|
||||
|
||||
public String getDbSubnetGroupName() { return dbSubnetGroupName; }
|
||||
public void setDbSubnetGroupName(String dbSubnetGroupName) { this.dbSubnetGroupName = dbSubnetGroupName; }
|
||||
|
||||
public String getPreferredBackupWindow() { return preferredBackupWindow; }
|
||||
public void setPreferredBackupWindow(String preferredBackupWindow) { this.preferredBackupWindow = preferredBackupWindow; }
|
||||
|
||||
public String getPreferredMaintenanceWindow() { return preferredMaintenanceWindow; }
|
||||
public void setPreferredMaintenanceWindow(String preferredMaintenanceWindow) {
|
||||
this.preferredMaintenanceWindow = preferredMaintenanceWindow;
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package io.github.hectorvent.floci.services.neptune.model;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.BackupWindows;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
public record NeptuneInstanceSettings(String availabilityZone,
|
||||
Boolean autoMinorVersionUpgrade,
|
||||
Integer promotionTier,
|
||||
Boolean publiclyAccessible,
|
||||
String dbParameterGroupName,
|
||||
String dbSubnetGroupName,
|
||||
String preferredBackupWindow,
|
||||
String preferredMaintenanceWindow) {
|
||||
|
||||
public static NeptuneInstanceSettings defaults() {
|
||||
return new NeptuneInstanceSettings(null, null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
public static NeptuneInstanceSettings unchanged() {
|
||||
return defaults();
|
||||
}
|
||||
|
||||
public void validate() {
|
||||
if (promotionTier != null && (promotionTier < 0 || promotionTier > 15)) {
|
||||
throw new AwsException("InvalidParameterValue", "Invalid promotion tier: " + promotionTier
|
||||
+ ". Promotion tier must be between 0 and 15.", 400);
|
||||
}
|
||||
if (preferredBackupWindow != null && !preferredBackupWindow.isBlank()) {
|
||||
BackupWindows.parseBackupWindow(preferredBackupWindow);
|
||||
}
|
||||
if (preferredMaintenanceWindow != null && !preferredMaintenanceWindow.isBlank()) {
|
||||
BackupWindows.parseMaintenanceWindow(preferredMaintenanceWindow);
|
||||
}
|
||||
}
|
||||
|
||||
public void applyTo(NeptuneInstance instance) {
|
||||
if (availabilityZone != null && !availabilityZone.isBlank()) {
|
||||
instance.setAvailabilityZone(availabilityZone);
|
||||
}
|
||||
if (autoMinorVersionUpgrade != null) {
|
||||
instance.setAutoMinorVersionUpgrade(autoMinorVersionUpgrade);
|
||||
}
|
||||
if (promotionTier != null) {
|
||||
instance.setPromotionTier(promotionTier);
|
||||
}
|
||||
if (publiclyAccessible != null) {
|
||||
instance.setPubliclyAccessible(publiclyAccessible);
|
||||
}
|
||||
if (dbParameterGroupName != null && !dbParameterGroupName.isBlank()) {
|
||||
instance.setDbParameterGroupName(dbParameterGroupName);
|
||||
}
|
||||
if (dbSubnetGroupName != null && !dbSubnetGroupName.isBlank()) {
|
||||
instance.setDbSubnetGroupName(dbSubnetGroupName);
|
||||
}
|
||||
if (preferredBackupWindow != null && !preferredBackupWindow.isBlank()) {
|
||||
instance.setPreferredBackupWindow(preferredBackupWindow);
|
||||
}
|
||||
if (preferredMaintenanceWindow != null && !preferredMaintenanceWindow.isBlank()) {
|
||||
instance.setPreferredMaintenanceWindow(BackupWindows.lowerCase(preferredMaintenanceWindow));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user