From dbecba3a4baffacf9f2da82592b3e3a9e2929f21 Mon Sep 17 00:00:00 2001 From: Saravanan A Date: Mon, 10 Sep 2018 17:31:33 +0530 Subject: Add implementation for OOF PCI use case Receive DMaaP message from PCI-Handler MS with PCI Config change recommendations through DCAE_CL_OUTPUT topic. Trigger SDN-R (if allowed by policy) by sending DMaaP request through SDNR-CL topic. When the response is received from SDNR through SDNR-CL-RSP topic, just parse and print. Code review comments addressed Change-Id: If340a23ae18367b7f98e31fe79c09a09e645b2ad Issue-ID: POLICY-1089 Signed-off-by: Saravanan A --- .../eventmanager/ControlLoopOperationManager.java | 59 +++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) (limited to 'controlloop/common/eventmanager/src/main') diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java index f1d912ef5..1ad1e5af7 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java @@ -26,8 +26,8 @@ import java.time.Instant; import java.util.AbstractMap; import java.util.LinkedList; import java.util.List; -import java.util.Properties; import java.util.NoSuchElementException; +import java.util.Properties; import javax.persistence.EntityManager; import javax.persistence.Persistence; @@ -43,12 +43,14 @@ import org.onap.policy.controlloop.ControlLoopOperation; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.actor.appc.APPCActorServiceProvider; import org.onap.policy.controlloop.actor.appclcm.AppcLcmActorServiceProvider; +import org.onap.policy.controlloop.actor.sdnr.SdnrActorServiceProvider; import org.onap.policy.controlloop.actor.so.SOActorServiceProvider; import org.onap.policy.controlloop.actor.vfc.VFCActorServiceProvider; import org.onap.policy.controlloop.policy.Policy; import org.onap.policy.controlloop.policy.PolicyResult; import org.onap.policy.drools.system.PolicyEngine; import org.onap.policy.guard.Util; +import org.onap.policy.sdnr.PciResponseWrapper; import org.onap.policy.so.SOResponseWrapper; import org.onap.policy.vfc.VFCResponse; import org.slf4j.Logger; @@ -214,6 +216,8 @@ public class ControlLoopOperationManager implements Serializable { break; case "SO": break; + case "SDNR": + break; case "VFC": break; default: @@ -283,6 +287,21 @@ public class ControlLoopOperationManager implements Serializable { if (this.operationRequest == null) { this.policyResult = PolicyResult.FAILURE; } + return operationRequest; + case "SDNR": + /* + * If the recipe is ModifyConfig, a SDNR request is constructed. + */ + this.currentOperation = operation; + this.operationRequest = SdnrActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset, + operation.clOperation, this.policy); + // + // Save the operation + // + if (this.operationRequest == null) { + this.policyResult = PolicyResult.FAILURE; + } + return operationRequest; default: throw new ControlLoopException("invalid actor " + policy.getActor() + " on policy"); @@ -309,6 +328,11 @@ public class ControlLoopOperationManager implements Serializable { // Cast LCM response and handle it // return onResponse((LcmResponseWrapper) response); + } else if (response instanceof PciResponseWrapper) { + // + // Cast SDNR response and handle it + // + return onResponse((PciResponseWrapper) response); } else if (response instanceof SOResponseWrapper) { // // Cast SO response and handle it @@ -450,6 +474,39 @@ public class ControlLoopOperationManager implements Serializable { return null; } + /** + * This method handles operation responses from SDNR. + * + * @param dmaapResponse the SDNR response + * @return the result of the response handling + */ + private PolicyResult onResponse(PciResponseWrapper dmaapResponse) { + /* + * Parse out the operation attempt using the subrequestid + */ + Integer operationAttempt = SdnrActorServiceProvider + .parseOperationAttempt(dmaapResponse.getBody().getCommonHeader().getSubRequestId()); + if (operationAttempt == null) { + this.completeOperation(operationAttempt, "Policy was unable to parse SDNR SubRequestID.", + PolicyResult.FAILURE_EXCEPTION); + } + + /* + * Process the SDNR response to see what PolicyResult should be returned + */ + SdnrActorServiceProvider.Pair result = + SdnrActorServiceProvider.processResponse(dmaapResponse); + + if (result.getResult() != null) { + this.completeOperation(operationAttempt, result.getMessage(), result.getResult()); + if (PolicyResult.FAILURE_TIMEOUT.equals(this.policyResult)) { + return null; + } + return result.getResult(); + } + return null; + } + /** * This method handles operation responses from SO. * -- cgit 1.2.3-korg