Search in sources :

Example 1 with StoragePlatformEntity

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();
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) StoragePlatformEntity(org.finra.herd.model.jpa.StoragePlatformEntity) StorageEntity(org.finra.herd.model.jpa.StorageEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 2 with StoragePlatformEntity

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);
}
Also used : AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) Attribute(org.finra.herd.model.api.xml.Attribute) StoragePlatformEntity(org.finra.herd.model.jpa.StoragePlatformEntity) StorageAttributeEntity(org.finra.herd.model.jpa.StorageAttributeEntity) ArrayList(java.util.ArrayList) StorageEntity(org.finra.herd.model.jpa.StorageEntity)

Example 3 with StoragePlatformEntity

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);
}
Also used : StoragePlatformEntity(org.finra.herd.model.jpa.StoragePlatformEntity)

Example 4 with 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;
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) BusinessObjectDataStatusEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusEntity) StorageEntity(org.finra.herd.model.jpa.StorageEntity) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) Predicate(javax.persistence.criteria.Predicate) StoragePlatformEntity(org.finra.herd.model.jpa.StoragePlatformEntity) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity)

Example 5 with StoragePlatformEntity

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);
}
Also used : HashMap(java.util.HashMap) StoragePlatformEntity(org.finra.herd.model.jpa.StoragePlatformEntity) Test(org.junit.Test)

Aggregations

StoragePlatformEntity (org.finra.herd.model.jpa.StoragePlatformEntity)20 StorageEntity (org.finra.herd.model.jpa.StorageEntity)13 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)12 Predicate (javax.persistence.criteria.Predicate)9 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)9 StorageUnitStatusEntity (org.finra.herd.model.jpa.StorageUnitStatusEntity)9 ArrayList (java.util.ArrayList)7 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)7 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)7 Test (org.junit.Test)7 Order (javax.persistence.criteria.Order)5 BusinessObjectDataStatusEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusEntity)5 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)4 FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)4 Timestamp (java.sql.Timestamp)3 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)3 StorageFileEntity (org.finra.herd.model.jpa.StorageFileEntity)3 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)3 HashMap (java.util.HashMap)2 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)2