Use "outcome" to indicate pending record 39/108139/5
authorJim Hahn <jrh3@att.com>
Fri, 22 May 2020 13:06:58 +0000 (09:06 -0400)
committerJim Hahn <jrh3@att.com>
Fri, 22 May 2020 17:35:50 +0000 (13:35 -0400)
Mariadb is setting the "endtime" to the current time by default,
so rather than indicate a pending record using a null endtime, just
modified the code set "outcome" to "Started" to indicate a pending record.
Also added code to ensure the "outcome" is never null, as that causes
a DB error.
Also addressed a comment from a previous review to log a warning message
if more than one matching record is found in operations history.

Issue-ID: POLICY-2581
Change-Id: I6bf67551cef46808a79cc15afeb0abbfc1b6d945
Signed-off-by: Jim Hahn <jrh3@att.com>
controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java
controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java
controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImplTest.java

index 5e8cbbc..9ef892e 100644 (file)
@@ -212,6 +212,12 @@ public class ControlLoopOperationManager2 implements Serializable {
             clOperation = outcome.toControlLoopOperation();
             clOperation.setTarget(policy.getTarget().toString());
             clResponse = outcome.getControlLoopResponse();
+
+            if (outcome.getEnd() == null) {
+                clOperation.setOutcome("Started");
+            } else if (clOperation.getOutcome() == null) {
+                clOperation.setOutcome("");
+            }
         }
     }
 
index 1d108a3..2b67865 100644 (file)
@@ -278,6 +278,10 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana
                 .setParameter(6, record.getTargetEntity())
                 .getResultList();
 
+        if (results.size() > 1) {
+            logger.warn("unexpected operation history record count {} for {}", results.size(), event.getRequestId());
+        }
+
         Dbao entry = (results.isEmpty() ? new Dbao() : results.get(0));
 
         entry.setClosedLoopName(event.getClosedLoopControlName());
index e6d42d4..6976281 100644 (file)
@@ -340,17 +340,21 @@ public class OperationHistoryDataManagerImplTest {
          */
 
         // no start time
+        operation.setStart(null);
         mgr.store(REQ_ID, event, MY_ENTITY, operation);
 
         // no end time
+        operation = new ControlLoopOperation(operation);
         operation.setStart(Instant.now());
         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, MY_ENTITY, operation);
 
         // only end time
+        operation = new ControlLoopOperation(operation);
         operation.setStart(null);
         mgr.store(REQ_ID, event, MY_ENTITY, operation);