Search in sources :

Example 41 with StorageUnitEntity

use of org.finra.herd.model.jpa.StorageUnitEntity in project herd by FINRAOS.

the class BusinessObjectDataInitiateDestroyHelperServiceImpl method getAndValidateStorageUnit.

/**
 * Retrieves and validates storage unit for the specified business object data. The method makes sure that there is one and only one S3 storage unit.
 *
 * @param businessObjectDataEntity the business object data entity
 * @param businessObjectDataKey the business object data key
 *
 * @return the storage unit entity
 */
protected StorageUnitEntity getAndValidateStorageUnit(BusinessObjectDataEntity businessObjectDataEntity, BusinessObjectDataKey businessObjectDataKey) {
    // Retrieve all S3 storage units for this business object data.
    List<StorageUnitEntity> s3StorageUnitEntities = storageUnitDao.getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity);
    // Validate that business object data has at least one S3 storage unit.
    if (CollectionUtils.isEmpty(s3StorageUnitEntities)) {
        throw new IllegalArgumentException(String.format("Business object data has no S3 storage unit. Business object data: {%s}", businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)));
    }
    // Validate that this business object data has no multiple S3 storage units.
    if (CollectionUtils.size(s3StorageUnitEntities) > 1) {
        throw new IllegalArgumentException(String.format("Business object data has multiple (%s) %s storage units. Business object data: {%s}", s3StorageUnitEntities.size(), StoragePlatformEntity.S3, businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)));
    }
    // Get the S3 storage unit.
    StorageUnitEntity storageUnitEntity = s3StorageUnitEntities.get(0);
    // Get the storage unit status code.
    String storageUnitStatus = storageUnitEntity.getStatus().getCode();
    // Validate storage unit status.
    if (!BusinessObjectDataInitiateDestroyHelperServiceImpl.SUPPORTED_STORAGE_UNIT_STATUSES.contains(storageUnitStatus)) {
        throw new IllegalArgumentException(String.format("Storage unit status \"%s\" is not supported by the business object data destroy feature. Storage: {%s}, business object data: {%s}", storageUnitStatus, storageUnitEntity.getStorage().getName(), businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)));
    }
    return storageUnitEntity;
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity)

Example 42 with StorageUnitEntity

use of org.finra.herd.model.jpa.StorageUnitEntity in project herd by FINRAOS.

the class BusinessObjectDataServiceImpl method checkBusinessObjectDataAvailabilityImpl.

/**
 * Performs a search and returns a list of business object data key values and relative statuses for a range of requested business object data.
 *
 * @param request the business object data availability request
 * @param skipRequestValidation specifies whether to skip the request validation and trimming
 *
 * @return the business object data availability information
 */
