From 9dfbaadad1aa134925973a38ab165e9c51c41c73 Mon Sep 17 00:00:00 2001 From: RPKI Team at RIPE NCC Date: Mon, 14 Oct 2024 12:48:10 +0000 Subject: [PATCH] RIPE NCC has merged c7221e69c * Fix typo [01a7e298b] * Report lastUpdated in more cases [5ec659a0d] * Update dependency io.freefair.lombok:io.freefair.lombok.gradle.plugin to v8.10.2 [6e6bd7f80] --- buildSrc/build.gradle | 2 +- .../ripe/rpki/rest/service/AnnouncementService.java | 13 ++++++++++--- .../rpki/rest/service/AnnouncementServiceTest.java | 6 ++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index f514c7e..828c3c0 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -9,7 +9,7 @@ repositories { } dependencies { - implementation 'io.freefair.lombok:io.freefair.lombok.gradle.plugin:8.10' + implementation 'io.freefair.lombok:io.freefair.lombok.gradle.plugin:8.10.2' implementation('com.gorylenko.gradle-git-properties:com.gorylenko.gradle-git-properties.gradle.plugin:2.4.2') { exclude group: 'org.eclipse.jgit', module: 'org.eclipse.jgit' } diff --git a/src/main/java/net/ripe/rpki/rest/service/AnnouncementService.java b/src/main/java/net/ripe/rpki/rest/service/AnnouncementService.java index 50687c1..1157b00 100644 --- a/src/main/java/net/ripe/rpki/rest/service/AnnouncementService.java +++ b/src/main/java/net/ripe/rpki/rest/service/AnnouncementService.java @@ -43,6 +43,7 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -114,13 +115,18 @@ private AnnouncementResponse getAnnouncements(CaName caName) { ).toList(); Instant risLastUpdated = bgpRisEntryViewService.getLastUpdated(); + Function reportProblem = + problem -> risLastUpdated == null ? + new AnnouncementResponse.Problem(problem) : + new AnnouncementResponse.ProblemWithTimestamp(problem, risLastUpdated); + if (certifiedResources.isEmpty()) - return new AnnouncementResponse.Problem(NO_CA_RESOURCES); + return reportProblem.apply(NO_CA_RESOURCES); else if (risLastUpdated == null) - return new AnnouncementResponse.Problem(NO_RIS_UPDATES); + return reportProblem.apply(NO_RIS_UPDATES); else if (!announcements.isEmpty() && announcements.values().stream().allMatch(Collection::isEmpty)) - return new AnnouncementResponse.Problem(NO_OVERLAP_WITH_RIS); + return reportProblem.apply(NO_OVERLAP_WITH_RIS); var announcement = Stream.concat(announcedAnnouncements.stream(), notSeenAnnouncements.stream()).toList(); return new AnnouncementResponse.Announcements(announcement, risLastUpdated); @@ -191,6 +197,7 @@ public ResponseEntity> getAffectedAnnouncementsForCaAndRoa public interface AnnouncementResponse { record Problem(String emptyAnnouncementsReason) implements AnnouncementResponse {} + record ProblemWithTimestamp(String emptyAnnouncementsReason, Instant lastUpdated) implements AnnouncementResponse {} record Announcements(List announcements, Instant lastUpdated) implements AnnouncementResponse { } diff --git a/src/test/java/net/ripe/rpki/rest/service/AnnouncementServiceTest.java b/src/test/java/net/ripe/rpki/rest/service/AnnouncementServiceTest.java index a226e4a..4dc580e 100644 --- a/src/test/java/net/ripe/rpki/rest/service/AnnouncementServiceTest.java +++ b/src/test/java/net/ripe/rpki/rest/service/AnnouncementServiceTest.java @@ -192,7 +192,8 @@ public void announcements_shouldGetAnnouncementNoOverlapsBetweenRisAndResources( bgpRisEntries.put(true, Collections.emptyList()); when(bgpRisEntryViewService.findMostSpecificContainedAndNotContained(ipResourceSet)).thenReturn(bgpRisEntries); - when(bgpRisEntryViewService.getLastUpdated()).thenReturn(Instant.now()); + Instant now = Instant.now(); + when(bgpRisEntryViewService.getLastUpdated()).thenReturn(now); when(roaService.getRoaConfiguration(CA_ID)).thenReturn(new RoaConfigurationData(new ArrayList<>())); @@ -203,7 +204,8 @@ public void announcements_shouldGetAnnouncementNoOverlapsBetweenRisAndResources( ) .andExpect(status().isOk()) .andExpect(content().contentType(APPLICATION_JSON)) - .andExpect(jsonPath("$.emptyAnnouncementsReason").value(AnnouncementService.NO_OVERLAP_WITH_RIS)); + .andExpect(jsonPath("$.emptyAnnouncementsReason").value(AnnouncementService.NO_OVERLAP_WITH_RIS)) + .andExpect(jsonPath("$.lastUpdated").value(now.toString())); } @Test