From 6beb3433c4598a9836e8ac3288f55d92097bd627 Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Fri, 28 Oct 2022 13:49:36 +0200 Subject: Better error handling if both schemas/ and searchdefintions/ exist If something fails when having both directories, throw an InvalidApplicationException with an explanation about what to do --- .../config/server/session/SessionRepository.java | 25 +++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'configserver') 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 89ca0265008..49678c5e385 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 @@ -841,15 +841,24 @@ public class SessionRepository { File schemasDir = applicationDir.resolve(ApplicationPackage.SCHEMAS_DIR.getRelative()).toFile(); File sdDir = applicationDir.resolve(ApplicationPackage.SEARCH_DEFINITIONS_DIR.getRelative()).toFile(); if (sdDir.exists() && sdDir.isDirectory()) { - File[] sdFiles = sdDir.listFiles(); - if (sdFiles != null) { - Files.createDirectories(schemasDir.toPath()); - Arrays.asList(sdFiles).forEach(file -> Exceptions.uncheck( - () -> Files.move(file.toPath(), - schemasDir.toPath().resolve(file.toPath().getFileName()), - StandardCopyOption.REPLACE_EXISTING))); + try { + File[] sdFiles = sdDir.listFiles(); + if (sdFiles != null) { + Files.createDirectories(schemasDir.toPath()); + Arrays.asList(sdFiles).forEach(file -> Exceptions.uncheck( + () -> Files.move(file.toPath(), + schemasDir.toPath().resolve(file.toPath().getFileName()), + StandardCopyOption.REPLACE_EXISTING))); + } + Files.delete(sdDir.toPath()); + } catch (IOException | UncheckedIOException e) { + if (schemasDir.exists() && schemasDir.isDirectory()) + throw new InvalidApplicationException( + "Both " + ApplicationPackage.SCHEMAS_DIR.getRelative() + " and " + ApplicationPackage.SEARCH_DEFINITIONS_DIR + + " exists in application package, please remove " + ApplicationPackage.SEARCH_DEFINITIONS_DIR, e); + else + throw e; } - Files.delete(sdDir.toPath()); } } -- cgit v1.2.3 From 26eb6c17a2a253de73c181949627fdabb7b23061 Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Fri, 28 Oct 2022 14:26:27 +0200 Subject: Minor change to exception message --- .../java/com/yahoo/vespa/config/server/session/SessionRepository.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'configserver') 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 49678c5e385..b36e8d2d37c 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 @@ -854,8 +854,8 @@ public class SessionRepository { } catch (IOException | UncheckedIOException e) { if (schemasDir.exists() && schemasDir.isDirectory()) throw new InvalidApplicationException( - "Both " + ApplicationPackage.SCHEMAS_DIR.getRelative() + " and " + ApplicationPackage.SEARCH_DEFINITIONS_DIR + - " exists in application package, please remove " + ApplicationPackage.SEARCH_DEFINITIONS_DIR, e); + "Both " + ApplicationPackage.SCHEMAS_DIR.getRelative() + "/ and " + ApplicationPackage.SEARCH_DEFINITIONS_DIR + + "/ exist in application package, please remove " + ApplicationPackage.SEARCH_DEFINITIONS_DIR + "/", e); else throw e; } -- cgit v1.2.3