summaryrefslogtreecommitdiffstats
path: root/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackage.java
diff options
context:
space:
mode:
Diffstat (limited to 'configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackage.java')
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackage.java57
1 files changed, 33 insertions, 24 deletions
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..cc9b799f2d9 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,10 +21,10 @@ 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;
-import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -33,6 +33,9 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
+import static com.yahoo.vespa.config.server.zookeeper.ZKApplication.DEFCONFIGS_ZK_SUBPATH;
+import static com.yahoo.vespa.config.server.zookeeper.ZKApplication.USERAPP_ZK_SUBPATH;
+
/**
* Represents an application residing in zookeeper.
*
@@ -49,16 +52,21 @@ public class ZKApplicationPackage implements ApplicationPackage {
public static final String allocatedHostsNode = "allocatedHosts";
private final ApplicationMetaData metaData;
- public ZKApplicationPackage(ConfigCurator zk, Path sessionPath) {
- verifyAppPath(zk, sessionPath);
- zkApplication = new ZKApplication(zk, sessionPath);
+ public ZKApplicationPackage(Curator curator, Path sessionPath, int maxNodeSize) {
+ verifyAppPath(curator, sessionPath);
+ zkApplication = new ZKApplication(curator, sessionPath, maxNodeSize);
metaData = readMetaDataFromLiveApp(zkApplication);
importFileRegistries();
allocatedHosts = importAllocatedHosts();
}
+ // For testing
+ ZKApplicationPackage(Curator curator, Path sessionPath) {
+ this(curator, sessionPath, 10 * 1024 * 1024);
+ }
+
private Optional<AllocatedHosts> importAllocatedHosts() {
- if ( ! zkApplication.exists(allocatedHostsNode)) return Optional.empty();
+ if ( ! zkApplication.exists(Path.fromString(allocatedHostsNode))) return Optional.empty();
return Optional.of(readAllocatedHosts());
}
@@ -69,14 +77,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),
@@ -85,18 +93,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(ZKApplication.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
@@ -104,8 +113,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");
}
@@ -125,7 +134,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;
}
@@ -133,9 +142,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;
}
@@ -161,7 +170,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);
}
@@ -171,7 +180,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);
@@ -201,7 +210,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
@@ -226,7 +235,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();
@@ -246,17 +255,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());
@@ -266,8 +275,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!");
}