Code Review
/
nonrtric.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Merge "Remove code smells in dashboard"
[nonrtric.git]
/
policy-agent
/
src
/
main
/
java
/
org
/
oransc
/
policyagent
/
dmaap
/
DmaapMessageHandler.java
diff --git
a/policy-agent/src/main/java/org/oransc/policyagent/dmaap/DmaapMessageHandler.java
b/policy-agent/src/main/java/org/oransc/policyagent/dmaap/DmaapMessageHandler.java
index
9b0c809
..
b23595a
100644
(file)
--- a/
policy-agent/src/main/java/org/oransc/policyagent/dmaap/DmaapMessageHandler.java
+++ b/
policy-agent/src/main/java/org/oransc/policyagent/dmaap/DmaapMessageHandler.java
@@
-2,7
+2,7
@@
* ========================LICENSE_START=================================
* O-RAN-SC
* %%
* ========================LICENSE_START=================================
* O-RAN-SC
* %%
- * Copyright (C) 20
19
Nordix Foundation
+ * Copyright (C) 20
20
Nordix Foundation
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@
-27,7
+27,6
@@
import java.io.IOException;
import org.onap.dmaap.mr.client.MRBatchingPublisher;
import org.oransc.policyagent.clients.AsyncRestClient;
import org.onap.dmaap.mr.client.MRBatchingPublisher;
import org.oransc.policyagent.clients.AsyncRestClient;
-import org.oransc.policyagent.configuration.ApplicationConfig;
import org.oransc.policyagent.dmaap.DmaapRequestMessage.Operation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.oransc.policyagent.dmaap.DmaapRequestMessage.Operation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@
-39,21
+38,19
@@
public class DmaapMessageHandler {
private static final Logger logger = LoggerFactory.getLogger(DmaapMessageHandler.class);
private static Gson gson = new GsonBuilder() //
private static final Logger logger = LoggerFactory.getLogger(DmaapMessageHandler.class);
private static Gson gson = new GsonBuilder() //
- .serializeNulls() //
.create(); //
private final MRBatchingPublisher dmaapClient;
private final AsyncRestClient agentClient;
.create(); //
private final MRBatchingPublisher dmaapClient;
private final AsyncRestClient agentClient;
- public DmaapMessageHandler(MRBatchingPublisher dmaapClient, ApplicationConfig applicationConfig,
- AsyncRestClient agentClient) {
+ public DmaapMessageHandler(MRBatchingPublisher dmaapClient, AsyncRestClient agentClient) {
this.agentClient = agentClient;
this.dmaapClient = dmaapClient;
}
public void handleDmaapMsg(String msg) {
this.createTask(msg) //
this.agentClient = agentClient;
this.dmaapClient = dmaapClient;
}
public void handleDmaapMsg(String msg) {
this.createTask(msg) //
- .subscribe(
x -> logger.debug("handleDmaapMsg: " + x
), //
+ .subscribe(
message -> logger.debug("handleDmaapMsg: {}", message
), //
throwable -> logger.warn("handleDmaapMsg failure ", throwable), //
() -> logger.debug("handleDmaapMsg complete"));
}
throwable -> logger.warn("handleDmaapMsg failure ", throwable), //
() -> logger.debug("handleDmaapMsg complete"));
}
@@
-73,9
+70,9
@@
public class DmaapMessageHandler {
}
private Mono<String> handleAgentCallError(Throwable t, DmaapRequestMessage dmaapRequestMessage) {
}
private Mono<String> handleAgentCallError(Throwable t, DmaapRequestMessage dmaapRequestMessage) {
- logger.debug("Agent call failed:
" +
t.getMessage());
+ logger.debug("Agent call failed:
{}",
t.getMessage());
return sendDmaapResponse(t.toString(), dmaapRequestMessage, HttpStatus.NOT_FOUND) //
return sendDmaapResponse(t.toString(), dmaapRequestMessage, HttpStatus.NOT_FOUND) //
- .flatMap(
s
-> Mono.empty());
+ .flatMap(
notUsed
-> Mono.empty());
}
private Mono<String> invokePolicyAgent(DmaapRequestMessage dmaapRequestMessage) {
}
private Mono<String> invokePolicyAgent(DmaapRequestMessage dmaapRequestMessage) {
@@
-87,20
+84,29
@@
public class DmaapMessageHandler {
} else if (operation == Operation.GET) {
result = agentClient.get(uri);
} else if (operation == Operation.PUT) {
} else if (operation == Operation.GET) {
result = agentClient.get(uri);
} else if (operation == Operation.PUT) {
- result = agentClient.put(uri,
dmaapRequestMessage.payload(
));
+ result = agentClient.put(uri,
payload(dmaapRequestMessage
));
} else if (operation == Operation.POST) {
} else if (operation == Operation.POST) {
- result = agentClient.post(uri,
dmaapRequestMessage.payload(
));
+ result = agentClient.post(uri,
payload(dmaapRequestMessage
));
} else {
return Mono.error(new Exception("Not implemented operation: " + operation));
}
return result;
}
} else {
return Mono.error(new Exception("Not implemented operation: " + operation));
}
return result;
}
+ private String payload(DmaapRequestMessage message) {
+ if (message.payload().isPresent()) {
+ return gson.toJson(message.payload().get());
+ } else {
+ logger.warn("Expected payload in message from DMAAP: {}", message);
+ return "";
+ }
+ }
+
private Mono<String> sendDmaapResponse(String response, DmaapRequestMessage dmaapRequestMessage,
HttpStatus status) {
return getDmaapResponseMessage(dmaapRequestMessage, response, status) //
private Mono<String> sendDmaapResponse(String response, DmaapRequestMessage dmaapRequestMessage,
HttpStatus status) {
return getDmaapResponseMessage(dmaapRequestMessage, response, status) //
- .flatMap(
body -> sendToDmaap(body)
) //
- .onErrorResume(t
-> handleResponseCallError(t, dmaapRequestMessage)
);
+ .flatMap(
this::sendToDmaap
) //
+ .onErrorResume(t
his::handleResponseCallError
);
}
private Mono<String> sendToDmaap(String body) {
}
private Mono<String> sendToDmaap(String body) {
@@
-114,8
+120,8
@@
public class DmaapMessageHandler {
}
}
}
}
- private Mono<String> handleResponseCallError(Throwable t
, DmaapRequestMessage dmaapRequestMessage
) {
- logger.debug("Failed to respond:
" +
t.getMessage());
+ private Mono<String> handleResponseCallError(Throwable t) {
+ logger.debug("Failed to respond:
{}",
t.getMessage());
return Mono.empty();
}
return Mono.empty();
}
@@
-135,5
+141,4
@@
public class DmaapMessageHandler {
return Mono.just(str);
}
return Mono.just(str);
}
-
}
}