Search in sources :

Example 16 with BusinessObjectDataStorageUnitKey

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

the class StoragePolicyProcessorHelperServiceImplTest method testUpdateStoragePolicyTransitionFailedAttemptsIgnoreExceptionImplFirstFailure.

@Test
public void testUpdateStoragePolicyTransitionFailedAttemptsIgnoreExceptionImplFirstFailure() {
    // 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 entity with its storagePolicyTransitionFailedAttempts set to NULL.
    StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
    // Create a business object data 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 a storage policy transition parameters DTO.
    StoragePolicyTransitionParamsDto storagePolicyTransitionParamsDto = new StoragePolicyTransitionParamsDto();
    storagePolicyTransitionParamsDto.setBusinessObjectDataKey(businessObjectDataKey);
    storagePolicyTransitionParamsDto.setStorageName(STORAGE_NAME);
    // Mock the external calls.
    when(storageUnitHelper.createBusinessObjectDataStorageUnitKey(businessObjectDataKey, STORAGE_NAME)).thenReturn(businessObjectDataStorageUnitKey);
    when(storageUnitDaoHelper.getStorageUnitEntityByKey(businessObjectDataStorageUnitKey)).thenReturn(storageUnitEntity);
    // Call the method under test.
    storagePolicyProcessorHelperServiceImpl.updateStoragePolicyTransitionFailedAttemptsIgnoreException(storagePolicyTransitionParamsDto);
    // Verify the external calls.
    verify(jsonHelper).objectToJson(storagePolicyTransitionParamsDto);
    verify(storageUnitHelper).createBusinessObjectDataStorageUnitKey(businessObjectDataKey, STORAGE_NAME);
    verify(storageUnitDaoHelper).getStorageUnitEntityByKey(businessObjectDataStorageUnitKey);
    verify(storageUnitDao).saveAndRefresh(storageUnitEntity);
    verify(jsonHelper).objectToJson(businessObjectDataStorageUnitKey);
    verifyNoMoreInteractionsHelper();
    // Validate the results. The counter value now should be equal to 1.
    assertEquals(Integer.valueOf(1), storageUnitEntity.getStoragePolicyTransitionFailedAttempts());
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) StoragePolicyTransitionParamsDto(org.finra.herd.model.dto.StoragePolicyTransitionParamsDto) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 17 with BusinessObjectDataStorageUnitKey

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

the class BusinessObjectDataFinalizeRestoreJob method executeInternal.

@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
    // Log that the system job is started.
    LOGGER.info("Started system job. systemJobName=\"{}\"", JOB_NAME);
    // Get the parameter values.
    int maxBusinessObjectDataInstancesToFinalize = parameterHelper.getParameterValueAsInteger(parameters, ConfigurationValue.BDATA_FINALIZE_RESTORE_JOB_MAX_BDATA_INSTANCES);
    // Log the parameter values.
    LOGGER.info("systemJobName=\"{}\" {}={}", JOB_NAME, ConfigurationValue.BDATA_FINALIZE_RESTORE_JOB_MAX_BDATA_INSTANCES, maxBusinessObjectDataInstancesToFinalize);
    // Continue the processing only if the maximum number of business object data instances
    // that is allowed to be processed in a single run of this system job is greater than zero.
    int finalizedRestores = 0;
    if (maxBusinessObjectDataInstancesToFinalize > 0) {
        // Get business object data that is currently being restored.
        List<BusinessObjectDataStorageUnitKey> storageUnitKeys = businessObjectDataFinalizeRestoreService.getS3StorageUnitsToRestore(maxBusinessObjectDataInstancesToFinalize);
        // Log the number of storage units selected for processing.
        LOGGER.info("Selected for processing S3 storage units. systemJobName=\"{}\" storageUnitCount={}", JOB_NAME, storageUnitKeys.size());
        // Try to finalize restore for each of the selected storage units.
        for (BusinessObjectDataStorageUnitKey storageUnitKey : storageUnitKeys) {
            try {
                businessObjectDataFinalizeRestoreService.finalizeRestore(storageUnitKey);
                finalizedRestores += 1;
            } catch (RuntimeException runtimeException) {
                // Log the exception as a warning.
                LOGGER.warn("Failed to finalize a business object data restore from the Glacier storage. " + "systemJobName=\"{}\" storageName=\"{}\" businessObjectDataKey={}", JOB_NAME, storageUnitKey.getStorageName(), jsonHelper.objectToJson(businessObjectDataHelper.createBusinessObjectDataKeyFromStorageUnitKey(storageUnitKey)), runtimeException);
            }
        }
    }
    // Log the number of finalized restores.
    LOGGER.info("Finalized restore for business object data instances. systemJobName=\"{}\" businessObjectDataCount={}", JOB_NAME, finalizedRestores);
    // Log that the system job is ended.
    LOGGER.info("Completed system job. systemJobName=\"{}\"", JOB_NAME);
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey)

