summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2021-07-08 22:22:07 +0200
committerHarald Musum <musum@verizonmedia.com>2021-07-08 22:22:07 +0200
commit9e4889d949f2b7b8163e22ed8b08a6804f728fd2 (patch)
tree7a3436b258c89628b4e91f8956f294c64ed34c90
parent3c06371c9393e9c2ebae773c350737db7c540f89 (diff)
Use Curator instead of ConfigCurator, part 2
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/UserConfigDefinitionRepo.java19
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java3
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackage.java7
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationFileTest.java10
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackageTest.java27
5 files changed, 40 insertions, 26 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/UserConfigDefinitionRepo.java b/configserver/src/main/java/com/yahoo/vespa/config/server/UserConfigDefinitionRepo.java
index 15a9b8f74d0..8097cd24514 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/UserConfigDefinitionRepo.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/UserConfigDefinitionRepo.java
@@ -1,16 +1,19 @@
-// Copyright 2018 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;
import com.google.common.base.Splitter;
import com.yahoo.config.model.api.ConfigDefinitionRepo;
-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.buildergen.ConfigDefinition;
-import com.yahoo.vespa.config.server.zookeeper.ConfigCurator;
import com.yahoo.vespa.config.util.ConfigUtils;
+import com.yahoo.vespa.curator.Curator;
import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.Optional;
+import java.util.logging.Level;
import java.util.logging.Logger;
/**
@@ -24,10 +27,12 @@ public class UserConfigDefinitionRepo implements ConfigDefinitionRepo {
// For testing only
public UserConfigDefinitionRepo() {}
- public UserConfigDefinitionRepo(ConfigCurator configCurator, String appPath) {
- if (configCurator.exists(appPath)) {
- for (String nodeName : configCurator.getChildren(appPath)) {
- String payload = configCurator.getData(appPath, nodeName);
+ public UserConfigDefinitionRepo(Curator curator, Path appPath) {
+ if (curator.exists(appPath)) {
+ for (String nodeName : curator.getChildren(appPath)) {
+ String payload = curator.getData(appPath.append(nodeName))
+ .map(Utf8::toString)
+ .orElseThrow(() -> new IllegalArgumentException("No config definition data at " + nodeName));
ConfigDefinitionKey dKey = ConfigUtils.createConfigDefinitionKeyFromZKString(nodeName);
defs.put(dKey, new ConfigDefinition(dKey.getName(), Splitter.on("\n").splitToList(payload).toArray(new String[0])));
}
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 f2b26f809d6..349c7afafed 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
@@ -36,6 +36,7 @@ import java.util.List;
import java.util.Optional;
import java.util.logging.Level;
+import static com.yahoo.vespa.config.server.zookeeper.ConfigCurator.USER_DEFCONFIGS_ZK_SUBPATH;
import static com.yahoo.vespa.curator.Curator.CompletionWaiter;
import static com.yahoo.yolean.Exceptions.uncheck;
@@ -141,7 +142,7 @@ public class SessionZooKeeperClient {
}
public ConfigDefinitionRepo getUserConfigDefinitions() {
- return new UserConfigDefinitionRepo(configCurator, sessionPath.append(ConfigCurator.USER_DEFCONFIGS_ZK_SUBPATH).getAbsolute());
+ return new UserConfigDefinitionRepo(curator, sessionPath.append(USER_DEFCONFIGS_ZK_SUBPATH));
}
private Path applicationIdPath() {
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 bcb19a8f25a..f35af268c29 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
@@ -21,6 +21,7 @@ import com.yahoo.vespa.config.ConfigDefinition;
import com.yahoo.vespa.config.ConfigDefinitionBuilder;
import com.yahoo.vespa.config.ConfigDefinitionKey;
import com.yahoo.vespa.config.util.ConfigUtils;
+import com.yahoo.vespa.curator.Curator;
import java.io.File;
import java.io.Reader;
@@ -50,7 +51,7 @@ public class ZKApplicationPackage implements ApplicationPackage {
private final ApplicationMetaData metaData;
public ZKApplicationPackage(ConfigCurator zk, Path sessionPath) {
- verifyAppPath(zk, sessionPath);
+ verifyAppPath(zk.curator(), sessionPath);
zkApplication = new ZKApplication(zk, sessionPath);
metaData = readMetaDataFromLiveApp(zkApplication);
importFileRegistries();
@@ -104,8 +105,8 @@ public class ZKApplicationPackage implements ApplicationPackage {
return metaData;
}
- private static void verifyAppPath(ConfigCurator zk, Path appPath) {
- if (!zk.exists(appPath.getAbsolute()))
+ private static void verifyAppPath(Curator zk, Path appPath) {
+ if (!zk.exists(appPath))
throw new RuntimeException("App with path " + appPath + " does not exist");
}
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationFileTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationFileTest.java
index a34c17dc909..c452e1cf0f3 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationFileTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationFileTest.java
@@ -1,9 +1,10 @@
-// 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.zookeeper;
import com.yahoo.config.application.api.ApplicationFile;
import com.yahoo.config.application.api.ApplicationFileTest;
import com.yahoo.path.Path;
+import com.yahoo.text.Utf8;
import com.yahoo.vespa.curator.mock.MockCurator;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
@@ -11,6 +12,7 @@ import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.io.IOException;
+import static com.yahoo.vespa.config.server.zookeeper.ConfigCurator.USERAPP_ZK_SUBPATH;
import static org.junit.Assert.assertTrue;
/**
@@ -23,9 +25,9 @@ public class ZKApplicationFileTest extends ApplicationFileTest {
private void feed(ConfigCurator zk, File dirToFeed) {
assertTrue(dirToFeed.isDirectory());
- String appPath = "/0";
- ZKApplicationPackageTest.feedZooKeeper(zk, dirToFeed, appPath + ConfigCurator.USERAPP_ZK_SUBPATH, null, true);
- zk.putData(appPath, ZKApplicationPackage.fileRegistryNode, "dummyfiles");
+ Path appPath = Path.fromString("/0");
+ ZKApplicationPackageTest.feedZooKeeper(zk.curator(), dirToFeed, appPath.append(USERAPP_ZK_SUBPATH), null, true);
+ zk.curator().set(appPath.append(ZKApplicationPackage.fileRegistryNode), Utf8.toBytes("dummyfiles"));
}
@Override
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackageTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackageTest.java
index 458cdb82066..3f84646ad82 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackageTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackageTest.java
@@ -14,6 +14,7 @@ import com.yahoo.config.provisioning.FlavorsConfig;
import com.yahoo.io.IOUtils;
import com.yahoo.path.Path;
import com.yahoo.text.Utf8;
+import com.yahoo.vespa.curator.Curator;
import com.yahoo.vespa.curator.mock.MockCurator;
import org.junit.Before;
import org.junit.Rule;
@@ -31,6 +32,8 @@ import java.util.Set;
import java.util.regex.Pattern;
import static com.yahoo.config.provision.serialization.AllocatedHostsSerializer.toJson;
+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 org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -71,7 +74,7 @@ public class ZKApplicationPackageTest {
@Test
public void testBasicZKFeed() throws IOException {
- feed(configCurator, new File(APP));
+ feed(configCurator.curator(), new File(APP));
ZKApplicationPackage zkApp = new ZKApplicationPackage(configCurator, Path.fromString("/0"));
assertTrue(Pattern.compile(".*<slobroks>.*",Pattern.MULTILINE+Pattern.DOTALL).matcher(IOUtils.readAll(zkApp.getServices())).matches());
assertTrue(Pattern.compile(".*<alias>.*",Pattern.MULTILINE+Pattern.DOTALL).matcher(IOUtils.readAll(zkApp.getHosts())).matches());
@@ -103,13 +106,14 @@ public class ZKApplicationPackageTest {
assertEquals("mydisc", DeploymentSpec.fromXml(zkApp.getDeployment().get()).requireInstance("default").globalServiceId().get());
}
- private void feed(ConfigCurator zk, File dirToFeed) throws IOException {
+ private void feed(Curator zk, File dirToFeed) throws IOException {
assertTrue(dirToFeed.isDirectory());
- feedZooKeeper(zk, dirToFeed, "/0" + ConfigCurator.USERAPP_ZK_SUBPATH, null, true);
+ Path sessionPath = Path.fromString("/0");
+ feedZooKeeper(zk, dirToFeed, sessionPath.append(USERAPP_ZK_SUBPATH), null, true);
String metaData = "{\"deploy\":{\"user\":\"foo\",\"from\":\"bar\",\"timestamp\":1},\"application\":{\"id\":\"foo:foo:default\",\"checksum\":\"abc\",\"generation\":4,\"previousActiveGeneration\":3}}";
- zk.putData("/0", ConfigCurator.META_ZK_PATH, metaData);
- zk.putData("/0/" + ZKApplicationPackage.fileRegistryNode + "/3.0.0", "dummyfiles");
- zk.putData("/0/" + ZKApplicationPackage.allocatedHostsNode, toJson(ALLOCATED_HOSTS));
+ zk.set(sessionPath.append(META_ZK_PATH), Utf8.toBytes(metaData));
+ zk.set(sessionPath.append(ZKApplicationPackage.fileRegistryNode).append("/3.0.0"), Utf8.toBytes("dummyfiles"));
+ zk.set(sessionPath.append(ZKApplicationPackage.allocatedHostsNode), toJson(ALLOCATED_HOSTS));
}
private static class MockNodeFlavors extends NodeFlavors{
@@ -131,7 +135,7 @@ public class ZKApplicationPackageTest {
* @param filenameFilter A FilenameFilter which decides which files in dir are fed to zookeeper
* @param recurse recurse subdirectories
*/
- static void feedZooKeeper(ConfigCurator zk, File dir, String path, FilenameFilter filenameFilter, boolean recurse) {
+ static void feedZooKeeper(Curator zk, File dir, Path path, FilenameFilter filenameFilter, boolean recurse) {
try {
if (filenameFilter == null) {
filenameFilter = acceptsAllFileNameFilter;
@@ -141,12 +145,13 @@ public class ZKApplicationPackageTest {
}
for (File file : listFiles(dir, filenameFilter)) {
if (file.getName().startsWith(".")) continue; //.svn , .git ...
+ Path filePath = path.append(file.getName());
if (file.isFile()) {
- String contents = IOUtils.readFile(file);
- zk.putData(path, file.getName(), contents);
+ byte[] contents = IOUtils.readFileBytes(file);
+ zk.set(filePath, contents);
} else if (recurse && file.isDirectory()) {
- zk.createNode(path, file.getName());
- feedZooKeeper(zk, file, path + '/' + file.getName(), filenameFilter, recurse);
+ zk.create(filePath);
+ feedZooKeeper(zk, file, filePath, filenameFilter, recurse);
}
}
}