diff options
author | Jon Marius Venstad <jvenstad@yahoo-inc.com> | 2019-06-12 11:06:09 +0200 |
---|---|---|
committer | Jon Marius Venstad <jvenstad@yahoo-inc.com> | 2019-06-12 13:58:50 +0200 |
commit | 5947043e5f011f4634e1f824837a19a5f1d39c74 (patch) | |
tree | afe2962b153adabf79d7883b506bd9eea644f301 /controller-server/src | |
parent | 67e75197e2e5352b38c141044cef69c4a23fc49b (diff) |
Use cluster endpoints in test config, and test serialisation
Diffstat (limited to 'controller-server/src')
3 files changed, 66 insertions, 24 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunner.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunner.java index 891a696be9c..04ff0fd2e86 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunner.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunner.java @@ -11,8 +11,10 @@ import com.yahoo.config.application.api.Notifications.When; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.AthenzDomain; import com.yahoo.config.provision.AthenzService; +import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.SystemName; import com.yahoo.config.provision.zone.ZoneId; +import com.yahoo.data.access.simple.JsonRender; import com.yahoo.io.IOUtils; import com.yahoo.log.LogLevel; import com.yahoo.slime.Cursor; @@ -28,7 +30,6 @@ import com.yahoo.vespa.hosted.controller.api.integration.LogEntry; import com.yahoo.vespa.hosted.controller.api.integration.configserver.ConfigServerException; import com.yahoo.vespa.hosted.controller.api.integration.configserver.Node; import com.yahoo.vespa.hosted.controller.api.integration.configserver.PrepareResponse; -import com.yahoo.vespa.hosted.controller.api.integration.configserver.ServiceConvergence; import com.yahoo.vespa.hosted.controller.api.integration.deployment.ApplicationVersion; import com.yahoo.vespa.hosted.controller.api.integration.deployment.JobType; import com.yahoo.vespa.hosted.controller.api.integration.deployment.RunId; @@ -48,6 +49,7 @@ import java.net.URI; import java.nio.charset.StandardCharsets; import java.time.Duration; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; @@ -320,19 +322,23 @@ public class InternalStepRunner implements StepRunner { private boolean endpointsAvailable(ApplicationId id, ZoneId zoneId, DualLogger logger) { logger.log("Attempting to find deployment endpoints ..."); - Map<ZoneId, List<URI>> endpoints = deploymentEndpoints(id, Set.of(zoneId)); + var endpoints = deploymentEndpoints(id, Set.of(zoneId)); if ( ! endpoints.containsKey(zoneId)) { logger.log("Endpoints not yet ready."); return false; } + logEndpoints(endpoints, logger); + return true; + } + + private void logEndpoints(Map<ZoneId, Map<ClusterSpec.Id, URI>> endpoints, DualLogger logger) { List<String> messages = new ArrayList<>(); messages.add("Found endpoints:"); endpoints.forEach((zone, uris) -> { messages.add("- " + zone); - uris.forEach(uri -> messages.add(" |-- " + uri)); + uris.forEach((cluster, uri) -> messages.add(" |-- " + uri + " (" + cluster + ")")); }); logger.log(messages); - return true; } private boolean nodesConverged(ApplicationId id, JobType type, Version target, DualLogger logger) { @@ -387,18 +393,12 @@ public class InternalStepRunner implements StepRunner { Set<ZoneId> zones = testedZoneAndProductionZones(id); logger.log("Attempting to find endpoints ..."); - Map<ZoneId, List<URI>> endpoints = deploymentEndpoints(id.application(), zones); + var endpoints = deploymentEndpoints(id.application(), zones); if ( ! endpoints.containsKey(id.type().zone(controller.system())) && timedOut(deployment.get(), endpointTimeout)) { logger.log(WARNING, "Endpoints for the deployment to test vanished again, while it was still active!"); return Optional.of(error); } - List<String> messages = new ArrayList<>(); - messages.add("Found endpoints:"); - endpoints.forEach((zone, uris) -> { - messages.add("- " + zone); - uris.forEach(uri -> messages.add(" |-- " + uri)); - }); - logger.log(messages); + logEndpoints(endpoints, logger); Optional<URI> testerEndpoint = controller.jobController().testerEndpoint(id); if (testerEndpoint.isEmpty() && timedOut(deployment.get(), endpointTimeout)) { @@ -620,17 +620,12 @@ public class InternalStepRunner implements StepRunner { } /** Returns all endpoints for all current deployments of the given real application. */ - private Map<ZoneId, List<URI>> deploymentEndpoints(ApplicationId id, Iterable<ZoneId> zones) { - ImmutableMap.Builder<ZoneId, List<URI>> deployments = ImmutableMap.builder(); - for (ZoneId zone : zones) { - controller.applications().getDeploymentEndpoints(new DeploymentId(id, zone)) + private Map<ZoneId, Map<ClusterSpec.Id, URI>> deploymentEndpoints(ApplicationId id, Collection<ZoneId> zones) { + ImmutableMap.Builder<ZoneId, Map<ClusterSpec.Id, URI>> deployments = ImmutableMap.builder(); + for (ZoneId zone : zones) + controller.applications().clusterEndpoints(new DeploymentId(id, zone)) .filter(endpoints -> ! endpoints.isEmpty()) - .or(() -> Optional.of(controller.applications().routingPolicies().get(id, zone).stream() - .map(policy -> policy.endpointIn(controller.system()).url()) - .collect(Collectors.toUnmodifiableList())) - .filter(endpoints -> ! endpoints.isEmpty())) .ifPresent(endpoints -> deployments.put(zone, endpoints)); - } return deployments.build(); } @@ -713,8 +708,8 @@ public class InternalStepRunner implements StepRunner { } /** Returns the config for the tests to run for the given job. */ - private static byte[] testConfig(ApplicationId id, ZoneId testerZone, SystemName system, - Map<ZoneId, List<URI>> deployments, Map<ZoneId, List<String>> clusters) { + static byte[] testConfig(ApplicationId id, ZoneId testerZone, SystemName system, + Map<ZoneId, Map<ClusterSpec.Id, URI>> deployments, Map<ZoneId, List<String>> clusters) { Slime slime = new Slime(); Cursor root = slime.setObject(); @@ -725,10 +720,18 @@ public class InternalStepRunner implements StepRunner { Cursor endpointsObject = root.setObject("endpoints"); deployments.forEach((zone, endpoints) -> { Cursor endpointArray = endpointsObject.setArray(zone.value()); - for (URI endpoint : endpoints) + for (URI endpoint : endpoints.values()) endpointArray.addString(endpoint.toString()); }); + Cursor zoneEndpointsObject = root.setObject("zoneEndpoints"); + deployments.forEach((zone, endpoints) -> { + Cursor clusterEndpointsObject = zoneEndpointsObject.setObject(zone.value()); + endpoints.forEach((cluster, endpoint) -> { + clusterEndpointsObject.setString(cluster.value(), endpoint.toString()); + }); + }); + Cursor clustersObject = root.setObject("clusters"); clusters.forEach((zone, clusterList) -> { Cursor clusterArray = clustersObject.setArray(zone.value()); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunnerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunnerTest.java index 370fd03d9e7..e1b4ccc0e1f 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunnerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunnerTest.java @@ -3,12 +3,15 @@ package com.yahoo.vespa.hosted.controller.deployment; import com.yahoo.component.Version; import com.yahoo.config.application.api.DeploymentSpec; +import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.HostName; import com.yahoo.config.provision.SystemName; import com.yahoo.config.provision.zone.ZoneId; import com.yahoo.slime.ArrayTraverser; import com.yahoo.slime.Inspector; +import com.yahoo.slime.JsonFormat; +import com.yahoo.slime.ObjectTraverser; import com.yahoo.vespa.config.SlimeUtils; import com.yahoo.vespa.hosted.controller.api.application.v4.model.configserverbindings.ConfigChangeActions; import com.yahoo.vespa.hosted.controller.api.application.v4.model.configserverbindings.RefeedAction; @@ -25,6 +28,7 @@ import com.yahoo.vespa.hosted.controller.application.RoutingPolicy; import org.junit.Before; import org.junit.Test; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.UncheckedIOException; import java.net.URI; @@ -34,6 +38,7 @@ import java.nio.file.Paths; import java.time.Duration; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.concurrent.Executors; @@ -398,6 +403,20 @@ public class InternalStepRunnerTest { "1554970337.947844\t17491290-v6-1.ostk.bm2.prod.ne1.yahoo.com\t5480\tcontainer\tstderr\twarning\tjava.lang.NullPointerException\\n\\tat org.apache.felix.framework.BundleRevisionImpl.calculateContentPath(BundleRevisionImpl.java:438)\\n\\tat org.apache.felix.framework.BundleRevisionImpl.initializeContentPath(BundleRevisionImpl.java:371)"; @Test + public void testConfig() throws IOException { + ZoneId zone = ZoneId.from("test", "eu-north-1"); + byte[] json = InternalStepRunner.testConfig(appId, + zone, + SystemName.Public, + Map.of(zone, Map.of(ClusterSpec.Id.from("ai"), + URI.create("https://server/"))), + Map.of(zone, List.of("facts"))); + byte[] expected = InternalStepRunnerTest.class.getResourceAsStream("/testConfig.json").readAllBytes(); + assertEquals(new String(SlimeUtils.toJsonBytes(SlimeUtils.jsonToSlime(expected))), + new String(json)); + } + + @Test public void generates_correct_services_xml_test() { assertFile("test_runner_services.xml-cd", new String(InternalStepRunner.servicesXml(SystemName.cd, Optional.of("d-2-12-75")))); } diff --git a/controller-server/src/test/resources/testConfig.json b/controller-server/src/test/resources/testConfig.json new file mode 100644 index 00000000000..4145d863995 --- /dev/null +++ b/controller-server/src/test/resources/testConfig.json @@ -0,0 +1,20 @@ +{ + "application": "tenant:application:default", + "zone": "test.aws-us-east-1c", + "system": "publiccd", + "endpoints": { + "test.aws-us-east-1c": [ + "https://server/" + ] + }, + "zoneEndpoints": { + "test.aws-us-east-1c": { + "ai": "https://server/" + } + }, + "clusters": { + "test.aws-us-east-1c": [ + "facts" + ] + } +} |