Search in sources :

Example 51 with StorageFile

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

the class StorageFileDaoHelper method createStorageFileEntitiesFromStorageFiles.

/**
 * Creates storage file entities from the list of storage files.
 *
 * @param storageUnitEntity the storage unit entity
 * @param storageFiles the list of storage files
 *
 * @return the list storage file entities
 */
public List<StorageFileEntity> createStorageFileEntitiesFromStorageFiles(StorageUnitEntity storageUnitEntity, List<StorageFile> storageFiles) {
    List<StorageFileEntity> storageFileEntities = new ArrayList<>();
    for (StorageFile storageFile : storageFiles) {
        StorageFileEntity storageFileEntity = new StorageFileEntity();
        storageFileEntities.add(storageFileEntity);
        storageFileEntity.setStorageUnit(storageUnitEntity);
        storageFileEntity.setPath(storageFile.getFilePath());
        storageFileEntity.setFileSizeBytes(storageFile.getFileSizeBytes());
        storageFileEntity.setRowCount(storageFile.getRowCount());
        storageFileDao.saveAndRefresh(storageFileEntity);
    }
    return storageFileEntities;
}
Also used : StorageFileEntity(org.finra.herd.model.jpa.StorageFileEntity) ArrayList(java.util.ArrayList) StorageFile(org.finra.herd.model.api.xml.StorageFile)

Example 52 with StorageFile

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

the class BusinessObjectDataInitiateRestoreHelperServiceImpl method prepareToInitiateRestoreImpl.

/**
 * Prepares for the business object data initiate a restore request by validating the business object data along with other related database entities. The
 * method also creates and returns a business object data restore DTO.
 *
 * @param businessObjectDataKey the business object data key
 * @param expirationInDays the the time, in days, between when the business object data is restored to the S3 bucket and when it expires
 *
 * @return the DTO that holds various parameters needed to perform a business object data restore
 */
protected BusinessObjectDataRestoreDto prepareToInitiateRestoreImpl(BusinessObjectDataKey businessObjectDataKey, Integer expirationInDays) {
    // Validate and trim the business object data key.
    businessObjectDataHelper.validateBusinessObjectDataKey(businessObjectDataKey, true, true);
    // If expiration time is not specified, use the configured default value.
    int localExpirationInDays = expirationInDays != null ? expirationInDays : herdStringHelper.getConfigurationValueAsInteger(ConfigurationValue.BDATA_RESTORE_EXPIRATION_IN_DAYS_DEFAULT);
    // Validate the expiration time.
    Assert.isTrue(localExpirationInDays > 0, "Expiration in days value must be a positive integer.");
    // Retrieve the business object data and ensure it exists.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey);
    // Retrieve and validate a Glacier storage unit for this business object data.
    StorageUnitEntity storageUnitEntity = getStorageUnit(businessObjectDataEntity);
    // Get the storage name.
    String storageName = storageUnitEntity.getStorage().getName();
    // 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());
    // Set the expiration time for the restored storage unit.
    Timestamp currentTime = new Timestamp(System.currentTimeMillis());
    storageUnitEntity.setRestoreExpirationOn(HerdDateUtils.addDays(currentTime, localExpirationInDays));
    // Retrieve and ensure the RESTORING storage unit status entity exists.
    StorageUnitStatusEntity newStorageUnitStatusEntity = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(StorageUnitStatusEntity.RESTORING);
    // Save the old storage unit status value.
    String oldOriginStorageUnitStatus = storageUnitEntity.getStatus().getCode();
    // Update the S3 storage unit status to RESTORING.
    storageUnitDaoHelper.updateStorageUnitStatus(storageUnitEntity, newStorageUnitStatusEntity, StorageUnitStatusEntity.RESTORING);
    // Build the business object data restore parameters DTO.
    BusinessObjectDataRestoreDto businessObjectDataRestoreDto = new BusinessObjectDataRestoreDto();
    businessObjectDataRestoreDto.setBusinessObjectDataKey(businessObjectDataHelper.getBusinessObjectDataKey(businessObjectDataEntity));
    businessObjectDataRestoreDto.setStorageName(storageName);
    businessObjectDataRestoreDto.setS3Endpoint(configurationHelper.getProperty(ConfigurationValue.S3_ENDPOINT));
    businessObjectDataRestoreDto.setS3BucketName(s3BucketName);
    businessObjectDataRestoreDto.setS3KeyPrefix(s3KeyPrefix);
    businessObjectDataRestoreDto.setStorageFiles(storageFiles);
    businessObjectDataRestoreDto.setNewStorageUnitStatus(newStorageUnitStatusEntity.getCode());
    businessObjectDataRestoreDto.setOldStorageUnitStatus(oldOriginStorageUnitStatus);
    // Return the parameters DTO.
    return businessObjectDataRestoreDto;
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) StorageFile(org.finra.herd.model.api.xml.StorageFile) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) Timestamp(java.sql.Timestamp) BusinessObjectDataRestoreDto(org.finra.herd.model.dto.BusinessObjectDataRestoreDto)

Example 53 with StorageFile

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

the class ExpireRestoredBusinessObjectDataHelperServiceImpl method prepareToExpireStorageUnitImpl.

/**
 * Prepares for the business object data expiration by validating the S3 storage unit along with other related database entities. The method also creates
 * and returns a DTO that contains parameters needed to expire business object data.
 *
 * @param storageUnitKey the storage unit key
 *
 * @return the DTO that holds various parameters required to expire business object data
 */
