Search in sources :

Example 36 with ObjectNotFoundException

use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.

the class StorageFileHelper method validateS3Files.

/**
 * Validates S3 files per list of expected storage files.
 *
 * @param expectedStorageFiles the list of expected S3 files represented by storage files
 * @param actualS3Files the list of actual S3 files represented by S3 object summaries
 * @param storageName the storage name
 * @param businessObjectDataKey the business object data key
 * @param fileDescription the file description (i.e. "registered" or "copied") to be used in the relative error messages
 */
private void validateS3Files(List<StorageFile> expectedStorageFiles, List<S3ObjectSummary> actualS3Files, String storageName, BusinessObjectDataKey businessObjectDataKey, String fileDescription) {
    // Load all actual S3 files into a map for easy access.
    Map<String, StorageFile> actualFilesMap = getStorageFilesMapFromS3ObjectSummaries(actualS3Files);
    // Validate existence and file size for all expected files.
    for (StorageFile expectedFile : expectedStorageFiles) {
        if (!actualFilesMap.containsKey(expectedFile.getFilePath())) {
            throw new ObjectNotFoundException(String.format("%s file \"%s\" does not exist in \"%s\" storage.", StringUtils.capitalize(fileDescription), expectedFile.getFilePath(), storageName));
        } else {
            // Validate the file size.
            StorageFile actualFile = actualFilesMap.get(expectedFile.getFilePath());
            if (!Objects.equals(actualFile.getFileSizeBytes(), expectedFile.getFileSizeBytes())) {
                throw new IllegalStateException(String.format("Specified file size of %d bytes for %s \"%s\" S3 file in \"%s\" storage does not match file size of %d bytes reported by S3.", expectedFile.getFileSizeBytes(), fileDescription, expectedFile.getFilePath(), storageName, actualFile.getFileSizeBytes()));
            }
        }
    }
    // Get a list of actual S3 file paths.
    List<String> actualFilePaths = new ArrayList<>(actualFilesMap.keySet());
    // Get a list of expected file paths.
    List<String> expectedFilePaths = getFilePathsFromStorageFiles(expectedStorageFiles);
    // Validate that no other files in S3 bucket except for expected files have the same S3 key prefix.
    if (!expectedFilePaths.containsAll(actualFilePaths)) {
        actualFilePaths.removeAll(expectedFilePaths);
        throw new IllegalStateException(String.format("Found unexpected S3 file \"%s\" in \"%s\" storage while validating %s S3 files. Business object data {%s}", actualFilePaths.get(0), storageName, fileDescription, businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)));
    }
}
Also used : ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) StorageFile(org.finra.herd.model.api.xml.StorageFile) ArrayList(java.util.ArrayList)

Example 37 with ObjectNotFoundException

use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.

the class SampleDataJmsMessageListener method processMessage.

/**
 * Processes a JMS message.
 *
 * @param payload the message payload
 * @param allHeaders the JMS headers
 */
@JmsListener(id = HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE, containerFactory = "jmsListenerContainerFactory", destination = HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE)
public void processMessage(String payload, @Headers Map<Object, Object> allHeaders) {
    LOGGER.info("Message received from the JMS queue. jmsQueueName=\"{}\" jmsMessageHeaders=\"{}\" jmsMessagePayload={}", HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE, allHeaders, payload);
    try {
        // Process messages coming from S3 bucket.
        S3EventNotification s3EventNotification = S3EventNotification.parseJson(payload);
        String objectKey = URLDecoder.decode(s3EventNotification.getRecords().get(0).getS3().getObject().getKey(), CharEncoding.UTF_8);
        long fileSize = s3EventNotification.getRecords().get(0).getS3().getObject().getSizeAsLong();
        // parse the objectKey, it should be in the format of namespace/businessObjectDefinitionName/fileName
        String[] objectKeyArrays = objectKey.split("/");
        Assert.isTrue(objectKeyArrays.length == 3, String.format("S3 notification message %s is not in expected format", objectKey));
        String namespace = objectKeyArrays[0];
        String businessObjectDefinitionName = objectKeyArrays[1];
        String fileName = objectKeyArrays[2];
        String path = namespace + "/" + businessObjectDefinitionName + "/";
        BusinessObjectDefinitionSampleFileUpdateDto businessObjectDefinitionSampleFileUpdateDto = new BusinessObjectDefinitionSampleFileUpdateDto(path, fileName, fileSize);
        String convertedNamespaece = convertS3KeyFormat(namespace);
        String convertedBusinessObjectDefinitionName = convertS3KeyFormat(businessObjectDefinitionName);
        BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(convertedNamespaece, convertedBusinessObjectDefinitionName);
        try {
            businessObjectDefinitionService.updateBusinessObjectDefinitionEntitySampleFile(businessObjectDefinitionKey, businessObjectDefinitionSampleFileUpdateDto);
        } catch (ObjectNotFoundException ex) {
            LOGGER.info("Failed to find the business object definition, next try the original namespace and business oject defination name " + ex);
            // if Business object definition is not found, use the original name space and bdef name
            businessObjectDefinitionKey = new BusinessObjectDefinitionKey(namespace, businessObjectDefinitionName);
            businessObjectDefinitionService.updateBusinessObjectDefinitionEntitySampleFile(businessObjectDefinitionKey, businessObjectDefinitionSampleFileUpdateDto);
        }
    } catch (RuntimeException | IOException e) {
        LOGGER.error("Failed to process message from the JMS queue. jmsQueueName=\"{}\" jmsMessagePayload={}", HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE, payload, e);
    }
}
Also used : S3EventNotification(com.amazonaws.services.s3.event.S3EventNotification) BusinessObjectDefinitionSampleFileUpdateDto(org.finra.herd.model.dto.BusinessObjectDefinitionSampleFileUpdateDto) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) IOException(java.io.IOException) JmsListener(org.springframework.jms.annotation.JmsListener)

