use of org.finra.herd.model.api.xml.BusinessObjectDataKey in project herd by FINRAOS.
the class BusinessObjectDataInitiateRestoreHelperServiceTest method testPrepareToInitiateRestoreMultipleS3StorageUnitsExist.
@Test
public void testPrepareToInitiateRestoreMultipleS3StorageUnitsExist() 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, SUBPARTITION_VALUES, DATA_VERSION);
// Create a business object data entity.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(businessObjectDataKey, LATEST_VERSION_FLAG_SET, BDATA_STATUS);
// Create multiple archived storage units for this business object data.
storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, StoragePlatformEntity.S3, businessObjectDataEntity, STORAGE_UNIT_STATUS, NO_STORAGE_DIRECTORY_PATH);
storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME_2, StoragePlatformEntity.S3, businessObjectDataEntity, STORAGE_UNIT_STATUS, NO_STORAGE_DIRECTORY_PATH);
// when business object data has multiple S3 storage units.
try {
businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(businessObjectDataKey, EXPIRATION_IN_DAYS);
fail();
} catch (IllegalArgumentException e) {
assertEquals(String.format("Business object data has multiple (2) S3 storage units. Business object data: {%s}", businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataKeyAsString(businessObjectDataKey)), e.getMessage());
}
}
use of org.finra.herd.model.api.xml.BusinessObjectDataKey in project herd by FINRAOS.
the class StoragePolicyProcessorHelperServiceImpl method initiateStoragePolicyTransitionImpl.
/**
* Initiates a storage policy transition as per specified storage policy selection. This method also updates storage policy transition DTO with parameters
* needed to perform a storage policy transition.
*
* @param storagePolicyTransitionParamsDto the storage policy transition DTO to be updated with parameters needed to perform a storage policy transition
* @param storagePolicySelection the storage policy selection message
*/
protected void initiateStoragePolicyTransitionImpl(StoragePolicyTransitionParamsDto storagePolicyTransitionParamsDto, StoragePolicySelection storagePolicySelection) {
// Validate and trim the storage policy selection message content.
validateStoragePolicySelection(storagePolicySelection);
// Get the business object data and storage policy keys from the storage policy selection message.
BusinessObjectDataKey businessObjectDataKey = storagePolicySelection.getBusinessObjectDataKey();
StoragePolicyKey storagePolicyKey = storagePolicySelection.getStoragePolicyKey();
Integer storagePolicyVersion = storagePolicySelection.getStoragePolicyVersion();
// Retrieve the business object data entity and ensure it exists.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey);
// Retrieve the storage policy and ensure it exists.
StoragePolicyEntity storagePolicyEntity = storagePolicyDaoHelper.getStoragePolicyEntityByKeyAndVersion(storagePolicyKey, storagePolicyVersion);
// Get the storage name.
String storageName = storagePolicyEntity.getStorage().getName();
// Initialize the storage policy transition parameters DTO by setting business object data key and storage name.
storagePolicyTransitionParamsDto.setBusinessObjectDataKey(businessObjectDataKey);
storagePolicyTransitionParamsDto.setStorageName(storageName);
// Validate the business object data.
validateBusinessObjectData(businessObjectDataEntity, businessObjectDataKey);
// Validate the storage.
validateStorage(storagePolicyEntity.getStorage(), storagePolicyKey, storagePolicyVersion);
// Validate that storage policy filter 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), storagePolicyEntity.getStorage(), true);
// Validate that storage policy transition type is GLACIER.
Assert.isTrue(StoragePolicyTransitionTypeEntity.GLACIER.equals(storagePolicyEntity.getStoragePolicyTransitionType().getCode()), String.format("Storage policy transition type \"%s\" is not supported. Storage policy: {%s}", storagePolicyEntity.getStoragePolicyTransitionType().getCode(), storagePolicyHelper.storagePolicyKeyAndVersionToString(storagePolicyKey, storagePolicyVersion)));
// Get the S3 object tag key to be used to tag the objects for archiving.
String s3ObjectTagKey = configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_TAG_KEY);
// Get the S3 object tag value to be used to tag S3 objects for archiving to Glacier.
String s3ObjectTagValue = configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_TAG_VALUE);
// Get the ARN of the role to assume to tag S3 objects for archiving to Glacier.
String s3ObjectTaggerRoleArn = configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_ROLE_ARN);
// Get the session identifier for the assumed role to be used to tag S3 objects for archiving to Glacier.
String s3ObjectTaggerRoleSessionName = configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_ROLE_SESSION_NAME);
// Retrieve the storage unit and ensure it exists.
StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(storageName, businessObjectDataEntity);
// Validate the storage unit.
validateStorageUnit(storageUnitEntity, storageName, businessObjectDataKey);
// Get S3 key prefix for this business object data.
String s3KeyPrefix = s3KeyPrefixHelper.buildS3KeyPrefix(storagePolicyEntity.getStorage(), storageUnitEntity.getBusinessObjectData().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());
// Update the storage unit status.
String reason = StorageUnitStatusEntity.ARCHIVING;
String oldStorageUnitStatus = storageUnitEntity.getStatus().getCode();
storageUnitDaoHelper.updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.ARCHIVING, reason);
// Update the policy transition parameters DTO.
storagePolicyTransitionParamsDto.setS3Endpoint(configurationHelper.getProperty(ConfigurationValue.S3_ENDPOINT));
storagePolicyTransitionParamsDto.setS3BucketName(s3BucketName);
storagePolicyTransitionParamsDto.setS3KeyPrefix(s3KeyPrefix);
storagePolicyTransitionParamsDto.setNewStorageUnitStatus(storageUnitEntity.getStatus().getCode());
storagePolicyTransitionParamsDto.setOldStorageUnitStatus(oldStorageUnitStatus);
storagePolicyTransitionParamsDto.setStorageFiles(storageFiles);
storagePolicyTransitionParamsDto.setS3ObjectTagKey(s3ObjectTagKey);
storagePolicyTransitionParamsDto.setS3ObjectTagValue(s3ObjectTagValue);
storagePolicyTransitionParamsDto.setS3ObjectTaggerRoleArn(s3ObjectTaggerRoleArn);
storagePolicyTransitionParamsDto.setS3ObjectTaggerRoleSessionName(s3ObjectTaggerRoleSessionName);
}
use of org.finra.herd.model.api.xml.BusinessObjectDataKey in project herd by FINRAOS.
the class StoragePolicyProcessorHelperServiceImpl method completeStoragePolicyTransitionImpl.
/**
* Completes a storage policy transition as per specified storage policy selection.
*
* @param storagePolicyTransitionParamsDto the storage policy transition DTO that contains parameters needed to complete a storage policy transition
*/
protected void completeStoragePolicyTransitionImpl(StoragePolicyTransitionParamsDto storagePolicyTransitionParamsDto) {
// Get the business object data key.
BusinessObjectDataKey businessObjectDataKey = storagePolicyTransitionParamsDto.getBusinessObjectDataKey();
// Retrieve the business object data and ensure it exists.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey);
// Validate that business object data status is supported by the storage policy feature.
String businessObjectDataStatus = businessObjectDataEntity.getStatus().getCode();
Assert.isTrue(StoragePolicySelectorServiceImpl.SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES.contains(businessObjectDataStatus), String.format("Business object data status \"%s\" is not supported by the storage policy feature. Business object data: {%s}", businessObjectDataStatus, businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)));
// Retrieve storage unit and ensure it exists.
StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(storagePolicyTransitionParamsDto.getStorageName(), businessObjectDataEntity);
// Validate that storage unit status is ARCHIVING.
Assert.isTrue(StorageUnitStatusEntity.ARCHIVING.equals(storageUnitEntity.getStatus().getCode()), String.format("Storage unit status is \"%s\", but must be \"%s\" for storage policy transition to proceed. Storage: {%s}, business object data: {%s}", storageUnitEntity.getStatus().getCode(), StorageUnitStatusEntity.ARCHIVING, storagePolicyTransitionParamsDto.getStorageName(), businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)));
// Change the storage unit status to ARCHIVED.
String reason = StorageUnitStatusEntity.ARCHIVED;
storagePolicyTransitionParamsDto.setOldStorageUnitStatus(storageUnitEntity.getStatus().getCode());
storageUnitDaoHelper.updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.ARCHIVED, reason);
storagePolicyTransitionParamsDto.setNewStorageUnitStatus(storageUnitEntity.getStatus().getCode());
}
use of org.finra.herd.model.api.xml.BusinessObjectDataKey in project herd by FINRAOS.
the class GetBusinessObjectDataAttributes method executeImpl.
@Override
public void executeImpl(DelegateExecution execution) throws Exception {
String namespace = activitiHelper.getExpressionVariableAsString(this.namespace, execution);
String businessObjectDefinitionName = activitiHelper.getExpressionVariableAsString(this.businessObjectDefinitionName, execution);
String businessObjectFormatUsage = activitiHelper.getExpressionVariableAsString(this.businessObjectFormatUsage, execution);
String businessObjectFormatFileType = activitiHelper.getExpressionVariableAsString(this.businessObjectFormatFileType, execution);
Integer businessObjectFormatVersion = activitiHelper.getExpressionVariableAsInteger(this.businessObjectFormatVersion, execution, "businessObjectFormatVersion", false);
String partitionValue = activitiHelper.getExpressionVariableAsString(this.partitionValue, execution);
String subPartitionValuesString = activitiHelper.getExpressionVariableAsString(this.subPartitionValues, execution);
List<String> subPartitionValues = daoHelper.splitStringWithDefaultDelimiterEscaped(subPartitionValuesString);
Integer businessObjectDataVersion = activitiHelper.getExpressionVariableAsInteger(this.businessObjectDataVersion, execution, "businessObjectDataVersion", false);
BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey();
businessObjectDataKey.setNamespace(namespace);
businessObjectDataKey.setBusinessObjectDefinitionName(businessObjectDefinitionName);
businessObjectDataKey.setBusinessObjectFormatUsage(businessObjectFormatUsage);
businessObjectDataKey.setBusinessObjectFormatFileType(businessObjectFormatFileType);
businessObjectDataKey.setBusinessObjectFormatVersion(businessObjectFormatVersion);
businessObjectDataKey.setPartitionValue(partitionValue);
businessObjectDataKey.setSubPartitionValues(subPartitionValues);
businessObjectDataKey.setBusinessObjectDataVersion(businessObjectDataVersion);
BusinessObjectDataAttributeKeys businessObjectDataAttributeKeys = businessObjectDataAttributeService.getBusinessObjectDataAttributes(businessObjectDataKey);
setJsonResponseAsWorkflowVariable(businessObjectDataAttributeKeys, execution);
}
use of org.finra.herd.model.api.xml.BusinessObjectDataKey in project herd by FINRAOS.
the class UploadDownloadRestControllerTest method testInitiateUploadSingle.
@Test
public void testInitiateUploadSingle() {
// Create business object format keys.
BusinessObjectFormatKey sourceBusinessObjectFormatKey = new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION);
BusinessObjectFormatKey targetBusinessObjectFormatKey = new BusinessObjectFormatKey(BDEF_NAMESPACE_2, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION_2);
// Create a file object.
File file = new File(LOCAL_FILE, FILE_SIZE);
// Create a request.
UploadSingleInitiationRequest request = new UploadSingleInitiationRequest(sourceBusinessObjectFormatKey, targetBusinessObjectFormatKey, Arrays.asList(new Attribute(ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_VALUE_1)), file, STORAGE_NAME);
// Create business object data keys.
BusinessObjectDataKey sourceBusinessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION);
BusinessObjectDataKey targetBusinessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE_2, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION_2, PARTITION_VALUE_2, SUBPARTITION_VALUES_2, DATA_VERSION_2);
// Create a business object data objects.
BusinessObjectData sourceBusinessObjectData = new BusinessObjectData();
sourceBusinessObjectData.setId(ID);
sourceBusinessObjectData.setStatus(BDATA_STATUS);
sourceBusinessObjectData.setStorageUnits(Arrays.asList(new StorageUnit(new Storage(STORAGE_NAME, STORAGE_PLATFORM_CODE, NO_ATTRIBUTES), NO_STORAGE_DIRECTORY, NO_STORAGE_FILES, STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS_HISTORY, NO_STORAGE_POLICY_TRANSITION_FAILED_ATTEMPTS, NO_RESTORE_EXPIRATION_ON)));
BusinessObjectData targetBusinessObjectData = new BusinessObjectData();
targetBusinessObjectData.setId(ID_2);
targetBusinessObjectData.setStatus(BDATA_STATUS_2);
targetBusinessObjectData.setStorageUnits(Arrays.asList(new StorageUnit(new Storage(STORAGE_NAME_2, STORAGE_PLATFORM_CODE, NO_ATTRIBUTES), NO_STORAGE_DIRECTORY, NO_STORAGE_FILES, STORAGE_UNIT_STATUS_2, NO_STORAGE_UNIT_STATUS_HISTORY, NO_STORAGE_POLICY_TRANSITION_FAILED_ATTEMPTS, NO_RESTORE_EXPIRATION_ON)));
// Create a response.
UploadSingleInitiationResponse response = new UploadSingleInitiationResponse(sourceBusinessObjectData, targetBusinessObjectData, file, UUID_VALUE, AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, AWS_ASSUMED_ROLE_SESSION_EXPIRATION_TIME, AWS_KMS_KEY_ID, STORAGE_NAME);
// Mock the external calls.
when(uploadDownloadService.initiateUploadSingle(request)).thenReturn(response);
when(businessObjectDataHelper.getBusinessObjectDataKey(sourceBusinessObjectData)).thenReturn(sourceBusinessObjectDataKey);
when(businessObjectDataHelper.getBusinessObjectDataKey(targetBusinessObjectData)).thenReturn(targetBusinessObjectDataKey);
// Call the method under test.
UploadSingleInitiationResponse result = uploadDownloadRestController.initiateUploadSingle(request);
// Verify the external calls.
verify(uploadDownloadService).initiateUploadSingle(request);
verify(businessObjectDataHelper).getBusinessObjectDataKey(sourceBusinessObjectData);
verify(businessObjectDataHelper).getBusinessObjectDataKey(targetBusinessObjectData);
verify(notificationEventService).processBusinessObjectDataNotificationEventAsync(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_RGSTN, sourceBusinessObjectDataKey, BDATA_STATUS, null);
verify(notificationEventService).processBusinessObjectDataNotificationEventAsync(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_STTS_CHG, sourceBusinessObjectDataKey, BDATA_STATUS, null);
verify(notificationEventService).processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, sourceBusinessObjectDataKey, STORAGE_NAME, STORAGE_UNIT_STATUS, null);
verify(notificationEventService).processBusinessObjectDataNotificationEventAsync(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_RGSTN, targetBusinessObjectDataKey, BDATA_STATUS_2, null);
verify(notificationEventService).processBusinessObjectDataNotificationEventAsync(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_STTS_CHG, targetBusinessObjectDataKey, BDATA_STATUS_2, null);
verify(notificationEventService).processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, targetBusinessObjectDataKey, STORAGE_NAME_2, STORAGE_UNIT_STATUS_2, null);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(response, result);
}
Aggregations