summaryrefslogtreecommitdiffstats
path: root/controlloop/common/controller-usecases
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-05-04 17:34:03 -0400
committerJim Hahn <jrh3@att.com>2021-05-05 12:53:55 -0400
commitd304f7d3a058b024ab413374e1a6065411903e3c (patch)
tree08e3966a424e8234c4ba62a033aed0510852bc3f /controlloop/common/controller-usecases
parent7cc5fd31420bf71b41853a66c0a0b66bd9495ef3 (diff)
EventManagerServices shouldn't be static
Currently, the event manager uses a static EventManagerServices object, which precludes the possibility of configuring the actors, for each rule set, from using different properties. Modified the code to allow the rules to specify the event services to use on a per manager basis. Issue-ID: POLICY-3260 Change-Id: If493ae1b55cb752f11e0b2f72dced9c4f3883e34 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'controlloop/common/controller-usecases')
-rw-r--r--controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManager.java8
-rw-r--r--controlloop/common/controller-usecases/src/main/resources/usecases.drl26
-rw-r--r--controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManagerTest.java60
3 files changed, 56 insertions, 38 deletions
diff --git a/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManager.java b/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManager.java
index 4db243408..cb71f8ea0 100644
--- a/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManager.java
+++ b/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManager.java
@@ -51,6 +51,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOp
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
import org.onap.policy.controlloop.eventmanager.ActorConstants;
import org.onap.policy.controlloop.eventmanager.ClEventManagerWithEvent;
+import org.onap.policy.controlloop.eventmanager.EventManagerServices;
import org.onap.policy.controlloop.eventmanager.StepContext;
import org.onap.policy.drools.apps.controller.usecases.step.AaiCqStep2;
import org.onap.policy.drools.apps.controller.usecases.step.AaiGetPnfStep2;
@@ -105,16 +106,17 @@ public class UsecasesEventManager extends ClEventManagerWithEvent<Step2> impleme
/**
* Constructs the object.
*
+ * @param services services the manager should use when processing the event
* @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 UsecasesEventManager(ControlLoopParams params, VirtualControlLoopEvent event, WorkingMemory workMem)
- throws ControlLoopException {
+ public UsecasesEventManager(EventManagerServices services, ControlLoopParams params, VirtualControlLoopEvent event,
+ WorkingMemory workMem) throws ControlLoopException {
- super(params, event, workMem);
+ super(services, params, event, workMem);
if (isClosedLoopDisabled(event)) {
throw new IllegalStateException("is-closed-loop-disabled is set to true on VServer or VNF");
diff --git a/controlloop/common/controller-usecases/src/main/resources/usecases.drl b/controlloop/common/controller-usecases/src/main/resources/usecases.drl
index 49ab78d71..5074215bb 100644
--- a/controlloop/common/controller-usecases/src/main/resources/usecases.drl
+++ b/controlloop/common/controller-usecases/src/main/resources/usecases.drl
@@ -45,6 +45,7 @@ import org.onap.policy.drools.apps.controller.usecases.UsecasesEventManager;
import org.onap.policy.controlloop.eventmanager.ClEventManagerWithSteps.State;
import org.onap.policy.controlloop.eventmanager.ClEventManagerWithOutcome.OperationOutcome2;
import org.onap.policy.controlloop.eventmanager.ClEventManagerWithEvent.NewEventStatus;
+import org.onap.policy.controlloop.eventmanager.EventManagerServices;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.slf4j.LoggerFactory;
@@ -52,6 +53,27 @@ import org.slf4j.Logger;
import org.onap.policy.drools.system.PolicyEngineConstants;
+
+/*
+* Called at initial start-up, to create the event services that will be used by all
+* event managers in this rule engine instance.
+*/
+rule "CREATE.EVENT.SERVICES"
+ when
+ not (EventManagerServices())
+ then
+
+ Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage());
+ logger.info("{}", drools.getRule().getName());
+
+ try {
+ insert(new EventManagerServices("event-manager"));
+
+ } catch(RuntimeException e) {
+ logger.warn("{}: cannot create event services", drools.getRule().getName(), e);
+ }
+end
+
/*
*
* Called when the ControlLoopParams object has been inserted into working memory from the PAP.
@@ -114,6 +136,7 @@ rule "EVENT"
when
$params : ControlLoopParams( $clName : getClosedLoopControlName() )
$event : CanonicalOnset( closedLoopControlName == $clName )
+ $services : EventManagerServices()
not ( UsecasesEventManager( closedLoopControlName == $event.getClosedLoopControlName(),
getEvent() == $event ) )
then
@@ -144,7 +167,8 @@ rule "EVENT"
notification.setPolicyVersion($params.getPolicyVersion());
} else {
- UsecasesEventManager manager = new UsecasesEventManager($params, $event, drools.getWorkingMemory());
+ UsecasesEventManager manager =
+ new UsecasesEventManager($services, $params, $event, drools.getWorkingMemory());
insert(manager);
try {
// load the first policy/step
diff --git a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManagerTest.java b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManagerTest.java
index 318d6b7cc..434939d5d 100644
--- a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManagerTest.java
+++ b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/UsecasesEventManagerTest.java
@@ -57,7 +57,6 @@ import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.ControlLoopResponse;
import org.onap.policy.controlloop.ControlLoopTargetType;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
-import org.onap.policy.controlloop.actorserviceprovider.ActorService;
import org.onap.policy.controlloop.actorserviceprovider.Operation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
@@ -68,6 +67,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOp
import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
import org.onap.policy.controlloop.eventmanager.ActorConstants;
+import org.onap.policy.controlloop.eventmanager.EventManagerServices;
import org.onap.policy.controlloop.ophistory.OperationHistoryDataManager;
import org.onap.policy.drools.apps.controller.usecases.step.AaiCqStep2;
import org.onap.policy.drools.apps.controller.usecases.step.AaiGetPnfStep2;
@@ -113,7 +113,7 @@ public class UsecasesEventManagerTest {
@Mock
private Actor policyActor;
@Mock
- private ActorService actors;
+ private EventManagerServices services;
@Mock
private OperationHistoryDataManager dataMgr;
@Mock
@@ -134,6 +134,8 @@ public class UsecasesEventManagerTest {
*/
@Before
public void setUp() throws ControlLoopException, CoderException {
+ when(services.getDataManager()).thenReturn(dataMgr);
+
when(workMem.getFactHandle(any())).thenReturn(factHandle);
event = new VirtualControlLoopEvent();
@@ -154,7 +156,7 @@ public class UsecasesEventManagerTest {
locks = new ArrayList<>();
- mgr = new MyManager(params, event, workMem);
+ mgr = new MyManager(services, params, event, workMem);
}
@Test
@@ -165,37 +167,37 @@ public class UsecasesEventManagerTest {
Map<String, String> orig = event.getAai();
event.setAai(addAai(orig, UsecasesConstants.VSERVER_IS_CLOSED_LOOP_DISABLED, "true"));
- assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+ assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
.hasMessage("is-closed-loop-disabled is set to true on VServer or VNF");
// vserver ACTIVE
event.setAai(addAai(orig, UsecasesConstants.VSERVER_PROV_STATUS,
UsecasesConstants.PROV_STATUS_ACTIVE.toUpperCase()));
- assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+ assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
// vserver active
event.setAai(addAai(orig, UsecasesConstants.VSERVER_PROV_STATUS,
UsecasesConstants.PROV_STATUS_ACTIVE.toLowerCase()));
- assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+ assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
// vserver inactive
event.setAai(addAai(orig, UsecasesConstants.VSERVER_PROV_STATUS, "inactive"));
- assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+ assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
.hasMessage("prov-status is not ACTIVE on VServer or VNF");
// vnf ACTIVE
event.setAai(addAai(orig, UsecasesConstants.GENERIC_VNF_PROV_STATUS,
UsecasesConstants.PROV_STATUS_ACTIVE.toUpperCase()));
- assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+ assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
// vnf active
event.setAai(addAai(orig, UsecasesConstants.GENERIC_VNF_PROV_STATUS,
UsecasesConstants.PROV_STATUS_ACTIVE.toLowerCase()));
- assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+ assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
// vnf inactive
event.setAai(addAai(orig, UsecasesConstants.GENERIC_VNF_PROV_STATUS, "inactive"));
- assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+ assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
.hasMessage("prov-status is not ACTIVE on VServer or VNF");
// valid
@@ -204,7 +206,7 @@ public class UsecasesEventManagerTest {
// invalid
event.setTarget("unknown-target");
- assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+ assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
.isInstanceOf(ControlLoopException.class);
}
@@ -541,15 +543,15 @@ public class UsecasesEventManagerTest {
Map<String, String> orig = event.getAai();
event.setAai(addAai(orig, UsecasesConstants.VSERVER_IS_CLOSED_LOOP_DISABLED, "true"));
- assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+ assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
.isInstanceOf(IllegalStateException.class);
event.setAai(addAai(orig, UsecasesConstants.GENERIC_VNF_IS_CLOSED_LOOP_DISABLED, "true"));
- assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+ assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
.isInstanceOf(IllegalStateException.class);
event.setAai(addAai(orig, UsecasesConstants.PNF_IS_IN_MAINT, "true"));
- assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+ assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
.isInstanceOf(IllegalStateException.class);
}
@@ -558,17 +560,17 @@ public class UsecasesEventManagerTest {
Map<String, String> orig = event.getAai();
event.setAai(addAai(orig, UsecasesConstants.VSERVER_PROV_STATUS, "ACTIVE"));
- assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+ assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
event.setAai(addAai(orig, UsecasesConstants.VSERVER_PROV_STATUS, "inactive"));
- assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+ assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
.isInstanceOf(IllegalStateException.class);
event.setAai(addAai(orig, UsecasesConstants.GENERIC_VNF_PROV_STATUS, "ACTIVE"));
- assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+ assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
event.setAai(addAai(orig, UsecasesConstants.GENERIC_VNF_PROV_STATUS, "inactive"));
- assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+ assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
.isInstanceOf(IllegalStateException.class);
}
@@ -578,15 +580,15 @@ public class UsecasesEventManagerTest {
for (String value : Arrays.asList("yes", "y", "true", "t", "yEs", "trUe")) {
event.setAai(addAai(orig, UsecasesConstants.VSERVER_IS_CLOSED_LOOP_DISABLED, value));
- assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+ assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
.isInstanceOf(IllegalStateException.class);
}
event.setAai(addAai(orig, UsecasesConstants.VSERVER_IS_CLOSED_LOOP_DISABLED, "false"));
- assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+ assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
event.setAai(addAai(orig, UsecasesConstants.VSERVER_IS_CLOSED_LOOP_DISABLED, "no"));
- assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+ assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
}
@@ -665,10 +667,10 @@ public class UsecasesEventManagerTest {
private class MyManager extends UsecasesEventManager {
private static final long serialVersionUID = 1L;
- public MyManager(ControlLoopParams params, VirtualControlLoopEvent event, WorkingMemory workMem)
- throws ControlLoopException {
+ public MyManager(EventManagerServices services, ControlLoopParams params, VirtualControlLoopEvent event,
+ WorkingMemory workMem) throws ControlLoopException {
- super(params, event, workMem);
+ super(services, params, event, workMem);
}
@Override
@@ -684,16 +686,6 @@ public class UsecasesEventManagerTest {
}
@Override
- public ActorService getActorService() {
- return actors;
- }
-
- @Override
- public OperationHistoryDataManager getDataManager() {
- return dataMgr;
- }
-
- @Override
protected PolicyEngine getPolicyEngineManager() {
return engineMgr;
}