Search in sources :

Example 86 with BusinessObjectDataKey

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

the class BusinessObjectDataServiceImpl method getPartitionFilters.

/**
 * Gets a list of matched partition filters per specified list of storage unit entities and a sample partition filter.
 *
 * @param storageUnitEntities the list of storage unit entities
 * @param samplePartitionFilter the sample partition filter
 *
 * @return the list of partition filters
 */
private List<List<String>> getPartitionFilters(List<StorageUnitEntity> storageUnitEntities, List<String> samplePartitionFilter) {
    List<List<String>> partitionFilters = new ArrayList<>();
    for (StorageUnitEntity storageUnitEntity : storageUnitEntities) {
        BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper.getBusinessObjectDataKey(storageUnitEntity.getBusinessObjectData());
        partitionFilters.add(businessObjectDataHelper.getPartitionFilter(businessObjectDataKey, samplePartitionFilter));
    }
    return partitionFilters;
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey)

Example 87 with BusinessObjectDataKey

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

the class UploaderWebClientTest method testUpdateBusinessObjectDataStatusIgnoreException.

@Test
public void testUpdateBusinessObjectDataStatusIgnoreException() throws Exception {
    uploaderWebClient.getRegServerAccessParamsDto().setRegServerHost(MockHttpClientOperationsImpl.HOSTNAME_THROW_IO_EXCEPTION_DURING_UPDATE_BDATA_STATUS);
    BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey();
    String businessObjectDataStatus = "testBusinessObjectDataStatus";
    executeWithoutLogging(UploaderWebClient.class, () -> {
        uploaderWebClient.updateBusinessObjectDataStatusIgnoreException(businessObjectDataKey, businessObjectDataStatus);
    });
}
Also used : BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Test(org.junit.Test)

Example 88 with BusinessObjectDataKey

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

the class StorageUnitDaoTest method testGetS3StorageUnitsToCleanup.

@Test
public void testGetS3StorageUnitsToCleanup() {
    // Create a list of business object data keys.
    List<BusinessObjectDataKey> businessObjectDataKeys = new ArrayList<>();
    for (int i = 0; i < 7; i++) {
        businessObjectDataKeys.add(new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, Integer.toString(i), SUBPARTITION_VALUES, DATA_VERSION));
    }
    // Create database entities required for testing.
    List<StorageUnitEntity> storageUnitEntities = Lists.newArrayList();
    // Add 4 valid storage unit entries
    storageUnitEntities.add(storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, StoragePlatformEntity.S3, businessObjectDataKeys.get(0), LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.DELETED, StorageUnitStatusEntity.DISABLED, NO_STORAGE_DIRECTORY_PATH));
    storageUnitEntities.add(storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, StoragePlatformEntity.S3, businessObjectDataKeys.get(1), LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.DELETED, StorageUnitStatusEntity.DISABLED, NO_STORAGE_DIRECTORY_PATH));
    storageUnitEntities.add(storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, StoragePlatformEntity.S3, businessObjectDataKeys.get(2), LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.DELETED, StorageUnitStatusEntity.DISABLED, NO_STORAGE_DIRECTORY_PATH));
    storageUnitEntities.add(storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME_2, StoragePlatformEntity.S3, businessObjectDataKeys.get(3), LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.DELETED, StorageUnitStatusEntity.DISABLED, NO_STORAGE_DIRECTORY_PATH));
    // Not a valid business object data status
    storageUnitEntities.add(storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, StoragePlatformEntity.S3, businessObjectDataKeys.get(4), LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.ARCHIVED, StorageUnitStatusEntity.DISABLED, NO_STORAGE_DIRECTORY_PATH));
    // Not a valid storage unit status
    storageUnitEntities.add(storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, StoragePlatformEntity.S3, businessObjectDataKeys.get(5), LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.DELETED, StorageUnitStatusEntity.ARCHIVED, NO_STORAGE_DIRECTORY_PATH));
    // Not a valid storage platform
    storageUnitEntities.add(storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME_3, StoragePlatformEntity.TABLE_NAME, businessObjectDataKeys.get(6), LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.DELETED, StorageUnitStatusEntity.DISABLED, NO_STORAGE_DIRECTORY_PATH));
    // Set restore expiration time values.
    Timestamp currentTime = new Timestamp(System.currentTimeMillis());
    // Not a valid final destroy on date
    storageUnitEntities.get(0).setFinalDestroyOn(null);
    // Final destroy on date is not less than current timestamp
    storageUnitEntities.get(1).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, 1));
    // Valid final destroy on dates
    storageUnitEntities.get(2).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -1));
    storageUnitEntities.get(3).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -2));
    storageUnitEntities.get(4).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -2));
    storageUnitEntities.get(5).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -2));
    storageUnitEntities.get(6).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -2));
    // Retrieve the storage units and validate the results. Only two entities are expected to match all select criteria.
    List<StorageUnitEntity> result = storageUnitDao.getS3StorageUnitsToCleanup(MAX_RESULT);
    assertEquals(Arrays.asList(storageUnitEntities.get(3), storageUnitEntities.get(2)), result);
    // Try to retrieve the storage units with max result limit set to 1. Only a single storage unit entity should get selected.
    result = storageUnitDao.getS3StorageUnitsToCleanup(1);
    assertEquals(Collections.singletonList(storageUnitEntities.get(3)), result);
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) ArrayList(java.util.ArrayList) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 89 with BusinessObjectDataKey

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

