diff options
5 files changed, 131 insertions, 127 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ZooKeeperClient.java b/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ZooKeeperClient.java index 754f73547d6..c7b64c05405 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ZooKeeperClient.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ZooKeeperClient.java @@ -12,11 +12,11 @@ import com.yahoo.config.model.application.provider.PreGeneratedFileRegistry; import com.yahoo.config.provision.AllocatedHosts; import com.yahoo.config.provision.serialization.AllocatedHostsSerializer; import com.yahoo.io.reader.NamedReader; -import java.util.logging.Level; import com.yahoo.path.Path; +import com.yahoo.text.Utf8; import com.yahoo.vespa.config.ConfigDefinitionKey; -import com.yahoo.vespa.config.server.zookeeper.ConfigCurator; import com.yahoo.vespa.config.server.zookeeper.ZKApplicationPackage; +import com.yahoo.vespa.curator.Curator; import com.yahoo.yolean.Exceptions; import java.io.ByteArrayOutputStream; @@ -27,6 +27,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.logging.Level; import static com.yahoo.config.application.api.ApplicationPackage.*; import static com.yahoo.vespa.config.server.zookeeper.ConfigCurator.DEFCONFIGS_ZK_SUBPATH; @@ -41,14 +42,14 @@ import static com.yahoo.vespa.config.server.zookeeper.ConfigCurator.USER_DEFCONF */ public class ZooKeeperClient { - private final ConfigCurator configCurator; + private final Curator curator; private final DeployLogger logger; private final Path sessionPath; // session id private static final ApplicationFile.PathFilter xmlFilter = path -> path.getName().endsWith(".xml"); - public ZooKeeperClient(ConfigCurator configCurator, DeployLogger logger, Path sessionPath) { - this.configCurator = configCurator; + public ZooKeeperClient(Curator curator, DeployLogger logger, Path sessionPath) { + this.curator = curator; this.logger = logger; this.sessionPath = sessionPath; } @@ -58,16 +59,14 @@ public class ZooKeeperClient { * This is the first operation on ZK during deploy. */ void initialize() { - if ( ! configCurator.exists(sessionPath.getAbsolute())) - configCurator.createNode(sessionPath.getAbsolute()); + curator.create(sessionPath); for (String subPath : Arrays.asList(DEFCONFIGS_ZK_SUBPATH, USER_DEFCONFIGS_ZK_SUBPATH, USERAPP_ZK_SUBPATH, ZKApplicationPackage.fileRegistryNode)) { // TODO: The replaceFirst below is hackish. - configCurator.createNode(getZooKeeperAppPath().getAbsolute(), - subPath.replaceFirst("/", "")); + curator.create(getZooKeeperAppPath().append(subPath.replaceFirst("/", ""))); } } @@ -95,12 +94,12 @@ public class ZooKeeperClient { if (sds.isEmpty()) return; Path zkPath = getZooKeeperAppPath(USERAPP_ZK_SUBPATH).append(SCHEMAS_DIR); - configCurator.createNode(zkPath.getAbsolute()); + curator.create(zkPath); // Ensures that ranking expressions and other files are also written writeDir(app.getFile(ApplicationPackage.SEARCH_DEFINITIONS_DIR), zkPath, false); writeDir(app.getFile(ApplicationPackage.SCHEMAS_DIR), zkPath, false); for (NamedReader sd : sds) { - configCurator.putData(zkPath.getAbsolute(), sd.getName(), com.yahoo.io.IOUtils.readAll(sd.getReader())); + curator.set(zkPath.append(sd.getName()), Utf8.toBytes(com.yahoo.io.IOUtils.readAll(sd.getReader()))); sd.getReader().close(); } } @@ -154,7 +153,7 @@ public class ZooKeeperClient { String name = file.getPath().getName(); if (name.startsWith(".")) continue; //.svn , .git ... if (file.isDirectory()) { - configCurator.createNode(path.append(name).getAbsolute()); + curator.create(path.append(name)); if (recurse) { writeDir(file, path.append(name), filenameFilter, recurse); } @@ -192,7 +191,7 @@ public class ZooKeeperClient { try (InputStream inputStream = file.createInputStream()) { inputStream.transferTo(baos); baos.flush(); - configCurator.putData(zkPath.append(file.getPath().getName()).getAbsolute(), baos.toByteArray()); + curator.set(zkPath.append(file.getPath().getName()), baos.toByteArray()); } } @@ -201,7 +200,7 @@ public class ZooKeeperClient { ApplicationFile dir = applicationPackage.getFile(Path.fromString(userInclude)); final List<ApplicationFile> files = dir.listFiles(); if (files == null || files.isEmpty()) { - configCurator.createNode(getZooKeeperAppPath(USERAPP_ZK_SUBPATH + "/" + userInclude).getAbsolute()); + curator.create(getZooKeeperAppPath(USERAPP_ZK_SUBPATH + "/" + userInclude)); } writeDir(dir, getZooKeeperAppPath(USERAPP_ZK_SUBPATH + "/" + userInclude), @@ -218,21 +217,20 @@ public class ZooKeeperClient { for (Map.Entry<ConfigDefinitionKey, UnparsedConfigDefinition> entry : configDefs.entrySet()) { ConfigDefinitionKey key = entry.getKey(); String contents = entry.getValue().getUnparsedContent(); - writeConfigDefinition(key.getName(), key.getNamespace(), getZooKeeperAppPath(USER_DEFCONFIGS_ZK_SUBPATH).getAbsolute(), contents); - writeConfigDefinition(key.getName(), key.getNamespace(), getZooKeeperAppPath(DEFCONFIGS_ZK_SUBPATH).getAbsolute(), contents); + writeConfigDefinition(key.getName(), key.getNamespace(), getZooKeeperAppPath(USER_DEFCONFIGS_ZK_SUBPATH), contents); + writeConfigDefinition(key.getName(), key.getNamespace(), getZooKeeperAppPath(DEFCONFIGS_ZK_SUBPATH), contents); } logger.log(Level.FINE, configDefs.size() + " user config definitions"); } - private void writeConfigDefinition(String name, String namespace, String path, String data) { - configCurator.putData(path, namespace + "." + name, data); + private void writeConfigDefinition(String name, String namespace, Path path, String data) { + curator.set(path.append(namespace + "." + name), Utf8.toBytes(data)); } private void write(Version vespaVersion, FileRegistry fileRegistry) { String exportedRegistry = PreGeneratedFileRegistry.exportRegistry(fileRegistry); - configCurator.putData(getZooKeeperAppPath(ZKApplicationPackage.fileRegistryNode).getAbsolute(), - vespaVersion.toFullString(), - exportedRegistry); + curator.set(getZooKeeperAppPath(ZKApplicationPackage.fileRegistryNode).append(vespaVersion.toFullString()), + Utf8.toBytes(exportedRegistry)); } /** @@ -242,13 +240,13 @@ public class ZooKeeperClient { * @param metaData The application metadata. */ private void writeMetadata(ApplicationMetaData metaData) { - configCurator.putData(getZooKeeperAppPath(META_ZK_PATH).getAbsolute(), metaData.asJsonBytes()); + curator.set(getZooKeeperAppPath(META_ZK_PATH), metaData.asJsonBytes()); } void cleanupZooKeeper() { try { List.of(DEFCONFIGS_ZK_SUBPATH, USER_DEFCONFIGS_ZK_SUBPATH, USERAPP_ZK_SUBPATH) - .forEach(path -> configCurator.deleteRecurse(getZooKeeperAppPath(path).getAbsolute())); + .forEach(path -> curator.delete(getZooKeeperAppPath(path))); } catch (Exception e) { logger.log(Level.WARNING, "Could not clean up in zookeeper: " + Exceptions.toMessageString(e)); //Might be called in an exception handler before re-throw, so do not throw here. @@ -277,8 +275,8 @@ public class ZooKeeperClient { } public void write(AllocatedHosts hosts) throws IOException { - configCurator.putData(sessionPath.append(ZKApplicationPackage.allocatedHostsNode).getAbsolute(), - AllocatedHostsSerializer.toJson(hosts)); + curator.set(sessionPath.append(ZKApplicationPackage.allocatedHostsNode), + AllocatedHostsSerializer.toJson(hosts)); } public void write(Map<Version, FileRegistry> fileRegistryMap) { 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 e677d248630..4c248482f30 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 @@ -591,7 +591,7 @@ public class SessionRepository { private void ensureSessionPathDoesNotExist(long sessionId) { Path sessionPath = getSessionPath(sessionId); - if (configCurator.exists(sessionPath.getAbsolute())) { + if (curator.exists(sessionPath)) { throw new IllegalArgumentException("Path " + sessionPath.getAbsolute() + " already exists in ZooKeeper"); } } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java index 26e9e45f1e7..f2b26f809d6 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java @@ -91,8 +91,8 @@ public class SessionZooKeeperClient { public Session.Status readStatus() { try { - String data = configCurator.getData(sessionStatusPath.getAbsolute()); - return Session.Status.parse(data); + Optional<byte[]> data = curator.getData(sessionStatusPath); + return data.map(d -> Session.Status.parse(Utf8.toString(d))).orElse(Session.Status.NONE); } catch (Exception e) { log.log(Level.INFO, "Failed to read session status at " + sessionStatusPath.getAbsolute() + ", will assume session has been removed: " + e.getMessage()); @@ -144,86 +144,88 @@ public class SessionZooKeeperClient { return new UserConfigDefinitionRepo(configCurator, sessionPath.append(ConfigCurator.USER_DEFCONFIGS_ZK_SUBPATH).getAbsolute()); } - private String applicationIdPath() { - return sessionPath.append(APPLICATION_ID_PATH).getAbsolute(); + private Path applicationIdPath() { + return sessionPath.append(APPLICATION_ID_PATH); } public void writeApplicationId(ApplicationId id) { if ( ! id.tenant().equals(tenantName)) throw new IllegalArgumentException("Cannot write application id '" + id + "' for tenant '" + tenantName + "'"); - configCurator.putData(applicationIdPath(), id.serializedForm()); + curator.set(applicationIdPath(), Utf8.toBytes(id.serializedForm())); } public Optional<ApplicationId> readApplicationId() { - if ( ! configCurator.exists(applicationIdPath())) return Optional.empty(); - return Optional.of(ApplicationId.fromSerializedForm(configCurator.getData(applicationIdPath()))); + Optional<byte[]> data = curator.getData(applicationIdPath()); + if (data.isEmpty()) return Optional.empty(); + return Optional.of(ApplicationId.fromSerializedForm(Utf8.toString(data.get()))); } void writeApplicationPackageReference(Optional<FileReference> applicationPackageReference) { applicationPackageReference.ifPresent( - reference -> configCurator.putData(applicationPackageReferencePath(), reference.value())); + reference -> curator.set(applicationPackageReferencePath(), Utf8.toBytes(reference.value()))); } FileReference readApplicationPackageReference() { - if ( ! configCurator.exists(applicationPackageReferencePath())) return null; // This should not happen. - return new FileReference(configCurator.getData(applicationPackageReferencePath())); + Optional<byte[]> data = curator.getData(applicationPackageReferencePath()); + if (data.isEmpty()) return null; // This should not happen. + + return new FileReference(Utf8.toString(data.get())); } - private String applicationPackageReferencePath() { - return sessionPath.append(APPLICATION_PACKAGE_REFERENCE_PATH).getAbsolute(); + private Path applicationPackageReferencePath() { + return sessionPath.append(APPLICATION_PACKAGE_REFERENCE_PATH); } - private String versionPath() { - return sessionPath.append(VERSION_PATH).getAbsolute(); + private Path versionPath() { + return sessionPath.append(VERSION_PATH); } - private String dockerImageRepositoryPath() { - return sessionPath.append(DOCKER_IMAGE_REPOSITORY_PATH).getAbsolute(); + private Path dockerImageRepositoryPath() { + return sessionPath.append(DOCKER_IMAGE_REPOSITORY_PATH); } - private String athenzDomainPath() { - return sessionPath.append(ATHENZ_DOMAIN).getAbsolute(); + private Path athenzDomainPath() { + return sessionPath.append(ATHENZ_DOMAIN); } - private String quotaPath() { - return sessionPath.append(QUOTA_PATH).getAbsolute(); + private Path quotaPath() { + return sessionPath.append(QUOTA_PATH); } - private String tenantSecretStorePath() { - return sessionPath.append(TENANT_SECRET_STORES_PATH).getAbsolute(); + private Path tenantSecretStorePath() { + return sessionPath.append(TENANT_SECRET_STORES_PATH); } - private String operatorCertificatesPath() { - return sessionPath.append(OPERATOR_CERTIFICATES_PATH).getAbsolute(); + private Path operatorCertificatesPath() { + return sessionPath.append(OPERATOR_CERTIFICATES_PATH); } public void writeVespaVersion(Version version) { - configCurator.putData(versionPath(), version.toString()); + curator.set(versionPath(), Utf8.toBytes(version.toString())); } public Version readVespaVersion() { - if ( ! configCurator.exists(versionPath())) return Vtag.currentVersion; // TODO: This should not be possible any more - verify and remove - return new Version(configCurator.getData(versionPath())); + Optional<byte[]> data = curator.getData(versionPath()); + // TODO: Empty version should not be possible any more - verify and remove + return data.map(d -> new Version(Utf8.toString(d))).orElse(Vtag.currentVersion); } public Optional<DockerImage> readDockerImageRepository() { - if ( ! configCurator.exists(dockerImageRepositoryPath())) return Optional.empty(); - String dockerImageRepository = configCurator.getData(dockerImageRepositoryPath()); - return dockerImageRepository.isEmpty() ? Optional.empty() : Optional.of(DockerImage.fromString(dockerImageRepository)); + Optional<byte[]> dockerImageRepository = curator.getData(dockerImageRepositoryPath()); + return dockerImageRepository.map(d -> DockerImage.fromString(Utf8.toString(d))); } public void writeDockerImageRepository(Optional<DockerImage> dockerImageRepository) { - dockerImageRepository.ifPresent(repo -> configCurator.putData(dockerImageRepositoryPath(), repo.untagged())); + dockerImageRepository.ifPresent(repo -> curator.set(dockerImageRepositoryPath(), Utf8.toBytes(repo.untagged()))); } public Instant readCreateTime() { - String path = getCreateTimePath(); - if ( ! configCurator.exists(path)) return Instant.EPOCH; - return Instant.ofEpochSecond(Long.parseLong(configCurator.getData(path))); + Optional<byte[]> data = curator.getData(getCreateTimePath()); + return data.map(d -> Instant.ofEpochSecond(Long.parseLong(Utf8.toString(d)))).orElse(Instant.EPOCH); } - private String getCreateTimePath() { - return sessionPath.append(CREATE_TIME_PATH).getAbsolute(); + private Path getCreateTimePath() { + return sessionPath.append(CREATE_TIME_PATH); } AllocatedHosts getAllocatedHosts() { @@ -232,14 +234,13 @@ public class SessionZooKeeperClient { } public ZooKeeperDeployer createDeployer(DeployLogger logger) { - ZooKeeperClient zkClient = new ZooKeeperClient(configCurator, logger, sessionPath); + ZooKeeperClient zkClient = new ZooKeeperClient(curator, logger, sessionPath); return new ZooKeeperDeployer(zkClient); } public Transaction createWriteStatusTransaction(Session.Status status) { - String path = sessionStatusPath.getAbsolute(); CuratorTransaction transaction = new CuratorTransaction(curator); - if (configCurator.exists(path)) { + if (curator.exists(sessionStatusPath)) { transaction.add(CuratorOperations.setData(sessionStatusPath.getAbsolute(), Utf8.toBytes(status.name()))); } else { transaction.add(CuratorOperations.create(sessionStatusPath.getAbsolute(), Utf8.toBytes(status.name()))); @@ -248,59 +249,56 @@ public class SessionZooKeeperClient { } public void writeAthenzDomain(Optional<AthenzDomain> athenzDomain) { - athenzDomain.ifPresent(domain -> configCurator.putData(athenzDomainPath(), domain.value())); + athenzDomain.ifPresent(domain -> curator.set(athenzDomainPath(), Utf8.toBytes(domain.value()))); } public Optional<AthenzDomain> readAthenzDomain() { - if ( ! configCurator.exists(athenzDomainPath())) return Optional.empty(); - return Optional.ofNullable(configCurator.getData(athenzDomainPath())) - .filter(domain -> ! domain.isBlank()) - .map(AthenzDomain::from); + return curator.getData(athenzDomainPath()) + .map(Utf8::toString) + .filter(domain -> !domain.isBlank()) + .map(AthenzDomain::from); } public void writeQuota(Optional<Quota> maybeQuota) { maybeQuota.ifPresent(quota -> { var bytes = uncheck(() -> SlimeUtils.toJsonBytes(quota.toSlime())); - configCurator.putData(quotaPath(), bytes); + curator.set(quotaPath(), bytes); }); } public Optional<Quota> readQuota() { - if ( ! configCurator.exists(quotaPath())) return Optional.empty(); - return Optional.ofNullable(configCurator.getData(quotaPath())) - .map(SlimeUtils::jsonToSlime) - .map(slime -> Quota.fromSlime(slime.get())); + return curator.getData(quotaPath()) + .map(SlimeUtils::jsonToSlime) + .map(slime -> Quota.fromSlime(slime.get())); } public void writeTenantSecretStores(List<TenantSecretStore> tenantSecretStores) { if (!tenantSecretStores.isEmpty()) { var bytes = uncheck(() -> SlimeUtils.toJsonBytes(TenantSecretStoreSerializer.toSlime(tenantSecretStores))); - configCurator.putData(tenantSecretStorePath(), bytes); + curator.set(tenantSecretStorePath(), bytes); } } public List<TenantSecretStore> readTenantSecretStores() { - if ( ! configCurator.exists(tenantSecretStorePath())) return List.of(); - return Optional.ofNullable(configCurator.getData(tenantSecretStorePath())) - .map(SlimeUtils::jsonToSlime) - .map(slime -> TenantSecretStoreSerializer.listFromSlime(slime.get())) - .orElse(List.of()); + return curator.getData(tenantSecretStorePath()) + .map(SlimeUtils::jsonToSlime) + .map(slime -> TenantSecretStoreSerializer.listFromSlime(slime.get())) + .orElse(List.of()); } public void writeOperatorCertificates(List<X509Certificate> certificates) { if( ! certificates.isEmpty()) { var bytes = uncheck(() -> SlimeUtils.toJsonBytes(OperatorCertificateSerializer.toSlime(certificates))); - configCurator.putData(operatorCertificatesPath(), bytes); + curator.set(operatorCertificatesPath(), bytes); } } public List<X509Certificate> readOperatorCertificates() { - if ( ! configCurator.exists(operatorCertificatesPath())) return List.of(); - return Optional.ofNullable(configCurator.getData(operatorCertificatesPath())) - .map(SlimeUtils::jsonToSlime) - .map(slime -> OperatorCertificateSerializer.fromSlime(slime.get())) - .orElse(List.of()); + return curator.getData(operatorCertificatesPath()) + .map(SlimeUtils::jsonToSlime) + .map(slime -> OperatorCertificateSerializer.fromSlime(slime.get())) + .orElse(List.of()); } /** @@ -313,7 +311,7 @@ public class SessionZooKeeperClient { transaction.add(CuratorOperations.create(sessionPath.getAbsolute())); transaction.add(CuratorOperations.create(sessionPath.append(UPLOAD_BARRIER).getAbsolute())); transaction.add(createWriteStatusTransaction(Session.Status.NEW).operations()); - transaction.add(CuratorOperations.create(getCreateTimePath(), Utf8.toBytes(String.valueOf(createTime.getEpochSecond())))); + transaction.add(CuratorOperations.create(getCreateTimePath().getAbsolute(), Utf8.toBytes(String.valueOf(createTime.getEpochSecond())))); transaction.commit(); } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperClientTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperClientTest.java index e20363af4e9..4acf0ea6603 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperClientTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperClientTest.java @@ -14,8 +14,9 @@ import com.yahoo.config.provision.AllocatedHosts; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.HostSpec; import com.yahoo.path.Path; -import com.yahoo.vespa.config.server.zookeeper.ConfigCurator; +import com.yahoo.text.Utf8; import com.yahoo.vespa.config.server.zookeeper.ZKApplicationPackage; +import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.curator.mock.MockCurator; import org.junit.Before; import org.junit.Rule; @@ -31,6 +32,10 @@ import java.util.Map; import java.util.Optional; import static com.yahoo.config.provision.serialization.AllocatedHostsSerializer.fromJson; +import static com.yahoo.vespa.config.server.zookeeper.ConfigCurator.DEFCONFIGS_ZK_SUBPATH; +import static com.yahoo.vespa.config.server.zookeeper.ConfigCurator.META_ZK_PATH; +import static com.yahoo.vespa.config.server.zookeeper.ConfigCurator.USERAPP_ZK_SUBPATH; +import static com.yahoo.vespa.config.server.zookeeper.ConfigCurator.USER_DEFCONFIGS_ZK_SUBPATH; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; @@ -46,13 +51,13 @@ public class ZooKeeperClientTest { @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); - private ConfigCurator zk; - private final String appPath = "/1"; + private Curator zk; + private final Path appPath = Path.fromString("/1"); @Before public void setupZK() throws IOException { - zk = ConfigCurator.create(new MockCurator()); - ZooKeeperClient zkc = new ZooKeeperClient(zk, new BaseDeployLogger(), Path.fromString(appPath)); + zk = new MockCurator(); + ZooKeeperClient zkc = new ZooKeeperClient(zk, new BaseDeployLogger(), appPath); ApplicationPackage app = FilesApplicationPackage.fromFileWithDeployData(new File("src/test/apps/zkfeed"), new DeployData("foo", "/bar/baz", @@ -81,30 +86,30 @@ public class ZooKeeperClientTest { @Test public void testInitZooKeeper() { - ConfigCurator zk = ConfigCurator.create(new MockCurator()); + Curator zk = new MockCurator(); BaseDeployLogger logger = new BaseDeployLogger(); long generation = 1L; ZooKeeperClient zooKeeperClient = new ZooKeeperClient(zk, logger, Path.fromString("/1")); zooKeeperClient.initialize(); - String appPath = "/"; + Path appPath = Path.fromString("/"); assertThat(zk.getChildren(appPath).size(), is(1)); - assertTrue(zk.exists("/" + generation)); - String currentAppPath = appPath + generation; - assertTrue(zk.exists(currentAppPath, ConfigCurator.DEFCONFIGS_ZK_SUBPATH.replaceFirst("/", ""))); + Path currentAppPath = appPath.append(String.valueOf(generation)); + assertTrue(zk.exists(currentAppPath)); + assertTrue(zk.exists(currentAppPath.append(DEFCONFIGS_ZK_SUBPATH.replaceFirst("/", "")))); assertThat(zk.getChildren(currentAppPath).size(), is(4)); } @Test public void testFeedDefFilesToZooKeeper() { - String defsPath = appPath + ConfigCurator.DEFCONFIGS_ZK_SUBPATH; - assertTrue(zk.exists(appPath, ConfigCurator.DEFCONFIGS_ZK_SUBPATH.replaceFirst("/", ""))); + Path defsPath = appPath.append(DEFCONFIGS_ZK_SUBPATH); + assertTrue(zk.exists(appPath.append(DEFCONFIGS_ZK_SUBPATH.replaceFirst("/", "")))); List<String> children = zk.getChildren(defsPath); assertEquals(defsPath + " children", 1, children.size()); Collections.sort(children); assertThat(children.get(0), is("a.b.test2")); - assertTrue(zk.exists(appPath, ConfigCurator.USER_DEFCONFIGS_ZK_SUBPATH.replaceFirst("/", ""))); - String userDefsPath = appPath + ConfigCurator.USER_DEFCONFIGS_ZK_SUBPATH; + assertTrue(zk.exists(appPath.append(USER_DEFCONFIGS_ZK_SUBPATH.replaceFirst("/", "")))); + Path userDefsPath = appPath.append(USER_DEFCONFIGS_ZK_SUBPATH); children = zk.getChildren(userDefsPath); assertThat(children.size(), is(1)); Collections.sort(children); @@ -113,8 +118,9 @@ public class ZooKeeperClientTest { @Test public void testFeedAppMetaDataToZooKeeper() { - assertTrue(zk.exists(appPath, ConfigCurator.META_ZK_PATH)); - ApplicationMetaData metaData = ApplicationMetaData.fromJsonString(zk.getData(appPath, ConfigCurator.META_ZK_PATH)); + assertTrue(zk.exists(appPath.append(META_ZK_PATH))); + ApplicationMetaData metaData = ApplicationMetaData.fromJsonString( + Utf8.toString(zk.getData(appPath.append(META_ZK_PATH)).get())); assertTrue(metaData.getChecksum().length() > 0); assertTrue(metaData.isInternalRedeploy()); assertThat(metaData.getDeployedByUser(), is("foo")); @@ -126,34 +132,34 @@ public class ZooKeeperClientTest { @Test public void testVersionedFileRegistry() { - String fileRegPath = appPath + "/" + ZKApplicationPackage.fileRegistryNode; + Path fileRegPath = appPath.append(ZKApplicationPackage.fileRegistryNode); assertTrue(zk.exists(fileRegPath)); - assertTrue(zk.exists(fileRegPath + "/1.2.3")); - assertTrue(zk.exists(fileRegPath + "/3.2.1")); + assertTrue(zk.exists(fileRegPath.append("/1.2.3"))); + assertTrue(zk.exists(fileRegPath.append("/3.2.1"))); // assertNull("Data at " + fileRegPath, zk.getData(fileRegPath)); Not null any more .. hm } @Test public void include_dirs_are_written_to_ZK() { - assertTrue(zk.exists(appPath + ConfigCurator.USERAPP_ZK_SUBPATH + "/" + "dir1", "default.xml")); - assertTrue(zk.exists(appPath + ConfigCurator.USERAPP_ZK_SUBPATH + "/nested/" + "dir2", "chain2.xml")); - assertTrue(zk.exists(appPath + ConfigCurator.USERAPP_ZK_SUBPATH + "/nested/" + "dir2", "chain3.xml")); + assertTrue(zk.exists(appPath.append(USERAPP_ZK_SUBPATH).append("dir1").append("default.xml"))); + assertTrue(zk.exists(appPath.append(USERAPP_ZK_SUBPATH).append("nested").append("dir2").append("chain2.xml"))); + assertTrue(zk.exists(appPath.append(USERAPP_ZK_SUBPATH).append("nested").append("dir2").append("chain3.xml"))); } @Test public void search_chain_dir_written_to_ZK() { - assertTrue(zk.exists(appPath().append("search").append("chains").append("dir1").append("default.xml").getAbsolute())); - assertTrue(zk.exists(appPath().append("search").append("chains").append("dir2").append("chain2.xml").getAbsolute())); - assertTrue(zk.exists(appPath().append("search").append("chains").append("dir2").append("chain3.xml").getAbsolute())); + assertTrue(zk.exists(appPath().append("search").append("chains").append("dir1").append("default.xml"))); + assertTrue(zk.exists(appPath().append("search").append("chains").append("dir2").append("chain2.xml"))); + assertTrue(zk.exists(appPath().append("search").append("chains").append("dir2").append("chain3.xml"))); } private Path appPath() { - return Path.fromString(appPath).append(ConfigCurator.USERAPP_ZK_SUBPATH); + return appPath.append(USERAPP_ZK_SUBPATH); } @Test public void testWritingHostNamesToZooKeeper() throws IOException { - ConfigCurator zk = ConfigCurator.create(new MockCurator()); + Curator zk = new MockCurator(); BaseDeployLogger logger = new BaseDeployLogger(); Path app = Path.fromString("/1"); ZooKeeperClient zooKeeperClient = new ZooKeeperClient(zk, logger, app); @@ -163,9 +169,9 @@ public class ZooKeeperClientTest { ImmutableSet<HostSpec> hosts = ImmutableSet.of(host1, host2); zooKeeperClient.write(AllocatedHosts.withHosts(hosts)); Path hostsPath = app.append(ZKApplicationPackage.allocatedHostsNode); - assertTrue(zk.exists(hostsPath.getAbsolute())); + assertTrue(zk.exists(hostsPath)); - AllocatedHosts deserialized = fromJson(zk.getBytes(hostsPath.getAbsolute())); + AllocatedHosts deserialized = fromJson(zk.getData(hostsPath).get()); assertEquals(hosts, deserialized.getHosts()); } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperDeployerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperDeployerTest.java index 641fbe5bf41..ebbb10c2d2a 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperDeployerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/ZooKeeperDeployerTest.java @@ -1,15 +1,16 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.deploy; +import com.yahoo.component.Version; import com.yahoo.config.application.api.ApplicationPackage; import com.yahoo.config.application.api.DeployLogger; -import com.yahoo.config.model.application.provider.*; +import com.yahoo.config.model.application.provider.FilesApplicationPackage; +import com.yahoo.config.model.application.provider.MockFileRegistry; import com.yahoo.config.provision.AllocatedHosts; -import com.yahoo.component.Version; import com.yahoo.io.IOUtils; import com.yahoo.path.Path; +import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.curator.mock.MockCurator; -import com.yahoo.vespa.config.server.zookeeper.ConfigCurator; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -33,7 +34,7 @@ public class ZooKeeperDeployerTest { @Test public void require_that_deployer_is_initialized() throws IOException { - ConfigCurator zkfacade = ConfigCurator.create(new MockCurator()); + Curator curator = new MockCurator(); File serverdbDir = folder.newFolder("serverdb"); File defsDir = new File(serverdbDir, "serverdefs"); try { @@ -42,21 +43,22 @@ public class ZooKeeperDeployerTest { e.printStackTrace(); fail(); } - deploy(FilesApplicationPackage.fromFile(new File("src/test/apps/content")), zkfacade, Path.fromString("/1")); - deploy(FilesApplicationPackage.fromFile(new File("src/test/apps/content")), zkfacade, Path.fromString("/2")); + deploy(FilesApplicationPackage.fromFile(new File("src/test/apps/content")), curator, Path.fromString("/1")); + deploy(FilesApplicationPackage.fromFile(new File("src/test/apps/content")), curator, Path.fromString("/2")); } - public void deploy(ApplicationPackage applicationPackage, ConfigCurator configCurator, Path appPath) throws IOException { + public void deploy(ApplicationPackage applicationPackage, Curator curator, Path appPath) throws IOException { MockDeployLogger logger = new MockDeployLogger(); - ZooKeeperClient client = new ZooKeeperClient(configCurator, logger, appPath); + ZooKeeperClient client = new ZooKeeperClient(curator, logger, appPath); ZooKeeperDeployer deployer = new ZooKeeperDeployer(client); deployer.deploy(applicationPackage, Collections.singletonMap(new Version(1, 0, 0), new MockFileRegistry()), AllocatedHosts.withHosts(Collections.emptySet())); - assertTrue(configCurator.exists(appPath.getAbsolute())); + assertTrue(curator.exists(appPath)); } private static class MockDeployLogger implements DeployLogger { @Override public void log(Level level, String message) { } } + } |