use of org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey in project herd by FINRAOS.
the class ExpireRestoredBusinessObjectDataJob 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 maxBusinessObjectDataInstancesToProcess = parameterHelper.getParameterValueAsInteger(parameters, ConfigurationValue.EXPIRE_RESTORED_BDATA_JOB_MAX_BDATA_INSTANCES);
// Log the parameter values.
LOGGER.info("systemJobName=\"{}\" {}={}", JOB_NAME, ConfigurationValue.EXPIRE_RESTORED_BDATA_JOB_MAX_BDATA_INSTANCES, maxBusinessObjectDataInstancesToProcess);
// 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 processedBusinessObjectDataInstances = 0;
if (maxBusinessObjectDataInstancesToProcess > 0) {
// Select restored business object data that is already expired.
List<BusinessObjectDataStorageUnitKey> storageUnitKeys = expireRestoredBusinessObjectDataService.getS3StorageUnitsToExpire(maxBusinessObjectDataInstancesToProcess);
// 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 expire each of the selected storage units.
for (BusinessObjectDataStorageUnitKey storageUnitKey : storageUnitKeys) {
try {
expireRestoredBusinessObjectDataService.expireS3StorageUnit(storageUnitKey);
processedBusinessObjectDataInstances += 1;
} catch (RuntimeException runtimeException) {
// Log the exception.
LOGGER.error("Failed to expire a restored business object data. systemJobName=\"{}\" storageName=\"{}\" businessObjectDataKey={}", JOB_NAME, storageUnitKey.getStorageName(), jsonHelper.objectToJson(businessObjectDataHelper.createBusinessObjectDataKeyFromStorageUnitKey(storageUnitKey)), runtimeException);
}
}
}
// Log the number of finalized restores.
LOGGER.info("Expired restored business object data instances. systemJobName=\"{}\" businessObjectDataCount={}", JOB_NAME, processedBusinessObjectDataInstances);
// Log that the system job is ended.
LOGGER.info("Completed system job. systemJobName=\"{}\"", JOB_NAME);
}
use of org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey in project herd by FINRAOS.
the class StoragePolicyProcessorHelperServiceImplTest method testUpdateStoragePolicyTransitionFailedAttemptsIgnoreExceptionImplSecondFailure.
@Test
public void testUpdateStoragePolicyTransitionFailedAttemptsIgnoreExceptionImplSecondFailure() {
// 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 already set to 1.
StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
storageUnitEntity.setStoragePolicyTransitionFailedAttempts(1);
// 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 2.
assertEquals(Integer.valueOf(2), storageUnitEntity.getStoragePolicyTransitionFailedAttempts());
}
use of org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey in project herd by FINRAOS.
the class StorageUnitHelperTest method testCreateStorageUnitKeyFromEntity.
@Test
public void testCreateStorageUnitKeyFromEntity() {
// 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 unit entity.
StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(businessObjectDataStorageUnitKey, STORAGE_UNIT_STATUS);
// Mock the external calls.
when(businessObjectDataHelper.getSubPartitionValues(storageUnitEntity.getBusinessObjectData())).thenReturn(SUBPARTITION_VALUES);
// Call the method under test.
BusinessObjectDataStorageUnitKey result = storageUnitHelper.createStorageUnitKeyFromEntity(storageUnitEntity);
// Verify the external calls.
verify(businessObjectDataHelper).getSubPartitionValues(storageUnitEntity.getBusinessObjectData());
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME), result);
}
use of org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey in project herd by FINRAOS.
the class StorageUnitHelperTest method testValidateBusinessObjectDataStorageUnitKey.
@Test
public void testValidateBusinessObjectDataStorageUnitKey() {
// 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);
// Mock the external calls.
when(alternateKeyHelper.validateStringParameter("namespace", BDEF_NAMESPACE)).thenReturn(BDEF_NAMESPACE);
when(alternateKeyHelper.validateStringParameter("business object definition name", BDEF_NAME)).thenReturn(BDEF_NAME);
when(alternateKeyHelper.validateStringParameter("business object format usage", FORMAT_USAGE_CODE)).thenReturn(FORMAT_USAGE_CODE);
when(alternateKeyHelper.validateStringParameter("business object format file type", FORMAT_FILE_TYPE_CODE)).thenReturn(FORMAT_FILE_TYPE_CODE);
when(alternateKeyHelper.validateStringParameter("partition value", PARTITION_VALUE)).thenReturn(PARTITION_VALUE);
when(alternateKeyHelper.validateStringParameter("storage name", STORAGE_NAME)).thenReturn(STORAGE_NAME);
// Call the method under test.
storageUnitHelper.validateBusinessObjectDataStorageUnitKey(businessObjectDataStorageUnitKey);
// Verify the external calls.
verify(alternateKeyHelper).validateStringParameter("namespace", BDEF_NAMESPACE);
verify(alternateKeyHelper).validateStringParameter("business object definition name", BDEF_NAME);
verify(alternateKeyHelper).validateStringParameter("business object format usage", FORMAT_USAGE_CODE);
verify(alternateKeyHelper).validateStringParameter("business object format file type", FORMAT_FILE_TYPE_CODE);
verify(alternateKeyHelper).validateStringParameter("partition value", PARTITION_VALUE);
verify(businessObjectDataHelper).validateSubPartitionValues(SUBPARTITION_VALUES);
verify(alternateKeyHelper).validateStringParameter("storage name", STORAGE_NAME);
verifyNoMoreInteractionsHelper();
}
use of org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey in project herd by FINRAOS.
the class StorageUnitHelperTest method testCreateStorageUnitsFromEntities.
@Test
public void testCreateStorageUnitsFromEntities() {
// 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);
Timestamp restoredExpirationOn = new Timestamp(new Date().getTime());
// Create a storage unit entity.
StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(businessObjectDataStorageUnitKey, STORAGE_UNIT_STATUS);
storageUnitEntity.setDirectoryPath(STORAGE_DIRECTORY_PATH);
storageUnitEntity.setStoragePolicyTransitionFailedAttempts(STORAGE_POLICY_TRANSITION_FAILED_ATTEMPTS);
storageUnitEntity.setRestoreExpirationOn(restoredExpirationOn);
// Call the method under test.
List<StorageUnit> result = storageUnitHelper.createStorageUnitsFromEntities(Arrays.asList(storageUnitEntity), NO_INCLUDE_STORAGE_UNIT_STATUS_HISTORY);
// Verify the external calls.
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(Arrays.asList(new StorageUnit(new Storage(STORAGE_NAME, StoragePlatformEntity.S3, null), new StorageDirectory(STORAGE_DIRECTORY_PATH), null, STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS_HISTORY, STORAGE_POLICY_TRANSITION_FAILED_ATTEMPTS, HerdDateUtils.getXMLGregorianCalendarValue(restoredExpirationOn))), result);
}
Aggregations