Search in sources :

Example 36 with BusinessObjectDataStorageUnitKey

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

the class UpdateBusinessObjectDataStorageUnitStatusTest method testUpdateBusinessObjectDataStorageUnitStatusMissingOptionalParameters.

@Test
public void testUpdateBusinessObjectDataStorageUnitStatusMissingOptionalParameters() throws Exception {
    // 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, NO_SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME);
    // Create a storage unit entity.
    storageUnitDaoTestHelper.createStorageUnitEntity(businessObjectDataStorageUnitKey, STORAGE_UNIT_STATUS);
    // Create a storage unit status entity.
    storageUnitStatusDaoTestHelper.createStorageUnitStatusEntity(STORAGE_UNIT_STATUS_2);
    List<FieldExtension> fieldExtensionList = new ArrayList<>();
    fieldExtensionList.add(buildFieldExtension("namespace", "${namespace}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectDefinitionName", "${businessObjectDefinitionName}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectFormatUsage", "${businessObjectFormatUsage}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectFormatFileType", "${businessObjectFormatFileType}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectFormatVersion", "${businessObjectFormatVersion}"));
    fieldExtensionList.add(buildFieldExtension("partitionValue", "${partitionValue}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectDataVersion", "${businessObjectDataVersion}"));
    fieldExtensionList.add(buildFieldExtension("storageName", "${storageName}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectDataStorageUnitStatus", "${businessObjectDataStorageUnitStatus}"));
    List<Parameter> parameters = new ArrayList<>();
    parameters.add(buildParameter("namespace", BDEF_NAMESPACE));
    parameters.add(buildParameter("businessObjectDefinitionName", BDEF_NAME));
    parameters.add(buildParameter("businessObjectFormatUsage", FORMAT_USAGE_CODE));
    parameters.add(buildParameter("businessObjectFormatFileType", FORMAT_FILE_TYPE_CODE));
    parameters.add(buildParameter("businessObjectFormatVersion", FORMAT_VERSION.toString()));
    parameters.add(buildParameter("partitionValue", PARTITION_VALUE));
    parameters.add(buildParameter("businessObjectDataVersion", DATA_VERSION.toString()));
    parameters.add(buildParameter("storageName", STORAGE_NAME));
    parameters.add(buildParameter("businessObjectDataStorageUnitStatus", STORAGE_UNIT_STATUS_2));
    // Build the expected response object.
    BusinessObjectDataStorageUnitStatusUpdateResponse expectedResponse = new BusinessObjectDataStorageUnitStatusUpdateResponse(businessObjectDataStorageUnitKey, STORAGE_UNIT_STATUS_2, STORAGE_UNIT_STATUS);
    // Run the activiti task and validate the returned response object.
    Map<String, Object> variableValuesToValidate = new HashMap<>();
    variableValuesToValidate.put(UpdateBusinessObjectDataStorageUnitStatus.VARIABLE_JSON_RESPONSE, jsonHelper.objectToJson(expectedResponse));
    testActivitiServiceTaskSuccess(UpdateBusinessObjectDataStorageUnitStatus.class.getCanonicalName(), fieldExtensionList, parameters, variableValuesToValidate);
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) HashMap(java.util.HashMap) FieldExtension(org.activiti.bpmn.model.FieldExtension) ArrayList(java.util.ArrayList) Parameter(org.finra.herd.model.api.xml.Parameter) BusinessObjectDataStorageUnitStatusUpdateResponse(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitStatusUpdateResponse) Test(org.junit.Test)

Example 37 with BusinessObjectDataStorageUnitKey

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

the class UpdateBusinessObjectDataStorageUnitStatusTest method testUpdateBusinessObjectDataStorageUnitStatus.

