Search in sources :

Example 56 with StorageFile

use of org.finra.herd.model.api.xml.StorageFile in project herd by FINRAOS.

the class BusinessObjectDataHelper method createBusinessObjectDataCreateRequest.

/**
 * Validates the upload single initiation request. This method also trims the request parameters.
 *
 * @param businessObjectFormatEntity the business object format entity
 * @param uuid the UUID
 * @param businessObjectDataStatus the status of the business object data
 * @param attributes the list of attributes
 * @param storageEntity the storage entity
 * @param storageDirectoryPath the storage directory path
 * @param storageFilePath the storage file path
 * @param storageFileSizeBytes the storage file size in bytes
 * @param storageFileRowCount the storage file row count
 *
 * @return the business object data create request.
 */
public BusinessObjectDataCreateRequest createBusinessObjectDataCreateRequest(BusinessObjectFormatEntity businessObjectFormatEntity, String uuid, String businessObjectDataStatus, List<Attribute> attributes, StorageEntity storageEntity, String storageDirectoryPath, String storageFilePath, Long storageFileSizeBytes, Long storageFileRowCount) {
    BusinessObjectDataCreateRequest request = new BusinessObjectDataCreateRequest();
    // Set the values required for the business object data partition key.
    request.setNamespace(businessObjectFormatEntity.getBusinessObjectDefinition().getNamespace().getCode());
    request.setBusinessObjectDefinitionName(businessObjectFormatEntity.getBusinessObjectDefinition().getName());
    request.setBusinessObjectFormatUsage(businessObjectFormatEntity.getUsage());
    request.setBusinessObjectFormatFileType(businessObjectFormatEntity.getFileType().getCode());
    request.setBusinessObjectFormatVersion(businessObjectFormatEntity.getBusinessObjectFormatVersion());
    request.setPartitionKey(businessObjectFormatEntity.getPartitionKey());
    request.setPartitionValue(uuid);
    // Set the business object data status.
    request.setStatus(businessObjectDataStatus);
    // Add a storage unit.
    StorageUnitCreateRequest storageUnitCreateRequest = new StorageUnitCreateRequest();
    request.setStorageUnits(Arrays.asList(storageUnitCreateRequest));
    storageUnitCreateRequest.setStorageName(storageEntity.getName());
    storageUnitCreateRequest.setStorageDirectory(new StorageDirectory(storageDirectoryPath));
    storageUnitCreateRequest.setStorageFiles(Arrays.asList(new StorageFile(storageFilePath, storageFileSizeBytes, storageFileRowCount)));
    // Set the attributes if any are specified.
    request.setAttributes(attributes);
    // Since we are using UUID as our partition value, set the flag to only allow business object data initial version creation.
    request.setCreateNewVersion(false);
    return request;
}
Also used : BusinessObjectDataCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest) StorageFile(org.finra.herd.model.api.xml.StorageFile) StorageDirectory(org.finra.herd.model.api.xml.StorageDirectory) StorageUnitCreateRequest(org.finra.herd.model.api.xml.StorageUnitCreateRequest)

Example 57 with StorageFile

use of org.finra.herd.model.api.xml.StorageFile in project herd by FINRAOS.

the class StoragePolicyProcessorServiceTest method testProcessStoragePolicySelectionMessageRuntimeException.

