diff options
author | Jim Hahn <jrh3@att.com> | 2021-04-13 14:22:19 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2021-04-13 14:23:53 -0400 |
commit | 9496f31d3b2a1674f57a0395d050be0d9c6b87f0 (patch) | |
tree | 374fc3402a011573f75e87168d98ec31f2ab1013 /controlloop/common | |
parent | 6a394bb781d6e6216cf6f9ac2d2d8d788f9691ad (diff) |
Make op history classes work with generic events
Issue-ID: POLICY-3198
Change-Id: I5b80d35fbb523094ae5464e9c058fd8f2c71ff50
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'controlloop/common')
7 files changed, 55 insertions, 61 deletions
diff --git a/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManager.java b/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManager.java index 0649f1882..d586240d9 100644 --- a/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManager.java +++ b/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManager.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 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. @@ -550,7 +550,8 @@ public class UsecasesEventManager extends ControlLoopEventManager implements Ste public void storeInDataBase(OperationOutcome2 outcome) { String targetEntity = getProperty(OperationProperties.AAI_TARGET_ENTITY); - getDataManager().store(requestIdStr, event, targetEntity, outcome.getClOperation()); + getDataManager().store(requestIdStr, event.getClosedLoopControlName(), event, targetEntity, + outcome.getClOperation()); } /** diff --git a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManagerTest.java b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManagerTest.java index 98758f4da..7160f372f 100644 --- a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManagerTest.java +++ b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManagerTest.java @@ -523,10 +523,9 @@ public class UsecasesEventManagerTest { */ @Test public void testLoadPreprocessorStepsNeedTargetEntity() { - stepa = new Step2(mgr, - ControlLoopOperationParams.builder() - .targetType(TargetType.toTargetType(event.getTargetType())) - .targetEntityIds(Map.of()).build(), event) { + stepa = new Step2(mgr, ControlLoopOperationParams.builder() + .targetType(TargetType.toTargetType(event.getTargetType())).targetEntityIds(Map.of()).build(), + event) { @Override public List<String> getPropertyNames() { return List.of(OperationProperties.AAI_TARGET_ENTITY); @@ -758,7 +757,8 @@ public class UsecasesEventManagerTest { mgr.storeInDataBase(mgr.getPartialHistory().peekLast()); - verify(dataMgr).store(REQ_ID.toString(), event, null, mgr.getPartialHistory().peekLast().getClOperation()); + verify(dataMgr).store(REQ_ID.toString(), event.getClosedLoopControlName(), event, null, + mgr.getPartialHistory().peekLast().getClOperation()); } @Test diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManager.java index 091c38ef3..6dd372dc5 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManager.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManager.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 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. @@ -21,7 +21,6 @@ package org.onap.policy.controlloop.ophistory; import org.onap.policy.controlloop.ControlLoopOperation; -import org.onap.policy.controlloop.VirtualControlLoopEvent; /** * Data manager for the Operation History table. @@ -33,11 +32,13 @@ public interface OperationHistoryDataManager { * discarded. * * @param requestId request ID - * @param event event with which the operation is associated + * @param clName control loop name + * @param event event with which the operation is associated, typically just used for + * logging * @param targetEntity target entity associated with the operation * @param operation operation to be stored */ - void store(String requestId, VirtualControlLoopEvent event, String targetEntity, ControlLoopOperation operation); + void store(String requestId, String clName, Object event, String targetEntity, ControlLoopOperation operation); /** * Starts the background thread. 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 52a869597..7632a087f 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 @@ -38,7 +38,6 @@ import org.onap.policy.common.parameters.ValidationResult; 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.guard.OperationsHistory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -149,7 +148,7 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana } @Override - public synchronized void store(String requestId, VirtualControlLoopEvent event, String targetEntity, + public synchronized void store(String requestId, String clName, Object event, String targetEntity, ControlLoopOperation operation) { if (stopped) { @@ -158,7 +157,7 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana return; } - operations.add(new Record(requestId, event, targetEntity, operation)); + operations.add(new Record(requestId, clName, event, targetEntity, operation)); if (operations.size() > maxQueueLength) { Record discarded = operations.remove(); @@ -255,35 +254,28 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana */ private void storeRecord(EntityManager entityMgr, Record record) { - final VirtualControlLoopEvent event = record.getEvent(); + final String reqId = record.getRequestId(); + final String clName = record.getClName(); final ControlLoopOperation operation = record.getOperation(); - logger.info("store operation history record for {}", event.getRequestId()); - - 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", - OperationsHistory.class) - .setParameter(1, event.getClosedLoopControlName()) - .setParameter(2, record.getRequestId()) - .setParameter(3, operation.getSubRequestId()) - .setParameter(4, operation.getActor()) - .setParameter(5, operation.getOperation()) - .setParameter(6, record.getTargetEntity()) - .getResultList(); + logger.info("store operation history record for {}", reqId); + + 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", OperationsHistory.class) + .setParameter(1, clName).setParameter(2, record.getRequestId()) + .setParameter(3, operation.getSubRequestId()).setParameter(4, operation.getActor()) + .setParameter(5, operation.getOperation()).setParameter(6, record.getTargetEntity()) + .getResultList(); if (results.size() > 1) { - logger.warn("unexpected operation history record count {} for {}", results.size(), event.getRequestId()); + logger.warn("unexpected operation history record count {} for {}", results.size(), reqId); } OperationsHistory entry = (results.isEmpty() ? new OperationsHistory() : results.get(0)); - entry.setClosedLoopName(event.getClosedLoopControlName()); + entry.setClosedLoopName(clName); entry.setRequestId(record.getRequestId()); entry.setActor(operation.getActor()); entry.setOperation(operation.getOperation()); @@ -303,11 +295,11 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana } if (results.isEmpty()) { - logger.info("insert operation history record for {}", event.getRequestId()); + logger.info("insert operation history record for {}", reqId); ++recordsInserted; entityMgr.persist(entry); } else { - logger.info("update operation history record for {}", event.getRequestId()); + logger.info("update operation history record for {}", reqId); ++recordsUpdated; entityMgr.merge(entry); } @@ -337,7 +329,8 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana @ToString private static class Record { private String requestId; - private VirtualControlLoopEvent event; + private String clName; + private Object event; private String targetEntity; private ControlLoopOperation operation; } diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerStub.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerStub.java index bd2ee043c..ce5f1c100 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerStub.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerStub.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 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. @@ -21,7 +21,6 @@ package org.onap.policy.controlloop.ophistory; import org.onap.policy.controlloop.ControlLoopOperation; -import org.onap.policy.controlloop.VirtualControlLoopEvent; /** * Stub implementation of a data manager; all methods return without doing anything. @@ -29,7 +28,7 @@ import org.onap.policy.controlloop.VirtualControlLoopEvent; public class OperationHistoryDataManagerStub implements OperationHistoryDataManager { @Override - public void store(String requestId, VirtualControlLoopEvent event, String targetEntity, + public void store(String requestId, String clName, Object event, String targetEntity, ControlLoopOperation operation) { // do nothing } diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImplTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImplTest.java index a360a7474..9d32a85e1 100644 --- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImplTest.java +++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImplTest.java @@ -173,7 +173,7 @@ public class OperationHistoryDataManagerImplTest { @Test public void testStore_testStop() throws InterruptedException { // store - mgr.store(REQ_ID, event, MY_ENTITY, operation); + mgr.store(REQ_ID, event.getClosedLoopControlName(), event, MY_ENTITY, operation); runThread(); @@ -200,7 +200,7 @@ public class OperationHistoryDataManagerImplTest { mgr.stop(); // store - mgr.store(REQ_ID, event, MY_ENTITY, operation); + mgr.store(REQ_ID, event.getClosedLoopControlName(), event, MY_ENTITY, operation); assertEquals(0, mgr.getRecordsCommitted()); } @@ -212,7 +212,7 @@ public class OperationHistoryDataManagerImplTest { public void testStoreTooManyItems() throws InterruptedException { final int nextra = 5; for (int nitems = 0; nitems < MAX_QUEUE_LENGTH + nextra; ++nitems) { - mgr.store(REQ_ID, event, MY_ENTITY, operation); + mgr.store(REQ_ID, event.getClosedLoopControlName(), event, MY_ENTITY, operation); } runThread(); @@ -233,9 +233,9 @@ public class OperationHistoryDataManagerImplTest { mgr = new RealThread(); mgr.start(); - mgr.store(REQ_ID, event, MY_ENTITY, operation); - mgr.store(REQ_ID, event, MY_ENTITY, operation); - mgr.store(REQ_ID, event, MY_ENTITY, operation); + mgr.store(REQ_ID, event.getClosedLoopControlName(), event, MY_ENTITY, operation); + mgr.store(REQ_ID, event.getClosedLoopControlName(), event, MY_ENTITY, operation); + mgr.store(REQ_ID, event.getClosedLoopControlName(), event, MY_ENTITY, operation); waitForThread(); @@ -269,9 +269,9 @@ public class OperationHistoryDataManagerImplTest { mgr = new RealThread(); mgr.start(); - mgr.store(REQ_ID, event, MY_ENTITY, operation); - mgr.store(REQ_ID, event, MY_ENTITY, operation); - mgr.store(REQ_ID, event, MY_ENTITY, operation); + mgr.store(REQ_ID, event.getClosedLoopControlName(), event, MY_ENTITY, operation); + mgr.store(REQ_ID, event.getClosedLoopControlName(), event, MY_ENTITY, operation); + mgr.store(REQ_ID, event.getClosedLoopControlName(), event, MY_ENTITY, operation); waitForThread(); @@ -286,7 +286,7 @@ public class OperationHistoryDataManagerImplTest { // arrange to throw an exception when(emfSpy.createEntityManager()).thenThrow(EXPECTED_EXCEPTION); - mgr.store(REQ_ID, event, MY_ENTITY, operation); + mgr.store(REQ_ID, event.getClosedLoopControlName(), event, MY_ENTITY, operation); runThread(); } @@ -299,25 +299,25 @@ public class OperationHistoryDataManagerImplTest { */ // no start time - mgr.store(REQ_ID, event, MY_ENTITY, operation); + mgr.store(REQ_ID, event.getClosedLoopControlName(), event, MY_ENTITY, operation); // no end time operation = new ControlLoopOperation(operation); operation.setSubRequestId(UUID.randomUUID().toString()); operation.setStart(Instant.now()); - mgr.store(REQ_ID, event, MY_ENTITY, operation); + mgr.store(REQ_ID, event.getClosedLoopControlName(), event, MY_ENTITY, operation); // both start and end times operation = new ControlLoopOperation(operation); operation.setSubRequestId(UUID.randomUUID().toString()); operation.setEnd(Instant.now()); - mgr.store(REQ_ID, event, MY_ENTITY, operation); + mgr.store(REQ_ID, event.getClosedLoopControlName(), event, MY_ENTITY, operation); // only end time operation = new ControlLoopOperation(operation); operation.setSubRequestId(UUID.randomUUID().toString()); operation.setStart(null); - mgr.store(REQ_ID, event, MY_ENTITY, operation); + mgr.store(REQ_ID, event.getClosedLoopControlName(), event, MY_ENTITY, operation); runThread(); @@ -341,22 +341,22 @@ public class OperationHistoryDataManagerImplTest { // no start time operation.setStart(null); - mgr.store(REQ_ID, event, MY_ENTITY, operation); + mgr.store(REQ_ID, event.getClosedLoopControlName(), event, MY_ENTITY, operation); // no end time operation = new ControlLoopOperation(operation); operation.setStart(Instant.now()); - mgr.store(REQ_ID, event, MY_ENTITY, operation); + mgr.store(REQ_ID, event.getClosedLoopControlName(), event, MY_ENTITY, operation); // both start and end times operation = new ControlLoopOperation(operation); operation.setEnd(Instant.now()); - mgr.store(REQ_ID, event, MY_ENTITY, operation); + mgr.store(REQ_ID, event.getClosedLoopControlName(), event, MY_ENTITY, operation); // only end time operation = new ControlLoopOperation(operation); operation.setStart(null); - mgr.store(REQ_ID, event, MY_ENTITY, operation); + mgr.store(REQ_ID, event.getClosedLoopControlName(), event, MY_ENTITY, operation); runThread(); diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerStubTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerStubTest.java index a6f50629c..4774af427 100644 --- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerStubTest.java +++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerStubTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 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. @@ -30,7 +30,7 @@ public class OperationHistoryDataManagerStubTest { public void test() { OperationHistoryDataManagerStub mgr = new OperationHistoryDataManagerStub(); - assertThatCode(() -> mgr.store(null, null, null, null)).doesNotThrowAnyException(); + assertThatCode(() -> mgr.store(null, null, null, null, null)).doesNotThrowAnyException(); assertThatCode(() -> mgr.stop()).doesNotThrowAnyException(); } } |