protected BusinessObjectDataRestoreDto prepareToExpireStorageUnitImpl(BusinessObjectDataStorageUnitKey storageUnitKey) {
    // Get the storage unit 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(storageName, 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());
    // Update the storage unit status.
    String oldStorageUnitStatus = storageUnitEntity.getStatus().getCode();
    String reason = StorageUnitStatusEntity.EXPIRING;
    storageUnitDaoHelper.updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.EXPIRING, reason);
    // Build a DTO with parameters required to expire business object data.
    BusinessObjectDataRestoreDto businessObjectDataRestoreDto = new BusinessObjectDataRestoreDto();
    businessObjectDataRestoreDto.setBusinessObjectDataKey(businessObjectDataKey);
    businessObjectDataRestoreDto.setNewStorageUnitStatus(storageUnitEntity.getStatus().getCode());
    businessObjectDataRestoreDto.setOldStorageUnitStatus(oldStorageUnitStatus);
    businessObjectDataRestoreDto.setS3BucketName(s3BucketName);
    businessObjectDataRestoreDto.setS3Endpoint(configurationHelper.getProperty(ConfigurationValue.S3_ENDPOINT));
    businessObjectDataRestoreDto.setS3KeyPrefix(s3KeyPrefix);
    businessObjectDataRestoreDto.setStorageFiles(storageFiles);
    businessObjectDataRestoreDto.setStorageName(storageName);
    // Return the business object data restore parameters DTO.
    return businessObjectDataRestoreDto;
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) StorageFile(org.finra.herd.model.api.xml.StorageFile) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectDataRestoreDto(org.finra.herd.model.dto.BusinessObjectDataRestoreDto)

Example 54 with StorageFile

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

the class BusinessObjectDataFinalizeRestoreHelperServiceTest method testCompleteFinalizeRestore.

@Test
public void testCompleteFinalizeRestore() 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 database entities required for testing.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForFinalizeRestoreTesting(businessObjectDataKey);
    // Get the origin storage unit entity.
    StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity);
    // Validate that the storage unit status is RESTORING.
    assertEquals(StorageUnitStatusEntity.RESTORING, storageUnitEntity.getStatus().getCode());
    // Create a business object data restore DTO.
    BusinessObjectDataRestoreDto businessObjectDataRestoreDto = new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, TEST_S3_KEY_PREFIX, NO_STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS, Arrays.asList(new StorageFile(TEST_S3_KEY_PREFIX + "/" + LOCAL_FILE, FILE_SIZE_1_KB, NO_ROW_COUNT)), NO_EXCEPTION);
    // Enable origin storage unit to finalize a restore for business object data.
    businessObjectDataFinalizeRestoreHelperService.completeFinalizeRestore(businessObjectDataRestoreDto);
    // Validate that the storage unit status is RESTORED.
    assertEquals(StorageUnitStatusEntity.RESTORED, storageUnitEntity.getStatus().getCode());
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) StorageFile(org.finra.herd.model.api.xml.StorageFile) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectDataRestoreDto(org.finra.herd.model.dto.BusinessObjectDataRestoreDto) Test(org.junit.Test)

Example 55 with StorageFile

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

the class BusinessObjectDataFinalizeRestoreHelperServiceTest method testBusinessObjectDataFinalizeRestoreHelperServiceMethodsNewTransactionPropagation.

/**
 * This method is to get coverage for the business object data finalize restore helper service methods that have an explicit annotation for transaction
 * propagation.
 */
@Test
public void testBusinessObjectDataFinalizeRestoreHelperServiceMethodsNewTransactionPropagation() {
    // 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 = storageUnitHelper.createStorageUnitKey(businessObjectDataKey, STORAGE_NAME);
    try {
        businessObjectDataFinalizeRestoreHelperServiceImpl.prepareToFinalizeRestore(storageUnitKey);
        fail();
    } catch (ObjectNotFoundException e) {
        assertEquals(businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataNotFoundErrorMessage(businessObjectDataKey, NO_BDATA_STATUS), e.getMessage());
    }
    // Create a storage file.
    StorageFile storageFile = new StorageFile(TEST_S3_KEY_PREFIX + "/" + LOCAL_FILE, FILE_SIZE_1_KB, NO_ROW_COUNT);
    // Create a business object data restore DTO.
    BusinessObjectDataRestoreDto businessObjectDataRestoreDto = new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, NO_S3_ENDPOINT, S3_BUCKET_NAME, TEST_S3_KEY_PREFIX, NO_STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS, Arrays.asList(storageFile), NO_EXCEPTION);
    try {
        businessObjectDataFinalizeRestoreHelperServiceImpl.executeS3SpecificSteps(businessObjectDataRestoreDto);
        fail();
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Registered file \"%s\" does not exist in \"%s\" storage.", storageFile.getFilePath(), STORAGE_NAME), e.getMessage());
    }
    try {
        businessObjectDataFinalizeRestoreHelperServiceImpl.completeFinalizeRestore(businessObjectDataRestoreDto);
        fail();
    } catch (ObjectNotFoundException e) {
        assertEquals(businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataNotFoundErrorMessage(businessObjectDataKey, NO_BDATA_STATUS), e.getMessage());
    }
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) StorageFile(org.finra.herd.model.api.xml.StorageFile) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectDataRestoreDto(org.finra.herd.model.dto.BusinessObjectDataRestoreDto) 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