@Test
public void testUpdateBusinessObjectDataStorageUnitStatus() throws Exception {
    // 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.
    storageUnitDaoTestHelper.createStorageUnitEntity(businessObjectDataStorageUnitKey, STORAGE_UNIT_STATUS);
    // Create a storage unit status entity.
    storageUnitStatusDaoTestHelper.createStorageUnitStatusEntity(STORAGE_UNIT_STATUS_2);
    List<FieldExtension> fieldExtensionList = new ArrayList<>();
    fieldExtensionList.add(buildFieldExtension("namespace", "${namespace}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectDefinitionName", "${businessObjectDefinitionName}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectFormatUsage", "${businessObjectFormatUsage}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectFormatFileType", "${businessObjectFormatFileType}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectFormatVersion", "${businessObjectFormatVersion}"));
    fieldExtensionList.add(buildFieldExtension("partitionValue", "${partitionValue}"));
    fieldExtensionList.add(buildFieldExtension("subPartitionValues", "${subPartitionValues}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectDataVersion", "${businessObjectDataVersion}"));
    fieldExtensionList.add(buildFieldExtension("storageName", "${storageName}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectDataStorageUnitStatus", "${businessObjectDataStorageUnitStatus}"));
    List<Parameter> parameters = new ArrayList<>();
    parameters.add(buildParameter("namespace", BDEF_NAMESPACE));
    parameters.add(buildParameter("businessObjectDefinitionName", BDEF_NAME));
    parameters.add(buildParameter("businessObjectFormatUsage", FORMAT_USAGE_CODE));
    parameters.add(buildParameter("businessObjectFormatFileType", FORMAT_FILE_TYPE_CODE));
    parameters.add(buildParameter("businessObjectFormatVersion", FORMAT_VERSION.toString()));
    parameters.add(buildParameter("partitionValue", PARTITION_VALUE));
    parameters.add(buildParameter("subPartitionValues", herdStringHelper.buildStringWithDefaultDelimiter(SUBPARTITION_VALUES)));
    parameters.add(buildParameter("businessObjectDataVersion", DATA_VERSION.toString()));
    parameters.add(buildParameter("storageName", STORAGE_NAME));
    parameters.add(buildParameter("businessObjectDataStorageUnitStatus", STORAGE_UNIT_STATUS_2));
    // Build the expected response object.
    BusinessObjectDataStorageUnitStatusUpdateResponse expectedResponse = new BusinessObjectDataStorageUnitStatusUpdateResponse(businessObjectDataStorageUnitKey, STORAGE_UNIT_STATUS_2, STORAGE_UNIT_STATUS);
    // Run the activiti task and validate the returned response object.
    Map<String, Object> variableValuesToValidate = new HashMap<>();
    variableValuesToValidate.put(UpdateBusinessObjectDataStorageUnitStatus.VARIABLE_JSON_RESPONSE, jsonHelper.objectToJson(expectedResponse));
    testActivitiServiceTaskSuccess(UpdateBusinessObjectDataStorageUnitStatus.class.getCanonicalName(), fieldExtensionList, parameters, variableValuesToValidate);
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) HashMap(java.util.HashMap) FieldExtension(org.activiti.bpmn.model.FieldExtension) ArrayList(java.util.ArrayList) Parameter(org.finra.herd.model.api.xml.Parameter) BusinessObjectDataStorageUnitStatusUpdateResponse(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitStatusUpdateResponse) Test(org.junit.Test)

Example 38 with BusinessObjectDataStorageUnitKey

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

the class CleanupDestroyedBusinessObjectDataServiceImpl method cleanupS3StorageUnitImpl.

/**
 * All traces of BData are removed from the Herd repository: BData record, Attributes, related Storage Units and Storage Files, Status history, parent-child
 * relationships
 *
 * @param businessObjectDataStorageUnitKey the business object data storage unit key
 */
