aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2023-02-02 14:53:43 +0000
committerliamfallon <liam.fallon@est.tech>2023-02-02 18:03:35 +0000
commit70ddcbe8e34eda99a7e6e9f383cc78a0d6f0cbd2 (patch)
tree491c8cbafdea48b8e9d82e003488572fd9317883
parent0d52472a24ba317d6c96fcd215c7f2a2b6bd43f8 (diff)
Replace Eclipselink with Hibernate
Issue-ID: POLICY-4533 Change-Id: Ica9b02be76ba45461e615e806d779b0799681680 Signed-off-by: liamfallon <liam.fallon@est.tech>
-rw-r--r--controlloop/common/controller-usecases/src/test/resources/config/event-manager.properties3
-rw-r--r--controlloop/common/eventmanager/pom.xml7
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java34
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerParams.java11
-rw-r--r--controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml25
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImplTest.java3
-rw-r--r--controlloop/common/eventmanager/src/test/resources/eventService/event-svc-with-db.properties3
7 files changed, 49 insertions, 37 deletions
diff --git a/controlloop/common/controller-usecases/src/test/resources/config/event-manager.properties b/controlloop/common/controller-usecases/src/test/resources/config/event-manager.properties
index 5ec8c578f..ad5599142 100644
--- a/controlloop/common/controller-usecases/src/test/resources/config/event-manager.properties
+++ b/controlloop/common/controller-usecases/src/test/resources/config/event-manager.properties
@@ -3,6 +3,7 @@
# ONAP
# ===============================================================================
# Copyright (C) 2020-2022 AT&T Intellectual Property. All rights reserved.
+# Modifications Copyright (C) 2023 Nordix Foundation.
# ===============================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -22,6 +23,8 @@
operation.history.url=jdbc:h2:mem:Usecases
operation.history.userName=sa
operation.history.password=
+operation.history.driver=org.h2.Driver
+operation.history.dbType=H2
# Actor parameters
#
diff --git a/controlloop/common/eventmanager/pom.xml b/controlloop/common/eventmanager/pom.xml
index a0be107fd..dd2a42028 100644
--- a/controlloop/common/eventmanager/pom.xml
+++ b/controlloop/common/eventmanager/pom.xml
@@ -3,7 +3,7 @@
eventmanager
================================================================================
Copyright (C) 2017-2022 AT&T Intellectual Property. All rights reserved.
- Modifications Copyright (C) 2019 Nordix Foundation.
+ Modifications Copyright (C) 2019,2023 Nordix Foundation.
Modifications Copyright (C) 2019-2020 Bell Canada.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,9 +34,8 @@
<dependencies>
<dependency>
- <groupId>org.eclipse.persistence</groupId>
- <artifactId>org.eclipse.persistence.jpa</artifactId>
- <scope>provided</scope>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
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 2e18e8395..c36ca786d 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,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,7 +34,6 @@ import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
-import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.utils.jpa.EntityMgrCloser;
import org.onap.policy.common.utils.jpa.EntityTransCloser;
@@ -97,7 +97,6 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana
@Getter
private long recordsUpdated = 0;
-
/**
* Constructs the object.
*
@@ -149,11 +148,11 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana
@Override
public synchronized void store(String requestId, String clName, Object event, String targetEntity,
- ControlLoopOperation operation) {
+ ControlLoopOperation operation) {
if (stopped) {
logger.warn("operation history thread is stopped, discarding requestId={} event={} operation={}", requestId,
- event, operation);
+ event, operation);
return;
}
@@ -226,7 +225,7 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana
logger.info("store operation history record batch");
try (var emc = new EntityMgrCloser(entityManager);
- var trans = new EntityTransCloser(entityManager.getTransaction())) {
+ var trans = new EntityTransCloser(entityManager.getTransaction())) {
var nrecords = 0;
var rec = firstRecord;
@@ -261,13 +260,13 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana
logger.info("store operation history record for {}", reqId);
List<OperationsHistory> results = entityMgr
- .createQuery("select e from OperationsHistory e" + " where e.closedLoopName= ?1"
- + " and e.requestId= ?2" + " and e.subrequestId= ?3" + " and e.actor= ?4"
- + " and e.operation= ?5" + " and e.target= ?6", OperationsHistory.class)
- .setParameter(1, clName).setParameter(2, rec.getRequestId())
- .setParameter(3, operation.getSubRequestId()).setParameter(4, operation.getActor())
- .setParameter(5, operation.getOperation()).setParameter(6, rec.getTargetEntity())
- .getResultList();
+ .createQuery("select e from OperationsHistory e" + " where e.closedLoopName= ?1"
+ + " and e.requestId= ?2" + " and e.subrequestId= ?3" + " and e.actor= ?4"
+ + " and e.operation= ?5" + " and e.target= ?6", OperationsHistory.class)
+ .setParameter(1, clName).setParameter(2, rec.getRequestId())
+ .setParameter(3, operation.getSubRequestId()).setParameter(4, operation.getActor())
+ .setParameter(5, operation.getOperation()).setParameter(6, rec.getTargetEntity())
+ .getResultList();
if (results.size() > 1) {
logger.warn("unexpected operation history record count {} for {}", results.size(), reqId);
@@ -313,12 +312,11 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana
*/
private Properties toProperties(OperationHistoryDataManagerParams params) {
var props = new Properties();
- props.put(PersistenceUnitProperties.JDBC_DRIVER, params.getDriver());
- props.put(PersistenceUnitProperties.JDBC_URL, params.getUrl());
- props.put(PersistenceUnitProperties.JDBC_USER, params.getUserName());
- props.put(PersistenceUnitProperties.JDBC_PASSWORD, params.getPassword());
- props.put(PersistenceUnitProperties.TARGET_DATABASE, params.getDbType());
- props.put(PersistenceUnitProperties.CLASSLOADER, getClass().getClassLoader());
+ props.put("javax.persistence.jdbc.driver", params.getDriver());
+ props.put("javax.persistence.jdbc.url", params.getUrl());
+ props.put("javax.persistence.jdbc.user", params.getUserName());
+ props.put("javax.persistence.jdbc.password", params.getPassword());
+ props.put("hibernate.dialect", params.getDbHibernateDialect());
return 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 c93ac8b58..054f4b1c1 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,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,7 +42,7 @@ 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 = "MySQL";
+ public static final String DEFAULT_TYPE = "MariaDB";
@NotBlank
private String url;
@@ -85,4 +86,12 @@ 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 f5d313adc..115ec51ae 100644
--- a/controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml
+++ b/controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml
@@ -1,9 +1,10 @@
-<?xml version="1.0" encoding="UTF-8" ?>
+<?xml version="1.0" encoding="UTF-8"?>
<!--
============LICENSE_START=======================================================
drools-applications
================================================================================
Copyright (C) 2018-2021 AT&T Intellectual Property. All rights reserved.
+ Modifications Copyright (C) 2023 Nordix Foundation.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -18,19 +19,15 @@
limitations under the License.
============LICENSE_END=========================================================
-->
-<persistence version="2.1"
- xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
+<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
- <persistence-unit name="OperationsHistoryPU"
- transaction-type="RESOURCE_LOCAL">
- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
+ <persistence-unit name="OperationsHistoryPU" transaction-type="RESOURCE_LOCAL">
+ <class>org.onap.policy.guard.OperationsHistory</class>
- <class>org.onap.policy.guard.OperationsHistory</class>
-
- <properties>
- <property name="eclipselink.ddl-generation" value="create-or-extend-tables" />
- <property name="eclipselink.logging.level" value="WARNING" />
- </properties>
- </persistence-unit>
+ <properties>
+ <property name="javax.persistence.schema-generation.database.action" value="create" />
+ <property name="hibernate.dialect" value="org.hibernate.dialect.MariaDBDialect" />
+ <property name="hibernate.show_sql" value="false" />
+ </properties>
+ </persistence-unit>
</persistence>
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 9d32a85e1..a88014e27 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,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -392,6 +393,8 @@ public class OperationHistoryDataManagerImplTest {
// @formatter:off
return OperationHistoryDataManagerParams.builder()
.url("jdbc:h2:mem:" + OperationHistoryDataManagerImplTest.class.getSimpleName())
+ .dbType("H2")
+ .driver("org.h2.Driver")
.userName("sa")
.password("")
.batchSize(BATCH_SIZE)
diff --git a/controlloop/common/eventmanager/src/test/resources/eventService/event-svc-with-db.properties b/controlloop/common/eventmanager/src/test/resources/eventService/event-svc-with-db.properties
index c20f82b22..0d550bf98 100644
--- a/controlloop/common/eventmanager/src/test/resources/eventService/event-svc-with-db.properties
+++ b/controlloop/common/eventmanager/src/test/resources/eventService/event-svc-with-db.properties
@@ -3,6 +3,7 @@
# ONAP
# ===============================================================================
# Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+# Modifications Copyright (C) 2023 Nordix Foundation.
# ===============================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -28,3 +29,5 @@ actor.service.XACML.operations.Guard.path=decide
operation.history.url=jdbc:h2:mem:EventManagerServicesTest
operation.history.userName=sa
operation.history.password=
+operation.history.driver=org.h2.Driver
+operation.history.dbType=H2