aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/common/eventmanager/src/main')
-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;
+ }
}