summaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager
diff options
context:
space:
mode:
authorJorge Hernandez <jorge.hernandez-herrero@att.com>2020-03-25 22:30:09 +0000
committerGerrit Code Review <gerrit@onap.org>2020-03-25 22:30:09 +0000
commit5582113b8f017f9cdae475d3198ab7a495c26657 (patch)
tree2c7a395340d4aefbe3e8755e15d8a01ee318b106 /controlloop/common/eventmanager
parent36bb77d724436ea2c859f615ca23caad232142d9 (diff)
parentea3ba40703cba1e5a95fea05f359b7364ba1f7da (diff)
Merge "Fix db exception in frankfurt junit"
Diffstat (limited to 'controlloop/common/eventmanager')
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java2
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManager.java3
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java16
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerStub.java3
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java13
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImplTest.java29
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerStubTest.java2
7 files changed, 41 insertions, 27 deletions
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 156dad7e6..a096522bc 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
@@ -585,7 +585,7 @@ public class ControlLoopOperationManager2 implements Serializable {
* Stores the latest operation in the DB.
*/
private void storeOperationInDataBase() {
- operContext.getDataManager().store(requestId, eventContext.getEvent(),
+ operContext.getDataManager().store(requestId, eventContext.getEvent(), targetEntity,
operationHistory.peekLast().getClOperation());
}
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 a1774ea6f..091c38ef3 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
@@ -34,9 +34,10 @@ public interface OperationHistoryDataManager {
*
* @param requestId request ID
* @param event event with which the operation is associated
+ * @param targetEntity target entity associated with the operation
* @param operation operation to be stored
*/
- void store(String requestId, VirtualControlLoopEvent event, ControlLoopOperation operation);
+ void store(String requestId, VirtualControlLoopEvent 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 f7576f139..5de38a4c3 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
@@ -110,6 +110,8 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana
return;
}
+ logger.info("start operation history thread");
+
thread = makeThread(emFactory, this::run);
thread.setDaemon(true);
thread.start();
@@ -117,6 +119,8 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana
@Override
public synchronized void stop() {
+ logger.info("requesting stop of operation history thread");
+
stopped = true;
if (thread == null) {
@@ -130,7 +134,8 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana
}
@Override
- public synchronized void store(String requestId, VirtualControlLoopEvent event, ControlLoopOperation operation) {
+ public synchronized void store(String requestId, VirtualControlLoopEvent event, String targetEntity,
+ ControlLoopOperation operation) {
if (stopped) {
logger.warn("operation history thread is stopped, discarding requestId={} event={} operation={}", requestId,
@@ -138,7 +143,7 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana
return;
}
- operations.add(new Record(requestId, event, operation));
+ operations.add(new Record(requestId, event, targetEntity, operation));
if (operations.size() > maxQueueLength) {
Record discarded = operations.remove();
@@ -204,6 +209,7 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana
* @param firstRecord first record to be stored
*/
private void storeBatch(EntityManager entityManager, Record firstRecord) {
+ logger.info("store operation history record batch");
try (EntityMgrCloser emc = new EntityMgrCloser(entityManager);
EntityTransCloser trans = new EntityTransCloser(entityManager.getTransaction())) {
@@ -233,17 +239,18 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana
* @param record record to be stored
*/
private void storeRecord(EntityManager entityMgr, Record record) {
-
Dbao newEntry = new Dbao();
final VirtualControlLoopEvent event = record.getEvent();
final ControlLoopOperation operation = record.getOperation();
+ logger.info("store operation history record for {}", event.getRequestId());
+
newEntry.setClosedLoopName(event.getClosedLoopControlName());
newEntry.setRequestId(record.getRequestId());
newEntry.setActor(operation.getActor());
newEntry.setOperation(operation.getOperation());
- newEntry.setTarget(operation.getTarget());
+ newEntry.setTarget(record.getTargetEntity());
newEntry.setSubrequestId(operation.getSubRequestId());
newEntry.setMessage(operation.getMessage());
newEntry.setOutcome(operation.getOutcome());
@@ -280,6 +287,7 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana
private static class Record {
private String requestId;
private VirtualControlLoopEvent 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 e1e0cbe09..bd2ee043c 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
@@ -29,7 +29,8 @@ import org.onap.policy.controlloop.VirtualControlLoopEvent;
public class OperationHistoryDataManagerStub implements OperationHistoryDataManager {
@Override
- public void store(String requestId, VirtualControlLoopEvent event, ControlLoopOperation operation) {
+ public void store(String requestId, VirtualControlLoopEvent event, String targetEntity,
+ ControlLoopOperation operation) {
// do nothing
}
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 e946d2edc..9c2e22d26 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
@@ -276,7 +276,7 @@ public class ControlLoopOperationManager2Test {
verify(mgrctx).updated(mgr);
// should not have tried to store anything in the DB
- verify(dataMgr, never()).store(any(), any(), any());
+ verify(dataMgr, never()).store(any(), any(), any(), any());
}
@Test
@@ -561,7 +561,7 @@ public class ControlLoopOperationManager2Test {
assertTrue(mgr.nextStep());
verify(mgrctx, times(2)).updated(mgr);
- verify(dataMgr, never()).store(any(), any(), any());
+ verify(dataMgr, never()).store(any(), any(), any(), any());
}
/**
@@ -951,10 +951,13 @@ public class ControlLoopOperationManager2Test {
}
private void verifyDb(int nrecords, PolicyResult expectedResult, String expectedMsg) {
- ArgumentCaptor<ControlLoopOperation> captor = ArgumentCaptor.forClass(ControlLoopOperation.class);
- verify(dataMgr, times(nrecords)).store(any(), any(), captor.capture());
+ ArgumentCaptor<String> entityCaptor = ArgumentCaptor.forClass(String.class);
+ ArgumentCaptor<ControlLoopOperation> opCaptor = ArgumentCaptor.forClass(ControlLoopOperation.class);
+ verify(dataMgr, times(nrecords)).store(any(), any(), entityCaptor.capture(), opCaptor.capture());
- ControlLoopOperation oper = captor.getValue();
+ assertEquals(MY_TARGET, entityCaptor.getValue());
+
+ ControlLoopOperation oper = opCaptor.getValue();
assertEquals(expectedResult.toString(), oper.getOutcome());
assertEquals(expectedMsg, oper.getMessage());
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 8e3c1fa9b..e6c66d120 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
@@ -54,6 +54,7 @@ public class OperationHistoryDataManagerImplTest {
private static final IllegalStateException EXPECTED_EXCEPTION = new IllegalStateException("expected exception");
private static final String MY_TARGET = "my-target";
+ private static final String MY_ENTITY = "my-entity";
private static final String REQ_ID = "my-request-id";
private static final int BATCH_SIZE = 5;
private static final int MAX_QUEUE_LENGTH = 23;
@@ -165,7 +166,7 @@ public class OperationHistoryDataManagerImplTest {
@Test
public void testStore_testStop() throws InterruptedException {
// store
- mgr.store(REQ_ID, event, operation);
+ mgr.store(REQ_ID, event, MY_ENTITY, operation);
runThread();
@@ -192,7 +193,7 @@ public class OperationHistoryDataManagerImplTest {
mgr.stop();
// store
- mgr.store(REQ_ID, event, operation);
+ mgr.store(REQ_ID, event, MY_ENTITY, operation);
assertEquals(0, mgr.getRecordsAdded());
}
@@ -204,7 +205,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, operation);
+ mgr.store(REQ_ID, event, MY_ENTITY, operation);
}
runThread();
@@ -225,9 +226,9 @@ public class OperationHistoryDataManagerImplTest {
mgr = new RealThread();
mgr.start();
- mgr.store(REQ_ID, event, operation);
- mgr.store(REQ_ID, event, operation);
- mgr.store(REQ_ID, event, operation);
+ mgr.store(REQ_ID, event, MY_ENTITY, operation);
+ mgr.store(REQ_ID, event, MY_ENTITY, operation);
+ mgr.store(REQ_ID, event, MY_ENTITY, operation);
waitForThread();
@@ -261,9 +262,9 @@ public class OperationHistoryDataManagerImplTest {
mgr = new RealThread();
mgr.start();
- mgr.store(REQ_ID, event, operation);
- mgr.store(REQ_ID, event, operation);
- mgr.store(REQ_ID, event, operation);
+ mgr.store(REQ_ID, event, MY_ENTITY, operation);
+ mgr.store(REQ_ID, event, MY_ENTITY, operation);
+ mgr.store(REQ_ID, event, MY_ENTITY, operation);
waitForThread();
@@ -278,7 +279,7 @@ public class OperationHistoryDataManagerImplTest {
// arrange to throw an exception
when(emfSpy.createEntityManager()).thenThrow(EXPECTED_EXCEPTION);
- mgr.store(REQ_ID, event, operation);
+ mgr.store(REQ_ID, event, MY_ENTITY, operation);
runThread();
}
@@ -286,22 +287,22 @@ public class OperationHistoryDataManagerImplTest {
@Test
public void testStoreRecord() throws InterruptedException {
// no start time
- mgr.store(REQ_ID, event, operation);
+ mgr.store(REQ_ID, event, MY_ENTITY, operation);
// no start time
operation = new ControlLoopOperation(operation);
operation.setStart(Instant.now());
- mgr.store(REQ_ID, event, operation);
+ mgr.store(REQ_ID, event, MY_ENTITY, operation);
// both start and end times
operation = new ControlLoopOperation(operation);
operation.setEnd(Instant.now());
- mgr.store(REQ_ID, event, operation);
+ mgr.store(REQ_ID, event, MY_ENTITY, operation);
// only end time
operation = new ControlLoopOperation(operation);
operation.setStart(null);
- mgr.store(REQ_ID, event, operation);
+ mgr.store(REQ_ID, 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 f4a7ff8c5..a6f50629c 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
@@ -30,7 +30,7 @@ public class OperationHistoryDataManagerStubTest {
public void test() {
OperationHistoryDataManagerStub mgr = new OperationHistoryDataManagerStub();
- assertThatCode(() -> mgr.store(null, null, null)).doesNotThrowAnyException();
+ assertThatCode(() -> mgr.store(null, null, null, null)).doesNotThrowAnyException();
assertThatCode(() -> mgr.stop()).doesNotThrowAnyException();
}
}