diff options
author | Valerij Fredriksen <freva@users.noreply.github.com> | 2019-08-16 14:55:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-16 14:55:58 +0200 |
commit | ba318cb1604b4a1377d57bb1e0c233948e61d743 (patch) | |
tree | 65aff8587ba8f3a41ecff34df2d5819360c49333 | |
parent | 050adb059aadc22c81f4fb93d6b60e5c5888e3a7 (diff) | |
parent | ec4359c6ffdf8bd1c258664fae832eb616633957 (diff) |
Merge pull request #10307 from vespa-engine/hmusum/cleanup-zk-application
Hmusum/cleanup zk application
-rw-r--r-- | configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ZooKeeperClient.java | 21 | ||||
-rw-r--r-- | configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ConfigCurator.java | 88 | ||||
-rw-r--r-- | configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/InitializedCounter.java | 4 | ||||
-rw-r--r-- | configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplication.java (renamed from configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKLiveApp.java) | 43 | ||||
-rw-r--r-- | configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationFile.java | 7 | ||||
-rw-r--r-- | configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationPackage.java | 68 | ||||
-rw-r--r-- | configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationFileTest.java | 2 |
7 files changed, 69 insertions, 164 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 a99a2a2917d..401b6974596 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 @@ -42,12 +42,7 @@ public class ZooKeeperClient { /* This is the generation that will be used for reading and writing application data. (1 more than last deployed application) */ private final Path rootPath; - static final ApplicationFile.PathFilter xmlFilter = new ApplicationFile.PathFilter() { - @Override - public boolean accept(Path path) { - return path.getName().endsWith(".xml"); - } - }; + private static final ApplicationFile.PathFilter xmlFilter = path -> path.getName().endsWith(".xml"); public ZooKeeperClient(ConfigCurator configCurator, DeployLogger logger, boolean logFine, Path rootPath) { this.configCurator = configCurator; @@ -116,23 +111,15 @@ public class ZooKeeperClient { logFine("Feeding application config into ZooKeeper"); // gives lots and lots of debug output: // BasicConfigurator.configure(); try { - logFine("zk operations: " + configCurator.getNumberOfOperations()); logFine("Feeding user def files into ZooKeeper"); writeUserDefs(app); - logFine("zk operations: " + configCurator.getNumberOfOperations()); logFine("Feeding application package into ZooKeeper"); - // TODO 1200 zk operations done in the below method writeSomeOf(app); writeSearchDefinitions(app); writeUserIncludeDirs(app, app.getUserIncludeDirs()); - logFine("zk operations: " + configCurator.getNumberOfOperations()); - logFine("zk read operations: " + configCurator.getNumberOfReadOperations()); - logFine("zk write operations: " + configCurator.getNumberOfWriteOperations()); logFine("Feeding sd from docproc bundle into ZooKeeper"); - logFine("zk operations: " + configCurator.getNumberOfOperations()); logFine("Write application metadata into ZooKeeper"); write(app.getMetaData()); - logFine("zk operations: " + configCurator.getNumberOfOperations()); } catch (Exception e) { throw new IllegalStateException("Unable to write vespa model to config server(s) " + System.getProperty("configsources") + "\n" + "Please ensure that cloudconfig_server is started on the config server node(s), " + @@ -164,7 +151,7 @@ public class ZooKeeperClient { * @param app The application package to use as input. * @throws java.io.IOException if not able to write to Zookeeper */ - void writeSomeOf(ApplicationPackage app) throws IOException { + private void writeSomeOf(ApplicationPackage app) throws IOException { ApplicationFile.PathFilter srFilter = new ApplicationFile.PathFilter() { @Override public boolean accept(Path path) { @@ -342,7 +329,7 @@ public class ZooKeeperClient { * @param trailingPath trailing part of path to be appended to ZK app path * @return a String with the full ZK application path including trailing path, if set */ - Path getZooKeeperAppPath(String trailingPath) { + private Path getZooKeeperAppPath(String trailingPath) { if (trailingPath != null) { return rootPath.append(trailingPath); } else { @@ -350,7 +337,7 @@ public class ZooKeeperClient { } } - void logFine(String msg) { + private void logFine(String msg) { if (logFine) { logger.log(LogLevel.FINE, msg); } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ConfigCurator.java b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ConfigCurator.java index 56709225c1d..30754b7bc04 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ConfigCurator.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ConfigCurator.java @@ -13,7 +13,6 @@ import java.io.FilenameFilter; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; /** * A (stateful) curator wrapper for the config server. This simplifies Curator method calls used by the config server @@ -23,17 +22,12 @@ import java.util.concurrent.atomic.AtomicInteger; * Config ids are stored as foo#bar#c0 instead of foo/bar/c0, for simplicity. * Keep the amount of domain-specific logic here to a minimum. * Data for one application x is stored on this form: - * /vespa/config/apps/x/defconfigs - * /vespa/config/apps/x/userapp - * The different types of configs are stored on this form (ie. names of the ZK nodes under their respective - * paths): + * /config/v2/tenants/x/sessions/y/defconfigs + * /config/v2/tenants/x/sessions/y/userapp * <p> - * Def configs are stored on the form name,version * The user application structure is exactly the same as in the user's app dir during deploy. - * The current live app id (for example x) is stored in the node /vespa/config/liveapp - * It is updated outside this class, typically in config server during reload-config. - * Some methods have retries and/or reconnect. This is necessary because ZK will throw on certain scenarios, - * even though it will recover from it itself, @see http://wiki.apache.org/hadoop/ZooKeeper/ErrorHandling + * The current live app id (for example y) is stored in the node //config/v2/tenants/x/applications/<application-id> + * It is updated outside this class, typically in config server when activating config * * @author Vegard Havdal * @author bratseth @@ -55,33 +49,15 @@ public class ConfigCurator { /** Path for session state */ public static final String SESSIONSTATE_ZK_SUBPATH = "/sessionState"; - protected static final FilenameFilter acceptsAllFileNameFilter = (dir, name) -> true; + private static final FilenameFilter acceptsAllFileNameFilter = (dir, name) -> true; private final Curator curator; public static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(ConfigCurator.class.getName()); - /** The number of zookeeper operations done with this ZKFacade instance */ - private final AtomicInteger operations = new AtomicInteger(); - - /** The number of zookeeper read operations done with this ZKFacade instance */ - private final AtomicInteger readOperations = new AtomicInteger(); - - /** The number of zookeeper write operations done with this ZKFacade instance */ - private final AtomicInteger writeOperations = new AtomicInteger(); - /** The maximum size of a ZooKeeper node */ private final int maxNodeSize; - /** - * Sets up thread local zk access if not done before and returns a facade object - * - * @return a ZKFacade object - */ - public static ConfigCurator create(Curator curator, int juteMaxBuffer) { - return new ConfigCurator(curator, juteMaxBuffer); - } - public static ConfigCurator create(Curator curator) { return new ConfigCurator(curator, 1024*1024*10); } @@ -102,10 +78,8 @@ public class ConfigCurator { public Curator curator() { return curator; } /** Cleans and creates a zookeeper completely */ - public void initAndClear(String path) { + void initAndClear(String path) { try { - operations.incrementAndGet(); - readOperations.incrementAndGet(); if (exists(path)) deleteRecurse(path); createRecurse(path); @@ -151,8 +125,6 @@ public class ConfigCurator { public byte[] getBytes(String path) { try { if ( ! exists(path)) return null; // TODO: Ugh - operations.incrementAndGet(); - readOperations.incrementAndGet(); return curator.framework().getData().forPath(path); } catch (Exception e) { @@ -179,8 +151,6 @@ public class ConfigCurator { public void createNode(String path) { if ( ! exists(path)) createRecurse(path); - operations.incrementAndGet(); - writeOperations.incrementAndGet(); } /** Creates a Zookeeper node synchronously. Replaces / by # in node names. */ @@ -210,7 +180,7 @@ public class ConfigCurator { } /** Sets data at a given path and name. Replaces / by # in node names. Creates the node if it doesn't exist */ - public void putData(String path, String node, byte[] data) { + private void putData(String path, String node, byte[] data) { putData(createFullPath(path, node), data); } @@ -218,8 +188,6 @@ public class ConfigCurator { public void putData(String path, byte[] data) { try { ensureDataIsNotTooLarge(data, path); - operations.incrementAndGet(); - writeOperations.incrementAndGet(); if (exists(path)) curator.framework().setData().forPath(path, data); else @@ -230,36 +198,13 @@ public class ConfigCurator { } } - /** Sets data at an existing node. Replaces / by # in node names. */ - public void setData(String path, String node, String data) { - setData(path, node, Utf8.toBytes(data)); - } - - /** Sets data at an existing node. Replaces / by # in node names. */ - public void setData(String path, String node, byte[] data) { - setData(createFullPath(path, node), data); - } - - /** Sets data at an existing node. Replaces / by # in node names. */ - public void setData(String path, byte[] data) { - try { - ensureDataIsNotTooLarge(data, path); - operations.incrementAndGet(); - writeOperations.incrementAndGet(); - curator.framework().setData().forPath(path, data); - } - catch (Exception e) { - throw new RuntimeException("Exception writing to path " + path + " in ZooKeeper", e); - } - } - /** * Replaces / with # in the given node. * * @param node a zookeeper node name * @return a config server node name */ - protected String toConfigserverName(String node) { + private String toConfigserverName(String node) { if (node.startsWith("/")) node = node.substring(1); return node.replaceAll("/", "#"); } @@ -271,8 +216,6 @@ public class ConfigCurator { */ public List<String> getChildren(String path) { try { - operations.incrementAndGet(); - readOperations.incrementAndGet(); return curator.framework().getChildren().forPath(path); } catch (Exception e) { @@ -300,7 +243,7 @@ public class ConfigCurator { * @param filenameFilter A FilenameFilter which decides which files in dir are fed to zookeeper * @param recurse recurse subdirectories */ - public void feedZooKeeper(File dir, String path, FilenameFilter filenameFilter, boolean recurse) { + void feedZooKeeper(File dir, String path, FilenameFilter filenameFilter, boolean recurse) { try { if (filenameFilter == null) { filenameFilter = acceptsAllFileNameFilter; @@ -347,7 +290,7 @@ public class ConfigCurator { } } } - return ret.toArray(new File[ret.size()]); + return ret.toArray(new File[0]); } /** Deletes the node at the given path, and any children it may have. If the node does not exist this does nothing */ @@ -361,17 +304,6 @@ public class ConfigCurator { } } - public Integer getNumberOfOperations() { return operations.intValue(); } - - public Integer getNumberOfReadOperations() { - return readOperations.intValue(); - } - - public Integer getNumberOfWriteOperations() { - return writeOperations.intValue(); - } - - private void testZkConnection() { // This is not necessary, but allows us to give a useful error message if (curator.connectionSpec().isEmpty()) return; try { diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/InitializedCounter.java b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/InitializedCounter.java index dc93886e0c0..773888a8a03 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/InitializedCounter.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/InitializedCounter.java @@ -17,10 +17,10 @@ import java.util.List; public class InitializedCounter { private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(InitializedCounter.class.getName()); - protected final CuratorCounter counter; + final CuratorCounter counter; private final String sessionsDirPath; - public InitializedCounter(ConfigCurator configCurator, String counterPath, String sessionsDirPath) { + InitializedCounter(ConfigCurator configCurator, String counterPath, String sessionsDirPath) { this.sessionsDirPath = sessionsDirPath; this.counter = new CuratorCounter(configCurator.curator(), counterPath); initializeCounterValue(getLatestSessionId(configCurator, sessionsDirPath)); diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKLiveApp.java b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplication.java index 383672b3639..3ae678969eb 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKLiveApp.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplication.java @@ -9,25 +9,22 @@ import java.io.StringReader; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.logging.Logger; /** - * Responsible for providing data from the currently live application subtree in zookeeper. - * (i.e. /vespa/config/apps/<id of currently active app>/). + * Responsible for providing data from an application subtree in zookeeper. + * (i.e. /config/v2/tenants/x/session/<session id for an application>/). + * + * Takes care of * - * Note: The application revision ("session") stored in this tree is not necessarily live, just complete, - * preparable, prepared or active. * * @author Tony Vaagenes */ -public class ZKLiveApp { - - private static final Logger log = Logger.getLogger(ZKLiveApp.class.getName()); +public class ZKApplication { private final ConfigCurator zk; private final Path appPath; - public ZKLiveApp(ConfigCurator zk, Path appPath) { + ZKApplication(ConfigCurator zk, Path appPath) { this.zk = zk; this.appPath = appPath; } @@ -36,14 +33,14 @@ public class ZKLiveApp { * Returns a list of the files (as readers) in the given path. The readers <b>must</b> * be closed by the caller. * - * @param path a path relative to the currently active application - * (i.e. /vespa/config/apps/<id of currently active app>/). + * @param path a path relative to the session + * (i.e. /config/v2/tenants/x/sessions/<session id>/). * @param fileNameSuffix the suffix of files to return, or null to return all * @param recursive if true, all files from all subdirectories of this will also be returned - * @return the files in the given path, or an empty list (never null) if the directory does not exist or is empty. + * @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. */ - public List<NamedReader> getAllDataFromDirectory(String path, String fileNameSuffix, boolean recursive) { + List<NamedReader> getAllDataFromDirectory(String path, String fileNameSuffix, boolean recursive) { return getAllDataFromDirectory(path, "", fileNameSuffix, recursive); } @@ -73,14 +70,13 @@ public class ZKLiveApp { } /** - * Retrieves a node relative to the node of the live application, - * e.g. /vespa/config/apps/$lt;app_id>/<path>/<node> + * 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 */ - public Reader getDataReader(String path, String node) { + Reader getDataReader(String path, String node) { String data = getData(path, node); if (data == null) { throw new IllegalArgumentException("No node for " + getFullPath(path) + "/" + node + " exists"); @@ -113,7 +109,7 @@ public class ZKLiveApp { } } - public void putData(String path, String data) { + void putData(String path, String data) { try { zk.putData(getFullPath(path), data); } catch (RuntimeException e) { @@ -121,15 +117,6 @@ public class ZKLiveApp { } } - public void create(String path, String node) { - if (path != null && !path.startsWith("/")) path = "/" + path; - try { - zk.createNode(getFullPath(path), node); - } catch (RuntimeException e) { - throw new IllegalArgumentException(e); - } - } - /** * Checks if the given node exists under path under this live app * @@ -164,7 +151,7 @@ public class ZKLiveApp { * * @param path path to delete */ - public void deleteRecurse(String path) { + void deleteRecurse(String path) { zk.deleteRecurse(getFullPath(path)); } @@ -193,7 +180,7 @@ public class ZKLiveApp { } } - public Reader getDataReader(String path) { + Reader getDataReader(String path) { final String data = getData(path); if (data == null) { throw new IllegalArgumentException("No node for " + getFullPath(path) + " exists"); 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 c2d59844fde..ad0d4a2e540 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 @@ -15,16 +15,15 @@ import java.util.logging.Logger; /** * @author Ulf Lilleengen - * @author vegardh - * @since 5.1 + * @author Vegard Havdal */ class ZKApplicationFile extends ApplicationFile { private static final Logger log = Logger.getLogger("ZKApplicationFile"); - private final ZKLiveApp zkApp; + private final ZKApplication zkApp; private final ObjectMapper mapper = new ObjectMapper(); - public ZKApplicationFile(Path path, ZKLiveApp app) { + public ZKApplicationFile(Path path, ZKApplication app) { super(path); this.zkApp = app; } 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 e013244c80c..786b26318a3 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 @@ -31,6 +31,7 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; /** @@ -40,7 +41,7 @@ import java.util.Optional; */ public class ZKApplicationPackage implements ApplicationPackage { - private ZKLiveApp liveApp; + private ZKApplication zkApplication; private final Map<Version, PreGeneratedFileRegistry> fileRegistryMap = new HashMap<>(); private final Optional<AllocatedHosts> allocatedHosts; @@ -50,17 +51,17 @@ public class ZKApplicationPackage implements ApplicationPackage { public static final String allocatedHostsNode = "allocatedHosts"; private final ApplicationMetaData metaData; - public ZKApplicationPackage(ConfigCurator zk, Path appPath, Optional<NodeFlavors> nodeFlavors) { - verifyAppPath(zk, appPath); - liveApp = new ZKLiveApp(zk, appPath); - metaData = readMetaDataFromLiveApp(liveApp); - importFileRegistries(fileRegistryNode); - allocatedHosts = importAllocatedHosts(allocatedHostsNode, nodeFlavors); + public ZKApplicationPackage(ConfigCurator zk, Path sessionPath, Optional<NodeFlavors> nodeFlavors) { + verifyAppPath(zk, sessionPath); + zkApplication = new ZKApplication(zk, sessionPath); + metaData = readMetaDataFromLiveApp(zkApplication); + importFileRegistries(); + allocatedHosts = importAllocatedHosts(nodeFlavors); } - private Optional<AllocatedHosts> importAllocatedHosts(String allocatedHostsPath, Optional<NodeFlavors> nodeFlavors) { - if ( ! liveApp.exists(allocatedHostsPath)) return Optional.empty(); - return Optional.of(readAllocatedHosts(allocatedHostsPath, nodeFlavors)); + private Optional<AllocatedHosts> importAllocatedHosts(Optional<NodeFlavors> nodeFlavors) { + if ( ! zkApplication.exists(ZKApplicationPackage.allocatedHostsNode)) return Optional.empty(); + return Optional.of(readAllocatedHosts(nodeFlavors)); } /** @@ -68,35 +69,35 @@ public class ZKApplicationPackage implements ApplicationPackage { * * @return the allocated hosts at this node or empty if there is no data at this path */ - private AllocatedHosts readAllocatedHosts(String allocatedHostsPath, Optional<NodeFlavors> nodeFlavors) { + private AllocatedHosts readAllocatedHosts(Optional<NodeFlavors> nodeFlavors) { try { - return AllocatedHostsSerializer.fromJson(liveApp.getBytes(allocatedHostsPath), nodeFlavors); + return AllocatedHostsSerializer.fromJson(zkApplication.getBytes(ZKApplicationPackage.allocatedHostsNode), nodeFlavors); } catch (Exception e) { throw new RuntimeException("Unable to read allocated hosts", e); } } - private void importFileRegistries(String fileRegistryNode) { - List<String> fileRegistryNodes = liveApp.getChildren(fileRegistryNode); + private void importFileRegistries() { + List<String> fileRegistryNodes = zkApplication.getChildren(ZKApplicationPackage.fileRegistryNode); if (fileRegistryNodes.isEmpty()) { - fileRegistryMap.put(legacyVersion, importFileRegistry(fileRegistryNode)); + fileRegistryMap.put(legacyVersion, importFileRegistry(ZKApplicationPackage.fileRegistryNode)); } else { fileRegistryNodes.forEach(version -> fileRegistryMap.put(Version.fromString(version), - importFileRegistry(Joiner.on("/").join(fileRegistryNode, version)))); + importFileRegistry(Joiner.on("/").join(ZKApplicationPackage.fileRegistryNode, version)))); } } private PreGeneratedFileRegistry importFileRegistry(String fileRegistryNode) { try { - return PreGeneratedFileRegistry.importRegistry(liveApp.getDataReader(fileRegistryNode)); + return PreGeneratedFileRegistry.importRegistry(zkApplication.getDataReader(fileRegistryNode)); } catch (Exception e) { throw new RuntimeException("Could not determine which files to distribute. " + "Please try redeploying the application", e); } } - private ApplicationMetaData readMetaDataFromLiveApp(ZKLiveApp liveApp) { + private ApplicationMetaData readMetaDataFromLiveApp(ZKApplication liveApp) { String metaDataString = liveApp.getData(ConfigCurator.META_ZK_PATH); if (metaDataString == null || metaDataString.isEmpty()) { return null; @@ -126,7 +127,7 @@ public class ZKApplicationPackage implements ApplicationPackage { @Override public Reader getHosts() { - if (liveApp.exists(ConfigCurator.USERAPP_ZK_SUBPATH,HOSTS)) + if (zkApplication.exists(ConfigCurator.USERAPP_ZK_SUBPATH, HOSTS)) return getUserAppData(HOSTS); return null; } @@ -134,9 +135,9 @@ public class ZKApplicationPackage implements ApplicationPackage { @Override public List<NamedReader> searchDefinitionContents() { List<NamedReader> ret = new ArrayList<>(); - for (String sd : liveApp.getChildren(ConfigCurator.USERAPP_ZK_SUBPATH+"/"+SEARCH_DEFINITIONS_DIR)) { + for (String sd : zkApplication.getChildren(ConfigCurator.USERAPP_ZK_SUBPATH+"/"+SEARCH_DEFINITIONS_DIR)) { if (sd.endsWith(ApplicationPackage.SD_NAME_SUFFIX)) { - ret.add(new NamedReader(sd, new StringReader(liveApp.getData(ConfigCurator.USERAPP_ZK_SUBPATH+"/"+SEARCH_DEFINITIONS_DIR, sd)))); + ret.add(new NamedReader(sd, new StringReader(zkApplication.getData(ConfigCurator.USERAPP_ZK_SUBPATH+"/"+SEARCH_DEFINITIONS_DIR, sd)))); } } return ret; @@ -155,7 +156,7 @@ public class ZKApplicationPackage implements ApplicationPackage { private Optional<PreGeneratedFileRegistry> getPreGeneratedFileRegistry(Version vespaVersion) { // Assumes at least one file registry, which we always have. Optional<PreGeneratedFileRegistry> fileRegistry = Optional.ofNullable(fileRegistryMap.get(vespaVersion)); - if ( ! fileRegistry.isPresent()) { + if (fileRegistry.isEmpty()) { fileRegistry = Optional.of(fileRegistryMap.values().iterator().next()); } return fileRegistry; @@ -168,7 +169,7 @@ public class ZKApplicationPackage implements ApplicationPackage { private Reader retrieveConfigDefReader(String def) { try { - return liveApp.getDataReader(ConfigCurator.DEFCONFIGS_ZK_SUBPATH, def); + return zkApplication.getDataReader(ConfigCurator.DEFCONFIGS_ZK_SUBPATH, def); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Could not retrieve config definition " + def + ".", e); } @@ -178,7 +179,7 @@ public class ZKApplicationPackage implements ApplicationPackage { public Map<ConfigDefinitionKey, UnparsedConfigDefinition> getAllExistingConfigDefs() { Map<ConfigDefinitionKey, UnparsedConfigDefinition> ret = new LinkedHashMap<>(); - List<String> allDefs = liveApp.getChildren(ConfigCurator.DEFCONFIGS_ZK_SUBPATH); + List<String> allDefs = zkApplication.getChildren(ConfigCurator.DEFCONFIGS_ZK_SUBPATH); for (String nodeName : allDefs) { ConfigDefinitionKey key = ConfigUtils.createConfigDefinitionKeyFromZKString(nodeName); @@ -208,12 +209,12 @@ public class ZKApplicationPackage implements ApplicationPackage { */ @Override public List<NamedReader> getFiles(Path relativePath, String suffix, boolean recurse) { - return liveApp.getAllDataFromDirectory(ConfigCurator.USERAPP_ZK_SUBPATH + '/' + relativePath.getRelative(), suffix, recurse); + return zkApplication.getAllDataFromDirectory(ConfigCurator.USERAPP_ZK_SUBPATH + '/' + relativePath.getRelative(), suffix, recurse); } @Override public ApplicationFile getFile(Path file) { - return new ZKApplicationFile(file, liveApp); + return new ZKApplicationFile(file, zkApplication); } @Override @@ -233,7 +234,7 @@ public class ZKApplicationPackage implements ApplicationPackage { public Optional<Reader> getValidationOverrides() { return optionalFile(VALIDATION_OVERRIDES.getName()); } private Optional<Reader> optionalFile(String file) { - if (liveApp.exists(ConfigCurator.USERAPP_ZK_SUBPATH, file)) + if (zkApplication.exists(ConfigCurator.USERAPP_ZK_SUBPATH, file)) return Optional.of(getUserAppData(file)); else return Optional.empty(); @@ -253,26 +254,25 @@ public class ZKApplicationPackage implements ApplicationPackage { } private Reader getUserAppData(String node) { - return liveApp.getDataReader(ConfigCurator.USERAPP_ZK_SUBPATH, node); + return zkApplication.getDataReader(ConfigCurator.USERAPP_ZK_SUBPATH, node); } @Override public Reader getRankingExpression(String name) { - return liveApp.getDataReader(ConfigCurator.USERAPP_ZK_SUBPATH+"/"+SEARCH_DEFINITIONS_DIR, name); + return zkApplication.getDataReader(ConfigCurator.USERAPP_ZK_SUBPATH+"/"+SEARCH_DEFINITIONS_DIR, name); } @Override public File getFileReference(Path pathRelativeToAppDir) { - String fileName = liveApp.getData(ConfigCurator.USERAPP_ZK_SUBPATH + "/" + pathRelativeToAppDir.getRelative()); - if (fileName == null) - return new File(pathRelativeToAppDir.getRelative()); // File does not exist: Manufacture a non-existing file - return new File(fileName); + String fileName = zkApplication.getData(ConfigCurator.USERAPP_ZK_SUBPATH + "/" + pathRelativeToAppDir.getRelative()); + // File does not exist: Manufacture a non-existing file + return new File(Objects.requireNonNullElseGet(fileName, pathRelativeToAppDir::getRelative)); } @Override public void validateIncludeDir(String dirName) { String fullPath = ConfigCurator.USERAPP_ZK_SUBPATH + "/" + dirName; - if (!liveApp.exists(fullPath)) { + if ( ! zkApplication.exists(fullPath)) { 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/zookeeper/ZKApplicationFileTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationFileTest.java index 0bea19adaf1..0b028b96eab 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 @@ -31,7 +31,7 @@ public class ZKApplicationFileTest extends ApplicationFileTest { File tmp = Files.createTempDir(); writeAppTo(tmp); feed(configCurator, tmp); - return new ZKApplicationFile(path, new ZKLiveApp(configCurator, Path.fromString("/0"))); + return new ZKApplicationFile(path, new ZKApplication(configCurator, Path.fromString("/0"))); } } |