PostgreSQL support for Drools 85/138785/1
authoradheli.tavares <adheli.tavares@est.tech>
Thu, 15 Aug 2024 10:11:48 +0000 (11:11 +0100)
committeradheli.tavares <adheli.tavares@est.tech>
Thu, 15 Aug 2024 10:12:43 +0000 (11:12 +0100)
- change hardcoded values to be configurable.

Issue-ID: POLICY-5107
Change-Id: I2176cb136c6a5d9cdf6153730e209418dec7bc3c
Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java
controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerParams.java
controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml
controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImplTest.java
controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerParamsTest.java
controlloop/common/feature-controlloop-management/src/main/feature/config/event-manager.properties

index 16cf527..1f6dfdc 100644 (file)
@@ -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);
     }
 
index 054f4b1..1ea8376 100644 (file)
@@ -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";
-    }
 }
index fd0ab08..9a3e034 100644 (file)
@@ -27,7 +27,7 @@
         <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="jakarta.persistence.schema-generation.database.action" value="none"/>
             <property name="hibernate.show_sql" value="false"/>
         </properties>
     </persistence-unit>
index a9d05bd..397c1c5 100644 (file)
@@ -387,7 +387,6 @@ class OperationHistoryDataManagerImplTest {
     private static OperationHistoryDataManagerParamsBuilder makeBuilder() {
         return OperationHistoryDataManagerParams.builder()
             .url("jdbc:h2:mem:" + OperationHistoryDataManagerImplTest.class.getSimpleName())
-            .dbType("H2")
             .driver("org.h2.Driver")
             .userName("sa")
             .password("")
index f0159aa..623df93 100644 (file)
@@ -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);
index 7124989..96d2f9a 100644 (file)
 operation.history.url=${envd:JDBC_URL}operationshistory${envd:JDBC_OPTS}
 operation.history.userName=${envd:SQL_USER}
 operation.history.password=${envd:SQL_PASSWORD}
+operation.history.driver=${envd:JDBC_DRIVER}
 
 #
 # Actor parameters
 #
 # Note: every operation must have at least one entry, otherwise it will not be
-# configured and started.  Thus some of them have a "placeholder" property.
+# configured and started. Thus, some of them have a "placeholder" property.
 #
 
 actor.service.XACML.disabled=${envd:GUARD_DISABLED:false}