@Test
public void testProcessStoragePolicySelectionMessageRuntimeException() throws Exception {
    // Build the expected S3 key prefix for test business object data.
    String s3KeyPrefix = getExpectedS3KeyPrefix(BDEF_NAMESPACE, DATA_PROVIDER_NAME, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, null, null, DATA_VERSION);
    // Create S3FileTransferRequestParamsDto to access the S3 bucket location.
    // Since test S3 key prefix represents a directory, we add a trailing '/' character to it.
    S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = S3FileTransferRequestParamsDto.builder().withS3BucketName(S3_BUCKET_NAME).withS3KeyPrefix(s3KeyPrefix + "/").build();
    // Create and persist the relative database entities.
    storagePolicyServiceTestHelper.createDatabaseEntitiesForStoragePolicyTesting(STORAGE_POLICY_NAMESPACE_CD, Arrays.asList(STORAGE_POLICY_RULE_TYPE), BDEF_NAMESPACE, BDEF_NAME, Arrays.asList(FORMAT_FILE_TYPE_CODE), Arrays.asList(STORAGE_NAME), Arrays.asList(StoragePolicyTransitionTypeEntity.GLACIER));
    // 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 and persist a storage unit in the storage.
    StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, businessObjectDataKey, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.VALID, StorageUnitStatusEntity.ENABLED, NO_STORAGE_DIRECTORY_PATH);
    // Add storage files to the storage unit.
    for (String filePath : LOCAL_FILES) {
        storageFileDaoTestHelper.createStorageFileEntity(storageUnitEntity, s3KeyPrefix + "/" + filePath, FILE_SIZE_1_KB, ROW_COUNT_1000);
    }
    // Get the storage files.
    List<StorageFile> storageFiles = storageFileHelper.createStorageFilesFromEntities(storageUnitEntity.getStorageFiles());
    // Create a storage policy key.
    StoragePolicyKey storagePolicyKey = new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME);
    // Create and persist a storage policy entity.
    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);
    // Override configuration to specify some settings required for testing.
    Map<String, Object> overrideMap = new HashMap<>();
    overrideMap.put(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_ROLE_ARN.getKey(), S3_OBJECT_TAGGER_ROLE_ARN);
    overrideMap.put(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_ROLE_SESSION_NAME.getKey(), S3_OBJECT_TAGGER_ROLE_SESSION_NAME);
    modifyPropertySourceInEnvironment(overrideMap);
    try {
        // Put relative S3 files into the S3 bucket, except for the last one.  This should trigger a RuntimeException.
        for (StorageFile storageFile : storageFiles.subList(0, storageFiles.size() - 1)) {
            s3Operations.putObject(new PutObjectRequest(S3_BUCKET_NAME, storageFile.getFilePath(), new ByteArrayInputStream(new byte[storageFile.getFileSizeBytes().intValue()]), null), null);
        }
        // Try to perform a storage policy transition.
        storagePolicyProcessorService.processStoragePolicySelectionMessage(new StoragePolicySelection(businessObjectDataKey, storagePolicyKey, INITIAL_VERSION));
        fail();
    } catch (RuntimeException e) {
        // Validate the exception error message.
        assertEquals(String.format("Registered file \"%s\" does not exist in \"%s\" storage.", storageFiles.get(storageFiles.size() - 1).getFilePath(), STORAGE_NAME), e.getMessage());
        // Validate the StoragePolicyTransitionFailedAttempts value.
        assertEquals(Integer.valueOf(1), storageUnitEntity.getStoragePolicyTransitionFailedAttempts());
        // Validate the status of the storage unit.
        assertEquals(StorageUnitStatusEntity.ARCHIVING, storageUnitEntity.getStatus().getCode());
    } finally {
        // Delete test files from S3 storage.
        if (!s3Dao.listDirectory(s3FileTransferRequestParamsDto).isEmpty()) {
            s3Dao.deleteDirectory(s3FileTransferRequestParamsDto);
        }
        s3Operations.rollback();
        // Restore the property sources so we don't affect other tests.
        restorePropertySourceInEnvironment();
    }
}
Also used : S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) HashMap(java.util.HashMap) StoragePolicySelection(org.finra.herd.model.dto.StoragePolicySelection) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) ByteArrayInputStream(java.io.ByteArrayInputStream) StoragePolicyKey(org.finra.herd.model.api.xml.StoragePolicyKey) StorageFile(org.finra.herd.model.api.xml.StorageFile) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) Test(org.junit.Test)

Example 58 with StorageFile

use of org.finra.herd.model.api.xml.StorageFile in project herd by FINRAOS.

the class StoragePolicyProcessorHelperServiceTest method runExecuteStoragePolicyTransitionTest.

