Search in sources :

Example 31 with StorageUnitEntity

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

the class BusinessObjectDataInitiateRestoreHelperServiceTest method testPrepareToInitiateRestoreMissingOptionalParameters.

@Test
public void testPrepareToInitiateRestoreMissingOptionalParameters() throws Exception {
    // Create a business object data key without sub-partition values.
    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 database entities required for testing.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey);
    // Execute a before step for the initiate a business object data restore request for business object data without sub-partition values.
    BusinessObjectDataRestoreDto storagePolicyTransitionParamsDto = businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(businessObjectDataKey, NO_EXPIRATION_IN_DAYS);
    // Validate the returned object.
    assertEquals(businessObjectDataKey, storagePolicyTransitionParamsDto.getBusinessObjectDataKey());
    // Validate that restore expiration time is set correctly on the storage unit.
    StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity);
    assertNotNull(storageUnitEntity.getRestoreExpirationOn());
    Long differenceInDays = TimeUnit.DAYS.convert(storageUnitEntity.getRestoreExpirationOn().getTime() - storageUnitEntity.getCreatedOn().getTime(), TimeUnit.MILLISECONDS);
    assertTrue((Integer) ConfigurationValue.BDATA_RESTORE_EXPIRATION_IN_DAYS_DEFAULT.getDefaultValue() - differenceInDays <= 1);
}
Also used : 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)

Example 32 with StorageUnitEntity

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

the class BusinessObjectDataInitiateRestoreHelperServiceTest method testPrepareToInitiateRestoreStorageUnitHasNoStorageFiles.

@Test
public void testPrepareToInitiateRestoreStorageUnitHasNoStorageFiles() 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 database entities required for testing.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey, STORAGE_NAME, S3_BUCKET_NAME, StorageUnitStatusEntity.ARCHIVED);
    // Get the storage unit entity.
    StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity);
    // Remove storage files from the storage unit.
    storageUnitEntity.getStorageFiles().clear();
    // Try to execute a before step for the initiate a business object data restore request when storage unit has no storage files.
    try {
        businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(businessObjectDataKey, EXPIRATION_IN_DAYS);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Business object data has no storage files registered in \"%s\" storage. Business object data: {%s}", STORAGE_NAME, businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataKeyAsString(businessObjectDataKey)), e.getMessage());
    }
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Test(org.junit.Test)

Example 33 with StorageUnitEntity

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

the class BusinessObjectDataInitiateRestoreHelperServiceTest method testPrepareToInitiateRestore.

@Test
public void testPrepareToInitiateRestore() 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 database entities required for testing.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey);
    // Get the current time and compute the expected timestamp value.
    Timestamp currentTime = new Timestamp(System.currentTimeMillis());
    Timestamp expectedTimestamp = HerdDateUtils.addDays(currentTime, EXPIRATION_IN_DAYS);
    // Execute a before step for the initiate a business object data restore request.
    BusinessObjectDataRestoreDto storagePolicyTransitionParamsDto = businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(businessObjectDataKey, EXPIRATION_IN_DAYS);
    // Validate the returned object.
    assertEquals(businessObjectDataKey, storagePolicyTransitionParamsDto.getBusinessObjectDataKey());
    // Validate that restore expiration time is set correctly on the storage unit.
    StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity);
    assertNotNull(storageUnitEntity.getRestoreExpirationOn());
    Long differenceInMilliseconds = storageUnitEntity.getRestoreExpirationOn().getTime() - expectedTimestamp.getTime();
    assertTrue(Math.abs(differenceInMilliseconds) < 1000);
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Timestamp(java.sql.Timestamp) BusinessObjectDataRestoreDto(org.finra.herd.model.dto.BusinessObjectDataRestoreDto) Test(org.junit.Test)

Example 34 with StorageUnitEntity

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

the class CleanupDestroyedBusinessObjectDataServiceImpl method getS3StorageUnitsToCleanupImpl.

/**
 * Retrieves a list of keys for destroyed S3 storage units that are ready for cleanup.
 *
 * @param maxResult the maximum number of results to retrieve
 *
 * @return the list of storage unit keys
 */
List<BusinessObjectDataStorageUnitKey> getS3StorageUnitsToCleanupImpl(int maxResult) {
    // Retrieves a list of storage units that belong to S3 storage, and has a final destroy on timestamp < current time, has a DELETED status,
    // and associated BData has a DELETED status.
    List<StorageUnitEntity> storageUnitEntities = storageUnitDao.getS3StorageUnitsToCleanup(maxResult);
    // Build a list of storage unit keys.
    List<BusinessObjectDataStorageUnitKey> storageUnitKeys = new ArrayList<>();
    for (StorageUnitEntity storageUnitEntity : storageUnitEntities) {
        storageUnitKeys.add(storageUnitHelper.createStorageUnitKeyFromEntity(storageUnitEntity));
    }
    return storageUnitKeys;
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) ArrayList(java.util.ArrayList)

Example 35 with StorageUnitEntity

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

the class StoragePolicyProcessorHelperServiceImpl method updateStoragePolicyTransitionFailedAttemptsIgnoreExceptionImpl.

/**
 * Increments the count for failed storage policy transition attempts for the specified storage unit. This method does not fail in case storage unit entity
 * update is unsuccessful, but simply logs the exception information as a warning.
 *
 * @param storagePolicyTransitionParamsDto the storage policy transition DTO that contains parameters needed to complete a storage policy transition. The
 * business object data key and storage name identify the storage unit to be updated
 */
protected void updateStoragePolicyTransitionFailedAttemptsIgnoreExceptionImpl(StoragePolicyTransitionParamsDto storagePolicyTransitionParamsDto) {
    // Log the DTO contents.
    LOGGER.info("storagePolicyTransitionParamsDto={}", jsonHelper.objectToJson(storagePolicyTransitionParamsDto));
    // Continue only when business object data kay and storage name are specified.
    if (storagePolicyTransitionParamsDto.getBusinessObjectDataKey() != null && storagePolicyTransitionParamsDto.getStorageName() != null) {
        try {
            // Create a storage unit key.
            BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey = storageUnitHelper.createBusinessObjectDataStorageUnitKey(storagePolicyTransitionParamsDto.getBusinessObjectDataKey(), storagePolicyTransitionParamsDto.getStorageName());
            // Retrieve the storage unit entity and make sure it exists.
            StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntityByKey(businessObjectDataStorageUnitKey);
            // Update the storage policy transition failed attempts count.
            storageUnitEntity.setStoragePolicyTransitionFailedAttempts(storageUnitEntity.getStoragePolicyTransitionFailedAttempts() == null ? 1 : storageUnitEntity.getStoragePolicyTransitionFailedAttempts() + 1);
            storageUnitDao.saveAndRefresh(storageUnitEntity);
            // Log the new value for the storage policy transition failed attempts counter.
            LOGGER.info("Incremented storage policy transition failed attempts counter. " + "storagePolicyTransitionFailedAttempts={} businessObjectDataStorageUnitKey={}", storageUnitEntity.getStoragePolicyTransitionFailedAttempts(), jsonHelper.objectToJson(businessObjectDataStorageUnitKey));
        } catch (Exception e) {
            LOGGER.warn(e.getMessage(), e);
        }
    }
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity)

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