Example 38 with ObjectNotFoundException

use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.

the class BusinessObjectFormatServiceTest method testGenerateBusinessObjectFormatDdlInvalidParameters.

@Test
public void testGenerateBusinessObjectFormatDdlInvalidParameters() {
    // Prepare test data.
    businessObjectFormatServiceTestHelper.createDatabaseEntitiesForBusinessObjectFormatDdlTesting();
    BusinessObjectFormatDdlRequest request;
    // Try to retrieve business object format ddl using non-existing format.
    request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(CUSTOM_DDL_NAME);
    request.setBusinessObjectDefinitionName("I_DO_NOT_EXIST");
    try {
        businessObjectFormatService.generateBusinessObjectFormatDdl(request);
        fail("Should throw an ObjectNotFoundException when non-existing business object format is used.");
    } catch (ObjectNotFoundException e) {
        assertEquals(businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatNotFoundErrorMessage(request.getNamespace(), request.getBusinessObjectDefinitionName(), request.getBusinessObjectFormatUsage(), request.getBusinessObjectFormatFileType(), request.getBusinessObjectFormatVersion()), e.getMessage());
    }
    // Try to retrieve business object format ddl using non-existing custom ddl.
    request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(CUSTOM_DDL_NAME);
    request.setCustomDdlName("I_DO_NOT_EXIST");
    try {
        businessObjectFormatService.generateBusinessObjectFormatDdl(request);
        fail("Should throw an ObjectNotFoundException when non-existing custom ddl is used.");
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Custom DDL with name \"%s\" does not exist for business object format with namespace \"%s\", " + "business object definition name \"%s\", format usage \"%s\", format file type \"%s\", and format version \"%d\".", request.getCustomDdlName(), request.getNamespace(), request.getBusinessObjectDefinitionName(), request.getBusinessObjectFormatUsage(), request.getBusinessObjectFormatFileType(), request.getBusinessObjectFormatVersion()), e.getMessage());
    }
}
Also used : ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) BusinessObjectFormatDdlRequest(org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest) Test(org.junit.Test)

Example 39 with ObjectNotFoundException

use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.

the class CustomDdlServiceTest method testUpdateCustomDdlCustomDdlNoExists.

@Test
public void testUpdateCustomDdlCustomDdlNoExists() {
    // Try to update a non-existing custom DDL.
    try {
        customDdlService.updateCustomDdl(new CustomDdlKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, CUSTOM_DDL_NAME), customDdlServiceTestHelper.createCustomDdlUpdateRequest(TEST_DDL));
        fail("Should throw an ObjectNotFoundException when custom DDL does not exist.");
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Custom DDL with name \"%s\" does not exist for business object format with namespace \"%s\", " + "business object definition name \"%s\", format usage \"%s\", format file type \"%s\", and format version \"%d\".", CUSTOM_DDL_NAME, NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION), e.getMessage());
    }
}
Also used : ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) CustomDdlKey(org.finra.herd.model.api.xml.CustomDdlKey) Test(org.junit.Test)

Example 40 with ObjectNotFoundException

use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.

the class BusinessObjectDefinitionServiceTest method testDeleteBusinessObjectDefinitionNoExists.

@Test
public void testDeleteBusinessObjectDefinitionNoExists() throws Exception {
    // Try to get a non-existing business object definition.
    try {
        businessObjectDefinitionService.deleteBusinessObjectDefinition(new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME));
        fail("Should throw an ObjectNotFoundException when business object definition doesn't exist.");
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Business object definition with name \"%s\" doesn't exist for namespace \"%s\".", BDEF_NAME, NAMESPACE), e.getMessage());
    }
}
Also used : BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) Test(org.junit.Test)

Aggregations

ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)216 Test (org.junit.Test)193 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)36 ArrayList (java.util.ArrayList)18 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)16 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)16 BusinessObjectDataAttributeKey (org.finra.herd.model.api.xml.BusinessObjectDataAttributeKey)14 PartitionValueFilter (org.finra.herd.model.api.xml.PartitionValueFilter)12 TagKey (org.finra.herd.model.api.xml.TagKey)11 NotificationRegistrationKey (org.finra.herd.model.api.xml.NotificationRegistrationKey)10 StoragePolicyKey (org.finra.herd.model.api.xml.StoragePolicyKey)10 BusinessObjectDataDdlRequest (org.finra.herd.model.api.xml.BusinessObjectDataDdlRequest)9 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)8 InstanceDefinition (org.finra.herd.model.api.xml.InstanceDefinition)7 MasterInstanceDefinition (org.finra.herd.model.api.xml.MasterInstanceDefinition)7 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)6 BusinessObjectDefinitionColumnKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionColumnKey)6 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)6 AmazonServiceException (com.amazonaws.AmazonServiceException)5 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)5