the class CleanupDestroyedBusinessObjectDataServiceImplTest method testCleanupS3StorageUnit.

@Test
public void testCleanupS3StorageUnit() {
    // Create some data for testing the cleanup
    BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey = createDatabaseEntitiesForCleanupDestroyedBusinessObjectDataTesting();
    // Get a business object data key.
    BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper.createBusinessObjectDataKeyFromStorageUnitKey(businessObjectDataStorageUnitKey);
    // Confirm the business object data entity exists.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDao.getBusinessObjectDataByAltKey(businessObjectDataKey);
    assertThat("The business object data entity is null.", businessObjectDataEntity, is(notNullValue()));
    // Confirm the business object data attribute exists.
    BusinessObjectDataAttributeKey businessObjectDataAttributeKey = businessObjectDataAttributeHelper.getBusinessObjectDataAttributeKey(businessObjectDataKey, ATTRIBUTE_NAME);
    assertThat("The business object data attribute key is null.", businessObjectDataAttributeKey, is(notNullValue()));
    assertThat("The business object data entity attributes size is not correct.", businessObjectDataEntity.getAttributes().size(), is(equalTo(1)));
    // Confirm the business object data attribute exists.
    BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = businessObjectDataAttributeDao.getBusinessObjectDataAttributeByKey(businessObjectDataAttributeKey);
    assertThat("The business object data attribute entity is null.", businessObjectDataAttributeEntity, is(notNullValue()));
    // Confirm the storage unity exists.
    StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntityByKey(businessObjectDataStorageUnitKey);
    assertThat("The storage unit entity is null.", storageUnitEntity, is(notNullValue()));
    // Confirm the storage file exists.
    StorageFileEntity storageFileEntity = storageFileDao.getStorageFileByStorageNameAndFilePath(STORAGE_NAME, STORAGE_DIRECTORY_PATH);
    assertThat("The storage file entity is null.", storageFileEntity, is(notNullValue()));
    // Confirm the business object data status history exists.
    Collection<BusinessObjectDataStatusHistoryEntity> businessObjectDataStatusHistoryEntities = businessObjectDataEntity.getHistoricalStatuses();
    assertThat("The business object data status history entities size is not correct.", businessObjectDataStatusHistoryEntities.size(), is(equalTo(1)));
    // Confirm the business object data children
    assertThat("The business object data children size is not correct.", businessObjectDataEntity.getBusinessObjectDataChildren().size(), is(equalTo(1)));
    BusinessObjectDataEntity businessObjectDataEntityChild = businessObjectDataEntity.getBusinessObjectDataChildren().get(0);
    assertThat("The business object data children is not correct.", businessObjectDataEntityChild.getBusinessObjectDataParents().get(0), is(businessObjectDataEntity));
    // Confirm the business object data parents
    assertThat("The business object data parents size is not correct.", businessObjectDataEntity.getBusinessObjectDataParents().size(), is(equalTo(1)));
    assertThat(businessObjectDataEntityChild.getBusinessObjectDataParents().get(0), is(businessObjectDataEntity));
    BusinessObjectDataEntity businessObjectDataEntityParent = businessObjectDataEntity.getBusinessObjectDataParents().get(0);
    assertThat("The business object data parent is not correct.", businessObjectDataEntityParent.getBusinessObjectDataChildren().get(0), is(businessObjectDataEntity));
    // All traces of BData are removed: BData record, Attributes, related Storage Units and Storage Files, Status history, parent-child relationships
    cleanupDestroyedBusinessObjectDataService.cleanupS3StorageUnit(businessObjectDataStorageUnitKey);
    // Verify the business object data has been removed.
    businessObjectDataEntity = businessObjectDataDao.getBusinessObjectDataByAltKey(businessObjectDataKey);
    assertThat("The business object data entity is not null.", businessObjectDataEntity, is(nullValue()));
    // Verify the business object data attribute has been removed.
    businessObjectDataAttributeEntity = businessObjectDataAttributeDao.getBusinessObjectDataAttributeByKey(businessObjectDataAttributeKey);
    assertThat("The business object data attribute entity is not null.", businessObjectDataAttributeEntity, is(nullValue()));
    // Verify the storage unit has been removed.
    storageUnitEntity = storageUnitDao.getStorageUnitByKey(businessObjectDataStorageUnitKey);
    assertThat("The storage unit entity is not null.", storageUnitEntity, is(nullValue()));
    // Verify the storage file has been removed.
    storageFileEntity = storageFileDao.getStorageFileByStorageNameAndFilePath(STORAGE_NAME, STORAGE_DIRECTORY_PATH);
    assertThat("The storage file entity is not null.", storageFileEntity, is(nullValue()));
    // Verify the business object data children parent relationship has been removed
    businessObjectDataEntityChild = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataHelper.createBusinessObjectDataKeyFromEntity(businessObjectDataEntityChild));
    assertThat("The business object data children size is not correct.", businessObjectDataEntityChild.getBusinessObjectDataParents().size(), is(equalTo(0)));
    // // Verify the business object data parent child relationship has been removed
    businessObjectDataEntityParent = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataHelper.createBusinessObjectDataKeyFromEntity(businessObjectDataEntityParent));
    assertThat("The business object data parents size is not correct.", businessObjectDataEntityParent.getBusinessObjectDataChildren().size(), is(equalTo(0)));
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) BusinessObjectDataAttributeEntity(org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity) BusinessObjectDataStatusHistoryEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusHistoryEntity) StorageFileEntity(org.finra.herd.model.jpa.StorageFileEntity) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) BusinessObjectDataAttributeKey(org.finra.herd.model.api.xml.BusinessObjectDataAttributeKey) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Test(org.junit.Test)

