Search in sources :

Example 21 with BusinessObjectDataStorageUnitKey

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

the class StoragePolicyProcessorHelperServiceImpl method updateStoragePolicyTransitionFailedAttemptsIgnoreExceptionImpl.

/**
 * Increments the count for failed storage policy transition attempts for the specified storage unit. This method does not fail in case storage unit entity
 * update is unsuccessful, but simply logs the exception information as a warning.
 *
 * @param storagePolicyTransitionParamsDto the storage policy transition DTO that contains parameters needed to complete a storage policy transition. The
 * business object data key and storage name identify the storage unit to be updated
 */
protected void updateStoragePolicyTransitionFailedAttemptsIgnoreExceptionImpl(StoragePolicyTransitionParamsDto storagePolicyTransitionParamsDto) {
    // Log the DTO contents.
    LOGGER.info("storagePolicyTransitionParamsDto={}", jsonHelper.objectToJson(storagePolicyTransitionParamsDto));
    // Continue only when business object data kay and storage name are specified.
    if (storagePolicyTransitionParamsDto.getBusinessObjectDataKey() != null && storagePolicyTransitionParamsDto.getStorageName() != null) {
        try {
            // Create a storage unit key.
            BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey = storageUnitHelper.createBusinessObjectDataStorageUnitKey(storagePolicyTransitionParamsDto.getBusinessObjectDataKey(), storagePolicyTransitionParamsDto.getStorageName());
            // Retrieve the storage unit entity and make sure it exists.
            StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntityByKey(businessObjectDataStorageUnitKey);
            // Update the storage policy transition failed attempts count.
            storageUnitEntity.setStoragePolicyTransitionFailedAttempts(storageUnitEntity.getStoragePolicyTransitionFailedAttempts() == null ? 1 : storageUnitEntity.getStoragePolicyTransitionFailedAttempts() + 1);
            storageUnitDao.saveAndRefresh(storageUnitEntity);
            // Log the new value for the storage policy transition failed attempts counter.
            LOGGER.info("Incremented storage policy transition failed attempts counter. " + "storagePolicyTransitionFailedAttempts={} businessObjectDataStorageUnitKey={}", storageUnitEntity.getStoragePolicyTransitionFailedAttempts(), jsonHelper.objectToJson(businessObjectDataStorageUnitKey));
        } catch (Exception e) {
            LOGGER.warn(e.getMessage(), e);
        }
    }
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity)

Example 22 with BusinessObjectDataStorageUnitKey

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

the class ExpireRestoredBusinessObjectDataServiceImpl method getS3StorageUnitsToExpireImpl.

/**
 * Retrieves a list of keys for restored S3 storage units that are ready to be expired.
 *
 * @param maxResult the maximum number of results to retrieve
 *
 * @return the list of storage unit keys
 */
protected List<BusinessObjectDataStorageUnitKey> getS3StorageUnitsToExpireImpl(int maxResult) {
    // Retrieves a list of storage units that belong to S3 storage, have RESTORED status, and ready to be expired.
    List<StorageUnitEntity> storageUnitEntities = storageUnitDao.getS3StorageUnitsToExpire(maxResult);
    // Build a list of storage unit keys.
    List<BusinessObjectDataStorageUnitKey> storageUnitKeys = new ArrayList<>();
    for (StorageUnitEntity storageUnitEntity : storageUnitEntities) {
        storageUnitKeys.add(storageUnitHelper.createStorageUnitKeyFromEntity(storageUnitEntity));
    }
    return storageUnitKeys;
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) ArrayList(java.util.ArrayList)

Example 23 with BusinessObjectDataStorageUnitKey

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

the class BusinessObjectDataFinalizeRestoreServiceImpl method getS3StorageUnitsToRestoreImpl.

/**
 * Retrieves a list of keys for S3 storage units that are currently being restored.
 *
 * @param maxResult the maximum number of results to retrieve
 *
 * @return the list of storage unit keys
 */
