summaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager/src/main/java
diff options
context:
space:
mode:
authorJorge Hernandez <jorge.hernandez-herrero@att.com>2020-05-21 23:27:24 +0000
committerGerrit Code Review <gerrit@onap.org>2020-05-21 23:27:24 +0000
commit0c544a84cd51f49ad3de56a2f1f47f4eb0af6c8e (patch)
treead8041e20a0166b3541f47ba3282caf55d87c077 /controlloop/common/eventmanager/src/main/java
parent6dc566131200f634d54cc27712518bb163885cb0 (diff)
parentb1091d8713089d0ab20c66123adf8b0b5ea6f613 (diff)
Merge "Insert pending record when operation starts"
Diffstat (limited to 'controlloop/common/eventmanager/src/main/java')
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java24
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java76
2 files changed, 73 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 9d7ca586c..5e8cbbc2e 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
@@ -500,20 +500,20 @@ public class ControlLoopOperationManager2 implements Serializable {
// operation started
++attempts;
state = State.OPERATION_STARTED;
- operationHistory.add(new Operation(outcome));
- break;
- }
- /*
- * Operation completed. If the last entry was a "start" (i.e., "end" field
- * is null), then replace it. Otherwise, just add the completion.
- */
- state = (outcome.getResult() == PolicyResult.SUCCESS ? State.OPERATION_SUCCESS
- : State.OPERATION_FAILURE);
- controlLoopResponse = outcome.getControlLoopResponse();
- if (!operationHistory.isEmpty() && operationHistory.peekLast().getClOperation().getEnd() == null) {
- operationHistory.removeLast();
+ } else {
+ /*
+ * Operation completed. If the last entry was a "start" (i.e., "end" field
+ * is null), then replace it. Otherwise, just add the completion.
+ */
+ state = (outcome.getResult() == PolicyResult.SUCCESS ? State.OPERATION_SUCCESS
+ : State.OPERATION_FAILURE);
+ controlLoopResponse = outcome.getControlLoopResponse();
+ if (!operationHistory.isEmpty() && operationHistory.peekLast().getClOperation().getEnd() == null) {
+ operationHistory.removeLast();
+ }
}
+
operationHistory.add(new Operation(outcome));
storeOperationInDataBase();
break;
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 5de38a4c3..1d108a349 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
@@ -21,6 +21,7 @@
package org.onap.policy.controlloop.ophistory;
import java.util.Date;
+import java.util.List;
import java.util.Properties;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
@@ -78,10 +79,25 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana
private final BlockingQueue<Record> operations = new LinkedBlockingQueue<>();
/**
- * Number of records that have been added to the DB by this data manager instance.
+ * Number of records that have been processed and committed into the DB by this data
+ * manager instance.
*/
@Getter
- private long recordsAdded = 0;
+ private long recordsCommitted = 0;
+
+ /**
+ * Number of records that have been inserted into the DB by this data manager
+ * instance, whether or not they were committed.
+ */
+ @Getter
+ private long recordsInserted = 0;
+
+ /**
+ * Number of records that have been updated within the DB by this data manager
+ * instance, whether or not they were committed.
+ */
+ @Getter
+ private long recordsUpdated = 0;
/**
@@ -228,7 +244,7 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana
}
trans.commit();
- recordsAdded += nrecords;
+ recordsCommitted += nrecords;
}
}
@@ -239,29 +255,59 @@ 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(record.getTargetEntity());
- newEntry.setSubrequestId(operation.getSubRequestId());
- newEntry.setMessage(operation.getMessage());
- newEntry.setOutcome(operation.getOutcome());
+ List<Dbao> results =
+ entityMgr.createQuery("select e from Dbao 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)
+ .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();
+
+ Dbao entry = (results.isEmpty() ? new Dbao() : results.get(0));
+
+ entry.setClosedLoopName(event.getClosedLoopControlName());
+ entry.setRequestId(record.getRequestId());
+ entry.setActor(operation.getActor());
+ entry.setOperation(operation.getOperation());
+ entry.setTarget(record.getTargetEntity());
+ entry.setSubrequestId(operation.getSubRequestId());
+ entry.setMessage(operation.getMessage());
+ entry.setOutcome(operation.getOutcome());
if (operation.getStart() != null) {
- newEntry.setStarttime(new Date(operation.getStart().toEpochMilli()));
+ entry.setStarttime(new Date(operation.getStart().toEpochMilli()));
+ } else {
+ entry.setStarttime(null);
}
if (operation.getEnd() != null) {
- newEntry.setEndtime(new Date(operation.getEnd().toEpochMilli()));
+ entry.setEndtime(new Date(operation.getEnd().toEpochMilli()));
+ } else {
+ entry.setEndtime(null);
}
- entityMgr.persist(newEntry);
+ if (results.isEmpty()) {
+ logger.info("insert operation history record for {}", event.getRequestId());
+ ++recordsInserted;
+ entityMgr.persist(entry);
+ } else {
+ logger.info("update operation history record for {}", event.getRequestId());
+ ++recordsUpdated;
+ entityMgr.merge(entry);
+ }
}
/**