private void runExecuteStoragePolicyTransitionTest() {
    // Create S3FileTransferRequestParamsDto to access the S3 bucket location.
    // Since test S3 key prefix represents a directory, we add a trailing '/' character to it.
    S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = S3FileTransferRequestParamsDto.builder().withS3BucketName(S3_BUCKET_NAME).withS3KeyPrefix(TEST_S3_KEY_PREFIX + "/").build();
    // Create a list of storage files.
    List<StorageFile> storageFiles = new ArrayList<>();
    for (String file : LOCAL_FILES) {
        storageFiles.add(new StorageFile(String.format(String.format("%s/%s", TEST_S3_KEY_PREFIX, file)), FILE_SIZE_1_KB, ROW_COUNT));
    }
    try {
        // Put relative S3 files into the S3 bucket.
        for (StorageFile storageFile : storageFiles) {
            s3Operations.putObject(new PutObjectRequest(S3_BUCKET_NAME, storageFile.getFilePath(), new ByteArrayInputStream(new byte[(int) FILE_SIZE_1_KB]), null), null);
        }
        // Execute a storage policy transition.
        storagePolicyProcessorHelperService.executeStoragePolicyTransition(new StoragePolicyTransitionParamsDto(new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION), STORAGE_NAME, NO_S3_ENDPOINT, S3_BUCKET_NAME, TEST_S3_KEY_PREFIX, NO_STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS, storageFiles, S3_ARCHIVE_TO_GLACIER_TAG_KEY, S3_ARCHIVE_TO_GLACIER_TAG_VALUE, S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME));
        // Validate that all S3 files are now tagged.
        for (StorageFile storageFile : storageFiles) {
            GetObjectTaggingResult getObjectTaggingResult = s3Operations.getObjectTagging(new GetObjectTaggingRequest(S3_BUCKET_NAME, storageFile.getFilePath()), null);
            assertEquals(Arrays.asList(new Tag(S3_ARCHIVE_TO_GLACIER_TAG_KEY, S3_ARCHIVE_TO_GLACIER_TAG_VALUE)), getObjectTaggingResult.getTagSet());
        }
    } finally {
        // Delete test files from S3 storage.
        if (!s3Dao.listDirectory(s3FileTransferRequestParamsDto).isEmpty()) {
            s3Dao.deleteDirectory(s3FileTransferRequestParamsDto);
        }
        s3Operations.rollback();
    }
}
Also used : GetObjectTaggingRequest(com.amazonaws.services.s3.model.GetObjectTaggingRequest) S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) ByteArrayInputStream(java.io.ByteArrayInputStream) StorageFile(org.finra.herd.model.api.xml.StorageFile) ArrayList(java.util.ArrayList) StoragePolicyTransitionParamsDto(org.finra.herd.model.dto.StoragePolicyTransitionParamsDto) Tag(com.amazonaws.services.s3.model.Tag) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) GetObjectTaggingResult(com.amazonaws.services.s3.model.GetObjectTaggingResult)

Example 59 with StorageFile

use of org.finra.herd.model.api.xml.StorageFile in project herd by FINRAOS.

the class BusinessObjectDataStorageFileServiceImpl method discoverStorageFiles.

/**
 * Discovers new storage files in S3 for the specified storage unit.
 *
 * @param storageUnitEntity the storage unit entity
 *
 * @return the list of discovered storage files
 */
