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;
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;
//
// And setup an operation
//
+ this.lastOperationManager = this.currentOperation;
this.currentOperation = new ControlLoopOperationManager(this.onset, policy, this);
//
// Return it
//
// Just null this out
//
+ this.lastOperationManager = this.currentOperation;
this.currentOperation = null;
//
// TODO: Release our lock
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.
*
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
+import java.util.NoSuchElementException;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
}
}
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;
+ }
}
logger.info("{}: {}: abatement received for {}. Closing the control loop",
$params.getClosedLoopControlName(), drools.getRule().getName(),
$event.getRequestId());
+
+ /// DB Write---end event processing for this RequestId()
+ $manager.commitAbatement("Event Abated","Closed");
+
notification.setFrom("policy");
notification.setPolicyName(drools.getRule().getName());
notification.setPolicyScope("${policyScope}");