Search in sources :

Example 6 with StorageAttributeEntity

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

the class StorageServiceTest method testUpdateStorageAttributesStorageHasDuplicateAttributes.

@Test
public void testUpdateStorageAttributesStorageHasDuplicateAttributes() {
    // Create and persist a valid storage.
    StorageCreateRequest request = getNewStorageCreateRequest();
    Storage storage = storageService.createStorage(request);
    // Add a duplicate attribute to the storage.
    StorageEntity storageEntity = storageDao.getStorageByName(storage.getName());
    StorageAttributeEntity storageAttributeEntity = new StorageAttributeEntity();
    storageAttributeEntity.setStorage(storageEntity);
    storageAttributeEntity.setName(request.getAttributes().get(0).getName().toUpperCase());
    storageEntity.getAttributes().add(storageAttributeEntity);
    storageDao.saveAndRefresh(storageEntity);
    // Try to update attributes for the storage.
    try {
        storageService.updateStorageAttributes(new StorageKey(storage.getName()), new StorageAttributesUpdateRequest(businessObjectDefinitionServiceTestHelper.getNewAttributes2()));
    } catch (IllegalStateException e) {
        assertEquals(String.format("Found duplicate attribute with name \"%s\" for \"%s\" storage.", request.getAttributes().get(0).getName().toLowerCase(), storage.getName()), e.getMessage());
    }
}
Also used : Storage(org.finra.herd.model.api.xml.Storage) StorageAttributeEntity(org.finra.herd.model.jpa.StorageAttributeEntity) StorageAttributesUpdateRequest(org.finra.herd.model.api.xml.StorageAttributesUpdateRequest) StorageEntity(org.finra.herd.model.jpa.StorageEntity) StorageCreateRequest(org.finra.herd.model.api.xml.StorageCreateRequest) StorageKey(org.finra.herd.model.api.xml.StorageKey) Test(org.junit.Test)

Example 7 with StorageAttributeEntity

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

the class StorageDaoTestHelper method getBucketNameFromStorage.

/**
 * Returns the bucket name of the specified storage name.
 * <p/>
 * Gets the storage with specified name and finds and returns the value of the attribute for the bucket name.
 *
 * @param storageName the name of the storage to get the bucket name for.
 *
 * @return S3 bucket name
 * @throws IllegalStateException when either the storage or attribute is not found.
 */
private String getBucketNameFromStorage(String storageName) {
    String s3BucketName = null;
    StorageEntity storageEntity = storageDao.getStorageByName(storageName);
    if (storageEntity == null) {
        throw new IllegalStateException("storageEntity \"" + storageName + "\" not found");
    }
    for (StorageAttributeEntity storageAttributeEntity : storageEntity.getAttributes()) {
        if (configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME).equals(storageAttributeEntity.getName())) {
            s3BucketName = storageAttributeEntity.getValue();
            break;
        }
    }
    if (s3BucketName == null) {
        throw new IllegalStateException("storageAttributeEntity with name " + configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME) + " not found for storage \"" + storageName + "\".");
    }
    return s3BucketName;
}
Also used : StorageAttributeEntity(org.finra.herd.model.jpa.StorageAttributeEntity) StorageEntity(org.finra.herd.model.jpa.StorageEntity)

Example 8 with StorageAttributeEntity

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

the class StorageUnitHelper method createStorageUnitsFromEntities.

/**
 * Creates a list of storage units from the list of storage unit entities.
 *
 * @param storageUnitEntities the storage unit entities.
 * @param includeStorageUnitStatusHistory specifies to include storage unit status history for each storage unit in the response
 *
 * @return the list of storage units.
 */
