use of org.finra.herd.model.jpa.StorageUnitEntity in project herd by FINRAOS.
the class BusinessObjectDataInitiateRestoreHelperServiceTest method testPrepareToInitiateRestoreMissingOptionalParameters.
@Test
public void testPrepareToInitiateRestoreMissingOptionalParameters() throws Exception {
// Create a business object data key without sub-partition values.
BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION);
// Create database entities required for testing.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey);
// Execute a before step for the initiate a business object data restore request for business object data without sub-partition values.
BusinessObjectDataRestoreDto storagePolicyTransitionParamsDto = businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(businessObjectDataKey, NO_EXPIRATION_IN_DAYS);
// Validate the returned object.
assertEquals(businessObjectDataKey, storagePolicyTransitionParamsDto.getBusinessObjectDataKey());
// Validate that restore expiration time is set correctly on the storage unit.
StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity);
assertNotNull(storageUnitEntity.getRestoreExpirationOn());
Long differenceInDays = TimeUnit.DAYS.convert(storageUnitEntity.getRestoreExpirationOn().getTime() - storageUnitEntity.getCreatedOn().getTime(), TimeUnit.MILLISECONDS);
assertTrue((Integer) ConfigurationValue.BDATA_RESTORE_EXPIRATION_IN_DAYS_DEFAULT.getDefaultValue() - differenceInDays <= 1);
}
use of org.finra.herd.model.jpa.StorageUnitEntity in project herd by FINRAOS.
the class BusinessObjectDataInitiateRestoreHelperServiceTest method testPrepareToInitiateRestoreStorageUnitHasNoStorageFiles.
@Test
public void testPrepareToInitiateRestoreStorageUnitHasNoStorageFiles() throws Exception {
// Create a business object data key.
BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION);
// Create database entities required for testing.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey, STORAGE_NAME, S3_BUCKET_NAME, StorageUnitStatusEntity.ARCHIVED);
// Get the storage unit entity.
StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity);
// Remove storage files from the storage unit.
storageUnitEntity.getStorageFiles().clear();
// Try to execute a before step for the initiate a business object data restore request when storage unit has no storage files.
try {
businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(businessObjectDataKey, EXPIRATION_IN_DAYS);
fail();
} catch (IllegalArgumentException e) {
assertEquals(String.format("Business object data has no storage files registered in \"%s\" storage. Business object data: {%s}", STORAGE_NAME, businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataKeyAsString(businessObjectDataKey)), e.getMessage());
}
}
use of org.finra.herd.model.jpa.StorageUnitEntity in project herd by FINRAOS.
the class BusinessObjectDataInitiateRestoreHelperServiceTest method testPrepareToInitiateRestore.
@Test
public void testPrepareToInitiateRestore() throws Exception {
// Create a business object data key.
BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION);
// Create database entities required for testing.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey);
// Get the current time and compute the expected timestamp value.
Timestamp currentTime = new Timestamp(System.currentTimeMillis());
Timestamp expectedTimestamp = HerdDateUtils.addDays(currentTime, EXPIRATION_IN_DAYS);
// Execute a before step for the initiate a business object data restore request.
BusinessObjectDataRestoreDto storagePolicyTransitionParamsDto = businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(businessObjectDataKey, EXPIRATION_IN_DAYS);
// Validate the returned object.
assertEquals(businessObjectDataKey, storagePolicyTransitionParamsDto.getBusinessObjectDataKey());
// Validate that restore expiration time is set correctly on the storage unit.
StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity);
assertNotNull(storageUnitEntity.getRestoreExpirationOn());
Long differenceInMilliseconds = storageUnitEntity.getRestoreExpirationOn().getTime() - expectedTimestamp.getTime();
assertTrue(Math.abs(differenceInMilliseconds) < 1000);
}
use of org.finra.herd.model.jpa.StorageUnitEntity in project herd by FINRAOS.
the class CleanupDestroyedBusinessObjectDataServiceImpl method getS3StorageUnitsToCleanupImpl.
/**
* Retrieves a list of keys for destroyed S3 storage units that are ready for cleanup.
*
* @param maxResult the maximum number of results to retrieve
*
* @return the list of storage unit keys
*/
List<BusinessObjectDataStorageUnitKey> getS3StorageUnitsToCleanupImpl(int maxResult) {
// Retrieves a list of storage units that belong to S3 storage, and has a final destroy on timestamp < current time, has a DELETED status,
// and associated BData has a DELETED status.
List<StorageUnitEntity> storageUnitEntities = storageUnitDao.getS3StorageUnitsToCleanup(maxResult);
// Build a list of storage unit keys.
List<BusinessObjectDataStorageUnitKey> storageUnitKeys = new ArrayList<>();
for (StorageUnitEntity storageUnitEntity : storageUnitEntities) {
storageUnitKeys.add(storageUnitHelper.createStorageUnitKeyFromEntity(storageUnitEntity));
}
return storageUnitKeys;
}
use of org.finra.herd.model.jpa.StorageUnitEntity in project herd by FINRAOS.
the class StoragePolicyProcessorHelperServiceImpl method updateStoragePolicyTransitionFailedAttemptsIgnoreExceptionImpl.
/**
* Increments the count for failed storage policy transition attempts for the specified storage unit. This method does not fail in case storage unit entity
* update is unsuccessful, but simply logs the exception information as a warning.
*
* @param storagePolicyTransitionParamsDto the storage policy transition DTO that contains parameters needed to complete a storage policy transition. The
* business object data key and storage name identify the storage unit to be updated
*/
protected void updateStoragePolicyTransitionFailedAttemptsIgnoreExceptionImpl(StoragePolicyTransitionParamsDto storagePolicyTransitionParamsDto) {
// Log the DTO contents.
LOGGER.info("storagePolicyTransitionParamsDto={}", jsonHelper.objectToJson(storagePolicyTransitionParamsDto));
// Continue only when business object data kay and storage name are specified.
if (storagePolicyTransitionParamsDto.getBusinessObjectDataKey() != null && storagePolicyTransitionParamsDto.getStorageName() != null) {
try {
// Create a storage unit key.
BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey = storageUnitHelper.createBusinessObjectDataStorageUnitKey(storagePolicyTransitionParamsDto.getBusinessObjectDataKey(), storagePolicyTransitionParamsDto.getStorageName());
// Retrieve the storage unit entity and make sure it exists.
StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntityByKey(businessObjectDataStorageUnitKey);
// Update the storage policy transition failed attempts count.
storageUnitEntity.setStoragePolicyTransitionFailedAttempts(storageUnitEntity.getStoragePolicyTransitionFailedAttempts() == null ? 1 : storageUnitEntity.getStoragePolicyTransitionFailedAttempts() + 1);
storageUnitDao.saveAndRefresh(storageUnitEntity);
// Log the new value for the storage policy transition failed attempts counter.
LOGGER.info("Incremented storage policy transition failed attempts counter. " + "storagePolicyTransitionFailedAttempts={} businessObjectDataStorageUnitKey={}", storageUnitEntity.getStoragePolicyTransitionFailedAttempts(), jsonHelper.objectToJson(businessObjectDataStorageUnitKey));
} catch (Exception e) {
LOGGER.warn(e.getMessage(), e);
}
}
}
Aggregations