diff options
Diffstat (limited to 'controlloop/common/eventmanager/src')
7 files changed, 75 insertions, 72 deletions
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java index 16cf527d5..1f6dfdca3 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.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. @@ -85,14 +85,14 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana /** * Number of records that have been inserted into the DB by this data manager - * instance, whether or not they were committed. + * instance, whether they were committed. */ @Getter private long recordsInserted = 0; /** * Number of records that have been updated within the DB by this data manager - * instance, whether or not they were committed. + * instance, whether they were committed. */ @Getter private long recordsUpdated = 0; @@ -317,7 +317,6 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana props.put("jakarta.persistence.jdbc.url", params.getUrl()); props.put("jakarta.persistence.jdbc.user", params.getUserName()); props.put("jakarta.persistence.jdbc.password", params.getPassword()); - props.put("hibernate.dialect", params.getDbHibernateDialect()); return props; } @@ -337,6 +336,8 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana // the following may be overridden by junit tests protected EntityManagerFactory makeEntityManagerFactory(String opsHistPu, Properties props) { + logger.info("Starting persistence unit {}", opsHistPu); + logger.info("Properties {}", props); return Persistence.createEntityManagerFactory(opsHistPu, props); } diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerParams.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerParams.java index 054f4b1c1..1ea83761c 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerParams.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerParams.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. @@ -42,7 +42,6 @@ import org.onap.policy.common.parameters.annotations.NotNull; public class OperationHistoryDataManagerParams { public static final String DEFAULT_PU = "OperationsHistoryPU"; public static final String DEFAULT_DRIVER = "org.mariadb.jdbc.Driver"; - public static final String DEFAULT_TYPE = "MariaDB"; @NotBlank private String url; @@ -58,9 +57,6 @@ public class OperationHistoryDataManagerParams { @Builder.Default private String driver = DEFAULT_DRIVER; - @Builder.Default - private String dbType = DEFAULT_TYPE; - /** * Maximum number of records that can be waiting to be inserted into the DB. When the * limit is reached, the oldest records are discarded. @@ -86,12 +82,4 @@ public class OperationHistoryDataManagerParams { public ValidationResult validate(String resultName) { return new BeanValidator().validateTop(resultName, this); } - - /** - * Return the Hibernate dialect for the database type. - * @return the dialect - */ - public Object getDbHibernateDialect() { - return "org.hibernate.dialect." + dbType + "Dialect"; - } } 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..9a3e03488 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="none"/> + <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..397c1c5fe 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,14 @@ 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()) + .driver("org.h2.Driver") + .userName("sa") + .password("") + .persistenceUnit("OperationsHistoryTest") + .batchSize(BATCH_SIZE) + .maxQueueLength(MAX_QUEUE_LENGTH); } /** diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerParamsTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerParamsTest.java index f0159aaff..623df93d0 100644 --- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerParamsTest.java +++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerParamsTest.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. @@ -38,7 +38,6 @@ class OperationHistoryDataManagerParamsTest { private static final String MY_PASS = "my-pass"; private static final String MY_PU = "my-pu"; private static final String MY_DRIVER = "my-driver"; - private static final String MY_DB_TYPE = "my-db-type"; private static final String MY_URL = "my-url"; private static final String MY_USER = "my-user"; @@ -56,7 +55,6 @@ class OperationHistoryDataManagerParamsTest { assertEquals(MY_PASS, params.getPassword()); assertEquals(OperationHistoryDataManagerParams.DEFAULT_PU, params.getPersistenceUnit()); assertEquals(OperationHistoryDataManagerParams.DEFAULT_DRIVER, params.getDriver()); - assertEquals(OperationHistoryDataManagerParams.DEFAULT_TYPE, params.getDbType()); assertEquals(MY_URL, params.getUrl()); assertEquals(MY_USER, params.getUserName()); @@ -65,9 +63,6 @@ class OperationHistoryDataManagerParamsTest { // use specified driver assertEquals(MY_DRIVER, makeBuilder().driver(MY_DRIVER).build().getDriver()); - - // use specified DB type - assertEquals(MY_DB_TYPE, makeBuilder().dbType(MY_DB_TYPE).build().getDbType()); } @Test @@ -79,7 +74,6 @@ class OperationHistoryDataManagerParamsTest { testValidateField("password", "null", params2 -> params2.setPassword(null)); testValidateField("persistenceUnit", "null", params2 -> params2.setPersistenceUnit(null)); testValidateField("driver", "null", params2 -> params2.setDriver(null)); - testValidateField("dbType", "null", params2 -> params2.setDbType(null)); // check edge cases params.setBatchSize(0); 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> |