Search in sources :

Example 41 with StoragePolicyKey

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

the class StoragePolicyProcessorHelperServiceTest method testInitiateStoragePolicyTransitionStoragePolicyFilterStorageBucketNameNotConfigured.

@Test
public void testInitiateStoragePolicyTransitionStoragePolicyFilterStorageBucketNameNotConfigured() {
    // 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 and persist a business object data entity.
    businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(businessObjectDataKey, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.VALID);
    // Create a storage policy key.
    StoragePolicyKey storagePolicyKey = new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME);
    // Create and persist an S3 storage entity without S3 bucket name configured.
    List<Attribute> attributes = new ArrayList<>();
    attributes.add(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX), Boolean.TRUE.toString()));
    attributes.add(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_FILE_EXISTENCE), Boolean.TRUE.toString()));
    storageDaoTestHelper.createStorageEntity(STORAGE_NAME, StoragePlatformEntity.S3, attributes);
    // Create and persist a storage policy entity with storage policy filter storage has no S3 bucket name attribute configured.
    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);
    // Try to initiate a storage policy transition when storage policy filter storage has no S3 bucket name attribute configured.
    try {
        storagePolicyProcessorHelperService.initiateStoragePolicyTransition(new StoragePolicyTransitionParamsDto(), new StoragePolicySelection(businessObjectDataKey, storagePolicyKey, INITIAL_VERSION));
        fail("Should throw an IllegalStateException when storage policy filter storage has no S3 bucket name attribute configured.");
    } catch (IllegalStateException e) {
        assertEquals(String.format("Attribute \"%s\" for \"%s\" storage must be configured.", configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), STORAGE_NAME), e.getMessage());
    }
}
Also used : Attribute(org.finra.herd.model.api.xml.Attribute) StoragePolicyKey(org.finra.herd.model.api.xml.StoragePolicyKey) ArrayList(java.util.ArrayList) StoragePolicyTransitionParamsDto(org.finra.herd.model.dto.StoragePolicyTransitionParamsDto) StoragePolicySelection(org.finra.herd.model.dto.StoragePolicySelection) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Test(org.junit.Test)

Example 42 with StoragePolicyKey

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

the class BusinessObjectDataDaoTest method testBusinessObjectDataEntitiesMatchingStoragePoliciesNoStoragePolicyLatestVersion.

@Test
public void testBusinessObjectDataEntitiesMatchingStoragePoliciesNoStoragePolicyLatestVersion() {
    // Create and persist an enabled storage policy entity that has no latest version flag set.
    storagePolicyDaoTestHelper.createStoragePolicyEntity(new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME), StoragePolicyRuleTypeEntity.DAYS_SINCE_BDATA_REGISTERED, BDATA_AGE_IN_DAYS, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, STORAGE_NAME, StoragePolicyTransitionTypeEntity.GLACIER, StoragePolicyStatusEntity.ENABLED, INITIAL_VERSION, NO_LATEST_VERSION_FLAG_SET);
    // Create and persist a storage unit with ENABLED status in the storage policy filter storage.
    storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BDATA_STATUS, StorageUnitStatusEntity.ENABLED, NO_STORAGE_DIRECTORY_PATH);
    // Try to retrieve the business object data matching to the storage policy.
    Map<BusinessObjectDataEntity, StoragePolicyEntity> result = businessObjectDataDao.getBusinessObjectDataEntitiesMatchingStoragePolicies(new StoragePolicyPriorityLevel(false, false, false), Collections.singletonList(BDATA_STATUS), 0, 0, MAX_RESULT);
    // Validate the results.
    assertEquals(0, result.size());
}
Also used : StoragePolicyKey(org.finra.herd.model.api.xml.StoragePolicyKey) StoragePolicyEntity(org.finra.herd.model.jpa.StoragePolicyEntity) StoragePolicyPriorityLevel(org.finra.herd.model.dto.StoragePolicyPriorityLevel) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) Test(org.junit.Test)

Example 43 with StoragePolicyKey

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

the class BusinessObjectDataDaoTest method testBusinessObjectDataEntitiesMatchingStoragePoliciesTestingStartPositionAndMaxResult.

