diff options
Diffstat (limited to 'controlloop/common/eventmanager/src/main')
4 files changed, 57 insertions, 20 deletions
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 2a5e64d97..d0c19ba67 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 @@ -64,8 +64,8 @@ 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.controlloop.policy.TargetType; -import org.onap.policy.database.operationshistory.Dbao; import org.onap.policy.drools.system.PolicyEngineConstants; +import org.onap.policy.guard.OperationsHistory; import org.onap.policy.guard.Util; import org.onap.policy.sdnc.SdncResponse; import org.onap.policy.sdnr.PciResponseWrapper; @@ -1093,7 +1093,7 @@ public class ControlLoopOperationManager implements Serializable { return; } - Dbao newEntry = new Dbao(); + OperationsHistory newEntry = new OperationsHistory(); newEntry.setClosedLoopName(this.onset.getClosedLoopControlName()); newEntry.setRequestId(this.onset.getRequestId().toString()); diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java index 3f7aca6e0..5141b7100 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java @@ -43,12 +43,15 @@ import org.onap.policy.aai.AaiCqResponse; import org.onap.policy.controlloop.ControlLoopOperation; import org.onap.policy.controlloop.ControlLoopResponse; import org.onap.policy.controlloop.VirtualControlLoopEvent; +import org.onap.policy.controlloop.actor.guard.GuardActorServiceProvider; +import org.onap.policy.controlloop.actor.sdnr.SdnrActorServiceProvider; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.controlloop.actorserviceprovider.pipeline.PipelineUtil; import org.onap.policy.controlloop.policy.Policy; import org.onap.policy.controlloop.policy.PolicyResult; +import org.onap.policy.sdnr.PciMessage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -64,7 +67,7 @@ public class ControlLoopOperationManager2 implements Serializable { private static final String CL_TIMEOUT_ACTOR = "-CL-TIMEOUT-"; public static final String LOCK_ACTOR = "LOCK"; public static final String LOCK_OPERATION = "Lock"; - private static final String GUARD_ACTOR = "GUARD"; + private static final String GUARD_ACTOR = GuardActorServiceProvider.NAME; public static final String VSERVER_VSERVER_NAME = "vserver.vserver-name"; public static final String GENERIC_VNF_VNF_NAME = "generic-vnf.vnf-name"; public static final String GENERIC_VNF_VNF_ID = "generic-vnf.vnf-id"; @@ -212,7 +215,7 @@ public class ControlLoopOperationManager2 implements Serializable { policyResult = outcome.getResult(); clOperation = outcome.toControlLoopOperation(); clOperation.setTarget(policy.getTarget().toString()); - clResponse = outcome.getControlLoopResponse(); + clResponse = makeControlLoopResponse(outcome); if (outcome.getEnd() == null) { clOperation.setOutcome("Started"); @@ -478,6 +481,7 @@ public class ControlLoopOperationManager2 implements Serializable { case CL_TIMEOUT_ACTOR: state = State.CONTROL_LOOP_TIMEOUT; + processAbort(outcome, PolicyResult.FAILURE, "Control loop timed out"); break; case LOCK_ACTOR: @@ -487,7 +491,7 @@ public class ControlLoopOperationManager2 implements Serializable { storeFailureInDataBase(outcome, PolicyResult.FAILURE_GUARD, "Operation denied by Lock"); } else { state = State.LOCK_LOST; - storeFailureInDataBase(outcome, PolicyResult.FAILURE, "Operation aborted by Lock"); + processAbort(outcome, PolicyResult.FAILURE, "Operation aborted by Lock"); } break; @@ -515,7 +519,7 @@ public class ControlLoopOperationManager2 implements Serializable { */ state = (outcome.getResult() == PolicyResult.SUCCESS ? State.OPERATION_SUCCESS : State.OPERATION_FAILURE); - controlLoopResponse = makeControlLoopResponse(outcome.getControlLoopResponse()); + controlLoopResponse = makeControlLoopResponse(outcome); if (!operationHistory.isEmpty() && operationHistory.peekLast().getClOperation().getEnd() == null) { operationHistory.removeLast(); } @@ -531,18 +535,46 @@ public class ControlLoopOperationManager2 implements Serializable { } /** - * Makes a control loop response. + * Processes an operation abort, updating the DB record, if an operation has been + * started. * - * @param source original control loop response or {@code null} - * @return a new control loop response, or {@code null} none is required + * @param outcome operation outcome + * @param result result to put into the DB + * @param message message to put into the DB */ - protected ControlLoopResponse makeControlLoopResponse(ControlLoopResponse source) { - if (source != null) { - return source; + private void processAbort(OperationOutcome outcome, PolicyResult result, String message) { + if (operationHistory.isEmpty() || operationHistory.peekLast().getClOperation().getEnd() != null) { + // last item was not a "start" operation + + // NOTE: do NOT generate control loop response since operation was not started + + storeFailureInDataBase(outcome, result, message); + return; } + // last item was a "start" operation - replace it with a failure + final Operation operOrig = operationHistory.removeLast(); + + // use start time from the operation, itself + if (operOrig != null && operOrig.getClOperation() != null) { + outcome.setStart(operOrig.getClOperation().getStart()); + } + + controlLoopResponse = makeControlLoopResponse(outcome); + + storeFailureInDataBase(outcome, result, message); + } + + /** + * Makes a control loop response. + * + * @param outcome operation outcome + * @return a new control loop response, or {@code null} if none is required + */ + protected ControlLoopResponse makeControlLoopResponse(OperationOutcome outcome) { + // only generate response for certain actors. - if (!actor.equals("SDNR")) { + if (outcome == null || !actor.equals(SdnrActorServiceProvider.NAME)) { return null; } @@ -557,6 +589,11 @@ public class ControlLoopOperationManager2 implements Serializable { clRsp.setRequestId(event.getRequestId()); clRsp.setVersion(event.getVersion()); + PciMessage msg = outcome.getResponse(); + if (msg != null && msg.getBody() != null && msg.getBody().getOutput() != null) { + clRsp.setPayload(msg.getBody().getOutput().getPayload()); + } + return clRsp; } diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java index 2b67865bf..741ce20f8 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java @@ -39,7 +39,7 @@ import org.onap.policy.common.utils.jpa.EntityMgrCloser; import org.onap.policy.common.utils.jpa.EntityTransCloser; import org.onap.policy.controlloop.ControlLoopOperation; import org.onap.policy.controlloop.VirtualControlLoopEvent; -import org.onap.policy.database.operationshistory.Dbao; +import org.onap.policy.guard.OperationsHistory; import org.onap.policy.guard.Util; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -261,15 +261,15 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana logger.info("store operation history record for {}", event.getRequestId()); - List<Dbao> results = - entityMgr.createQuery("select e from Dbao e" + List<OperationsHistory> results = + entityMgr.createQuery("select e from OperationsHistory e" + " where e.closedLoopName= ?1" + " and e.requestId= ?2" + " and e.subrequestId= ?3" + " and e.actor= ?4" + " and e.operation= ?5" + " and e.target= ?6", - Dbao.class) + OperationsHistory.class) .setParameter(1, event.getClosedLoopControlName()) .setParameter(2, record.getRequestId()) .setParameter(3, operation.getSubRequestId()) @@ -282,7 +282,7 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana logger.warn("unexpected operation history record count {} for {}", results.size(), event.getRequestId()); } - Dbao entry = (results.isEmpty() ? new Dbao() : results.get(0)); + OperationsHistory entry = (results.isEmpty() ? new OperationsHistory() : results.get(0)); entry.setClosedLoopName(event.getClosedLoopControlName()); entry.setRequestId(record.getRequestId()); diff --git a/controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml b/controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml index 210e22f27..c3c633674 100644 --- a/controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml +++ b/controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml @@ -3,7 +3,7 @@ ============LICENSE_START======================================================= drools-applications ================================================================================ - Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ transaction-type="RESOURCE_LOCAL"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> - <class>org.onap.policy.database.operationshistory.Dbao</class> + <class>org.onap.policy.guard.OperationsHistory</class> <properties> <property name="eclipselink.ddl-generation" value="create-or-extend-tables" /> |