use of org.finra.herd.model.jpa.StorageUnitStatusEntity in project herd by FINRAOS.
the class BusinessObjectDataDaoTest method testGetBusinessObjectDataEntitiesByPartitionFiltersAndStorageOlderFormatVersionHasNewerDataVersion.
@Test
public void testGetBusinessObjectDataEntitiesByPartitionFiltersAndStorageOlderFormatVersionHasNewerDataVersion() {
// Create two business object data instances that have newer data version in the older format version.
List<BusinessObjectDataEntity> businessObjectDataEntities = Arrays.asList(businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, SECOND_DATA_VERSION, true, BDATA_STATUS), businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, SECOND_FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, INITIAL_DATA_VERSION, true, BDATA_STATUS));
// Create a storage instance and relative storage units.
StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(STORAGE_NAME);
StorageUnitStatusEntity storageUnitStatusEntity = storageUnitStatusDaoTestHelper.createStorageUnitStatusEntity(STORAGE_UNIT_STATUS);
for (BusinessObjectDataEntity businessObjectDataEntity : businessObjectDataEntities) {
storageUnitDaoTestHelper.createStorageUnitEntity(storageEntity, businessObjectDataEntity, storageUnitStatusEntity, NO_STORAGE_DIRECTORY_PATH);
}
// Build a list of partition filters to select the "available" business object data.
List<List<String>> partitionFilters = new ArrayList<>();
partitionFilters.add(Arrays.asList(PARTITION_VALUE, null, null, null, null));
// Retrieve the available business object data without specifying both business object format version and business object data version.
List<BusinessObjectDataEntity> resultBusinessObjectDataEntities = businessObjectDataDao.getBusinessObjectDataEntities(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, null), partitionFilters, null, BDATA_STATUS, STORAGE_NAME);
// Validate the results.
assertNotNull(resultBusinessObjectDataEntities);
assertEquals(1, resultBusinessObjectDataEntities.size());
assertEquals(SECOND_FORMAT_VERSION, resultBusinessObjectDataEntities.get(0).getBusinessObjectFormat().getBusinessObjectFormatVersion());
assertEquals(INITIAL_DATA_VERSION, resultBusinessObjectDataEntities.get(0).getVersion());
}
use of org.finra.herd.model.jpa.StorageUnitStatusEntity in project herd by FINRAOS.
the class BusinessObjectDataDaoTest method testGetBusinessObjectDataEntitiesByPartitionFiltersAndStorageLatestDataVersionNotInStorage.
/**
* This unit test validates that we do not rely on the business object data latest version flag when selecting business object entities by partition filters
* and storage.
*/
@Test
public void testGetBusinessObjectDataEntitiesByPartitionFiltersAndStorageLatestDataVersionNotInStorage() {
// Create several versions of business object data instances with the latest version not located in the test storage and
// the second version having different business object data status.
List<BusinessObjectDataEntity> businessObjectDataEntities = Arrays.asList(businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, INITIAL_DATA_VERSION, false, BDATA_STATUS), businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, SECOND_DATA_VERSION, false, BDATA_STATUS_2), businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, THIRD_DATA_VERSION, true, BDATA_STATUS));
// Create a storage instance and relative storage units for the first two business object data versions.
StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(STORAGE_NAME);
StorageUnitStatusEntity storageUnitStatusEntity = storageUnitStatusDaoTestHelper.createStorageUnitStatusEntity(STORAGE_UNIT_STATUS);
for (BusinessObjectDataEntity businessObjectDataEntity : businessObjectDataEntities.subList(0, 2)) {
storageUnitDaoTestHelper.createStorageUnitEntity(storageEntity, businessObjectDataEntity, storageUnitStatusEntity, NO_STORAGE_DIRECTORY_PATH);
}
// Build a list of partition filters to select the "available" business object data.
List<List<String>> partitionFilters = new ArrayList<>();
partitionFilters.add(Arrays.asList(PARTITION_VALUE, null, null, null, null));
// Retrieve a business object data in the test storage without specifying business object data version
// - the latest available business object data with the specified business object data status.
List<BusinessObjectDataEntity> resultBusinessObjectDataEntities = businessObjectDataDao.getBusinessObjectDataEntities(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION), partitionFilters, null, BDATA_STATUS, STORAGE_NAME);
// Validate the results - we expect to get back the initial business object data version.
assertNotNull(resultBusinessObjectDataEntities);
assertEquals(1, resultBusinessObjectDataEntities.size());
assertEquals(INITIAL_DATA_VERSION, resultBusinessObjectDataEntities.get(0).getVersion());
// Retrieve a business object data in the test storage without specifying both business object data status
// and business object data version - the latest available business object data regardless of the status.
resultBusinessObjectDataEntities = businessObjectDataDao.getBusinessObjectDataEntities(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION), partitionFilters, null, null, STORAGE_NAME);
// Validate the results - we expect to get back the second business object data version.
assertNotNull(resultBusinessObjectDataEntities);
assertEquals(1, resultBusinessObjectDataEntities.size());
assertEquals(SECOND_DATA_VERSION, resultBusinessObjectDataEntities.get(0).getVersion());
}
use of org.finra.herd.model.jpa.StorageUnitStatusEntity in project herd by FINRAOS.
the class BusinessObjectDataDaoTest method testGetBusinessObjectDataPartitionValueIgnoringNotAvailableStorageUnits.
@Test
public void testGetBusinessObjectDataPartitionValueIgnoringNotAvailableStorageUnits() {
// Create database entities required for testing.
StorageUnitStatusEntity availableStorageUnitStatusEntity = storageUnitStatusDaoTestHelper.createStorageUnitStatusEntity(STORAGE_UNIT_STATUS, DESCRIPTION, STORAGE_UNIT_STATUS_AVAILABLE_FLAG_SET);
StorageUnitStatusEntity notAvailableStorageUnitStatusEntity = storageUnitStatusDaoTestHelper.createStorageUnitStatusEntity(STORAGE_UNIT_STATUS_2, DESCRIPTION, NO_STORAGE_UNIT_STATUS_AVAILABLE_FLAG_SET);
StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.VALID, availableStorageUnitStatusEntity.getCode(), NO_STORAGE_DIRECTORY_PATH);
// Create a business object format key.
BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION);
// Validate that we can retrieve maximum and minimum partition values.
assertEquals(PARTITION_VALUE, businessObjectDataDao.getBusinessObjectDataMaxPartitionValue(BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, businessObjectFormatKey, NO_DATA_VERSION, NO_BDATA_STATUS, Collections.singletonList(STORAGE_NAME), null, null, null, null));
assertEquals(PARTITION_VALUE, businessObjectDataDao.getBusinessObjectDataMinPartitionValue(BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, businessObjectFormatKey, NO_DATA_VERSION, NO_BDATA_STATUS, Collections.singletonList(STORAGE_NAME), null, null));
// Change the storage unit status to a "not available" status.
storageUnitEntity.setStatus(notAvailableStorageUnitStatusEntity);
storageUnitDao.saveAndRefresh(storageUnitEntity);
// Validate that we now fail to retrieve maximum and minimum partition values.
assertNull(businessObjectDataDao.getBusinessObjectDataMaxPartitionValue(BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, businessObjectFormatKey, NO_DATA_VERSION, NO_BDATA_STATUS, Collections.singletonList(STORAGE_NAME), null, null, null, null));
assertNull(businessObjectDataDao.getBusinessObjectDataMinPartitionValue(BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, businessObjectFormatKey, NO_DATA_VERSION, NO_BDATA_STATUS, Collections.singletonList(STORAGE_NAME), null, null));
}
use of org.finra.herd.model.jpa.StorageUnitStatusEntity in project herd by FINRAOS.
the class StorageUnitDaoImpl method getS3StorageUnitsToExpire.
@Override
public List<StorageUnitEntity> getS3StorageUnitsToExpire(int maxResult) {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<StorageUnitEntity> criteria = builder.createQuery(StorageUnitEntity.class);
// The criteria root is the storage unit.
Root<StorageUnitEntity> storageUnitEntityRoot = criteria.from(StorageUnitEntity.class);
// Join to the other tables we can filter on.
Join<StorageUnitEntity, StorageEntity> storageEntityJoin = storageUnitEntityRoot.join(StorageUnitEntity_.storage);
Join<StorageEntity, StoragePlatformEntity> storagePlatformEntityJoin = storageEntityJoin.join(StorageEntity_.storagePlatform);
Join<StorageUnitEntity, StorageUnitStatusEntity> storageUnitStatusEntityJoin = storageUnitEntityRoot.join(StorageUnitEntity_.status);
// Get the current time.
Timestamp currentTime = new Timestamp(System.currentTimeMillis());
// Create the standard restrictions (i.e. the standard where clauses).
List<Predicate> predicates = new ArrayList<>();
predicates.add(builder.equal(storagePlatformEntityJoin.get(StoragePlatformEntity_.name), StoragePlatformEntity.S3));
predicates.add(builder.equal(storageUnitStatusEntityJoin.get(StorageUnitStatusEntity_.code), StorageUnitStatusEntity.RESTORED));
predicates.add(builder.lessThan(storageUnitEntityRoot.get(StorageUnitEntity_.restoreExpirationOn), currentTime));
// Order the results.
Order orderBy = builder.asc(storageUnitEntityRoot.get(StorageUnitEntity_.restoreExpirationOn));
// Add the clauses for the query.
criteria.select(storageUnitEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(orderBy);
// Execute the query and return the results.
return entityManager.createQuery(criteria).setMaxResults(maxResult).getResultList();
}
use of org.finra.herd.model.jpa.StorageUnitStatusEntity in project herd by FINRAOS.
the class StorageUnitDaoImpl method getS3StorageUnitsToCleanup.
@Override
public List<StorageUnitEntity> getS3StorageUnitsToCleanup(int maxResult) {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<StorageUnitEntity> criteria = builder.createQuery(StorageUnitEntity.class);
// The criteria root is the storage unit.
Root<StorageUnitEntity> storageUnitEntityRoot = criteria.from(StorageUnitEntity.class);
// Join to the other tables we can filter on.
Join<StorageUnitEntity, StorageEntity> storageEntityJoin = storageUnitEntityRoot.join(StorageUnitEntity_.storage);
Join<StorageEntity, StoragePlatformEntity> storagePlatformEntityJoin = storageEntityJoin.join(StorageEntity_.storagePlatform);
Join<StorageUnitEntity, StorageUnitStatusEntity> storageUnitStatusEntityJoin = storageUnitEntityRoot.join(StorageUnitEntity_.status);
Join<StorageUnitEntity, BusinessObjectDataEntity> businessObjectDataEntityJoin = storageUnitEntityRoot.join(StorageUnitEntity_.businessObjectData);
Join<BusinessObjectDataEntity, BusinessObjectDataStatusEntity> businessObjectDataStatusEntity = businessObjectDataEntityJoin.join(BusinessObjectDataEntity_.status);
// Get the current time.
Timestamp currentTime = new Timestamp(System.currentTimeMillis());
// Create the standard restrictions (i.e. the standard where clauses).
// Restrictions include:
// - Storage platform is set to S3 storage
// - Storage unit status is DISABLED
// - Associated BData has a DELETED status
// - Final destroy on timestamp < current time
List<Predicate> predicates = new ArrayList<>();
predicates.add(builder.equal(storagePlatformEntityJoin.get(StoragePlatformEntity_.name), StoragePlatformEntity.S3));
predicates.add(builder.equal(storageUnitStatusEntityJoin.get(StorageUnitStatusEntity_.code), StorageUnitStatusEntity.DISABLED));
predicates.add(builder.equal(businessObjectDataStatusEntity.get(BusinessObjectDataStatusEntity_.code), BusinessObjectDataStatusEntity.DELETED));
predicates.add(builder.lessThan(storageUnitEntityRoot.get(StorageUnitEntity_.finalDestroyOn), currentTime));
// Order the results.
Order orderBy = builder.asc(storageUnitEntityRoot.get(StorageUnitEntity_.finalDestroyOn));
// Add the clauses for the query.
criteria.select(storageUnitEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(orderBy);
// Execute the query and return the results.
return entityManager.createQuery(criteria).setMaxResults(maxResult).getResultList();
}
Aggregations