summaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager/src/main/java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-08-31 20:53:44 +0000
committerGerrit Code Review <gerrit@onap.org>2020-08-31 20:53:44 +0000
commita588736799d94747f70ed648d3d821210993c5c4 (patch)
treef54ea646db61861985fe6ae87b76d87e8a9369a2 /controlloop/common/eventmanager/src/main/java
parent1c5cb8a0d740ccd92d2b3fdce8eb192cd20b147f (diff)
parenta6d4077e3639a0f3478f0cbf51e06ef46517a10d (diff)
Merge "Add tdjam-controller"
Diffstat (limited to 'controlloop/common/eventmanager/src/main/java')
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java33
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Drools.java74
2 files changed, 94 insertions, 13 deletions
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java
index 556fa31d5..b738cefe1 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java
@@ -44,8 +44,6 @@ import java.util.stream.Stream;
import lombok.Getter;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;
-import org.drools.core.WorkingMemory;
-import org.kie.api.runtime.rule.FactHandle;
import org.onap.policy.controlloop.ControlLoopEventStatus;
import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.ControlLoopNotificationType;
@@ -73,7 +71,7 @@ import org.slf4j.LoggerFactory;
* {@link #isActive()} returns {@code false}, indicating that all steps have completed.
*/
@ToString(onlyExplicitlyIncluded = true)
-public class ControlLoopEventManager2 implements ManagerContext, Serializable {
+public abstract class ControlLoopEventManager2 implements ManagerContext, Serializable {
private static final Logger logger = LoggerFactory.getLogger(ControlLoopEventManager2.class);
private static final long serialVersionUID = -1216568161322872641L;
@@ -161,20 +159,16 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
@Getter
private boolean updated = false;
- private final transient WorkingMemory workMem;
- private transient FactHandle factHandle;
-
/**
* Constructs the object.
*
* @param params control loop parameters
* @param event event to be managed by this object
- * @param workMem working memory to update if this changes
* @throws ControlLoopException if the event is invalid or if a YAML processor cannot
* be created
*/
- public ControlLoopEventManager2(ControlLoopParams params, VirtualControlLoopEvent event, WorkingMemory workMem)
+ public ControlLoopEventManager2(ControlLoopParams params, VirtualControlLoopEvent event)
throws ControlLoopException {
createCount.incrementAndGet();
@@ -197,7 +191,6 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
this.policyScope = params.getPolicyScope();
this.policyVersion = params.getPolicyVersion();
this.processor = new ControlLoopProcessor(params.getToscaPolicy());
- this.workMem = workMem;
this.endTimeMs = System.currentTimeMillis() + detmControlLoopTimeoutMs();
}
@@ -219,9 +212,7 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
throw new IllegalStateException("manager is no longer active");
}
- if ((factHandle = workMem.getFactHandle(this)) == null) {
- throw new IllegalStateException("manager is not in working memory");
- }
+ startHook();
if (currentOperation.get() != null) {
throw new IllegalStateException("manager already started");
@@ -373,7 +364,7 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
}
updated = true;
- workMem.update(factHandle, this);
+ notifyUpdate();
}
/**
@@ -637,4 +628,20 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
public OperationHistoryDataManager getDataManager() {
return LazyInitData.DATA_MANAGER;
}
+
+ /* ============================================================ */
+
+ /**
+ * This is a method, invoked from the 'start' method -- it gives subclasses
+ * the ability to add operations. The default implementation does nothing.
+ */
+ protected void startHook() {
+ }
+
+ /**
+ * This is an abstract method that is called after a notable update has
+ * occurred to the 'ControlLoopEventManager2' object. It gives subclasses
+ * the ability to add a callback method to process state changes.
+ */
+ protected abstract void notifyUpdate();
}
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Drools.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Drools.java
new file mode 100644
index 000000000..3af9defc7
--- /dev/null
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Drools.java
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.controlloop.eventmanager;
+
+import org.drools.core.WorkingMemory;
+import org.kie.api.runtime.rule.FactHandle;
+import org.onap.policy.controlloop.ControlLoopException;
+import org.onap.policy.controlloop.VirtualControlLoopEvent;
+import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
+
+/**
+ * Manager for a single control loop event. Once this has been created, the event can be
+ * retracted from working memory. Once this has been created, {@link #start()} should be
+ * invoked, and then {@link #nextStep()} should be invoked continually until
+ * {@link #isActive()} returns {@code false}, indicating that all steps have completed.
+ */
+public class ControlLoopEventManager2Drools extends ControlLoopEventManager2 {
+ private final transient WorkingMemory workMem;
+ private transient FactHandle factHandle;
+
+ /**
+ * Constructs the object.
+ *
+ * @param params control loop parameters
+ * @param event event to be managed by this object
+ * @param workMem working memory to update if this changes
+ * @throws ControlLoopException if the event is invalid or if a YAML processor cannot
+ * be created
+ */
+ public ControlLoopEventManager2Drools(ControlLoopParams params, VirtualControlLoopEvent event,
+ WorkingMemory workMem) throws ControlLoopException {
+
+ super(params, event);
+ this.workMem = workMem;
+ }
+
+ /**
+ * This is a hook added to 'ControlLoopEventManager2.start()' --
+ * here, we add an additional check.
+ */
+ @Override
+ protected void startHook() {
+ if ((factHandle = workMem.getFactHandle(this)) == null) {
+ throw new IllegalStateException("manager is not in working memory");
+ }
+ }
+
+ /**
+ * This is a hook added to 'ControlLoopEventManager2.updated(...)' --
+ * here, we mark it as updated in Drools memory.
+ */
+ @Override
+ protected void notifyUpdate() {
+ workMem.update(factHandle, this);
+ }
+}