protected List<BusinessObjectDataStorageUnitKey> getS3StorageUnitsToRestoreImpl(int maxResult) {
    // Retrieves a list of storage units that belong to S3 storage and have the relative S3 storage unit in RESTORING state.
    List<StorageUnitEntity> storageUnitEntities = storageUnitDao.getS3StorageUnitsToRestore(maxResult);
    // Build a list of storage unit keys.
    List<BusinessObjectDataStorageUnitKey> storageUnitKeys = new ArrayList<>();
    for (StorageUnitEntity storageUnitEntity : storageUnitEntities) {
        storageUnitKeys.add(storageUnitHelper.createStorageUnitKeyFromEntity(storageUnitEntity));
    }
    return storageUnitKeys;
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) ArrayList(java.util.ArrayList)

Example 24 with BusinessObjectDataStorageUnitKey

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

the class StorageUnitDaoTest method testGetStorageUnitByKey.

@Test
public void testGetStorageUnitByKey() {
    // Create and persist the relative database entities.
    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, STORAGE_UNIT_STATUS, STORAGE_DIRECTORY_PATH);
    // Get a storage unit.
    assertEquals(storageUnitEntity, storageUnitDao.getStorageUnitByKey(new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME)));
    // Test case insensitivity.
    assertEquals(storageUnitEntity, storageUnitDao.getStorageUnitByKey(new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE.toUpperCase(), BDEF_NAME.toUpperCase(), FORMAT_USAGE_CODE.toUpperCase(), FORMAT_FILE_TYPE_CODE.toUpperCase(), FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME.toUpperCase())));
    assertEquals(storageUnitEntity, storageUnitDao.getStorageUnitByKey(new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE.toLowerCase(), BDEF_NAME.toLowerCase(), FORMAT_USAGE_CODE.toLowerCase(), FORMAT_FILE_TYPE_CODE.toLowerCase(), FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME.toLowerCase())));
    // Try to retrieve storage unit using invalid input parameters.
    assertNull(storageUnitDao.getStorageUnitByKey(new BusinessObjectDataStorageUnitKey(I_DO_NOT_EXIST, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME)));
    assertNull(storageUnitDao.getStorageUnitByKey(new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, I_DO_NOT_EXIST, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME)));
    assertNull(storageUnitDao.getStorageUnitByKey(new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, I_DO_NOT_EXIST, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME)));
    assertNull(storageUnitDao.getStorageUnitByKey(new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, I_DO_NOT_EXIST, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME)));
    assertNull(storageUnitDao.getStorageUnitByKey(new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION_2, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME)));
    assertNull(storageUnitDao.getStorageUnitByKey(new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, I_DO_NOT_EXIST, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME)));
    assertNull(storageUnitDao.getStorageUnitByKey(new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES_2, DATA_VERSION, STORAGE_NAME)));
    assertNull(storageUnitDao.getStorageUnitByKey(new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION_2, STORAGE_NAME)));
    assertNull(storageUnitDao.getStorageUnitByKey(new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, I_DO_NOT_EXIST)));
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) Test(org.junit.Test)

Example 25 with BusinessObjectDataStorageUnitKey

use of org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey 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)

Aggregations

BusinessObjectDataStorageUnitKey (org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey)62 Test (org.junit.Test)51 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)33 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)30 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)26 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)14 ArrayList (java.util.ArrayList)10 StorageFile (org.finra.herd.model.api.xml.StorageFile)7 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)6 BusinessObjectDataStorageUnitStatusUpdateRequest (org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitStatusUpdateRequest)6 BusinessObjectDataStorageUnitStatusUpdateResponse (org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitStatusUpdateResponse)6 StorageDirectory (org.finra.herd.model.api.xml.StorageDirectory)6 BusinessObjectDataRestoreDto (org.finra.herd.model.dto.BusinessObjectDataRestoreDto)6 BusinessObjectDataStorageUnitCreateRequest (org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitCreateRequest)5 StorageFileEntity (org.finra.herd.model.jpa.StorageFileEntity)5 HashMap (java.util.HashMap)4 FieldExtension (org.activiti.bpmn.model.FieldExtension)4 Parameter (org.finra.herd.model.api.xml.Parameter)4 StorageEntity (org.finra.herd.model.jpa.StorageEntity)4 BusinessObjectDataStorageUnitCreateResponse (org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitCreateResponse)3