/** * Creates a new {@link EmrClusterPriceDto} object from the given parameters. * * @param availabilityZone the AZ * @param masterPrice the master instance's price * @param corePrice the core instance's price * @param taskPrice the task instance's price * * @return the new {@link EmrClusterPriceDto} */ private EmrClusterPriceDto createEmrClusterPrice(AvailabilityZone availabilityZone, Ec2PriceDto masterPrice, Ec2PriceDto corePrice, Ec2PriceDto taskPrice) { EmrClusterPriceDto emrClusterPrice = new EmrClusterPriceDto(); emrClusterPrice.setAvailabilityZone(availabilityZone.getZoneName()); emrClusterPrice.setMasterPrice(masterPrice); emrClusterPrice.setCorePrice(corePrice); emrClusterPrice.setTaskPrice(taskPrice); return emrClusterPrice; }
public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) { { String theAvailabilityZone; theAvailabilityZone = this.getAvailabilityZone(); strategy.appendField(locator, this, "availabilityZone", buffer, theAvailabilityZone, (this.availabilityZone!= null)); } { Ec2PriceDto theMasterPrice; theMasterPrice = this.getMasterPrice(); strategy.appendField(locator, this, "masterPrice", buffer, theMasterPrice, (this.masterPrice!= null)); } { Ec2PriceDto theCorePrice; theCorePrice = this.getCorePrice(); strategy.appendField(locator, this, "corePrice", buffer, theCorePrice, (this.corePrice!= null)); } { Ec2PriceDto theTaskPrice; theTaskPrice = this.getTaskPrice(); strategy.appendField(locator, this, "taskPrice", buffer, theTaskPrice, (this.taskPrice!= null)); } return buffer; }
public String toString() { final ToStringStrategy2 strategy = JAXBToStringStrategy.INSTANCE; final StringBuilder buffer = new StringBuilder(); append(null, buffer, strategy); return buffer.toString(); }
public Object copyTo(ObjectLocator locator, Object target, CopyStrategy2 strategy) { final Object draftCopy = ((target == null)?createNewInstance():target); if (draftCopy instanceof EmrClusterPriceDto) { final EmrClusterPriceDto copy = ((EmrClusterPriceDto) draftCopy); if (availabilityZoneShouldBeCopiedAndSet == Boolean.TRUE) { String sourceAvailabilityZone; sourceAvailabilityZone = this.getAvailabilityZone(); String copyAvailabilityZone = ((String) strategy.copy(LocatorUtils.property(locator, "availabilityZone", sourceAvailabilityZone), sourceAvailabilityZone, (this.availabilityZone!= null))); copy.setAvailabilityZone(copyAvailabilityZone); } else { if (availabilityZoneShouldBeCopiedAndSet == Boolean.FALSE) { if (masterPriceShouldBeCopiedAndSet == Boolean.TRUE) { Ec2PriceDto sourceMasterPrice; sourceMasterPrice = this.getMasterPrice(); Ec2PriceDto copyMasterPrice = ((Ec2PriceDto) strategy.copy(LocatorUtils.property(locator, "masterPrice", sourceMasterPrice), sourceMasterPrice, (this.masterPrice!= null))); copy.setMasterPrice(copyMasterPrice); } else { if (masterPriceShouldBeCopiedAndSet == Boolean.FALSE) { if (corePriceShouldBeCopiedAndSet == Boolean.TRUE) { Ec2PriceDto sourceCorePrice; sourceCorePrice = this.getCorePrice(); Ec2PriceDto copyCorePrice = ((Ec2PriceDto) strategy.copy(LocatorUtils.property(locator, "corePrice", sourceCorePrice), sourceCorePrice, (this.corePrice!= null))); copy.setCorePrice(copyCorePrice); } else { if (corePriceShouldBeCopiedAndSet == Boolean.FALSE) { if (taskPriceShouldBeCopiedAndSet == Boolean.TRUE) {
private EmrClusterPriceDto createSimpleEmrClusterPrice(final String availabilityZone, final BigDecimal instancePrice) { EmrClusterPriceDto emrClusterPriceDto = new EmrClusterPriceDto(); emrClusterPriceDto.setAvailabilityZone(availabilityZone); if (instancePrice != null) { Ec2PriceDto corePrice = new Ec2PriceDto(); corePrice.setInstanceCount(1); corePrice.setInstancePrice(instancePrice); emrClusterPriceDto.setCorePrice(corePrice); } return emrClusterPriceDto; }
@Test public void testGetEmrClusterPricesWithinLowestCoreInstancePriceThresholdSinglePricing() throws Exception { List<EmrClusterPriceDto> pricingList = Arrays.asList(createSimpleEmrClusterPrice(AVAILABILITY_ZONE_1, BigDecimal.ONE)); List<EmrClusterPriceDto> lowestCoreInstancePriceClusters = emrPricingHelper.getEmrClusterPricesWithinLowestCoreInstancePriceThreshold(pricingList, TEN_PERCENT); assertEquals(1, lowestCoreInstancePriceClusters.size()); assertEquals(AVAILABILITY_ZONE_1, lowestCoreInstancePriceClusters.get(0).getAvailabilityZone()); }
/** * Updates the given definition with the given subnet and EMR pricing information. * <p/> * Sets the subnet with the given subnet ID. Removes any maxSearchPrice and onDemandThreshold that were set. Sets the spotPrice only if the given cluster * price is a spot. * * @param emrClusterDefinition the definition to update * @param bestEmrClusterSubnet the subnet to use * @param bestEmrClusterPrice the EMR pricing information for each instance */ private void updateInstanceDefinitionsWithBestPrice(EmrClusterDefinition emrClusterDefinition, Subnet bestEmrClusterSubnet, EmrClusterPriceDto bestEmrClusterPrice) { emrClusterDefinition.setSubnetId(bestEmrClusterSubnet.getSubnetId()); emrClusterDefinition.getInstanceDefinitions().getMasterInstances().setInstanceMaxSearchPrice(null); emrClusterDefinition.getInstanceDefinitions().getMasterInstances().setInstanceOnDemandThreshold(null); emrClusterDefinition.getInstanceDefinitions().getMasterInstances().setInstanceSpotPrice(getSpotBidPrice(bestEmrClusterPrice.getMasterPrice())); if (bestEmrClusterPrice.getCorePrice() != null) { emrClusterDefinition.getInstanceDefinitions().getCoreInstances().setInstanceMaxSearchPrice(null); emrClusterDefinition.getInstanceDefinitions().getCoreInstances().setInstanceOnDemandThreshold(null); emrClusterDefinition.getInstanceDefinitions().getCoreInstances().setInstanceSpotPrice(getSpotBidPrice(bestEmrClusterPrice.getCorePrice())); } }
/** * Create an instance of {@link EmrClusterPriceDto } * */ public EmrClusterPriceDto createEmrClusterPriceDto() { return new EmrClusterPriceDto(); }
/** * Gets the core instance price in the cluster. * * @param emrClusterPrice the pricing information * * @return the core instance price */ private BigDecimal getEmrClusterCoreInstancePrice(EmrClusterPriceDto emrClusterPrice) { BigDecimal coreInstancePrice = BigDecimal.ZERO; if (emrClusterPrice.getCorePrice() != null) { coreInstancePrice = emrClusterPrice.getCorePrice().getInstancePrice(); } return coreInstancePrice; }
/** * Tests when one cluster does not have core instance. In this case this cluster will be picked since the price for the cluster is now zero (the lowest) * * @throws Exception */ @Test public void testGetEmrClusterPricesWithinLowestCoreInstancePriceEmptyCoreInstanceMultiplePricings() throws Exception { List<EmrClusterPriceDto> pricingList = Arrays.asList(createSimpleEmrClusterPrice(AVAILABILITY_ZONE_1, BigDecimal.ONE), createSimpleEmrClusterPrice(AVAILABILITY_ZONE_4, null)); List<EmrClusterPriceDto> lowestCoreInstancePriceClusters = emrPricingHelper.getEmrClusterPricesWithinLowestCoreInstancePriceThreshold(pricingList, TEN_PERCENT); assertEquals(1, lowestCoreInstancePriceClusters.size()); for (EmrClusterPriceDto emrClusterPriceDto : lowestCoreInstancePriceClusters) { assertTrue(Arrays.asList(AVAILABILITY_ZONE_4).contains(emrClusterPriceDto.getAvailabilityZone())); } }
/** * Updates the given definition with the given subnet and EMR pricing information. * <p/> * Sets the subnet with the given subnet ID. Removes any maxSearchPrice and onDemandThreshold that were set. Sets the spotPrice only if the given cluster * price is a spot. * * @param emrClusterDefinition the definition to update * @param bestEmrClusterSubnet the subnet to use * @param bestEmrClusterPrice the EMR pricing information for each instance */ private void updateInstanceDefinitionsWithBestPrice(EmrClusterDefinition emrClusterDefinition, Subnet bestEmrClusterSubnet, EmrClusterPriceDto bestEmrClusterPrice) { emrClusterDefinition.setSubnetId(bestEmrClusterSubnet.getSubnetId()); emrClusterDefinition.getInstanceDefinitions().getMasterInstances().setInstanceMaxSearchPrice(null); emrClusterDefinition.getInstanceDefinitions().getMasterInstances().setInstanceOnDemandThreshold(null); emrClusterDefinition.getInstanceDefinitions().getMasterInstances().setInstanceSpotPrice(getSpotBidPrice(bestEmrClusterPrice.getMasterPrice())); if (bestEmrClusterPrice.getCorePrice() != null) { emrClusterDefinition.getInstanceDefinitions().getCoreInstances().setInstanceMaxSearchPrice(null); emrClusterDefinition.getInstanceDefinitions().getCoreInstances().setInstanceOnDemandThreshold(null); emrClusterDefinition.getInstanceDefinitions().getCoreInstances().setInstanceSpotPrice(getSpotBidPrice(bestEmrClusterPrice.getCorePrice())); } }
public Object createNewInstance() { return new EmrClusterPriceDto(); }
/** * Gets the core instance price in the cluster. * * @param emrClusterPrice the pricing information * * @return the core instance price */ private BigDecimal getEmrClusterCoreInstancePrice(EmrClusterPriceDto emrClusterPrice) { BigDecimal coreInstancePrice = BigDecimal.ZERO; if (emrClusterPrice.getCorePrice() != null) { coreInstancePrice = emrClusterPrice.getCorePrice().getInstancePrice(); } return coreInstancePrice; }
/** * Creates a new {@link EmrClusterPriceDto} object from the given parameters. * * @param availabilityZone the AZ * @param masterPrice the master instance's price * @param corePrice the core instance's price * @param taskPrice the task instance's price * * @return the new {@link EmrClusterPriceDto} */ private EmrClusterPriceDto createEmrClusterPrice(AvailabilityZone availabilityZone, Ec2PriceDto masterPrice, Ec2PriceDto corePrice, Ec2PriceDto taskPrice) { EmrClusterPriceDto emrClusterPrice = new EmrClusterPriceDto(); emrClusterPrice.setAvailabilityZone(availabilityZone.getZoneName()); emrClusterPrice.setMasterPrice(masterPrice); emrClusterPrice.setCorePrice(corePrice); emrClusterPrice.setTaskPrice(taskPrice); return emrClusterPrice; }
lhsAvailabilityZone = this.getAvailabilityZone(); String rhsAvailabilityZone; rhsAvailabilityZone = that.getAvailabilityZone(); if (!strategy.equals(LocatorUtils.property(thisLocator, "availabilityZone", lhsAvailabilityZone), LocatorUtils.property(thatLocator, "availabilityZone", rhsAvailabilityZone), lhsAvailabilityZone, rhsAvailabilityZone, (this.availabilityZone!= null), (that.availabilityZone!= null))) { return false; lhsMasterPrice = this.getMasterPrice(); Ec2PriceDto rhsMasterPrice; rhsMasterPrice = that.getMasterPrice(); if (!strategy.equals(LocatorUtils.property(thisLocator, "masterPrice", lhsMasterPrice), LocatorUtils.property(thatLocator, "masterPrice", rhsMasterPrice), lhsMasterPrice, rhsMasterPrice, (this.masterPrice!= null), (that.masterPrice!= null))) { return false; lhsCorePrice = this.getCorePrice(); Ec2PriceDto rhsCorePrice; rhsCorePrice = that.getCorePrice(); if (!strategy.equals(LocatorUtils.property(thisLocator, "corePrice", lhsCorePrice), LocatorUtils.property(thatLocator, "corePrice", rhsCorePrice), lhsCorePrice, rhsCorePrice, (this.corePrice!= null), (that.corePrice!= null))) { return false; lhsTaskPrice = this.getTaskPrice(); Ec2PriceDto rhsTaskPrice; rhsTaskPrice = that.getTaskPrice(); if (!strategy.equals(LocatorUtils.property(thisLocator, "taskPrice", lhsTaskPrice), LocatorUtils.property(thatLocator, "taskPrice", rhsTaskPrice), lhsTaskPrice, rhsTaskPrice, (this.taskPrice!= null), (that.taskPrice!= null))) { return false;
@Test public void testGetEmrClusterPricesWithinLowestCoreInstancePriceThresholdMultiplePricing() throws Exception { List<EmrClusterPriceDto> pricingList = Arrays .asList(createSimpleEmrClusterPrice(AVAILABILITY_ZONE_1, BigDecimal.ONE), createSimpleEmrClusterPrice(AVAILABILITY_ZONE_2, BigDecimal.TEN), createSimpleEmrClusterPrice(AVAILABILITY_ZONE_3, ONE_POINT_ONE), createSimpleEmrClusterPrice(AVAILABILITY_ZONE_4, ONE_POINT_ONE_ONE)); List<EmrClusterPriceDto> lowestCoreInstancePriceClusters = emrPricingHelper.getEmrClusterPricesWithinLowestCoreInstancePriceThreshold(pricingList, TEN_PERCENT); assertEquals(2, lowestCoreInstancePriceClusters.size()); for (EmrClusterPriceDto emrClusterPriceDto : lowestCoreInstancePriceClusters) { assertTrue(Arrays.asList(AVAILABILITY_ZONE_1, AVAILABILITY_ZONE_3).contains(emrClusterPriceDto.getAvailabilityZone())); } }
@Override public EmrClusterPriceDto build() { if (_storedValue == null) { return this.init(new EmrClusterPriceDto()); } else { return ((EmrClusterPriceDto) _storedValue); } }
public int hashCode(ObjectLocator locator, HashCodeStrategy2 strategy) { int currentHashCode = 1; { String theAvailabilityZone; theAvailabilityZone = this.getAvailabilityZone(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "availabilityZone", theAvailabilityZone), currentHashCode, theAvailabilityZone, (this.availabilityZone!= null)); } { Ec2PriceDto theMasterPrice; theMasterPrice = this.getMasterPrice(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "masterPrice", theMasterPrice), currentHashCode, theMasterPrice, (this.masterPrice!= null)); } { Ec2PriceDto theCorePrice; theCorePrice = this.getCorePrice(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "corePrice", theCorePrice), currentHashCode, theCorePrice, (this.corePrice!= null)); } { Ec2PriceDto theTaskPrice; theTaskPrice = this.getTaskPrice(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "taskPrice", theTaskPrice), currentHashCode, theTaskPrice, (this.taskPrice!= null)); } return currentHashCode; }
/** * Tests when the threshold is set to zero. * * @throws Exception */ @Test public void testGetEmrClusterPricesWithinLowestCoreInstancePriceZeroThresholdMultiplePricings() throws Exception { List<EmrClusterPriceDto> pricingList = Arrays .asList(createSimpleEmrClusterPrice(AVAILABILITY_ZONE_1, BigDecimal.ONE), createSimpleEmrClusterPrice(AVAILABILITY_ZONE_2, BigDecimal.TEN), createSimpleEmrClusterPrice(AVAILABILITY_ZONE_3, BigDecimal.ONE.add(FIVE_UNIT)), createSimpleEmrClusterPrice(AVAILABILITY_ZONE_4, BigDecimal.ONE)); List<EmrClusterPriceDto> lowestCoreInstancePriceClusters = emrPricingHelper.getEmrClusterPricesWithinLowestCoreInstancePriceThreshold(pricingList, BigDecimal.ZERO); assertEquals(2, lowestCoreInstancePriceClusters.size()); for (EmrClusterPriceDto emrClusterPriceDto : lowestCoreInstancePriceClusters) { assertTrue(Arrays.asList(AVAILABILITY_ZONE_1, AVAILABILITY_ZONE_4).contains(emrClusterPriceDto.getAvailabilityZone())); } }
Subnet bestEmrClusterSubnet = getBestSubnetForAvailabilityZone(bestEmrClusterPrice.getAvailabilityZone(), subnets);