void cleanupS3StorageUnitImpl(BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey) {
    // Get a business object data key.
    BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper.createBusinessObjectDataKeyFromStorageUnitKey(businessObjectDataStorageUnitKey);
    // Retrieve the business object data entity.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey);
    // Get the number of S3 storage units associated with this Business Object Data.
    long numberOfS3StorageUnitsAssociatedWithThisBusinessObjectData = businessObjectDataEntity.getStorageUnits().stream().filter(storageUnitEntity -> storageUnitEntity.getStorage().getStoragePlatform().getName().equals(StoragePlatformEntity.S3)).count();
    // Validate that there are not multiple S3 storage units associated with this Business Object Data.
    if (numberOfS3StorageUnitsAssociatedWithThisBusinessObjectData > 1) {
        // If there are multiple S3 storage units associated with this Business Object Data then throw a runtime exception.
        throw new IllegalArgumentException(String.format("Business object data has multiple (%s) %s storage units. Business object data: {%s}", numberOfS3StorageUnitsAssociatedWithThisBusinessObjectData, StoragePlatformEntity.S3, businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)));
    }
    // Get a list of children business object data
    List<BusinessObjectDataEntity> childrenBusinessObjectDataEntities = businessObjectDataEntity.getBusinessObjectDataChildren();
    // For each child in the list of children business object data entities remove this business object data from the list of parents
    for (BusinessObjectDataEntity childBusinessObjectDataEntity : childrenBusinessObjectDataEntities) {
        List<BusinessObjectDataEntity> parentBusinessObjectDataEntities = childBusinessObjectDataEntity.getBusinessObjectDataParents();
        parentBusinessObjectDataEntities.remove(businessObjectDataEntity);
        businessObjectDataDao.saveAndRefresh(childBusinessObjectDataEntity);
    }
    // Get a list of parent business object data
    List<BusinessObjectDataEntity> parentBusinessObjectDataEntities = businessObjectDataEntity.getBusinessObjectDataParents();
    // For each child in the list of children business object data entities remove this business object data from the list of parents
    for (BusinessObjectDataEntity parentBusinessObjectDataEntity : parentBusinessObjectDataEntities) {
        List<BusinessObjectDataEntity> childBusinessObjectDataEntities = parentBusinessObjectDataEntity.getBusinessObjectDataChildren();
        childBusinessObjectDataEntities.remove(businessObjectDataEntity);
        businessObjectDataDao.saveAndRefresh(parentBusinessObjectDataEntity);
    }
    // Delete this business object data.
    businessObjectDataDao.delete(businessObjectDataEntity);
    // If this business object data version is the latest, set the latest flag on the previous version of this object data, if it exists.
    if (businessObjectDataEntity.getLatestVersion()) {
        // Get the maximum version for this business object data, if it exists.
        Integer maxBusinessObjectDataVersion = businessObjectDataDao.getBusinessObjectDataMaxVersion(businessObjectDataKey);
        if (maxBusinessObjectDataVersion != null) {
            // Retrieve the previous version business object data entity. Since we successfully got the maximum
            // version for this business object data, the retrieved entity is not expected to be null.
            BusinessObjectDataEntity previousVersionBusinessObjectDataEntity = businessObjectDataDao.getBusinessObjectDataByAltKey(new BusinessObjectDataKey(businessObjectDataKey.getNamespace(), businessObjectDataKey.getBusinessObjectDefinitionName(), businessObjectDataKey.getBusinessObjectFormatUsage(), businessObjectDataKey.getBusinessObjectFormatFileType(), businessObjectDataKey.getBusinessObjectFormatVersion(), businessObjectDataKey.getPartitionValue(), businessObjectDataKey.getSubPartitionValues(), maxBusinessObjectDataVersion));
            // Update the previous version business object data entity.
            previousVersionBusinessObjectDataEntity.setLatestVersion(true);
            businessObjectDataDao.saveAndRefresh(previousVersionBusinessObjectDataEntity);
        }
    }
    // Create a storage unit notification for the storage unit status change event.
    notificationEventService.processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataKey, businessObjectDataStorageUnitKey.getStorageName(), null, StorageUnitStatusEntity.DISABLED);
    // Create a business object data notification for the business object data status change event.
    notificationEventService.processBusinessObjectDataNotificationEventAsync(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_STTS_CHG, businessObjectDataKey, null, BusinessObjectDataStatusEntity.DELETED);
}
Also used : NotificationEventTypeEntity(org.finra.herd.model.jpa.NotificationEventTypeEntity) BusinessObjectDataDao(org.finra.herd.dao.BusinessObjectDataDao) StorageUnitDao(org.finra.herd.dao.StorageUnitDao) Autowired(org.springframework.beans.factory.annotation.Autowired) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) BusinessObjectDataHelper(org.finra.herd.service.helper.BusinessObjectDataHelper) DaoSpringModuleConfig(org.finra.herd.dao.config.DaoSpringModuleConfig) ArrayList(java.util.ArrayList) BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) List(java.util.List) PublishNotificationMessages(org.finra.herd.model.annotation.PublishNotificationMessages) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) NotificationEventService(org.finra.herd.service.NotificationEventService) BusinessObjectDataDaoHelper(org.finra.herd.service.helper.BusinessObjectDataDaoHelper) Propagation(org.springframework.transaction.annotation.Propagation) StoragePlatformEntity(org.finra.herd.model.jpa.StoragePlatformEntity) Service(org.springframework.stereotype.Service) CleanupDestroyedBusinessObjectDataService(org.finra.herd.service.CleanupDestroyedBusinessObjectDataService) Lazy(org.springframework.context.annotation.Lazy) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) StorageUnitHelper(org.finra.herd.service.helper.StorageUnitHelper) Transactional(org.springframework.transaction.annotation.Transactional) BusinessObjectDataStatusEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey)

