diff options
Diffstat (limited to 'controlloop/common/eventmanager')
7 files changed, 150 insertions, 83 deletions
diff --git a/controlloop/common/eventmanager/pom.xml b/controlloop/common/eventmanager/pom.xml index 00e3c79df..aa4f8e8bb 100644 --- a/controlloop/common/eventmanager/pom.xml +++ b/controlloop/common/eventmanager/pom.xml @@ -105,11 +105,6 @@ </dependency> <dependency> <groupId>org.onap.policy.drools-applications.controlloop.common</groupId> - <artifactId>database</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onap.policy.drools-applications.controlloop.common</groupId> <artifactId>guard</artifactId> <version>${project.version}</version> <scope>provided</scope> @@ -134,6 +129,11 @@ </dependency> <dependency> <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> + <artifactId>guard</artifactId> + <version>${policy.models.version}</version> + </dependency> + <dependency> + <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> <artifactId>vfc</artifactId> <version>${policy.models.version}</version> <scope>provided</scope> 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" /> diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java index be8b70b13..90fdccabb 100644 --- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java +++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java @@ -70,6 +70,9 @@ import org.onap.policy.controlloop.policy.Policy; import org.onap.policy.controlloop.policy.PolicyResult; import org.onap.policy.controlloop.policy.Target; import org.onap.policy.controlloop.policy.TargetType; +import org.onap.policy.sdnr.PciBody; +import org.onap.policy.sdnr.PciMessage; +import org.onap.policy.sdnr.PciResponse; public class ControlLoopOperationManager2Test { private static final UUID REQ_ID = UUID.randomUUID(); @@ -240,7 +243,7 @@ public class ControlLoopOperationManager2Test { } /** - * Tests start() when the control loop times out. + * Tests start() when the control loop times out before the operation starts. */ @Test public void testStartClTimeout_testHandleTimeout() throws InterruptedException { @@ -276,8 +279,8 @@ public class ControlLoopOperationManager2Test { // should have called update() for operation-start, but not for any nextStep() verify(mgrctx).updated(mgr); - // should not have tried to store anything in the DB - verify(dataMgr, never()).store(any(), any(), any(), any()); + // should have added a record to the DB + verify(dataMgr).store(any(), any(), any(), any()); } @Test @@ -345,12 +348,21 @@ public class ControlLoopOperationManager2Test { @Test public void testMakeControlLoopResponse() { - // should always return its input, if non-null - ControlLoopResponse resp = new ControlLoopResponse(); - assertSame(resp, mgr.makeControlLoopResponse(resp)); + final OperationOutcome outcome = new OperationOutcome(); + PciMessage msg = new PciMessage(); + outcome.setResponse(msg); + + PciBody body = new PciBody(); + msg.setBody(body); + + PciResponse output = new PciResponse(); + body.setOutput(output); + + output.setPayload("my-payload"); + // not an SDNR action - should return null - assertNull(mgr.makeControlLoopResponse(null)); + assertNull(mgr.makeControlLoopResponse(outcome)); /* * now work with SDNR actor @@ -358,15 +370,26 @@ public class ControlLoopOperationManager2Test { policy.setActor("SDNR"); mgr = new ControlLoopOperationManager2(mgrctx, context, policy, executor); - // should still return its input, if non-null - resp = new ControlLoopResponse(); - assertSame(resp, mgr.makeControlLoopResponse(resp)); + // should return null for a null input + assertNull(mgr.makeControlLoopResponse(null)); - // should generate a response - resp = mgr.makeControlLoopResponse(null); - assertNotNull(resp); - assertEquals(REQ_ID, resp.getRequestId()); - assertNull(resp.getPayload()); + // should generate a response, with a payload + checkResp(outcome, "my-payload"); + + /* + * these should generate a response, with null payload + */ + output.setPayload(null); + checkResp(outcome, null); + + body.setOutput(null); + checkResp(outcome, null); + + msg.setBody(null); + checkResp(outcome, null); + + outcome.setResponse(null); + checkResp(outcome, null); } @Test @@ -977,6 +1000,13 @@ public class ControlLoopOperationManager2Test { target.setType(TargetType.VNF); } + private void checkResp(OperationOutcome outcome, String expectedPayload) { + ControlLoopResponse resp = mgr.makeControlLoopResponse(outcome); + assertNotNull(resp); + assertEquals(REQ_ID, resp.getRequestId()); + assertEquals(expectedPayload, resp.getPayload()); + } + private void verifyDb(int nrecords, PolicyResult expectedResult, String expectedMsg) { ArgumentCaptor<String> entityCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor<ControlLoopOperation> opCaptor = ArgumentCaptor.forClass(ControlLoopOperation.class); diff --git a/controlloop/common/eventmanager/src/test/resources/META-INF/persistence.xml b/controlloop/common/eventmanager/src/test/resources/META-INF/persistence.xml index 4d47751bf..917f8aad3 100644 --- a/controlloop/common/eventmanager/src/test/resources/META-INF/persistence.xml +++ b/controlloop/common/eventmanager/src/test/resources/META-INF/persistence.xml @@ -1,43 +1,43 @@ -<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ============LICENSE_START=======================================================
- drools-applications
- ================================================================================
- Copyright (C) 2018-2019 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.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- ============LICENSE_END=========================================================
- -->
-<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence_1_0.xsd" version="1.0">
-
- <!-- In-mem DB for junit -->
- <persistence-unit name="OperationsHistoryPUTest" transaction-type="RESOURCE_LOCAL">
- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
-
- <class>org.onap.policy.database.operationshistory.Dbao</class>
-
- <properties>
- <property name="eclipselink.ddl-generation" value="create-tables" />
- <property name="eclipselink.logging.level" value="INFO" />
- <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
- <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
- <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:testdb;DATABASE_TO_UPPER=FALSE" />
- <property name="javax.persistence.jdbc.user" value="policy" />
- <property name="javax.persistence.jdbc.password" value="P01icY" />
- <property name="javax.persistence.schema-generation.database.action" value="drop-and-create" />
- <property name="javax.persistence.schema-generation.create-source" value="metadata" />
- </properties>
- </persistence-unit>
-
-</persistence>
+<?xml version="1.0" encoding="UTF-8"?> +<!-- + ============LICENSE_START======================================================= + drools-applications + ================================================================================ + 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. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= + --> +<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence_1_0.xsd" version="1.0"> + + <!-- In-mem DB for junit --> + <persistence-unit name="OperationsHistoryPUTest" transaction-type="RESOURCE_LOCAL"> + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> + + <class>org.onap.policy.guard.OperationsHistory</class> + + <properties> + <property name="eclipselink.ddl-generation" value="create-tables" /> + <property name="eclipselink.logging.level" value="INFO" /> + <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" /> + <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" /> + <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:testdb;DATABASE_TO_UPPER=FALSE" /> + <property name="javax.persistence.jdbc.user" value="policy" /> + <property name="javax.persistence.jdbc.password" value="P01icY" /> + <property name="javax.persistence.schema-generation.database.action" value="drop-and-create" /> + <property name="javax.persistence.schema-generation.create-source" value="metadata" /> + </properties> + </persistence-unit> + +</persistence> |