aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager
diff options
context:
space:
mode:
authorJoshua Reich <jreich@research.att.com>2018-08-14 15:04:03 -0700
committerJoshua Reich <jreich@research.att.com>2018-08-31 11:51:59 -0700
commita35ca0b16ffa99119b5d16cd005f91ff734c8df8 (patch)
treea5437a6dfb69000772fa530f0878a9642412dd7f /controlloop/common/eventmanager
parent8279af376b435e1d7dd118a1955c5681edf3b847 (diff)
Add code to store abatement events.
Stores abatement events in history DB. Change-Id: Ifca6acd42cd9eea85e27765bd268a491028e305a Issue-ID: POLICY-975 Signed-off-by: Joshua Reich <jreich@research.att.com>
Diffstat (limited to 'controlloop/common/eventmanager')
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java24
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java32
2 files changed, 55 insertions, 1 deletions
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
index 4b438a94d..930f9578f 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
@@ -30,6 +30,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
+import java.util.NoSuchElementException;
import org.onap.policy.aai.AaiGetVnfResponse;
import org.onap.policy.aai.AaiGetVserverResponse;
@@ -99,6 +100,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
private boolean isActivated = false;
private LinkedList<ControlLoopOperation> controlLoopHistory = new LinkedList<>();
private ControlLoopOperationManager currentOperation = null;
+ private ControlLoopOperationManager lastOperationManager = null;
private transient TargetLock targetLock = null;
private AaiGetVnfResponse vnfResponse = null;
private AaiGetVserverResponse vserverResponse = null;
@@ -414,6 +416,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
//
// And setup an operation
//
+ this.lastOperationManager = this.currentOperation;
this.currentOperation = new ControlLoopOperationManager(this.onset, policy, this);
//
// Return it
@@ -449,6 +452,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
//
// Just null this out
//
+ this.lastOperationManager = this.currentOperation;
this.currentOperation = null;
//
// TODO: Release our lock
@@ -594,6 +598,26 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
return NEW_EVENT_STATUS.SYNTAX_ERROR;
}
+
+ /**
+ * Commit the abatement to the history database.
+ *
+ * @param message the abatement message
+ * @param outcome the abatement outcome
+ */
+ public void commitAbatement(String message, String outcome) {
+ if (this.lastOperationManager == null) {
+ logger.error("{}: commitAbatement: no operation manager", this);
+ return;
+ }
+ try{
+ this.lastOperationManager.commitAbatement(message,outcome);
+ } catch (NoSuchElementException e) {
+ logger.error("{}: commitAbatement threw an exception ", this, e);
+ }
+ }
+
+
/**
* Set the control loop time out.
*
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 0eb924dd2..f1d912ef5 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
@@ -27,6 +27,7 @@ import java.util.AbstractMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
+import java.util.NoSuchElementException;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
@@ -844,7 +845,36 @@ public class ControlLoopOperationManager implements Serializable {
}
}
logger.debug("Could not find associated operation");
-
}
+
+ /**
+ * Commit the abatement to the history database.
+ *
+ * @param message the abatement message
+ * @param outcome the abatement outcome
+ */
+ public void commitAbatement(String message, String outcome) {
+ logger.info("commitAbatement: " + message + ", " + outcome);
+
+ if (this.currentOperation == null) {
+ try {
+ this.currentOperation = this.operationHistory.getLast();
+ } catch (NoSuchElementException e) {
+ logger.error("{}: commitAbatement threw an exception ", this, e);
+ return;
+ }
+ }
+ this.currentOperation.clOperation.setEnd(Instant.now());
+ this.currentOperation.clOperation.setMessage(message);
+ this.currentOperation.clOperation.setOutcome(outcome);
+ //
+ // Store commit in DB
+ //
+ this.storeOperationInDataBase();
+ //
+ // Clear the current operation field
+ //
+ this.currentOperation = null;
+ }
}