Search in sources :

Example 6 with ObjectNotFoundException

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

the class StorageUnitDaoHelperTest method testGetStorageUnitEntityByKeyStorageUnitNoExists.

@Test
public void testGetStorageUnitEntityByKeyStorageUnitNoExists() {
    // Create a business object data key.
    BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION);
    // Create a storage unit key.
    BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey = new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME);
    // Mock the external calls.
    when(storageUnitDao.getStorageUnitByKey(businessObjectDataStorageUnitKey)).thenReturn(null);
    // Try to call the method under test.
    try {
        storageUnitDaoHelper.getStorageUnitEntityByKey(businessObjectDataStorageUnitKey);
        fail();
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Business object data storage unit {%s, storageName: \"%s\"} doesn't exist.", businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataKeyAsString(businessObjectDataKey), STORAGE_NAME), e.getMessage());
    }
    // Verify the external calls.
    verify(storageUnitDao).getStorageUnitByKey(businessObjectDataStorageUnitKey);
    verifyNoMoreInteractionsHelper();
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 7 with ObjectNotFoundException

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

the class StorageFileHelperTest method testValidateRegisteredS3FilesActualFileNoExists.

@Test
public void testValidateRegisteredS3FilesActualFileNoExists() throws IOException {
    // Create two lists of expected and actual storage files, with one expected file not being added to the list of actual files.
    List<StorageFile> testExpectedFiles = Arrays.asList(new StorageFile(TARGET_S3_KEY, FILE_SIZE, ROW_COUNT_1000));
    List<S3ObjectSummary> testActualFiles = new ArrayList<>();
    // Try to validate S3 files when expected S3 file does not exist.
    try {
        storageFileHelper.validateRegisteredS3Files(testExpectedFiles, testActualFiles, STORAGE_NAME, new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION));
        fail("Should throw an ObjectNotFoundException when the registered S3 file does not exist.");
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Registered file \"%s\" does not exist in \"%s\" storage.", TARGET_S3_KEY, STORAGE_NAME), e.getMessage());
    }
}
Also used : ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) StorageFile(org.finra.herd.model.api.xml.StorageFile) ArrayList(java.util.ArrayList) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 8 with ObjectNotFoundException

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

the class EmrPricingHelperTest method testBestPriceAlgorithmicMaxSearchPriceTooLowAndSpotPriceNotAvailable.

/**
 * Tests algorithmic case when the max search price is lower than on-demand price and spot price is not available. The update method should throw an error
 * indicating that no subnets satisfied the given criteria.
 */
@Test
public void testBestPriceAlgorithmicMaxSearchPriceTooLowAndSpotPriceNotAvailable() {
    String subnetId = SUBNET_1;
    // For master instance definition, use instance type that does not have spot price available.
    MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition();
    masterInstanceDefinition.setInstanceCount(1);
    masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_4);
    masterInstanceDefinition.setInstanceMaxSearchPrice(ON_DEMAND_LESS_ONE);
    InstanceDefinition coreInstanceDefinition = null;
    InstanceDefinition taskInstanceDefinition = null;
    // Try with master failing criteria
    try {
        updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition);
        fail();
    } catch (ObjectNotFoundException e) {
        // Set expected EMR VPC price state.
        EmrVpcPricingState expectedEmrVpcPricingState = new EmrVpcPricingState();
        expectedEmrVpcPricingState.setSubnetAvailableIpAddressCounts(new HashMap<String, Integer>() {

            {
                put(SUBNET_1, 10);
            }
        });
        expectedEmrVpcPricingState.setSpotPricesPerAvailabilityZone(new HashMap<String, Map<String, BigDecimal>>() {

            {
                put(AVAILABILITY_ZONE_1, new HashMap<>());
            }
        });
        expectedEmrVpcPricingState.setOnDemandPricesPerAvailabilityZone(new HashMap<String, Map<String, BigDecimal>>() {

            {
                put(AVAILABILITY_ZONE_1, new HashMap<String, BigDecimal>() {

                    {
                        put(INSTANCE_TYPE_4, ON_DEMAND);
                    }
                });
            }
        });
        assertEquals(String.format("There were no subnets which satisfied your best price search criteria. If you explicitly opted to use spot EC2 instances, please confirm " + "that your instance types support spot pricing. Otherwise, try setting the max price or the on-demand threshold to a higher value.%n%s", emrVpcPricingStateFormatter.format(expectedEmrVpcPricingState)), e.getMessage());
    }
}
Also used : InstanceDefinition(org.finra.herd.model.api.xml.InstanceDefinition) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) EmrVpcPricingState(org.finra.herd.model.dto.EmrVpcPricingState) HashMap(java.util.HashMap) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 9 with ObjectNotFoundException

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

