EmrPricingHelper extends AwsHelper { public void updateEmrClusterDefinitionWithBestPrice(EmrClusterAlternateKeyDto emrClusterAlternateKeyDto, EmrClusterDefinition emrClusterDefinition, AwsParamsDto awsParamsDto) { EmrVpcPricingState emrVpcPricingState = new EmrVpcPricingState(); int totalInstanceCount = getTotalInstanceCount(emrClusterDefinition); List<Subnet> subnets = getSubnets(emrClusterDefinition, awsParamsDto); for (Subnet subnet : subnets) { emrVpcPricingState.getSubnetAvailableIpAddressCounts().put(subnet.getSubnetId(), subnet.getAvailableIpAddressCount()); } removeSubnetsWithAvailableIpsLessThan(subnets, totalInstanceCount); if (subnets.isEmpty()) { LOGGER.info(String.format("Insufficient IP availability. namespace=\"%s\" emrClusterDefinitionName=\"%s\" emrClusterName=\"%s\" " + "totalRequestedInstanceCount=%s emrVpcPricingState=%s", emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName(), emrClusterAlternateKeyDto.getEmrClusterName(), totalInstanceCount, jsonHelper.objectToJson(emrVpcPricingState))); throw new ObjectNotFoundException(String.format( "There are no subnets in the current VPC which have sufficient IP addresses available to run your " + "clusters. Try expanding the list of subnets or try again later. requestedInstanceCount=%s%n%s", totalInstanceCount, emrVpcPricingStateFormatter.format(emrVpcPricingState))); } List<EmrClusterPriceDto> emrClusterPrices = new ArrayList<>(); InstanceDefinition masterInstanceDefinition = getMasterInstanceDefinition(emrClusterDefinition); InstanceDefinition coreInstanceDefinition = getCoreInstanceDefinition(emrClusterDefinition); InstanceDefinition taskInstanceDefinition = getTaskInstanceDefinition(emrClusterDefinition); Set<String> requestedInstanceTypes = new HashSet<>(); String masterInstanceType = masterInstanceDefinition.getInstanceType(); requestedInstanceTypes.add(masterInstanceType); if (coreInstanceDefinition != null) { String coreInstanceType = coreInstanceDefinition.getInstanceType(); requestedInstanceTypes.add(coreInstanceType); } if (taskInstanceDefinition != null) { String taskInstanceType = taskInstanceDefinition.getInstanceType(); requestedInstanceTypes.add(taskInstanceType); } for (AvailabilityZone availabilityZone : getAvailabilityZones(subnets, awsParamsDto)) { Map<String, BigDecimal> instanceTypeSpotPrices = getInstanceTypeSpotPrices(availabilityZone, requestedInstanceTypes, awsParamsDto); emrVpcPricingState.getSpotPricesPerAvailabilityZone().put(availabilityZone.getZoneName(), instanceTypeSpotPrices); BigDecimal masterSpotPrice = instanceTypeSpotPrices.get(masterInstanceType); Ec2PriceDto masterPrice = getBestInstancePrice(masterSpotPrice, masterInstanceDefinition); Ec2PriceDto corePrice = null; if (coreInstanceDefinition != null) { String coreInstanceType = coreInstanceDefinition.getInstanceType(); BigDecimal coreSpotPrice = instanceTypeSpotPrices.get(coreInstanceType); corePrice = getBestInstancePrice(coreSpotPrice, coreInstanceDefinition); } Ec2PriceDto taskPrice = null; if (taskInstanceDefinition != null) { String taskInstanceType = taskInstanceDefinition.getInstanceType(); BigDecimal taskSpotPrice = instanceTypeSpotPrices.get(taskInstanceType); taskPrice = getBestInstancePrice(taskSpotPrice, taskInstanceDefinition); } if (masterPrice != null && (coreInstanceDefinition == null || corePrice != null) && (taskInstanceDefinition == null || taskPrice != null)) { emrClusterPrices.add(createEmrClusterPrice(availabilityZone, masterPrice, corePrice, taskPrice)); } } if (emrClusterPrices.isEmpty()) { LOGGER.info(String.format("No subnets which satisfied the best price search criteria. namespace=\"%s\" emrClusterDefinitionName=\"%s\" " + "emrClusterName=\"%s\" emrVpcPricingState=%s", emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName(), emrClusterAlternateKeyDto.getEmrClusterName(), jsonHelper.objectToJson(emrVpcPricingState))); throw new ObjectNotFoundException(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(emrVpcPricingState))); } EmrClusterPriceDto bestEmrClusterPrice = getEmrClusterPriceWithLowestCoreInstancePrice(emrClusterPrices); if (bestEmrClusterPrice != null) { Subnet bestEmrClusterSubnet = getBestSubnetForAvailabilityZone(bestEmrClusterPrice.getAvailabilityZone(), subnets); updateInstanceDefinitionsWithBestPrice(emrClusterDefinition, bestEmrClusterSubnet, bestEmrClusterPrice); } }  void updateEmrClusterDefinitionWithBestPrice(EmrClusterAlternateKeyDto emrClusterAlternateKeyDto, EmrClusterDefinition emrClusterDefinition,
        AwsParamsDto awsParamsDto); List<Subnet> getSubnets(EmrClusterDefinition emrClusterDefinition, AwsParamsDto awsParamsDto);  }