Example 90 with BusinessObjectDataKey

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

the class CleanupDestroyedBusinessObjectDataServiceImplTest method testGetS3StorageUnitsToCleanup.

@Test
public void testGetS3StorageUnitsToCleanup() {
    // Create a list of business object data keys.
    List<BusinessObjectDataKey> businessObjectDataKeys = new ArrayList<>();
    for (int i = 0; i < 7; i++) {
        businessObjectDataKeys.add(new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, Integer.toString(i), SUBPARTITION_VALUES, DATA_VERSION));
    }
    // Create database entities required for testing.
    List<StorageUnitEntity> storageUnitEntities = Lists.newArrayList();
    // Add 4 valid storage unit entries
    storageUnitEntities.add(storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, StoragePlatformEntity.S3, businessObjectDataKeys.get(0), LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.DELETED, StorageUnitStatusEntity.DISABLED, NO_STORAGE_DIRECTORY_PATH));
    storageUnitEntities.add(storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, StoragePlatformEntity.S3, businessObjectDataKeys.get(1), LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.DELETED, StorageUnitStatusEntity.DISABLED, NO_STORAGE_DIRECTORY_PATH));
    storageUnitEntities.add(storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, StoragePlatformEntity.S3, businessObjectDataKeys.get(2), LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.DELETED, StorageUnitStatusEntity.DISABLED, NO_STORAGE_DIRECTORY_PATH));
    storageUnitEntities.add(storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME_2, StoragePlatformEntity.S3, businessObjectDataKeys.get(3), LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.DELETED, StorageUnitStatusEntity.DISABLED, NO_STORAGE_DIRECTORY_PATH));
    // Not a valid business object data status
    storageUnitEntities.add(storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, StoragePlatformEntity.S3, businessObjectDataKeys.get(4), LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.ARCHIVED, StorageUnitStatusEntity.DISABLED, NO_STORAGE_DIRECTORY_PATH));
    // Not a valid storage unit status
    storageUnitEntities.add(storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, StoragePlatformEntity.S3, businessObjectDataKeys.get(5), LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.DELETED, StorageUnitStatusEntity.ARCHIVED, NO_STORAGE_DIRECTORY_PATH));
    // Not a valid storage platform
    storageUnitEntities.add(storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME_3, StoragePlatformEntity.TABLE_NAME, businessObjectDataKeys.get(6), LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.DELETED, StorageUnitStatusEntity.DISABLED, NO_STORAGE_DIRECTORY_PATH));
    // Set restore expiration time values.
    Timestamp currentTime = new Timestamp(System.currentTimeMillis());
    // Not a valid final destroy on date
    storageUnitEntities.get(0).setFinalDestroyOn(null);
    // Final destroy on date is not less than current timestamp
    storageUnitEntities.get(1).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, 1));
    // Valid final destroy on dates
    storageUnitEntities.get(2).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -1));
    storageUnitEntities.get(3).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -2));
    storageUnitEntities.get(4).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -2));
    storageUnitEntities.get(5).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -2));
    storageUnitEntities.get(6).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -2));
    // Retrieve the business object data storage unit keys and validate the results. Only two entities are expected to match all select criteria.
    List<BusinessObjectDataStorageUnitKey> result = cleanupDestroyedBusinessObjectDataService.getS3StorageUnitsToCleanup(MAX_RESULT);
    BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey3 = storageUnitHelper.createStorageUnitKeyFromEntity(storageUnitEntities.get(3));
    BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey2 = storageUnitHelper.createStorageUnitKeyFromEntity(storageUnitEntities.get(2));
    assertEquals(Arrays.asList(businessObjectDataStorageUnitKey3, businessObjectDataStorageUnitKey2), result);
    // Try to retrieve the business object data storage unit keys with max result limit set to 1. Only a single storage unit entity should get selected.
    result = cleanupDestroyedBusinessObjectDataService.getS3StorageUnitsToCleanup(1);
    assertEquals(Collections.singletonList(businessObjectDataStorageUnitKey3), result);
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) ArrayList(java.util.ArrayList) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Aggregations

BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)444 Test (org.junit.Test)378 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)138 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)93 ArrayList (java.util.ArrayList)92 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)78 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)62 StoragePolicyKey (org.finra.herd.model.api.xml.StoragePolicyKey)50 HashMap (java.util.HashMap)43 StorageFile (org.finra.herd.model.api.xml.StorageFile)38 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)36 BusinessObjectDataStorageUnitKey (org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey)33 Attribute (org.finra.herd.model.api.xml.Attribute)32 NotificationMessageDefinitions (org.finra.herd.model.api.xml.NotificationMessageDefinitions)32 StoragePolicySelection (org.finra.herd.model.dto.StoragePolicySelection)32 ConfigurationEntity (org.finra.herd.model.jpa.ConfigurationEntity)32 NotificationMessageDefinition (org.finra.herd.model.api.xml.NotificationMessageDefinition)30 Parameter (org.finra.herd.model.api.xml.Parameter)30 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)29 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)29