diff options
author | Harald Musum <musum@yahooinc.com> | 2023-09-04 14:56:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-04 14:56:49 +0200 |
commit | 6e298f7f8f3130cd8f3f75702ef1e10a0f5d55cc (patch) | |
tree | 04859bba148bf4609d9509538e481931490eb273 /configserver/src | |
parent | e428de004953c5015936ee14714af8984b026c18 (diff) |
Revert "Add auth method to ApplicationClusterEndpoint"
Diffstat (limited to 'configserver/src')
2 files changed, 24 insertions, 72 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/ContainerEndpointSerializer.java b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/ContainerEndpointSerializer.java index 33f47bbc154..b813d56b345 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/ContainerEndpointSerializer.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/ContainerEndpointSerializer.java @@ -11,7 +11,6 @@ import com.yahoo.slime.SlimeUtils; import java.util.ArrayList; import java.util.List; -import java.util.OptionalInt; /** * Contains all methods for de-/serializing ContainerEndpoints to/from JSON. @@ -33,48 +32,48 @@ public class ContainerEndpointSerializer { private static final String namesField = "names"; private static final String weightField = "weight"; private static final String routingMethodField = "routingMethod"; - private static final String authMethodField = "authMethod"; private ContainerEndpointSerializer() {} public static ContainerEndpoint endpointFromSlime(Inspector inspector) { - String clusterId = inspector.field(clusterIdField).asString(); - String scope = inspector.field(scopeField).asString(); - Inspector namesInspector = inspector.field(namesField); - OptionalInt weight = SlimeUtils.optionalInteger(inspector.field(weightField)); + final var clusterId = inspector.field(clusterIdField).asString(); + final var scope = inspector.field(scopeField).asString(); + final var namesInspector = inspector.field(namesField); + final var weight = SlimeUtils.optionalInteger(inspector.field(weightField)); // assign default routingmethod. Remove when 7.507 is latest version - // Cannot be used before all endpoints are assigned explicit routing method (from controller) - ApplicationClusterEndpoint.RoutingMethod routingMethod = SlimeUtils.optionalString(inspector.field(routingMethodField)) - .map(ContainerEndpointSerializer::routingMethodFrom) - .orElse(ApplicationClusterEndpoint.RoutingMethod.sharedLayer4); - ApplicationClusterEndpoint.AuthMethod authMethod = SlimeUtils.optionalString(inspector.field(authMethodField)) - .map(ContainerEndpointSerializer::authMethodFrom) - .orElse(ApplicationClusterEndpoint.AuthMethod.mtls); + // Cannot be used before all endpoints are assigned explicit routingmethod (from controller) + final var routingMethod = SlimeUtils.optionalString(inspector.field(routingMethodField)).orElse(ApplicationClusterEndpoint.RoutingMethod.sharedLayer4.name()); if (clusterId.isEmpty()) { throw new IllegalStateException("'clusterId' missing on serialized ContainerEndpoint"); } + if (scope.isEmpty()) { throw new IllegalStateException("'scope' missing on serialized ContainerEndpoint"); } - if (!namesInspector.valid()) { + + if (! namesInspector.valid()) { throw new IllegalStateException("'names' missing on serialized ContainerEndpoint"); } - List<String> names = new ArrayList<>(); + if(routingMethod.isEmpty()) { + throw new IllegalStateException("'routingMethod' missing on serialized ContainerEndpoint"); + } + + final var names = new ArrayList<String>(); namesInspector.traverse((ArrayTraverser) (idx, nameInspector) -> { final var containerName = nameInspector.asString(); names.add(containerName); }); - return new ContainerEndpoint(clusterId, scopeFrom(scope), names, weight, routingMethod, authMethod); + return new ContainerEndpoint(clusterId, ApplicationClusterEndpoint.Scope.valueOf(scope), names, weight, + ApplicationClusterEndpoint.RoutingMethod.valueOf(routingMethod)); } public static List<ContainerEndpoint> endpointListFromSlime(Slime slime) { final var inspector = slime.get(); return endpointListFromSlime(inspector); } - public static List<ContainerEndpoint> endpointListFromSlime(Inspector inspector) { final var endpoints = new ArrayList<ContainerEndpoint>(); @@ -89,12 +88,11 @@ public class ContainerEndpointSerializer { public static void endpointToSlime(Cursor cursor, ContainerEndpoint endpoint) { cursor.setString(clusterIdField, endpoint.clusterId()); - cursor.setString(scopeField, asString(endpoint.scope())); + cursor.setString(scopeField, endpoint.scope().name()); endpoint.weight().ifPresent(w -> cursor.setLong(weightField, w)); final var namesInspector = cursor.setArray(namesField); endpoint.names().forEach(namesInspector::addString); - cursor.setString(routingMethodField, asString(endpoint.routingMethod())); - cursor.setString(authMethodField, asString(endpoint.authMethod())); + cursor.setString(routingMethodField, endpoint.routingMethod().name()); } public static Slime endpointListToSlime(List<ContainerEndpoint> endpoints) { @@ -109,53 +107,4 @@ public class ContainerEndpointSerializer { return slime; } - private static ApplicationClusterEndpoint.RoutingMethod routingMethodFrom(String s) { - return switch (s) { - case "shared" -> ApplicationClusterEndpoint.RoutingMethod.shared; - case "sharedLayer4" -> ApplicationClusterEndpoint.RoutingMethod.sharedLayer4; - case "exclusive" -> ApplicationClusterEndpoint.RoutingMethod.exclusive; - default -> throw new IllegalArgumentException("Unknown routing method '" + s + "'"); - }; - } - - private static ApplicationClusterEndpoint.AuthMethod authMethodFrom(String s) { - return switch (s) { - case "mtls" -> ApplicationClusterEndpoint.AuthMethod.mtls; - case "token" -> ApplicationClusterEndpoint.AuthMethod.token; - default -> throw new IllegalArgumentException("Unknown auth method '" + s + "'"); - }; - } - - private static ApplicationClusterEndpoint.Scope scopeFrom(String s) { - return switch (s) { - case "global" -> ApplicationClusterEndpoint.Scope.global; - case "application" -> ApplicationClusterEndpoint.Scope.application; - case "zone" -> ApplicationClusterEndpoint.Scope.zone; - default -> throw new IllegalArgumentException("Unknown scope '" + s + "'"); - }; - } - - private static String asString(ApplicationClusterEndpoint.RoutingMethod routingMethod) { - return switch (routingMethod) { - case shared -> "shared"; - case sharedLayer4 -> "sharedLayer4"; - case exclusive -> "exclusive"; - }; - } - - private static String asString(ApplicationClusterEndpoint.AuthMethod authMethod) { - return switch (authMethod) { - case mtls -> "mtls"; - case token -> "token"; - }; - } - - private static String asString(ApplicationClusterEndpoint.Scope scope) { - return switch (scope) { - case global -> "global"; - case application -> "application"; - case zone -> "zone"; - }; - } - } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/ContainerEndpointSerializerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/ContainerEndpointSerializerTest.java index 5e7fe64f998..c8f31697c5e 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/ContainerEndpointSerializerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/ContainerEndpointSerializerTest.java @@ -8,6 +8,7 @@ import org.junit.Test; import java.util.List; import java.util.OptionalInt; +import java.util.OptionalLong; import static org.junit.Assert.assertEquals; @@ -45,9 +46,11 @@ public class ContainerEndpointSerializerTest { @Test public void writeReadEndpoints() { - List<ContainerEndpoint> endpoints = List.of(new ContainerEndpoint("foo", ApplicationClusterEndpoint.Scope.global, List.of("a", "b"), OptionalInt.of(3), - ApplicationClusterEndpoint.RoutingMethod.shared, ApplicationClusterEndpoint.AuthMethod.token)); - assertEquals(endpoints, ContainerEndpointSerializer.endpointListFromSlime(ContainerEndpointSerializer.endpointListToSlime(endpoints))); + final var endpoints = List.of(new ContainerEndpoint("foo", ApplicationClusterEndpoint.Scope.global, List.of("a", "b"), OptionalInt.of(3), ApplicationClusterEndpoint.RoutingMethod.shared)); + final var serialized = ContainerEndpointSerializer.endpointListToSlime(endpoints); + final var deserialized = ContainerEndpointSerializer.endpointListFromSlime(serialized); + + assertEquals(endpoints, deserialized); } } |