use of org.finra.herd.model.dto.StoragePolicyTransitionParamsDto in project herd by FINRAOS.
the class StoragePolicyProcessorHelperServiceImplTest method testExecuteStoragePolicyTransitionImpl.
@Test
public void testExecuteStoragePolicyTransitionImpl() {
// 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 a storage file path.
String storageFilePath = TEST_S3_KEY_PREFIX + "/" + LOCAL_FILE;
// Create a list of storage files to be passed as an input.
List<StorageFile> storageFiles = Arrays.asList(new StorageFile(storageFilePath, FILE_SIZE_1_KB, ROW_COUNT_1000));
// Create a storage policy transition parameters DTO.
StoragePolicyTransitionParamsDto storagePolicyTransitionParamsDto = new StoragePolicyTransitionParamsDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, TEST_S3_KEY_PREFIX, StorageUnitStatusEntity.ARCHIVING, StorageUnitStatusEntity.ENABLED, storageFiles, S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE, S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME);
// Create an S3 file transfer parameters DTO to access the S3 bucket.
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
// Create an S3 file transfer parameters DTO to be used for S3 object tagging operation.
S3FileTransferRequestParamsDto s3ObjectTaggerParamsDto = new S3FileTransferRequestParamsDto();
s3ObjectTaggerParamsDto.setAwsAccessKeyId(AWS_ASSUMED_ROLE_ACCESS_KEY);
s3ObjectTaggerParamsDto.setAwsSecretKey(AWS_ASSUMED_ROLE_SECRET_KEY);
s3ObjectTaggerParamsDto.setSessionToken(AWS_ASSUMED_ROLE_SESSION_TOKEN);
// Create a list of S3 object summaries selected without zero byte directory markers.
List<S3ObjectSummary> actualS3FilesWithoutZeroByteDirectoryMarkers = Arrays.asList(new S3ObjectSummary());
// Create a list of all S3 files matching the S3 key prefix form the S3 bucket.
List<S3ObjectSummary> actualS3Files = Arrays.asList(new S3ObjectSummary());
// Create a list of storage files selected for S3 object tagging.
List<StorageFile> storageFilesSelectedForTagging = Arrays.asList(new StorageFile());
// Create a list of storage files selected for S3 object tagging.
List<File> filesSelectedForTagging = Arrays.asList(new File(storageFilePath));
// Create an updated S3 file transfer parameters DTO to access the S3 bucket.
S3FileTransferRequestParamsDto updatedS3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
updatedS3FileTransferRequestParamsDto.setS3Endpoint(S3_ENDPOINT);
updatedS3FileTransferRequestParamsDto.setS3BucketName(S3_BUCKET_NAME);
updatedS3FileTransferRequestParamsDto.setS3KeyPrefix(TEST_S3_KEY_PREFIX + "/");
updatedS3FileTransferRequestParamsDto.setFiles(filesSelectedForTagging);
// Create an updated S3 file transfer parameters DTO to be used for S3 object tagging operation.
S3FileTransferRequestParamsDto updatedS3ObjectTaggerParamsDto = new S3FileTransferRequestParamsDto();
updatedS3ObjectTaggerParamsDto.setAwsAccessKeyId(AWS_ASSUMED_ROLE_ACCESS_KEY);
updatedS3ObjectTaggerParamsDto.setAwsSecretKey(AWS_ASSUMED_ROLE_SECRET_KEY);
updatedS3ObjectTaggerParamsDto.setSessionToken(AWS_ASSUMED_ROLE_SESSION_TOKEN);
updatedS3ObjectTaggerParamsDto.setS3Endpoint(S3_ENDPOINT);
// Mock the external calls.
when(storageHelper.getS3FileTransferRequestParamsDto()).thenReturn(s3FileTransferRequestParamsDto);
when(storageHelper.getS3FileTransferRequestParamsDtoByRole(S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME)).thenReturn(s3ObjectTaggerParamsDto);
when(s3Service.listDirectory(s3FileTransferRequestParamsDto, true)).thenReturn(actualS3FilesWithoutZeroByteDirectoryMarkers);
when(s3Service.listDirectory(s3FileTransferRequestParamsDto, false)).thenReturn(actualS3Files);
when(storageFileHelper.createStorageFilesFromS3ObjectSummaries(actualS3Files)).thenReturn(storageFilesSelectedForTagging);
when(storageFileHelper.getFiles(storageFilesSelectedForTagging)).thenReturn(filesSelectedForTagging);
// Call the method under test.
storagePolicyProcessorHelperServiceImpl.executeStoragePolicyTransitionImpl(storagePolicyTransitionParamsDto);
// Verify the external calls.
verify(storageHelper).getS3FileTransferRequestParamsDto();
verify(storageHelper).getS3FileTransferRequestParamsDtoByRole(S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME);
verify(s3Service).listDirectory(s3FileTransferRequestParamsDto, true);
verify(storageFileHelper).validateRegisteredS3Files(storageFiles, actualS3FilesWithoutZeroByteDirectoryMarkers, STORAGE_NAME, businessObjectDataKey);
verify(s3Service).listDirectory(s3FileTransferRequestParamsDto, true);
verify(s3Service).listDirectory(s3FileTransferRequestParamsDto, false);
verify(storageFileHelper).createStorageFilesFromS3ObjectSummaries(actualS3Files);
verify(storageFileHelper).getFiles(storageFilesSelectedForTagging);
verify(s3Service).tagObjects(updatedS3FileTransferRequestParamsDto, updatedS3ObjectTaggerParamsDto, new Tag(S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE));
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(new StoragePolicyTransitionParamsDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, TEST_S3_KEY_PREFIX, StorageUnitStatusEntity.ARCHIVING, StorageUnitStatusEntity.ENABLED, storageFiles, S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE, S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME), storagePolicyTransitionParamsDto);
}
use of org.finra.herd.model.dto.StoragePolicyTransitionParamsDto in project herd by FINRAOS.
the class StoragePolicyProcessorHelperServiceImplTest method testUpdateStoragePolicyTransitionFailedAttemptsIgnoreExceptionImplNoStorageName.
@Test
public void testUpdateStoragePolicyTransitionFailedAttemptsIgnoreExceptionImplNoStorageName() {
// 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, SUBPARTITION_VALUES, DATA_VERSION);
// Create a storage policy transition parameters DTO that does not have storage name specified.
StoragePolicyTransitionParamsDto storagePolicyTransitionParamsDto = new StoragePolicyTransitionParamsDto();
storagePolicyTransitionParamsDto.setBusinessObjectDataKey(businessObjectDataKey);
// Call the method under test.
storagePolicyProcessorHelperServiceImpl.updateStoragePolicyTransitionFailedAttemptsIgnoreException(storagePolicyTransitionParamsDto);
// Verify the external calls.
verify(jsonHelper).objectToJson(storagePolicyTransitionParamsDto);
verifyNoMoreInteractionsHelper();
}
use of org.finra.herd.model.dto.StoragePolicyTransitionParamsDto in project herd by FINRAOS.
the class StoragePolicyProcessorHelperServiceImplTest method testUpdateStoragePolicyTransitionFailedAttemptsIgnoreExceptionImplFirstFailure.
@Test
public void testUpdateStoragePolicyTransitionFailedAttemptsIgnoreExceptionImplFirstFailure() {
// 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, SUBPARTITION_VALUES, DATA_VERSION);
// Create a storage unit entity with its storagePolicyTransitionFailedAttempts set to NULL.
StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
// Create a business object data storage unit key.
BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey = new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME);
// Create a storage policy transition parameters DTO.
StoragePolicyTransitionParamsDto storagePolicyTransitionParamsDto = new StoragePolicyTransitionParamsDto();
storagePolicyTransitionParamsDto.setBusinessObjectDataKey(businessObjectDataKey);
storagePolicyTransitionParamsDto.setStorageName(STORAGE_NAME);
// Mock the external calls.
when(storageUnitHelper.createBusinessObjectDataStorageUnitKey(businessObjectDataKey, STORAGE_NAME)).thenReturn(businessObjectDataStorageUnitKey);
when(storageUnitDaoHelper.getStorageUnitEntityByKey(businessObjectDataStorageUnitKey)).thenReturn(storageUnitEntity);
// Call the method under test.
storagePolicyProcessorHelperServiceImpl.updateStoragePolicyTransitionFailedAttemptsIgnoreException(storagePolicyTransitionParamsDto);
// Verify the external calls.
verify(jsonHelper).objectToJson(storagePolicyTransitionParamsDto);
verify(storageUnitHelper).createBusinessObjectDataStorageUnitKey(businessObjectDataKey, STORAGE_NAME);
verify(storageUnitDaoHelper).getStorageUnitEntityByKey(businessObjectDataStorageUnitKey);
verify(storageUnitDao).saveAndRefresh(storageUnitEntity);
verify(jsonHelper).objectToJson(businessObjectDataStorageUnitKey);
verifyNoMoreInteractionsHelper();
// Validate the results. The counter value now should be equal to 1.
assertEquals(Integer.valueOf(1), storageUnitEntity.getStoragePolicyTransitionFailedAttempts());
}
use of org.finra.herd.model.dto.StoragePolicyTransitionParamsDto in project herd by FINRAOS.
the class StoragePolicyProcessorServiceImpl method processStoragePolicySelectionMessageImpl.
/**
* Performs a storage policy transition as specified by the storage policy selection message.
*
* @param storagePolicySelection the storage policy selection message
*/
protected void processStoragePolicySelectionMessageImpl(StoragePolicySelection storagePolicySelection) {
// Create a storage policy transition parameters DTO.
StoragePolicyTransitionParamsDto storagePolicyTransitionParamsDto = new StoragePolicyTransitionParamsDto();
try {
// Initiate the storage policy transition.
storagePolicyProcessorHelperService.initiateStoragePolicyTransition(storagePolicyTransitionParamsDto, storagePolicySelection);
// Create a storage unit notification for the source storage unit.
notificationEventService.processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, storagePolicyTransitionParamsDto.getBusinessObjectDataKey(), storagePolicyTransitionParamsDto.getStorageName(), storagePolicyTransitionParamsDto.getNewStorageUnitStatus(), storagePolicyTransitionParamsDto.getOldStorageUnitStatus());
// Execute the actual transition using the DAO tier.
storagePolicyProcessorHelperService.executeStoragePolicyTransition(storagePolicyTransitionParamsDto);
// Complete the storage policy transition.
storagePolicyProcessorHelperService.completeStoragePolicyTransition(storagePolicyTransitionParamsDto);
// Create a storage unit notification for the source storage unit.
notificationEventService.processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, storagePolicyTransitionParamsDto.getBusinessObjectDataKey(), storagePolicyTransitionParamsDto.getStorageName(), storagePolicyTransitionParamsDto.getNewStorageUnitStatus(), storagePolicyTransitionParamsDto.getOldStorageUnitStatus());
} catch (RuntimeException e) {
// Try to increment the count for failed storage policy transition attempts for the specified storage unit.
storagePolicyProcessorHelperService.updateStoragePolicyTransitionFailedAttemptsIgnoreException(storagePolicyTransitionParamsDto);
// Rethrow the original exception.
throw e;
}
}
use of org.finra.herd.model.dto.StoragePolicyTransitionParamsDto in project herd by FINRAOS.
the class StoragePolicyProcessorHelperServiceTest method testInitiateStoragePolicyTransitionStoragePolicyFilterStorageInvalidStoragePlatform.
@Test
public void testInitiateStoragePolicyTransitionStoragePolicyFilterStorageInvalidStoragePlatform() {
// 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, SUBPARTITION_VALUES, DATA_VERSION);
// Create and persist a business object data entity.
businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(businessObjectDataKey, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.VALID);
// Create a storage policy key.
StoragePolicyKey storagePolicyKey = new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME);
// Create and persist a storage entity with storage platform type not set to S3.
storageDaoTestHelper.createStorageEntity(STORAGE_NAME, STORAGE_PLATFORM_CODE);
// Create and persist a storage policy entity with storage policy filter storage having a non-S3 storage platform type.
storagePolicyDaoTestHelper.createStoragePolicyEntity(storagePolicyKey, STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, STORAGE_NAME, StoragePolicyTransitionTypeEntity.GLACIER, StoragePolicyStatusEntity.ENABLED, INITIAL_VERSION, LATEST_VERSION_FLAG_SET);
// Try to initiate a storage policy transition when storage policy filter storage has a non-S3 storage platform type.
try {
storagePolicyProcessorHelperService.initiateStoragePolicyTransition(new StoragePolicyTransitionParamsDto(), new StoragePolicySelection(businessObjectDataKey, storagePolicyKey, INITIAL_VERSION));
fail("Should throw an IllegalArgumentException when using non-S3 storage platform for storage policy filter storage.");
} catch (IllegalArgumentException e) {
assertEquals(String.format("Storage platform for storage policy filter storage with name \"%s\" is not \"%s\". Storage policy: {%s}", STORAGE_NAME, StoragePlatformEntity.S3, storagePolicyServiceTestHelper.getExpectedStoragePolicyKeyAndVersionAsString(storagePolicyKey, INITIAL_VERSION)), e.getMessage());
}
}
Aggregations