Skip to content

Commit a8f47dc

Browse files
committed
chore: add warning message in case failed to retrieve TC recommendations
Signed-off-by: Zvi Grinberg <[email protected]>
1 parent f71b792 commit a8f47dc

File tree

5 files changed

+32
-21
lines changed

5 files changed

+32
-21
lines changed

src/main/java/com/redhat/exhort/integration/backend/ExhortIntegration.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,15 @@
2525
import java.io.InputStream;
2626
import java.util.Arrays;
2727

28-
import com.redhat.exhort.integration.trustedcontent.TcResponseHandler;
29-
import org.apache.camel.AggregationStrategy;
3028
import org.apache.camel.Exchange;
3129
import org.apache.camel.LoggingLevel;
3230
import org.apache.camel.builder.AggregationStrategies;
3331
import org.apache.camel.builder.endpoint.EndpointRouteBuilder;
3432
import org.apache.camel.component.micrometer.MicrometerConstants;
3533
import org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicyFactory;
3634

37-
import com.fasterxml.jackson.databind.ObjectMapper;
3835
import com.redhat.exhort.analytics.AnalyticsService;
3936
import com.redhat.exhort.integration.Constants;
40-
import com.redhat.exhort.integration.VulnerabilityProvider;
4137
import com.redhat.exhort.integration.backend.sbom.SbomParserFactory;
4238
import com.redhat.exhort.integration.providers.ProviderAggregationStrategy;
4339
import com.redhat.exhort.integration.providers.VulnerabilityProvider;
@@ -64,7 +60,7 @@ public class ExhortIntegration extends EndpointRouteBuilder {
6460

6561
@Inject AnalyticsService analytics;
6662

67-
@Inject ObjectMapper mapper;
63+
// @Inject ObjectMapper mapper;
6864

6965
@Inject MonitoringProcessor monitoringProcessor;
7066

src/main/java/com/redhat/exhort/integration/trustedcontent/TcResponseHandler.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,17 @@ public class TcResponseHandler {
3333

3434
// ObjectMapper mapper = ObjectMapperProducer.newInstance();
3535

36-
public Map<String, String> responseToMap(@Body Map<String, Map<String,List>> tcResponse) throws IOException {
36+
public Map<String, String> responseToMap(@Body Map<String, Map<String, List>> tcResponse)
37+
throws IOException {
3738
HashMap<String, String> recommendations = new HashMap<>();
3839

3940
Map<String, List> rec = (Map<String, List>) tcResponse.get("recommendations");
4041
rec.entrySet().stream()
4142
.forEach(
4243
(entry) -> {
43-
recommendations.put(entry.getKey(), (String)((Map)entry.getValue().stream().findFirst().get()).get("package"));
44+
recommendations.put(
45+
entry.getKey(),
46+
(String) ((Map) entry.getValue().stream().findFirst().get()).get("package"));
4447
});
4548

4649
return recommendations;

src/main/java/com/redhat/exhort/integration/trustedcontent/TrustedContentIntegration.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,21 @@
2121
import java.util.*;
2222

2323
import org.apache.camel.Exchange;
24+
import org.apache.camel.LoggingLevel;
2425
import org.apache.camel.builder.endpoint.EndpointRouteBuilder;
26+
import org.apache.camel.model.dataformat.JsonLibrary;
2527

2628
import com.redhat.exhort.api.PackageRef;
2729
import com.redhat.exhort.integration.Constants;
2830
import com.redhat.exhort.model.DependencyTree;
2931

32+
import io.quarkus.runtime.annotations.RegisterForReflection;
33+
3034
import jakarta.enterprise.context.ApplicationScoped;
3135
import jakarta.ws.rs.core.MediaType;
32-
import org.apache.camel.model.dataformat.JsonLibrary;
3336

3437
@ApplicationScoped
38+
@RegisterForReflection
3539
public class TrustedContentIntegration extends EndpointRouteBuilder {
3640

3741
@Override
@@ -59,6 +63,10 @@ public void configure() {
5963
.endCircuitBreaker()
6064
.onFallback()
6165
.setBody(constant(Map.of("recommendations", Map.of())))
66+
.log(
67+
LoggingLevel.WARN,
68+
"Failed to retrieve recommendations from Trusted content service' /recommend endpoint,"
69+
+ " error message => ${exception.message}")
6270
.end();
6371
}
6472

src/test/java/com/redhat/exhort/integration/trustedcontent/TcResponseAggregationTest.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,13 @@ void Check_Integration_With_Empty_Map_Of_Recommendations() {
121121
newMessageWithRecommendations.getMessage().setBody(Map.of());
122122
int hashCodeBefore = analysisReport.hashCode();
123123
Exchange aggregate =
124-
tcResponseAggregation.aggregate(originalMessage, newMessageWithRecommendations);
124+
tcResponseAggregation.aggregate(originalMessage, newMessageWithRecommendations);
125125

126126
int hashCodeAfter = aggregate.getMessage().getBody().hashCode();
127-
//Empty recommendations list must not touch AnalysisReport instance and let it remain the same.
128-
assertEquals(hashCodeBefore,hashCodeAfter);
129-
127+
// Empty recommendations list must not touch AnalysisReport instance and let it remain the same.
128+
assertEquals(hashCodeBefore, hashCodeAfter);
130129
}
131130

132-
133131
@Test
134132
void Check_Integration_With_Map_Of_Recommendations() {
135133
TcResponseAggregation tcResponseAggregation = new TcResponseAggregation();
@@ -145,8 +143,6 @@ void Check_Integration_With_Map_Of_Recommendations() {
145143
AnalysisReport result = (AnalysisReport) aggregate.getMessage().getBody();
146144
Source resultDummySourceRef =
147145
result.getProviders().get("dummy-provider").getSources().get("dummy-source");
148-
assertEquals(5, resultDummySourceRef.getSummary().getDirect());
149-
assertEquals(5, resultDummySourceRef.getSummary().getDependencies());
150146
assertEquals(5, resultDummySourceRef.getSummary().getRecommendations());
151147
assertEquals(
152148
4,
@@ -1041,7 +1037,6 @@ public void setAutowiredEnabled(Boolean autowiredEnabled) {}
10411037
};
10421038
}
10431039

1044-
10451040
private static Issue buildIssue(String id, Float score) {
10461041
return new Issue()
10471042
.id(String.format("ISSUE-00-%s", id))

src/test/java/com/redhat/exhort/integration/trustedcontent/TcResponseHandlerTest.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,22 @@ private static Stream<Arguments> getPayload() {
4343
Map.of(
4444
"pkg:mgr/io.group/[email protected]",
4545
List.of(
46-
Map.of("package","pkg:mgr/io.group/[email protected]" + REDHAT_REPOSITORY_SUFFIX)),
46+
Map.of(
47+
"package",
48+
"pkg:mgr/io.group/[email protected]"
49+
+ REDHAT_REPOSITORY_SUFFIX)),
4750
"pkg:mgr/io.group/[email protected]",
4851
List.of(
49-
Map.of("package","pkg:mgr/io.group/[email protected]" + REDHAT_REPOSITORY_SUFFIX)),
52+
Map.of(
53+
"package",
54+
"pkg:mgr/io.group/[email protected]"
55+
+ REDHAT_REPOSITORY_SUFFIX)),
5056
"pkg:mgr/io.group/[email protected]",
5157
List.of(
52-
Map.of("package","pkg:mgr/io.group/[email protected]" + REDHAT_REPOSITORY_SUFFIX)))
53-
),
58+
Map.of(
59+
"package",
60+
"pkg:mgr/io.group/[email protected]"
61+
+ REDHAT_REPOSITORY_SUFFIX)))),
5462
Map.of(
5563
"pkg:mgr/io.group/[email protected]",
5664
"pkg:mgr/io.group/[email protected]" + REDHAT_REPOSITORY_SUFFIX,
@@ -64,7 +72,8 @@ private static Stream<Arguments> getPayload() {
6472

6573
@ParameterizedTest
6674
@MethodSource("getPayload")
67-
void test_Payload_With_Purls(Map<String, Map<String,List>> input, Map<String, String> expectedOutput) {
75+
void test_Payload_With_Purls(
76+
Map<String, Map<String, List>> input, Map<String, String> expectedOutput) {
6877
TcResponseHandler tcResponseHandler = new TcResponseHandler();
6978
try {
7079
Map<String, String> actualOutput = tcResponseHandler.responseToMap(input);

0 commit comments

Comments
 (0)