diff options
Diffstat (limited to 'config-proxy')
-rw-r--r-- | config-proxy/src/main/java/com/yahoo/vespa/config/proxy/MemoryCache.java | 23 | ||||
-rw-r--r-- | config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ConfigProxyRpcServerTest.java | 10 |
2 files changed, 26 insertions, 7 deletions
diff --git a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/MemoryCache.java b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/MemoryCache.java index 112bd1f86de..91bb669f396 100644 --- a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/MemoryCache.java +++ b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/MemoryCache.java @@ -13,6 +13,7 @@ import com.yahoo.vespa.defaults.Defaults; import java.io.File; import java.io.IOException; import java.io.Writer; +import java.nio.file.Files; import java.util.Collection; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Logger; @@ -77,18 +78,30 @@ public class MemoryCache { String dumpCacheToDisk(String path, MemoryCache cache) { if (path == null || path.isEmpty()) { path = DEFAULT_DUMP_DIR; - log.log(LogLevel.DEBUG, "dumpCache. No path or empty path. Using dir '" + path + "'"); + log.log(LogLevel.INFO, "dumpCache. No path or empty path. Using '" + path + "'"); } if (path.endsWith("/")) { path = path.substring(0, path.length() - 1); } - log.log(LogLevel.DEBUG, "Dumping cache to path '" + path + "'"); - IOUtils.createDirectory(path); + File dir = new File(path); + if ( ! dir.exists()) { + log.log(LogLevel.INFO, dir.getAbsolutePath() + " does not exist, creating it"); + try { + Files.createDirectory(dir.toPath()); + } catch (IOException e) { + return "Failed creating '" + dir.getAbsolutePath() + "', " + e.getClass().getSimpleName(); + } + } - if (!dir.isDirectory() || !dir.canWrite()) { - return "Not a dir or not able to write to '" + dir + "'"; + if ( ! dir.isDirectory()) { + return "Not a directory: '" + dir.getAbsolutePath() + "'"; } + if ( ! dir.canWrite()) { + return "Not able to write to '" + dir.getAbsolutePath() + "'"; + } + + log.log(LogLevel.INFO, "Dumping cache to '" + dir.getAbsolutePath() + "'"); for (RawConfig config : cache.values()) { writeConfigToFile(config, path); } diff --git a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ConfigProxyRpcServerTest.java b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ConfigProxyRpcServerTest.java index ffa70b5bfb5..dc1c995fbb5 100644 --- a/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ConfigProxyRpcServerTest.java +++ b/config-proxy/src/test/java/com/yahoo/vespa/config/proxy/ConfigProxyRpcServerTest.java @@ -13,8 +13,11 @@ import com.yahoo.jrt.Transport; import com.yahoo.vespa.config.RawConfig; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import java.io.IOException; import java.time.Duration; import static org.hamcrest.CoreMatchers.is; @@ -32,6 +35,9 @@ public class ConfigProxyRpcServerTest { private TestServer server; private TestClient client; + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + @Before public void setup() throws ListenFailedException { server = new TestServer(); @@ -247,9 +253,9 @@ public class ConfigProxyRpcServerTest { * Tests dumpCache RPC command */ @Test - public void testRpcMethodDumpCache() { + public void testRpcMethodDumpCache() throws IOException { Request req = new Request("dumpCache"); - String path = "/tmp"; + String path = temporaryFolder.newFolder().getAbsolutePath(); req.parameters().add(new StringValue(path)); client.invoke(req); assertFalse(req.errorMessage(), req.isError()); |