protected BusinessObjectDataAvailability checkBusinessObjectDataAvailabilityImpl(BusinessObjectDataAvailabilityRequest request, boolean skipRequestValidation) {
    // Perform the validation.
    if (!skipRequestValidation) {
        validateBusinessObjectDataAvailabilityRequest(request);
    }
    // Get business object format key from the request.
    BusinessObjectFormatKey businessObjectFormatKey = getBusinessObjectFormatKey(request);
    // Make sure that specified business object format exists.
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatKey);
    // Get the list of storages from the request and validate that specified storages exist.
    List<String> storageNames = getStorageNames(request);
    storageDaoHelper.validateStorageExistence(storageNames);
    // Build partition filters based on the specified partition value filters.
    // Business object data availability works across all storage platform types, so the storage platform type is not specified in the call.
    List<List<String>> partitionFilters = businessObjectDataDaoHelper.buildPartitionFilters(request.getPartitionValueFilters(), request.getPartitionValueFilter(), businessObjectFormatKey, request.getBusinessObjectDataVersion(), storageNames, null, null, businessObjectFormatEntity);
    // Retrieve a list of storage unit entities for the specified partition values. The entities will be sorted by partition value that is identified
    // by partition column position. If a business object data version isn't specified, the latest VALID business object data version is returned.
    // Business object data availability works across all storage platform types, so the storage platform type is not specified in the herdDao call.
    // We want to select only "available" storage units, so we pass "true" for selectOnlyAvailableStorageUnits parameter.
    List<StorageUnitEntity> availableStorageUnitEntities = storageUnitDao.getStorageUnitsByPartitionFiltersAndStorages(businessObjectFormatKey, partitionFilters, request.getBusinessObjectDataVersion(), BusinessObjectDataStatusEntity.VALID, storageNames, null, null, true);
    // Create business object data availability object instance and initialise it with request field values.
    BusinessObjectDataAvailability businessObjectDataAvailability = createBusinessObjectDataAvailability(request);
    // Create "available" and "not available" business object data status lists.
    List<BusinessObjectDataStatus> availableStatuses = new ArrayList<>();
    businessObjectDataAvailability.setAvailableStatuses(availableStatuses);
    List<BusinessObjectDataStatus> notAvailableStatuses = new ArrayList<>();
    businessObjectDataAvailability.setNotAvailableStatuses(notAvailableStatuses);
    // Build a list of matched available partition filters and populate the available statuses list. Please note that each request partition filter
    // might result in multiple available business object data entities. If storage names are not specified, fail on "duplicate" business object data
    // (same business object data instance registered with multiple storages). Otherwise, remove possible "duplicates".
    List<List<String>> matchedAvailablePartitionFilters = new ArrayList<>();
    List<List<String>> availablePartitions = new ArrayList<>();
    Map<BusinessObjectDataEntity, StorageUnitEntity> businessObjectDataToStorageUnitMap = new HashMap<>();
    for (StorageUnitEntity storageUnitEntity : availableStorageUnitEntities) {
        BusinessObjectDataEntity businessObjectDataEntity = storageUnitEntity.getBusinessObjectData();
        if (businessObjectDataToStorageUnitMap.containsKey(businessObjectDataEntity)) {
            // If storage names are not specified, fail on a business object data registered in multiple storages. Otherwise, ignore that storage unit.
            if (CollectionUtils.isEmpty(storageNames)) {
                throw new IllegalArgumentException(String.format("Found business object data registered in more than one storage. " + "Please specify storage(s) in the request to resolve this. Business object data {%s}", businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)));
            }
        } else {
            BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper.getBusinessObjectDataKey(businessObjectDataEntity);
            matchedAvailablePartitionFilters.add(businessObjectDataHelper.getPartitionFilter(businessObjectDataKey, partitionFilters.get(0)));
            availablePartitions.add(businessObjectDataHelper.getPrimaryAndSubPartitionValues(businessObjectDataKey));
            availableStatuses.add(createAvailableBusinessObjectDataStatus(businessObjectDataEntity));
            businessObjectDataToStorageUnitMap.put(businessObjectDataEntity, storageUnitEntity);
        }
    }
    // Check if request specifies to include all registered sub-partitions in the response.
    boolean includeAllRegisteredSubPartitions = request.getBusinessObjectDataVersion() == null && BooleanUtils.isTrue(request.isIncludeAllRegisteredSubPartitions());
    // matched partition filters one more time to discover any non-available registered sub-partitions.
    if (includeAllRegisteredSubPartitions && !CollectionUtils.isEmpty(matchedAvailablePartitionFilters)) {
        addNotAvailableBusinessObjectDataStatuses(notAvailableStatuses, businessObjectFormatKey, matchedAvailablePartitionFilters, availablePartitions, storageNames);
    }
    // Get a list of unmatched partition filters.
    List<List<String>> unmatchedPartitionFilters = new ArrayList<>(partitionFilters);
    unmatchedPartitionFilters.removeAll(matchedAvailablePartitionFilters);
    // We still need to try to retrieve business object data per list of unmatched filters regardless of business object data and/or storage unit statuses.
    // This is done to populate not-available statuses with legitimate reasons.
    // Business object data availability works across all storage platform types, so the storage platform type is not specified in the herdDao call.
    // We want to select any existing storage units regardless of their status, so we pass "false" for selectOnlyAvailableStorageUnits parameter.
    List<StorageUnitEntity> notAvailableStorageUnitEntities = storageUnitDao.getStorageUnitsByPartitionFiltersAndStorages(businessObjectFormatKey, unmatchedPartitionFilters, request.getBusinessObjectDataVersion(), null, storageNames, null, null, false);
    // Populate the not-available statuses list.
    addNotAvailableBusinessObjectDataStatuses(notAvailableStatuses, notAvailableStorageUnitEntities);
    // Build a list of matched "not-available" partition filters.
    // Please note that each request partition filter might result in multiple available business object data entities.
    List<List<String>> matchedNotAvailablePartitionFilters = getPartitionFilters(notAvailableStorageUnitEntities, partitionFilters.get(0));
    // Update the list of unmatched partition filters.
    unmatchedPartitionFilters.removeAll(matchedNotAvailablePartitionFilters);
    // Populate the "not available" statuses per remaining unmatched filters.
    for (List<String> unmatchedPartitionFilter : unmatchedPartitionFilters) {
        notAvailableStatuses.add(createNotAvailableBusinessObjectDataStatus(request, unmatchedPartitionFilter, REASON_NOT_REGISTERED));
    }
    return businessObjectDataAvailability;
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) HashMap(java.util.HashMap) BusinessObjectDataAvailability(org.finra.herd.model.api.xml.BusinessObjectDataAvailability) ArrayList(java.util.ArrayList) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) List(java.util.List) ArrayList(java.util.ArrayList) BusinessObjectDataStatus(org.finra.herd.model.api.xml.BusinessObjectDataStatus) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity)

