@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; }
/** * 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(); }
@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); }
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)
maxNumMasters, desiredNumMasters, Optional.of(availabilityZone.getZoneName()), Optional.<Integer>absent(), Optional.<Integer>absent(),
this.maxWorkers, this.desiredWorkers, Optional.of(availabilityZone.getZoneName()), Optional.<Integer>absent(), Optional.<Integer>absent(),
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()); } } }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getZoneName() == null) ? 0 : getZoneName().hashCode()); hashCode = prime * hashCode + ((getState() == null) ? 0 : getState().hashCode()); hashCode = prime * hashCode + ((getRegionName() == null) ? 0 : getRegionName().hashCode()); hashCode = prime * hashCode + ((getMessages() == null) ? 0 : getMessages().hashCode()); return hashCode; }
/** * Returns a string representation of this object; useful for testing and * debugging. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getZoneName() != null) sb.append("ZoneName: " + getZoneName() + ","); if (getState() != null) sb.append("State: " + getState() + ","); if (getRegionName() != null) sb.append("RegionName: " + getRegionName() + ","); if (getMessages() != null) sb.append("Messages: " + getMessages() ); sb.append("}"); return sb.toString(); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof AvailabilityZone == false) return false; AvailabilityZone other = (AvailabilityZone)obj; if (other.getZoneName() == null ^ this.getZoneName() == null) return false; if (other.getZoneName() != null && other.getZoneName().equals(this.getZoneName()) == false) return false; if (other.getState() == null ^ this.getState() == null) return false; if (other.getState() != null && other.getState().equals(this.getState()) == 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.getMessages() == null ^ this.getMessages() == null) return false; if (other.getMessages() != null && other.getMessages().equals(this.getMessages()) == 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; }
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; }
@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; }
/** * 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 spot prices for the given AZ and instance types. The spot prices are retrieved from EC2 API. * <p/> * This method also validates that the given instance types are real instance types supported by AWS. * * @param availabilityZone the AZ of the spot instances * @param instanceTypes the size of the spot instances * @param awsParamsDto the AWS related parameters for access/secret keys and proxy details * * @return the mapping of instance type to spot prices * @throws ObjectNotFoundException when any of the instance type does not exist in AWS */ private Map<String, BigDecimal> getInstanceTypeSpotPrices(AvailabilityZone availabilityZone, Set<String> instanceTypes, AwsParamsDto awsParamsDto) { List<String> productDescriptions = herdStringHelper.getDelimitedConfigurationValue(ConfigurationValue.EMR_SPOT_PRICE_HISTORY_PRODUCT_DESCRIPTIONS); List<SpotPrice> spotPrices = ec2Dao.getLatestSpotPrices(availabilityZone.getZoneName(), instanceTypes, productDescriptions, awsParamsDto); Map<String, BigDecimal> instanceTypeSpotPrices = new HashMap<>(); for (SpotPrice spotPrice : spotPrices) { instanceTypeSpotPrices.put(spotPrice.getInstanceType(), new BigDecimal(spotPrice.getSpotPrice())); } return instanceTypeSpotPrices; }
public static ListBoxModel fillZoneItems(AWSCredentialsProvider credentialsProvider, String region) { ListBoxModel model = new ListBoxModel(); if (AmazonEC2Cloud.testMode) { model.add(TEST_ZONE); return model; } if (!StringUtils.isEmpty(region)) { AmazonEC2 client = EC2Cloud.connect(credentialsProvider, AmazonEC2Cloud.getEc2EndpointUrl(region)); DescribeAvailabilityZonesResult zones = client.describeAvailabilityZones(); List<AvailabilityZone> zoneList = zones.getAvailabilityZones(); model.add("<not specified>", ""); for (AvailabilityZone z : zoneList) { model.add(z.getZoneName(), z.getZoneName()); } } return model; }
public static ListBoxModel fillZoneItems(AWSCredentialsProvider credentialsProvider, String region) { ListBoxModel model = new ListBoxModel(); if (AmazonEC2Cloud.testMode) { model.add(TEST_ZONE); return model; } if (!StringUtils.isEmpty(region)) { AmazonEC2 client = EC2Cloud.connect(credentialsProvider, AmazonEC2Cloud.getEc2EndpointUrl(region)); DescribeAvailabilityZonesResult zones = client.describeAvailabilityZones(); List<AvailabilityZone> zoneList = zones.getAvailabilityZones(); model.add("<not specified>", ""); for (AvailabilityZone z : zoneList) { model.add(z.getZoneName(), z.getZoneName()); } } return model; }
@Override public Map<AvailabilityZone, List<ReservedInstances>> getReservedInstancesForZone( AvailabilityZone zone, AmazonEC2Client client) throws Exception { OperationStats op = new OperationStats("ec2InstanceStore", "getReservedInstancesForZone"); try { Map<AvailabilityZone, List<ReservedInstances>> ret = new HashMap<>(); DescribeReservedInstancesRequest request = new DescribeReservedInstancesRequest() .withFilters(new Filter("availability-zone", Arrays.asList(zone.getZoneName()))) .withSdkClientExecutionTimeout( 600 * 1000) //10 minutes time out for total execution including retries .withSdkRequestTimeout(300 * 1000); //5 minutes time out for a single request DescribeReservedInstancesResult result = client.describeReservedInstances(request); ret.put(zone, result.getReservedInstances()); op.succeed(); return ret; } catch (Exception e) { op.failed(); logger.error(ExceptionUtils.getRootCauseMessage(e)); throw e; } }
/** * 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; }
/** * 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; }