Example 18 with BusinessObjectDataStorageUnitKey

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

the class BusinessObjectDataFinalizeRestoreHelperServiceTest method testPrepareToFinalizeRestoreMissingOptionalParameters.

@Test
public void testPrepareToFinalizeRestoreMissingOptionalParameters() throws Exception {
    // Create a business object data key without sub-partition values.
    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 database entities required for testing.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForFinalizeRestoreTesting(businessObjectDataKey);
    // Get the storage unit entity.
    StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity);
    // Create a storage unit key.
    BusinessObjectDataStorageUnitKey storageUnitKey = storageUnitHelper.createStorageUnitKey(businessObjectDataKey, STORAGE_NAME);
    // Prepare to finalize a restore for business object data without sub-partition values.
    BusinessObjectDataRestoreDto result = businessObjectDataFinalizeRestoreHelperService.prepareToFinalizeRestore(storageUnitKey);
    // Validate the returned object.
    assertEquals(new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, NO_S3_ENDPOINT, S3_BUCKET_NAME, result.getS3KeyPrefix(), NO_STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS, storageFileHelper.createStorageFilesFromEntities(storageUnitEntity.getStorageFiles()), NO_EXCEPTION), result);
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectDataRestoreDto(org.finra.herd.model.dto.BusinessObjectDataRestoreDto) Test(org.junit.Test)

Example 19 with BusinessObjectDataStorageUnitKey

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

the class BusinessObjectDataFinalizeRestoreHelperServiceTest method testPrepareToFinalizeRestoreStorageUnitNotInRestoringState.

@Test
public void testPrepareToFinalizeRestoreStorageUnitNotInRestoringState() throws Exception {
    // 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 not in RESTORING state along with other database entities required for testing.
    storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, StoragePlatformEntity.S3, businessObjectDataKey, LATEST_VERSION_FLAG_SET, BDATA_STATUS, STORAGE_UNIT_STATUS, NO_STORAGE_DIRECTORY_PATH);
    // Create a storage unit key.
    BusinessObjectDataStorageUnitKey storageUnitKey = storageUnitHelper.createStorageUnitKey(businessObjectDataKey, STORAGE_NAME);
    // Try to prepare to finalize a restore when storage unit is not in RESTORING state.
    try {
        businessObjectDataFinalizeRestoreHelperService.prepareToFinalizeRestore(storageUnitKey);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("S3 storage unit in \"%s\" storage must have \"%s\" status, but it actually has \"%s\" status. Business object data: {%s}", STORAGE_NAME, StorageUnitStatusEntity.RESTORING, STORAGE_UNIT_STATUS, businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataKeyAsString(businessObjectDataKey)), e.getMessage());
    }
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Test(org.junit.Test)

Example 20 with BusinessObjectDataStorageUnitKey

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

the class CleanupDestroyedBusinessObjectDataServiceImpl method getS3StorageUnitsToCleanupImpl.

/**
 * Retrieves a list of keys for destroyed S3 storage units that are ready for cleanup.
 *
 * @param maxResult the maximum number of results to retrieve
 *
 * @return the list of storage unit keys
 */
List<BusinessObjectDataStorageUnitKey> getS3StorageUnitsToCleanupImpl(int maxResult) {
    // Retrieves a list of storage units that belong to S3 storage, and has a final destroy on timestamp < current time, has a DELETED status,
    // and associated BData has a DELETED status.
    List<StorageUnitEntity> storageUnitEntities = storageUnitDao.getS3StorageUnitsToCleanup(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)

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