Example 43 with StorageUnitEntity

use of org.finra.herd.model.jpa.StorageUnitEntity in project herd by FINRAOS.

the class BusinessObjectDataStorageUnitServiceImpl method createBusinessObjectDataStorageUnitImpl.

/**
 * Creates new storage unit for a given business object data and storage.
 *
 * @param request the create business object data storage unit create request
 *
 * @return the create business object data storage unit create response
 */
protected BusinessObjectDataStorageUnitCreateResponse createBusinessObjectDataStorageUnitImpl(BusinessObjectDataStorageUnitCreateRequest request) {
    // Validate the request.
    validateBusinessObjectDataStorageUnitCreateRequest(request);
    // Retrieve and validate that business object data exists.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(storageUnitHelper.getBusinessObjectDataKey(request.getBusinessObjectDataStorageUnitKey()));
    // Retrieve and validate that storage exists.
    StorageEntity storageEntity = storageDaoHelper.getStorageEntity(request.getBusinessObjectDataStorageUnitKey().getStorageName());
    // Create a storage unit entity.
    StorageUnitEntity storageUnitEntity = businessObjectDataDaoHelper.createStorageUnitEntity(businessObjectDataEntity, storageEntity, request.getStorageDirectory(), request.getStorageFiles(), request.isDiscoverStorageFiles());
    // Persist the newly created storage unit entity.
    storageUnitDao.saveAndRefresh(storageUnitEntity);
    // Construct and return the response.
    return createBusinessObjectDataStorageUnitCreateResponse(storageUnitEntity);
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) StorageEntity(org.finra.herd.model.jpa.StorageEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity)

Example 44 with StorageUnitEntity

use of org.finra.herd.model.jpa.StorageUnitEntity 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 45 with StorageUnitEntity

use of org.finra.herd.model.jpa.StorageUnitEntity 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)

Aggregations

StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)196 Test (org.junit.Test)124 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)105 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)78 StorageEntity (org.finra.herd.model.jpa.StorageEntity)57 ArrayList (java.util.ArrayList)42 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)39 StorageUnitStatusEntity (org.finra.herd.model.jpa.StorageUnitStatusEntity)36 BusinessObjectDataStorageUnitKey (org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey)30 StorageFileEntity (org.finra.herd.model.jpa.StorageFileEntity)30 StoragePolicyKey (org.finra.herd.model.api.xml.StoragePolicyKey)24 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)23 StorageFile (org.finra.herd.model.api.xml.StorageFile)22 Predicate (javax.persistence.criteria.Predicate)19 BusinessObjectDataStatusEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusEntity)19 HashMap (java.util.HashMap)18 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)17 StoragePolicySelection (org.finra.herd.model.dto.StoragePolicySelection)16 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)15 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)14