mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
refactor(elasticache): move library usages to imports (#3899)
* refactor(elasticache): move library usages to imports * refactor(elasticache): move library usages to imports and eliminate var declarations * refactor(elasticache): extract entity variable in query handler test
This commit is contained in:
1 parent
45bfcc464e
commit
22bff32e19
12 files changed
+106
-96
No files matched your search
+23
-20
@@ -2,15 +2,15 @@ package io.github.hectorvent.floci.services.elasticache;
|
||||
|
||||
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.common.AwsNamespaces;
|
||||
import io.github.hectorvent.floci.core.common.AwsQueryResponse;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.XmlBuilder;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.AuthMode;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.CacheCluster;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.CacheParameterGroup;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.ClusterNode;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.CacheSubnetGroup;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.ClusterNode;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.ElastiCacheUser;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.Endpoint;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroup;
|
||||
@@ -23,6 +23,9 @@ import jakarta.ws.rs.core.MultivaluedMap;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -183,7 +186,7 @@ public class ElastiCacheQueryHandler {
|
||||
String filterId = params.getFirst("ReplicationGroupId");
|
||||
try {
|
||||
Collection<ReplicationGroup> groups = service.listReplicationGroups(filterId);
|
||||
var xml = new XmlBuilder().start("ReplicationGroups");
|
||||
XmlBuilder xml = new XmlBuilder().start("ReplicationGroups");
|
||||
for (ReplicationGroup g : groups) {
|
||||
xml.raw(replicationGroupXml(g));
|
||||
}
|
||||
@@ -272,7 +275,7 @@ public class ElastiCacheQueryHandler {
|
||||
String filterEngine = params.getFirst("Engine");
|
||||
try {
|
||||
Collection<ElastiCacheUser> users = service.listUsers(filterId, filterEngine);
|
||||
var xml = new XmlBuilder().start("Users");
|
||||
XmlBuilder xml = new XmlBuilder().start("Users");
|
||||
for (ElastiCacheUser u : users) {
|
||||
xml.start("member").raw(userXml(u)).end("member");
|
||||
}
|
||||
@@ -346,7 +349,7 @@ public class ElastiCacheQueryHandler {
|
||||
} else {
|
||||
clusterList = memcachedService.listCacheClusters(filterId);
|
||||
}
|
||||
var xml = new XmlBuilder().start("CacheClusters");
|
||||
XmlBuilder xml = new XmlBuilder().start("CacheClusters");
|
||||
for (CacheCluster c : clusterList) {
|
||||
xml.raw(cacheClusterXml(c));
|
||||
}
|
||||
@@ -363,7 +366,7 @@ public class ElastiCacheQueryHandler {
|
||||
private String memberCacheClusterXml(ElastiCacheService.MemberCacheCluster member, boolean showNodeInfo) {
|
||||
ReplicationGroup g = member.group();
|
||||
boolean authTokenEnabled = g.getAuthMode() == AuthMode.PASSWORD;
|
||||
var xml = new XmlBuilder()
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.start("CacheCluster")
|
||||
.elem("CacheClusterId", member.cacheClusterId())
|
||||
.elem("CacheClusterStatus", memberCacheClusterStatus(g))
|
||||
@@ -440,7 +443,7 @@ public class ElastiCacheQueryHandler {
|
||||
params.getFirst("CacheSubnetGroupDescription"),
|
||||
parseSubnetIds(params),
|
||||
parseTags(params));
|
||||
var xml = new XmlBuilder();
|
||||
XmlBuilder xml = new XmlBuilder();
|
||||
appendSubnetGroup(xml, group);
|
||||
return Response.ok(AwsQueryResponse.envelope("CreateCacheSubnetGroup", AwsNamespaces.EC, xml.build())).build();
|
||||
} catch (AwsException e) {
|
||||
@@ -452,7 +455,7 @@ public class ElastiCacheQueryHandler {
|
||||
try {
|
||||
List<CacheSubnetGroup> groups =
|
||||
service.describeCacheSubnetGroups(params.getFirst("CacheSubnetGroupName"));
|
||||
var xml = new XmlBuilder().start("CacheSubnetGroups");
|
||||
XmlBuilder xml = new XmlBuilder().start("CacheSubnetGroups");
|
||||
groups.forEach(group -> appendSubnetGroup(xml, group));
|
||||
xml.end("CacheSubnetGroups");
|
||||
return Response.ok(AwsQueryResponse.envelope("DescribeCacheSubnetGroups", AwsNamespaces.EC, xml.build())).build();
|
||||
@@ -467,7 +470,7 @@ public class ElastiCacheQueryHandler {
|
||||
params.getFirst("CacheSubnetGroupName"),
|
||||
params.getFirst("CacheSubnetGroupDescription"),
|
||||
parseSubnetIds(params));
|
||||
var xml = new XmlBuilder();
|
||||
XmlBuilder xml = new XmlBuilder();
|
||||
appendSubnetGroup(xml, group);
|
||||
return Response.ok(AwsQueryResponse.envelope("ModifyCacheSubnetGroup", AwsNamespaces.EC, xml.build())).build();
|
||||
} catch (AwsException e) {
|
||||
@@ -525,7 +528,7 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
|
||||
params.getFirst("CacheParameterGroupFamily"),
|
||||
params.getFirst("Description"),
|
||||
parseTags(params));
|
||||
var xml = new XmlBuilder();
|
||||
XmlBuilder xml = new XmlBuilder();
|
||||
appendParameterGroup(xml, group);
|
||||
return Response.ok(AwsQueryResponse.envelope("CreateCacheParameterGroup", AwsNamespaces.EC, xml.build())).build();
|
||||
} catch (AwsException e) {
|
||||
@@ -537,7 +540,7 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
|
||||
try {
|
||||
List<CacheParameterGroup> groups =
|
||||
service.describeCacheParameterGroups(params.getFirst("CacheParameterGroupName"));
|
||||
var xml = new XmlBuilder().start("CacheParameterGroups");
|
||||
XmlBuilder xml = new XmlBuilder().start("CacheParameterGroups");
|
||||
groups.forEach(group -> appendParameterGroup(xml, group));
|
||||
xml.end("CacheParameterGroups");
|
||||
return Response.ok(AwsQueryResponse.envelope("DescribeCacheParameterGroups", AwsNamespaces.EC, xml.build())).build();
|
||||
@@ -550,7 +553,7 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
|
||||
try {
|
||||
String name = params.getFirst("CacheParameterGroupName");
|
||||
service.modifyCacheParameterGroup(name, parseParameterNameValues(params));
|
||||
var xml = new XmlBuilder().elem("CacheParameterGroupName", name);
|
||||
XmlBuilder xml = new XmlBuilder().elem("CacheParameterGroupName", name);
|
||||
return Response.ok(AwsQueryResponse.envelope("ModifyCacheParameterGroup", AwsNamespaces.EC, xml.build())).build();
|
||||
} catch (AwsException e) {
|
||||
return AwsQueryResponse.error(e.getErrorCode(), e.getMessage(), AwsNamespaces.EC, e.getHttpStatus());
|
||||
@@ -565,7 +568,7 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
|
||||
String source = params.getFirst("Source");
|
||||
boolean includeUserParameters = source == null || source.isBlank() || "user".equals(source);
|
||||
|
||||
var xml = new XmlBuilder().start("Parameters");
|
||||
XmlBuilder xml = new XmlBuilder().start("Parameters");
|
||||
if (includeUserParameters) {
|
||||
group.getParameters().forEach((name, value) -> xml
|
||||
.start("Parameter")
|
||||
@@ -632,7 +635,7 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
|
||||
arn[6] + " is not present", 404))
|
||||
.getTags();
|
||||
}
|
||||
var xml = new XmlBuilder().start("TagList");
|
||||
XmlBuilder xml = new XmlBuilder().start("TagList");
|
||||
tags.forEach((key, value) -> xml.start("Tag")
|
||||
.elem("Key", key)
|
||||
.elem("Value", value)
|
||||
@@ -731,7 +734,7 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
|
||||
|
||||
private String cacheClusterXml(CacheCluster c) {
|
||||
Endpoint ep = c.getConfigurationEndpoint();
|
||||
var xml = new XmlBuilder()
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.start("CacheCluster")
|
||||
.elem("CacheClusterId", c.getCacheClusterId())
|
||||
.elem("CacheClusterStatus", c.getCacheClusterStatus().name().toLowerCase())
|
||||
@@ -762,7 +765,7 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
|
||||
Endpoint ep = g.getConfigurationEndpoint();
|
||||
boolean authTokenEnabled = g.getAuthMode() == AuthMode.PASSWORD;
|
||||
List<ElastiCacheService.MemberCacheCluster> members = service.memberCacheClusters(g);
|
||||
var xml = new XmlBuilder()
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.start("ReplicationGroup")
|
||||
.elem("ReplicationGroupId", g.getReplicationGroupId())
|
||||
.elem("Description", g.getDescription())
|
||||
@@ -902,7 +905,7 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
|
||||
|
||||
private static String extractUriHost(String token) {
|
||||
try {
|
||||
return java.net.URI.create("http://" + token).getHost();
|
||||
return URI.create("http://" + token).getHost();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
@@ -910,15 +913,15 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
|
||||
|
||||
private static String extractQueryParam(String token, String name) {
|
||||
try {
|
||||
String rawQuery = java.net.URI.create("http://" + token).getRawQuery();
|
||||
String rawQuery = URI.create("http://" + token).getRawQuery();
|
||||
if (rawQuery == null) {
|
||||
return "";
|
||||
}
|
||||
for (String pair : rawQuery.split("&")) {
|
||||
int eq = pair.indexOf('=');
|
||||
if (eq >= 0 && name.equals(pair.substring(0, eq))) {
|
||||
return java.net.URLDecoder.decode(pair.substring(eq + 1),
|
||||
java.nio.charset.StandardCharsets.UTF_8);
|
||||
return URLDecoder.decode(pair.substring(eq + 1),
|
||||
StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
+8
-7
@@ -11,6 +11,8 @@ import io.github.hectorvent.floci.core.resource.SupportedResourceType;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.ec2.Ec2Service;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Subnet;
|
||||
import io.github.hectorvent.floci.services.elasticache.container.ElastiCacheContainerHandle;
|
||||
import io.github.hectorvent.floci.services.elasticache.container.ElastiCacheContainerManager;
|
||||
import io.github.hectorvent.floci.services.elasticache.container.ValkeyClusterFormation;
|
||||
@@ -18,13 +20,14 @@ import io.github.hectorvent.floci.services.elasticache.model.AuthMode;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.CacheParameterGroup;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.CacheSubnetGroup;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.ClusterNode;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.Endpoint;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.ElastiCacheUser;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.Endpoint;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroup;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroupSettings;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroupStatus;
|
||||
import io.github.hectorvent.floci.services.ec2.Ec2Service;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Subnet;
|
||||
import io.github.hectorvent.floci.services.elasticache.proxy.ElastiCacheProxyManager;
|
||||
import io.github.hectorvent.floci.services.kms.KmsService;
|
||||
import io.github.hectorvent.floci.services.kms.model.KmsKey;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
@@ -35,13 +38,11 @@ import java.net.UnknownHostException;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroupSettings;
|
||||
import io.github.hectorvent.floci.services.kms.KmsService;
|
||||
import io.github.hectorvent.floci.services.kms.model.KmsKey;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -1200,7 +1201,7 @@ public class ElastiCacheService implements ResourceProvider {
|
||||
}
|
||||
|
||||
/** The group by that name, whether stored or one of the published defaults. */
|
||||
public java.util.Optional<CacheParameterGroup> findParameterGroup(String name) {
|
||||
public Optional<CacheParameterGroup> findParameterGroup(String name) {
|
||||
return parameterGroups.get(name)
|
||||
.or(() -> defaultParameterGroups().stream()
|
||||
.filter(group -> group.getName().equals(name))
|
||||
|
||||
+2
-1
@@ -12,6 +12,7 @@ import java.net.Socket;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Forms a Valkey cluster out of freshly started cluster-enabled nodes, the way
|
||||
@@ -158,7 +159,7 @@ public class ValkeyClusterFormation {
|
||||
}
|
||||
|
||||
private static boolean allMatch(List<RespClient> clients,
|
||||
java.util.function.Predicate<String> infoPredicate) throws IOException {
|
||||
Predicate<String> infoPredicate) throws IOException {
|
||||
for (RespClient client : clients) {
|
||||
if (!infoPredicate.test(client.callString("CLUSTER", "INFO"))) {
|
||||
return false;
|
||||
|
||||
Reference in new issue
Block a user