From 2fa29d8632a6dc9fb855a732320b679d724f384f Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Wed, 9 Jan 2019 15:39:46 -0500 Subject: Remove policy/common integrity-audit suppressions Changed "DbDAO" to "DbDao". Change-Id: I51a6706cceef6857404ae7c12ce43e553ea0da29 Issue-ID: POLICY-1133 Signed-off-by: Jim Hahn --- integrity-audit/checkstyle-suppressions.xml | 30 - integrity-audit/pom.xml | 3 +- .../org/onap/policy/common/ia/AuditThread.java | 10 +- .../java/org/onap/policy/common/ia/DbAudit.java | 10 +- .../main/java/org/onap/policy/common/ia/DbDAO.java | 780 --------------------- .../main/java/org/onap/policy/common/ia/DbDao.java | 780 +++++++++++++++++++++ .../common/ia/DbAuditCompareEntriesTest.java | 24 +- .../org/onap/policy/common/ia/DbAuditTest.java | 28 +- .../java/org/onap/policy/common/ia/DbDAOTest.java | 460 ------------ .../java/org/onap/policy/common/ia/DbDaoTest.java | 460 ++++++++++++ .../common/ia/IntegrityAuditDesignationTest.java | 12 +- 11 files changed, 1283 insertions(+), 1314 deletions(-) delete mode 100644 integrity-audit/checkstyle-suppressions.xml delete mode 100644 integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java create mode 100644 integrity-audit/src/main/java/org/onap/policy/common/ia/DbDao.java delete mode 100644 integrity-audit/src/test/java/org/onap/policy/common/ia/DbDAOTest.java create mode 100644 integrity-audit/src/test/java/org/onap/policy/common/ia/DbDaoTest.java (limited to 'integrity-audit') diff --git a/integrity-audit/checkstyle-suppressions.xml b/integrity-audit/checkstyle-suppressions.xml deleted file mode 100644 index c97e4c22..00000000 --- a/integrity-audit/checkstyle-suppressions.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - diff --git a/integrity-audit/pom.xml b/integrity-audit/pom.xml index 95b0cd26..c662b3d5 100644 --- a/integrity-audit/pom.xml +++ b/integrity-audit/pom.xml @@ -2,7 +2,7 @@ ============LICENSE_START======================================================= ONAP Policy Engine - Common Modules ================================================================================ - Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -101,7 +101,6 @@ true - ${project.basedir}/checkstyle-suppressions.xml true true warning diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java index 51752329..2e996cdb 100644 --- a/integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java +++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * Integrity Audit * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -67,7 +67,7 @@ public class AuditThread extends Thread { /* * DB access class. */ - private DbDAO dbDao; + private DbDao dbDao; /* * E.g. pdp_xacml @@ -129,13 +129,13 @@ public class AuditThread extends Thread { this.integrityAudit = integrityAudit; /* - * The DbDAO Constructor registers this node in the IntegrityAuditEntity table. Each + * The DbDao Constructor registers this node in the IntegrityAuditEntity table. Each * resource (node) inserts its own name, persistenceUnit, DB access properties and other * pertinent properties in the table. This allows the audit on each node to compare its own * version of the entities for the persistenceUnit in question with the versions from all * other nodes of similar type. */ - dbDao = new DbDAO(this.resourceName, this.persistenceUnit, this.properties); + dbDao = new DbDao(this.resourceName, this.persistenceUnit, this.properties); this.nodeType = properties.getProperty(IntegrityAuditProperties.NODE_TYPE); } diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java index d7fbd749..14e0d33a 100644 --- a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java +++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Integrity Audit * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,14 +49,14 @@ public class DbAudit { private static final long DB_AUDIT_UPDATE_MS = 5000L; private static final long DB_AUDIT_SLEEP_MS = 2000L; - DbDAO dbDao = null; + DbDao dbDao = null; /** - * Construct an instance with the given DbDAO. + * Construct an instance with the given DbDao. * - * @param dbDao the DbDAO + * @param dbDao the DbDao */ - public DbAudit(DbDAO dbDao) { + public DbAudit(DbDao dbDao) { if (logger.isDebugEnabled()) { logger.debug("Constructor: Entering"); diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java deleted file mode 100644 index 611fda98..00000000 --- a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java +++ /dev/null @@ -1,780 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Integrity Audit - * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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========================================================= - */ - -package org.onap.policy.common.ia; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.EntityTransaction; -import javax.persistence.LockTimeoutException; -import javax.persistence.Persistence; -import javax.persistence.PersistenceUnitUtil; -import javax.persistence.Query; -import javax.persistence.TypedQuery; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import javax.persistence.metamodel.ManagedType; -import javax.persistence.metamodel.Metamodel; -import org.onap.policy.common.ia.jpa.IntegrityAuditEntity; -import org.onap.policy.common.logging.flexlogger.FlexLogger; -import org.onap.policy.common.logging.flexlogger.Logger; - -/** - * class DbDAO provides the inteface to the DBs for the purpose of audits. - * - */ -public class DbDAO { - private static final Logger logger = FlexLogger.getLogger(DbDAO.class.getName()); - - private String resourceName; - private String persistenceUnit; - private String dbDriver; - private String dbUrl; - private String dbUser; - private String siteName; - private String nodeType; - private Properties properties = null; - - private EntityManagerFactory emf; - - /* - * Supports designation serialization. - */ - private static final Object lock = new Object(); - - /* - * Common strings. - */ - private static final String RESOURCE_MESSAGE = "Resource: "; - private static final String WITH_PERSISTENCE_MESSAGE = " with PersistenceUnit: "; - private static final String DBDAO_MESSAGE = "DbDAO: "; - private static final String ENCOUNTERED_MESSAGE = "ecountered a problem in execution: "; - - /* - * DB SELECT String. - */ - private static final String SELECT_STRING = "Select i from IntegrityAuditEntity i " - + "where i.resourceName=:rn and i.persistenceUnit=:pu"; - - /** - * DbDAO Constructor. - * - * @param resourceName the resource name - * @param persistenceUnit the persistence unit - * @param properties the properties - * @throws IntegrityAuditException if an error occurs - */ - public DbDAO(String resourceName, String persistenceUnit, Properties properties) throws IntegrityAuditException { - this(resourceName, persistenceUnit, properties, null); - } - - /** - * DbDAO Constructor. - * - * @param resourceName the resource name - * @param persistenceUnit the persistence unit - * @param properties the properties - * @param lastUpdateDate may be {@code null} - * @param altDbUrl may be {@code null} - * @throws IntegrityAuditException if an error occurs - */ - protected DbDAO(String resourceName, String persistenceUnit, Properties properties, String altDbUrl) - throws IntegrityAuditException { - logger.debug("DbDAO contructor: enter"); - - validateProperties(resourceName, persistenceUnit, properties); - - emf = Persistence.createEntityManagerFactory(persistenceUnit, properties); - - register(altDbUrl); - - logger.debug("DbDAO contructor: exit"); - } - - /** - * Release resources (i.e., the EntityManagerFactory). - */ - public void destroy() { - emf.close(); - } - - /** - * validateProperties will validate the properties. - * - * @param resourceName the rseource name - * @param persistenceUnit the persistence unit - * @param properties the properties - * @throws IntegrityAuditPropertiesException if an error occurs - */ - private void validateProperties(String resourceName, String persistenceUnit, Properties properties) - throws IntegrityAuditPropertiesException { - StringBuilder badparams = new StringBuilder(); - if (IntegrityAudit.parmsAreBad(resourceName, persistenceUnit, properties, badparams)) { - String msg = "DbDAO: Bad parameters: badparams" + badparams; - throw new IntegrityAuditPropertiesException(msg); - } - this.resourceName = resourceName; - this.persistenceUnit = persistenceUnit; - this.dbDriver = properties.getProperty(IntegrityAuditProperties.DB_DRIVER).trim(); - this.dbUrl = properties.getProperty(IntegrityAuditProperties.DB_URL).trim(); - this.dbUser = properties.getProperty(IntegrityAuditProperties.DB_USER).trim(); - this.siteName = properties.getProperty(IntegrityAuditProperties.SITE_NAME).trim(); - this.nodeType = properties.getProperty(IntegrityAuditProperties.NODE_TYPE).trim(); - this.properties = properties; - logger.debug("DbDAO.assignProperties: exit:" + "\nresourceName: " + this.resourceName + "\npersistenceUnit: " - + this.persistenceUnit + "\nproperties: " + this.properties); - } - - /** - * getAllMyEntries gets all the DB entries for a particular class. - * - * @param className the class name - * @return all the DB entries for the given class - */ - public Map getAllMyEntries(String className) { - logger.debug("getAllMyEntries: Entering, className=" + className); - HashMap resultMap = new HashMap<>(); - EntityManager em = emf.createEntityManager(); - try { - CriteriaBuilder cb = em.getCriteriaBuilder(); - CriteriaQuery cq = cb.createQuery(); - Root rootEntry = cq.from(Class.forName(className)); - CriteriaQuery all = cq.select(rootEntry); - TypedQuery allQuery = em.createQuery(all); - List objectList = allQuery.getResultList(); - // Now create the map - - PersistenceUnitUtil util = emf.getPersistenceUnitUtil(); - for (Object o : objectList) { - Object key = util.getIdentifier(o); - resultMap.put(key, o); - } - } catch (Exception e) { - logger.error("getAllEntries encountered exception: ", e); - } - em.close(); - logger.debug("getAllMyEntries: Exit, resultMap.keySet()=" + resultMap.keySet()); - return resultMap; - } - - /** - * getAllMyEntries gets all entries for a class. - * - * @param className the name of the class - * @param keySet the keys to get the entries for - * @return the map of requested entries - */ - public Map getAllMyEntries(String className, Set keySet) { - logger.debug("getAllMyEntries: Entering, className=" + className + ",\n keySet=" + keySet); - - HashMap resultMap = new HashMap<>(); - EntityManager em = emf.createEntityManager(); - try { - Class clazz = Class.forName(className); - for (Object key : keySet) { - Object entry = em.find(clazz, key); - resultMap.put(key, entry); - } - } catch (Exception e) { - logger.error("getAllMyEntries encountered exception: ", e); - } - em.close(); - - logger.debug("getAllMyEntries: Returning resultMap, size=" + resultMap.size()); - return resultMap; - } - - /** - * getAllEntries gets all entriesfor a particular persistence unit adn className. - * - * @param persistenceUnit the persistence unit - * @param properties the properties - * @param className the class name - * @return the map of entries - */ - public Map getAllEntries(String persistenceUnit, Properties properties, String className) { - - logger.debug("getAllEntries: Entering, persistenceUnit=" + persistenceUnit + ",\n className=" + className); - HashMap resultMap = new HashMap<>(); - - EntityManagerFactory theEmf = Persistence.createEntityManagerFactory(persistenceUnit, properties); - EntityManager em = theEmf.createEntityManager(); - try { - CriteriaBuilder cb = em.getCriteriaBuilder(); - CriteriaQuery cq = cb.createQuery(); - Root rootEntry = cq.from(Class.forName(className)); - CriteriaQuery all = cq.select(rootEntry); - TypedQuery allQuery = em.createQuery(all); - List objectList = allQuery.getResultList(); - - PersistenceUnitUtil util = theEmf.getPersistenceUnitUtil(); - for (Object o : objectList) { - Object key = util.getIdentifier(o); - resultMap.put(key, o); - } - } catch (Exception e) { - logger.error("getAllEntries encountered exception:", e); - } - em.close(); - theEmf.close(); - - logger.debug("getAllEntries: Returning resultMap, size=" + resultMap.size()); - - return resultMap; - } - - - /** - * getAllEntries gets all entries for a persistence unit. - * - * @param persistenceUnit the persistence unit - * @param properties the properties - * @param className the class name - * @param keySet the keys - * @return the map of entries - */ - - public Map getAllEntries(String persistenceUnit, Properties properties, String className, - Set keySet) { - logger.debug("getAllEntries: Entering, persistenceUnit=" + persistenceUnit + ",\n properties= " + properties - + ",\n className=" + className + ",\n keySet= " + keySet); - EntityManagerFactory theEmf = Persistence.createEntityManagerFactory(persistenceUnit, properties); - EntityManager em = theEmf.createEntityManager(); - HashMap resultMap = new HashMap<>(); - try { - Class clazz = Class.forName(className); - for (Object key : keySet) { - Object entry = em.find(clazz, key); - resultMap.put(key, entry); - } - } catch (Exception e) { - String msg = "getAllEntries encountered exception: " + e; - logger.error(msg, e); - } - em.close(); - theEmf.close(); - logger.debug("getAllEntries: Exit, resultMap, size=" + resultMap.size()); - return resultMap; - } - - /** - * getIntegrityAuditEntities() Get all the IntegrityAuditEntities for a particular persistence - * unit and node type. - * - * @param persistenceUnit the persistence unit - * @param nodeType the node type - * @return the list of IntegrityAuditEntity - * @throws DbDaoTransactionException if an error occurs - */ - @SuppressWarnings("unchecked") - public List getIntegrityAuditEntities(String persistenceUnit, String nodeType) - throws DbDaoTransactionException { - logger.debug("getIntegrityAuditEntities: Entering, persistenceUnit=" + persistenceUnit + ",\n nodeType= " - + nodeType); - try { - EntityManager em = emf.createEntityManager(); - // Start a transaction - EntityTransaction et = em.getTransaction(); - - et.begin(); - - // if IntegrityAuditEntity entry exists for resourceName and PU, update it. If not - // found, create a new entry - Query iaequery = em - .createQuery("Select i from IntegrityAuditEntity i where i.persistenceUnit=:pu and i.nodeType=:nt"); - iaequery.setParameter("pu", persistenceUnit); - iaequery.setParameter("nt", nodeType); - - List iaeList = iaequery.getResultList(); - - // commit transaction - et.commit(); - em.close(); - logger.debug("getIntegrityAuditEntities: Exit, iaeList=" + iaeList); - return iaeList; - } catch (Exception e) { - String msg = DBDAO_MESSAGE + "getIntegrityAuditEntities() " + ENCOUNTERED_MESSAGE; - logger.error(msg, e); - throw new DbDaoTransactionException(e); - } - - } - - /** - * getMyIntegrityAuditEntity() gets my IntegrityAuditEntity. - * - * @return the IntegrityAuditEntity - * @throws DbDaoTransactionException if an error occurs - */ - public IntegrityAuditEntity getMyIntegrityAuditEntity() throws DbDaoTransactionException { - try { - EntityManager em = emf.createEntityManager(); - - // Start a transaction - EntityTransaction et = em.getTransaction(); - - et.begin(); - - // if IntegrityAuditEntity entry exists for resourceName and PU, retrieve it - Query iaequery = em.createQuery( - SELECT_STRING); - iaequery.setParameter("rn", this.resourceName); - iaequery.setParameter("pu", this.persistenceUnit); - - @SuppressWarnings("rawtypes") - List iaeList = iaequery.getResultList(); - IntegrityAuditEntity iae = null; - - if (!iaeList.isEmpty()) { - // ignores multiple results - iae = (IntegrityAuditEntity) iaeList.get(0); - // refresh the object from DB in case cached data was returned - em.refresh(iae); - logger.info(RESOURCE_MESSAGE + this.resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit - + " exists"); - } else { - // If it does not exist, log an error - logger.error("Attempting to setLastUpdated" + " on an entry that does not exist: resource " - + this.resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit); - } - - // close the transaction - et.commit(); - // close the EntityManager - em.close(); - - return iae; - } catch (Exception e) { - String msg = DBDAO_MESSAGE + "setLastUpdated() " + ENCOUNTERED_MESSAGE; - logger.error(msg + e); - throw new DbDaoTransactionException(e); - } - } - - - /** - * getIntegrityAuditEntity() gets the IntegrityAuditEntity with a particular ID. - * - * @param id the ID - * @return the IntegrityAuditEntity - * @throws DbDaoTransactionException if an error occurs - */ - public IntegrityAuditEntity getIntegrityAuditEntity(long id) throws DbDaoTransactionException { - try { - EntityManager em = emf.createEntityManager(); - - // Start a transaction - EntityTransaction et = em.getTransaction(); - - et.begin(); - - IntegrityAuditEntity iae = em.find(IntegrityAuditEntity.class, id); - - et.commit(); - em.close(); - - return iae; - } catch (Exception e) { - String msg = DBDAO_MESSAGE + "getIntegrityAuditEntity() " + ENCOUNTERED_MESSAGE; - logger.error(msg + e); - throw new DbDaoTransactionException(e); - } - } - - /** - * getPersistenceClassNames() gets all the persistence class names. - * - * @return the persistence class names - */ - public Set getPersistenceClassNames() { - logger.debug("DbDAO: getPersistenceClassNames() entry"); - HashSet returnList = new HashSet<>(); - final Metamodel mm = emf.getMetamodel(); - logger.debug("\n" + persistenceUnit + " persistence unit classes:"); - for (final ManagedType managedType : mm.getManagedTypes()) { - Class clazz = managedType.getJavaType(); - logger.debug(" " + clazz.getSimpleName()); - returnList.add(clazz.getName()); // the full class name needed to make a query using jpa - } - logger.debug("DbDAO: getPersistenceClassNames() exit"); - return returnList; - } - - /** - * Register the IntegrityAudit instance. - * - * @param altDbUrl alternate DB URL to be placed into the record, or {@code null} to use the - * default - */ - private void register(String altDbUrl) throws DbDaoTransactionException { - try { - EntityManager em = emf.createEntityManager(); - - // Start a transaction - EntityTransaction et = em.getTransaction(); - - et.begin(); - - // if IntegrityAuditEntity entry exists for resourceName and PU, update it. If not - // found, create a new entry - Query iaequery = em.createQuery( - SELECT_STRING); - iaequery.setParameter("rn", this.resourceName); - iaequery.setParameter("pu", this.persistenceUnit); - - @SuppressWarnings("rawtypes") - List iaeList = iaequery.getResultList(); - IntegrityAuditEntity iae; - - // If it already exists, we just want to update the properties and lastUpdated date - if (!iaeList.isEmpty()) { - // ignores multiple results - iae = (IntegrityAuditEntity) iaeList.get(0); - // refresh the object from DB in case cached data was returned - em.refresh(iae); - logger.info(RESOURCE_MESSAGE + this.resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit - + " exists and entry be updated"); - } else { - // If it does not exist, we also must add teh resourceName, persistenceUnit and - // designated values - logger.info("Adding resource " + resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit - + " to IntegrityAuditEntity table"); - iae = new IntegrityAuditEntity(); - iae.setResourceName(this.resourceName); - iae.setPersistenceUnit(this.persistenceUnit); - iae.setDesignated(false); - } - // update/set properties in entry - iae.setSite(this.siteName); - iae.setNodeType(this.nodeType); - iae.setJdbcDriver(this.dbDriver); - iae.setJdbcPassword(properties.getProperty(IntegrityAuditProperties.DB_PWD).trim()); - iae.setJdbcUrl(altDbUrl == null ? this.dbUrl : altDbUrl); - iae.setJdbcUser(dbUser); - - em.persist(iae); - // flush to the DB - em.flush(); - - // commit transaction - et.commit(); - em.close(); - } catch (Exception e) { - String msg = DBDAO_MESSAGE + "register() " + "encountered a problem in execution: "; - logger.error(msg + e); - throw new DbDaoTransactionException(e); - } - - } - - public void setDesignated(boolean designated) throws DbDaoTransactionException { - setDesignated(this.resourceName, this.persistenceUnit, designated); - } - - /** - * Set designated. - * - * @param resourceName the resource name - * @param persistenceUnit the persistence unit - * @param desig true if is designated - * @throws DbDaoTransactionException if an error occurs - */ - public void setDesignated(String resourceName, String persistenceUnit, boolean desig) - throws DbDaoTransactionException { - logger.debug("setDesignated: enter, resourceName: " + resourceName + ", persistenceUnit: " + persistenceUnit - + ", designated: " + desig); - try { - - EntityManager em = emf.createEntityManager(); - - // Start a transaction - EntityTransaction et = em.getTransaction(); - - et.begin(); - - // if IntegrityAuditEntity entry exists for resourceName and PU, update it. If not - // found, create a new entry - Query iaequery = em.createQuery( - SELECT_STRING); - iaequery.setParameter("rn", resourceName); - iaequery.setParameter("pu", persistenceUnit); - - @SuppressWarnings("rawtypes") - List iaeList = iaequery.getResultList(); - IntegrityAuditEntity iae; - - if (!iaeList.isEmpty()) { - // ignores multiple results - iae = (IntegrityAuditEntity) iaeList.get(0); - // refresh the object from DB in case cached data was returned - em.refresh(iae); - logger.info(RESOURCE_MESSAGE + resourceName + WITH_PERSISTENCE_MESSAGE + persistenceUnit - + " exists and designated be updated"); - iae.setDesignated(desig); - - em.persist(iae); - // flush to the DB - em.flush(); - } else { - // If it does not exist, log an error - logger.error("Attempting to setDesignated(" + desig + ") on an entry that does not exist:" - + " resource " + resourceName + WITH_PERSISTENCE_MESSAGE + persistenceUnit); - } - - // close the transaction - et.commit(); - // close the EntityManager - em.close(); - } catch (Exception e) { - String msg = DBDAO_MESSAGE + "setDesignated() " + ENCOUNTERED_MESSAGE; - logger.error(msg + e); - throw new DbDaoTransactionException(e); - } - - } - - /** - * Set last updated. - * - * @throws DbDaoTransactionException if an error occurs - */ - public void setLastUpdated() throws DbDaoTransactionException { - logger.debug("setLastUpdated: enter, resourceName: " + this.resourceName + ", persistenceUnit: " - + this.persistenceUnit); - try { - EntityManager em = emf.createEntityManager(); - - // Start a transaction - EntityTransaction et = em.getTransaction(); - - et.begin(); - - // if IntegrityAuditEntity entry exists for resourceName and PU, update it. If not - // found, create a new entry - Query iaequery = em.createQuery( - SELECT_STRING); - iaequery.setParameter("rn", this.resourceName); - iaequery.setParameter("pu", this.persistenceUnit); - - @SuppressWarnings("rawtypes") - List iaeList = iaequery.getResultList(); - IntegrityAuditEntity iae; - - if (!iaeList.isEmpty()) { - // ignores multiple results - iae = (IntegrityAuditEntity) iaeList.get(0); - // refresh the object from DB in case cached data was returned - em.refresh(iae); - logger.info(RESOURCE_MESSAGE + this.resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit - + " exists and lastUpdated be updated"); - iae.setLastUpdated(AuditorTime.getInstance().getDate()); - - em.persist(iae); - // flush to the DB - em.flush(); - } else { - // If it does not exist, log an error - logger.error("Attempting to setLastUpdated" + " on an entry that does not exist:" + " resource " - + this.resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit); - } - - // close the transaction - et.commit(); - // close the EntityManager - em.close(); - } catch (Exception e) { - String msg = DBDAO_MESSAGE + "setLastUpdated() " + ENCOUNTERED_MESSAGE; - logger.error(msg + e); - throw new DbDaoTransactionException(e); - } - - } - - /** - * Normally this method should only be used in a JUnit test environment. Manually deletes all - * PDP records in droolspdpentity table. - */ - public int deleteAllIntegrityAuditEntities() throws DbDaoTransactionException { - - try { - - if (!IntegrityAudit.isUnitTesting()) { - String msg = DBDAO_MESSAGE + "deleteAllIntegrityAuditEntities() " - + "should only be invoked during JUnit testing"; - logger.error(msg); - throw new DbDaoTransactionException(msg); - } - - EntityManager em = emf.createEntityManager(); - // Start a transaction - EntityTransaction et = em.getTransaction(); - - et.begin(); - - // if IntegrityAuditEntity entry exists for resourceName and PU, update it. If not - // found, create a new entry - Query iaequery = em.createQuery("Delete from IntegrityAuditEntity"); - - int returnCode = iaequery.executeUpdate(); - - // commit transaction - et.commit(); - em.close(); - - logger.info("deleteAllIntegrityAuditEntities: returnCode=" + returnCode); - - return returnCode; - - } catch (Exception e) { - String msg = DBDAO_MESSAGE + "deleteAllIntegrityAuditEntities() " + "encountered a problem in execution: "; - logger.error(msg + e); - throw new DbDaoTransactionException(e); - } - - } - - /** - * Changes designation to specified resourceName - * - *

static lock object in conjunction with synchronized keyword ensures that designation - * changes are done serially within a resource. I.e. static lock ensures that multiple - * instantiations of DbDAO don't interleave changeDesignated() invocations and potentially - * produce simultaneous designations. - * - *

Optimistic locking (the default, versus pessimistic) is sufficient to avoid simultaneous - * designations from interleaved changeDesignated() invocations from different resources - * (entities), because it prevents "dirty" and "non-repeatable" reads. - * - *

See http://www.objectdb.com/api/java/jpa/LockModeType - * - *

and - * - *

http://stackoverflow.com/questions/2120248/how-to-synchronize-a-static- - * variable-among-threads-running-different-instances-o - */ - public void changeDesignated(String resourceName, String persistenceUnit, String nodeType) - throws DbDaoTransactionException { - - if (logger.isDebugEnabled()) { - logger.debug("changeDesignated: Entering, resourceName=" + resourceName + ", persistenceUnit=" - + persistenceUnit + ", nodeType=" + nodeType); - } - - long startTime = AuditorTime.getInstance().getMillis(); - - synchronized (lock) { - - EntityManager em = null; - try { - - em = emf.createEntityManager(); - em.getTransaction().begin(); - - /* - * Define query - */ - Query query = em.createQuery( - "Select i from IntegrityAuditEntity i where i.persistenceUnit=:pu and i.nodeType=:nt"); - query.setParameter("pu", persistenceUnit); - query.setParameter("nt", nodeType); - - /* - * Execute query using pessimistic write lock. This ensures that if anyone else is - * currently reading the records we'll throw a LockTimeoutException. - */ - @SuppressWarnings("unchecked") - List integrityAuditEntityList = query.getResultList(); - for (Object o : integrityAuditEntityList) { - if (o instanceof IntegrityAuditEntity) { - IntegrityAuditEntity integrityAuditEntity = (IntegrityAuditEntity) o; - if (integrityAuditEntity.getResourceName().equals(resourceName)) { - if (logger.isDebugEnabled()) { - logger.debug("changeDesignated: Designating resourceName=" - + integrityAuditEntity.getResourceName()); - } - integrityAuditEntity.setDesignated(true); - } else { - if (logger.isDebugEnabled()) { - logger.debug("changeDesignated: Removing designation from resourceName=" - + integrityAuditEntity.getResourceName()); - } - integrityAuditEntity.setDesignated(false); - } - } - } - - if (logger.isDebugEnabled()) { - logger.debug("changeDesignated: Committing designation to resourceName=" + resourceName); - } - em.getTransaction().commit(); - - /* - * If we get a LockTimeoutException, no harm done really. We'll probably be - * successful on the next attempt. The odds of another DbDAO instance on this entity - * or another entity attempting a simultaneous IntegrityAuditEntity table - * read/update are pretty slim (we're only in this method for two or three - * milliseconds) - */ - } catch (LockTimeoutException e) { - if (em != null) { - em.getTransaction().rollback(); - - String msg = "DbDAO: changeDesignated() caught LockTimeoutException, message=" - + e.getMessage(); - logger.error(msg + e); - throw new DbDaoTransactionException(msg, e); - } else { - String msg = "DbDAO: changeDesignated() caught LockTimeoutException, message=" - + e.getMessage() + ". Error rolling back transaction."; - logger.error(msg + e); - throw new DbDaoTransactionException(msg, e); - } - } catch (Exception e) { - if (em != null) { - em.getTransaction().rollback(); - - String msg = "DbDAO: changeDesignated() caught Exception, message=" + e.getMessage(); - logger.error(msg + e); - throw new DbDaoTransactionException(msg, e); - } else { - String msg = "DbDAO: changeDesignated() caught Exception, message=" - + e.getMessage() + ". Error rolling back transaction."; - logger.error(msg + e); - throw new DbDaoTransactionException(msg, e); - } - } - - } // end synchronized block - - if (logger.isDebugEnabled()) { - logger.debug("changeDesignated: Exiting; time expended=" - + (AuditorTime.getInstance().getMillis() - startTime) + "ms"); - } - - } - -} diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDao.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDao.java new file mode 100644 index 00000000..08243310 --- /dev/null +++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDao.java @@ -0,0 +1,780 @@ +/* + * ============LICENSE_START======================================================= + * Integrity Audit + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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========================================================= + */ + +package org.onap.policy.common.ia; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityTransaction; +import javax.persistence.LockTimeoutException; +import javax.persistence.Persistence; +import javax.persistence.PersistenceUnitUtil; +import javax.persistence.Query; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import javax.persistence.metamodel.ManagedType; +import javax.persistence.metamodel.Metamodel; +import org.onap.policy.common.ia.jpa.IntegrityAuditEntity; +import org.onap.policy.common.logging.flexlogger.FlexLogger; +import org.onap.policy.common.logging.flexlogger.Logger; + +/** + * class DbDao provides the inteface to the DBs for the purpose of audits. + * + */ +public class DbDao { + private static final Logger logger = FlexLogger.getLogger(DbDao.class.getName()); + + private String resourceName; + private String persistenceUnit; + private String dbDriver; + private String dbUrl; + private String dbUser; + private String siteName; + private String nodeType; + private Properties properties = null; + + private EntityManagerFactory emf; + + /* + * Supports designation serialization. + */ + private static final Object lock = new Object(); + + /* + * Common strings. + */ + private static final String RESOURCE_MESSAGE = "Resource: "; + private static final String WITH_PERSISTENCE_MESSAGE = " with PersistenceUnit: "; + private static final String DBDAO_MESSAGE = "DbDao: "; + private static final String ENCOUNTERED_MESSAGE = "ecountered a problem in execution: "; + + /* + * DB SELECT String. + */ + private static final String SELECT_STRING = "Select i from IntegrityAuditEntity i " + + "where i.resourceName=:rn and i.persistenceUnit=:pu"; + + /** + * DbDao Constructor. + * + * @param resourceName the resource name + * @param persistenceUnit the persistence unit + * @param properties the properties + * @throws IntegrityAuditException if an error occurs + */ + public DbDao(String resourceName, String persistenceUnit, Properties properties) throws IntegrityAuditException { + this(resourceName, persistenceUnit, properties, null); + } + + /** + * DbDao Constructor. + * + * @param resourceName the resource name + * @param persistenceUnit the persistence unit + * @param properties the properties + * @param lastUpdateDate may be {@code null} + * @param altDbUrl may be {@code null} + * @throws IntegrityAuditException if an error occurs + */ + protected DbDao(String resourceName, String persistenceUnit, Properties properties, String altDbUrl) + throws IntegrityAuditException { + logger.debug("DbDao contructor: enter"); + + validateProperties(resourceName, persistenceUnit, properties); + + emf = Persistence.createEntityManagerFactory(persistenceUnit, properties); + + register(altDbUrl); + + logger.debug("DbDao contructor: exit"); + } + + /** + * Release resources (i.e., the EntityManagerFactory). + */ + public void destroy() { + emf.close(); + } + + /** + * validateProperties will validate the properties. + * + * @param resourceName the rseource name + * @param persistenceUnit the persistence unit + * @param properties the properties + * @throws IntegrityAuditPropertiesException if an error occurs + */ + private void validateProperties(String resourceName, String persistenceUnit, Properties properties) + throws IntegrityAuditPropertiesException { + StringBuilder badparams = new StringBuilder(); + if (IntegrityAudit.parmsAreBad(resourceName, persistenceUnit, properties, badparams)) { + String msg = "DbDao: Bad parameters: badparams" + badparams; + throw new IntegrityAuditPropertiesException(msg); + } + this.resourceName = resourceName; + this.persistenceUnit = persistenceUnit; + this.dbDriver = properties.getProperty(IntegrityAuditProperties.DB_DRIVER).trim(); + this.dbUrl = properties.getProperty(IntegrityAuditProperties.DB_URL).trim(); + this.dbUser = properties.getProperty(IntegrityAuditProperties.DB_USER).trim(); + this.siteName = properties.getProperty(IntegrityAuditProperties.SITE_NAME).trim(); + this.nodeType = properties.getProperty(IntegrityAuditProperties.NODE_TYPE).trim(); + this.properties = properties; + logger.debug("DbDao.assignProperties: exit:" + "\nresourceName: " + this.resourceName + "\npersistenceUnit: " + + this.persistenceUnit + "\nproperties: " + this.properties); + } + + /** + * getAllMyEntries gets all the DB entries for a particular class. + * + * @param className the class name + * @return all the DB entries for the given class + */ + public Map getAllMyEntries(String className) { + logger.debug("getAllMyEntries: Entering, className=" + className); + HashMap resultMap = new HashMap<>(); + EntityManager em = emf.createEntityManager(); + try { + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery cq = cb.createQuery(); + Root rootEntry = cq.from(Class.forName(className)); + CriteriaQuery all = cq.select(rootEntry); + TypedQuery allQuery = em.createQuery(all); + List objectList = allQuery.getResultList(); + // Now create the map + + PersistenceUnitUtil util = emf.getPersistenceUnitUtil(); + for (Object o : objectList) { + Object key = util.getIdentifier(o); + resultMap.put(key, o); + } + } catch (Exception e) { + logger.error("getAllEntries encountered exception: ", e); + } + em.close(); + logger.debug("getAllMyEntries: Exit, resultMap.keySet()=" + resultMap.keySet()); + return resultMap; + } + + /** + * getAllMyEntries gets all entries for a class. + * + * @param className the name of the class + * @param keySet the keys to get the entries for + * @return the map of requested entries + */ + public Map getAllMyEntries(String className, Set keySet) { + logger.debug("getAllMyEntries: Entering, className=" + className + ",\n keySet=" + keySet); + + HashMap resultMap = new HashMap<>(); + EntityManager em = emf.createEntityManager(); + try { + Class clazz = Class.forName(className); + for (Object key : keySet) { + Object entry = em.find(clazz, key); + resultMap.put(key, entry); + } + } catch (Exception e) { + logger.error("getAllMyEntries encountered exception: ", e); + } + em.close(); + + logger.debug("getAllMyEntries: Returning resultMap, size=" + resultMap.size()); + return resultMap; + } + + /** + * getAllEntries gets all entriesfor a particular persistence unit adn className. + * + * @param persistenceUnit the persistence unit + * @param properties the properties + * @param className the class name + * @return the map of entries + */ + public Map getAllEntries(String persistenceUnit, Properties properties, String className) { + + logger.debug("getAllEntries: Entering, persistenceUnit=" + persistenceUnit + ",\n className=" + className); + HashMap resultMap = new HashMap<>(); + + EntityManagerFactory theEmf = Persistence.createEntityManagerFactory(persistenceUnit, properties); + EntityManager em = theEmf.createEntityManager(); + try { + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery cq = cb.createQuery(); + Root rootEntry = cq.from(Class.forName(className)); + CriteriaQuery all = cq.select(rootEntry); + TypedQuery allQuery = em.createQuery(all); + List objectList = allQuery.getResultList(); + + PersistenceUnitUtil util = theEmf.getPersistenceUnitUtil(); + for (Object o : objectList) { + Object key = util.getIdentifier(o); + resultMap.put(key, o); + } + } catch (Exception e) { + logger.error("getAllEntries encountered exception:", e); + } + em.close(); + theEmf.close(); + + logger.debug("getAllEntries: Returning resultMap, size=" + resultMap.size()); + + return resultMap; + } + + + /** + * getAllEntries gets all entries for a persistence unit. + * + * @param persistenceUnit the persistence unit + * @param properties the properties + * @param className the class name + * @param keySet the keys + * @return the map of entries + */ + + public Map getAllEntries(String persistenceUnit, Properties properties, String className, + Set keySet) { + logger.debug("getAllEntries: Entering, persistenceUnit=" + persistenceUnit + ",\n properties= " + properties + + ",\n className=" + className + ",\n keySet= " + keySet); + EntityManagerFactory theEmf = Persistence.createEntityManagerFactory(persistenceUnit, properties); + EntityManager em = theEmf.createEntityManager(); + HashMap resultMap = new HashMap<>(); + try { + Class clazz = Class.forName(className); + for (Object key : keySet) { + Object entry = em.find(clazz, key); + resultMap.put(key, entry); + } + } catch (Exception e) { + String msg = "getAllEntries encountered exception: " + e; + logger.error(msg, e); + } + em.close(); + theEmf.close(); + logger.debug("getAllEntries: Exit, resultMap, size=" + resultMap.size()); + return resultMap; + } + + /** + * getIntegrityAuditEntities() Get all the IntegrityAuditEntities for a particular persistence + * unit and node type. + * + * @param persistenceUnit the persistence unit + * @param nodeType the node type + * @return the list of IntegrityAuditEntity + * @throws DbDaoTransactionException if an error occurs + */ + @SuppressWarnings("unchecked") + public List getIntegrityAuditEntities(String persistenceUnit, String nodeType) + throws DbDaoTransactionException { + logger.debug("getIntegrityAuditEntities: Entering, persistenceUnit=" + persistenceUnit + ",\n nodeType= " + + nodeType); + try { + EntityManager em = emf.createEntityManager(); + // Start a transaction + EntityTransaction et = em.getTransaction(); + + et.begin(); + + // if IntegrityAuditEntity entry exists for resourceName and PU, update it. If not + // found, create a new entry + Query iaequery = em + .createQuery("Select i from IntegrityAuditEntity i where i.persistenceUnit=:pu and i.nodeType=:nt"); + iaequery.setParameter("pu", persistenceUnit); + iaequery.setParameter("nt", nodeType); + + List iaeList = iaequery.getResultList(); + + // commit transaction + et.commit(); + em.close(); + logger.debug("getIntegrityAuditEntities: Exit, iaeList=" + iaeList); + return iaeList; + } catch (Exception e) { + String msg = DBDAO_MESSAGE + "getIntegrityAuditEntities() " + ENCOUNTERED_MESSAGE; + logger.error(msg, e); + throw new DbDaoTransactionException(e); + } + + } + + /** + * getMyIntegrityAuditEntity() gets my IntegrityAuditEntity. + * + * @return the IntegrityAuditEntity + * @throws DbDaoTransactionException if an error occurs + */ + public IntegrityAuditEntity getMyIntegrityAuditEntity() throws DbDaoTransactionException { + try { + EntityManager em = emf.createEntityManager(); + + // Start a transaction + EntityTransaction et = em.getTransaction(); + + et.begin(); + + // if IntegrityAuditEntity entry exists for resourceName and PU, retrieve it + Query iaequery = em.createQuery( + SELECT_STRING); + iaequery.setParameter("rn", this.resourceName); + iaequery.setParameter("pu", this.persistenceUnit); + + @SuppressWarnings("rawtypes") + List iaeList = iaequery.getResultList(); + IntegrityAuditEntity iae = null; + + if (!iaeList.isEmpty()) { + // ignores multiple results + iae = (IntegrityAuditEntity) iaeList.get(0); + // refresh the object from DB in case cached data was returned + em.refresh(iae); + logger.info(RESOURCE_MESSAGE + this.resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit + + " exists"); + } else { + // If it does not exist, log an error + logger.error("Attempting to setLastUpdated" + " on an entry that does not exist: resource " + + this.resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit); + } + + // close the transaction + et.commit(); + // close the EntityManager + em.close(); + + return iae; + } catch (Exception e) { + String msg = DBDAO_MESSAGE + "setLastUpdated() " + ENCOUNTERED_MESSAGE; + logger.error(msg + e); + throw new DbDaoTransactionException(e); + } + } + + + /** + * getIntegrityAuditEntity() gets the IntegrityAuditEntity with a particular ID. + * + * @param id the ID + * @return the IntegrityAuditEntity + * @throws DbDaoTransactionException if an error occurs + */ + public IntegrityAuditEntity getIntegrityAuditEntity(long id) throws DbDaoTransactionException { + try { + EntityManager em = emf.createEntityManager(); + + // Start a transaction + EntityTransaction et = em.getTransaction(); + + et.begin(); + + IntegrityAuditEntity iae = em.find(IntegrityAuditEntity.class, id); + + et.commit(); + em.close(); + + return iae; + } catch (Exception e) { + String msg = DBDAO_MESSAGE + "getIntegrityAuditEntity() " + ENCOUNTERED_MESSAGE; + logger.error(msg + e); + throw new DbDaoTransactionException(e); + } + } + + /** + * getPersistenceClassNames() gets all the persistence class names. + * + * @return the persistence class names + */ + public Set getPersistenceClassNames() { + logger.debug("DbDao: getPersistenceClassNames() entry"); + HashSet returnList = new HashSet<>(); + final Metamodel mm = emf.getMetamodel(); + logger.debug("\n" + persistenceUnit + " persistence unit classes:"); + for (final ManagedType managedType : mm.getManagedTypes()) { + Class clazz = managedType.getJavaType(); + logger.debug(" " + clazz.getSimpleName()); + returnList.add(clazz.getName()); // the full class name needed to make a query using jpa + } + logger.debug("DbDao: getPersistenceClassNames() exit"); + return returnList; + } + + /** + * Register the IntegrityAudit instance. + * + * @param altDbUrl alternate DB URL to be placed into the record, or {@code null} to use the + * default + */ + private void register(String altDbUrl) throws DbDaoTransactionException { + try { + EntityManager em = emf.createEntityManager(); + + // Start a transaction + EntityTransaction et = em.getTransaction(); + + et.begin(); + + // if IntegrityAuditEntity entry exists for resourceName and PU, update it. If not + // found, create a new entry + Query iaequery = em.createQuery( + SELECT_STRING); + iaequery.setParameter("rn", this.resourceName); + iaequery.setParameter("pu", this.persistenceUnit); + + @SuppressWarnings("rawtypes") + List iaeList = iaequery.getResultList(); + IntegrityAuditEntity iae; + + // If it already exists, we just want to update the properties and lastUpdated date + if (!iaeList.isEmpty()) { + // ignores multiple results + iae = (IntegrityAuditEntity) iaeList.get(0); + // refresh the object from DB in case cached data was returned + em.refresh(iae); + logger.info(RESOURCE_MESSAGE + this.resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit + + " exists and entry be updated"); + } else { + // If it does not exist, we also must add teh resourceName, persistenceUnit and + // designated values + logger.info("Adding resource " + resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit + + " to IntegrityAuditEntity table"); + iae = new IntegrityAuditEntity(); + iae.setResourceName(this.resourceName); + iae.setPersistenceUnit(this.persistenceUnit); + iae.setDesignated(false); + } + // update/set properties in entry + iae.setSite(this.siteName); + iae.setNodeType(this.nodeType); + iae.setJdbcDriver(this.dbDriver); + iae.setJdbcPassword(properties.getProperty(IntegrityAuditProperties.DB_PWD).trim()); + iae.setJdbcUrl(altDbUrl == null ? this.dbUrl : altDbUrl); + iae.setJdbcUser(dbUser); + + em.persist(iae); + // flush to the DB + em.flush(); + + // commit transaction + et.commit(); + em.close(); + } catch (Exception e) { + String msg = DBDAO_MESSAGE + "register() " + "encountered a problem in execution: "; + logger.error(msg + e); + throw new DbDaoTransactionException(e); + } + + } + + public void setDesignated(boolean designated) throws DbDaoTransactionException { + setDesignated(this.resourceName, this.persistenceUnit, designated); + } + + /** + * Set designated. + * + * @param resourceName the resource name + * @param persistenceUnit the persistence unit + * @param desig true if is designated + * @throws DbDaoTransactionException if an error occurs + */ + public void setDesignated(String resourceName, String persistenceUnit, boolean desig) + throws DbDaoTransactionException { + logger.debug("setDesignated: enter, resourceName: " + resourceName + ", persistenceUnit: " + persistenceUnit + + ", designated: " + desig); + try { + + EntityManager em = emf.createEntityManager(); + + // Start a transaction + EntityTransaction et = em.getTransaction(); + + et.begin(); + + // if IntegrityAuditEntity entry exists for resourceName and PU, update it. If not + // found, create a new entry + Query iaequery = em.createQuery( + SELECT_STRING); + iaequery.setParameter("rn", resourceName); + iaequery.setParameter("pu", persistenceUnit); + + @SuppressWarnings("rawtypes") + List iaeList = iaequery.getResultList(); + IntegrityAuditEntity iae; + + if (!iaeList.isEmpty()) { + // ignores multiple results + iae = (IntegrityAuditEntity) iaeList.get(0); + // refresh the object from DB in case cached data was returned + em.refresh(iae); + logger.info(RESOURCE_MESSAGE + resourceName + WITH_PERSISTENCE_MESSAGE + persistenceUnit + + " exists and designated be updated"); + iae.setDesignated(desig); + + em.persist(iae); + // flush to the DB + em.flush(); + } else { + // If it does not exist, log an error + logger.error("Attempting to setDesignated(" + desig + ") on an entry that does not exist:" + + " resource " + resourceName + WITH_PERSISTENCE_MESSAGE + persistenceUnit); + } + + // close the transaction + et.commit(); + // close the EntityManager + em.close(); + } catch (Exception e) { + String msg = DBDAO_MESSAGE + "setDesignated() " + ENCOUNTERED_MESSAGE; + logger.error(msg + e); + throw new DbDaoTransactionException(e); + } + + } + + /** + * Set last updated. + * + * @throws DbDaoTransactionException if an error occurs + */ + public void setLastUpdated() throws DbDaoTransactionException { + logger.debug("setLastUpdated: enter, resourceName: " + this.resourceName + ", persistenceUnit: " + + this.persistenceUnit); + try { + EntityManager em = emf.createEntityManager(); + + // Start a transaction + EntityTransaction et = em.getTransaction(); + + et.begin(); + + // if IntegrityAuditEntity entry exists for resourceName and PU, update it. If not + // found, create a new entry + Query iaequery = em.createQuery( + SELECT_STRING); + iaequery.setParameter("rn", this.resourceName); + iaequery.setParameter("pu", this.persistenceUnit); + + @SuppressWarnings("rawtypes") + List iaeList = iaequery.getResultList(); + IntegrityAuditEntity iae; + + if (!iaeList.isEmpty()) { + // ignores multiple results + iae = (IntegrityAuditEntity) iaeList.get(0); + // refresh the object from DB in case cached data was returned + em.refresh(iae); + logger.info(RESOURCE_MESSAGE + this.resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit + + " exists and lastUpdated be updated"); + iae.setLastUpdated(AuditorTime.getInstance().getDate()); + + em.persist(iae); + // flush to the DB + em.flush(); + } else { + // If it does not exist, log an error + logger.error("Attempting to setLastUpdated" + " on an entry that does not exist:" + " resource " + + this.resourceName + WITH_PERSISTENCE_MESSAGE + this.persistenceUnit); + } + + // close the transaction + et.commit(); + // close the EntityManager + em.close(); + } catch (Exception e) { + String msg = DBDAO_MESSAGE + "setLastUpdated() " + ENCOUNTERED_MESSAGE; + logger.error(msg + e); + throw new DbDaoTransactionException(e); + } + + } + + /** + * Normally this method should only be used in a JUnit test environment. Manually deletes all + * PDP records in droolspdpentity table. + */ + public int deleteAllIntegrityAuditEntities() throws DbDaoTransactionException { + + try { + + if (!IntegrityAudit.isUnitTesting()) { + String msg = DBDAO_MESSAGE + "deleteAllIntegrityAuditEntities() " + + "should only be invoked during JUnit testing"; + logger.error(msg); + throw new DbDaoTransactionException(msg); + } + + EntityManager em = emf.createEntityManager(); + // Start a transaction + EntityTransaction et = em.getTransaction(); + + et.begin(); + + // if IntegrityAuditEntity entry exists for resourceName and PU, update it. If not + // found, create a new entry + Query iaequery = em.createQuery("Delete from IntegrityAuditEntity"); + + int returnCode = iaequery.executeUpdate(); + + // commit transaction + et.commit(); + em.close(); + + logger.info("deleteAllIntegrityAuditEntities: returnCode=" + returnCode); + + return returnCode; + + } catch (Exception e) { + String msg = DBDAO_MESSAGE + "deleteAllIntegrityAuditEntities() " + "encountered a problem in execution: "; + logger.error(msg + e); + throw new DbDaoTransactionException(e); + } + + } + + /** + * Changes designation to specified resourceName + * + *

static lock object in conjunction with synchronized keyword ensures that designation + * changes are done serially within a resource. I.e. static lock ensures that multiple + * instantiations of DbDao don't interleave changeDesignated() invocations and potentially + * produce simultaneous designations. + * + *

Optimistic locking (the default, versus pessimistic) is sufficient to avoid simultaneous + * designations from interleaved changeDesignated() invocations from different resources + * (entities), because it prevents "dirty" and "non-repeatable" reads. + * + *

See http://www.objectdb.com/api/java/jpa/LockModeType + * + *

and + * + *

http://stackoverflow.com/questions/2120248/how-to-synchronize-a-static- + * variable-among-threads-running-different-instances-o + */ + public void changeDesignated(String resourceName, String persistenceUnit, String nodeType) + throws DbDaoTransactionException { + + if (logger.isDebugEnabled()) { + logger.debug("changeDesignated: Entering, resourceName=" + resourceName + ", persistenceUnit=" + + persistenceUnit + ", nodeType=" + nodeType); + } + + long startTime = AuditorTime.getInstance().getMillis(); + + synchronized (lock) { + + EntityManager em = null; + try { + + em = emf.createEntityManager(); + em.getTransaction().begin(); + + /* + * Define query + */ + Query query = em.createQuery( + "Select i from IntegrityAuditEntity i where i.persistenceUnit=:pu and i.nodeType=:nt"); + query.setParameter("pu", persistenceUnit); + query.setParameter("nt", nodeType); + + /* + * Execute query using pessimistic write lock. This ensures that if anyone else is + * currently reading the records we'll throw a LockTimeoutException. + */ + @SuppressWarnings("unchecked") + List integrityAuditEntityList = query.getResultList(); + for (Object o : integrityAuditEntityList) { + if (o instanceof IntegrityAuditEntity) { + IntegrityAuditEntity integrityAuditEntity = (IntegrityAuditEntity) o; + if (integrityAuditEntity.getResourceName().equals(resourceName)) { + if (logger.isDebugEnabled()) { + logger.debug("changeDesignated: Designating resourceName=" + + integrityAuditEntity.getResourceName()); + } + integrityAuditEntity.setDesignated(true); + } else { + if (logger.isDebugEnabled()) { + logger.debug("changeDesignated: Removing designation from resourceName=" + + integrityAuditEntity.getResourceName()); + } + integrityAuditEntity.setDesignated(false); + } + } + } + + if (logger.isDebugEnabled()) { + logger.debug("changeDesignated: Committing designation to resourceName=" + resourceName); + } + em.getTransaction().commit(); + + /* + * If we get a LockTimeoutException, no harm done really. We'll probably be + * successful on the next attempt. The odds of another DbDao instance on this entity + * or another entity attempting a simultaneous IntegrityAuditEntity table + * read/update are pretty slim (we're only in this method for two or three + * milliseconds) + */ + } catch (LockTimeoutException e) { + if (em != null) { + em.getTransaction().rollback(); + + String msg = "DbDao: changeDesignated() caught LockTimeoutException, message=" + + e.getMessage(); + logger.error(msg + e); + throw new DbDaoTransactionException(msg, e); + } else { + String msg = "DbDao: changeDesignated() caught LockTimeoutException, message=" + + e.getMessage() + ". Error rolling back transaction."; + logger.error(msg + e); + throw new DbDaoTransactionException(msg, e); + } + } catch (Exception e) { + if (em != null) { + em.getTransaction().rollback(); + + String msg = "DbDao: changeDesignated() caught Exception, message=" + e.getMessage(); + logger.error(msg + e); + throw new DbDaoTransactionException(msg, e); + } else { + String msg = "DbDao: changeDesignated() caught Exception, message=" + + e.getMessage() + ". Error rolling back transaction."; + logger.error(msg + e); + throw new DbDaoTransactionException(msg, e); + } + } + + } // end synchronized block + + if (logger.isDebugEnabled()) { + logger.debug("changeDesignated: Exiting; time expended=" + + (AuditorTime.getInstance().getMillis() - startTime) + "ms"); + } + + } + +} diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditCompareEntriesTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditCompareEntriesTest.java index 6335482a..a5d0ef1b 100644 --- a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditCompareEntriesTest.java +++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditCompareEntriesTest.java @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * Integrity Audit * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,7 +52,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase { private static Logger logger = FlexLogger.getLogger(DbAuditCompareEntriesTest.class); - private DbDAO dbDao; + private DbDao dbDao; private static String resourceName = "pdp1"; @BeforeClass @@ -105,7 +105,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase { public void testSuccessfulComparison() throws Exception { logger.info("testSuccessfulComparison: Entering"); - dbDao = new DbDAO(resourceName, A_SEQ_PU, makeProperties()); + dbDao = new DbDao(resourceName, A_SEQ_PU, makeProperties()); final DbAudit dbAudit = new DbAudit(dbDao); String className = null; @@ -175,7 +175,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase { public void testComparisonError() throws Exception { logger.info("testComparisonError: Entering"); - dbDao = new DbDAO(resourceName, A_SEQ_PU, makeProperties()); + dbDao = new DbDao(resourceName, A_SEQ_PU, makeProperties()); final DbAudit dbAudit = new DbAudit(dbDao); final String resourceName1 = resourceName; @@ -235,7 +235,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase { public void testCompareMissingEntries() throws Exception { logger.info("testCompareMissingEntries: Entering"); - dbDao = new DbDAO(resourceName, A_SEQ_PU, makeProperties()); + dbDao = new DbDao(resourceName, A_SEQ_PU, makeProperties()); final DbAudit dbAudit = new DbAudit(dbDao); final String resourceName1 = resourceName; @@ -321,7 +321,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase { public void testCompareAllHashEntities() throws Exception { logger.info("testCompareAllHashEntities: Entering"); - dbDao = new DbDAO(resourceName, A_SEQ_PU, makeProperties()); + dbDao = new DbDao(resourceName, A_SEQ_PU, makeProperties()); DbAudit dbAudit = new DbAudit(dbDao); Set classNameSet = dbDao.getPersistenceClassNames(); @@ -442,13 +442,13 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase { truncateTables(properties2); // Add entries into DB1 - dbDao = new DbDAO(resourceName, A_SEQ_PU, properties); - new DbDAO("pdp2", A_SEQ_PU, properties).destroy(); + dbDao = new DbDao(resourceName, A_SEQ_PU, properties); + new DbDao("pdp2", A_SEQ_PU, properties).destroy(); DbAudit dbAudit = new DbAudit(dbDao); // Add entries into DB2 - DbDAO dbDao3 = new DbDAO(resourceName, A_SEQ_PU, properties2); - new DbDAO("pdp2", A_SEQ_PU, properties2).destroy(); + DbDao dbDao3 = new DbDao(resourceName, A_SEQ_PU, properties2); + new DbDao("pdp2", A_SEQ_PU, properties2).destroy(); // Pull all entries and compare Set classNameSet = dbDao.getPersistenceClassNames(); @@ -491,7 +491,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase { public void testEmbeddedClass() throws Exception { logger.info("testEmbeddedClasses: Entering"); - dbDao = new DbDAO(resourceName, A_SEQ_PU, properties); + dbDao = new DbDao(resourceName, A_SEQ_PU, properties); final DbAudit dbAudit = new DbAudit(dbDao); String className = null; diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditTest.java index 8e848787..836aa288 100644 --- a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditTest.java +++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Integrity Audit * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,7 +57,7 @@ public class DbAuditTest extends IntegrityAuditTestBase { private EntityManagerFactory emf2; private EntityManager em2; - private DbDAO dbDao; + private DbDao dbDao; @BeforeClass public static void setUpBeforeClass() throws Exception { @@ -135,7 +135,7 @@ public class DbAuditTest extends IntegrityAuditTestBase { logger.info("noEntitiesTest: Entering"); - dbDao = new DbDAO(resourceName, A_SEQ_PU, properties); + dbDao = new DbDao(resourceName, A_SEQ_PU, properties); dbDao.deleteAllIntegrityAuditEntities(); try { DbAudit dbAudit = new DbAudit(dbDao); @@ -161,7 +161,7 @@ public class DbAuditTest extends IntegrityAuditTestBase { final ExtractAppender log = watch(debugLogger, "DbAudit: Found only (one) IntegrityAuditEntity entry:"); // Add one entry in the database - dbDao = new DbDAO(resourceName, A_SEQ_PU, properties); + dbDao = new DbDao(resourceName, A_SEQ_PU, properties); DbAudit dbAudit = new DbAudit(dbDao); dbAudit.dbAudit(resourceName, A_SEQ_PU, nodeType); @@ -206,24 +206,24 @@ public class DbAuditTest extends IntegrityAuditTestBase { /* * Create entries in DB1 & DB2 for the resource of interest */ - dbDao = new DbDAO(resourceName, A_SEQ_PU, properties); + dbDao = new DbDao(resourceName, A_SEQ_PU, properties); - new DbDAO(resourceName, A_SEQ_PU, properties2).destroy(); + new DbDao(resourceName, A_SEQ_PU, properties2).destroy(); /* * Entries in DB1, pointing to DB2, except for pdp3 */ - new DbDAO("pdp2", A_SEQ_PU, properties, dbUrl2).destroy(); - new DbDAO("pdp1", A_SEQ_PU, properties, dbUrl2).destroy(); - new DbDAO("pdp3", A_SEQ_PU, properties).destroy(); // mismatched URL - new DbDAO("pdp4", A_SEQ_PU, properties, dbUrl2).destroy(); + new DbDao("pdp2", A_SEQ_PU, properties, dbUrl2).destroy(); + new DbDao("pdp1", A_SEQ_PU, properties, dbUrl2).destroy(); + new DbDao("pdp3", A_SEQ_PU, properties).destroy(); // mismatched URL + new DbDao("pdp4", A_SEQ_PU, properties, dbUrl2).destroy(); /* * Identical entries in DB2, all pointing to DB2, including pdp3, but leaving out pdp4 */ - new DbDAO("pdp2", A_SEQ_PU, properties2).destroy(); - new DbDAO("pdp1", A_SEQ_PU, properties2).destroy(); - new DbDAO("pdp3", A_SEQ_PU, properties2).destroy(); + new DbDao("pdp2", A_SEQ_PU, properties2).destroy(); + new DbDao("pdp1", A_SEQ_PU, properties2).destroy(); + new DbDao("pdp3", A_SEQ_PU, properties2).destroy(); /* * Run the DB Audit, once it finds a mismatch and sleeps, update DB1 to have the same entry @@ -233,7 +233,7 @@ public class DbAuditTest extends IntegrityAuditTestBase { dbAudit.dbAudit(resourceName, A_SEQ_PU, nodeType); // update pdp3 entry in DB1 to point to DB2 - new DbDAO("pdp3", A_SEQ_PU, properties, dbUrl2).destroy(); + new DbDao("pdp3", A_SEQ_PU, properties, dbUrl2).destroy(); /* * Run the audit again and correct the mismatch, the result should be one entry in the diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbDAOTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbDAOTest.java deleted file mode 100644 index 6e93529c..00000000 --- a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbDAOTest.java +++ /dev/null @@ -1,460 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Integrity Audit - * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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========================================================= - */ - -package org.onap.policy.common.ia; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -/* - * All JUnits are designed to run in the local development environment - * where they have write privileges and can execute time-sensitive - * tasks. - */ - -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - -import javax.persistence.PersistenceUnitUtil; -import javax.persistence.Query; -import javax.persistence.TypedQuery; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.onap.policy.common.ia.jpa.IntegrityAuditEntity; -import org.onap.policy.common.utils.jpa.EntityTransCloser; -import org.onap.policy.common.utils.time.TestTime; - -/* - * All JUnits are designed to run in the local development environment - * where they have write privileges and can execute time-sensitive - * tasks. - */ -public class DbDAOTest extends IntegrityAuditTestBase { - private static String resourceName = "pdp0"; - - private DbDAO dbDao; - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - IntegrityAuditTestBase.setUpBeforeClass(DEFAULT_DB_URL_PREFIX + DbDAOTest.class.getSimpleName()); - } - - @AfterClass - public static void tearDownAfterClass() { - IntegrityAuditTestBase.tearDownAfterClass(); - } - - @Override - @Before - public void setUp() { - super.setUp(); - dbDao = null; - } - - /** - * Tear down after test cases. - */ - @Override - @After - public void tearDown() { - if (dbDao != null) { - dbDao.destroy(); - } - - super.tearDown(); - } - - /* Tests registering a new IntegrityAuditEntity object in the DB */ - @Test - public void testNewRegistration() throws Exception { - Properties properties = makeProperties(); - - try (EntityTransCloser et = new EntityTransCloser(em.getTransaction())) { - dbDao = new DbDAO(resourceName, A_SEQ_PU, properties); - - // Find the proper entry in the database - Query iaequery = em.createQuery( - "Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu"); - iaequery.setParameter("rn", DbDAOTest.resourceName); - iaequery.setParameter("pu", DbDAOTest.A_SEQ_PU); - - @SuppressWarnings("rawtypes") - List iaeList = iaequery.getResultList(); - - // Assert that the IntegrityAuditEntity object was found - assertNotNull(iaeList); - - // flush to the DB - em.flush(); - et.commit(); - } - } - - /* - * Tests updating an IntegrityAuditEntity if it has already been registered - */ - @Test - public void testUpdateRegistration() throws Exception { - Properties properties = makeProperties(); - - dbDao = new DbDAO(resourceName, A_SEQ_PU, properties); - - // Change site_name in properties to test that an update was made to - // an existing entry in the table - properties.put(IntegrityAuditProperties.SITE_NAME, "SiteB"); - dbDao = new DbDAO(resourceName, A_SEQ_PU, properties); - - try (EntityTransCloser et = new EntityTransCloser(em.getTransaction())) { - // Find the proper entry in the database - Query iaequery = em.createQuery( - "Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu"); - iaequery.setParameter("rn", DbDAOTest.resourceName); - iaequery.setParameter("pu", DbDAOTest.A_SEQ_PU); - - @SuppressWarnings("rawtypes") - List iaeList = iaequery.getResultList(); - IntegrityAuditEntity iae = null; - if (!iaeList.isEmpty()) { - // ignores multiple results - iae = (IntegrityAuditEntity) iaeList.get(0); - - em.refresh(iae); - em.persist(iae); - - // flush to the DB - em.flush(); - - // commit transaction - et.commit(); - - // Assert that the site_name for the existing entry was updated - assertEquals("SiteB", iae.getSite()); - } - } - } - - /* Tests obtaining all Integrity Audit Entities from a table */ - @Test - public void testGetIntegrityAuditEntities() throws Exception { - Properties properties = makeProperties(); - - // Add some entries to the DB - dbDao = new DbDAO(resourceName, A_SEQ_PU, properties); - new DbDAO("pdp1", A_SEQ_PU, properties).destroy(); - properties.put(IntegrityAuditProperties.NODE_TYPE, "pdp_drools"); - new DbDAO("pdp2", A_SEQ_PU, properties).destroy(); - - List entities; - // Obtain entries based on persistenceUnit and nodeType - entities = dbDao.getIntegrityAuditEntities(A_SEQ_PU, "pdp_xacml"); - assertEquals(2, entities.size()); - } - - /* Tests retrieving a DbDAO instance's IntegrityAuditEntity */ - @Test - public void testGetMyIntegrityAuditEntity() throws Exception { - Properties properties = makeProperties(); - - dbDao = new DbDAO(resourceName, A_SEQ_PU, properties); - IntegrityAuditEntity iae = dbDao.getMyIntegrityAuditEntity(); - // assertEquals("integrityAuditPU", iae.getPersistenceUnit()); - assertEquals(A_SEQ_PU, iae.getPersistenceUnit()); - } - - /* Tests obtaining an IntegrityAuditEntity by ID */ - @Test - public void testGetIntegrityAuditEntity() throws Exception { - Properties properties = makeProperties(); - - // Obtain an entry from the database based on ID - dbDao = new DbDAO(resourceName, A_SEQ_PU, properties); - - // Find the proper database entry - Query iaequery = em - .createQuery("Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu"); - iaequery.setParameter("rn", DbDAOTest.resourceName); - iaequery.setParameter("pu", DbDAOTest.A_SEQ_PU); - - @SuppressWarnings("rawtypes") - List iaeList = iaequery.getResultList(); - IntegrityAuditEntity iae = null; - if (!iaeList.isEmpty()) { - // ignores multiple results - iae = (IntegrityAuditEntity) iaeList.get(0); - - // refresh the object from DB in case cached data was returned - em.refresh(iae); - - // Obtain ID for an IntegrityAuditEntity - PersistenceUnitUtil util = emf.getPersistenceUnitUtil(); - Object iaeId = util.getIdentifier(iae); - - // Obtain the same IntegrityAuditEntity based on ID - IntegrityAuditEntity iaeDuplicate = dbDao.getIntegrityAuditEntity((long) iaeId); - Object duplicateId = util.getIdentifier(iaeDuplicate); - - // Assert that the proper entry was retrieved based on ID - assertEquals((long) iaeId, (long) duplicateId); - } - } - - /* Tests setting an IntegrityAuditEntity as the designated node */ - @Test - public void testSetDesignated() throws Exception { - Properties properties = makeProperties(); - - try (EntityTransCloser et = new EntityTransCloser(em.getTransaction())) { - // Create an entry and set it's designated field to true - dbDao = new DbDAO(resourceName, A_SEQ_PU, properties); - dbDao.setDesignated(resourceName, A_SEQ_PU, true); - - // Find the proper entry in the database - Query iaequery = em.createQuery( - "Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu"); - iaequery.setParameter("rn", resourceName); - iaequery.setParameter("pu", A_SEQ_PU); - - @SuppressWarnings("rawtypes") - List iaeList = iaequery.getResultList(); - IntegrityAuditEntity iae = null; - - if (!iaeList.isEmpty()) { - // ignores multiple results - iae = (IntegrityAuditEntity) iaeList.get(0); - em.refresh(iae); - - // Check if the node is designated - boolean result = iae.isDesignated(); - - // Assert that it is designated - assertTrue(result); - } - - // flush to the DB - em.flush(); - - // close the transaction - et.commit(); - } - } - - /* Tests that the lastUpdated column in the database is updated properly */ - @Test - public void testSetLastUpdated() throws Exception { - Properties properties = makeProperties(); - - try (EntityTransCloser et = new EntityTransCloser(em.getTransaction())) { - TestTime testTime = getTestTime(); - - // Create an entry - dbDao = new DbDAO(resourceName, A_SEQ_PU, properties); - - // Find the proper entry in the database - Query iaequery = em.createQuery( - "Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu"); - iaequery.setParameter("rn", resourceName); - iaequery.setParameter("pu", A_SEQ_PU); - - @SuppressWarnings("rawtypes") - List iaeList = iaequery.getResultList(); - IntegrityAuditEntity iae = null; - - if (!iaeList.isEmpty()) { - // ignores multiple results - iae = (IntegrityAuditEntity) iaeList.get(0); - // refresh the object from DB in case cached data was returned - em.refresh(iae); - - // Obtain old update value and set new update value - final Date oldDate = iae.getLastUpdated(); - - // ensure dates are different by sleeping for a bit - testTime.sleep(1); - - iae.setSite("SiteB"); - iae.setLastUpdated(testTime.getDate()); - final Date newDate = iae.getLastUpdated(); - - em.persist(iae); - // flush to the DB - em.flush(); - // close the transaction - et.commit(); - - // Assert that the old and new update times are different - assertNotEquals(oldDate, newDate); - } - } - } - - /* Tests that all the entries from a class can be retrieved */ - @Test - public void testGetAllMyEntriesString() throws Exception { - Properties properties = makeProperties(); - - // create entries for the IntegrityAuditEntity table - dbDao = new DbDAO(resourceName, A_SEQ_PU, properties); - new DbDAO("pdp1", A_SEQ_PU, properties).destroy(); - new DbDAO("pdp2", A_SEQ_PU, properties).destroy(); - - // Obtain a hash with the persisted objects - Map entries = dbDao.getAllMyEntries("org.onap.policy.common.ia.jpa.IntegrityAuditEntity"); - - // Assert there were 3 entries for that class - assertEquals(3, entries.size()); - } - - /* - * Tests retrieving all entities in a Persistence Unit using the class name and a hashset of IDs - */ - @Test - public void testGetAllMyEntriesStringHashSet() throws Exception { - Properties properties = makeProperties(); - - // create entries for the IntegrityAuditEntity table - dbDao = new DbDAO(resourceName, A_SEQ_PU, properties); - new DbDAO("pdp1", A_SEQ_PU, properties).destroy(); - new DbDAO("pdp2", A_SEQ_PU, properties).destroy(); - - // Obtain all entity keys - CriteriaBuilder cb = em.getCriteriaBuilder(); - CriteriaQuery cq = cb.createQuery(); - Root rootEntry = cq.from(Class.forName("org.onap.policy.common.ia.jpa.IntegrityAuditEntity")); - CriteriaQuery all = cq.select(rootEntry); - TypedQuery allQuery = em.createQuery(all); - List objectList = allQuery.getResultList(); - HashSet resultSet = new HashSet(); - PersistenceUnitUtil util = emf.getPersistenceUnitUtil(); - for (Object o : objectList) { - Object key = util.getIdentifier(o); - resultSet.add(key); - } - - // Obtain a hash with the persisted objects - Map entries = - dbDao.getAllMyEntries("org.onap.policy.common.ia.jpa.IntegrityAuditEntity", resultSet); - - // Assert there were 3 entries for that class - assertEquals(3, entries.size()); - } - - /* - * Tests retrieving all entities in a Persistence Unit using the persistence unit, properties, - * and class name - */ - @Test - public void testGetAllEntriesStringPropertiesString() throws Exception { - Properties properties = makeProperties(); - - // create entries for the IntegrityAuditEntity table - dbDao = new DbDAO(resourceName, A_SEQ_PU, properties); - new DbDAO("pdp1", A_SEQ_PU, properties).destroy(); - new DbDAO("pdp2", A_SEQ_PU, properties).destroy(); - - // Obtain a hash with the persisted objects - Map entries = dbDao.getAllEntries("integrityAuditPU", properties, - "org.onap.policy.common.ia.jpa.IntegrityAuditEntity"); - - // Assert there were 3 entries for that class - assertEquals(3, entries.size()); - } - - /* - * Tests retrieving all entities in a Persistence Unit using the persistence unit, properties, - * class name, and a hashset of IDs - */ - @Test - public void testGetAllEntriesStringPropertiesStringHashSet() throws Exception { - Properties properties = makeProperties(); - - // create entries for the IntegrityAuditEntity table - dbDao = new DbDAO(resourceName, A_SEQ_PU, properties); - new DbDAO("pdp1", A_SEQ_PU, properties).destroy(); - new DbDAO("pdp2", A_SEQ_PU, properties).destroy(); - - // Obtain all entity keys - CriteriaBuilder cb = em.getCriteriaBuilder(); - CriteriaQuery cq = cb.createQuery(); - Root rootEntry = cq.from(Class.forName("org.onap.policy.common.ia.jpa.IntegrityAuditEntity")); - CriteriaQuery all = cq.select(rootEntry); - TypedQuery allQuery = em.createQuery(all); - List objectList = allQuery.getResultList(); - HashSet resultSet = new HashSet(); - PersistenceUnitUtil util = emf.getPersistenceUnitUtil(); - for (Object o : objectList) { - Object key = util.getIdentifier(o); - resultSet.add(key); - } - - // Obtain a hash with the persisted objects - Map entries = dbDao.getAllEntries("integrityAuditPU", properties, - "org.onap.policy.common.ia.jpa.IntegrityAuditEntity", resultSet); - - // Assert there were 3 entries for that class - assertEquals(3, entries.size()); - } - - /* - * Tests getting all the entries from a class based on persistenceUnit, properties, and - * className - */ - @Test - public void testGetAllEntries() throws Exception { - Properties properties = makeProperties(); - - // create entries for the IntegrityAuditEntity table - dbDao = new DbDAO(resourceName, A_SEQ_PU, properties); - new DbDAO("pdp1", A_SEQ_PU, properties).destroy(); - new DbDAO("pdp2", A_SEQ_PU, properties).destroy(); - - // Obtain a hash with the persisted objects - Map entries = - dbDao.getAllEntries(A_SEQ_PU, properties, "org.onap.policy.common.ia.jpa.IntegrityAuditEntity"); - - // Assert there were 3 entries for that class - assertEquals(3, entries.size()); - } - - /** - * Tests obtaining all class names of persisted classes. - */ - public void testGetPersistenceClassNames() throws Exception { - Properties properties = makeProperties(); - - dbDao = new DbDAO(resourceName, A_SEQ_PU, properties); - - // Retrieve persistence class names - Set result = dbDao.getPersistenceClassNames(); - assertEquals(1, result.size()); - } -} diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbDaoTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbDaoTest.java new file mode 100644 index 00000000..357e638c --- /dev/null +++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbDaoTest.java @@ -0,0 +1,460 @@ +/* + * ============LICENSE_START======================================================= + * Integrity Audit + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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========================================================= + */ + +package org.onap.policy.common.ia; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +/* + * All JUnits are designed to run in the local development environment + * where they have write privileges and can execute time-sensitive + * tasks. + */ + +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import javax.persistence.PersistenceUnitUtil; +import javax.persistence.Query; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.common.ia.jpa.IntegrityAuditEntity; +import org.onap.policy.common.utils.jpa.EntityTransCloser; +import org.onap.policy.common.utils.time.TestTime; + +/* + * All JUnits are designed to run in the local development environment + * where they have write privileges and can execute time-sensitive + * tasks. + */ +public class DbDaoTest extends IntegrityAuditTestBase { + private static String resourceName = "pdp0"; + + private DbDao dbDao; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + IntegrityAuditTestBase.setUpBeforeClass(DEFAULT_DB_URL_PREFIX + DbDaoTest.class.getSimpleName()); + } + + @AfterClass + public static void tearDownAfterClass() { + IntegrityAuditTestBase.tearDownAfterClass(); + } + + @Override + @Before + public void setUp() { + super.setUp(); + dbDao = null; + } + + /** + * Tear down after test cases. + */ + @Override + @After + public void tearDown() { + if (dbDao != null) { + dbDao.destroy(); + } + + super.tearDown(); + } + + /* Tests registering a new IntegrityAuditEntity object in the DB */ + @Test + public void testNewRegistration() throws Exception { + Properties properties = makeProperties(); + + try (EntityTransCloser et = new EntityTransCloser(em.getTransaction())) { + dbDao = new DbDao(resourceName, A_SEQ_PU, properties); + + // Find the proper entry in the database + Query iaequery = em.createQuery( + "Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu"); + iaequery.setParameter("rn", DbDaoTest.resourceName); + iaequery.setParameter("pu", DbDaoTest.A_SEQ_PU); + + @SuppressWarnings("rawtypes") + List iaeList = iaequery.getResultList(); + + // Assert that the IntegrityAuditEntity object was found + assertNotNull(iaeList); + + // flush to the DB + em.flush(); + et.commit(); + } + } + + /* + * Tests updating an IntegrityAuditEntity if it has already been registered + */ + @Test + public void testUpdateRegistration() throws Exception { + Properties properties = makeProperties(); + + dbDao = new DbDao(resourceName, A_SEQ_PU, properties); + + // Change site_name in properties to test that an update was made to + // an existing entry in the table + properties.put(IntegrityAuditProperties.SITE_NAME, "SiteB"); + dbDao = new DbDao(resourceName, A_SEQ_PU, properties); + + try (EntityTransCloser et = new EntityTransCloser(em.getTransaction())) { + // Find the proper entry in the database + Query iaequery = em.createQuery( + "Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu"); + iaequery.setParameter("rn", DbDaoTest.resourceName); + iaequery.setParameter("pu", DbDaoTest.A_SEQ_PU); + + @SuppressWarnings("rawtypes") + List iaeList = iaequery.getResultList(); + IntegrityAuditEntity iae = null; + if (!iaeList.isEmpty()) { + // ignores multiple results + iae = (IntegrityAuditEntity) iaeList.get(0); + + em.refresh(iae); + em.persist(iae); + + // flush to the DB + em.flush(); + + // commit transaction + et.commit(); + + // Assert that the site_name for the existing entry was updated + assertEquals("SiteB", iae.getSite()); + } + } + } + + /* Tests obtaining all Integrity Audit Entities from a table */ + @Test + public void testGetIntegrityAuditEntities() throws Exception { + Properties properties = makeProperties(); + + // Add some entries to the DB + dbDao = new DbDao(resourceName, A_SEQ_PU, properties); + new DbDao("pdp1", A_SEQ_PU, properties).destroy(); + properties.put(IntegrityAuditProperties.NODE_TYPE, "pdp_drools"); + new DbDao("pdp2", A_SEQ_PU, properties).destroy(); + + List entities; + // Obtain entries based on persistenceUnit and nodeType + entities = dbDao.getIntegrityAuditEntities(A_SEQ_PU, "pdp_xacml"); + assertEquals(2, entities.size()); + } + + /* Tests retrieving a DbDao instance's IntegrityAuditEntity */ + @Test + public void testGetMyIntegrityAuditEntity() throws Exception { + Properties properties = makeProperties(); + + dbDao = new DbDao(resourceName, A_SEQ_PU, properties); + IntegrityAuditEntity iae = dbDao.getMyIntegrityAuditEntity(); + // assertEquals("integrityAuditPU", iae.getPersistenceUnit()); + assertEquals(A_SEQ_PU, iae.getPersistenceUnit()); + } + + /* Tests obtaining an IntegrityAuditEntity by ID */ + @Test + public void testGetIntegrityAuditEntity() throws Exception { + Properties properties = makeProperties(); + + // Obtain an entry from the database based on ID + dbDao = new DbDao(resourceName, A_SEQ_PU, properties); + + // Find the proper database entry + Query iaequery = em + .createQuery("Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu"); + iaequery.setParameter("rn", DbDaoTest.resourceName); + iaequery.setParameter("pu", DbDaoTest.A_SEQ_PU); + + @SuppressWarnings("rawtypes") + List iaeList = iaequery.getResultList(); + IntegrityAuditEntity iae = null; + if (!iaeList.isEmpty()) { + // ignores multiple results + iae = (IntegrityAuditEntity) iaeList.get(0); + + // refresh the object from DB in case cached data was returned + em.refresh(iae); + + // Obtain ID for an IntegrityAuditEntity + PersistenceUnitUtil util = emf.getPersistenceUnitUtil(); + Object iaeId = util.getIdentifier(iae); + + // Obtain the same IntegrityAuditEntity based on ID + IntegrityAuditEntity iaeDuplicate = dbDao.getIntegrityAuditEntity((long) iaeId); + Object duplicateId = util.getIdentifier(iaeDuplicate); + + // Assert that the proper entry was retrieved based on ID + assertEquals((long) iaeId, (long) duplicateId); + } + } + + /* Tests setting an IntegrityAuditEntity as the designated node */ + @Test + public void testSetDesignated() throws Exception { + Properties properties = makeProperties(); + + try (EntityTransCloser et = new EntityTransCloser(em.getTransaction())) { + // Create an entry and set it's designated field to true + dbDao = new DbDao(resourceName, A_SEQ_PU, properties); + dbDao.setDesignated(resourceName, A_SEQ_PU, true); + + // Find the proper entry in the database + Query iaequery = em.createQuery( + "Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu"); + iaequery.setParameter("rn", resourceName); + iaequery.setParameter("pu", A_SEQ_PU); + + @SuppressWarnings("rawtypes") + List iaeList = iaequery.getResultList(); + IntegrityAuditEntity iae = null; + + if (!iaeList.isEmpty()) { + // ignores multiple results + iae = (IntegrityAuditEntity) iaeList.get(0); + em.refresh(iae); + + // Check if the node is designated + boolean result = iae.isDesignated(); + + // Assert that it is designated + assertTrue(result); + } + + // flush to the DB + em.flush(); + + // close the transaction + et.commit(); + } + } + + /* Tests that the lastUpdated column in the database is updated properly */ + @Test + public void testSetLastUpdated() throws Exception { + Properties properties = makeProperties(); + + try (EntityTransCloser et = new EntityTransCloser(em.getTransaction())) { + TestTime testTime = getTestTime(); + + // Create an entry + dbDao = new DbDao(resourceName, A_SEQ_PU, properties); + + // Find the proper entry in the database + Query iaequery = em.createQuery( + "Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu"); + iaequery.setParameter("rn", resourceName); + iaequery.setParameter("pu", A_SEQ_PU); + + @SuppressWarnings("rawtypes") + List iaeList = iaequery.getResultList(); + IntegrityAuditEntity iae = null; + + if (!iaeList.isEmpty()) { + // ignores multiple results + iae = (IntegrityAuditEntity) iaeList.get(0); + // refresh the object from DB in case cached data was returned + em.refresh(iae); + + // Obtain old update value and set new update value + final Date oldDate = iae.getLastUpdated(); + + // ensure dates are different by sleeping for a bit + testTime.sleep(1); + + iae.setSite("SiteB"); + iae.setLastUpdated(testTime.getDate()); + final Date newDate = iae.getLastUpdated(); + + em.persist(iae); + // flush to the DB + em.flush(); + // close the transaction + et.commit(); + + // Assert that the old and new update times are different + assertNotEquals(oldDate, newDate); + } + } + } + + /* Tests that all the entries from a class can be retrieved */ + @Test + public void testGetAllMyEntriesString() throws Exception { + Properties properties = makeProperties(); + + // create entries for the IntegrityAuditEntity table + dbDao = new DbDao(resourceName, A_SEQ_PU, properties); + new DbDao("pdp1", A_SEQ_PU, properties).destroy(); + new DbDao("pdp2", A_SEQ_PU, properties).destroy(); + + // Obtain a hash with the persisted objects + Map entries = dbDao.getAllMyEntries("org.onap.policy.common.ia.jpa.IntegrityAuditEntity"); + + // Assert there were 3 entries for that class + assertEquals(3, entries.size()); + } + + /* + * Tests retrieving all entities in a Persistence Unit using the class name and a hashset of IDs + */ + @Test + public void testGetAllMyEntriesStringHashSet() throws Exception { + Properties properties = makeProperties(); + + // create entries for the IntegrityAuditEntity table + dbDao = new DbDao(resourceName, A_SEQ_PU, properties); + new DbDao("pdp1", A_SEQ_PU, properties).destroy(); + new DbDao("pdp2", A_SEQ_PU, properties).destroy(); + + // Obtain all entity keys + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery cq = cb.createQuery(); + Root rootEntry = cq.from(Class.forName("org.onap.policy.common.ia.jpa.IntegrityAuditEntity")); + CriteriaQuery all = cq.select(rootEntry); + TypedQuery allQuery = em.createQuery(all); + List objectList = allQuery.getResultList(); + HashSet resultSet = new HashSet(); + PersistenceUnitUtil util = emf.getPersistenceUnitUtil(); + for (Object o : objectList) { + Object key = util.getIdentifier(o); + resultSet.add(key); + } + + // Obtain a hash with the persisted objects + Map entries = + dbDao.getAllMyEntries("org.onap.policy.common.ia.jpa.IntegrityAuditEntity", resultSet); + + // Assert there were 3 entries for that class + assertEquals(3, entries.size()); + } + + /* + * Tests retrieving all entities in a Persistence Unit using the persistence unit, properties, + * and class name + */ + @Test + public void testGetAllEntriesStringPropertiesString() throws Exception { + Properties properties = makeProperties(); + + // create entries for the IntegrityAuditEntity table + dbDao = new DbDao(resourceName, A_SEQ_PU, properties); + new DbDao("pdp1", A_SEQ_PU, properties).destroy(); + new DbDao("pdp2", A_SEQ_PU, properties).destroy(); + + // Obtain a hash with the persisted objects + Map entries = dbDao.getAllEntries("integrityAuditPU", properties, + "org.onap.policy.common.ia.jpa.IntegrityAuditEntity"); + + // Assert there were 3 entries for that class + assertEquals(3, entries.size()); + } + + /* + * Tests retrieving all entities in a Persistence Unit using the persistence unit, properties, + * class name, and a hashset of IDs + */ + @Test + public void testGetAllEntriesStringPropertiesStringHashSet() throws Exception { + Properties properties = makeProperties(); + + // create entries for the IntegrityAuditEntity table + dbDao = new DbDao(resourceName, A_SEQ_PU, properties); + new DbDao("pdp1", A_SEQ_PU, properties).destroy(); + new DbDao("pdp2", A_SEQ_PU, properties).destroy(); + + // Obtain all entity keys + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery cq = cb.createQuery(); + Root rootEntry = cq.from(Class.forName("org.onap.policy.common.ia.jpa.IntegrityAuditEntity")); + CriteriaQuery all = cq.select(rootEntry); + TypedQuery allQuery = em.createQuery(all); + List objectList = allQuery.getResultList(); + HashSet resultSet = new HashSet(); + PersistenceUnitUtil util = emf.getPersistenceUnitUtil(); + for (Object o : objectList) { + Object key = util.getIdentifier(o); + resultSet.add(key); + } + + // Obtain a hash with the persisted objects + Map entries = dbDao.getAllEntries("integrityAuditPU", properties, + "org.onap.policy.common.ia.jpa.IntegrityAuditEntity", resultSet); + + // Assert there were 3 entries for that class + assertEquals(3, entries.size()); + } + + /* + * Tests getting all the entries from a class based on persistenceUnit, properties, and + * className + */ + @Test + public void testGetAllEntries() throws Exception { + Properties properties = makeProperties(); + + // create entries for the IntegrityAuditEntity table + dbDao = new DbDao(resourceName, A_SEQ_PU, properties); + new DbDao("pdp1", A_SEQ_PU, properties).destroy(); + new DbDao("pdp2", A_SEQ_PU, properties).destroy(); + + // Obtain a hash with the persisted objects + Map entries = + dbDao.getAllEntries(A_SEQ_PU, properties, "org.onap.policy.common.ia.jpa.IntegrityAuditEntity"); + + // Assert there were 3 entries for that class + assertEquals(3, entries.size()); + } + + /** + * Tests obtaining all class names of persisted classes. + */ + public void testGetPersistenceClassNames() throws Exception { + Properties properties = makeProperties(); + + dbDao = new DbDao(resourceName, A_SEQ_PU, properties); + + // Retrieve persistence class names + Set result = dbDao.getPersistenceClassNames(); + assertEquals(1, result.size()); + } +} diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditDesignationTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditDesignationTest.java index bd3baf49..084c648d 100644 --- a/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditDesignationTest.java +++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditDesignationTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Integrity Audit * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -261,7 +261,7 @@ public class IntegrityAuditDesignationTest extends IntegrityAuditTestBase { /* * Populate DB for pdp2, which will simulate it having registered but then having died. */ - new DbDAO("pdp2", A_SEQ_PU, makeProperties()).destroy(); + new DbDao("pdp2", A_SEQ_PU, makeProperties()).destroy(); /* * Sleep long enough to allow @@ -431,7 +431,7 @@ public class IntegrityAuditDesignationTest extends IntegrityAuditTestBase { /* * Populate DB for pdp3, which will simulate it having registered but then having died. */ - new DbDAO("pdp3", A_SEQ_PU, makeProperties()).destroy(); + new DbDao("pdp3", A_SEQ_PU, makeProperties()).destroy(); /* * Start audit for pdp4. @@ -488,12 +488,12 @@ public class IntegrityAuditDesignationTest extends IntegrityAuditTestBase { /* * Populate DB for "pdp1", which will simulate it having registered but then having died. */ - new DbDAO("pdp1", A_SEQ_PU, makeProperties()).destroy(); + new DbDao("pdp1", A_SEQ_PU, makeProperties()).destroy(); /* * Populate DB for pdp2, which will simulate it having registered but then having died. */ - new DbDAO("pdp2", A_SEQ_PU, makeProperties()).destroy(); + new DbDao("pdp2", A_SEQ_PU, makeProperties()).destroy(); /* * Start audit for pdp3. @@ -503,7 +503,7 @@ public class IntegrityAuditDesignationTest extends IntegrityAuditTestBase { /* * Populate DB for pdp4, which will simulate it having registered but then having died. */ - new DbDAO("pdp4", A_SEQ_PU, makeProperties()).destroy(); + new DbDao("pdp4", A_SEQ_PU, makeProperties()).destroy(); /* * Sleep long enough to allow -- cgit 1.2.3-korg