Search in sources :

Example 11 with StoragePolicyEntity

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

the class StoragePolicyServiceTest method testUpdateStoragePolicy.

// Unit tests for updateStoragePolicy().
@Test
public void testUpdateStoragePolicy() {
    // Create a storage policy key.
    StoragePolicyKey storagePolicyKey = new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME);
    // Create and persist the relative database entities.
    storagePolicyServiceTestHelper.createDatabaseEntitiesForStoragePolicyTesting();
    // Create and persist a storage policy entity.
    StoragePolicyEntity storagePolicyEntity = storagePolicyDaoTestHelper.createStoragePolicyEntity(storagePolicyKey, STORAGE_POLICY_RULE_TYPE_2, STORAGE_POLICY_RULE_VALUE_2, BDEF_NAMESPACE_2, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, STORAGE_NAME_2, STORAGE_POLICY_TRANSITION_TYPE_2, StoragePolicyStatusEntity.ENABLED, INITIAL_VERSION, LATEST_VERSION_FLAG_SET);
    // Update a storage policy.
    StoragePolicy resultStoragePolicy = storagePolicyService.updateStoragePolicy(storagePolicyKey, storagePolicyServiceTestHelper.createStoragePolicyUpdateRequest(STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, STORAGE_NAME, STORAGE_POLICY_TRANSITION_TYPE, StoragePolicyStatusEntity.DISABLED));
    // Validate the returned object.
    assertEquals(new StoragePolicy(resultStoragePolicy.getId(), storagePolicyKey, new StoragePolicyRule(STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE), new StoragePolicyFilter(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, STORAGE_NAME), new StoragePolicyTransition(STORAGE_POLICY_TRANSITION_TYPE), StoragePolicyStatusEntity.DISABLED), resultStoragePolicy);
    assertTrue(resultStoragePolicy.getId() > storagePolicyEntity.getId());
}
Also used : StoragePolicyRule(org.finra.herd.model.api.xml.StoragePolicyRule) StoragePolicyTransition(org.finra.herd.model.api.xml.StoragePolicyTransition) StoragePolicyFilter(org.finra.herd.model.api.xml.StoragePolicyFilter) StoragePolicyKey(org.finra.herd.model.api.xml.StoragePolicyKey) StoragePolicyEntity(org.finra.herd.model.jpa.StoragePolicyEntity) StoragePolicy(org.finra.herd.model.api.xml.StoragePolicy) Test(org.junit.Test)

Example 12 with StoragePolicyEntity

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

the class BusinessObjectDataServiceTestHelper method createDatabaseEntitiesForRetryStoragePolicyTransitionTesting.

/**
 * Create and persist database entities required for the retry storage policy transition testing.
 *
 * @param businessObjectDataKey the business object data key
 * @param storagePolicyKey the storage policy key
 * @param storageName the storage name
 * @param s3BucketName the S3 bucket name
 * @param storageUnitStatus the storage unit status
 *
 * @return the business object data entity
 */
