use of org.finra.herd.model.dto.BusinessObjectDataRestoreDto in project herd by FINRAOS.
the class BusinessObjectDataInitiateRestoreHelperServiceTest method testPrepareToInitiateRestoreLowerCaseParameters.
@Test
public void testPrepareToInitiateRestoreLowerCaseParameters() {
// 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.
businessObjectDataServiceTestHelper.createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey);
// Execute a before step for the initiate a business object data restore request
// using lower case input parameters (except for case-sensitive partition values).
BusinessObjectDataRestoreDto storagePolicyTransitionParamsDto = businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(new BusinessObjectDataKey(BDEF_NAMESPACE.toLowerCase(), BDEF_NAME.toLowerCase(), FORMAT_USAGE_CODE.toLowerCase(), FORMAT_FILE_TYPE_CODE.toLowerCase(), FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION), EXPIRATION_IN_DAYS);
// Validate the returned object.
assertEquals(businessObjectDataKey, storagePolicyTransitionParamsDto.getBusinessObjectDataKey());
}
use of org.finra.herd.model.dto.BusinessObjectDataRestoreDto 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.dto.BusinessObjectDataRestoreDto in project herd by FINRAOS.
the class BusinessObjectDataFinalizeRestoreHelperServiceImpl method prepareToFinalizeRestoreImpl.
/**
* Prepares for the business object data finalize restore by validating the S3 storage unit along with other related database entities. The method also
* creates and returns a business object data restore DTO.
*
* @param storageUnitKey the storage unit key
*
* @return the DTO that holds various parameters needed to perform a business object data restore
*/
protected BusinessObjectDataRestoreDto prepareToFinalizeRestoreImpl(BusinessObjectDataStorageUnitKey storageUnitKey) {
// Get the storage name.
String storageName = storageUnitKey.getStorageName();
// Get a business object data key.
BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper.createBusinessObjectDataKeyFromStorageUnitKey(storageUnitKey);
// Retrieve the business object data and ensure it exists.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey);
// Retrieve the storage unit and validate it.
StorageUnitEntity storageUnitEntity = getStorageUnit(storageUnitKey.getStorageName(), businessObjectDataEntity);
// Validate that S3 storage has S3 bucket name configured. Please note that since S3 bucket name attribute value is required we pass a "true" flag.
String s3BucketName = storageHelper.getStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), storageUnitEntity.getStorage(), true);
// Get storage specific S3 key prefix for this business object data.
String s3KeyPrefix = s3KeyPrefixHelper.buildS3KeyPrefix(storageUnitEntity.getStorage(), businessObjectDataEntity.getBusinessObjectFormat(), businessObjectDataKey);
// Retrieve and validate storage files registered with the storage unit.
List<StorageFile> storageFiles = storageFileHelper.getAndValidateStorageFiles(storageUnitEntity, s3KeyPrefix, storageName, businessObjectDataKey);
// Validate that this storage does not have any other registered storage files that
// start with the S3 key prefix, but belong to other business object data instances.
storageFileDaoHelper.validateStorageFilesCount(storageName, businessObjectDataKey, s3KeyPrefix, storageFiles.size());
// Build the business object data restore parameters DTO.
BusinessObjectDataRestoreDto businessObjectDataRestoreDto = new BusinessObjectDataRestoreDto();
businessObjectDataRestoreDto.setBusinessObjectDataKey(businessObjectDataKey);
businessObjectDataRestoreDto.setStorageName(storageName);
businessObjectDataRestoreDto.setS3Endpoint(configurationHelper.getProperty(ConfigurationValue.S3_ENDPOINT));
businessObjectDataRestoreDto.setS3BucketName(s3BucketName);
businessObjectDataRestoreDto.setS3KeyPrefix(s3KeyPrefix);
businessObjectDataRestoreDto.setStorageFiles(storageFiles);
// Return the business object data restore parameters DTO.
return businessObjectDataRestoreDto;
}
use of org.finra.herd.model.dto.BusinessObjectDataRestoreDto in project herd by FINRAOS.
the class ExpireRestoredBusinessObjectDataServiceImpl method expireS3StorageUnitImpl.
/**
* Expires a restored S3 storage unit.
*
* @param storageUnitKey the storage unit key
*/
protected void expireS3StorageUnitImpl(BusinessObjectDataStorageUnitKey storageUnitKey) {
// Build the business object data restore DTO.
BusinessObjectDataRestoreDto businessObjectDataRestoreDto = expireRestoredBusinessObjectDataHelperService.prepareToExpireStorageUnit(storageUnitKey);
// Create storage unit notification for the storage unit.
notificationEventService.processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataRestoreDto.getBusinessObjectDataKey(), businessObjectDataRestoreDto.getStorageName(), businessObjectDataRestoreDto.getNewStorageUnitStatus(), businessObjectDataRestoreDto.getOldStorageUnitStatus());
// Execute the S3 specific steps required to expire business object data.
expireRestoredBusinessObjectDataHelperService.executeS3SpecificSteps(businessObjectDataRestoreDto);
// Execute the after step.
expireRestoredBusinessObjectDataHelperService.completeStorageUnitExpiration(businessObjectDataRestoreDto);
// Create storage unit notification for the storage unit.
notificationEventService.processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataRestoreDto.getBusinessObjectDataKey(), businessObjectDataRestoreDto.getStorageName(), businessObjectDataRestoreDto.getNewStorageUnitStatus(), businessObjectDataRestoreDto.getOldStorageUnitStatus());
}
use of org.finra.herd.model.dto.BusinessObjectDataRestoreDto in project herd by FINRAOS.
the class BusinessObjectDataFinalizeRestoreServiceImpl method finalizeRestoreImpl.
/**
* Finalizes restore of an S3 storage unit.
*
* @param storageUnitKey the storage unit key
*/
protected void finalizeRestoreImpl(BusinessObjectDataStorageUnitKey storageUnitKey) {
// Build the business object data restore DTO.
BusinessObjectDataRestoreDto businessObjectDataRestoreDto = businessObjectDataFinalizeRestoreHelperService.prepareToFinalizeRestore(storageUnitKey);
// Execute the S3 specific steps required to finalize the business object data restore.
businessObjectDataFinalizeRestoreHelperService.executeS3SpecificSteps(businessObjectDataRestoreDto);
// Execute the after step regardless if the above step failed or not. Please note that the after step returns true on success and false otherwise.
businessObjectDataFinalizeRestoreHelperService.completeFinalizeRestore(businessObjectDataRestoreDto);
// Create storage unit notification for the origin storage unit.
notificationEventService.processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataRestoreDto.getBusinessObjectDataKey(), businessObjectDataRestoreDto.getStorageName(), businessObjectDataRestoreDto.getNewStorageUnitStatus(), businessObjectDataRestoreDto.getOldStorageUnitStatus());
}
Aggregations