summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2021-07-09 12:28:36 +0200
committerHarald Musum <musum@verizonmedia.com>2021-07-09 12:28:36 +0200
commitb0e2920c62e9679b07600328ae711d6657e70ff9 (patch)
tree9619cf72fd8732e4d19820d274a89373c4e4aa6a
parent9e4889d949f2b7b8163e22ed8b08a6804f728fd2 (diff)
Use Curator instead of ConfigCurator, part 3
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java6
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java10
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java6
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplication.java103
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationFile.java39
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackage.java47
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java1
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/session/MockSessionZKClient.java8
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java2
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionRepositoryTest.java2
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClientTest.java1
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationFileTest.java13
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackageTest.java12
13 files changed, 108 insertions, 142 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 4c248482f30..6c4e3c78232 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
@@ -114,7 +114,6 @@ public class SessionRepository {
private final SessionPreparer sessionPreparer;
private final Path sessionsPath;
private final TenantName tenantName;
- private final ConfigCurator configCurator;
private final SessionCounter sessionCounter;
private final SecretStore secretStore;
private final HostProvisionerProvider hostProvisionerProvider;
@@ -142,7 +141,6 @@ public class SessionRepository {
ModelFactoryRegistry modelFactoryRegistry,
ConfigDefinitionRepo configDefinitionRepo) {
this.tenantName = tenantName;
- this.configCurator = configCurator;
sessionCounter = new SessionCounter(configCurator, tenantName);
this.sessionsPath = TenantRepository.getSessionsPath(tenantName);
this.clock = clock;
@@ -780,7 +778,7 @@ public class SessionRepository {
private SessionZooKeeperClient createSessionZooKeeperClient(long sessionId) {
String serverId = configserverConfig.serverId();
- return new SessionZooKeeperClient(curator, configCurator, tenantName, sessionId, serverId);
+ return new SessionZooKeeperClient(curator, tenantName, sessionId, serverId);
}
private File getAndValidateExistingSessionAppDir(long sessionId) {
@@ -798,7 +796,7 @@ public class SessionRepository {
private void updateSessionStateWatcher(long sessionId, RemoteSession remoteSession) {
SessionStateWatcher sessionStateWatcher = sessionStateWatchers.get(sessionId);
if (sessionStateWatcher == null) {
- Curator.FileCache fileCache = curator.createFileCache(getSessionStatePath(sessionId).getAbsolute(), false);
+ com.yahoo.vespa.curator.Curator.FileCache fileCache = curator.createFileCache(getSessionStatePath(sessionId).getAbsolute(), false);
fileCache.addListener(this::nodeChanged);
sessionStateWatchers.put(sessionId, new SessionStateWatcher(fileCache, remoteSession, metricUpdater, zkWatcherExecutor, this));
} else {
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 349c7afafed..2d380c8eabd 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
@@ -63,19 +63,13 @@ public class SessionZooKeeperClient {
private static final String OPERATOR_CERTIFICATES_PATH = "operatorCertificates";
private final Curator curator;
- private final ConfigCurator configCurator;
private final TenantName tenantName;
private final Path sessionPath;
private final Path sessionStatusPath;
private final String serverId; // hostname
- public SessionZooKeeperClient(Curator curator,
- ConfigCurator configCurator,
- TenantName tenantName,
- long sessionId,
- String serverId) {
+ public SessionZooKeeperClient(Curator curator, TenantName tenantName, long sessionId, String serverId) {
this.curator = curator;
- this.configCurator = configCurator;
this.tenantName = tenantName;
this.sessionPath = getSessionPath(tenantName, sessionId);
this.serverId = serverId;
@@ -138,7 +132,7 @@ public class SessionZooKeeperClient {
}
public ApplicationPackage loadApplicationPackage() {
- return new ZKApplicationPackage(configCurator, sessionPath);
+ return new ZKApplicationPackage(curator, sessionPath);
}
public ConfigDefinitionRepo getUserConfigDefinitions() {
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java
index 2f7b397cbd9..40e6c99df9d 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java
@@ -256,7 +256,7 @@ public class TenantRepository {
return metaData.orElse(new TenantMetaData(tenant.getName(), tenant.getCreatedTime(), tenant.getCreatedTime()));
}
- private static Set<TenantName> readTenantsFromZooKeeper(Curator curator) {
+ private static Set<TenantName> readTenantsFromZooKeeper(com.yahoo.vespa.curator.Curator curator) {
return curator.getChildren(tenantsPath).stream().map(TenantName::from).collect(Collectors.toSet());
}
@@ -528,7 +528,7 @@ public class TenantRepository {
}
public void close() {
- directoryCache.ifPresent(Curator.DirectoryCache::close);
+ directoryCache.ifPresent(com.yahoo.vespa.curator.Curator.DirectoryCache::close);
try {
zkCacheExecutor.shutdown();
checkForRemovedApplicationsService.shutdown();
@@ -601,6 +601,6 @@ public class TenantRepository {
return barriersPath;
}
- public Curator getCurator() { return curator; }
+ public com.yahoo.vespa.curator.Curator getCurator() { return curator; }
}
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplication.java b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplication.java
index 084f26bd368..afdc7c8bad4 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplication.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplication.java
@@ -3,11 +3,12 @@ package com.yahoo.vespa.config.server.zookeeper;
import com.yahoo.io.reader.NamedReader;
import com.yahoo.path.Path;
+import com.yahoo.text.Utf8;
+import com.yahoo.vespa.curator.Curator;
import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
/**
@@ -18,11 +19,11 @@ import java.util.List;
*/
public class ZKApplication {
- private final ConfigCurator zk;
+ private final Curator curator;
private final Path appPath;
- ZKApplication(ConfigCurator zk, Path appPath) {
- this.zk = zk;
+ ZKApplication(Curator curator, Path appPath) {
+ this.curator = curator;
this.appPath = appPath;
}
@@ -37,7 +38,7 @@ public class ZKApplication {
* @return the files in the given path, or an empty list if the directory does not exist or is empty.
* The list gets owned by the caller and can be modified freely.
*/
- List<NamedReader> getAllDataFromDirectory(String path, String fileNameSuffix, boolean recursive) {
+ List<NamedReader> getAllDataFromDirectory(Path path, String fileNameSuffix, boolean recursive) {
return getAllDataFromDirectory(path, "", fileNameSuffix, recursive);
}
@@ -46,23 +47,22 @@ public class ZKApplication {
*
* @param namePrefix the prefix to prepend to the returned reader names
*/
- private List<NamedReader> getAllDataFromDirectory(String path, String namePrefix, String fileNameSuffix, boolean recursive) {
- String fullPath = getFullPath(path);
+ private List<NamedReader> getAllDataFromDirectory(Path path, String namePrefix, String fileNameSuffix, boolean recursive) {
List<NamedReader> result = new ArrayList<>();
List<String> children = getChildren(path);
try {
for (String child : children) {
if (fileNameSuffix == null || child.endsWith(fileNameSuffix)) {
- result.add(new NamedReader(namePrefix + child, reader(zk.getData(fullPath, child))));
+ result.add(new NamedReader(namePrefix + child, reader(getData(path.append(child)))));
}
if (recursive)
- result.addAll(getAllDataFromDirectory(path + "/" + child,
+ result.addAll(getAllDataFromDirectory(path.append(child),
namePrefix + child + "/", fileNameSuffix, recursive));
}
return result;
} catch (Exception e) {
- throw new RuntimeException("Could not retrieve all data from '" + fullPath + "' in zookeeper", e);
+ throw new RuntimeException("Could not retrieve all data from '" + path + "' in zookeeper", e);
}
}
@@ -70,45 +70,33 @@ public class ZKApplication {
* Retrieves a node relative to the node of the live application
*
* @param path a path relative to the currently active application
- * @param node a path relative to the path above
* @return a Reader that can be used to get the data
*/
- Reader getDataReader(String path, String node) {
- return reader(getData(path, node));
+ Reader getDataReader(Path path) {
+ return reader(getData(path));
}
- public String getData(String path, String node) {
- if ( ! exists(path, node)) throw new IllegalArgumentException("No node for " + getFullPath(path) + "/" + node + " exists");
-
- try {
- return zk.getData(getFullPath(path), node);
- } catch (Exception e) {
- throw new IllegalArgumentException("Could not retrieve node '" +
- getFullPath(path) + "/" + node + "' in zookeeper", e);
- }
+ NamedReader getNamedReader(String name, Path path) {
+ return new NamedReader(name, reader(getData(path)));
}
- public String getData(String path) {
- if ( ! exists(path)) throw new IllegalArgumentException("No node for " + getFullPath(path) + " exists");
+ public String getData(Path path) {
+ return Utf8.toString(getBytesInternal(getFullPath(path)));
+ }
- try {
- return zk.getData(getFullPath(path));
- } catch (RuntimeException e) {
- throw new IllegalArgumentException("Could not retrieve path '" + getFullPath(path) + "' in zookeeper", e);
- }
+ private byte[] getBytesInternal(Path path) {
+ return curator.getData(path)
+ .orElseThrow(() -> new IllegalArgumentException("Could not get data from '" +
+ path + "' in zookeeper"));
}
- public byte[] getBytes(String path) {
- try {
- return zk.getBytes(getFullPath(path));
- } catch (RuntimeException e) {
- throw new IllegalArgumentException("Could not retrieve path '" + getFullPath(path) + "' in zookeeper", e);
- }
+ public byte[] getBytes(Path path) {
+ return getBytesInternal(getFullPath(path));
}
- void putData(String path, String data) {
+ void putData(Path path, String data) {
try {
- zk.putData(getFullPath(path), data);
+ curator.set(getFullPath(path), Utf8.toBytes(data));
} catch (RuntimeException e) {
throw new IllegalArgumentException("Could not put data to node '" + getFullPath(path) + "' in zookeeper", e);
}
@@ -118,29 +106,18 @@ public class ZKApplication {
* Checks if the given node exists under path under this live app
*
* @param path a zookeeper path
- * @param node a zookeeper node
* @return true if the node exists in the path, false otherwise
*/
- public boolean exists(String path, String node) {
- return zk.exists(getFullPath(path), node);
+ public boolean exists(Path path) {
+ return curator.exists(getFullPath(path));
}
- /**
- * Checks if the given node exists under path under this live app
- *
- * @param path a zookeeper path
- * @return true if the node exists in the path, false otherwise
- */
- public boolean exists(String path) {
- return zk.exists(getFullPath(path));
- }
-
- private String getFullPath(String path) {
+ private Path getFullPath(Path path) {
Path fullPath = appPath;
if (path != null) {
fullPath = appPath.append(path);
}
- return fullPath.getAbsolute();
+ return fullPath;
}
/**
@@ -148,8 +125,8 @@ public class ZKApplication {
*
* @param path path to delete
*/
- void deleteRecurse(String path) {
- zk.deleteRecurse(getFullPath(path));
+ void deleteRecurse(Path path) {
+ curator.delete(getFullPath(path));
}
/**
@@ -158,31 +135,21 @@ public class ZKApplication {
* @param path a path relative to the currently active application
* @return a list of file names, which is empty (never null) if the path does not exist
*/
- public List<String> getChildren(String path) {
- String fullPath = getFullPath(path);
- if (! zk.exists(fullPath)) return Collections.emptyList();
- return zk.getChildren(fullPath);
+ public List<String> getChildren(Path path) {
+ return curator.getChildren(getFullPath(path));
}
private static Reader reader(String string) {
return new StringReader(string);
}
- public void create(String path) {
- if (path != null && !path.startsWith("/")) path = "/" + path;
+ public void create(Path path) {
try {
- zk.createNode(getFullPath(path));
+ curator.create(getFullPath(path));
} catch (RuntimeException e) {
throw new IllegalArgumentException(e);
}
}
- Reader getDataReader(String path) {
- String data = getData(path);
- if (data == null)
- throw new IllegalArgumentException("No node for " + getFullPath(path) + " exists");
- return reader(data);
- }
-
}
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationFile.java b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationFile.java
index 674c0f72c40..9ddc384cf93 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationFile.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationFile.java
@@ -5,14 +5,23 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.yahoo.config.application.api.ApplicationFile;
import com.yahoo.path.Path;
import com.yahoo.io.IOUtils;
+
+import java.io.ByteArrayInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
import java.util.logging.Level;
import com.yahoo.vespa.config.util.ConfigUtils;
-import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
+import static com.yahoo.vespa.config.server.zookeeper.ConfigCurator.USERAPP_ZK_SUBPATH;
+
/**
* @author Ulf Lilleengen
* @author Vegard Havdal
@@ -30,7 +39,7 @@ class ZKApplicationFile extends ApplicationFile {
@Override
public boolean isDirectory() {
- String zkPath = getZKPath(path);
+ Path zkPath = getZKPath(path);
if (zkApp.exists(zkPath)) {
String data = zkApp.getData(zkPath);
return data == null || data.isEmpty() || ! zkApp.getChildren(zkPath).isEmpty();
@@ -41,7 +50,7 @@ class ZKApplicationFile extends ApplicationFile {
@Override
public boolean exists() {
try {
- String zkPath = getZKPath(path);
+ Path zkPath = getZKPath(path);
return zkApp.exists(zkPath);
} catch (RuntimeException e) {
return false;
@@ -60,7 +69,7 @@ class ZKApplicationFile extends ApplicationFile {
@Override
public Reader createReader() throws FileNotFoundException {
- String zkPath = getZKPath(path);
+ Path zkPath = getZKPath(path);
if ( ! zkApp.exists(zkPath)) throw new FileNotFoundException("No such path: " + path);
return new StringReader(zkApp.getData(zkPath));
@@ -68,7 +77,7 @@ class ZKApplicationFile extends ApplicationFile {
@Override
public InputStream createInputStream() throws FileNotFoundException {
- String zkPath = getZKPath(path);
+ Path zkPath = getZKPath(path);
if ( ! zkApp.exists(zkPath)) throw new FileNotFoundException("No such path: " + path);
return new ByteArrayInputStream(zkApp.getBytes(zkPath));
@@ -76,7 +85,7 @@ class ZKApplicationFile extends ApplicationFile {
@Override
public ApplicationFile createDirectory() {
- String zkPath = getZKPath(path);
+ Path zkPath = getZKPath(path);
if (isDirectory()) return this;
if (exists()) {
throw new IllegalArgumentException("Unable to create directory, file exists: " + path);
@@ -88,7 +97,7 @@ class ZKApplicationFile extends ApplicationFile {
@Override
public ApplicationFile writeFile(Reader input) {
- String zkPath = getZKPath(path);
+ Path zkPath = getZKPath(path);
try {
String data = IOUtils.readAll(input);
String status = ContentStatusNew;
@@ -105,7 +114,7 @@ class ZKApplicationFile extends ApplicationFile {
@Override
public ApplicationFile appendFile(String value) {
- String zkPath = getZKPath(path);
+ Path zkPath = getZKPath(path);
String status = ContentStatusNew;
if (zkApp.exists(zkPath)) {
status = ContentStatusChanged;
@@ -120,7 +129,7 @@ class ZKApplicationFile extends ApplicationFile {
@Override
public List<ApplicationFile> listFiles(PathFilter filter) {
- String userPath = getZKPath(path);
+ Path userPath = getZKPath(path);
List<ApplicationFile> ret = new ArrayList<>();
for (String zkChild : zkApp.getChildren(userPath)) {
Path childPath = path.append(zkChild);
@@ -132,15 +141,15 @@ class ZKApplicationFile extends ApplicationFile {
return ret;
}
- private static String getZKPath(Path path) {
+ private static Path getZKPath(Path path) {
if (path.isRoot()) {
- return ConfigCurator.USERAPP_ZK_SUBPATH;
+ return Path.fromString(USERAPP_ZK_SUBPATH);
}
- return ConfigCurator.USERAPP_ZK_SUBPATH + "/" + path.getRelative();
+ return Path.fromString(USERAPP_ZK_SUBPATH).append(path);
}
private void writeMetaFile(String input, String status) {
- String metaPath = getZKPath(getMetaPath());
+ Path metaPath = getZKPath(getMetaPath());
StringWriter writer = new StringWriter();
try {
mapper.writeValue(writer, new MetaData(status, input == null ? "" : ConfigUtils.getMd5(input)));
@@ -152,7 +161,7 @@ class ZKApplicationFile extends ApplicationFile {
}
public MetaData getMetaData() {
- String metaPath = getZKPath(getMetaPath());
+ Path metaPath = getZKPath(getMetaPath());
log.log(Level.FINE, () -> "Getting metadata for " + metaPath);
if (!zkApp.exists(getZKPath(path))) {
if (zkApp.exists(metaPath)) {
@@ -167,7 +176,7 @@ class ZKApplicationFile extends ApplicationFile {
return new MetaData(ContentStatusNew, isDirectory() ? "" : ConfigUtils.getMd5(zkApp.getData(getZKPath(path))));
}
- private MetaData getMetaDataFromZk(String metaPath) {
+ private MetaData getMetaDataFromZk(Path metaPath) {
try {
return mapper.readValue(zkApp.getBytes(metaPath), MetaData.class);
} catch (IOException e) {
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 f35af268c29..e0ccc1fcea1 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
@@ -25,7 +25,6 @@ import com.yahoo.vespa.curator.Curator;
import java.io.File;
import java.io.Reader;
-import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -34,6 +33,9 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
+import static com.yahoo.vespa.config.server.zookeeper.ConfigCurator.DEFCONFIGS_ZK_SUBPATH;
+import static com.yahoo.vespa.config.server.zookeeper.ConfigCurator.USERAPP_ZK_SUBPATH;
+
/**
* Represents an application residing in zookeeper.
*
@@ -50,16 +52,16 @@ public class ZKApplicationPackage implements ApplicationPackage {
public static final String allocatedHostsNode = "allocatedHosts";
private final ApplicationMetaData metaData;
- public ZKApplicationPackage(ConfigCurator zk, Path sessionPath) {
- verifyAppPath(zk.curator(), sessionPath);
- zkApplication = new ZKApplication(zk, sessionPath);
+ public ZKApplicationPackage(Curator curator, Path sessionPath) {
+ verifyAppPath(curator, sessionPath);
+ zkApplication = new ZKApplication(curator, sessionPath);
metaData = readMetaDataFromLiveApp(zkApplication);
importFileRegistries();
allocatedHosts = importAllocatedHosts();
}
private Optional<AllocatedHosts> importAllocatedHosts() {
- if ( ! zkApplication.exists(allocatedHostsNode)) return Optional.empty();
+ if ( ! zkApplication.exists(Path.fromString(allocatedHostsNode))) return Optional.empty();
return Optional.of(readAllocatedHosts());
}
@@ -70,14 +72,14 @@ public class ZKApplicationPackage implements ApplicationPackage {
*/
private AllocatedHosts readAllocatedHosts() {
try {
- return AllocatedHostsSerializer.fromJson(zkApplication.getBytes(allocatedHostsNode));
+ return AllocatedHostsSerializer.fromJson(zkApplication.getBytes(Path.fromString(allocatedHostsNode)));
} catch (Exception e) {
throw new RuntimeException("Unable to read allocated hosts", e);
}
}
private void importFileRegistries() {
- List<String> perVersionFileRegistryNodes = zkApplication.getChildren(fileRegistryNode);
+ List<String> perVersionFileRegistryNodes = zkApplication.getChildren(Path.fromString(fileRegistryNode));
perVersionFileRegistryNodes
.forEach(version ->
fileRegistryMap.put(Version.fromString(version),
@@ -86,18 +88,19 @@ public class ZKApplicationPackage implements ApplicationPackage {
private PreGeneratedFileRegistry importFileRegistry(String fileRegistryNode) {
try {
- return PreGeneratedFileRegistry.importRegistry(zkApplication.getDataReader(fileRegistryNode));
+ return PreGeneratedFileRegistry.importRegistry(zkApplication.getDataReader(Path.fromString(fileRegistryNode)));
} catch (Exception e) {
throw new RuntimeException("Could not determine which files to distribute", e);
}
}
private ApplicationMetaData readMetaDataFromLiveApp(ZKApplication liveApp) {
- String metaDataString = liveApp.getData(ConfigCurator.META_ZK_PATH);
+ Path metaPath = Path.fromString(ConfigCurator.META_ZK_PATH);
+ String metaDataString = liveApp.getData(metaPath);
if (metaDataString == null || metaDataString.isEmpty()) {
return null;
}
- return ApplicationMetaData.fromJsonString(liveApp.getData(ConfigCurator.META_ZK_PATH));
+ return ApplicationMetaData.fromJsonString(liveApp.getData(metaPath));
}
@Override
@@ -126,7 +129,7 @@ public class ZKApplicationPackage implements ApplicationPackage {
@Override
public Reader getHosts() {
- if (zkApplication.exists(ConfigCurator.USERAPP_ZK_SUBPATH, HOSTS))
+ if (zkApplication.exists(Path.fromString(USERAPP_ZK_SUBPATH).append(HOSTS)))
return getUserAppData(HOSTS);
return null;
}
@@ -134,9 +137,9 @@ public class ZKApplicationPackage implements ApplicationPackage {
@Override
public List<NamedReader> getSchemas() {
List<NamedReader> schemas = new ArrayList<>();
- for (String sd : zkApplication.getChildren(ConfigCurator.USERAPP_ZK_SUBPATH + "/" + SCHEMAS_DIR)) {
+ for (String sd : zkApplication.getChildren(Path.fromString(USERAPP_ZK_SUBPATH).append(SCHEMAS_DIR))) {
if (sd.endsWith(SD_NAME_SUFFIX))
- schemas.add(new NamedReader(sd, new StringReader(zkApplication.getData(ConfigCurator.USERAPP_ZK_SUBPATH + "/" + SCHEMAS_DIR, sd))));
+ schemas.add(zkApplication.getNamedReader(sd, Path.fromString(USERAPP_ZK_SUBPATH).append(SCHEMAS_DIR).append(sd)));
}
return schemas;
}
@@ -162,7 +165,7 @@ public class ZKApplicationPackage implements ApplicationPackage {
private Reader retrieveConfigDefReader(String def) {
try {
- return zkApplication.getDataReader(ConfigCurator.DEFCONFIGS_ZK_SUBPATH, def);
+ return zkApplication.getNamedReader("configdefinition", Path.fromString(DEFCONFIGS_ZK_SUBPATH).append(def));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Could not retrieve config definition " + def, e);
}
@@ -172,7 +175,7 @@ public class ZKApplicationPackage implements ApplicationPackage {
public Map<ConfigDefinitionKey, UnparsedConfigDefinition> getAllExistingConfigDefs() {
Map<ConfigDefinitionKey, UnparsedConfigDefinition> ret = new LinkedHashMap<>();
- List<String> allDefs = zkApplication.getChildren(ConfigCurator.DEFCONFIGS_ZK_SUBPATH);
+ List<String> allDefs = zkApplication.getChildren(Path.fromString(DEFCONFIGS_ZK_SUBPATH));
for (String nodeName : allDefs) {
ConfigDefinitionKey key = ConfigUtils.createConfigDefinitionKeyFromZKString(nodeName);
@@ -202,7 +205,7 @@ public class ZKApplicationPackage implements ApplicationPackage {
*/
@Override
public List<NamedReader> getFiles(Path relativePath, String suffix, boolean recurse) {
- return zkApplication.getAllDataFromDirectory(ConfigCurator.USERAPP_ZK_SUBPATH + '/' + relativePath.getRelative(), suffix, recurse);
+ return zkApplication.getAllDataFromDirectory(Path.fromString(USERAPP_ZK_SUBPATH).append(relativePath), suffix, recurse);
}
@Override
@@ -227,7 +230,7 @@ public class ZKApplicationPackage implements ApplicationPackage {
public Optional<Reader> getValidationOverrides() { return optionalFile(VALIDATION_OVERRIDES.getName()); }
private Optional<Reader> optionalFile(String file) {
- if (zkApplication.exists(ConfigCurator.USERAPP_ZK_SUBPATH, file))
+ if (zkApplication.exists(Path.fromString(USERAPP_ZK_SUBPATH).append(file)))
return Optional.of(getUserAppData(file));
else
return Optional.empty();
@@ -247,17 +250,17 @@ public class ZKApplicationPackage implements ApplicationPackage {
}
private Reader getUserAppData(String node) {
- return zkApplication.getDataReader(ConfigCurator.USERAPP_ZK_SUBPATH, node);
+ return zkApplication.getDataReader(Path.fromString(USERAPP_ZK_SUBPATH).append(node));
}
@Override
public Reader getRankingExpression(String name) {
- return zkApplication.getDataReader(ConfigCurator.USERAPP_ZK_SUBPATH + "/" + SCHEMAS_DIR, name);
+ return zkApplication.getDataReader(Path.fromString(USERAPP_ZK_SUBPATH).append(SCHEMAS_DIR).append(name));
}
@Override
public File getFileReference(Path pathRelativeToAppDir) {
- String path = ConfigCurator.USERAPP_ZK_SUBPATH + "/" + pathRelativeToAppDir.getRelative();
+ Path path = Path.fromString(USERAPP_ZK_SUBPATH).append(pathRelativeToAppDir);
// File does not exist: Manufacture a non-existing file
if ( ! zkApplication.exists(path)) return new File(pathRelativeToAppDir.getRelative());
@@ -267,8 +270,8 @@ public class ZKApplicationPackage implements ApplicationPackage {
@Override
public void validateIncludeDir(String dirName) {
- String fullPath = ConfigCurator.USERAPP_ZK_SUBPATH + "/" + dirName;
- if ( ! zkApplication.exists(fullPath)) {
+ Path path = Path.fromString(USERAPP_ZK_SUBPATH).append(dirName);
+ if ( ! zkApplication.exists(path)) {
throw new IllegalArgumentException("Cannot include directory '" + dirName +
"', as it does not exist in ZooKeeper!");
}
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
index 934440f03d1..58b7385f4df 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
@@ -472,7 +472,6 @@ public class ApplicationRepositoryTest {
sessionId,
FilesApplicationPackage.fromFile(testApp),
new SessionZooKeeperClient(curator,
- configCurator,
tenant1,
sessionId,
ConfigUtils.getCanonicalHostName()));
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/MockSessionZKClient.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/MockSessionZKClient.java
index 0451ef84e09..bdd758ee1ec 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/MockSessionZKClient.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/MockSessionZKClient.java
@@ -8,7 +8,6 @@ import com.yahoo.config.provision.TenantName;
import com.yahoo.vespa.config.server.tenant.TenantRepository;
import com.yahoo.vespa.config.server.zookeeper.ConfigCurator;
import com.yahoo.vespa.config.util.ConfigUtils;
-import com.yahoo.vespa.curator.Curator;
import java.util.Optional;
@@ -22,18 +21,17 @@ public class MockSessionZKClient extends SessionZooKeeperClient {
private final ApplicationPackage app;
private Optional<AllocatedHosts> info = Optional.empty();
- public MockSessionZKClient(Curator curator, TenantName tenantName, long sessionId) {
+ public MockSessionZKClient(com.yahoo.vespa.curator.Curator curator, TenantName tenantName, long sessionId) {
this(curator, tenantName, sessionId, (ApplicationPackage) null);
}
- public MockSessionZKClient(Curator curator, TenantName tenantName, long sessionId, Optional<AllocatedHosts> allocatedHosts) {
+ public MockSessionZKClient(com.yahoo.vespa.curator.Curator curator, TenantName tenantName, long sessionId, Optional<AllocatedHosts> allocatedHosts) {
this(curator, tenantName, sessionId);
this.info = allocatedHosts;
}
- MockSessionZKClient(Curator curator, TenantName tenantName, long sessionId, ApplicationPackage application) {
+ MockSessionZKClient(com.yahoo.vespa.curator.Curator curator, TenantName tenantName, long sessionId, ApplicationPackage application) {
super(curator,
- ConfigCurator.create(curator),
tenantName,
sessionId,
ConfigUtils.getCanonicalHostName());
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 4995dc0decc..27e2d05a9fa 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
@@ -376,7 +376,7 @@ public class SessionPreparerTest {
}
private SessionZooKeeperClient createSessionZooKeeperClient(long sessionId) {
- return new SessionZooKeeperClient(curator, configCurator, applicationId().tenant(), sessionId, ConfigUtils.getCanonicalHostName());
+ return new SessionZooKeeperClient(curator, applicationId().tenant(), sessionId, ConfigUtils.getCanonicalHostName());
}
private Path sessionPath(long sessionId) {
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 3fa00e3ecc3..2c131e56d67 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
@@ -28,7 +28,6 @@ import com.yahoo.vespa.config.server.http.InvalidApplicationException;
import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry;
import com.yahoo.vespa.config.server.tenant.TenantRepository;
import com.yahoo.vespa.config.server.tenant.TestTenantRepository;
-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;
@@ -285,7 +284,6 @@ public class SessionRepositoryTest {
private void createSession(long sessionId, boolean wait) {
SessionZooKeeperClient zkc = new SessionZooKeeperClient(curator,
- ConfigCurator.create(curator),
tenantName,
sessionId,
ConfigUtils.getCanonicalHostName());
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClientTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClientTest.java
index f977011efbc..65c85c28a92 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClientTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClientTest.java
@@ -171,7 +171,6 @@ public class SessionZooKeeperClientTest {
private SessionZooKeeperClient createSessionZKClient(long sessionId) {
SessionZooKeeperClient zkc = new SessionZooKeeperClient(curator,
- ConfigCurator.create(curator),
tenantName,
sessionId,
ConfigUtils.getCanonicalHostName());
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 c452e1cf0f3..1c43591de9a 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
@@ -5,6 +5,7 @@ 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.Curator;
import com.yahoo.vespa.curator.mock.MockCurator;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
@@ -23,20 +24,20 @@ public class ZKApplicationFileTest extends ApplicationFileTest {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
- private void feed(ConfigCurator zk, File dirToFeed) {
+ private void feed(Curator curator, File dirToFeed) {
assertTrue(dirToFeed.isDirectory());
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"));
+ ZKApplicationPackageTest.feedZooKeeper(curator, dirToFeed, appPath.append(USERAPP_ZK_SUBPATH), null, true);
+ curator.set(appPath.append(ZKApplicationPackage.fileRegistryNode), Utf8.toBytes("dummyfiles"));
}
@Override
public ApplicationFile getApplicationFile(Path path) throws IOException{
- ConfigCurator configCurator = ConfigCurator.create(new MockCurator());
+ Curator curator = new MockCurator();
File tmp = temporaryFolder.newFolder();
writeAppTo(tmp);
- feed(configCurator, tmp);
- return new ZKApplicationFile(path, new ZKApplication(configCurator, Path.fromString("/0")));
+ feed(curator, tmp);
+ return new ZKApplicationFile(path, new ZKApplication(curator, Path.fromString("/0")));
}
}
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 3f84646ad82..20aee737a7d 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
@@ -62,20 +62,20 @@ public class ZKApplicationPackageTest {
Optional.of(DockerImage.fromString(dockerImage)))));
}
- private ConfigCurator configCurator;
+ private Curator curator;
@Rule
public TemporaryFolder tmpDir = new TemporaryFolder();
@Before
public void setup() {
- configCurator = ConfigCurator.create(new MockCurator());
+ curator = new MockCurator();
}
@Test
public void testBasicZKFeed() throws IOException {
- feed(configCurator.curator(), new File(APP));
- ZKApplicationPackage zkApp = new ZKApplicationPackage(configCurator, Path.fromString("/0"));
+ feed(curator, new File(APP));
+ ZKApplicationPackage zkApp = new ZKApplicationPackage(curator, 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());
assertTrue(Pattern.compile(".*<slobroks>.*",Pattern.MULTILINE+Pattern.DOTALL).matcher(IOUtils.readAll(zkApp.getFile(Path.fromString("services.xml")).createReader())).matches());
@@ -106,7 +106,7 @@ public class ZKApplicationPackageTest {
assertEquals("mydisc", DeploymentSpec.fromXml(zkApp.getDeployment().get()).requireInstance("default").globalServiceId().get());
}
- private void feed(Curator zk, File dirToFeed) throws IOException {
+ private void feed(com.yahoo.vespa.curator.Curator zk, File dirToFeed) throws IOException {
assertTrue(dirToFeed.isDirectory());
Path sessionPath = Path.fromString("/0");
feedZooKeeper(zk, dirToFeed, sessionPath.append(USERAPP_ZK_SUBPATH), null, true);
@@ -135,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(Curator zk, File dir, Path path, FilenameFilter filenameFilter, boolean recurse) {
+ static void feedZooKeeper(com.yahoo.vespa.curator.Curator zk, File dir, Path path, FilenameFilter filenameFilter, boolean recurse) {
try {
if (filenameFilter == null) {
filenameFilter = acceptsAllFileNameFilter;