com.amazonaws.services.ec2.model.AvailabilityZone Java Examples
The following examples show how to use
com.amazonaws.services.ec2.model.AvailabilityZone.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Ec2InstanceStore.java From soundwave with Apache License 2.0 | 6 votes |
@Override public Map<AvailabilityZone, List<Instance>> getInstancesMapForZone( AvailabilityZone zone, AmazonEC2Client client) throws Exception { OperationStats op = new OperationStats("ec2InstanceStore", "getInstancesMapForZone"); try { Map<AvailabilityZone, List<Instance>> ret = new HashMap<>(); ret.put(zone, getInstancesForZone(zone, client)); op.succeed(); return ret; } catch (Exception e) { op.failed(); logger.error(ExceptionUtils.getRootCauseMessage(e)); throw e; } }
Example #2
Source File: Ec2DaoImpl.java From herd with Apache License 2.0 | 6 votes |
/** * This implementation uses the DescribeAvailabilityZones API to get the list of AZs. */ @Override public List<AvailabilityZone> getAvailabilityZonesForSubnetIds(Collection<Subnet> subnets, AwsParamsDto awsParamsDto) { Set<String> zoneNames = new HashSet<>(); for (Subnet subnet : subnets) { zoneNames.add(subnet.getAvailabilityZone()); } AmazonEC2Client ec2Client = getEc2Client(awsParamsDto); DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest = new DescribeAvailabilityZonesRequest(); describeAvailabilityZonesRequest.setZoneNames(zoneNames); DescribeAvailabilityZonesResult describeAvailabilityZonesResult = ec2Operations.describeAvailabilityZones(ec2Client, describeAvailabilityZonesRequest); return describeAvailabilityZonesResult.getAvailabilityZones(); }
Example #3
Source File: MockAwsDescribeService.java From primecloud-controller with GNU General Public License v2.0 | 5 votes |
@Override public List<AvailabilityZone> getAvailabilityZones(Long userNo, Long platformNo) { List<AvailabilityZone> zones = new ArrayList<AvailabilityZone>(); zones.add(new AvailabilityZone().withZoneName("ap-northeast-1a")); zones.add(new AvailabilityZone().withZoneName("ap-northeast-1b")); zones.add(new AvailabilityZone().withZoneName("ap-northeast-1c")); return zones; }
Example #4
Source File: BaseTest.java From aws-mock with MIT License | 5 votes |
/** * Describe AvailabilityZone. * * @return AvailabilityZone */ protected final AvailabilityZone getAvailiablityZones() { AvailabilityZone availabilityZone = null; DescribeAvailabilityZonesResult result = amazonEC2Client.describeAvailabilityZones(); if (result != null && !result.getAvailabilityZones().isEmpty()) { availabilityZone = result.getAvailabilityZones().get(0); } return availabilityZone; }
Example #5
Source File: Ec2NetworkTest.java From aws-mock with MIT License | 5 votes |
/** * Test describing Availability Zones. */ @Test(timeout = TIMEOUT_LEVEL1) public final void describeAvailabilityZonesTest() { log.info("Start describing Availability Zones test"); AvailabilityZone availabiltyZone = getAvailiablityZones(); Assert.assertNotNull("route table should not be null", availabiltyZone); Assert.assertNotNull("route table id should not be null", availabiltyZone.getZoneName()); }
Example #6
Source File: AwsSubnetRequestProviderTest.java From cloudbreak with Apache License 2.0 | 5 votes |
private AmazonEC2Client createEc2Client(List<AvailabilityZone> availabilityZones) { AmazonEC2Client ec2Client = Mockito.mock(AmazonEC2Client.class); DescribeAvailabilityZonesResult result = new DescribeAvailabilityZonesResult(); result.setAvailabilityZones(availabilityZones); Mockito.when(ec2Client.describeAvailabilityZones()).thenReturn(result); return ec2Client; }
Example #7
Source File: AwsAvailabilityZoneProvider.java From cloudbreak with Apache License 2.0 | 5 votes |
@Cacheable(cacheNames = "cloudResourceAzCache", key = "{ #cloudCredential?.id, #awsRegion.regionName }") public List<AvailabilityZone> describeAvailabilityZones(CloudCredential cloudCredential, DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest, AmazonEC2Client ec2Client, com.amazonaws.services.ec2.model.Region awsRegion) { DescribeAvailabilityZonesResult describeAvailabilityZonesResult = ec2Client.describeAvailabilityZones(describeAvailabilityZonesRequest); return describeAvailabilityZonesResult.getAvailabilityZones(); }
Example #8
Source File: AwsSubnetRequestProvider.java From cloudbreak with Apache License 2.0 | 5 votes |
private List<String> getAvailabilityZones(AmazonEC2Client ec2Client) { return ec2Client.describeAvailabilityZones() .getAvailabilityZones() .stream() .map(AvailabilityZone::getZoneName) .collect(Collectors.toList()); }
Example #9
Source File: AWSSdkClient.java From incubator-gobblin with Apache License 2.0 | 5 votes |
/*** * Get availability zones in an Amazon AWS region * * @return List of availability zones */ public List<AvailabilityZone> getAvailabilityZones() { final AmazonEC2 amazonEC2 = getEc2Client(); final DescribeAvailabilityZonesResult describeAvailabilityZonesResult = amazonEC2.describeAvailabilityZones(); final List<AvailabilityZone> availabilityZones = describeAvailabilityZonesResult.getAvailabilityZones(); LOGGER.info("Found: " + availabilityZones.size() + " availability zone"); return availabilityZones; }
Example #10
Source File: GobblinAWSClusterLauncher.java From incubator-gobblin with Apache License 2.0 | 5 votes |
/** * Setup the Gobblin AWS cluster. * * @throws IOException If there's anything wrong setting up the AWS cluster */ @VisibleForTesting String setupGobblinCluster() throws IOException { final String uuid = UUID.randomUUID().toString(); // Create security group // TODO: Make security group restrictive final String securityGroupName = "GobblinSecurityGroup_" + uuid; this.awsSdkClient.createSecurityGroup(securityGroupName, "Gobblin cluster security group"); this.awsSdkClient.addPermissionsToSecurityGroup(securityGroupName, "0.0.0.0/0", "tcp", 0, 65535); // Create key value pair final String keyName = "GobblinKey_" + uuid; final String material = this.awsSdkClient.createKeyValuePair(keyName); LOGGER.debug("Material is: " + material); FileUtils.writeStringToFile(new File(keyName + ".pem"), material); // Get all availability zones in the region. Currently, we will only use first final List<AvailabilityZone> availabilityZones = this.awsSdkClient.getAvailabilityZones(); // Launch Cluster Master final String clusterId = launchClusterMaster(uuid, keyName, securityGroupName, availabilityZones.get(0)); // Launch WorkUnit runners launchWorkUnitRunners(uuid, keyName, securityGroupName, availabilityZones.get(0)); return clusterId; }
Example #11
Source File: EditInstanceAws.java From primecloud-controller with GNU General Public License v2.0 | 5 votes |
private boolean checkAvailabilityZoneName(Long userNo, Long platformNo, String zoneName) { List<AvailabilityZone> availabilityZones = awsDescribeService.getAvailabilityZones(userNo, platformNo); for (AvailabilityZone availabilityZone : availabilityZones) { if (StringUtils.equals(zoneName, availabilityZone.getZoneName())) { return true; } } return false; }
Example #12
Source File: AwsCommonProcess.java From primecloud-controller with GNU General Public License v2.0 | 5 votes |
public List<AvailabilityZone> describeAvailabilityZones(AwsProcessClient awsProcessClient) { DescribeAvailabilityZonesRequest request = new DescribeAvailabilityZonesRequest(); DescribeAvailabilityZonesResult result = awsProcessClient.getEc2Client().describeAvailabilityZones(request); List<AvailabilityZone> availabilityZones = result.getAvailabilityZones(); return availabilityZones; }
Example #13
Source File: AwsDescribeServiceImpl.java From primecloud-controller with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public List<AvailabilityZone> getAvailabilityZones(Long userNo, Long platformNo) { // アベイラビリティゾーンを取得 AwsProcessClient awsProcessClient = awsProcessClientFactory.createAwsProcessClient(userNo, platformNo); DescribeAvailabilityZonesRequest request = new DescribeAvailabilityZonesRequest(); DescribeAvailabilityZonesResult result = awsProcessClient.getEc2Client().describeAvailabilityZones(request); List<AvailabilityZone> availabilityZones = result.getAvailabilityZones(); // ソート Collections.sort(availabilityZones, Comparators.COMPARATOR_AVAILABILITY_ZONE); return availabilityZones; }
Example #14
Source File: AvailabilityZoneConverter.java From primecloud-controller with GNU General Public License v2.0 | 5 votes |
@Override protected AvailabilityZone convertObject(com.xerox.amazonws.ec2.AvailabilityZone from) { AvailabilityZone to = new AvailabilityZone(); to.setZoneName(from.getName()); to.setState(from.getState()); // 未実装 to.setRegionName(null); return to; }
Example #15
Source File: MockEc2OperationsImpl.java From herd with Apache License 2.0 | 5 votes |
@Override public DescribeAvailabilityZonesResult describeAvailabilityZones(AmazonEC2Client ec2Client, DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest) { List<AvailabilityZone> availabilityZones = new ArrayList<>(); List<String> requestedZoneNames = describeAvailabilityZonesRequest.getZoneNames(); // add all AZ if request is empty (this is AWS behavior) if (requestedZoneNames.isEmpty()) { requestedZoneNames.addAll(mockAvailabilityZones.keySet()); } for (String requestedZoneName : requestedZoneNames) { // ignore AZ name which does not exist (this is AWS behavior) MockAvailabilityZone mockAvailabilityZone = mockAvailabilityZones.get(requestedZoneName); if (mockAvailabilityZone != null) { availabilityZones.add(mockAvailabilityZone.toAwsObject()); } } DescribeAvailabilityZonesResult describeAvailabilityZonesResult = new DescribeAvailabilityZonesResult(); describeAvailabilityZonesResult.setAvailabilityZones(availabilityZones); return describeAvailabilityZonesResult; }
Example #16
Source File: MockAvailabilityZone.java From herd with Apache License 2.0 | 5 votes |
/** * 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; }
Example #17
Source File: EmrPricingHelper.java From herd with Apache License 2.0 | 5 votes |
/** * 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; }
Example #18
Source File: DescribeRegionsAndZones.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static void main(String[] args) { final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient(); // snippet-start:[ec2.java1.describe_region_and_zones.regions] DescribeRegionsResult regions_response = ec2.describeRegions(); for(Region region : regions_response.getRegions()) { System.out.printf( "Found region %s " + "with endpoint %s", region.getRegionName(), region.getEndpoint()); } // snippet-end:[ec2.java1.describe_region_and_zones.regions] // snippet-start:[ec2.java1.describe_region_and_zones.zones] 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()); } // snippet-end:[ec2.java1.describe_region_and_zones.zones] }
Example #19
Source File: Ec2InstanceStore.java From soundwave with Apache License 2.0 | 5 votes |
private List<InstanceStatus> getInstancesStatusByZone(AvailabilityZone zone, AmazonEC2Client client) { // Create this list to capture paginated async results from aws sdk List<InstanceStatus> statusList = new ArrayList<>(); // Create an initial request object DescribeInstanceStatusRequest statusRequest = new DescribeInstanceStatusRequest() .withMaxResults(1000) .withFilters(new Filter("availability-zone", Arrays.asList(zone.getZoneName()))) .withSdkClientExecutionTimeout(600 * 1000) .withSdkRequestTimeout(300 * 1000); // Make the request for instanceStatus DescribeInstanceStatusResult result = client.describeInstanceStatus(statusRequest); // Until more results are available we loop through this code while (result != null) { statusList.addAll(result.getInstanceStatuses()); if (result.getNextToken() != null) { statusRequest.setNextToken(result.getNextToken()); result = client.describeInstanceStatus(statusRequest); } else { result = null; } } // Return all statuses as a list of InstanceStatus objects return statusList; }
Example #20
Source File: Ec2InstanceStore.java From soundwave with Apache License 2.0 | 5 votes |
/** * This function is a wrapper to the ec2 describeInstanceStatus function. * * @param region * @return List of InstanceStatus */ public List<InstanceStatus> describeInstancesStatusAsync(Region region) throws Exception { Preconditions.checkNotNull(region); List<InstanceStatus> statusList = new ArrayList<>(); List<AvailabilityZone> zones = getAvailabilityZones(region); AmazonEC2Client client = getClient(region); ExecutorService executor = Executors.newFixedThreadPool(zones.size()); OperationStats op = new OperationStats("ec2InstanceStore", "describeInstancesStatusAsync"); try { List<Callable<List<InstanceStatus>>> retrieveFunction = new ArrayList<>(zones.size()); for (AvailabilityZone zone : zones) { retrieveFunction.add(new Callable<List<InstanceStatus>>() { @Override public List<InstanceStatus> call() throws Exception { return getInstancesStatusByZone(zone, client); } }); } List<Future<List<InstanceStatus>>> futures = executor.invokeAll(retrieveFunction); for (Future<List<InstanceStatus>> future : futures) { statusList.addAll(future.get()); } op.succeed(); } catch (Exception ex) { op.failed(); throw ex; } finally { executor.shutdown(); } return statusList; }
Example #21
Source File: Ec2InstanceStore.java From soundwave with Apache License 2.0 | 5 votes |
@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; } }
Example #22
Source File: Ec2InstanceStore.java From soundwave with Apache License 2.0 | 5 votes |
@Override public List<Instance> getInstancesForZone(AvailabilityZone zone, AmazonEC2Client client) throws Exception { OperationStats op = new OperationStats("ec2InstanceStore", "getInstancesForZone"); try { List<Instance> ret = new ArrayList<>(); DescribeInstancesRequest request = new DescribeInstancesRequest() .withMaxResults(1000) .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 List<Reservation> reservations = new ArrayList<>(); DescribeInstancesResult result = client.describeInstances(request); while (result != null) { reservations.addAll(result.getReservations()); if (result.getNextToken() != null) { request.setNextToken(result.getNextToken()); result = client.describeInstances(request); } else { result = null; } } for (Reservation reservation : reservations) { //Reservation refers to one launch command in EC2. Most time it should //only contains one instance for (Instance inst : reservation.getInstances()) { ret.add(inst); } } op.succeed(); return ret; } catch (Exception ex) { op.failed(); throw ex; } }
Example #23
Source File: Ec2InstanceStore.java From soundwave with Apache License 2.0 | 5 votes |
@Override public List<AvailabilityZone> getAvailabilityZones(Region region) throws Exception { OperationStats op = new OperationStats("ec2InstanceStore", "getAvailabilityZones"); try { DescribeAvailabilityZonesRequest request = new DescribeAvailabilityZonesRequest(); DescribeAvailabilityZonesResult result = getClient(region).describeAvailabilityZones(); List<AvailabilityZone> ret = result.getAvailabilityZones(); op.succeed(); return ret; } catch (Exception ex) { op.failed(); throw ex; } }
Example #24
Source File: Ec2InstanceStore.java From soundwave with Apache License 2.0 | 5 votes |
@Override public List<Instance> getInstances(Region region) throws Exception { List<Instance> ret = new ArrayList<>(); List<AvailabilityZone> zones = getAvailabilityZones(region); AmazonEC2Client client = getClient(region); ExecutorService executor = Executors.newFixedThreadPool(zones.size()); try { List<Callable<List<Instance>>> retrieveFunction = new ArrayList<>(); for (AvailabilityZone zone : zones) { retrieveFunction.add(new Callable<List<Instance>>() { @Override public List<Instance> call() throws Exception { return getInstancesForZone(zone, client); } }); } List<Future<List<Instance>>> futures = executor.invokeAll(retrieveFunction); for (Future<List<Instance>> future : futures) { ret.addAll(future.get()); } } finally { executor.shutdown(); } return ret; }
Example #25
Source File: CloudInstanceStore.java From soundwave with Apache License 2.0 | 4 votes |
List<Instance> getInstancesForZone(AvailabilityZone zone, AmazonEC2Client client) throws Exception;
Example #26
Source File: AwsSubnetRequestProviderTest.java From cloudbreak with Apache License 2.0 | 4 votes |
private AvailabilityZone createAZ(String name) { AvailabilityZone availabilityZone = new AvailabilityZone(); availabilityZone.setZoneName(name); return availabilityZone; }
Example #27
Source File: CloudInstanceStore.java From soundwave with Apache License 2.0 | 4 votes |
Map<AvailabilityZone, List<Instance>> getInstancesMapForZone( AvailabilityZone zone, AmazonEC2Client client) throws Exception;
Example #28
Source File: CloudInstanceStore.java From soundwave with Apache License 2.0 | 4 votes |
Map<AvailabilityZone, List<ReservedInstances>> getReservedInstancesGroupedByZone(Region region) throws Exception;
Example #29
Source File: EncryptedSnapshotService.java From cloudbreak with Apache License 2.0 | 4 votes |
private String prepareDescribeAvailabilityZonesResult(AuthenticatedContext ac, AmazonEC2 client) { String regionName = ac.getCloudContext().getLocation().getRegion().value(); Optional<AvailabilityZone> first = client.describeAvailabilityZones(prepareDescribeAvailabilityZoneRequest(regionName)).getAvailabilityZones().stream().findFirst(); return first.map(AvailabilityZone::getZoneName).orElse(null); }
Example #30
Source File: CloudInstanceStore.java From soundwave with Apache License 2.0 | 4 votes |
Map<AvailabilityZone, List<ReservedInstances>> getReservedInstancesForZone( AvailabilityZone zone, AmazonEC2Client client) throws Exception;