use of org.finra.herd.model.api.xml.StorageUnit in project herd by FINRAOS.
the class StorageFileHelperTest method testValidateStorageUnitS3FilesRegisteredFileNoExists.
@Test
public void testValidateStorageUnitS3FilesRegisteredFileNoExists() throws IOException {
StorageUnit storageUnit = createStorageUnit(TEST_S3_KEY_PREFIX, LOCAL_FILES, FILE_SIZE_1_KB);
List<String> actualS3Files = new ArrayList<>();
// Try to validate S3 files when actual S3 files do not exist.
try {
storageFileHelper.validateStorageUnitS3Files(storageUnit, actualS3Files, TEST_S3_KEY_PREFIX);
fail("Should throw a RuntimeException when actual S3 files do not exist.");
} catch (RuntimeException e) {
String expectedErrMsg = String.format("Registered file \"%s\" does not exist in \"%s\" storage.", storageUnit.getStorageFiles().get(0).getFilePath(), storageUnit.getStorage().getName());
assertEquals(expectedErrMsg, e.getMessage());
}
}
use of org.finra.herd.model.api.xml.StorageUnit in project herd by FINRAOS.
the class BusinessObjectDataHelperTest method getStorageUnitByStorageName.
@Test
public void getStorageUnitByStorageName() {
// Create business object data with several test storage units.
BusinessObjectData businessObjectData = new BusinessObjectData();
List<String> testStorageNames = Arrays.asList("Storage_1", "storage-2", "STORAGE3");
List<StorageUnit> storageUnits = new ArrayList<>();
businessObjectData.setStorageUnits(storageUnits);
for (String testStorageName : testStorageNames) {
StorageUnit storageUnit = new StorageUnit();
storageUnits.add(storageUnit);
Storage storage = new Storage();
storageUnit.setStorage(storage);
storage.setName(testStorageName);
}
// Validate that we can find all storage units regardless of the storage name case.
for (String testStorageName : testStorageNames) {
assertEquals(testStorageName, businessObjectDataHelper.getStorageUnitByStorageName(businessObjectData, testStorageName).getStorage().getName());
assertEquals(testStorageName, businessObjectDataHelper.getStorageUnitByStorageName(businessObjectData, testStorageName.toUpperCase()).getStorage().getName());
assertEquals(testStorageName, businessObjectDataHelper.getStorageUnitByStorageName(businessObjectData, testStorageName.toLowerCase()).getStorage().getName());
}
}
use of org.finra.herd.model.api.xml.StorageUnit in project herd by FINRAOS.
the class RelationalTableRegistrationServiceTest method testCreateRelationalTableRegistrationWithAppendToExistingBusinessObjectDefinitionSetToTrue.
@Test
public void testCreateRelationalTableRegistrationWithAppendToExistingBusinessObjectDefinitionSetToTrue() {
// Create an existing business object definition.
BusinessObjectDefinitionEntity existingBusinessObjectDefinitionEntity = businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(BDEF_NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, DESCRIPTION, BDEF_DISPLAY_NAME, new ArrayList<>());
// Create database entities required for relational table registration testing.
relationalTableRegistrationServiceTestHelper.createDatabaseEntitiesForRelationalTableRegistrationTesting(STORAGE_NAME);
// Pick one of the in-memory database tables to be registered as a relational table.
String relationalSchemaName = "PUBLIC";
String relationalTableName = BusinessObjectDefinitionEntity.TABLE_NAME.toUpperCase();
// Create a relational table registration create request for a table that is part of the in-memory database setup as part of DAO mocks.
RelationalTableRegistrationCreateRequest relationalTableRegistrationCreateRequest = new RelationalTableRegistrationCreateRequest(BDEF_NAMESPACE, BDEF_NAME, BDEF_DISPLAY_NAME, FORMAT_USAGE_CODE, DATA_PROVIDER_NAME, relationalSchemaName, relationalTableName, STORAGE_NAME);
// Create a relational table registration.
BusinessObjectData businessObjectData = relationalTableRegistrationService.createRelationalTableRegistration(relationalTableRegistrationCreateRequest, APPEND_TO_EXISTING_BUSINESS_OBJECT_DEFINTION_TRUE);
// Create an expected storage unit.
StorageUnit expectedStorageUnit = new StorageUnit();
expectedStorageUnit.setStorage(new Storage(STORAGE_NAME, StoragePlatformEntity.RELATIONAL, relationalTableRegistrationServiceTestHelper.getStorageAttributes()));
expectedStorageUnit.setStorageUnitStatus(StorageUnitStatusEntity.ENABLED);
// Create an expected business object data.
BusinessObjectData expectedBusinessObjectData = new BusinessObjectData();
expectedBusinessObjectData.setId(businessObjectData.getId());
expectedBusinessObjectData.setNamespace(BDEF_NAMESPACE);
expectedBusinessObjectData.setBusinessObjectDefinitionName(BDEF_NAME);
expectedBusinessObjectData.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE);
expectedBusinessObjectData.setBusinessObjectFormatFileType(FileTypeEntity.RELATIONAL_TABLE_FILE_TYPE);
expectedBusinessObjectData.setBusinessObjectFormatVersion(INITIAL_FORMAT_VERSION);
expectedBusinessObjectData.setPartitionValue(BusinessObjectDataServiceImpl.NO_PARTITIONING_PARTITION_VALUE);
expectedBusinessObjectData.setSubPartitionValues(new ArrayList<>());
expectedBusinessObjectData.setVersion(INITIAL_DATA_VERSION);
expectedBusinessObjectData.setPartitionKey(BusinessObjectDataServiceImpl.NO_PARTITIONING_PARTITION_KEY);
expectedBusinessObjectData.setLatestVersion(LATEST_VERSION_FLAG_SET);
expectedBusinessObjectData.setStatus(BusinessObjectDataStatusEntity.VALID);
expectedBusinessObjectData.setStorageUnits(Collections.singletonList(expectedStorageUnit));
expectedBusinessObjectData.setAttributes(new ArrayList<>());
expectedBusinessObjectData.setBusinessObjectDataParents(new ArrayList<>());
expectedBusinessObjectData.setBusinessObjectDataChildren(new ArrayList<>());
// Validate the response.
assertEquals(expectedBusinessObjectData, businessObjectData);
// Create a business object format key.
BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FileTypeEntity.RELATIONAL_TABLE_FILE_TYPE, INITIAL_FORMAT_VERSION);
// Retrieve business object format that was created as part of the relational table registration.
BusinessObjectFormat businessObjectFormat = businessObjectFormatService.getBusinessObjectFormat(businessObjectFormatKey);
// Create an expected schema.
Schema expectedSchema = new Schema();
expectedSchema.setColumns(relationalTableRegistrationServiceTestHelper.getExpectedSchemaColumns());
expectedSchema.setNullValue(EMPTY_STRING);
// Build an expected business object format.
BusinessObjectFormat expectedBusinessObjectFormat = new BusinessObjectFormat();
expectedBusinessObjectFormat.setId(businessObjectFormat.getId());
expectedBusinessObjectFormat.setNamespace(BDEF_NAMESPACE);
expectedBusinessObjectFormat.setBusinessObjectDefinitionName(BDEF_NAME);
expectedBusinessObjectFormat.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE);
expectedBusinessObjectFormat.setBusinessObjectFormatFileType(FileTypeEntity.RELATIONAL_TABLE_FILE_TYPE);
expectedBusinessObjectFormat.setBusinessObjectFormatVersion(INITIAL_FORMAT_VERSION);
expectedBusinessObjectFormat.setLatestVersion(LATEST_VERSION_FLAG_SET);
expectedBusinessObjectFormat.setPartitionKey(BusinessObjectDataServiceImpl.NO_PARTITIONING_PARTITION_KEY);
expectedBusinessObjectFormat.setBusinessObjectFormatParents(new ArrayList<>());
expectedBusinessObjectFormat.setBusinessObjectFormatChildren(new ArrayList<>());
expectedBusinessObjectFormat.setAttributeDefinitions(new ArrayList<>());
expectedBusinessObjectFormat.setAttributes(Arrays.asList(new Attribute(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_FORMAT_ATTRIBUTE_NAME_RELATIONAL_SCHEMA_NAME), relationalSchemaName), new Attribute(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_FORMAT_ATTRIBUTE_NAME_RELATIONAL_TABLE_NAME), relationalTableName)));
expectedBusinessObjectFormat.setSchema(expectedSchema);
// Validate the newly created business object format.
assertEquals(expectedBusinessObjectFormat, businessObjectFormat);
// Create a business object definition key.
BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME);
// Retrieve business object definition that was created as part of the relational table registration.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDao.getBusinessObjectDefinitionByKey(businessObjectDefinitionKey);
// Validate the newly created business object definition.
assertEquals(existingBusinessObjectDefinitionEntity, businessObjectDefinitionEntity);
}
use of org.finra.herd.model.api.xml.StorageUnit 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;
}
use of org.finra.herd.model.api.xml.StorageUnit in project herd by FINRAOS.
the class BusinessObjectDataInvalidateUnregisteredHelperTest method testInvalidateUnregisteredBusinessObjectDataS32Herd1.
/**
* Test case where S3 has 2 objects, and herd has 1 object registered. Expects one new registration in INVALID status.
*/
@Test
public void testInvalidateUnregisteredBusinessObjectDataS32Herd1() throws Exception {
BusinessObjectDataInvalidateUnregisteredRequest request = new BusinessObjectDataInvalidateUnregisteredRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, StorageEntity.MANAGED_STORAGE);
// Given a business object format
// Given 1 business object data registered
// Given 2 S3 objects
BusinessObjectFormatEntity businessObjectFormatEntity;
try {
businessObjectFormatEntity = businessObjectFormatServiceTestHelper.createBusinessObjectFormat(request);
createBusinessObjectDataEntityFromBusinessObjectDataInvalidateUnregisteredRequest(businessObjectFormatEntity, request, 0, true);
businessObjectDataServiceTestHelper.createS3Object(businessObjectFormatEntity, request, 0);
businessObjectDataServiceTestHelper.createS3Object(businessObjectFormatEntity, request, 1);
} catch (Exception e) {
throw new IllegalArgumentException("Test failed during setup. Most likely setup or developer error.", e);
}
// Call API
BusinessObjectDataInvalidateUnregisteredResponse actualResponse = businessObjectDataInvalidateUnregisteredHelper.invalidateUnregisteredBusinessObjectData(request);
// Make assertions
Assert.assertNotNull("response business object datas is null", actualResponse.getRegisteredBusinessObjectDataList());
Assert.assertEquals("response business object datas size", 1, actualResponse.getRegisteredBusinessObjectDataList().size());
{
BusinessObjectData businessObjectData = actualResponse.getRegisteredBusinessObjectDataList().get(0);
Assert.assertEquals("response business object data[0] version", 1, businessObjectData.getVersion());
Assert.assertEquals("response business object data[0] status", BusinessObjectDataInvalidateUnregisteredHelper.UNREGISTERED_STATUS, businessObjectData.getStatus());
Assert.assertNotNull("response business object data[0] storage units is null", businessObjectData.getStorageUnits());
Assert.assertEquals("response business object data[0] storage units size", 1, businessObjectData.getStorageUnits().size());
{
String expectedS3KeyPrefix = s3KeyPrefixHelper.buildS3KeyPrefix(S3_KEY_PREFIX_VELOCITY_TEMPLATE, businessObjectFormatEntity, businessObjectDataHelper.createBusinessObjectDataKey(businessObjectData), STORAGE_NAME);
StorageUnit storageUnit = businessObjectData.getStorageUnits().get(0);
Assert.assertNotNull("response business object data[0] storage unit[0] storage directory is null", storageUnit.getStorageDirectory());
Assert.assertEquals("response business object data[0] storage unit[0] storage directory path", expectedS3KeyPrefix, storageUnit.getStorageDirectory().getDirectoryPath());
}
}
}
Aggregations