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());
}
}
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;
}
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;
}
Aggregations