use of org.finra.herd.model.jpa.StoragePlatformEntity in project herd by FINRAOS.
the class CleanupDestroyedBusinessObjectDataServiceImplTest method testCleanupS3StorageUnitWithIllegalArgumentException.
@Test
public void testCleanupS3StorageUnitWithIllegalArgumentException() {
// 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 a storage unit key.
BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey = new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME);
// Create mocks
BusinessObjectDataEntity businessObjectDataEntity = mock(BusinessObjectDataEntity.class);
// Create storage units
StoragePlatformEntity storagePlatformEntity = new StoragePlatformEntity();
storagePlatformEntity.setName(StoragePlatformEntity.S3);
StorageEntity storageEntity = new StorageEntity();
storageEntity.setStoragePlatform(storagePlatformEntity);
StorageUnitEntity storageUnitEntity1 = new StorageUnitEntity();
storageUnitEntity1.setStorage(storageEntity);
StorageUnitEntity storageUnitEntity2 = new StorageUnitEntity();
storageUnitEntity2.setStorage(storageEntity);
Collection<StorageUnitEntity> storageUnitEntities = Lists.newArrayList();
storageUnitEntities.add(storageUnitEntity1);
storageUnitEntities.add(storageUnitEntity2);
// Mock the external calls.
when(mockBusinessObjectDataHelper.createBusinessObjectDataKeyFromStorageUnitKey(businessObjectDataStorageUnitKey)).thenReturn(businessObjectDataKey);
when(mockBusinessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey)).thenReturn(businessObjectDataEntity);
when(businessObjectDataEntity.getStorageUnits()).thenReturn(storageUnitEntities);
when(mockBusinessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)).thenReturn(businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey));
// Call the method under test.
try {
cleanupDestroyedBusinessObjectDataService.cleanupS3StorageUnit(businessObjectDataStorageUnitKey);
} catch (IllegalArgumentException illegalArgumentException) {
assertThat(illegalArgumentException.getMessage(), is(equalTo("Business object data has multiple (2) S3 storage units. Business object data: {" + businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey) + "}")));
}
// Verify the external calls.
verify(mockBusinessObjectDataHelper).createBusinessObjectDataKeyFromStorageUnitKey(businessObjectDataStorageUnitKey);
verify(mockBusinessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey);
verify(businessObjectDataEntity).getStorageUnits();
verify(mockBusinessObjectDataHelper).businessObjectDataKeyToString(businessObjectDataKey);
verifyNoMoreInteractions(businessObjectDataEntity);
verifyNoMoreInteractionsHelper();
}
use of org.finra.herd.model.jpa.StoragePlatformEntity in project herd by FINRAOS.
the class StorageServiceImpl method createStorage.
@Override
public Storage createStorage(StorageCreateRequest storageCreateRequest) {
// Perform validation and trim.
validateAndTrimStorageCreateRequest(storageCreateRequest);
// Retrieve storage platform.
StoragePlatformEntity storagePlatformEntity = storagePlatformHelper.getStoragePlatformEntity(storageCreateRequest.getStoragePlatformName());
// See if a storage with the specified name already exists.
StorageEntity storageEntity = storageDao.getStorageByName(storageCreateRequest.getName());
if (storageEntity != null) {
throw new AlreadyExistsException(String.format("Storage with name \"%s\" already exists.", storageCreateRequest.getName()));
}
// Create a storage entity.
storageEntity = new StorageEntity();
storageEntity.setName(storageCreateRequest.getName());
storageEntity.setStoragePlatform(storagePlatformEntity);
// Create attributes if they are specified.
if (!CollectionUtils.isEmpty(storageCreateRequest.getAttributes())) {
List<StorageAttributeEntity> attributeEntities = new ArrayList<>();
storageEntity.setAttributes(attributeEntities);
for (Attribute attribute : storageCreateRequest.getAttributes()) {
StorageAttributeEntity attributeEntity = new StorageAttributeEntity();
attributeEntities.add(attributeEntity);
attributeEntity.setStorage(storageEntity);
attributeEntity.setName(attribute.getName());
attributeEntity.setValue(attribute.getValue());
}
}
// Persist the storage entity.
storageEntity = storageDao.saveAndRefresh(storageEntity);
// Return the storage information.
return createStorageFromEntity(storageEntity);
}
use of org.finra.herd.model.jpa.StoragePlatformEntity in project herd by FINRAOS.
the class StoragePlatformDaoTestHelper method createStoragePlatformEntity.
/**
* Creates and persists a new storage platform entity.
*
* @param storagePlatformCode the storage platform code
*
* @return the newly created storage platform entity
*/
public StoragePlatformEntity createStoragePlatformEntity(String storagePlatformCode) {
StoragePlatformEntity storagePlatformEntity = new StoragePlatformEntity();
storagePlatformEntity.setName(storagePlatformCode);
return storagePlatformDao.saveAndRefresh(storagePlatformEntity);
}
use of org.finra.herd.model.jpa.StoragePlatformEntity in project herd by FINRAOS.
the class AbstractHerdDao method getMaximumBusinessObjectDataVersionSubQuery.
/**
* TODO This method may be bdata specific. Consider creating new abstract class to group all bdata related DAO. Builds a sub-query to select the maximum
* business object data version.
*
* @param builder the criteria builder
* @param criteria the criteria query
* @param businessObjectDataEntity the business object data entity that appears in the from clause of the main query
* @param businessObjectFormatEntity the business object format entity that appears in the from clause of the main query
* @param businessObjectDataStatus the business object data status
* @param storageNames the list of storage names where the business object data storage units should be looked for (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 selectOnlyAvailableStorageUnits specifies if only available storage units will be selected or any storage units regardless of their status
*
* @return the sub-query to select the maximum business object data version
*/
protected Subquery<Integer> getMaximumBusinessObjectDataVersionSubQuery(CriteriaBuilder builder, CriteriaQuery<?> criteria, From<?, BusinessObjectDataEntity> businessObjectDataEntity, From<?, BusinessObjectFormatEntity> businessObjectFormatEntity, String businessObjectDataStatus, List<String> storageNames, String storagePlatformType, String excludedStoragePlatformType, boolean selectOnlyAvailableStorageUnits) {
// Business object data version is not specified, so get the latest one in the specified storage.
Subquery<Integer> subQuery = criteria.subquery(Integer.class);
// The criteria root is the business object data.
Root<BusinessObjectDataEntity> subBusinessObjectDataEntity = subQuery.from(BusinessObjectDataEntity.class);
// Join to the other tables we can filter on.
Join<BusinessObjectDataEntity, StorageUnitEntity> subStorageUnitEntity = subBusinessObjectDataEntity.join(BusinessObjectDataEntity_.storageUnits);
Join<StorageUnitEntity, StorageEntity> subStorageEntity = subStorageUnitEntity.join(StorageUnitEntity_.storage);
Join<StorageEntity, StoragePlatformEntity> subStoragePlatformEntity = subStorageEntity.join(StorageEntity_.storagePlatform);
Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> subBusinessObjectFormatEntity = subBusinessObjectDataEntity.join(BusinessObjectDataEntity_.businessObjectFormat);
Join<StorageUnitEntity, StorageUnitStatusEntity> subStorageUnitStatusEntity = subStorageUnitEntity.join(StorageUnitEntity_.status);
// Add a standard restriction on business object format.
Predicate subQueryRestriction = builder.equal(subBusinessObjectFormatEntity, businessObjectFormatEntity);
// Create and add standard restrictions on primary and sub-partition values.
subQueryRestriction = builder.and(subQueryRestriction, getQueryRestrictionOnPartitionValues(builder, subBusinessObjectDataEntity, businessObjectDataEntity));
// If specified, create and add a standard restriction on business object data status.
if (businessObjectDataStatus != null) {
Join<BusinessObjectDataEntity, BusinessObjectDataStatusEntity> subBusinessObjectDataStatusEntity = subBusinessObjectDataEntity.join(BusinessObjectDataEntity_.status);
subQueryRestriction = builder.and(subQueryRestriction, builder.equal(builder.upper(subBusinessObjectDataStatusEntity.get(BusinessObjectDataStatusEntity_.code)), businessObjectDataStatus.toUpperCase()));
}
// Create and add a standard restriction on storage.
subQueryRestriction = builder.and(subQueryRestriction, getQueryRestrictionOnStorage(builder, subStorageEntity, subStoragePlatformEntity, storageNames, storagePlatformType, excludedStoragePlatformType));
// If specified, add a restriction on storage unit status availability flag.
if (selectOnlyAvailableStorageUnits) {
subQueryRestriction = builder.and(subQueryRestriction, builder.isTrue(subStorageUnitStatusEntity.get(StorageUnitStatusEntity_.available)));
}
subQuery.select(builder.max(subBusinessObjectDataEntity.get(BusinessObjectDataEntity_.version))).where(subQueryRestriction);
return subQuery;
}
use of org.finra.herd.model.jpa.StoragePlatformEntity in project herd by FINRAOS.
the class BaseJpaDaoTest method testFindUniqueByNamedPropertiesNoExist.
@Test
public void testFindUniqueByNamedPropertiesNoExist() {
Map<String, String> namedProperties = new HashMap<>();
// Search for a random entity name that doesn't exist.
namedProperties.put(NAME_PROPERTY, UUID.randomUUID().toString());
StoragePlatformEntity storagePlatformEntity = baseJpaDao.findUniqueByNamedProperties(StoragePlatformEntity.class, namedProperties);
assertNull(storagePlatformEntity);
}
Aggregations