private List<StorageFile> discoverStorageFiles(StorageUnitEntity storageUnitEntity) {
    // Retrieve all storage files already registered for this storage unit loaded in a map for easy access.
    Map<String, StorageFileEntity> storageFileEntities = storageFileHelper.getStorageFileEntitiesMap(storageUnitEntity.getStorageFiles());
    // Validate and get storage directory path from the storage unit.
    Assert.hasText(storageUnitEntity.getDirectoryPath(), "Business object data has no storage directory path which is required for auto-discovery of storage files.");
    String directoryPath = storageUnitEntity.getDirectoryPath();
    // Add a trailing slash to the storage directory path if it doesn't already have it.
    String directoryPathWithTrailingSlash = StringUtils.appendIfMissing(directoryPath, "/");
    // Retrieve all already registered storage files from the storage that start with the directory path.
    List<String> registeredStorageFilePaths = storageFileDao.getStorageFilesByStorageAndFilePathPrefix(storageUnitEntity.getStorage().getName(), directoryPathWithTrailingSlash);
    // Sanity check already registered storage files.
    if (storageFileEntities.size() != registeredStorageFilePaths.size()) {
        throw new IllegalArgumentException(String.format("Number of storage files (%d) already registered for the business object data in \"%s\" storage is not equal to " + "the number of registered storage files (%d) matching \"%s\" S3 key prefix in the same storage.", storageFileEntities.size(), storageUnitEntity.getStorage().getName(), registeredStorageFilePaths.size(), directoryPathWithTrailingSlash));
    }
    // Get S3 bucket access parameters and set the key prefix to the directory path with a trailing slash.
    // Please note that since we got here, the directory path can not be empty.
    S3FileTransferRequestParamsDto params = storageHelper.getS3BucketAccessParams(storageUnitEntity.getStorage());
    params.setS3KeyPrefix(directoryPathWithTrailingSlash);
    // List S3 files ignoring 0 byte objects that represent S3 directories.
    // Please note that the map implementation returned by the helper method below
    // preserves the original order of files as returned by the S3 list command.
    Map<String, StorageFile> actualS3Keys = storageFileHelper.getStorageFilesMapFromS3ObjectSummaries(s3Service.listDirectory(params, true));
    // For the already registered storage files, validate file existence and file size against S3 keys and metadata reported by S3.
    for (Map.Entry<String, StorageFileEntity> entry : storageFileEntities.entrySet()) {
        storageFileHelper.validateStorageFileEntity(entry.getValue(), params.getS3BucketName(), actualS3Keys, true);
    }
    // Remove all already registered storage files from the map of actual S3 keys.
    actualS3Keys.keySet().removeAll(storageFileEntities.keySet());
    // Validate that we have at least one unregistered storage file discovered in S3.
    Assert.notEmpty(actualS3Keys.keySet(), String.format("No unregistered storage files were discovered at s3://%s/%s location.", params.getS3BucketName(), directoryPathWithTrailingSlash));
    // Build and return a list of storage files.
    return new ArrayList<>(actualS3Keys.values());
}
Also used : StorageFileEntity(org.finra.herd.model.jpa.StorageFileEntity) S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) StorageFile(org.finra.herd.model.api.xml.StorageFile) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 60 with StorageFile

use of org.finra.herd.model.api.xml.StorageFile in project herd by FINRAOS.

the class BusinessObjectDataServiceCreateBusinessObjectDataTest method testCreateBusinessObjectDataMissingRequiredParameters.

