Search in sources :

Example 36 with StorageUnitEntity

use of org.finra.herd.model.jpa.StorageUnitEntity 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);
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) StoragePolicyKey(org.finra.herd.model.api.xml.StoragePolicyKey) StoragePolicyEntity(org.finra.herd.model.jpa.StoragePolicyEntity) StorageFile(org.finra.herd.model.api.xml.StorageFile) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey)

Example 37 with StorageUnitEntity

use of org.finra.herd.model.jpa.StorageUnitEntity 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());
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey)

Example 38 with StorageUnitEntity

use of org.finra.herd.model.jpa.StorageUnitEntity in project herd by FINRAOS.

the class ExpireRestoredBusinessObjectDataHelperServiceImpl method completeStorageUnitExpirationImpl.

/**
 * Completes the expiration of a storage unit.
 *
 * @param businessObjectDataRestoreDto the DTO that holds various parameters needed to expire business object data
 */
protected void completeStorageUnitExpirationImpl(BusinessObjectDataRestoreDto businessObjectDataRestoreDto) {
    // Retrieve the business object data and ensure it exists.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataRestoreDto.getBusinessObjectDataKey());
    // Retrieve the storage unit and ensure it exists.
    StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(businessObjectDataRestoreDto.getStorageName(), businessObjectDataEntity);
    // Update the storage unit status.
    String oldStorageUnitStatus = storageUnitEntity.getStatus().getCode();
    String reason = StorageUnitStatusEntity.ARCHIVED;
    storageUnitDaoHelper.updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.ARCHIVED, reason);
    // Update the new and old storage unit status values in the DTO.
    businessObjectDataRestoreDto.setNewStorageUnitStatus(storageUnitEntity.getStatus().getCode());
    businessObjectDataRestoreDto.setOldStorageUnitStatus(oldStorageUnitStatus);
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity)

Example 39 with StorageUnitEntity

use of org.finra.herd.model.jpa.StorageUnitEntity in project herd by FINRAOS.

the class ExpireRestoredBusinessObjectDataHelperServiceImpl method getStorageUnit.

/**
 * Retrieves a storage unit for the business object data in the specified storage and validates it.
 *
 * @param storageName the storage name
 * @param businessObjectDataEntity the business object data entity
 *
 * @return the storage unit entity
 */
protected StorageUnitEntity getStorageUnit(String storageName, BusinessObjectDataEntity businessObjectDataEntity) {
    // Get the storage unit and make sure it exists.
    StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(storageName, businessObjectDataEntity);
    // Get the storage unit status.
    String storageUnitStatus = storageUnitEntity.getStatus().getCode();
    // Validate that S3 storage unit is in RESTORED state.
    if (!StorageUnitStatusEntity.RESTORED.equals(storageUnitStatus)) {
        throw new IllegalArgumentException(String.format("S3 storage unit in \"%s\" storage must have \"%s\" status, but it actually has \"%s\" status. Business object data: {%s}", storageName, StorageUnitStatusEntity.RESTORED, storageUnitStatus, businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)));
    }
    return storageUnitEntity;
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity)

Example 40 with StorageUnitEntity

use of org.finra.herd.model.jpa.StorageUnitEntity in project herd by FINRAOS.

the class BusinessObjectDataFinalizeRestoreHelperServiceImpl method prepareToFinalizeRestoreImpl.

/**
 * Prepares for the business object data finalize restore by validating the S3 storage unit along with other related database entities. The method also
 * creates and returns a business object data restore DTO.
 *
 * @param storageUnitKey the storage unit key
 *
 * @return the DTO that holds various parameters needed to perform a business object data restore
 */
protected BusinessObjectDataRestoreDto prepareToFinalizeRestoreImpl(BusinessObjectDataStorageUnitKey storageUnitKey) {
    // Get the storage 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(storageUnitKey.getStorageName(), 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());
    // Build the business object data restore parameters DTO.
    BusinessObjectDataRestoreDto businessObjectDataRestoreDto = new BusinessObjectDataRestoreDto();
    businessObjectDataRestoreDto.setBusinessObjectDataKey(businessObjectDataKey);
    businessObjectDataRestoreDto.setStorageName(storageName);
    businessObjectDataRestoreDto.setS3Endpoint(configurationHelper.getProperty(ConfigurationValue.S3_ENDPOINT));
    businessObjectDataRestoreDto.setS3BucketName(s3BucketName);
    businessObjectDataRestoreDto.setS3KeyPrefix(s3KeyPrefix);
    businessObjectDataRestoreDto.setStorageFiles(storageFiles);
    // 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)

Aggregations

StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)196 Test (org.junit.Test)124 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)105 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)78 StorageEntity (org.finra.herd.model.jpa.StorageEntity)57 ArrayList (java.util.ArrayList)42 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)39 StorageUnitStatusEntity (org.finra.herd.model.jpa.StorageUnitStatusEntity)36 BusinessObjectDataStorageUnitKey (org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey)30 StorageFileEntity (org.finra.herd.model.jpa.StorageFileEntity)30 StoragePolicyKey (org.finra.herd.model.api.xml.StoragePolicyKey)24 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)23 StorageFile (org.finra.herd.model.api.xml.StorageFile)22 Predicate (javax.persistence.criteria.Predicate)19 BusinessObjectDataStatusEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusEntity)19 HashMap (java.util.HashMap)18 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)17 StoragePolicySelection (org.finra.herd.model.dto.StoragePolicySelection)16 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)15 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)14