@Test
public void testBusinessObjectDataEntitiesMatchingStoragePoliciesTestingStartPositionAndMaxResult() {
    // Create and persist a storage policy entity.
    StoragePolicyEntity storagePolicyEntity = storagePolicyDaoTestHelper.createStoragePolicyEntity(new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME), StoragePolicyRuleTypeEntity.DAYS_SINCE_BDATA_REGISTERED, BDATA_AGE_IN_DAYS, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, STORAGE_NAME, StoragePolicyTransitionTypeEntity.GLACIER, StoragePolicyStatusEntity.ENABLED, INITIAL_VERSION, LATEST_VERSION_FLAG_SET);
    // Create and persist a storage unit with ENABLED status in the storage policy filter storage.
    StorageUnitEntity storageUnitEntity1 = storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BDATA_STATUS, StorageUnitStatusEntity.ENABLED, NO_STORAGE_DIRECTORY_PATH);
    // Apply the offset in days to business object data "created on" value.
    businessObjectDataDaoTestHelper.ageBusinessObjectData(storageUnitEntity1.getBusinessObjectData(), BDATA_AGE_IN_DAYS + 1);
    // Create and persist a second storage unit with ENABLED status in the storage policy filter storage.
    StorageUnitEntity storageUnitEntity2 = storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE_2, SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BDATA_STATUS, StorageUnitStatusEntity.ENABLED, NO_STORAGE_DIRECTORY_PATH);
    // Also apply an offset to business object data "created on" value, but make this business object data older than the first.
    businessObjectDataDaoTestHelper.ageBusinessObjectData(storageUnitEntity2.getBusinessObjectData(), BDATA_AGE_IN_DAYS + 2);
    // Try to retrieve both business object data instances as matching to the storage policy, but with max result limit set to 1.
    Map<BusinessObjectDataEntity, StoragePolicyEntity> result = businessObjectDataDao.getBusinessObjectDataEntitiesMatchingStoragePolicies(new StoragePolicyPriorityLevel(false, false, false), Collections.singletonList(BDATA_STATUS), 0, 0, 1);
    // Validate the results. Only the oldest business object data should get selected.
    assertEquals(1, result.size());
    assertTrue(result.containsKey(storageUnitEntity2.getBusinessObjectData()));
    assertEquals(storagePolicyEntity, result.get(storageUnitEntity2.getBusinessObjectData()));
    // Try to retrieve the second business object data instance matching to the storage policy
    // by specifying the relative start position and max result limit set.
    result = businessObjectDataDao.getBusinessObjectDataEntitiesMatchingStoragePolicies(new StoragePolicyPriorityLevel(false, false, false), Collections.singletonList(BDATA_STATUS), 0, 1, 1);
    // Validate the results. Now, the second oldest business object data should get selected.
    assertEquals(1, result.size());
    assertTrue(result.containsKey(storageUnitEntity1.getBusinessObjectData()));
    assertEquals(storagePolicyEntity, result.get(storageUnitEntity1.getBusinessObjectData()));
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) StoragePolicyKey(org.finra.herd.model.api.xml.StoragePolicyKey) StoragePolicyEntity(org.finra.herd.model.jpa.StoragePolicyEntity) StoragePolicyPriorityLevel(org.finra.herd.model.dto.StoragePolicyPriorityLevel) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) Test(org.junit.Test)

Example 44 with StoragePolicyKey

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

the class BusinessObjectDataDaoTest method testBusinessObjectDataEntitiesMatchingStoragePoliciesWithStoragePolicyTransitionMaxAllowedAttempts.