@Test
public void testCreateBusinessObjectDataMissingRequiredParameters() {
    // Create relative database entities.
    businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, FORMAT_DESCRIPTION, true, PARTITION_KEY);
    storageDaoTestHelper.createStorageEntity(STORAGE_NAME);
    BusinessObjectDataCreateRequest request;
    List<StorageFile> storageFiles;
    // Try to create a business object data instance when business object definition name is not specified.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BLANK_TEXT, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when business object definition name is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A business object definition name must be specified.", e.getMessage());
    }
    // Try to create a business object data instance when business object format usage is not specified.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, BLANK_TEXT, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when business object format usage is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A business object format usage must be specified.", e.getMessage());
    }
    // Try to create a business object data instance when business object format file type is not specified.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, BLANK_TEXT, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when business object format file type is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A business object format file type must be specified.", e.getMessage());
    }
    // Try to create a business object data instance when business object format version is not specified.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, null, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when business object format version is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A business object format version must be specified.", e.getMessage());
    }
    // Try to create a business object data instance when business object format partition key is not specified.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, BLANK_TEXT, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when business object format partition key is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A partition key must be specified.", e.getMessage());
    }
    // Try to create a business object data instance when partition value is not specified.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, BLANK_TEXT, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when partition value is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A partition value must be specified.", e.getMessage());
    }
    // Try to create a business object data instance when request contains no storage units element.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
    request.setStorageUnits(null);
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when when request contains no storage units element.");
    } catch (IllegalArgumentException e) {
        assertEquals("At least one storage unit must be specified.", e.getMessage());
    }
    // Try to create a business object data instance when no storage units are specified.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
    request.setStorageUnits(new ArrayList<StorageUnitCreateRequest>());
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when when no storage units are specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("At least one storage unit must be specified.", e.getMessage());
    }
    // Try to create a business object data instance when request contains an empty storage unit element.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
    List<StorageUnitCreateRequest> storageUnits = new ArrayList<>();
    storageUnits.add(null);
    request.setStorageUnits(storageUnits);
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when when no storage units are specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A storage unit can't be null.", e.getMessage());
    }
    // Try to create a business object data instance when storage name is not specified for a storage unit.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
    request.getStorageUnits().get(0).setStorageName(BLANK_TEXT);
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when storage name is not specified for a storage unit.");
    } catch (IllegalArgumentException e) {
        assertEquals("A storage name is required for each storage unit.", e.getMessage());
    }
    // Try to create a business object data instance when both storage directory and storage files are not specified.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, null, null);
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when both storage directory and storage files are not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A storage directory or at least one storage file must be specified for each storage unit.", e.getMessage());
    }
    // Try to create a business object data instance when storage directory element is present, but the actual directory path value is not specified.
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, BLANK_TEXT, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES));
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when storage directory element is present, but the actual directory path value is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A storage directory path must be specified.", e.getMessage());
    }
    // Try to create a business object data instance when storage file element is present, but the actual file path value is not specified.
    storageFiles = businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, Arrays.asList(LOCAL_FILE));
    storageFiles.get(0).setFilePath(BLANK_TEXT);
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, storageFiles);
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when storage file element is present, but the actual file path value is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A file path must be specified.", e.getMessage());
    }
    // Try to create a business object data instance when storage file size is not specified.
    storageFiles = businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, Arrays.asList(LOCAL_FILE));
    storageFiles.get(0).setFileSizeBytes(null);
    request = businessObjectDataServiceTestHelper.createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BusinessObjectDataStatusEntity.VALID, STORAGE_NAME, testS3KeyPrefix, storageFiles);
    try {
        businessObjectDataService.createBusinessObjectData(request);
        fail("Should throw an IllegalArgumentException when storage file size is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A file size must be specified.", e.getMessage());
    }
}
Also used : BusinessObjectDataCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest) StorageFile(org.finra.herd.model.api.xml.StorageFile) ArrayList(java.util.ArrayList) StorageUnitCreateRequest(org.finra.herd.model.api.xml.StorageUnitCreateRequest) Test(org.junit.Test)

Aggregations

StorageFile (org.finra.herd.model.api.xml.StorageFile)75 Test (org.junit.Test)43 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)38 ArrayList (java.util.ArrayList)26 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)23 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)22 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)16 BusinessObjectDataRestoreDto (org.finra.herd.model.dto.BusinessObjectDataRestoreDto)15 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)15 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)13 BusinessObjectDataCreateRequest (org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest)11 Attribute (org.finra.herd.model.api.xml.Attribute)9 StorageEntity (org.finra.herd.model.jpa.StorageEntity)9 StorageFileEntity (org.finra.herd.model.jpa.StorageFileEntity)9 StorageUnitStatusEntity (org.finra.herd.model.jpa.StorageUnitStatusEntity)8 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)7 ByteArrayInputStream (java.io.ByteArrayInputStream)7 HashMap (java.util.HashMap)7 BusinessObjectDataStorageUnitKey (org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey)7 StorageDirectory (org.finra.herd.model.api.xml.StorageDirectory)7