@Test public void testBestPriceAlgorithmicMaxSearchPriceTooLowAndSpotPriceNotAvailable() { String subnetId = SUBNET_1; 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 { updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition); fail(); } catch (ObjectNotFoundException e) { 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<>()); }}); 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()); } }
@Test public void testBestPriceAlgorithmicSearchBelowOnDemandThresholdBelowOnDemand() { String subnetId = SUBNET_1; MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition(); masterInstanceDefinition.setInstanceCount(1); masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_1); masterInstanceDefinition.setInstanceMaxSearchPrice(ON_DEMAND_LESS_ONE); masterInstanceDefinition.setInstanceOnDemandThreshold(ON_DEMAND_LESS_ONE.subtract(SPOT_PRICE_LOW)); InstanceDefinition coreInstanceDefinition = new InstanceDefinition(); coreInstanceDefinition.setInstanceCount(1); coreInstanceDefinition.setInstanceType(INSTANCE_TYPE_1); coreInstanceDefinition.setInstanceMaxSearchPrice(ON_DEMAND_LESS_ONE); coreInstanceDefinition.setInstanceOnDemandThreshold(ON_DEMAND_LESS_ONE.subtract(SPOT_PRICE_LOW)); InstanceDefinition taskInstanceDefinition = null; EmrClusterDefinition emrClusterDefinition = updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition); assertBestPriceCriteriaRemoved(emrClusterDefinition); assertEquals("master instance bid price", ON_DEMAND_LESS_ONE, emrClusterDefinition.getInstanceDefinitions().getMasterInstances().getInstanceSpotPrice()); assertEquals("core instance bid price", ON_DEMAND_LESS_ONE, emrClusterDefinition.getInstanceDefinitions().getCoreInstances().getInstanceSpotPrice()); }
@Test public void testBestPriceExplicitSpotAndOnDemand() { String subnetId = SUBNET_1; MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition(); masterInstanceDefinition.setInstanceCount(1); masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_1); masterInstanceDefinition.setInstanceSpotPrice(ON_DEMAND); InstanceDefinition coreInstanceDefinition = new InstanceDefinition(); coreInstanceDefinition.setInstanceCount(1); coreInstanceDefinition.setInstanceType(INSTANCE_TYPE_1); InstanceDefinition taskInstanceDefinition = null; EmrClusterDefinition emrClusterDefinition = updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition); assertBestPriceCriteriaRemoved(emrClusterDefinition); assertEquals("master instance bid price", ON_DEMAND, emrClusterDefinition.getInstanceDefinitions().getMasterInstances().getInstanceSpotPrice()); assertNull("core instance was not on-demand", emrClusterDefinition.getInstanceDefinitions().getCoreInstances().getInstanceSpotPrice()); }
@Test public void testMaxSearchPriceConvertedToSportPrice() { String subnetId = SUBNET_1; MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition(); masterInstanceDefinition.setInstanceCount(1); masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_1); masterInstanceDefinition.setInstanceMaxSearchPrice(ONE_POINT_ONE); InstanceDefinition coreInstanceDefinition = new InstanceDefinition(); coreInstanceDefinition.setInstanceCount(1); coreInstanceDefinition.setInstanceType(INSTANCE_TYPE_1); coreInstanceDefinition.setInstanceMaxSearchPrice(ONE_POINT_ONE); InstanceDefinition taskInstanceDefinition = null; EmrClusterDefinition emrClusterDefinition = updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition); assertBestPriceCriteriaRemoved(emrClusterDefinition); assertEquals("master instance bid price", ONE_POINT_ONE, emrClusterDefinition.getInstanceDefinitions().getMasterInstances().getInstanceSpotPrice()); assertEquals("core instance bid price", ONE_POINT_ONE, emrClusterDefinition.getInstanceDefinitions().getCoreInstances().getInstanceSpotPrice()); }
@Test public void testBestPriceExplicitSpotAndSpotPriceNotAvailable() { String subnetId = SUBNET_1; MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition(); masterInstanceDefinition.setInstanceCount(1); masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_4); masterInstanceDefinition.setInstanceSpotPrice(ON_DEMAND); InstanceDefinition coreInstanceDefinition = null; InstanceDefinition taskInstanceDefinition = null; try { updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition); fail(); } catch (ObjectNotFoundException e) { 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<>()); }}); 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()); } }
@Test public void testBestPriceCheapestPriceDoenstHaveEnoughIp() { String subnetId = SUBNET_1 + "," + SUBNET_3; MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition(); masterInstanceDefinition.setInstanceCount(5); masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_1); masterInstanceDefinition.setInstanceSpotPrice(ON_DEMAND); InstanceDefinition coreInstanceDefinition = new InstanceDefinition(); coreInstanceDefinition.setInstanceCount(6); coreInstanceDefinition.setInstanceType(INSTANCE_TYPE_1); coreInstanceDefinition.setInstanceSpotPrice(ON_DEMAND); InstanceDefinition taskInstanceDefinition = null; EmrClusterDefinition emrClusterDefinition = updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition); assertBestPriceCriteriaRemoved(emrClusterDefinition); assertEquals("master instance bid price", ON_DEMAND, emrClusterDefinition.getInstanceDefinitions().getMasterInstances().getInstanceSpotPrice()); assertEquals("core instance bid price", ON_DEMAND, emrClusterDefinition.getInstanceDefinitions().getCoreInstances().getInstanceSpotPrice()); assertEquals("selected subnet", SUBNET_3, emrClusterDefinition.getSubnetId()); }
@Test public void testBestPriceAllSubnetNotEnoughIp() { String subnetId = SUBNET_1 + "," + SUBNET_2; MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition(); masterInstanceDefinition.setInstanceCount(10); masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_1); InstanceDefinition coreInstanceDefinition = new InstanceDefinition(); coreInstanceDefinition.setInstanceCount(11); 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()); } }
@Test public void testBestPricePickBestAz() { String subnetId = SUBNET_1 + "," + SUBNET_3; MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition(); masterInstanceDefinition.setInstanceCount(4); masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_1); masterInstanceDefinition.setInstanceMaxSearchPrice(ON_DEMAND); InstanceDefinition coreInstanceDefinition = new InstanceDefinition(); coreInstanceDefinition.setInstanceCount(5); coreInstanceDefinition.setInstanceType(INSTANCE_TYPE_1); coreInstanceDefinition.setInstanceMaxSearchPrice(ON_DEMAND); InstanceDefinition taskInstanceDefinition = null; EmrClusterDefinition emrClusterDefinition = updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition); assertBestPriceCriteriaRemoved(emrClusterDefinition); assertEquals("master instance bid price", ON_DEMAND, emrClusterDefinition.getInstanceDefinitions().getMasterInstances().getInstanceSpotPrice()); assertEquals("core instance bid price", ON_DEMAND, emrClusterDefinition.getInstanceDefinitions().getCoreInstances().getInstanceSpotPrice()); assertEquals("selected subnet", SUBNET_1, emrClusterDefinition.getSubnetId()); }
@Test public void testBestPricePickMultipleInstancesSelectCheaperCore() { String subnetId = SUBNET_1 + "," + SUBNET_4; MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition(); masterInstanceDefinition.setInstanceCount(1); masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_1); masterInstanceDefinition.setInstanceSpotPrice(ON_DEMAND); InstanceDefinition coreInstanceDefinition = new InstanceDefinition(); coreInstanceDefinition.setInstanceCount(1); coreInstanceDefinition.setInstanceType(INSTANCE_TYPE_2); coreInstanceDefinition.setInstanceSpotPrice(SPOT_PRICE_VERY_HIGH); InstanceDefinition taskInstanceDefinition = new InstanceDefinition(); taskInstanceDefinition.setInstanceCount(1); taskInstanceDefinition.setInstanceType(INSTANCE_TYPE_1); taskInstanceDefinition.setInstanceSpotPrice(ON_DEMAND); EmrClusterDefinition emrClusterDefinition = updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition); assertBestPriceCriteriaRemoved(emrClusterDefinition); assertEquals("master instance bid price", ON_DEMAND, emrClusterDefinition.getInstanceDefinitions().getMasterInstances().getInstanceSpotPrice()); assertEquals("core instance bid price", SPOT_PRICE_VERY_HIGH, emrClusterDefinition.getInstanceDefinitions().getCoreInstances().getInstanceSpotPrice()); assertEquals("task instance bid price", ON_DEMAND, emrClusterDefinition.getInstanceDefinitions().getTaskInstances().getInstanceSpotPrice()); assertEquals("selected subnet", SUBNET_1, emrClusterDefinition.getSubnetId()); }
@Test public void testBestPricePickMultipleInstancesAzPricesAreEqual() { String subnetId = SUBNET_1 + "," + SUBNET_4; MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition(); masterInstanceDefinition.setInstanceCount(1); masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_2); masterInstanceDefinition.setInstanceSpotPrice(SPOT_PRICE_VERY_HIGH); InstanceDefinition coreInstanceDefinition = new InstanceDefinition(); coreInstanceDefinition.setInstanceCount(2); coreInstanceDefinition.setInstanceType(INSTANCE_TYPE_1); coreInstanceDefinition.setInstanceSpotPrice(ON_DEMAND); InstanceDefinition taskInstanceDefinition = new InstanceDefinition(); taskInstanceDefinition.setInstanceCount(2); taskInstanceDefinition.setInstanceType(INSTANCE_TYPE_1); taskInstanceDefinition.setInstanceSpotPrice(ON_DEMAND); EmrClusterDefinition emrClusterDefinition = updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition); assertBestPriceCriteriaRemoved(emrClusterDefinition); assertEquals("master instance bid price", SPOT_PRICE_VERY_HIGH, emrClusterDefinition.getInstanceDefinitions().getMasterInstances().getInstanceSpotPrice()); assertEquals("core instance bid price", ON_DEMAND, emrClusterDefinition.getInstanceDefinitions().getCoreInstances().getInstanceSpotPrice()); assertEquals("task instance bid price", ON_DEMAND, emrClusterDefinition.getInstanceDefinitions().getTaskInstances().getInstanceSpotPrice()); assertTrue("selected subnet was neither SUBNET_1 or SUBNET_4", SUBNET_1.equals(emrClusterDefinition.getSubnetId()) || SUBNET_4.equals(emrClusterDefinition.getSubnetId())); }
@Test public void testBestPricePickMultipleInstancesSelectCheaperCoreAndTask() { String subnetId = SUBNET_1 + "," + SUBNET_4; MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition(); masterInstanceDefinition.setInstanceCount(1); masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_2); masterInstanceDefinition.setInstanceSpotPrice(SPOT_PRICE_VERY_HIGH); InstanceDefinition coreInstanceDefinition = new InstanceDefinition(); coreInstanceDefinition.setInstanceCount(2); coreInstanceDefinition.setInstanceType(INSTANCE_TYPE_1); coreInstanceDefinition.setInstanceSpotPrice(ON_DEMAND); InstanceDefinition taskInstanceDefinition = new InstanceDefinition(); taskInstanceDefinition.setInstanceCount(3); taskInstanceDefinition.setInstanceType(INSTANCE_TYPE_1); taskInstanceDefinition.setInstanceSpotPrice(ON_DEMAND); EmrClusterDefinition emrClusterDefinition = updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition); assertBestPriceCriteriaRemoved(emrClusterDefinition); assertEquals("master instance bid price", SPOT_PRICE_VERY_HIGH, emrClusterDefinition.getInstanceDefinitions().getMasterInstances().getInstanceSpotPrice()); assertEquals("core instance bid price", ON_DEMAND, emrClusterDefinition.getInstanceDefinitions().getCoreInstances().getInstanceSpotPrice()); assertEquals("task instance bid price", ON_DEMAND, emrClusterDefinition.getInstanceDefinitions().getTaskInstances().getInstanceSpotPrice()); assertEquals("selected subnet", SUBNET_4, emrClusterDefinition.getSubnetId()); }
@Test public void testBestPriceSpotInstanceNotFoundBecauseSpotPriceIsNotAvailable() { String subnetId = SUBNET_1 + "," + SUBNET_5; MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition(); masterInstanceDefinition.setInstanceCount(1); masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_3); InstanceDefinition coreInstanceDefinition = new InstanceDefinition(); coreInstanceDefinition.setInstanceCount(1); coreInstanceDefinition.setInstanceType(INSTANCE_TYPE_1); InstanceDefinition taskInstanceDefinition = null; EmrClusterDefinition emrClusterDefinition = updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition); assertBestPriceCriteriaRemoved(emrClusterDefinition); }
@Test public void testBestPriceSubnetIsEmpty() { String subnetId = ""; 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; EmrClusterDefinition emrClusterDefinition = updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition); assertBestPriceCriteriaRemoved(emrClusterDefinition); assertTrue("subnet was not selected", StringUtils.isNotBlank(emrClusterDefinition.getSubnetId())); }
@Test public void testBestPriceSubnetPermutations() { String subnetId = ", \n\t\r" + SUBNET_1 + " \n\t\r,, \n\t\r,"; 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; EmrClusterDefinition emrClusterDefinition = updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition); assertBestPriceCriteriaRemoved(emrClusterDefinition); assertEquals("selected subnet", SUBNET_1, emrClusterDefinition.getSubnetId()); }
@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()); } }
@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()); } }
@Test public void testBestPriceSameAzMultipleSubnets() { String subnetId = SUBNET_1 + "," + SUBNET_2; 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; EmrClusterDefinition emrClusterDefinition = updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition); assertBestPriceCriteriaRemoved(emrClusterDefinition); assertEquals("selected subnet", SUBNET_2, emrClusterDefinition.getSubnetId()); }
@Test public void testCoreInstanceNullSubnetInMultipleAzAssertSuccess() throws Exception { String subnetId = SUBNET_1 + "," + SUBNET_3; MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition(); masterInstanceDefinition.setInstanceCount(1); masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_1); InstanceDefinition coreInstanceDefinition = null; InstanceDefinition taskInstanceDefinition = null; EmrClusterDefinition emrClusterDefinition = updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition); assertTrue(Arrays.asList(SUBNET_1, SUBNET_3).contains(emrClusterDefinition.getSubnetId())); }
@Test public void testCoreInstanceCount0SubnetInMultipleAzAssertSuccess() { String subnetId = SUBNET_1 + "," + SUBNET_3; MasterInstanceDefinition masterInstanceDefinition = new MasterInstanceDefinition(); masterInstanceDefinition.setInstanceCount(1); masterInstanceDefinition.setInstanceType(INSTANCE_TYPE_1); InstanceDefinition coreInstanceDefinition = new InstanceDefinition(); coreInstanceDefinition.setInstanceCount(0); coreInstanceDefinition.setInstanceType(INSTANCE_TYPE_1); InstanceDefinition taskInstanceDefinition = null; EmrClusterDefinition emrClusterDefinition = updateEmrClusterDefinitionWithBestPrice(subnetId, masterInstanceDefinition, coreInstanceDefinition, taskInstanceDefinition); assertTrue(Arrays.asList(SUBNET_1, SUBNET_3).contains(emrClusterDefinition.getSubnetId())); }