use of org.finra.herd.model.api.xml.MasterInstanceDefinition in project herd by FINRAOS.
the class EmrPricingHelperTest method testBestPriceExplicitSpotAndSpotPriceNotAvailable.
/**
* Tests algorithmic case when spot is explicitly requested and spot price is not available. The update method should throw an error indicating that no
* subnets satisfied the given criteria.
*/
@Test
public void testBestPriceExplicitSpotAndSpotPriceNotAvailable() {
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.setInstanceSpotPrice(ON_DEMAND);
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());
}
}
use of org.finra.herd.model.api.xml.MasterInstanceDefinition in project herd by FINRAOS.
the class EmrPricingHelperTest method testBestPriceSubnetError.
/**
* Tests case where the subnet retrieval throws an unexpected amazon error.
*/
@Test
public void testBestPriceSubnetError() throws Exception {
String subnetId = "throw.SomeError";
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 AmazonServiceException, but no exception was thrown");
} catch (Exception e) {
assertEquals("thrown exception", AmazonServiceException.class, e.getClass());
}
}
use of org.finra.herd.model.api.xml.MasterInstanceDefinition in project herd by FINRAOS.
the class EmrHelperTest method testIsInstanceDefinitionsEmpty.
@Test
public void testIsInstanceDefinitionsEmpty() {
assertTrue(emrHelper.isInstanceDefinitionsEmpty(null));
assertTrue(emrHelper.isInstanceDefinitionsEmpty(new InstanceDefinitions(null, null, null)));
assertFalse(emrHelper.isInstanceDefinitionsEmpty(new InstanceDefinitions(new MasterInstanceDefinition(), null, null)));
assertFalse(emrHelper.isInstanceDefinitionsEmpty(new InstanceDefinitions(null, new InstanceDefinition(), null)));
assertFalse(emrHelper.isInstanceDefinitionsEmpty(new InstanceDefinitions(null, null, new InstanceDefinition())));
}
use of org.finra.herd.model.api.xml.MasterInstanceDefinition in project herd by FINRAOS.
the class EmrDaoImplTest method testGetInstanceGroupConfigsMissingOptionalInstanceDefinitions.
@Test
public void testGetInstanceGroupConfigsMissingOptionalInstanceDefinitions() {
// Create objects required for testing.
final Integer instanceCount = 0;
final InstanceDefinitions instanceDefinitions = new InstanceDefinitions(new MasterInstanceDefinition(), null, null);
// Mock the external calls.
when(emrHelper.isInstanceDefinitionsEmpty(instanceDefinitions)).thenReturn(false);
// Call the method under test.
List<InstanceGroupConfig> result = emrDaoImpl.getInstanceGroupConfigs(instanceDefinitions);
// Verify the external calls.
verify(emrHelper).isInstanceDefinitionsEmpty(instanceDefinitions);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(Arrays.asList(new InstanceGroupConfig(InstanceRoleType.MASTER, null, instanceCount)), result);
}
use of org.finra.herd.model.api.xml.MasterInstanceDefinition in project herd by FINRAOS.
the class EmrDaoTest method createEmrClusterAssertInstallOozieDisabled.
@Test
public void createEmrClusterAssertInstallOozieDisabled() throws Exception {
/*
* Use only minimum required options
*/
String clusterName = "clusterName";
EmrClusterDefinition emrClusterDefinition = new EmrClusterDefinition();
InstanceDefinitions instanceDefinitions = new InstanceDefinitions();
instanceDefinitions.setMasterInstances(new MasterInstanceDefinition(10, "masterInstanceType", NO_EMR_CLUSTER_DEFINITION_EBS_CONFIGURATION, NO_INSTANCE_SPOT_PRICE, NO_INSTANCE_MAX_SEARCH_PRICE, NO_INSTANCE_ON_DEMAND_THRESHOLD));
instanceDefinitions.setCoreInstances(new InstanceDefinition(20, "coreInstanceType", NO_EMR_CLUSTER_DEFINITION_EBS_CONFIGURATION, NO_INSTANCE_SPOT_PRICE, NO_INSTANCE_MAX_SEARCH_PRICE, NO_INSTANCE_ON_DEMAND_THRESHOLD));
emrClusterDefinition.setInstanceDefinitions(instanceDefinitions);
emrClusterDefinition.setNodeTags(Arrays.asList(new NodeTag("tagName", "tagValue")));
emrClusterDefinition.setInstallOozie(false);
String clusterId = "clusterId";
when(mockEmrOperations.runEmrJobFlow(any(), any())).then(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
RunJobFlowRequest runJobFlowRequest = invocation.getArgument(1);
// The oozie step should be skipped.
assertEquals(0, runJobFlowRequest.getSteps().size());
return clusterId;
}
});
assertEquals(clusterId, emrDao.createEmrCluster(clusterName, emrClusterDefinition, new AwsParamsDto()));
}
Aggregations