use of org.finra.herd.model.jpa.StoragePlatformEntity in project herd by FINRAOS.
the class BusinessObjectDataDaoImpl method getBusinessObjectDataPartitionValue.
/**
* Retrieves partition value per specified parameters that includes the aggregate function.
*
* <p>
* Returns null if the business object format key does not exist.
*
* @param partitionColumnPosition the partition column position (1-based numbering)
* @param businessObjectFormatKey the business object format key (case-insensitive). If a business object format version isn't specified, the latest
* available format version for each partition value will be used.
* @param businessObjectDataVersion the business object data version. If a business object data version isn't specified, the latest data version based on
* the specified business object data status will be used for each partition value.
* @param businessObjectDataStatus the business object data status. This parameter is ignored when the business object data version is specified.
* @param storageNames the optional list of storage names (case-insensitive)
* @param storagePlatformType the optional storage platform type, e.g. S3 for Hive DDL. It is ignored when the list of storages is not empty
* @param excludedStoragePlatformType the optional storage platform type to be excluded from search. It is ignored when the list of storages is not empty or
* the storage platform type is specified
* @param aggregateFunction the aggregate function to use against partition values
* @param upperBoundPartitionValue the optional inclusive upper bound for the maximum available partition value
* @param lowerBoundPartitionValue the optional inclusive lower bound for the maximum available partition value
*
* @return the partition value
*/
private String getBusinessObjectDataPartitionValue(int partitionColumnPosition, final BusinessObjectFormatKey businessObjectFormatKey, final Integer businessObjectDataVersion, String businessObjectDataStatus, List<String> storageNames, String storagePlatformType, String excludedStoragePlatformType, final AggregateFunction aggregateFunction, String upperBoundPartitionValue, String lowerBoundPartitionValue) {
// We cannot use businessObjectFormatKey passed in since it is case-insensitive. Case-insensitive values requires upper() function in the SQL query, and
// it has caused performance problems. So we need to extract case-sensitive business object format key from database so we can eliminate the upper()
// function.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKey);
BusinessObjectFormatKey businessObjectFormatKeyCaseSensitive = (BusinessObjectFormatKey) businessObjectFormatKey.clone();
if (businessObjectFormatEntity == null) {
// Returns null if business object format key does not exist.
return null;
} else {
// Sets the exact values for business object format key from the database. Note that usage type is still case-insensitive.
businessObjectFormatKeyCaseSensitive.setNamespace(businessObjectFormatEntity.getBusinessObjectDefinition().getNamespace().getCode());
businessObjectFormatKeyCaseSensitive.setBusinessObjectDefinitionName(businessObjectFormatEntity.getBusinessObjectDefinition().getName());
businessObjectFormatKeyCaseSensitive.setBusinessObjectFormatFileType(businessObjectFormatEntity.getFileType().getCode());
}
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<String> criteria = builder.createQuery(String.class);
// The criteria root is the business object data.
Root<BusinessObjectDataEntity> businessObjectDataEntityRoot = criteria.from(BusinessObjectDataEntity.class);
// Join to the other tables we can filter on.
Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> businessObjectFormatEntityJoin = businessObjectDataEntityRoot.join(BusinessObjectDataEntity_.businessObjectFormat);
Join<BusinessObjectFormatEntity, FileTypeEntity> fileTypeEntityJoin = businessObjectFormatEntityJoin.join(BusinessObjectFormatEntity_.fileType);
Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntityJoin = businessObjectFormatEntityJoin.join(BusinessObjectFormatEntity_.businessObjectDefinition);
Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntityJoin = businessObjectDefinitionEntityJoin.join(BusinessObjectDefinitionEntity_.namespace);
Join<BusinessObjectDataEntity, StorageUnitEntity> storageUnitEntityJoin = businessObjectDataEntityRoot.join(BusinessObjectDataEntity_.storageUnits);
Join<StorageUnitEntity, StorageUnitStatusEntity> storageUnitStatusEntityJoin = storageUnitEntityJoin.join(StorageUnitEntity_.status);
Join<StorageUnitEntity, StorageEntity> storageEntityJoin = storageUnitEntityJoin.join(StorageUnitEntity_.storage);
Join<StorageEntity, StoragePlatformEntity> storagePlatformEntityJoin = storageEntityJoin.join(StorageEntity_.storagePlatform);
// Create the path.
Expression<String> partitionValue;
SingularAttribute<BusinessObjectDataEntity, String> singleValuedAttribute = BUSINESS_OBJECT_DATA_PARTITIONS.get(partitionColumnPosition - 1);
switch(aggregateFunction) {
case GREATEST:
partitionValue = builder.greatest(businessObjectDataEntityRoot.get(singleValuedAttribute));
break;
case LEAST:
partitionValue = builder.least(businessObjectDataEntityRoot.get(singleValuedAttribute));
break;
default:
throw new IllegalArgumentException("Invalid aggregate function found: \"" + aggregateFunction + "\".");
}
// Create the standard restrictions (i.e. the standard where clauses).
Predicate mainQueryRestriction = builder.equal(namespaceEntityJoin.get(NamespaceEntity_.code), businessObjectFormatKeyCaseSensitive.getNamespace());
mainQueryRestriction = builder.and(mainQueryRestriction, builder.equal(businessObjectDefinitionEntityJoin.get(BusinessObjectDefinitionEntity_.name), businessObjectFormatKeyCaseSensitive.getBusinessObjectDefinitionName()));
mainQueryRestriction = builder.and(mainQueryRestriction, builder.equal(builder.upper(businessObjectFormatEntityJoin.get(BusinessObjectFormatEntity_.usage)), businessObjectFormatKeyCaseSensitive.getBusinessObjectFormatUsage().toUpperCase()));
mainQueryRestriction = builder.and(mainQueryRestriction, builder.equal(fileTypeEntityJoin.get(FileTypeEntity_.code), businessObjectFormatKeyCaseSensitive.getBusinessObjectFormatFileType()));
// If a business object format version was specified, use it.
if (businessObjectFormatKey.getBusinessObjectFormatVersion() != null) {
mainQueryRestriction = builder.and(mainQueryRestriction, builder.equal(businessObjectFormatEntityJoin.get(BusinessObjectFormatEntity_.businessObjectFormatVersion), businessObjectFormatKey.getBusinessObjectFormatVersion()));
}
// If a data version was specified, use it.
if (businessObjectDataVersion != null) {
mainQueryRestriction = builder.and(mainQueryRestriction, builder.equal(businessObjectDataEntityRoot.get(BusinessObjectDataEntity_.version), businessObjectDataVersion));
} else // Business object data version is not specified, so get the latest one as per specified business object data status in the specified storage.
{
Subquery<Integer> subQuery = getMaximumBusinessObjectDataVersionSubQuery(builder, criteria, businessObjectDataEntityRoot, businessObjectFormatEntityJoin, businessObjectDataStatus, storageNames, storagePlatformType, excludedStoragePlatformType, false);
mainQueryRestriction = builder.and(mainQueryRestriction, builder.in(businessObjectDataEntityRoot.get(BusinessObjectDataEntity_.version)).value(subQuery));
}
// Add an inclusive upper bound partition value restriction if specified.
if (upperBoundPartitionValue != null) {
mainQueryRestriction = builder.and(mainQueryRestriction, builder.lessThanOrEqualTo(businessObjectDataEntityRoot.get(singleValuedAttribute), upperBoundPartitionValue));
}
// Add an inclusive lower bound partition value restriction if specified.
if (lowerBoundPartitionValue != null) {
mainQueryRestriction = builder.and(mainQueryRestriction, builder.greaterThanOrEqualTo(businessObjectDataEntityRoot.get(singleValuedAttribute), lowerBoundPartitionValue));
}
// If specified, add restriction on storage.
mainQueryRestriction = builder.and(mainQueryRestriction, getQueryRestrictionOnStorage(builder, storageEntityJoin, storagePlatformEntityJoin, storageNames, storagePlatformType, excludedStoragePlatformType));
// Search across only "available" storage units.
mainQueryRestriction = builder.and(mainQueryRestriction, builder.isTrue(storageUnitStatusEntityJoin.get(StorageUnitStatusEntity_.available)));
criteria.select(partitionValue).where(mainQueryRestriction);
return entityManager.createQuery(criteria).getSingleResult();
}
use of org.finra.herd.model.jpa.StoragePlatformEntity in project herd by FINRAOS.
the class GetBusinessObjectDataTest method setupDatabase.
/**
* Inserts a business object data and their FK relationships into the database.
*
* @param dataProviderName the data provider name.
* @param businessObjectDefinitionName the business object definition name.
* @param fileTypeCode the file type code.
* @param businessObjectFormatUsage the business object format usage.
* @param businessObjectFormatVersion the business object format version.
* @param businessObjectDataVersion the business object data version.
* @param partitionKey the partition key.
* @param partitionValues the partition values.
*/
private void setupDatabase(String namespace, String dataProviderName, String businessObjectDefinitionName, String fileTypeCode, String businessObjectFormatUsage, Integer businessObjectFormatVersion, Integer businessObjectDataVersion, String partitionKey, String[] partitionValues) {
DataProviderEntity dataProviderEntity = new DataProviderEntity();
dataProviderEntity.setName(dataProviderName);
herdDao.saveAndRefresh(dataProviderEntity);
NamespaceEntity namespaceEntity = new NamespaceEntity();
namespaceEntity.setCode(namespace);
herdDao.saveAndRefresh(namespaceEntity);
BusinessObjectDefinitionEntity businessObjectDefinition = new BusinessObjectDefinitionEntity();
businessObjectDefinition.setDataProvider(dataProviderEntity);
businessObjectDefinition.setName(businessObjectDefinitionName);
businessObjectDefinition.setNamespace(namespaceEntity);
herdDao.saveAndRefresh(businessObjectDefinition);
FileTypeEntity fileTypeEntity = new FileTypeEntity();
fileTypeEntity.setCode(fileTypeCode);
herdDao.saveAndRefresh(fileTypeEntity);
BusinessObjectFormatEntity businessObjectFormatEntity = new BusinessObjectFormatEntity();
businessObjectFormatEntity.setBusinessObjectDefinition(businessObjectDefinition);
businessObjectFormatEntity.setBusinessObjectFormatVersion(businessObjectFormatVersion);
businessObjectFormatEntity.setFileType(fileTypeEntity);
businessObjectFormatEntity.setLatestVersion(true);
businessObjectFormatEntity.setNullValue("#");
businessObjectFormatEntity.setPartitionKey(partitionKey);
businessObjectFormatEntity.setUsage(businessObjectFormatUsage);
herdDao.saveAndRefresh(businessObjectFormatEntity);
StoragePlatformEntity storagePlatformEntity = new StoragePlatformEntity();
storagePlatformEntity.setName(randomString());
herdDao.saveAndRefresh(storagePlatformEntity);
StorageEntity storageEntity = new StorageEntity();
storageEntity.setName(randomString());
storageEntity.setStoragePlatform(storagePlatformEntity);
herdDao.saveAndRefresh(storageEntity);
BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
businessObjectDataEntity.setBusinessObjectFormat(businessObjectFormatEntity);
businessObjectDataEntity.setLatestVersion(true);
businessObjectDataEntity.setPartitionValue(partitionValues[0]);
businessObjectDataEntity.setPartitionValue2(partitionValues[1]);
businessObjectDataEntity.setPartitionValue3(partitionValues[2]);
businessObjectDataEntity.setPartitionValue4(partitionValues[3]);
businessObjectDataEntity.setPartitionValue5(partitionValues[4]);
businessObjectDataEntity.setStatus(businessObjectDataStatusDao.getBusinessObjectDataStatusByCode(BusinessObjectDataStatusEntity.VALID));
Collection<StorageUnitEntity> storageUnits = new ArrayList<>();
StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
storageUnitEntity.setStorage(storageEntity);
Collection<StorageFileEntity> storageFiles = new ArrayList<>();
StorageFileEntity storageFileEntity = new StorageFileEntity();
storageFileEntity.setPath(randomString());
storageFileEntity.setFileSizeBytes(1000l);
storageFileEntity.setStorageUnit(storageUnitEntity);
storageFiles.add(storageFileEntity);
storageUnitEntity.setStorageFiles(storageFiles);
storageUnitEntity.setBusinessObjectData(businessObjectDataEntity);
storageUnitEntity.setStatus(storageUnitStatusDao.getStorageUnitStatusByCode(StorageUnitStatusEntity.ENABLED));
storageUnits.add(storageUnitEntity);
businessObjectDataEntity.setStorageUnits(storageUnits);
businessObjectDataEntity.setVersion(businessObjectDataVersion);
herdDao.saveAndRefresh(businessObjectDataEntity);
}
use of org.finra.herd.model.jpa.StoragePlatformEntity in project herd by FINRAOS.
the class StoragePlatformServiceImpl method getStoragePlatforms.
/**
* Gets a list of storage platforms.
*
* @return the list of storage platforms.
*/
@Override
public StoragePlatforms getStoragePlatforms() {
List<StoragePlatformEntity> storagePlatformEntities = storagePlatformDao.findAll(StoragePlatformEntity.class);
StoragePlatforms storagePlatforms = new StoragePlatforms();
for (StoragePlatformEntity storagePlatformEntity : storagePlatformEntities) {
storagePlatforms.getStoragePlatforms().add(createStoragePlatformFromEntity(storagePlatformEntity));
}
return storagePlatforms;
}
use of org.finra.herd.model.jpa.StoragePlatformEntity in project herd by FINRAOS.
the class StoragePolicyProcessorHelperServiceImplTest method testInitiateStoragePolicyTransitionImpl.
@Test
public void testInitiateStoragePolicyTransitionImpl() {
// Create an empty storage policy transition parameters DTO.
StoragePolicyTransitionParamsDto storagePolicyTransitionParamsDto = new StoragePolicyTransitionParamsDto();
// 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 business object format entity.
BusinessObjectFormatEntity businessObjectFormatEntity = new BusinessObjectFormatEntity();
// Create a business object data status entity.
BusinessObjectDataStatusEntity businessObjectDataStatusEntity = new BusinessObjectDataStatusEntity();
businessObjectDataStatusEntity.setCode(BusinessObjectDataStatusEntity.VALID);
// Create a business object data entity.
BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
businessObjectDataEntity.setBusinessObjectFormat(businessObjectFormatEntity);
businessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
// Create a storage policy key.
StoragePolicyKey storagePolicyKey = new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME);
// Create a storage platform entity.
StoragePlatformEntity storagePlatformEntity = new StoragePlatformEntity();
storagePlatformEntity.setName(StoragePlatformEntity.S3);
// Create a storage entity.
StorageEntity storageEntity = new StorageEntity();
storageEntity.setStoragePlatform(storagePlatformEntity);
storageEntity.setName(STORAGE_NAME);
// Create a storage policy entity.
StoragePolicyTransitionTypeEntity storagePolicyTransitionTypeEntity = new StoragePolicyTransitionTypeEntity();
storagePolicyTransitionTypeEntity.setCode(StoragePolicyTransitionTypeEntity.GLACIER);
// Create a storage policy entity.
StoragePolicyEntity storagePolicyEntity = new StoragePolicyEntity();
storagePolicyEntity.setStorage(storageEntity);
storagePolicyEntity.setStoragePolicyTransitionType(storagePolicyTransitionTypeEntity);
// Create a list of storage file entities.
List<StorageFileEntity> storageFileEntities = Arrays.asList(new StorageFileEntity());
// Create a storage unit status entity.
StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity();
storageUnitStatusEntity.setCode(StorageUnitStatusEntity.ENABLED);
// Create a storage unit entity.
StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
storageUnitEntity.setStorage(storageEntity);
storageUnitEntity.setBusinessObjectData(businessObjectDataEntity);
storageUnitEntity.setStorageFiles(storageFileEntities);
storageUnitEntity.setStatus(storageUnitStatusEntity);
// Create a list of storage files.
List<StorageFile> storageFiles = Arrays.asList(new StorageFile(S3_KEY, FILE_SIZE_1_KB, ROW_COUNT_1000));
// Mock the external calls.
when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey)).thenReturn(businessObjectDataEntity);
when(storagePolicyDaoHelper.getStoragePolicyEntityByKeyAndVersion(storagePolicyKey, STORAGE_POLICY_VERSION)).thenReturn(storagePolicyEntity);
when(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX)).thenReturn(S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX);
when(storageHelper.getBooleanStorageAttributeValueByName(S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX, storageEntity, false, true)).thenReturn(true);
when(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_FILE_EXISTENCE)).thenReturn(S3_ATTRIBUTE_NAME_VALIDATE_FILE_EXISTENCE);
when(storageHelper.getBooleanStorageAttributeValueByName(S3_ATTRIBUTE_NAME_VALIDATE_FILE_EXISTENCE, storageEntity, false, true)).thenReturn(true);
when(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME)).thenReturn(S3_ATTRIBUTE_NAME_BUCKET_NAME);
when(storageHelper.getStorageAttributeValueByName(S3_ATTRIBUTE_NAME_BUCKET_NAME, storageEntity, true)).thenReturn(S3_BUCKET_NAME);
when(configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_TAG_KEY)).thenReturn(S3_OBJECT_TAG_KEY);
when(configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_TAG_VALUE)).thenReturn(S3_OBJECT_TAG_VALUE);
when(configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_ROLE_ARN)).thenReturn(S3_OBJECT_TAGGER_ROLE_ARN);
when(configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_ROLE_SESSION_NAME)).thenReturn(S3_OBJECT_TAGGER_ROLE_SESSION_NAME);
when(storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity)).thenReturn(storageUnitEntity);
when(s3KeyPrefixHelper.buildS3KeyPrefix(storageEntity, businessObjectFormatEntity, businessObjectDataKey)).thenReturn(S3_KEY_PREFIX);
when(storageFileHelper.getAndValidateStorageFiles(storageUnitEntity, S3_KEY_PREFIX, STORAGE_NAME, businessObjectDataKey)).thenReturn(storageFiles);
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) {
// Get the new storage unit status.
String storageUnitStatus = (String) invocation.getArguments()[1];
// Create a storage unit status entity for the new storage unit status.
StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity();
storageUnitStatusEntity.setCode(storageUnitStatus);
// Update the storage unit with the new status.
StorageUnitEntity storageUnitEntity = (StorageUnitEntity) invocation.getArguments()[0];
storageUnitEntity.setStatus(storageUnitStatusEntity);
return null;
}
}).when(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.ARCHIVING, StorageUnitStatusEntity.ARCHIVING);
when(configurationHelper.getProperty(ConfigurationValue.S3_ENDPOINT)).thenReturn(S3_ENDPOINT);
// Call the method under test.
storagePolicyProcessorHelperServiceImpl.initiateStoragePolicyTransitionImpl(storagePolicyTransitionParamsDto, new StoragePolicySelection(businessObjectDataKey, storagePolicyKey, STORAGE_POLICY_VERSION));
// Verify the external calls.
verify(businessObjectDataHelper).validateBusinessObjectDataKey(businessObjectDataKey, true, true);
verify(storagePolicyHelper).validateStoragePolicyKey(storagePolicyKey);
verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey);
verify(businessObjectDataHelper, times(2)).businessObjectDataKeyToString(businessObjectDataKey);
verify(storagePolicyDaoHelper).getStoragePolicyEntityByKeyAndVersion(storagePolicyKey, STORAGE_POLICY_VERSION);
verify(storagePolicyHelper, times(2)).storagePolicyKeyAndVersionToString(storagePolicyKey, STORAGE_POLICY_VERSION);
verify(configurationHelper).getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX);
verify(storageHelper).getBooleanStorageAttributeValueByName(S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX, storageEntity, false, true);
verify(configurationHelper).getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_FILE_EXISTENCE);
verify(storageHelper).getBooleanStorageAttributeValueByName(S3_ATTRIBUTE_NAME_VALIDATE_FILE_EXISTENCE, storageEntity, false, true);
verify(configurationHelper).getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME);
verify(storageHelper).getStorageAttributeValueByName(S3_ATTRIBUTE_NAME_BUCKET_NAME, storageEntity, true);
verify(configurationHelper).getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_TAG_KEY);
verify(configurationHelper).getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_TAG_VALUE);
verify(configurationHelper).getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_ROLE_ARN);
verify(configurationHelper).getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_ROLE_SESSION_NAME);
verify(storageUnitDaoHelper).getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity);
verify(s3KeyPrefixHelper).buildS3KeyPrefix(storageEntity, businessObjectFormatEntity, businessObjectDataKey);
verify(storageFileHelper).getAndValidateStorageFiles(storageUnitEntity, S3_KEY_PREFIX, STORAGE_NAME, businessObjectDataKey);
verify(storageFileDaoHelper).validateStorageFilesCount(STORAGE_NAME, businessObjectDataKey, S3_KEY_PREFIX, storageFileEntities.size());
verify(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.ARCHIVING, StorageUnitStatusEntity.ARCHIVING);
verify(configurationHelper).getProperty(ConfigurationValue.S3_ENDPOINT);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(new StoragePolicyTransitionParamsDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, S3_KEY_PREFIX, StorageUnitStatusEntity.ARCHIVING, StorageUnitStatusEntity.ENABLED, storageFiles, S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE, S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME), storagePolicyTransitionParamsDto);
}
use of org.finra.herd.model.jpa.StoragePlatformEntity in project herd by FINRAOS.
the class BusinessObjectDataInitiateDestroyHelperServiceImplTest method testPrepareToInitiateDestroy.
@Test
public void testPrepareToInitiateDestroy() {
// Create an empty business object data destroy parameters DTO.
BusinessObjectDataDestroyDto businessObjectDataDestroyDto = new BusinessObjectDataDestroyDto();
// Create a version-less business object format key.
BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, NO_FORMAT_VERSION);
// 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 retention type entity.
RetentionTypeEntity retentionTypeEntity = new RetentionTypeEntity();
retentionTypeEntity.setCode(RetentionTypeEntity.PARTITION_VALUE);
// Create a business object format entity.
BusinessObjectFormatEntity businessObjectFormatEntity = new BusinessObjectFormatEntity();
businessObjectFormatEntity.setLatestVersion(true);
businessObjectFormatEntity.setRetentionType(retentionTypeEntity);
businessObjectFormatEntity.setRetentionPeriodInDays(RETENTION_PERIOD_DAYS);
// Create a business object data status entity.
BusinessObjectDataStatusEntity businessObjectDataStatusEntity = new BusinessObjectDataStatusEntity();
businessObjectDataStatusEntity.setCode(BusinessObjectDataStatusEntity.VALID);
// Create a business object data entity.
BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
businessObjectDataEntity.setBusinessObjectFormat(businessObjectFormatEntity);
businessObjectDataEntity.setPartitionValue(PARTITION_VALUE);
businessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
// Create a storage platform entity.
StoragePlatformEntity storagePlatformEntity = new StoragePlatformEntity();
storagePlatformEntity.setName(StoragePlatformEntity.S3);
// Create a storage entity.
StorageEntity storageEntity = new StorageEntity();
storageEntity.setStoragePlatform(storagePlatformEntity);
storageEntity.setName(STORAGE_NAME);
// Create a list of storage file entities.
List<StorageFileEntity> storageFileEntities = Arrays.asList(new StorageFileEntity());
// Create a storage unit status entity.
StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity();
storageUnitStatusEntity.setCode(StorageUnitStatusEntity.ENABLED);
// Create a storage unit entity.
StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
storageUnitEntity.setStorage(storageEntity);
storageUnitEntity.setBusinessObjectData(businessObjectDataEntity);
storageUnitEntity.setStorageFiles(storageFileEntities);
storageUnitEntity.setStatus(storageUnitStatusEntity);
// Create a list of storage files.
List<StorageFile> storageFiles = Arrays.asList(new StorageFile(S3_KEY, FILE_SIZE_1_KB, ROW_COUNT_1000));
// Create a current timestamp.
Timestamp currentTimestamp = new Timestamp(new Date().getTime());
// Create a date representing the primary partition value that satisfies the retention threshold check.
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, -(RETENTION_PERIOD_DAYS + 1));
Date primaryPartitionValueDate = calendar.getTime();
// Mock the external calls.
when(configurationHelper.getRequiredProperty(ConfigurationValue.S3_OBJECT_DELETE_TAG_KEY)).thenReturn(S3_OBJECT_TAG_KEY);
when(configurationHelper.getRequiredProperty(ConfigurationValue.S3_OBJECT_DELETE_TAG_VALUE)).thenReturn(S3_OBJECT_TAG_VALUE);
when(configurationHelper.getRequiredProperty(ConfigurationValue.S3_OBJECT_DELETE_ROLE_ARN)).thenReturn(S3_OBJECT_TAGGER_ROLE_ARN);
when(configurationHelper.getRequiredProperty(ConfigurationValue.S3_OBJECT_DELETE_ROLE_SESSION_NAME)).thenReturn(S3_OBJECT_TAGGER_ROLE_SESSION_NAME);
when(herdStringHelper.getConfigurationValueAsInteger(ConfigurationValue.BDATA_FINAL_DESTROY_DELAY_IN_DAYS)).thenReturn(BDATA_FINAL_DESTROY_DELAY_IN_DAYS);
when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey)).thenReturn(businessObjectDataEntity);
when(businessObjectDataHelper.getDateFromString(PARTITION_VALUE)).thenReturn(primaryPartitionValueDate);
when(herdDao.getCurrentTimestamp()).thenReturn(currentTimestamp);
when(storageUnitDao.getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity)).thenReturn(Arrays.asList(storageUnitEntity));
when(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX)).thenReturn(S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX);
when(storageHelper.getBooleanStorageAttributeValueByName(S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX, storageEntity, false, true)).thenReturn(true);
when(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME)).thenReturn(S3_ATTRIBUTE_NAME_BUCKET_NAME);
when(storageHelper.getStorageAttributeValueByName(S3_ATTRIBUTE_NAME_BUCKET_NAME, storageEntity, true)).thenReturn(S3_BUCKET_NAME);
when(s3KeyPrefixHelper.buildS3KeyPrefix(storageEntity, businessObjectFormatEntity, businessObjectDataKey)).thenReturn(TEST_S3_KEY_PREFIX);
when(storageFileHelper.getAndValidateStorageFilesIfPresent(storageUnitEntity, TEST_S3_KEY_PREFIX, STORAGE_NAME, businessObjectDataKey)).thenReturn(storageFiles);
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) {
// Get the new storage unit status.
String storageUnitStatus = (String) invocation.getArguments()[1];
// Create a storage unit status entity for the new storage unit status.
StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity();
storageUnitStatusEntity.setCode(storageUnitStatus);
// Update the storage unit with the new status.
StorageUnitEntity storageUnitEntity = (StorageUnitEntity) invocation.getArguments()[0];
storageUnitEntity.setStatus(storageUnitStatusEntity);
return null;
}
}).when(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.DISABLING, StorageUnitStatusEntity.DISABLING);
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) {
// Get the new storage unit status.
String businessObjectDataStatus = (String) invocation.getArguments()[1];
// Create a business object data status entity for the new business object data status.
BusinessObjectDataStatusEntity businessObjectDataStatusEntity = new BusinessObjectDataStatusEntity();
businessObjectDataStatusEntity.setCode(businessObjectDataStatus);
// Update the business object data entity with the new status.
BusinessObjectDataEntity businessObjectDataEntity = (BusinessObjectDataEntity) invocation.getArguments()[0];
businessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
return null;
}
}).when(businessObjectDataDaoHelper).updateBusinessObjectDataStatus(businessObjectDataEntity, BusinessObjectDataStatusEntity.DELETED);
when(businessObjectDataHelper.getBusinessObjectDataKey(businessObjectDataEntity)).thenReturn(businessObjectDataKey);
when(configurationHelper.getProperty(ConfigurationValue.S3_ENDPOINT)).thenReturn(S3_ENDPOINT);
// Call the method under test.
businessObjectDataInitiateDestroyHelperServiceImpl.prepareToInitiateDestroy(businessObjectDataDestroyDto, businessObjectDataKey);
// Verify the external calls.
verify(businessObjectDataHelper).validateBusinessObjectDataKey(businessObjectDataKey, true, true);
verify(configurationHelper).getRequiredProperty(ConfigurationValue.S3_OBJECT_DELETE_TAG_KEY);
verify(configurationHelper).getRequiredProperty(ConfigurationValue.S3_OBJECT_DELETE_TAG_VALUE);
verify(configurationHelper).getRequiredProperty(ConfigurationValue.S3_OBJECT_DELETE_ROLE_ARN);
verify(configurationHelper).getRequiredProperty(ConfigurationValue.S3_OBJECT_DELETE_ROLE_SESSION_NAME);
verify(herdStringHelper).getConfigurationValueAsInteger(ConfigurationValue.BDATA_FINAL_DESTROY_DELAY_IN_DAYS);
verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey);
verify(businessObjectDataHelper).getDateFromString(PARTITION_VALUE);
verify(herdDao).getCurrentTimestamp();
verify(storageUnitDao).getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity);
verify(configurationHelper).getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX);
verify(storageHelper).getBooleanStorageAttributeValueByName(S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX, storageEntity, false, true);
verify(configurationHelper).getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME);
verify(storageHelper).getStorageAttributeValueByName(S3_ATTRIBUTE_NAME_BUCKET_NAME, storageEntity, true);
verify(s3KeyPrefixHelper).buildS3KeyPrefix(storageEntity, businessObjectFormatEntity, businessObjectDataKey);
verify(storageFileHelper).getAndValidateStorageFilesIfPresent(storageUnitEntity, TEST_S3_KEY_PREFIX, STORAGE_NAME, businessObjectDataKey);
verify(storageFileDaoHelper).validateStorageFilesCount(STORAGE_NAME, businessObjectDataKey, TEST_S3_KEY_PREFIX, storageFileEntities.size());
verify(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.DISABLING, StorageUnitStatusEntity.DISABLING);
verify(businessObjectDataDaoHelper).updateBusinessObjectDataStatus(businessObjectDataEntity, BusinessObjectDataStatusEntity.DELETED);
verify(businessObjectDataHelper).getBusinessObjectDataKey(businessObjectDataEntity);
verify(configurationHelper).getProperty(ConfigurationValue.S3_ENDPOINT);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(new BusinessObjectDataDestroyDto(businessObjectDataKey, STORAGE_NAME, BusinessObjectDataStatusEntity.DELETED, BusinessObjectDataStatusEntity.VALID, StorageUnitStatusEntity.DISABLING, StorageUnitStatusEntity.ENABLED, S3_ENDPOINT, S3_BUCKET_NAME, TEST_S3_KEY_PREFIX, S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE, S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME, BDATA_FINAL_DESTROY_DELAY_IN_DAYS), businessObjectDataDestroyDto);
}
Aggregations