From f327490426087377be00d86b6b2ba013976835a9 Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Fri, 11 Oct 2019 13:03:30 +0200 Subject: Stop writing to old rotations cache --- .../config/server/deploy/ModelContextImpl.java | 7 --- .../vespa/config/server/session/PrepareParams.java | 18 ++------ .../config/server/session/SessionPreparer.java | 48 ++----------------- .../vespa/config/server/ModelContextImplTest.java | 15 ++---- .../server/model/LbServicesProducerTest.java | 27 ++--------- .../config/server/session/SessionPreparerTest.java | 54 ++++++++-------------- 6 files changed, 32 insertions(+), 137 deletions(-) (limited to 'configserver') diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ModelContextImpl.java b/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ModelContextImpl.java index 9cba549838e..694ab8f037e 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ModelContextImpl.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ModelContextImpl.java @@ -14,7 +14,6 @@ import com.yahoo.config.model.api.ModelContext; import com.yahoo.config.model.api.TlsSecrets; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.HostName; -import com.yahoo.config.provision.Rotation; import com.yahoo.config.provision.Zone; import com.yahoo.vespa.flags.FetchVector; import com.yahoo.vespa.flags.FlagSource; @@ -127,7 +126,6 @@ public class ModelContextImpl implements ModelContext { private final String athenzDnsSuffix; private final boolean hostedVespa; private final Zone zone; - private final Set rotations; private final Set endpoints; private final boolean isBootstrap; private final boolean isFirstTimeDeployment; @@ -143,7 +141,6 @@ public class ModelContextImpl implements ModelContext { String athenzDnsSuffix, boolean hostedVespa, Zone zone, - Set rotations, Set endpoints, boolean isBootstrap, boolean isFirstTimeDeployment, @@ -157,7 +154,6 @@ public class ModelContextImpl implements ModelContext { this.athenzDnsSuffix = athenzDnsSuffix; this.hostedVespa = hostedVespa; this.zone = zone; - this.rotations = rotations; this.endpoints = endpoints; this.isBootstrap = isBootstrap; this.isFirstTimeDeployment = isFirstTimeDeployment; @@ -196,9 +192,6 @@ public class ModelContextImpl implements ModelContext { @Override public Zone zone() { return zone; } - @Override - public Set rotations() { return rotations; } - @Override public Set endpoints() { return endpoints; } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/PrepareParams.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/PrepareParams.java index 5b75371a13e..ab3e0e863ce 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/PrepareParams.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/PrepareParams.java @@ -4,7 +4,6 @@ package com.yahoo.vespa.config.server.session; import com.yahoo.component.Version; import com.yahoo.config.model.api.ContainerEndpoint; import com.yahoo.config.provision.ApplicationId; -import com.yahoo.config.provision.Rotation; import com.yahoo.config.provision.TenantName; import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.slime.Slime; @@ -17,7 +16,6 @@ import java.time.Clock; import java.time.Duration; import java.util.List; import java.util.Optional; -import java.util.Set; /** * Parameters for prepare. Immutable. @@ -42,14 +40,12 @@ public final class PrepareParams { private final boolean verbose; private final boolean isBootstrap; private final Optional vespaVersion; - private final Set rotations; private final List containerEndpoints; private final Optional tlsSecretsKeyName; private PrepareParams(ApplicationId applicationId, TimeoutBudget timeoutBudget, boolean ignoreValidationErrors, boolean dryRun, boolean verbose, boolean isBootstrap, Optional vespaVersion, - Set rotations, List containerEndpoints, - Optional tlsSecretsKeyName) { + List containerEndpoints, Optional tlsSecretsKeyName) { this.timeoutBudget = timeoutBudget; this.applicationId = applicationId; this.ignoreValidationErrors = ignoreValidationErrors; @@ -57,11 +53,7 @@ public final class PrepareParams { this.verbose = verbose; this.isBootstrap = isBootstrap; this.vespaVersion = vespaVersion; - this.rotations = rotations; this.containerEndpoints = containerEndpoints; - if ((rotations != null && !rotations.isEmpty()) && !containerEndpoints.isEmpty()) { - throw new IllegalArgumentException("Cannot set both rotations and containerEndpoints"); - } this.tlsSecretsKeyName = tlsSecretsKeyName; } @@ -137,8 +129,8 @@ public final class PrepareParams { } public PrepareParams build() { - return new PrepareParams(applicationId, timeoutBudget, ignoreValidationErrors, dryRun, - verbose, isBootstrap, vespaVersion, Set.of(), containerEndpoints, tlsSecretsKeyName); + return new PrepareParams(applicationId, timeoutBudget, ignoreValidationErrors, dryRun, + verbose, isBootstrap, vespaVersion, containerEndpoints, tlsSecretsKeyName); } } @@ -182,10 +174,6 @@ public final class PrepareParams { /** Returns the Vespa version the nodes running the prepared system should have, or empty to use the system version */ public Optional vespaVersion() { return vespaVersion; } - /** Returns the global rotations that should be made available for this deployment */ - // TODO: Remove this once all applications have to switched to containerEndpoints - public Set rotations() { return rotations; } - /** Returns the container endpoints that should be made available for this deployment. One per cluster */ public List containerEndpoints() { return containerEndpoints; diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionPreparer.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionPreparer.java index 3ec74a4c3eb..171eab35507 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionPreparer.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionPreparer.java @@ -9,16 +9,14 @@ import com.yahoo.component.Version; import com.yahoo.component.Vtag; import com.yahoo.config.application.api.ApplicationPackage; import com.yahoo.config.application.api.DeployLogger; -import com.yahoo.config.application.api.DeploymentInstanceSpec; -import com.yahoo.config.application.api.DeploymentSpec; import com.yahoo.config.application.api.FileRegistry; import com.yahoo.config.model.api.ConfigDefinitionRepo; +import com.yahoo.config.model.api.ContainerEndpoint; import com.yahoo.config.model.api.ModelContext; import com.yahoo.config.model.api.TlsSecrets; import com.yahoo.config.provision.AllocatedHosts; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.HostName; -import com.yahoo.config.provision.Rotation; import com.yahoo.config.provision.Zone; import com.yahoo.container.jdisc.secretstore.SecretStore; import com.yahoo.lang.SettableOptional; @@ -34,9 +32,7 @@ import com.yahoo.vespa.config.server.http.InvalidApplicationException; import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry; import com.yahoo.vespa.config.server.modelfactory.PreparedModelsBuilder; import com.yahoo.vespa.config.server.provision.HostProvisionerProvider; -import com.yahoo.config.model.api.ContainerEndpoint; import com.yahoo.vespa.config.server.tenant.ContainerEndpointsCache; -import com.yahoo.vespa.config.server.tenant.Rotations; import com.yahoo.vespa.config.server.tenant.TlsSecretsKeys; import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.flags.FlagSource; @@ -47,7 +43,6 @@ import javax.xml.transform.TransformerException; import java.io.IOException; import java.net.URI; import java.time.Instant; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Optional; @@ -118,13 +113,8 @@ public class SessionPreparer { preparation.makeResult(allocatedHosts); if ( ! params.isDryRun()) { preparation.writeStateZK(); - preparation.writeRotZK(); preparation.writeTlsZK(); - var globalServiceId = context.getApplicationPackage().getDeployment() - .map(DeploymentSpec::fromXml) - .flatMap(spec -> spec.instance(context.getApplicationPackage().getApplicationId().instance())) - .flatMap(DeploymentInstanceSpec::globalServiceId); - preparation.writeContainerEndpointsZK(globalServiceId); + preparation.writeContainerEndpointsZK(); preparation.distribute(); } log.log(LogLevel.DEBUG, () -> "time used " + params.getTimeoutBudget().timesUsed() + @@ -149,9 +139,7 @@ public class SessionPreparer { /** The version of Vespa the application to be prepared specifies for its nodes */ final com.yahoo.component.Version vespaVersion; - final Rotations rotations; // TODO: Remove this once we have migrated fully to container endpoints final ContainerEndpointsCache containerEndpoints; - final Set rotationsSet; final Set endpointsSet; final ModelContext.Properties properties; private final TlsSecretsKeys tlsSecretsKeys; @@ -173,9 +161,7 @@ public class SessionPreparer { this.applicationId = params.getApplicationId(); this.vespaVersion = params.vespaVersion().orElse(Vtag.currentVersion); - this.rotations = new Rotations(curator, tenantPath); this.containerEndpoints = new ContainerEndpointsCache(tenantPath, curator); - this.rotationsSet = getRotations(params.rotations()); this.tlsSecretsKeys = new TlsSecretsKeys(curator, tenantPath, secretStore); this.tlsSecrets = tlsSecretsKeys.getTlsSecrets(params.tlsSecretsKeyName(), applicationId); this.endpointsSet = getEndpoints(params.containerEndpoints()); @@ -188,7 +174,6 @@ public class SessionPreparer { configserverConfig.athenzDnsSuffix(), configserverConfig.hostedVespa(), zone, - rotationsSet, endpointsSet, params.isBootstrap(), ! currentActiveApplicationSet.isPresent(), @@ -248,27 +233,14 @@ public class SessionPreparer { checkTimeout("write state to zookeeper"); } - void writeRotZK() { - rotations.writeRotationsToZooKeeper(applicationId, rotationsSet); - checkTimeout("write rotations to zookeeper"); - } - void writeTlsZK() { tlsSecretsKeys.writeTlsSecretsKeyToZooKeeper(applicationId, params.tlsSecretsKeyName().orElse(null)); checkTimeout("write tlsSecretsKey to zookeeper"); } - void writeContainerEndpointsZK(Optional globalServiceId) { + void writeContainerEndpointsZK() { if (!params.containerEndpoints().isEmpty()) { // Use endpoints from parameter when explicitly given containerEndpoints.write(applicationId, params.containerEndpoints()); - } else { // Fall back to writing rotations as container endpoints - if (!rotationsSet.isEmpty()) { - if (globalServiceId.isEmpty()) { - log.log(LogLevel.WARNING, "Want to write rotations " + rotationsSet + " as container endpoints, but " + applicationId + " has no global-service-id. This should not happen"); - return; - } - containerEndpoints.write(applicationId, toContainerEndpoints(globalServiceId.get(), rotationsSet)); - } } checkTimeout("write container endpoints to zookeeper"); } @@ -283,13 +255,6 @@ public class SessionPreparer { return prepareResult.getConfigChangeActions(); } - private Set getRotations(Set rotations) { - if (rotations == null || rotations.isEmpty()) { - rotations = this.rotations.readRotationsFromZooKeeper(applicationId); - } - return rotations; - } - private Set getEndpoints(List endpoints) { if (endpoints == null || endpoints.isEmpty()) { endpoints = this.containerEndpoints.read(applicationId); @@ -299,13 +264,6 @@ public class SessionPreparer { } - private static List toContainerEndpoints(String globalServceId, Set rotations) { - return List.of(new ContainerEndpoint(globalServceId, - rotations.stream() - .map(Rotation::getId) - .collect(Collectors.toUnmodifiableList()))); - } - private void writeStateToZooKeeper(SessionZooKeeperClient zooKeeperClient, ApplicationPackage applicationPackage, ApplicationId applicationId, diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/ModelContextImplTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/ModelContextImplTest.java index 3102163df0d..370e0bd3c0e 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/ModelContextImplTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/ModelContextImplTest.java @@ -8,7 +8,6 @@ import com.yahoo.config.model.application.provider.BaseDeployLogger; import com.yahoo.config.model.application.provider.MockFileRegistry; import com.yahoo.config.model.test.MockApplicationPackage; import com.yahoo.config.provision.ApplicationId; -import com.yahoo.config.provision.Rotation; import com.yahoo.config.provision.Zone; import com.yahoo.vespa.config.server.deploy.ModelContextImpl; import com.yahoo.vespa.flags.InMemoryFlagSource; @@ -30,16 +29,13 @@ import static org.junit.Assert.assertTrue; * @author Ulf Lilleengen */ public class ModelContextImplTest { + @Test public void testModelContextTest() { - final Rotation rotation = new Rotation("this.is.a.mock.rotation"); - final Set rotations = Collections.singleton(rotation); - - final ContainerEndpoint endpoint = new ContainerEndpoint("foo", List.of("a", "b")); - final Set endpoints = Collections.singleton(endpoint); - - final InMemoryFlagSource flagSource = new InMemoryFlagSource(); + ContainerEndpoint endpoint = new ContainerEndpoint("foo", List.of("a", "b")); + Set endpoints = Collections.singleton(endpoint); + InMemoryFlagSource flagSource = new InMemoryFlagSource(); ModelContext context = new ModelContextImpl( MockApplicationPackage.createEmpty(), @@ -58,7 +54,6 @@ public class ModelContextImplTest { null, false, Zone.defaultZone(), - rotations, endpoints, false, false, @@ -78,8 +73,8 @@ public class ModelContextImplTest { assertTrue(context.properties().multitenant()); assertNotNull(context.properties().zone()); assertFalse(context.properties().hostedVespa()); - assertThat(context.properties().rotations(), equalTo(rotations)); assertThat(context.properties().endpoints(), equalTo(endpoints)); assertThat(context.properties().isFirstTimeDeployment(), equalTo(false)); } + } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/model/LbServicesProducerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/model/LbServicesProducerTest.java index bc777659298..9a7cb72804f 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/model/LbServicesProducerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/model/LbServicesProducerTest.java @@ -13,7 +13,6 @@ import com.yahoo.config.model.test.MockApplicationPackage; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.Environment; import com.yahoo.config.provision.RegionName; -import com.yahoo.config.provision.Rotation; import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.Zone; import com.yahoo.vespa.config.ConfigPayload; @@ -42,17 +41,15 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; -import static org.junit.Assume.assumeTrue; /** * @author Ulf Lilleengen */ @RunWith(Parameterized.class) public class LbServicesProducerTest { + private static final String rotation1 = "rotation-1"; private static final String rotation2 = "rotation-2"; - private static final String rotationString = rotation1 + "," + rotation2; - private static final Set rotations = Collections.singleton(new Rotation(rotationString)); private static final Set endpoints = Set.of( new ContainerEndpoint("mydisc", List.of("rotation-1", "rotation-2")) ); @@ -70,7 +67,7 @@ public class LbServicesProducerTest { @Test public void testDeterministicGetConfig() throws IOException, SAXException { - Map> testModel = createTestModel(new DeployState.Builder().rotations(rotations)); + Map> testModel = createTestModel(new DeployState.Builder().endpoints(endpoints)); LbServicesConfig last = null; for (int i = 0; i < 100; i++) { testModel = randomizeApplications(testModel, i); @@ -125,25 +122,6 @@ public class LbServicesProducerTest { return new LbServicesConfig(builder); } - @Test - public void testConfigAliasesWithRotations() throws IOException, SAXException { - assumeTrue(useGlobalServiceId); - - Map> testModel = createTestModel(new DeployState.Builder() - .rotations(rotations) - .properties(new TestProperties().setHostedVespa(true))); - RegionName regionName = RegionName.from("us-east-1"); - - var services = getLbServicesConfig(new Zone(Environment.prod, regionName), testModel) - .tenants("foo") - .applications("foo:prod:" + regionName.value() + ":default") - .hosts("foo.foo.yahoo.com") - .services(QRSERVER.serviceName); - - assertThat(services.servicealiases(), contains("service1")); - assertThat("Missing rotations in list: " + services.endpointaliases(), services.endpointaliases(), containsInAnyOrder("foo1.bar1.com", "foo2.bar2.com", rotation1, rotation2)); - } - @Test public void testConfigAliasesWithEndpoints() throws IOException, SAXException { assumeFalse(useGlobalServiceId); @@ -259,4 +237,5 @@ public class LbServicesProducerTest { assertThat(expected.toString(), is(actual.toString())); assertThat(ConfigPayload.fromInstance(expected).toString(true), is(ConfigPayload.fromInstance(actual).toString(true))); } + } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java index fbc36d37769..a099db5ebe8 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java @@ -3,7 +3,7 @@ package com.yahoo.vespa.config.server.session; import com.yahoo.component.Version; import com.yahoo.config.application.api.DeployLogger; -import com.yahoo.config.model.api.ModelContext; +import com.yahoo.config.model.api.ContainerEndpoint; import com.yahoo.config.model.api.TlsSecrets; import com.yahoo.config.model.application.provider.BaseDeployLogger; import com.yahoo.config.model.application.provider.FilesApplicationPackage; @@ -17,7 +17,6 @@ import com.yahoo.config.provision.HostSpec; import com.yahoo.config.provision.InstanceName; import com.yahoo.config.provision.ProvisionLogger; import com.yahoo.config.provision.Provisioner; -import com.yahoo.config.provision.Rotation; import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.exception.LoadBalancerServiceException; import com.yahoo.io.IOUtils; @@ -37,9 +36,7 @@ import com.yahoo.vespa.config.server.http.InvalidApplicationException; import com.yahoo.vespa.config.server.model.TestModelFactory; import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry; import com.yahoo.vespa.config.server.provision.HostProvisionerProvider; -import com.yahoo.config.model.api.ContainerEndpoint; import com.yahoo.vespa.config.server.tenant.ContainerEndpointsCache; -import com.yahoo.vespa.config.server.tenant.Rotations; import com.yahoo.vespa.config.server.tenant.TlsSecretsKeys; import com.yahoo.vespa.config.server.zookeeper.ConfigCurator; import com.yahoo.vespa.curator.mock.MockCurator; @@ -60,7 +57,6 @@ import java.util.Optional; import java.util.Set; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.Matchers.contains; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; @@ -185,38 +181,10 @@ public class SessionPreparerTest { assertThat(zkc.readApplicationId(), is(origId)); } - private List readContainerEndpoints(ApplicationId application) { - return new ContainerEndpointsCache(tenantPath, curator).read(application); - } - - private Set readRotationsFromZK(ApplicationId applicationId) { - return new Rotations(curator, tenantPath).readRotationsFromZooKeeper(applicationId); - } - - @Test - public void require_that_rotations_are_read_from_zookeeper_and_used() throws IOException { - final TestModelFactory modelFactory = new TestModelFactory(version123); - preparer = createPreparer(new ModelFactoryRegistry(Collections.singletonList(modelFactory)), - HostProvisionerProvider.empty()); - - final String rotations = "foo.msbe.global.vespa.yahooapis.com"; - final ApplicationId applicationId = applicationId("test"); - new Rotations(curator, tenantPath).writeRotationsToZooKeeper(applicationId, Collections.singleton(new Rotation(rotations))); - final PrepareParams params = new PrepareParams.Builder().applicationId(applicationId).build(); - final File app = new File("src/test/resources/deploy/app"); - prepare(app, params); - - // check that the rotation from zookeeper were used - final ModelContext modelContext = modelFactory.getModelContext(); - final Set rotationSet = modelContext.properties().rotations(); - assertThat(rotationSet, contains(new Rotation(rotations))); - - // Check that the persisted value is still the same - assertThat(readRotationsFromZK(applicationId), contains(new Rotation(rotations))); - } - @Test - public void require_that_container_endpoints_are_written() throws Exception { + public void require_that_container_endpoints_are_written_and_used() throws Exception { + var modelFactory = new TestModelFactory(version123); + preparer = createPreparer(new ModelFactoryRegistry(List.of(modelFactory)), HostProvisionerProvider.empty()); var endpoints = "[\n" + " {\n" + " \"clusterId\": \"foo\",\n" + @@ -246,6 +214,16 @@ public class SessionPreparerTest { List.of("bar.app1.tenant1.global.vespa.example.com", "rotation-043.vespa.global.routing"))); assertEquals(expected, readContainerEndpoints(applicationId)); + + + var modelContext = modelFactory.getModelContext(); + var containerEndpointsFromModel = modelContext.properties().endpoints(); + assertEquals(Set.copyOf(expected), containerEndpointsFromModel); + + // Writing empty container endpoints keeps old value + params = new PrepareParams.Builder().applicationId(applicationId).build(); + prepare(new File("src/test/resources/deploy/hosted-app"), params); + assertEquals(expected, readContainerEndpoints(applicationId)); } @Test @@ -288,6 +266,10 @@ public class SessionPreparerTest { prepare(new File("src/test/resources/deploy/hosted-app"), params); } + private List readContainerEndpoints(ApplicationId application) { + return new ContainerEndpointsCache(tenantPath, curator).read(application); + } + private void prepare(File app) throws IOException { prepare(app, new PrepareParams.Builder().build()); } -- cgit v1.2.3