summaryrefslogtreecommitdiffstats
path: root/configserver
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2021-06-09 10:12:47 +0200
committerHarald Musum <musum@verizonmedia.com>2021-06-09 10:12:47 +0200
commitebdb66f78441a0e902deca0b73be87e48586dc02 (patch)
treefaa983466696558cdea23835d13e61fc9abbd970 /configserver
parente6481326693a4384004f06aa8a7448891ee8db1b (diff)
Hide moving of schemas from searchdefinitions/ to schemas/ behind a feature flag
Diffstat (limited to 'configserver')
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java9
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java37
2 files changed, 36 insertions, 10 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java
index 45957110e23..9a0fd8bf12b 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java
@@ -41,7 +41,9 @@ import com.yahoo.vespa.config.server.zookeeper.ConfigCurator;
import com.yahoo.vespa.config.server.zookeeper.SessionCounter;
import com.yahoo.vespa.curator.Curator;
import com.yahoo.vespa.defaults.Defaults;
+import com.yahoo.vespa.flags.BooleanFlag;
import com.yahoo.vespa.flags.FlagSource;
+import com.yahoo.vespa.flags.Flags;
import com.yahoo.yolean.Exceptions;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.ChildData;
@@ -121,6 +123,7 @@ public class SessionRepository {
private final Zone zone;
private final ModelFactoryRegistry modelFactoryRegistry;
private final ConfigDefinitionRepo configDefinitionRepo;
+ private final BooleanFlag rewriteSearchDefinitions;
public SessionRepository(TenantName tenantName,
TenantApplications applicationRepo,
@@ -161,6 +164,7 @@ public class SessionRepository {
this.zone = zone;
this.modelFactoryRegistry = modelFactoryRegistry;
this.configDefinitionRepo = configDefinitionRepo;
+ this.rewriteSearchDefinitions = Flags.MOVE_SEARCH_DEFINITIONS_TO_SCHEMAS_DIR.bindTo(flagSource);
loadSessions(); // Needs to be done before creating cache below
this.directoryCache = curator.createDirectoryCache(sessionsPath.getAbsolute(), false, false, zkCacheExecutor);
@@ -676,7 +680,8 @@ public class SessionRepository {
tempDestinationDir = Files.createTempDirectory(destinationDir.getParentFile().toPath(), "app-package");
log.log(Level.FINE, "Copying dir " + sourceDir.getAbsolutePath() + " to " + tempDestinationDir.toFile().getAbsolutePath());
IOUtils.copyDirectory(sourceDir, tempDestinationDir.toFile());
- copyToSchemasDir(tempDestinationDir);
+ if (rewriteSearchDefinitions.value())
+ moveSearchDefinitionsToSchemasDir(tempDestinationDir);
log.log(Level.FINE, "Moving " + tempDestinationDir + " to " + destinationDir.getAbsolutePath());
Files.move(tempDestinationDir, destinationDir.toPath(), StandardCopyOption.ATOMIC_MOVE);
@@ -689,7 +694,7 @@ public class SessionRepository {
// TODO: Remove in Vespa 8 (when we don't allow files in SEARCH_DEFINITIONS_DIR)
// Copies schemas from searchdefinitions/ to schemas/ if searchdefinitions/ exists
- private void copyToSchemasDir(java.nio.file.Path applicationDir) throws IOException {
+ private void moveSearchDefinitionsToSchemasDir(java.nio.file.Path applicationDir) throws IOException {
File schemasDir = applicationDir.resolve(ApplicationPackage.SCHEMAS_DIR.getRelative()).toFile();
File sdDir = applicationDir.resolve(ApplicationPackage.SEARCH_DEFINITIONS_DIR.getRelative()).toFile();
if (sdDir.exists() && sdDir.isDirectory()) {
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java
index 6fdc77d3964..31d29e7b78e 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java
@@ -31,6 +31,8 @@ import com.yahoo.vespa.config.server.zookeeper.ConfigCurator;
import com.yahoo.vespa.config.util.ConfigUtils;
import com.yahoo.vespa.curator.Curator;
import com.yahoo.vespa.curator.mock.MockCurator;
+import com.yahoo.vespa.flags.Flags;
+import com.yahoo.vespa.flags.InMemoryFlagSource;
import com.yahoo.vespa.model.VespaModel;
import com.yahoo.vespa.model.VespaModelFactory;
import org.junit.Rule;
@@ -72,6 +74,7 @@ public class SessionRepositoryTest {
private TenantRepository tenantRepository;
private ApplicationRepository applicationRepository;
private SessionRepository sessionRepository;
+ private final InMemoryFlagSource flagSource = new InMemoryFlagSource();
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@@ -92,6 +95,7 @@ public class SessionRepositoryTest {
tenantRepository = new TestTenantRepository.Builder()
.withConfigserverConfig(configserverConfig)
.withCurator(curator)
+ .withFlagSource(flagSource)
.withFileDistributionFactory(new MockFileDistributionFactory(configserverConfig))
.withModelFactoryRegistry(modelFactoryRegistry)
.build();
@@ -100,6 +104,7 @@ public class SessionRepositoryTest {
.withTenantRepository(tenantRepository)
.withProvisioner(new MockProvisioner())
.withOrchestrator(new OrchestratorMock())
+ .withFlagSource(flagSource)
.build();
sessionRepository = tenantRepository.getTenant(tenantName).getSessionRepository();
}
@@ -254,21 +259,37 @@ public class SessionRepositoryTest {
@Test
public void require_that_searchdefinitions_are_written_to_schemas_dir() throws Exception {
setup();
+
+ // App has schemas in searchdefinitions/, should NOT be moved to schemas/ on deploy
+ flagSource.withBooleanFlag(Flags.MOVE_SEARCH_DEFINITIONS_TO_SCHEMAS_DIR.id(), false);
+ long sessionId = deploy(applicationId, new File("src/test/apps/deprecated-features-app"));
+ LocalSession session = sessionRepository.getLocalSession(sessionId);
+
+ assertEquals(1, session.applicationPackage.get().getSchemas().size());
+
+ ApplicationFile schema = getSchema(session, "schemas");
+ assertFalse(schema.exists());
+ ApplicationFile sd = getSchema(session, "searchdefinitions");
+ assertTrue(sd.exists());
+
+
// App has schemas in searchdefinitions/, should be moved to schemas/ on deploy
- long firstSessionId = deploy(applicationId, new File("src/test/apps/deprecated-features-app"));
- assertNotNull(sessionRepository.getLocalSession(firstSessionId));
+ flagSource.withBooleanFlag(Flags.MOVE_SEARCH_DEFINITIONS_TO_SCHEMAS_DIR.id(), true);
+ sessionId = deploy(applicationId, new File("src/test/apps/deprecated-features-app"));
+ session = sessionRepository.getLocalSession(sessionId);
- LocalSession session = sessionRepository.getLocalSession(firstSessionId);
- Collection<NamedReader> schemas = session.applicationPackage.get().getSchemas();
- assertEquals(1, schemas.size());
+ assertEquals(1, session.applicationPackage.get().getSchemas().size());
- ApplicationFile schema = session.applicationPackage.get().getFile(Path.fromString("schemas").append("music.sd"));
+ schema = getSchema(session, "schemas");
assertTrue(schema.exists());
-
- ApplicationFile sd = session.applicationPackage.get().getFile(Path.fromString("searchdefinitions").append("music.sd"));
+ sd = getSchema(session, "searchdefinitions");
assertFalse(sd.exists());
}
+ ApplicationFile getSchema(Session session, String subDirectory) {
+ return session.applicationPackage.get().getFile(Path.fromString(subDirectory).append("music.sd"));
+ }
+
private void createSession(long sessionId, boolean wait) {
SessionZooKeeperClient zkc = new SessionZooKeeperClient(curator,
ConfigCurator.create(curator),