use of org.finra.herd.model.api.xml.StorageFile in project herd by FINRAOS.
the class BusinessObjectDataDaoHelper method validateBusinessObjectDataCreateRequest.
/**
* Validates the business object data create request. This method also trims appropriate request parameters.
*
* @param request the request
* @param fileSizeRequired specifies if fileSizeBytes value is required or not
* @param businessObjectDataStatusEntity The status entity in the request
*
* @throws IllegalArgumentException if any validation errors were found.
*/
private void validateBusinessObjectDataCreateRequest(BusinessObjectDataCreateRequest request, boolean fileSizeRequired, BusinessObjectDataStatusEntity businessObjectDataStatusEntity) {
// Validate and trim the request parameters.
request.setNamespace(alternateKeyHelper.validateStringParameter("namespace", request.getNamespace()));
request.setBusinessObjectDefinitionName(alternateKeyHelper.validateStringParameter("business object definition name", request.getBusinessObjectDefinitionName()));
request.setBusinessObjectFormatUsage(alternateKeyHelper.validateStringParameter("business object format usage", request.getBusinessObjectFormatUsage()));
request.setBusinessObjectFormatFileType(alternateKeyHelper.validateStringParameter("business object format file type", request.getBusinessObjectFormatFileType()));
Assert.notNull(request.getBusinessObjectFormatVersion(), "A business object format version must be specified.");
request.setPartitionKey(alternateKeyHelper.validateStringParameter("partition key", request.getPartitionKey()));
request.setPartitionValue(alternateKeyHelper.validateStringParameter("partition value", request.getPartitionValue()));
businessObjectDataHelper.validateSubPartitionValues(request.getSubPartitionValues());
Assert.isTrue(CollectionUtils.isNotEmpty(request.getStorageUnits()), "At least one storage unit must be specified.");
for (StorageUnitCreateRequest storageUnit : request.getStorageUnits()) {
Assert.notNull(storageUnit, "A storage unit can't be null.");
// Validate and trim the storage name.
Assert.hasText(storageUnit.getStorageName(), "A storage name is required for each storage unit.");
storageUnit.setStorageName(storageUnit.getStorageName().trim());
if (BooleanUtils.isTrue(storageUnit.isDiscoverStorageFiles())) {
// The auto-discovery of storage files is enabled, thus a storage directory is required and storage files cannot be specified.
Assert.isTrue(storageUnit.getStorageDirectory() != null, "A storage directory must be specified when discovery of storage files is enabled.");
Assert.isTrue(CollectionUtils.isEmpty(storageUnit.getStorageFiles()), "Storage files cannot be specified when discovery of storage files is enabled.");
} else if (!Boolean.TRUE.equals(businessObjectDataStatusEntity.getPreRegistrationStatus())) {
// Since auto-discovery is disabled, a storage directory or at least one storage file are required for each storage unit.
Assert.isTrue(storageUnit.getStorageDirectory() != null || CollectionUtils.isNotEmpty(storageUnit.getStorageFiles()), "A storage directory or at least one storage file must be specified for each storage unit.");
}
// If storageDirectory element is present in the request, we require it to contain a non-empty directoryPath element.
if (storageUnit.getStorageDirectory() != null) {
Assert.hasText(storageUnit.getStorageDirectory().getDirectoryPath(), "A storage directory path must be specified.");
storageUnit.getStorageDirectory().setDirectoryPath(storageUnit.getStorageDirectory().getDirectoryPath().trim());
}
if (CollectionUtils.isNotEmpty(storageUnit.getStorageFiles())) {
for (StorageFile storageFile : storageUnit.getStorageFiles()) {
Assert.hasText(storageFile.getFilePath(), "A file path must be specified.");
storageFile.setFilePath(storageFile.getFilePath().trim());
if (fileSizeRequired) {
Assert.notNull(storageFile.getFileSizeBytes(), "A file size must be specified.");
}
// Ensure row count is not negative.
if (storageFile.getRowCount() != null) {
Assert.isTrue(storageFile.getRowCount() >= 0, "File \"" + storageFile.getFilePath() + "\" has a row count which is < 0.");
}
}
}
}
// Validate and trim the parents' keys.
validateBusinessObjectDataKeys(request.getBusinessObjectDataParents());
// Validate attributes.
attributeHelper.validateAttributes(request.getAttributes());
}
use of org.finra.herd.model.api.xml.StorageFile in project herd by FINRAOS.
the class BusinessObjectDataInitiateRestoreHelperServiceImplTest method testExecuteS3SpecificSteps.
@Test
public void testExecuteS3SpecificSteps() {
// 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 list of storage files to be passed as an input.
List<StorageFile> storageFiles = Arrays.asList(new StorageFile(S3_KEY, FILE_SIZE, ROW_COUNT));
// Create a DTO for business object data restore parameters.
BusinessObjectDataRestoreDto businessObjectDataRestoreDto = new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, S3_KEY_PREFIX, NO_STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS, storageFiles, NO_EXCEPTION);
// Create an S3 file transfer parameters DTO to access the S3 bucket.
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
// Create an updated version of the S3 file transfer request parameters DTO.
S3FileTransferRequestParamsDto updatedS3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
updatedS3FileTransferRequestParamsDto.setS3BucketName(S3_BUCKET_NAME);
updatedS3FileTransferRequestParamsDto.setS3Endpoint(S3_ENDPOINT);
updatedS3FileTransferRequestParamsDto.setS3KeyPrefix(S3_KEY_PREFIX + "/");
// Create a mock S3 object summary for S3 object that does not belong to Glacier storage class.
S3ObjectSummary glacierS3ObjectSummary = mock(S3ObjectSummary.class);
when(glacierS3ObjectSummary.getStorageClass()).thenReturn(StorageClass.Glacier.toString());
// Create a mock S3 object summary for S3 object that does not belong to Glacier storage class.
S3ObjectSummary standardS3ObjectSummary = mock(S3ObjectSummary.class);
when(standardS3ObjectSummary.getStorageClass()).thenReturn(StorageClass.Standard.toString());
// Create a list of S3 files.
List<S3ObjectSummary> s3Files = Arrays.asList(glacierS3ObjectSummary, standardS3ObjectSummary);
// Create a list of S3 objects that belong to Glacier storage class.
List<S3ObjectSummary> glacierS3Files = Arrays.asList(glacierS3ObjectSummary);
// Create a list of storage files that represent S3 objects of Glacier storage class.
List<StorageFile> glacierStorageFiles = Arrays.asList(new StorageFile(S3_KEY, FILE_SIZE, ROW_COUNT));
// Create a list of storage files selected for S3 object tagging.
List<File> filesSelectedForRestore = Arrays.asList(new File(S3_KEY));
// Create a final version of DTO for business object data restore parameters.
S3FileTransferRequestParamsDto finalS3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
finalS3FileTransferRequestParamsDto.setS3BucketName(S3_BUCKET_NAME);
finalS3FileTransferRequestParamsDto.setS3Endpoint(S3_ENDPOINT);
finalS3FileTransferRequestParamsDto.setS3KeyPrefix(S3_KEY_PREFIX + "/");
finalS3FileTransferRequestParamsDto.setFiles(filesSelectedForRestore);
// Mock the external calls.
when(storageHelper.getS3FileTransferRequestParamsDto()).thenReturn(s3FileTransferRequestParamsDto);
when(s3Service.listDirectory(updatedS3FileTransferRequestParamsDto, true)).thenReturn(s3Files);
when(storageFileHelper.createStorageFilesFromS3ObjectSummaries(glacierS3Files)).thenReturn(glacierStorageFiles);
when(storageFileHelper.getFiles(glacierStorageFiles)).thenReturn(filesSelectedForRestore);
// Call the method under test.
businessObjectDataInitiateRestoreHelperServiceImpl.executeS3SpecificSteps(businessObjectDataRestoreDto);
// Verify the external calls.
verify(storageHelper).getS3FileTransferRequestParamsDto();
verify(s3Service).listDirectory(any(S3FileTransferRequestParamsDto.class), eq(true));
verify(storageFileHelper).validateRegisteredS3Files(storageFiles, s3Files, STORAGE_NAME, businessObjectDataKey);
verify(storageFileHelper).createStorageFilesFromS3ObjectSummaries(glacierS3Files);
verify(storageFileHelper).getFiles(glacierStorageFiles);
verify(s3Service).restoreObjects(finalS3FileTransferRequestParamsDto, 36135);
verifyNoMoreInteractionsHelper();
}
use of org.finra.herd.model.api.xml.StorageFile in project herd by FINRAOS.
the class BusinessObjectDataStorageUnitServiceImplTest method testValidateBusinessObjectDataStorageUnitCreateRequestInvalidParameters.
@Test
public void testValidateBusinessObjectDataStorageUnitCreateRequestInvalidParameters() {
// Try to call the method under test when create request is not specified.
try {
businessObjectDataStorageUnitServiceImpl.validateBusinessObjectDataStorageUnitCreateRequest(null);
fail();
} catch (IllegalArgumentException e) {
assertEquals("A business object data storage unit create request must be specified.", e.getMessage());
}
// Try to call the method under test when auto-discovery is enabled and storage directory is not specified.
try {
businessObjectDataStorageUnitServiceImpl.validateBusinessObjectDataStorageUnitCreateRequest(new BusinessObjectDataStorageUnitCreateRequest(new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME), NO_STORAGE_DIRECTORY, NO_STORAGE_FILES, DISCOVER_STORAGE_FILES));
fail();
} catch (IllegalArgumentException e) {
assertEquals("A storage directory must be specified when discovery of storage files is enabled.", e.getMessage());
}
// Try to call the method under test when auto-discovery is enabled and storage files are specified.
try {
businessObjectDataStorageUnitServiceImpl.validateBusinessObjectDataStorageUnitCreateRequest(new BusinessObjectDataStorageUnitCreateRequest(new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME), new StorageDirectory(STORAGE_DIRECTORY_PATH), Collections.singletonList(new StorageFile(FILE_NAME, FILE_SIZE, ROW_COUNT)), DISCOVER_STORAGE_FILES));
fail();
} catch (IllegalArgumentException e) {
assertEquals("Storage files cannot be specified when discovery of storage files is enabled.", e.getMessage());
}
// Try to call the method under test when auto-discovery is not enabled and no storage directory or files are specified.
try {
businessObjectDataStorageUnitServiceImpl.validateBusinessObjectDataStorageUnitCreateRequest(new BusinessObjectDataStorageUnitCreateRequest(new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME), NO_STORAGE_DIRECTORY, NO_STORAGE_FILES, NO_DISCOVER_STORAGE_FILES));
fail();
} catch (IllegalArgumentException e) {
assertEquals("A storage directory or at least one storage file must be specified when discovery of storage files is not enabled.", e.getMessage());
}
// Try to call the method under test when storage directory is specified with a blank storage directory path.
try {
businessObjectDataStorageUnitServiceImpl.validateBusinessObjectDataStorageUnitCreateRequest(new BusinessObjectDataStorageUnitCreateRequest(new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME), new StorageDirectory(BLANK_TEXT), NO_STORAGE_FILES, NO_DISCOVER_STORAGE_FILES));
fail();
} catch (IllegalArgumentException e) {
assertEquals("A storage directory path must be specified.", e.getMessage());
}
}
use of org.finra.herd.model.api.xml.StorageFile in project herd by FINRAOS.
the class BusinessObjectDataStorageUnitServiceImplTest method testCreateBusinessObjectDataStorageUnit.
@Test
public void testCreateBusinessObjectDataStorageUnit() {
// 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 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 unit directory.
StorageDirectory storageDirectory = new StorageDirectory(STORAGE_DIRECTORY_PATH);
// Create a list of storage files.
List<StorageFile> storageFiles = Arrays.asList(new StorageFile(FILE_NAME, FILE_SIZE, ROW_COUNT), new StorageFile(FILE_NAME_2, FILE_SIZE_2, ROW_COUNT_2));
// Create a business object data storage unit request.
BusinessObjectDataStorageUnitCreateRequest request = new BusinessObjectDataStorageUnitCreateRequest(businessObjectDataStorageUnitKey, storageDirectory, storageFiles, NO_DISCOVER_STORAGE_FILES);
// Create a business object data entity.
BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
businessObjectDataEntity.setId(ID);
// Create a storage entity.
StorageEntity storageEntity = new StorageEntity();
storageEntity.setName(STORAGE_NAME);
// Create a list of storage file entities.
List<StorageFileEntity> storageFileEntities = Arrays.asList(new StorageFileEntity(), new StorageFileEntity());
// Create a storage unit entity.
StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
storageUnitEntity.setBusinessObjectData(businessObjectDataEntity);
storageUnitEntity.setStorage(storageEntity);
storageUnitEntity.setDirectoryPath(STORAGE_DIRECTORY_PATH);
storageUnitEntity.setStorageFiles(storageFileEntities);
// Create an expected business object data storage unit response.
BusinessObjectDataStorageUnitCreateResponse expectedResponse = new BusinessObjectDataStorageUnitCreateResponse(businessObjectDataStorageUnitKey, storageDirectory, storageFiles);
// Mock the external calls.
when(storageUnitHelper.getBusinessObjectDataKey(businessObjectDataStorageUnitKey)).thenReturn(businessObjectDataKey);
when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey)).thenReturn(businessObjectDataEntity);
when(storageDaoHelper.getStorageEntity(STORAGE_NAME)).thenReturn(storageEntity);
when(businessObjectDataDaoHelper.createStorageUnitEntity(businessObjectDataEntity, storageEntity, storageDirectory, storageFiles, NO_DISCOVER_STORAGE_FILES)).thenReturn(storageUnitEntity);
when(businessObjectDataHelper.createBusinessObjectDataKeyFromEntity(businessObjectDataEntity)).thenReturn(businessObjectDataKey);
when(storageUnitHelper.createBusinessObjectDataStorageUnitKey(businessObjectDataKey, STORAGE_NAME)).thenReturn(businessObjectDataStorageUnitKey);
when(storageFileHelper.createStorageFilesFromEntities(storageFileEntities)).thenReturn(storageFiles);
// Call the method under test.
BusinessObjectDataStorageUnitCreateResponse result = businessObjectDataStorageUnitServiceImpl.createBusinessObjectDataStorageUnit(request);
// Verify the external calls.
verify(storageUnitHelper).validateBusinessObjectDataStorageUnitKey(businessObjectDataStorageUnitKey);
verify(storageFileHelper).validateCreateRequestStorageFiles(storageFiles);
verify(storageUnitHelper).getBusinessObjectDataKey(businessObjectDataStorageUnitKey);
verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey);
verify(storageDaoHelper).getStorageEntity(STORAGE_NAME);
verify(businessObjectDataDaoHelper).createStorageUnitEntity(businessObjectDataEntity, storageEntity, storageDirectory, storageFiles, NO_DISCOVER_STORAGE_FILES);
verify(businessObjectDataHelper).createBusinessObjectDataKeyFromEntity(businessObjectDataEntity);
verify(storageUnitHelper).createBusinessObjectDataStorageUnitKey(businessObjectDataKey, STORAGE_NAME);
verify(storageFileHelper).createStorageFilesFromEntities(storageFileEntities);
verify(storageUnitDao).saveAndRefresh(storageUnitEntity);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(expectedResponse, result);
}
use of org.finra.herd.model.api.xml.StorageFile in project herd by FINRAOS.
the class ExpireRestoredBusinessObjectDataServiceImplTest method testExpireS3StorageUnit.
@Test
public void testExpireS3StorageUnit() {
// 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 key.
BusinessObjectDataStorageUnitKey storageUnitKey = 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 DTO for business object data restore parameters.
BusinessObjectDataRestoreDto businessObjectDataRestoreDto = new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, S3_KEY_PREFIX, StorageUnitStatusEntity.EXPIRING, StorageUnitStatusEntity.RESTORED, Arrays.asList(new StorageFile(S3_KEY, FILE_SIZE, ROW_COUNT)), NO_EXCEPTION);
// Mock the external calls.
when(expireRestoredBusinessObjectDataHelperService.prepareToExpireStorageUnit(storageUnitKey)).thenReturn(businessObjectDataRestoreDto);
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) {
// Get the parameters DTO for the business object data restore.
BusinessObjectDataRestoreDto businessObjectDataRestoreDto = (BusinessObjectDataRestoreDto) invocation.getArguments()[0];
// Set the value for the new and old storage unit statuses.
businessObjectDataRestoreDto.setNewStorageUnitStatus(StorageUnitStatusEntity.ARCHIVED);
businessObjectDataRestoreDto.setOldStorageUnitStatus(StorageUnitStatusEntity.EXPIRING);
return null;
}
}).when(expireRestoredBusinessObjectDataHelperService).completeStorageUnitExpiration(businessObjectDataRestoreDto);
// Call the method under test.
expireRestoredBusinessObjectDataServiceImpl.expireS3StorageUnit(storageUnitKey);
// Verify the external calls.
verify(expireRestoredBusinessObjectDataHelperService).prepareToExpireStorageUnit(storageUnitKey);
verify(notificationEventService).processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataKey, STORAGE_NAME, StorageUnitStatusEntity.EXPIRING, StorageUnitStatusEntity.RESTORED);
verify(expireRestoredBusinessObjectDataHelperService).executeS3SpecificSteps(businessObjectDataRestoreDto);
verify(expireRestoredBusinessObjectDataHelperService).completeStorageUnitExpiration(businessObjectDataRestoreDto);
verify(notificationEventService).processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataKey, STORAGE_NAME, StorageUnitStatusEntity.ARCHIVED, StorageUnitStatusEntity.EXPIRING);
verifyNoMoreInteractionsHelper();
}
Aggregations