@Test
public void testBusinessObjectDataEntitiesMatchingStoragePoliciesWithStoragePolicyTransitionMaxAllowedAttempts() {
    // Create and persist a storage policy entity.
    storagePolicyDaoTestHelper.createStoragePolicyEntity(new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME), StoragePolicyRuleTypeEntity.DAYS_SINCE_BDATA_REGISTERED, BDATA_AGE_IN_DAYS, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, STORAGE_NAME, StoragePolicyTransitionTypeEntity.GLACIER, StoragePolicyStatusEntity.ENABLED, INITIAL_VERSION, LATEST_VERSION_FLAG_SET);
    // Create and persist a storage unit in the storage policy filter storage.
    StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BDATA_STATUS, StorageUnitStatusEntity.ENABLED, NO_STORAGE_DIRECTORY_PATH);
    // Retrieve the business object data matching to the storage policy, when storagePolicyTransitionMaxAllowedAttempts is not specified.
    Map<BusinessObjectDataEntity, StoragePolicyEntity> result = businessObjectDataDao.getBusinessObjectDataEntitiesMatchingStoragePolicies(new StoragePolicyPriorityLevel(false, false, false), Collections.singletonList(BDATA_STATUS), 0, 0, MAX_RESULT);
    // Validate the results. A single match should get returned.
    assertEquals(1, result.size());
    assertTrue(result.containsKey(storageUnitEntity.getBusinessObjectData()));
    // Retrieve the business object data matching to the storage policy, when storagePolicyTransitionMaxAllowedAttempts is specified,
    // storage unit has storagePolicyTransitionFailedAttempts set to NULL.
    storageUnitEntity.setStoragePolicyTransitionFailedAttempts(null);
    storageUnitDao.saveAndRefresh(storageUnitEntity);
    result = businessObjectDataDao.getBusinessObjectDataEntitiesMatchingStoragePolicies(new StoragePolicyPriorityLevel(false, false, false), Collections.singletonList(BDATA_STATUS), 1, 0, MAX_RESULT);
    // Validate the results. A single match should get returned.
    assertEquals(1, result.size());
    assertTrue(result.containsKey(storageUnitEntity.getBusinessObjectData()));
    // Retrieve the business object data matching to the storage policy, when storagePolicyTransitionMaxAllowedAttempts is specified,
    // storage unit has storagePolicyTransitionFailedAttempts < storagePolicyTransitionMaxAllowedAttempts.
    storageUnitEntity.setStoragePolicyTransitionFailedAttempts(0);
    storageUnitDao.saveAndRefresh(storageUnitEntity);
    result = businessObjectDataDao.getBusinessObjectDataEntitiesMatchingStoragePolicies(new StoragePolicyPriorityLevel(false, false, false), Collections.singletonList(BDATA_STATUS), 1, 0, MAX_RESULT);
    // Validate the results. A single match should get returned.
    assertEquals(1, result.size());
    assertTrue(result.containsKey(storageUnitEntity.getBusinessObjectData()));
    // Try to retrieve the business object data matching to the storage policy, when storagePolicyTransitionMaxAllowedAttempts is specified,
    // storage unit has storagePolicyTransitionFailedAttempts == storagePolicyTransitionMaxAllowedAttempts.
    storageUnitEntity.setStoragePolicyTransitionFailedAttempts(1);
    storageUnitDao.saveAndRefresh(storageUnitEntity);
    result = businessObjectDataDao.getBusinessObjectDataEntitiesMatchingStoragePolicies(new StoragePolicyPriorityLevel(false, false, false), Collections.singletonList(BDATA_STATUS), 1, 0, MAX_RESULT);
    // Validate the results. No matches should get returned.
    assertEquals(0, result.size());
    // Try to retrieve the business object data matching to the storage policy, when storagePolicyTransitionMaxAllowedAttempts is specified,
    // storage unit has storagePolicyTransitionFailedAttempts > storagePolicyTransitionMaxAllowedAttempts.
    storageUnitEntity.setStoragePolicyTransitionFailedAttempts(2);
    storageUnitDao.saveAndRefresh(storageUnitEntity);
    result = businessObjectDataDao.getBusinessObjectDataEntitiesMatchingStoragePolicies(new StoragePolicyPriorityLevel(false, false, false), Collections.singletonList(BDATA_STATUS), 1, 0, MAX_RESULT);
    // Validate the results. No matches should get returned.
    assertEquals(0, result.size());
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) StoragePolicyKey(org.finra.herd.model.api.xml.StoragePolicyKey) StoragePolicyEntity(org.finra.herd.model.jpa.StoragePolicyEntity) StoragePolicyPriorityLevel(org.finra.herd.model.dto.StoragePolicyPriorityLevel) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) Test(org.junit.Test)

Example 45 with StoragePolicyKey

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

the class BusinessObjectDataRetryStoragePolicyTransitionHelperTest method testRetryStoragePolicyTransitionMissingOptionalParameters.

@Test
public void testRetryStoragePolicyTransitionMissingOptionalParameters() {
    // 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 a storage policy key.
    StoragePolicyKey storagePolicyKey = new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME);
    // Create database entities required for testing.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForRetryStoragePolicyTransitionTesting(businessObjectDataKey, storagePolicyKey);
    // Retry a storage policy transition.
    BusinessObjectData businessObjectData = businessObjectDataRetryStoragePolicyTransitionHelper.retryStoragePolicyTransition(businessObjectDataKey, new BusinessObjectDataRetryStoragePolicyTransitionRequest(storagePolicyKey));
    // Validate the returned object.
    businessObjectDataServiceTestHelper.validateBusinessObjectData(businessObjectDataEntity.getId(), businessObjectDataKey, LATEST_VERSION_FLAG_SET, BDATA_STATUS, businessObjectData);
}
Also used : BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) StoragePolicyKey(org.finra.herd.model.api.xml.StoragePolicyKey) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectDataRetryStoragePolicyTransitionRequest(org.finra.herd.model.api.xml.BusinessObjectDataRetryStoragePolicyTransitionRequest) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Aggregations

StoragePolicyKey (org.finra.herd.model.api.xml.StoragePolicyKey)101 Test (org.junit.Test)97 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)50 StoragePolicySelection (org.finra.herd.model.dto.StoragePolicySelection)32 StoragePolicyEntity (org.finra.herd.model.jpa.StoragePolicyEntity)24 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)24 StoragePolicyFilter (org.finra.herd.model.api.xml.StoragePolicyFilter)21 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)21 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)21 StoragePolicy (org.finra.herd.model.api.xml.StoragePolicy)20 StoragePolicyRule (org.finra.herd.model.api.xml.StoragePolicyRule)20 StoragePolicyTransition (org.finra.herd.model.api.xml.StoragePolicyTransition)20 HashMap (java.util.HashMap)18 BusinessObjectDataRetryStoragePolicyTransitionRequest (org.finra.herd.model.api.xml.BusinessObjectDataRetryStoragePolicyTransitionRequest)17 StoragePolicyTransitionParamsDto (org.finra.herd.model.dto.StoragePolicyTransitionParamsDto)17 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)10 StoragePolicyPriorityLevel (org.finra.herd.model.dto.StoragePolicyPriorityLevel)9 ArrayList (java.util.ArrayList)8 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)7 StorageFile (org.finra.herd.model.api.xml.StorageFile)7