Example 39 with BusinessObjectDataStorageUnitKey

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

the class BusinessObjectDataFinalizeRestoreHelperServiceTest method testPrepareToFinalizeRestoreStorageUnitAlreadyRestored.

@Test
public void testPrepareToFinalizeRestoreStorageUnitAlreadyRestored() 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 database entities required for testing with an already restored storage unit.
    businessObjectDataServiceTestHelper.createDatabaseEntitiesForFinalizeRestoreTesting(businessObjectDataKey, STORAGE_NAME, S3_BUCKET_NAME, StorageUnitStatusEntity.RESTORED);
    // Create a storage unit key.
    BusinessObjectDataStorageUnitKey storageUnitKey = storageUnitHelper.createStorageUnitKey(businessObjectDataKey, STORAGE_NAME);
    // Try to prepare to finalize a restore when storage unit is already restored.
    try {
        businessObjectDataFinalizeRestoreHelperService.prepareToFinalizeRestore(storageUnitKey);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Business object data is already restored in \"%s\" S3 storage. Business object data: {%s}", STORAGE_NAME, 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 40 with BusinessObjectDataStorageUnitKey

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

the class BusinessObjectDataFinalizeRestoreHelperServiceTest method testPrepareToFinalizeRestoreStorageUnitHasNoStorageFiles.

@Test
public void testPrepareToFinalizeRestoreStorageUnitHasNoStorageFiles() 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, NO_SUBPARTITION_VALUES, DATA_VERSION);
    // Create database entities required for testing.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForFinalizeRestoreTesting(businessObjectDataKey, STORAGE_NAME, S3_BUCKET_NAME, StorageUnitStatusEntity.RESTORING);
    // Get the origin storage unit entity.
    StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity);
    // Remove storage files from the storage unit.
    storageUnitEntity.getStorageFiles().clear();
    // Create a storage unit key.
    BusinessObjectDataStorageUnitKey glacierStorageUnitKey = storageUnitHelper.createStorageUnitKey(businessObjectDataKey, STORAGE_NAME);
    // Try to prepare to finalize a restore when storage unit has no storage files.
    try {
        businessObjectDataFinalizeRestoreHelperService.prepareToFinalizeRestore(glacierStorageUnitKey);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Business object data has no storage files registered in \"%s\" storage. Business object data: {%s}", STORAGE_NAME, businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataKeyAsString(businessObjectDataKey)), e.getMessage());
    }
}
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) 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