aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager
diff options
context:
space:
mode:
authoradheli.tavares <adheli.tavares@est.tech>2024-08-01 14:12:40 +0100
committeradheli.tavares <adheli.tavares@est.tech>2024-08-01 14:14:14 +0100
commit2e39e09b57e1d9484a5e0475653a1b4e7a1ec5b1 (patch)
tree1c350f0dffc7c7ce65fd42d3df16c346d64f781b /controlloop/common/eventmanager
parent24a68dcd259ab23b102fa99b44edfc3a5994446c (diff)
Fix Drools-Apps executing policies
- hibernate dependencies were causing conflicts; updated to latest hibernate-core with all the required deps. - adjusted some variables to be correctly read by properties parser. - added STDOUT option to logback.xml to be able to get logs from controllers/features when using docker logs command. Issue-ID: POLICY-4955 Change-Id: I254502e75332070c7d32f555927dc30c4bbb49a5 Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'controlloop/common/eventmanager')
-rw-r--r--controlloop/common/eventmanager/pom.xml5
-rw-r--r--controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml13
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithEventTest.java40
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImplTest.java31
-rw-r--r--controlloop/common/eventmanager/src/test/resources/META-INF/persistence.xml33
5 files changed, 69 insertions, 53 deletions
diff --git a/controlloop/common/eventmanager/pom.xml b/controlloop/common/eventmanager/pom.xml
index 2e7b0a497..c67021c47 100644
--- a/controlloop/common/eventmanager/pom.xml
+++ b/controlloop/common/eventmanager/pom.xml
@@ -37,11 +37,6 @@
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
-
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-core-jakarta</artifactId>
- </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
diff --git a/controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml b/controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml
index e55fda222..fd0ab088b 100644
--- a/controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml
+++ b/controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml
@@ -4,7 +4,7 @@
drools-applications
================================================================================
Copyright (C) 2018-2021 AT&T Intellectual Property. All rights reserved.
- Modifications Copyright (C) 2023 Nordix Foundation.
+ Modifications Copyright (C) 2023-2024 Nordix Foundation.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -19,19 +19,16 @@
limitations under the License.
============LICENSE_END=========================================================
-->
-<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
+<persistence version="3.1" xmlns="https://jakarta.ee/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"
- version="3.0">
+ xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_1.xsd">
<persistence-unit name="OperationsHistoryPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>org.onap.policy.guard.OperationsHistory</class>
-
<properties>
- <property name="jakarta.persistence.schema-generation.database.action" value="create" />
- <property name="hibernate.dialect" value="org.hibernate.dialect.MariaDBDialect" />
- <property name="hibernate.show_sql" value="false" />
+ <property name="jakarta.persistence.schema-generation.database.action" value="create"/>
+ <property name="hibernate.show_sql" value="false"/>
</properties>
</persistence-unit>
</persistence>
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithEventTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithEventTest.java
index 3b16f465b..6b60ec84c 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithEventTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithEventTest.java
@@ -3,7 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2021, 2023 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2023-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -55,12 +55,9 @@ import org.onap.policy.controlloop.ControlLoopTargetType;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.VirtualControlLoopNotification;
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.OperationResult;
-import org.onap.policy.controlloop.actorserviceprovider.Operator;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
-import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
import org.onap.policy.controlloop.eventmanager.ClEventManagerWithEvent.NewEventStatus;
import org.onap.policy.controlloop.ophistory.OperationHistoryDataManager;
@@ -82,27 +79,21 @@ class ClEventManagerWithEventTest {
private static final String TARGET_PROP = "my-target-property";
private static final String MY_TARGET = "my-target";
private static final String EVENT_MGR_MULTI_YAML =
- "../eventmanager/src/test/resources/eventManager/event-mgr-multi.yaml";
+ "../eventmanager/src/test/resources/eventManager/event-mgr-multi.yaml";
private static final String EVENT_MGR_SIMPLE_YAML =
- "../eventmanager/src/test/resources/eventManager/event-mgr-simple.yaml";
+ "../eventmanager/src/test/resources/eventManager/event-mgr-simple.yaml";
private static final Coder yamlCoder = new StandardYamlCoder();
private static final String OUTCOME_MSG = "my outcome message";
private final PolicyEngine engineMgr = mock(PolicyEngine.class);
private final WorkingMemory workMem = mock(WorkingMemory.class);
private final InternalFactHandle factHandle = mock(InternalFactHandle.class);
- private final Operator policyOperator = mock(Operator.class);
- private final Operation policyOperation = mock(Operation.class);
- private final Actor policyActor = mock(Actor.class);
private final EventManagerServices services = mock(EventManagerServices.class);
private final ActorService actors = mock(ActorService.class);
private final OperationHistoryDataManager dataMgr = mock(OperationHistoryDataManager.class);
private final ExecutorService executor = mock(ExecutorService.class);
- private final MyStep stepa = mock(MyStep.class);
- private final MyStep stepb = mock(MyStep.class);
private List<LockImpl> locks;
- private ToscaPolicy tosca;
private ControlLoopParams params;
private VirtualControlLoopEvent event;
private ClEventManagerWithEvent<MyStep> mgr;
@@ -149,7 +140,7 @@ class ClEventManagerWithEventTest {
// invalid
event.setTarget("");
assertThatThrownBy(() -> new MyManager(services, params, event, workMem))
- .isInstanceOf(ControlLoopException.class);
+ .isInstanceOf(ControlLoopException.class);
}
@Test
@@ -209,7 +200,7 @@ class ClEventManagerWithEventTest {
// null case
assertThatThrownBy(() -> mgr.loadNextPolicy(null)).isInstanceOf(NullPointerException.class)
- .hasMessageContaining("lastResult");
+ .hasMessageContaining("lastResult");
}
@Test
@@ -218,10 +209,12 @@ class ClEventManagerWithEventTest {
OperationOutcome outcome = makeOutcome();
mgr.addToHistory(outcome);
- mgr.storeInDataBase(mgr.getPartialHistory().peekLast(), MY_TARGET);
+ var peeked = mgr.getPartialHistory().peekLast();
+ assertNotNull(peeked);
+ mgr.storeInDataBase(peeked, MY_TARGET);
verify(dataMgr).store(REQ_ID.toString(), event.getClosedLoopControlName(), event, MY_TARGET,
- mgr.getPartialHistory().peekLast().getClOperation());
+ peeked.getClOperation());
}
@Test
@@ -265,7 +258,7 @@ class ClEventManagerWithEventTest {
event.setTarget(null);
assertThatCode(() -> mgr.checkEventSyntax(event)).isInstanceOf(ControlLoopException.class)
- .hasMessage("No target field");
+ .hasMessage("No target field");
// abated supersedes previous errors - so it shouldn't throw an exception
event.setClosedLoopEventStatus(ControlLoopEventStatus.ABATED);
@@ -273,11 +266,11 @@ class ClEventManagerWithEventTest {
event.setRequestId(null);
assertThatCode(() -> mgr.checkEventSyntax(event)).isInstanceOf(ControlLoopException.class)
- .hasMessage("No request ID");
+ .hasMessage("No request ID");
event.setClosedLoopControlName(null);
assertThatCode(() -> mgr.checkEventSyntax(event)).isInstanceOf(ControlLoopException.class)
- .hasMessage("No control loop name");
+ .hasMessage("No control loop name");
}
@Test
@@ -290,13 +283,12 @@ class ClEventManagerWithEventTest {
event.setClosedLoopEventStatus(null);
assertThatCode(() -> mgr.checkEventSyntax(event)).isInstanceOf(ControlLoopException.class)
- .hasMessage("Invalid value in closedLoopEventStatus");
+ .hasMessage("Invalid value in closedLoopEventStatus");
}
private void loadPolicy(String fileName) throws CoderException {
- var template =
- yamlCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
- tosca = template.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next();
+ var template = yamlCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
+ ToscaPolicy tosca = template.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next();
params.setToscaPolicy(tosca);
}
@@ -325,7 +317,7 @@ class ClEventManagerWithEventTest {
private static final long serialVersionUID = 1L;
public MyManager(EventManagerServices services, ControlLoopParams params, VirtualControlLoopEvent event,
- WorkingMemory workMem) throws ControlLoopException {
+ WorkingMemory workMem) throws ControlLoopException {
super(services, params, event, workMem);
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImplTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImplTest.java
index 22cfa643d..a9d05bdaf 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImplTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImplTest.java
@@ -3,7 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2023-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -151,8 +151,8 @@ class OperationHistoryDataManagerImplTest {
// invalid properties
params.setUrl(null);
- assertThatCode(() -> new PseudoThread()).isInstanceOf(IllegalArgumentException.class)
- .hasMessageContaining("data-manager-properties");
+ assertThatCode(PseudoThread::new).isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining("data-manager-properties");
}
@Test
@@ -192,7 +192,7 @@ class OperationHistoryDataManagerImplTest {
* Tests store() when it is already stopped.
*/
@Test
- void testStoreAlreadyStopped() throws InterruptedException {
+ void testStoreAlreadyStopped() {
mgr.stop();
// store
@@ -202,7 +202,7 @@ class OperationHistoryDataManagerImplTest {
}
/**
- * Tests store() when when the queue is full.
+ * Tests store() when the queue is full.
*/
@Test
void testStoreTooManyItems() throws InterruptedException {
@@ -217,7 +217,7 @@ class OperationHistoryDataManagerImplTest {
}
@Test
- void testRun() throws InterruptedException {
+ void testRun() {
// trigger thread shutdown when it completes this batch
when(emfSpy.createEntityManager()).thenAnswer(ans -> {
@@ -248,7 +248,7 @@ class OperationHistoryDataManagerImplTest {
* Tests run() when the entity manager throws an exception.
*/
@Test
- void testRunException() throws InterruptedException {
+ void testRunException() {
var count = new AtomicInteger(0);
when(emfSpy.createEntityManager()).thenAnswer(ans -> {
@@ -385,16 +385,15 @@ class OperationHistoryDataManagerImplTest {
}
private static OperationHistoryDataManagerParamsBuilder makeBuilder() {
- // @formatter:off
return OperationHistoryDataManagerParams.builder()
- .url("jdbc:h2:mem:" + OperationHistoryDataManagerImplTest.class.getSimpleName())
- .dbType("H2")
- .driver("org.h2.Driver")
- .userName("sa")
- .password("")
- .batchSize(BATCH_SIZE)
- .maxQueueLength(MAX_QUEUE_LENGTH);
- // @formatter:on
+ .url("jdbc:h2:mem:" + OperationHistoryDataManagerImplTest.class.getSimpleName())
+ .dbType("H2")
+ .driver("org.h2.Driver")
+ .userName("sa")
+ .password("")
+ .persistenceUnit("OperationsHistoryTest")
+ .batchSize(BATCH_SIZE)
+ .maxQueueLength(MAX_QUEUE_LENGTH);
}
/**
diff --git a/controlloop/common/eventmanager/src/test/resources/META-INF/persistence.xml b/controlloop/common/eventmanager/src/test/resources/META-INF/persistence.xml
new file mode 100644
index 000000000..f053f4fcb
--- /dev/null
+++ b/controlloop/common/eventmanager/src/test/resources/META-INF/persistence.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============LICENSE_START=======================================================
+ drools-applications
+ ================================================================================
+ Copyright (C) 2024 Nordix Foundation.
+ ================================================================================
+ 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=========================================================
+ -->
+<persistence version="3.1" xmlns="https://jakarta.ee/xml/ns/persistence"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_1.xsd">
+
+ <persistence-unit name="OperationsHistoryTest" transaction-type="RESOURCE_LOCAL">
+ <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
+ <class>org.onap.policy.guard.OperationsHistory</class>
+ <properties>
+ <property name="jakarta.persistence.schema-generation.database.action" value="drop-and-create"/>
+ <property name="hibernate.show_sql" value="false"/>
+ </properties>
+ </persistence-unit>
+</persistence>