Search in sources :

Example 16 with BusinessObjectDataRestoreDto

use of org.finra.herd.model.dto.BusinessObjectDataRestoreDto 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 17 with BusinessObjectDataRestoreDto

use of org.finra.herd.model.dto.BusinessObjectDataRestoreDto in project herd by FINRAOS.

the class BusinessObjectDataServiceImpl method restoreBusinessObjectDataImpl.

/**
 * Initiates a restore request for a currently archived business object data. Keeps current transaction context.
 *
 * @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 business object data information
 */
protected BusinessObjectData restoreBusinessObjectDataImpl(BusinessObjectDataKey businessObjectDataKey, Integer expirationInDays) {
    // Execute the initiate a restore request before step.
    BusinessObjectDataRestoreDto businessObjectDataRestoreDto = businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(businessObjectDataKey, expirationInDays);
    // Create storage unit notification for the origin storage unit.
    notificationEventService.processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataRestoreDto.getBusinessObjectDataKey(), businessObjectDataRestoreDto.getStorageName(), businessObjectDataRestoreDto.getNewStorageUnitStatus(), businessObjectDataRestoreDto.getOldStorageUnitStatus());
    // Initiate the restore request.
    businessObjectDataInitiateRestoreHelperService.executeS3SpecificSteps(businessObjectDataRestoreDto);
    // On failure of the above step, execute the "after" step, and re-throw the exception.
    if (businessObjectDataRestoreDto.getException() != null) {
        // On failure, execute the after step that updates the storage unit status back to ARCHIVED.
        businessObjectDataInitiateRestoreHelperService.executeInitiateRestoreAfterStep(businessObjectDataRestoreDto);
        // Create storage unit notification for the origin storage unit.
        notificationEventService.processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataRestoreDto.getBusinessObjectDataKey(), businessObjectDataRestoreDto.getStorageName(), businessObjectDataRestoreDto.getNewStorageUnitStatus(), businessObjectDataRestoreDto.getOldStorageUnitStatus());
        // Re-throw the original exception.
        throw new IllegalStateException(businessObjectDataRestoreDto.getException());
    } else {
        // and return the business object data information.
        return businessObjectDataInitiateRestoreHelperService.executeInitiateRestoreAfterStep(businessObjectDataRestoreDto);
    }
}
Also used : BusinessObjectDataRestoreDto(org.finra.herd.model.dto.BusinessObjectDataRestoreDto)

Example 18 with BusinessObjectDataRestoreDto

use of org.finra.herd.model.dto.BusinessObjectDataRestoreDto 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 19 with BusinessObjectDataRestoreDto

use of org.finra.herd.model.dto.BusinessObjectDataRestoreDto 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 20 with BusinessObjectDataRestoreDto

use of org.finra.herd.model.dto.BusinessObjectDataRestoreDto in project herd by FINRAOS.

the class BusinessObjectDataFinalizeRestoreHelperServiceTest method testPrepareToFinalizeRestore.

@Test
public void testPrepareToFinalizeRestore() 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, NO_SUBPARTITION_VALUES, DATA_VERSION);
    // Create a storage unit key.
    BusinessObjectDataStorageUnitKey storageUnitKey = storageUnitHelper.createStorageUnitKey(businessObjectDataKey, STORAGE_NAME);
    // Create database entities required for testing.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForFinalizeRestoreTesting(businessObjectDataKey);
    // Get the storage unit entity.
    StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity);
    // Prepare to finalize a restore for the business object data.
    BusinessObjectDataRestoreDto result = businessObjectDataFinalizeRestoreHelperService.prepareToFinalizeRestore(storageUnitKey);
    // Validate the returned object.
    assertEquals(new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, NO_S3_ENDPOINT, S3_BUCKET_NAME, result.getS3KeyPrefix(), NO_STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS, storageFileHelper.createStorageFilesFromEntities(storageUnitEntity.getStorageFiles()), NO_EXCEPTION), result);
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) 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)

Aggregations

BusinessObjectDataRestoreDto (org.finra.herd.model.dto.BusinessObjectDataRestoreDto)25 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)21 Test (org.junit.Test)19 StorageFile (org.finra.herd.model.api.xml.StorageFile)15 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)11 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)11 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)8 BusinessObjectDataStorageUnitKey (org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey)6 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)5 StorageUnitStatusEntity (org.finra.herd.model.jpa.StorageUnitStatusEntity)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)3 File (java.io.File)3 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)2 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Timestamp (java.sql.Timestamp)2 ArrayList (java.util.ArrayList)1 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)1 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)1