the class EmrPricingHelperTest method testBestPriceAlgorithmicMaxSearchPriceTooLow.

/**
 * Tests algorithmic case when the max search price is lower than both spot and on-demand price. The update method should throw an error indicating that no
 * subnets satisfied the given criteria.
 * <p/>
 * Test case reference ClusterSpotPriceAlgorithm 3
 */
@Test
public void testBestPriceAlgorithmicMaxSearchPriceTooLow() {
    String subnetId = SUBNET_1;
    MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition();
    masterInstanceDefinition.setInstanceCount(1);
    masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_1);
    masterInstanceDefinition.setInstanceMaxSearchPrice(SPOT_PRICE_LOW_LESS_ONE);
    InstanceDefinition coreInstanceDefinition = new InstanceDefinition();
    coreInstanceDefinition.setInstanceCount(1);
    coreInstanceDefinition.setInstanceType(INSTANCE_TYPE_1);
    coreInstanceDefinition.setInstanceMaxSearchPrice(SPOT_PRICE_LOW_LESS_ONE);
    InstanceDefinition taskInstanceDefinition = new InstanceDefinition();
    taskInstanceDefinition.setInstanceCount(1);
    taskInstanceDefinition.setInstanceType(INSTANCE_TYPE_1);
    taskInstanceDefinition.setInstanceMaxSearchPrice(SPOT_PRICE_LOW_LESS_ONE);
    // Try with both master, core, and task failing criteria
    try {
        updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition);
        fail("Expected ObjectNotFoundException, but no exception was thrown");
    } catch (Exception e) {
        assertEquals("thrown exception", ObjectNotFoundException.class, e.getClass());
    }
    // Now try with only core and task failing criteria
    masterInstanceDefinition.setInstanceMaxSearchPrice(ON_DEMAND);
    try {
        updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition);
        fail("Expected ObjectNotFoundException, but no exception was thrown");
    } catch (Exception e) {
        assertEquals("thrown exception", ObjectNotFoundException.class, e.getClass());
    }
    // Try with only task failing criteria
    coreInstanceDefinition.setInstanceMaxSearchPrice(ON_DEMAND);
    try {
        updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition);
        fail("Expected ObjectNotFoundException, but no exception was thrown");
    } catch (Exception e) {
        assertEquals("thrown exception", ObjectNotFoundException.class, e.getClass());
    }
}
Also used : InstanceDefinition(org.finra.herd.model.api.xml.InstanceDefinition) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AmazonServiceException(com.amazonaws.AmazonServiceException) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 10 with ObjectNotFoundException

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

the class EmrPricingHelperTest method testBestPriceSubnetNotFound.

/**
 * Tests case where at least one user specified subnet does not exist. This is a user error.
 */
@Test
public void testBestPriceSubnetNotFound() {
    String subnetId = "I_DO_NOT_EXIST," + SUBNET_1;
    MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition();
    masterInstanceDefinition.setInstanceCount(1);
    masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_1);
    InstanceDefinition coreInstanceDefinition = new InstanceDefinition();
    coreInstanceDefinition.setInstanceCount(1);
    coreInstanceDefinition.setInstanceType(INSTANCE_TYPE_1);
    InstanceDefinition taskInstanceDefinition = null;
    try {
        updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition);
        fail("expected ObjectNotFoundException, but no exception was thrown");
    } catch (Exception e) {
        assertEquals("thrown exception", ObjectNotFoundException.class, e.getClass());
    }
}
Also used : InstanceDefinition(org.finra.herd.model.api.xml.InstanceDefinition) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) MasterInstanceDefinition(org.finra.herd.model.api.xml.MasterInstanceDefinition) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AmazonServiceException(com.amazonaws.AmazonServiceException) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

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