public List<StorageUnit> createStorageUnitsFromEntities(Collection<StorageUnitEntity> storageUnitEntities, Boolean includeStorageUnitStatusHistory) {
    List<StorageUnit> storageUnits = new ArrayList<>();
    for (StorageUnitEntity storageUnitEntity : storageUnitEntities) {
        StorageUnit storageUnit = new StorageUnit();
        storageUnits.add(storageUnit);
        Storage storage = new Storage();
        storageUnit.setStorage(storage);
        StorageEntity storageEntity = storageUnitEntity.getStorage();
        storage.setName(storageEntity.getName());
        storage.setStoragePlatformName(storageEntity.getStoragePlatform().getName());
        // Add the storage attributes.
        if (!CollectionUtils.isEmpty(storageEntity.getAttributes())) {
            List<Attribute> storageAttributes = new ArrayList<>();
            storage.setAttributes(storageAttributes);
            for (StorageAttributeEntity storageAttributeEntity : storageEntity.getAttributes()) {
                Attribute attribute = new Attribute();
                storageAttributes.add(attribute);
                attribute.setName(storageAttributeEntity.getName());
                attribute.setValue(storageAttributeEntity.getValue());
            }
        }
        // Add the storage directory.
        if (storageUnitEntity.getDirectoryPath() != null) {
            StorageDirectory storageDirectory = new StorageDirectory();
            storageUnit.setStorageDirectory(storageDirectory);
            storageDirectory.setDirectoryPath(storageUnitEntity.getDirectoryPath());
        }
        // Add the storage files.
        if (!storageUnitEntity.getStorageFiles().isEmpty()) {
            List<StorageFile> storageFiles = new ArrayList<>();
            storageUnit.setStorageFiles(storageFiles);
            for (StorageFileEntity storageFileEntity : storageUnitEntity.getStorageFiles()) {
                storageFiles.add(storageFileHelper.createStorageFileFromEntity(storageFileEntity));
            }
        }
        // Set the storage unit status.
        storageUnit.setStorageUnitStatus(storageUnitEntity.getStatus().getCode());
        // If specified, add storage unit status history.
        if (BooleanUtils.isTrue(includeStorageUnitStatusHistory)) {
            List<StorageUnitStatusChangeEvent> storageUnitStatusChangeEvents = new ArrayList<>();
            storageUnit.setStorageUnitStatusHistory(storageUnitStatusChangeEvents);
            for (StorageUnitStatusHistoryEntity storageUnitStatusHistoryEntity : storageUnitEntity.getHistoricalStatuses()) {
                storageUnitStatusChangeEvents.add(new StorageUnitStatusChangeEvent(storageUnitStatusHistoryEntity.getStatus().getCode(), HerdDateUtils.getXMLGregorianCalendarValue(storageUnitStatusHistoryEntity.getCreatedOn()), storageUnitStatusHistoryEntity.getCreatedBy()));
            }
        }
        // Set the number of failed attempts to execute a storage policy transition.
        storageUnit.setStoragePolicyTransitionFailedAttempts(storageUnitEntity.getStoragePolicyTransitionFailedAttempts());
        if (storageUnitEntity.getRestoreExpirationOn() != null) {
            storageUnit.setRestoreExpirationOn(HerdDateUtils.getXMLGregorianCalendarValue(storageUnitEntity.getRestoreExpirationOn()));
        }
    }
    return storageUnits;
}
Also used : StorageUnitStatusChangeEvent(org.finra.herd.model.api.xml.StorageUnitStatusChangeEvent) StorageUnitStatusHistoryEntity(org.finra.herd.model.jpa.StorageUnitStatusHistoryEntity) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) Attribute(org.finra.herd.model.api.xml.Attribute) StorageAttributeEntity(org.finra.herd.model.jpa.StorageAttributeEntity) ArrayList(java.util.ArrayList) StorageUnit(org.finra.herd.model.api.xml.StorageUnit) StorageEntity(org.finra.herd.model.jpa.StorageEntity) StorageDirectory(org.finra.herd.model.api.xml.StorageDirectory) Storage(org.finra.herd.model.api.xml.Storage) StorageFileEntity(org.finra.herd.model.jpa.StorageFileEntity) StorageFile(org.finra.herd.model.api.xml.StorageFile)

Aggregations

StorageAttributeEntity (org.finra.herd.model.jpa.StorageAttributeEntity)8 StorageEntity (org.finra.herd.model.jpa.StorageEntity)5 ArrayList (java.util.ArrayList)4 Attribute (org.finra.herd.model.api.xml.Attribute)4 Storage (org.finra.herd.model.api.xml.Storage)2 HashMap (java.util.HashMap)1 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)1 StorageAttributesUpdateRequest (org.finra.herd.model.api.xml.StorageAttributesUpdateRequest)1 StorageCreateRequest (org.finra.herd.model.api.xml.StorageCreateRequest)1 StorageDirectory (org.finra.herd.model.api.xml.StorageDirectory)1 StorageFile (org.finra.herd.model.api.xml.StorageFile)1 StorageKey (org.finra.herd.model.api.xml.StorageKey)1 StorageUnit (org.finra.herd.model.api.xml.StorageUnit)1 StorageUnitStatusChangeEvent (org.finra.herd.model.api.xml.StorageUnitStatusChangeEvent)1 StorageFileEntity (org.finra.herd.model.jpa.StorageFileEntity)1 StoragePlatformEntity (org.finra.herd.model.jpa.StoragePlatformEntity)1 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)1 StorageUnitStatusHistoryEntity (org.finra.herd.model.jpa.StorageUnitStatusHistoryEntity)1 Test (org.junit.Test)1