summaryrefslogtreecommitdiffstats
path: root/node-maintainer/src
diff options
context:
space:
mode:
authorvalerijf <valerijf@yahoo-inc.com>2017-03-08 14:19:25 +0100
committervalerijf <valerijf@yahoo-inc.com>2017-03-08 14:19:25 +0100
commit86d966c3e11389b2f4190f7a549528efd6a8f11f (patch)
treee3fc26394997d0c8a3ecde2798943ac0315e219a /node-maintainer/src
parent91cf8827f3d9b286e19f69677de8afce0efac4ae (diff)
Renamed DeleteOldAppData to FileHelper
Diffstat (limited to 'node-maintainer/src')
-rw-r--r--node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/CoredumpHandler.java2
-rw-r--r--node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/FileHelper.java (renamed from node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/DeleteOldAppData.java)8
-rw-r--r--node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/restapi/v1/MaintainerApiHandler.java10
-rw-r--r--node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/maintainer/FileHelperTest.java (renamed from node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/maintainer/DeleteOldAppDataTest.java)40
4 files changed, 30 insertions, 30 deletions
diff --git a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/CoredumpHandler.java b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/CoredumpHandler.java
index 54ff7db997f..5794e5e5389 100644
--- a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/CoredumpHandler.java
+++ b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/CoredumpHandler.java
@@ -50,7 +50,7 @@ public class CoredumpHandler {
public void removeJavaCoredumps(Path javaCoredumpsPath) throws IOException {
if (! javaCoredumpsPath.toFile().isDirectory()) return;
- DeleteOldAppData.deleteFiles(javaCoredumpsPath, Duration.ZERO, Optional.of("^java_pid.*\\.hprof$"), false);
+ FileHelper.deleteFiles(javaCoredumpsPath, Duration.ZERO, Optional.of("^java_pid.*\\.hprof$"), false);
}
Path processCoredumps(Path coredumpsPath, Map<String, Object> nodeAttributes) throws IOException {
diff --git a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/DeleteOldAppData.java b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/FileHelper.java
index ea8481b6bcb..b9255ace848 100644
--- a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/DeleteOldAppData.java
+++ b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/FileHelper.java
@@ -20,8 +20,8 @@ import java.util.stream.Collectors;
* @author freva
*/
-public class DeleteOldAppData {
- private static final Logger logger = Logger.getLogger(DeleteOldAppData.class.getSimpleName());
+public class FileHelper {
+ private static final Logger logger = Logger.getLogger(FileHelper.class.getSimpleName());
/**
* (Recursively) deletes files if they match all the criteria, also deletes empty directories.
@@ -64,7 +64,7 @@ public class DeleteOldAppData {
List<Path> pathsInDeleteDir = Files.list(basePath)
.filter(Files::isRegularFile)
- .sorted(Comparator.comparing(DeleteOldAppData::getLastModifiedTime))
+ .sorted(Comparator.comparing(FileHelper::getLastModifiedTime))
.skip(nMostRecentToKeep)
.collect(Collectors.toList());
@@ -138,7 +138,7 @@ public class DeleteOldAppData {
private static Optional<Path> getMostRecentlyModifiedFileIn(Path basePath) {
return listContentsOfDirectory(basePath).stream()
.filter(Files::isRegularFile)
- .max(Comparator.comparing(DeleteOldAppData::getLastModifiedTime));
+ .max(Comparator.comparing(FileHelper::getLastModifiedTime));
}
private static boolean isTimeSinceLastModifiedMoreThan(Path path, Duration duration) {
diff --git a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/restapi/v1/MaintainerApiHandler.java b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/restapi/v1/MaintainerApiHandler.java
index 8564746a27d..7aa8b09c746 100644
--- a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/restapi/v1/MaintainerApiHandler.java
+++ b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/restapi/v1/MaintainerApiHandler.java
@@ -14,7 +14,7 @@ import com.yahoo.system.ProcessExecuter;
import com.yahoo.vespa.config.SlimeUtils;
import com.yahoo.vespa.hosted.node.maintainer.CoreCollector;
import com.yahoo.vespa.hosted.node.maintainer.CoredumpHandler;
-import com.yahoo.vespa.hosted.node.maintainer.DeleteOldAppData;
+import com.yahoo.vespa.hosted.node.maintainer.FileHelper;
import com.yahoo.yolean.Exceptions;
import org.apache.http.impl.client.HttpClientBuilder;
@@ -121,7 +121,7 @@ public class MaintainerApiHandler extends LoggingRequestHandler {
Optional<String> fileNameRegex = SlimeUtils.optionalString(getFieldOrFail(arguments, "fileNameRegex"));
boolean recursive = getFieldOrFail(arguments, "recursive").asBool();
try {
- DeleteOldAppData.deleteFiles(basePath, maxAge, fileNameRegex, recursive);
+ FileHelper.deleteFiles(basePath, maxAge, fileNameRegex, recursive);
} catch (IOException e) {
throw new RuntimeException("Failed deleting files under " + basePath.toAbsolutePath() +
fileNameRegex.map(regex -> ", matching '" + regex + "'").orElse("") +
@@ -135,7 +135,7 @@ public class MaintainerApiHandler extends LoggingRequestHandler {
Duration maxAge = Duration.ofSeconds(getFieldOrFail(arguments, "maxAgeSeconds").asLong());
Optional<String> dirNameRegex = SlimeUtils.optionalString(getFieldOrFail(arguments, "dirNameRegex"));
try {
- DeleteOldAppData.deleteDirectories(basePath, maxAge, dirNameRegex);
+ FileHelper.deleteDirectories(basePath, maxAge, dirNameRegex);
} catch (IOException e) {
throw new RuntimeException("Failed deleting directories under " + basePath.toAbsolutePath() +
dirNameRegex.map(regex -> ", matching '" + regex + "'").orElse("") +
@@ -146,7 +146,7 @@ public class MaintainerApiHandler extends LoggingRequestHandler {
private void parseRecursiveDelete(Inspector arguments) {
Path basePath = Paths.get(getFieldOrFail(arguments, "path").asString());
try {
- DeleteOldAppData.recursiveDelete(basePath);
+ FileHelper.recursiveDelete(basePath);
} catch (IOException e) {
throw new RuntimeException("Failed deleting " + basePath.toAbsolutePath(), e);
}
@@ -157,7 +157,7 @@ public class MaintainerApiHandler extends LoggingRequestHandler {
Path to = Paths.get(getFieldOrFail(arguments, "to").asString());
try {
- DeleteOldAppData.moveIfExists(from, to);
+ FileHelper.moveIfExists(from, to);
} catch (IOException e) {
throw new RuntimeException("Failed moving from " + from.toAbsolutePath() + ", to " + to.toAbsolutePath(), e);
}
diff --git a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/maintainer/DeleteOldAppDataTest.java b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/maintainer/FileHelperTest.java
index 0092c77e477..55057cd83f9 100644
--- a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/maintainer/DeleteOldAppDataTest.java
+++ b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/maintainer/FileHelperTest.java
@@ -24,7 +24,7 @@ import static org.junit.Assert.assertTrue;
/**
* @author freva
*/
-public class DeleteOldAppDataTest {
+public class FileHelperTest {
@Rule
public TemporaryFolder folder = new TemporaryFolder();
@@ -51,42 +51,42 @@ public class DeleteOldAppDataTest {
@Test
public void testDeleteAll() throws IOException {
- DeleteOldAppData.deleteFiles(folder.getRoot().toPath(), Duration.ZERO, Optional.empty(), false);
+ FileHelper.deleteFiles(folder.getRoot().toPath(), Duration.ZERO, Optional.empty(), false);
assertEquals(0, getContentsOfDirectory(folder.getRoot()).length);
}
@Test
public void testDeletePrefix() throws IOException {
- DeleteOldAppData.deleteFiles(folder.getRoot().toPath(), Duration.ZERO, Optional.of("^test_"), false);
+ FileHelper.deleteFiles(folder.getRoot().toPath(), Duration.ZERO, Optional.of("^test_"), false);
assertEquals(6, getContentsOfDirectory(folder.getRoot()).length); // 5 abc files + 1 week_old_file
}
@Test
public void testDeleteSuffix() throws IOException {
- DeleteOldAppData.deleteFiles(folder.getRoot().toPath(), Duration.ZERO, Optional.of(".json$"), false);
+ FileHelper.deleteFiles(folder.getRoot().toPath(), Duration.ZERO, Optional.of(".json$"), false);
assertEquals(7, getContentsOfDirectory(folder.getRoot()).length);
}
@Test
public void testDeletePrefixAndSuffix() throws IOException {
- DeleteOldAppData.deleteFiles(folder.getRoot().toPath(), Duration.ZERO, Optional.of("^test_.*\\.json$"), false);
+ FileHelper.deleteFiles(folder.getRoot().toPath(), Duration.ZERO, Optional.of("^test_.*\\.json$"), false);
assertEquals(13, getContentsOfDirectory(folder.getRoot()).length); // 5 abc files + 7 test_*_file.test files + week_old_file
}
@Test
public void testDeleteOld() throws IOException {
- DeleteOldAppData.deleteFiles(folder.getRoot().toPath(), Duration.ofSeconds(600), Optional.empty(), false);
+ FileHelper.deleteFiles(folder.getRoot().toPath(), Duration.ofSeconds(600), Optional.empty(), false);
assertEquals(13, getContentsOfDirectory(folder.getRoot()).length); // All 23 - 6 (from test_*_.json) - 3 (from test_*_file.test) - 1 week old file
}
@Test
public void testDeleteWithAllParameters() throws IOException {
- DeleteOldAppData.deleteFiles(folder.getRoot().toPath(), Duration.ofSeconds(200), Optional.of("^test_.*\\.json$"), false);
+ FileHelper.deleteFiles(folder.getRoot().toPath(), Duration.ofSeconds(200), Optional.of("^test_.*\\.json$"), false);
assertEquals(15, getContentsOfDirectory(folder.getRoot()).length); // All 23 - 8 (from test_*_.json)
}
@@ -94,7 +94,7 @@ public class DeleteOldAppDataTest {
@Test
public void testDeleteWithSubDirectoriesNoRecursive() throws IOException {
initSubDirectories();
- DeleteOldAppData.deleteFiles(folder.getRoot().toPath(), Duration.ZERO, Optional.of("^test_.*\\.json$"), false);
+ FileHelper.deleteFiles(folder.getRoot().toPath(), Duration.ZERO, Optional.of("^test_.*\\.json$"), false);
// 6 test_*.json from test_folder1/
// + 9 test_*.json and 4 abc_*.json from test_folder2/
@@ -107,7 +107,7 @@ public class DeleteOldAppDataTest {
@Test
public void testDeleteWithSubDirectoriesRecursive() throws IOException {
initSubDirectories();
- DeleteOldAppData.deleteFiles(folder.getRoot().toPath(), Duration.ZERO, Optional.of("^test_.*\\.json$"), true);
+ FileHelper.deleteFiles(folder.getRoot().toPath(), Duration.ZERO, Optional.of("^test_.*\\.json$"), true);
// 4 abc_*.json from test_folder2/
// + 7 test_*_file.test and 5 *-abc.json and 1 week_old_file from root
@@ -119,7 +119,7 @@ public class DeleteOldAppDataTest {
public void testDeleteFilesWhereFilenameRegexAlsoMatchesDirectories() throws IOException {
initSubDirectories();
- DeleteOldAppData.deleteFiles(folder.getRoot().toPath(), Duration.ZERO, Optional.of("^test_"), false);
+ FileHelper.deleteFiles(folder.getRoot().toPath(), Duration.ZERO, Optional.of("^test_"), false);
assertEquals(8, getContentsOfDirectory(folder.getRoot()).length); // 5 abc files + 1 week_old_file + 2 directories
}
@@ -127,17 +127,17 @@ public class DeleteOldAppDataTest {
@Test
public void testGetContentsOfNonExistingDirectory() throws IOException {
Path fakePath = Paths.get("/some/made/up/dir/");
- assertEquals(Collections.emptyList(), DeleteOldAppData.listContentsOfDirectory(fakePath));
+ assertEquals(Collections.emptyList(), FileHelper.listContentsOfDirectory(fakePath));
}
@Test(expected=IllegalArgumentException.class)
public void testDeleteFilesExceptNMostRecentWithNegativeN() throws IOException {
- DeleteOldAppData.deleteFilesExceptNMostRecent(folder.getRoot().toPath(), -5);
+ FileHelper.deleteFilesExceptNMostRecent(folder.getRoot().toPath(), -5);
}
@Test
public void testDeleteFilesExceptFiveMostRecent() throws IOException {
- DeleteOldAppData.deleteFilesExceptNMostRecent(folder.getRoot().toPath(), 5);
+ FileHelper.deleteFilesExceptNMostRecent(folder.getRoot().toPath(), 5);
assertEquals(5, getContentsOfDirectory(folder.getRoot()).length);
@@ -154,7 +154,7 @@ public class DeleteOldAppDataTest {
public void testDeleteFilesExceptNMostRecentWithLargeN() throws IOException {
String[] filesPreDelete = folder.getRoot().list();
- DeleteOldAppData.deleteFilesExceptNMostRecent(folder.getRoot().toPath(), 50);
+ FileHelper.deleteFilesExceptNMostRecent(folder.getRoot().toPath(), 50);
assertArrayEquals(filesPreDelete, folder.getRoot().list());
}
@@ -172,7 +172,7 @@ public class DeleteOldAppDataTest {
File temp3 = new File(folder.getRoot(), "test_folder1/some_other_file");
writeNBytesToFile(temp3, 75);
- DeleteOldAppData.deleteFilesLargerThan(folder.getRoot().toPath(), 10);
+ FileHelper.deleteFilesLargerThan(folder.getRoot().toPath(), 10);
assertEquals(58, getNumberOfFilesAndDirectoriesIn(folder.getRoot()));
assertFalse(temp1.exists() || temp2.exists() || temp3.exists());
@@ -182,7 +182,7 @@ public class DeleteOldAppDataTest {
public void testDeleteDirectories() throws IOException {
initSubDirectories();
- DeleteOldAppData.deleteDirectories(folder.getRoot().toPath(), Duration.ZERO, Optional.of(".*folder2"));
+ FileHelper.deleteDirectories(folder.getRoot().toPath(), Duration.ZERO, Optional.of(".*folder2"));
//23 files in root
// + 6 in test_folder1 + test_folder1 itself
@@ -193,7 +193,7 @@ public class DeleteOldAppDataTest {
public void testDeleteDirectoriesBasedOnAge() throws IOException {
initSubDirectories();
- DeleteOldAppData.deleteDirectories(folder.getRoot().toPath(), Duration.ofSeconds(50), Optional.of(".*folder.*"));
+ FileHelper.deleteDirectories(folder.getRoot().toPath(), Duration.ofSeconds(50), Optional.of(".*folder.*"));
//23 files in root
// + 13 in test_folder2
@@ -205,7 +205,7 @@ public class DeleteOldAppDataTest {
@Test
public void testRecursivelyDeleteDirectory() throws IOException {
initSubDirectories();
- DeleteOldAppData.recursiveDelete(folder.getRoot().toPath());
+ FileHelper.recursiveDelete(folder.getRoot().toPath());
assertFalse(folder.getRoot().exists());
}
@@ -214,7 +214,7 @@ public class DeleteOldAppDataTest {
File file = folder.newFile();
assertTrue(file.exists());
assertTrue(file.isFile());
- DeleteOldAppData.recursiveDelete(file.toPath());
+ FileHelper.recursiveDelete(file.toPath());
assertFalse(file.exists());
}
@@ -222,7 +222,7 @@ public class DeleteOldAppDataTest {
public void testRecursivelyDeleteNonExistingFile() throws IOException {
File file = folder.getRoot().toPath().resolve("non-existing-file.json").toFile();
assertFalse(file.exists());
- DeleteOldAppData.recursiveDelete(file.toPath());
+ FileHelper.recursiveDelete(file.toPath());
assertFalse(file.exists());
}