Skip to content

Commit 6a41f57

Browse files
committed
Fix getCases() for S3
Signed-off-by: Etienne Homer <etiennehomer@gmail.com>
1 parent 8bd6eca commit 6a41f57

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/main/java/com/powsybl/caseserver/service/FsCaseService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ String getFormat(Path caseFile) {
100100
public List<CaseInfos> getCases() {
101101
try (Stream<Path> walk = Files.walk(getStorageRootDir())) {
102102
return walk.filter(Files::isRegularFile)
103-
.map(this::getCaseInfosOrNull)
103+
.map(this::getCaseInfoSafely)
104104
.filter(Objects::nonNull)
105105
.toList();
106106
} catch (IOException e) {
@@ -113,7 +113,7 @@ private CaseInfos getCaseInfos(Path file) {
113113
return removeGzipExtensionFromPlainFile(caseInfos);
114114
}
115115

116-
private CaseInfos getCaseInfosOrNull(Path file) {
116+
private CaseInfos getCaseInfoSafely(Path file) {
117117
Objects.requireNonNull(file);
118118
try {
119119
return getCaseInfos(file);

src/main/java/com/powsybl/caseserver/service/S3CaseService.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,25 @@ public List<CaseInfos> getCases() {
270270
List<CaseInfos> caseInfosList = new ArrayList<>();
271271
CaseInfos caseInfos;
272272
for (S3Object o : getCaseS3Objects(rootDirectory + DELIMITER)) {
273-
caseInfos = getCaseInfos(parseUuidFromKey(o.key()));
273+
caseInfos = getCaseInfoSafely(parseUuidFromKey(o.key()));
274274
if (Objects.nonNull(caseInfos)) {
275275
caseInfosList.add(caseInfos);
276276
}
277277
}
278278
return caseInfosList;
279279
}
280280

281+
private CaseInfos getCaseInfoSafely(UUID uuid) {
282+
Objects.requireNonNull(uuid);
283+
try {
284+
return getCaseInfos(uuid);
285+
} catch (Exception e) {
286+
// This method is called by getCases() that is a method for supervision and administration. We do not want the request to stop and fail on error cases.
287+
LOGGER.error("Error processing case with uuid {}: {}", uuid, e.getMessage(), e);
288+
return null;
289+
}
290+
}
291+
281292
@Override
282293
public boolean caseExists(UUID uuid) {
283294
return !getCaseS3Objects(uuid).isEmpty();

0 commit comments

Comments
 (0)