@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getState() == null) ? 0 : getState().hashCode()); hashCode = prime * hashCode + ((getMessages() == null) ? 0 : getMessages().hashCode()); hashCode = prime * hashCode + ((getRegionName() == null) ? 0 : getRegionName().hashCode()); hashCode = prime * hashCode + ((getZoneName() == null) ? 0 : getZoneName().hashCode()); hashCode = prime * hashCode + ((getZoneId() == null) ? 0 : getZoneId().hashCode()); return hashCode; }
public AvailabilityZone unmarshall(StaxUnmarshallerContext context) throws Exception { AvailabilityZone availabilityZone = new AvailabilityZone(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; availabilityZone.setState(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; availabilityZone.withMessages(new ArrayList<AvailabilityZoneMessage>()); continue; availabilityZone.withMessages(AvailabilityZoneMessageStaxUnmarshaller.getInstance().unmarshall(context)); continue; availabilityZone.setRegionName(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; availabilityZone.setZoneName(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; availabilityZone.setZoneId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue;
@Override public List<String> getDefaultRacks() { // Get the fist 3 available zones in the region AmazonEC2 client = AmazonEC2ClientBuilder.standard() .withCredentials(credential.getAwsCredentialProvider()) .withRegion(getRegion()) .build(); DescribeAvailabilityZonesResult res = client.describeAvailabilityZones(); List<String> zone = Lists.newArrayList(); for (AvailabilityZone reg : res.getAvailabilityZones()) { if (reg.getState().equals("available")) zone.add(reg.getZoneName()); if (zone.size() == 3) break; } return ImmutableList.copyOf(zone); }
public static void main(String[] args) { final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient(); DescribeRegionsResult regions_response = ec2.describeRegions(); for(Region region : regions_response.getRegions()) { System.out.printf( "Found region %s " + "with endpoint %s", region.getRegionName(), region.getEndpoint()); } DescribeAvailabilityZonesResult zones_response = ec2.describeAvailabilityZones(); for(AvailabilityZone zone : zones_response.getAvailabilityZones()) { System.out.printf( "Found availability zone %s " + "with status %s " + "in region %s", zone.getZoneName(), zone.getState(), zone.getRegionName()); } } }
maxNumMasters, desiredNumMasters, Optional.of(availabilityZone.getZoneName()), Optional.<Integer>absent(), Optional.<Integer>absent(),
public AvailabilityZone unmarshall(StaxUnmarshallerContext context) throws Exception { AvailabilityZone availabilityZone = new AvailabilityZone(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; availabilityZone.setZoneName(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; availabilityZone.setState(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; availabilityZone.setRegionName(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; availabilityZone.getMessages().add(AvailabilityZoneMessageStaxUnmarshaller.getInstance().unmarshall(context)); continue;
/** * Converts this object into an AWS equivalent object. * * @return A new equivalent AWS object */ public AvailabilityZone toAwsObject() { AvailabilityZone availabilityZone = new AvailabilityZone(); availabilityZone.setRegionName(regionName); availabilityZone.setZoneName(zoneName); return availabilityZone; }
/** * Returns a mapping of instance types to on-demand prices for the given AZ and instance types. The on-demand prices are retrieved from database * configurations. The on-demand prices are looked up by the AZ's region name. This method also validates that the given instance types are real instance * types supported by AWS. * * @param availabilityZone the availability zone of the on-demand instances * @param instanceTypes the sizes of the on-demand instances * * @return the map of instance type to on-demand price * @throws ObjectNotFoundException when any of the instance type was not found in the given region */ private Map<String, BigDecimal> getInstanceTypeOnDemandPrices(AvailabilityZone availabilityZone, Set<String> instanceTypes) { Map<String, BigDecimal> instanceTypeOnDemandPrices = new HashMap<>(); for (String instanceType : instanceTypes) { Ec2OnDemandPricingEntity onDemandPrice = ec2OnDemandPricingDao.getEc2OnDemandPricing(availabilityZone.getRegionName(), instanceType); if (onDemandPrice == null) { throw new ObjectNotFoundException( "On-demand price for region '" + availabilityZone.getRegionName() + "' and instance type '" + instanceType + "' not found."); } instanceTypeOnDemandPrices.put(instanceType, onDemandPrice.getHourlyPrice()); } return instanceTypeOnDemandPrices; }
/** * <p> * The name of the region. * </p> * * @param regionName * The name of the region. * @return Returns a reference to this object so that method calls can be chained together. */ public AvailabilityZone withRegionName(String regionName) { setRegionName(regionName); return this; }
/** * <p> * The name of the Availability Zone. * </p> * * @param zoneName * The name of the Availability Zone. * @return Returns a reference to this object so that method calls can be chained together. */ public AvailabilityZone withZoneName(String zoneName) { setZoneName(zoneName); return this; }
this.maxWorkers, this.desiredWorkers, Optional.of(availabilityZone.getZoneName()), Optional.<Integer>absent(), Optional.<Integer>absent(),
/** * Get the fist 3 available zones in the region */ public void setDefaultRACList(String region){ AmazonEC2 client = new AmazonEC2Client(provider.getAwsCredentialProvider()); client.setEndpoint("ec2." + region + ".amazonaws.com"); DescribeAvailabilityZonesResult res = client.describeAvailabilityZones(); List<String> zone = Lists.newArrayList(); for(AvailabilityZone reg : res.getAvailabilityZones()){ if( reg.getState().equals("available") ) zone.add(reg.getZoneName()); if( zone.size() == 3) break; } // DEFAULT_AVAILABILITY_ZONES = StringUtils.join(zone, ","); DEFAULT_AVAILABILITY_ZONES = ImmutableList.copyOf(zone); }
/** * Returns a mapping of instance types to on-demand prices for the given AZ and instance types. The on-demand prices are retrieved from database * configurations. The on-demand prices are looked up by the AZ's region name. This method also validates that the given instance types are real instance * types supported by AWS. * * @param availabilityZone the availability zone of the on-demand instances * @param instanceTypes the sizes of the on-demand instances * * @return the map of instance type to on-demand price * @throws ObjectNotFoundException when any of the instance type was not found in the given region */ private Map<String, BigDecimal> getInstanceTypeOnDemandPrices(AvailabilityZone availabilityZone, Set<String> instanceTypes) { Map<String, BigDecimal> instanceTypeOnDemandPrices = new HashMap<>(); for (String instanceType : instanceTypes) { Ec2OnDemandPricingEntity onDemandPrice = ec2OnDemandPricingDao.getEc2OnDemandPricing(availabilityZone.getRegionName(), instanceType); if (onDemandPrice == null) { throw new ObjectNotFoundException( "On-demand price for region '" + availabilityZone.getRegionName() + "' and instance type '" + instanceType + "' not found."); } instanceTypeOnDemandPrices.put(instanceType, onDemandPrice.getHourlyPrice()); } return instanceTypeOnDemandPrices; }
/** * <p> * The name of the region. * </p> * * @param regionName * The name of the region. * @return Returns a reference to this object so that method calls can be chained together. */ public AvailabilityZone withRegionName(String regionName) { setRegionName(regionName); return this; }
/** * <p> * The name of the Availability Zone. * </p> * * @param zoneName * The name of the Availability Zone. * @return Returns a reference to this object so that method calls can be chained together. */ public AvailabilityZone withZoneName(String zoneName) { setZoneName(zoneName); return this; }
return false; AvailabilityZone other = (AvailabilityZone) obj; if (other.getState() == null ^ this.getState() == null) return false; if (other.getState() != null && other.getState().equals(this.getState()) == false) return false; if (other.getMessages() == null ^ this.getMessages() == null) return false; if (other.getMessages() != null && other.getMessages().equals(this.getMessages()) == false) return false; if (other.getRegionName() == null ^ this.getRegionName() == null) return false; if (other.getRegionName() != null && other.getRegionName().equals(this.getRegionName()) == false) return false; if (other.getZoneName() == null ^ this.getZoneName() == null) return false; if (other.getZoneName() != null && other.getZoneName().equals(this.getZoneName()) == false) return false; if (other.getZoneId() == null ^ this.getZoneId() == null) return false; if (other.getZoneId() != null && other.getZoneId().equals(this.getZoneId()) == false) return false; return true;
private ArrayList<String> getAvailabilityZones(AmazonEC2 ec2) { ArrayList<String> availabilityZones = new ArrayList<String>(); DescribeAvailabilityZonesResult zones = ec2.describeAvailabilityZones(); List<AvailabilityZone> zoneList = zones.getAvailabilityZones(); for (AvailabilityZone z : zoneList) { availabilityZones.add(z.getZoneName()); } return availabilityZones; }
public AvailabilityZone unmarshall(StaxUnmarshallerContext context) throws Exception { AvailabilityZone availabilityZone = new AvailabilityZone(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; availabilityZone.setState(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; availabilityZone.withMessages(new ArrayList<AvailabilityZoneMessage>()); continue; availabilityZone.withMessages(AvailabilityZoneMessageStaxUnmarshaller.getInstance().unmarshall(context)); continue; availabilityZone.setRegionName(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; availabilityZone.setZoneName(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; availabilityZone.setZoneId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue;
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getState() != null) sb.append("State: ").append(getState()).append(","); if (getMessages() != null) sb.append("Messages: ").append(getMessages()).append(","); if (getRegionName() != null) sb.append("RegionName: ").append(getRegionName()).append(","); if (getZoneName() != null) sb.append("ZoneName: ").append(getZoneName()).append(","); if (getZoneId() != null) sb.append("ZoneId: ").append(getZoneId()); sb.append("}"); return sb.toString(); }
private ArrayList<String> getAvailabilityZones(AmazonEC2 ec2) { ArrayList<String> availabilityZones = new ArrayList<String>(); DescribeAvailabilityZonesResult zones = ec2.describeAvailabilityZones(); List<AvailabilityZone> zoneList = zones.getAvailabilityZones(); for (AvailabilityZone z : zoneList) { availabilityZones.add(z.getZoneName()); } return availabilityZones; }