public BusinessObjectDataEntity createDatabaseEntitiesForRetryStoragePolicyTransitionTesting(BusinessObjectDataKey businessObjectDataKey, StoragePolicyKey storagePolicyKey, String storageName, String s3BucketName, String storageUnitStatus) {
    // Create a business object format entity with a schema.
    List<SchemaColumn> partitionColumns = schemaColumnDaoTestHelper.getTestSchemaColumns(AbstractServiceTest.RANDOM_SUFFIX);
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(businessObjectDataKey.getNamespace(), businessObjectDataKey.getBusinessObjectDefinitionName(), businessObjectDataKey.getBusinessObjectFormatUsage(), businessObjectDataKey.getBusinessObjectFormatFileType(), businessObjectDataKey.getBusinessObjectFormatVersion(), AbstractServiceTest.FORMAT_DESCRIPTION, AbstractServiceTest.LATEST_VERSION_FLAG_SET, partitionColumns.get(0).getName(), AbstractServiceTest.NO_PARTITION_KEY_GROUP, AbstractServiceTest.NO_ATTRIBUTES, AbstractServiceTest.SCHEMA_DELIMITER_PIPE, AbstractServiceTest.SCHEMA_ESCAPE_CHARACTER_BACKSLASH, AbstractServiceTest.SCHEMA_NULL_VALUE_BACKSLASH_N, schemaColumnDaoTestHelper.getTestSchemaColumns(), partitionColumns);
    // Create and persist a business object data entity.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(businessObjectFormatEntity, businessObjectDataKey.getPartitionValue(), businessObjectDataKey.getSubPartitionValues(), businessObjectDataKey.getBusinessObjectDataVersion(), AbstractServiceTest.LATEST_VERSION_FLAG_SET, AbstractServiceTest.BDATA_STATUS);
    // If specified, create and persist an S3 storage entity along with a storage unit.
    if (StringUtils.isNotBlank(storageName)) {
        StorageEntity storageEntity = storageDao.getStorageByName(storageName);
        if (storageEntity == null) {
            // Create and persist an S3 storage entity.
            List<Attribute> attributes = new ArrayList<>();
            if (StringUtils.isNotBlank(s3BucketName)) {
                attributes.add(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), s3BucketName));
            }
            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()));
            attributes.add(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), AbstractServiceTest.S3_KEY_PREFIX_VELOCITY_TEMPLATE));
            storageEntity = storageDaoTestHelper.createStorageEntity(storageName, StoragePlatformEntity.S3, attributes);
        }
        // Create and persist an S3 storage unit entity.
        if (StringUtils.isNotBlank(storageUnitStatus)) {
            StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(storageEntity, businessObjectDataEntity, storageUnitStatus, AbstractServiceTest.NO_STORAGE_DIRECTORY_PATH);
            // Get S3 key prefix for this business object data.
            String s3KeyPrefix = s3KeyPrefixHelper.buildS3KeyPrefix(storageEntity, storageUnitEntity.getBusinessObjectData().getBusinessObjectFormat(), businessObjectDataKey);
            // Create and add storage file entities to the storage unit.
            for (String relativeFilePath : AbstractServiceTest.LOCAL_FILES) {
                storageFileDaoTestHelper.createStorageFileEntity(storageUnitEntity, String.format("%s/%s", s3KeyPrefix, relativeFilePath), AbstractServiceTest.FILE_SIZE_1_KB, AbstractServiceTest.ROW_COUNT);
            }
        }
    }
    // Create and persist a storage policy if needed.
    StoragePolicyEntity storagePolicyEntity = storagePolicyDao.getStoragePolicyByAltKey(storagePolicyKey);
    if (storagePolicyEntity == null) {
        storagePolicyDaoTestHelper.createStoragePolicyEntity(storagePolicyKey, StoragePolicyRuleTypeEntity.DAYS_SINCE_BDATA_REGISTERED, AbstractServiceTest.BDATA_AGE_IN_DAYS, businessObjectDataKey.getNamespace(), businessObjectDataKey.getBusinessObjectDefinitionName(), businessObjectDataKey.getBusinessObjectFormatUsage(), businessObjectDataKey.getBusinessObjectFormatFileType(), storageName, StoragePolicyTransitionTypeEntity.GLACIER, StoragePolicyStatusEntity.ENABLED, AbstractServiceTest.INITIAL_VERSION, AbstractServiceTest.LATEST_VERSION_FLAG_SET);
    }
    // Return the business object data entity.
    return businessObjectDataEntity;
}
Also used : Attribute(org.finra.herd.model.api.xml.Attribute) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) SchemaColumn(org.finra.herd.model.api.xml.SchemaColumn) ArrayList(java.util.ArrayList) StoragePolicyEntity(org.finra.herd.model.jpa.StoragePolicyEntity) StorageEntity(org.finra.herd.model.jpa.StorageEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity)

Example 13 with StoragePolicyEntity

use of org.finra.herd.model.jpa.StoragePolicyEntity 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 14 with StoragePolicyEntity

use of org.finra.herd.model.jpa.StoragePolicyEntity 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 15 with StoragePolicyEntity

use of org.finra.herd.model.jpa.StoragePolicyEntity 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)

Aggregations

StoragePolicyEntity (org.finra.herd.model.jpa.StoragePolicyEntity)33 StoragePolicyKey (org.finra.herd.model.api.xml.StoragePolicyKey)24 Test (org.junit.Test)22 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)15 StoragePolicyFilter (org.finra.herd.model.api.xml.StoragePolicyFilter)12 StoragePolicy (org.finra.herd.model.api.xml.StoragePolicy)10 StoragePolicyRule (org.finra.herd.model.api.xml.StoragePolicyRule)10 StoragePolicyTransition (org.finra.herd.model.api.xml.StoragePolicyTransition)10 StoragePolicyPriorityLevel (org.finra.herd.model.dto.StoragePolicyPriorityLevel)9 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)9 StorageEntity (org.finra.herd.model.jpa.StorageEntity)5 StoragePolicyTransitionTypeEntity (org.finra.herd.model.jpa.StoragePolicyTransitionTypeEntity)5 ArrayList (java.util.ArrayList)4 StoragePolicySelection (org.finra.herd.model.dto.StoragePolicySelection)4 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)4 FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)4 StoragePolicyStatusEntity (org.finra.herd.model.jpa.StoragePolicyStatusEntity)4 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)3 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)3 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)3