diff options
author | Jon Bratseth <bratseth@oath.com> | 2022-01-07 10:54:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-07 10:54:48 +0100 |
commit | ea8199921bb9b46e86ef7f2c715c2e00b0708ade (patch) | |
tree | b4178b23227abe63dd14ae75310a8e7f07ed608d /configserver | |
parent | 7f0beb86fe8a571575aa220ce3dfd0061de9ece2 (diff) | |
parent | 2d80f10452966e85dafa3480a4b1c7c4e97ca55d (diff) |
Merge pull request #20680 from vespa-engine/arnej/add-legacy-overrides
Arnej/add legacy overrides
Diffstat (limited to 'configserver')
7 files changed, 202 insertions, 5 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ActivatedModelsBuilder.java b/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ActivatedModelsBuilder.java index 687c897c88b..54ceb394ee6 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ActivatedModelsBuilder.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ActivatedModelsBuilder.java @@ -102,7 +102,7 @@ public class ActivatedModelsBuilder extends ModelsBuilder<Application> { ) { log.log(Level.FINE, () -> String.format("Loading model version %s for session %s application %s", modelFactory.version(), applicationGeneration, applicationId)); - ModelContext.Properties modelContextProperties = createModelContextProperties(applicationId); + ModelContext.Properties modelContextProperties = createModelContextProperties(applicationId, applicationPackage); Provisioned provisioned = new Provisioned(); ModelContext modelContext = new ModelContextImpl( applicationPackage, @@ -146,14 +146,14 @@ public class ActivatedModelsBuilder extends ModelsBuilder<Application> { return Optional.of(value); } - private ModelContext.Properties createModelContextProperties(ApplicationId applicationId) { + private ModelContext.Properties createModelContextProperties(ApplicationId applicationId, ApplicationPackage applicationPackage) { return new ModelContextImpl.Properties(applicationId, configserverConfig, zone(), ImmutableSet.copyOf(new ContainerEndpointsCache(TenantRepository.getTenantPath(tenant), curator).read(applicationId)), false, // We may be bootstrapping, but we only know and care during prepare false, // Always false, assume no one uses it when activating - flagSource, + LegacyFlags.from(applicationPackage, flagSource), new EndpointCertificateMetadataStore(curator, TenantRepository.getTenantPath(tenant)) .readEndpointCertificateMetadata(applicationId) .flatMap(new EndpointCertificateRetriever(secretStore)::readEndpointCertificateSecrets), diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/LegacyFlags.java b/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/LegacyFlags.java new file mode 100644 index 00000000000..80467c80196 --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/LegacyFlags.java @@ -0,0 +1,46 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.modelfactory; + +import com.yahoo.config.application.api.ApplicationPackage; +import com.yahoo.vespa.flags.Flags; +import com.yahoo.vespa.flags.FlagSource; +import com.yahoo.vespa.flags.InMemoryFlagSource; +import com.yahoo.vespa.flags.OrderedFlagSource; + +import java.util.Map; + + +/** + * @author arnej + */ +public class LegacyFlags { + + public static final String GEO_POSITIONS = "v7-geo-positions"; + public static final String FOO_BAR = "foo-bar"; // for testing + + private static FlagSource buildFrom(Map<String, String> legacyOverrides) { + var flags = new InMemoryFlagSource(); + for (var entry : legacyOverrides.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + boolean legacyWanted = Boolean.valueOf(value); + switch (key) { + case GEO_POSITIONS: + flags = flags.withBooleanFlag(Flags.USE_V8_GEO_POSITIONS.id(), ! legacyWanted); + break; + case FOO_BAR: + // ignored + break; + default: + throw new IllegalArgumentException("Unknown legacy override: "+key); + } + } + return flags; + } + + public static FlagSource from(ApplicationPackage pkg, FlagSource input) { + var overrides = buildFrom(pkg.legacyOverrides()); + FlagSource result = new OrderedFlagSource(overrides, input); + return result; + } +} 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 aaacc9f69e0..e4a0fa81f94 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 @@ -35,6 +35,7 @@ import com.yahoo.vespa.config.server.deploy.ZooKeeperDeployer; import com.yahoo.vespa.config.server.filedistribution.FileDistributionFactory; import com.yahoo.vespa.config.server.host.HostValidator; import com.yahoo.vespa.config.server.http.InvalidApplicationException; +import com.yahoo.vespa.config.server.modelfactory.LegacyFlags; import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry; import com.yahoo.vespa.config.server.modelfactory.PreparedModelsBuilder; import com.yahoo.vespa.config.server.provision.HostProvisionerProvider; @@ -195,7 +196,7 @@ public class SessionPreparer { Set.copyOf(containerEndpoints), params.isBootstrap(), currentActiveApplicationSet.isEmpty(), - flagSource, + LegacyFlags.from(applicationPackage, flagSource), endpointCertificateSecrets, athenzDomain, params.quota(), diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackage.java b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackage.java index 806b67758c2..6a483c38aee 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackage.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackage.java @@ -10,6 +10,7 @@ import com.yahoo.config.application.api.ComponentInfo; import com.yahoo.config.application.api.FileRegistry; import com.yahoo.config.application.api.UnparsedConfigDefinition; import com.yahoo.config.codegen.DefParser; +import com.yahoo.config.model.application.AbstractApplicationPackage; import com.yahoo.config.provision.AllocatedHosts; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.serialization.AllocatedHostsSerializer; @@ -44,7 +45,7 @@ import static com.yahoo.vespa.config.server.zookeeper.ZKApplication.USERAPP_ZK_S * * @author Tony Vaagenes */ -public class ZKApplicationPackage implements ApplicationPackage { +public class ZKApplicationPackage extends AbstractApplicationPackage { private final ZKApplication zkApplication; diff --git a/configserver/src/test/apps/legacy-flag/schemas/music.sd b/configserver/src/test/apps/legacy-flag/schemas/music.sd new file mode 100644 index 00000000000..f4b11d1e8e4 --- /dev/null +++ b/configserver/src/test/apps/legacy-flag/schemas/music.sd @@ -0,0 +1,50 @@ +# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +# A basic search definition - called music, should be saved to music.sd +search music { + + # It contains one document type only - called music as well + document music { + + field title type string { + indexing: summary | index # How this field should be indexed + # index-to: title, default # Create two indexes + weight: 75 # Ranking importancy of this field, used by the built in nativeRank feature + } + + field artist type string { + indexing: summary | attribute | index + # index-to: artist, default + + weight: 25 + } + + field year type int { + indexing: summary | attribute + } + + # Increase query + field popularity type int { + indexing: summary | attribute + } + + field url type uri { + indexing: summary | index + } + + } + + rank-profile default inherits default { + first-phase { + expression: nativeRank(title,artist) + attribute(popularity) + } + + } + + rank-profile textmatch inherits default { + first-phase { + expression: nativeRank(title,artist) + } + + } + +} diff --git a/configserver/src/test/apps/legacy-flag/services.xml b/configserver/src/test/apps/legacy-flag/services.xml new file mode 100644 index 00000000000..4c9ac84b4f2 --- /dev/null +++ b/configserver/src/test/apps/legacy-flag/services.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!-- Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<services version="1.0"> + + <legacy> + <v7-geo-positions>false</v7-geo-positions> + <foo-bar>true</foo-bar> + </legacy> + + <admin version="2.0"> + <adminserver hostalias="node1"/> + <logserver hostalias="node1" /> + </admin> + + <content version="1.0"> + <redundancy>1</redundancy> + <documents> + <document type="music" mode="index"/> + </documents> + <nodes> + <node hostalias="node1" distribution-key="0"/> + </nodes> + </content> + + <container version="1.0"> + <nodes> + <node hostalias="node1" /> + </nodes> + </container> + +</services> diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/application/LegacyFlagsTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/application/LegacyFlagsTest.java new file mode 100644 index 00000000000..1bebe9089f1 --- /dev/null +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/application/LegacyFlagsTest.java @@ -0,0 +1,68 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.application; + +import com.yahoo.vespa.config.server.modelfactory.LegacyFlags; +import com.yahoo.cloud.config.ModelConfig; +import com.yahoo.component.Version; +import com.yahoo.config.model.application.provider.FilesApplicationPackage; +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.ApplicationName; +import com.yahoo.config.provision.InstanceName; +import com.yahoo.config.provision.TenantName; +import com.yahoo.vespa.config.server.ModelStub; +import com.yahoo.vespa.config.server.ServerCache; +import com.yahoo.vespa.config.server.monitoring.MetricUpdater; +import com.yahoo.vespa.config.server.monitoring.Metrics; +import com.yahoo.vespa.flags.Flags; +import com.yahoo.vespa.flags.FlagSource; +import com.yahoo.vespa.flags.InMemoryFlagSource; +import com.yahoo.vespa.model.VespaModel; +import org.junit.Before; +import org.junit.Test; + +import com.yahoo.config.ConfigInstance; +import com.yahoo.vespa.config.ConfigKey; +import com.yahoo.vespa.config.ConfigDefinitionKey; +import com.yahoo.vespa.config.buildergen.ConfigDefinition; +import com.yahoo.document.config.DocumentmanagerConfig; + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.util.Optional; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * @author arnej + */ +public class LegacyFlagsTest { + + @Test + public void testThatLegacyOverridesWork() throws Exception { + File testApp = new File("src/test/apps/legacy-flag"); + var appPkg = FilesApplicationPackage.fromFile(testApp); + var flag = Flags.USE_V8_GEO_POSITIONS.bindTo(LegacyFlags.from(appPkg, new InMemoryFlagSource())); + assertTrue(flag.value()); + /* rest here tests that having a "legacy" XML tag doesn't break other things, but without actually using it: */ + VespaModel model = new VespaModel(appPkg); + ApplicationId applicationId = new ApplicationId.Builder().tenant("foo").applicationName("foo").build(); + ServerCache cache = new ServerCache(); + Application app = new Application(model, cache, 1L, new Version(1, 2, 3), + new MetricUpdater(Metrics.createTestMetrics(), Metrics.createDimensions(applicationId)), applicationId); + assertNotNull(app.getModel()); + /* + // Note: no feature flags active with this code path + ConfigDefinitionKey cdk = new ConfigDefinitionKey(DocumentmanagerConfig.CONFIG_DEF_NAME, DocumentmanagerConfig.CONFIG_DEF_NAMESPACE); + ConfigDefinition cdd = new ConfigDefinition(cdk.getName(), DocumentmanagerConfig.CONFIG_DEF_SCHEMA); + var cfgBuilder = app.getModel().getConfigInstance(new ConfigKey<>(cdk.getName(), "client", cdk.getNamespace()), cdd); + assertTrue(cfgBuilder instanceof DocumentmanagerConfig.Builder); + var cfg = ((DocumentmanagerConfig.Builder)cfgBuilder).build(); + // no effect from legacy override seen here: + System.out.println("CFG: "+cfg); + */ + } + +} |