use of com.amazonaws.services.ec2.model.DescribeRegionsRequest in project cloudbreak by hortonworks.
the class AwsCredentialConnector method verifyAccessKeySecretKeyIsAssumable.
private CloudCredentialStatus verifyAccessKeySecretKeyIsAssumable(CloudCredential cloudCredential) {
AwsCredentialView awsCredential = new AwsCredentialView(cloudCredential);
try {
AmazonEC2Client access = awsClient.createAccess(cloudCredential);
DescribeRegionsRequest describeRegionsRequest = new DescribeRegionsRequest();
access.describeRegions(describeRegionsRequest);
} catch (AmazonClientException ae) {
String errorMessage = "Unable to verify AWS credentials: please make sure the access key and secret key is correct";
LOGGER.error(errorMessage, ae);
return new CloudCredentialStatus(cloudCredential, CredentialStatus.FAILED, ae, errorMessage);
} catch (RuntimeException e) {
String errorMessage = String.format("Could not verify keys '%s': check if the keys exists and if it's created with the correct external ID", awsCredential.getAccessKey());
LOGGER.error(errorMessage, e);
return new CloudCredentialStatus(cloudCredential, CredentialStatus.FAILED, e, errorMessage);
}
return new CloudCredentialStatus(cloudCredential, CredentialStatus.CREATED);
}
use of com.amazonaws.services.ec2.model.DescribeRegionsRequest in project photon-model by vmware.
the class AWSReservedInstancePlanService method getRegionAsyncHandler.
private AsyncHandler<DescribeRegionsRequest, DescribeRegionsResult> getRegionAsyncHandler(AWSReservedInstanceContext context) {
AWSReservedInstancePlanService service = this;
return new AsyncHandler<DescribeRegionsRequest, DescribeRegionsResult>() {
@Override
public void onError(Exception e) {
log(Level.WARNING, "Error while fetching the regions for compute " + context.computeDesc.documentSelfLink + " " + Utils.toString(e));
}
@Override
public void onSuccess(DescribeRegionsRequest request, DescribeRegionsResult describeRegionsResult) {
List<Region> regions = describeRegionsResult.getRegions();
if (CollectionUtils.isEmpty(regions)) {
log(Level.INFO, "No regions exist for compute" + context.computeDesc.documentSelfLink);
return;
}
AtomicInteger currentStageTaskCount = new AtomicInteger(regions.size());
/*
* Fetch all the regions from AWS and collect reserved instances plans for
* only those regions which are supported by SDK.
*/
for (Region region : regions) {
try {
Regions r = Regions.fromName(region.getRegionName());
if (r == null) {
new AWSReservedInstanceAsyncHandler(service.getHost(), currentStageTaskCount, region, context).checkAndPatchReservedInstancesPlans();
continue;
}
} catch (Exception e) {
log(Level.WARNING, e.getMessage());
new AWSReservedInstanceAsyncHandler(service.getHost(), currentStageTaskCount, region, context).checkAndPatchReservedInstancesPlans();
continue;
}
service.ec2ClientManager.getOrCreateEC2ClientAsync(context.parentAuth, region.getRegionName(), service).whenComplete((ec2Client, t) -> {
if (t != null) {
getFailureConsumer(context, "Error while creating EC2 client for").accept(t);
new AWSReservedInstanceAsyncHandler(service.getHost(), currentStageTaskCount, region, context).checkAndPatchReservedInstancesPlans();
logWarning("client is null for region %s for compute %s", region.getRegionName(), context.computeDesc.documentSelfLink);
return;
}
ec2Client.describeReservedInstancesAsync(new AWSReservedInstanceAsyncHandler(service.getHost(), currentStageTaskCount, region, context));
});
}
}
};
}
use of com.amazonaws.services.ec2.model.DescribeRegionsRequest in project cloudbreak by hortonworks.
the class AwsPlatformResources method regions.
@Override
@Cacheable(cacheNames = "cloudResourceRegionCache", key = "#cloudCredential?.id")
public CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
AmazonEC2Client ec2Client = awsClient.createAccess(cloudCredential);
Map<Region, List<AvailabilityZone>> regionListMap = new HashMap<>();
Map<Region, String> displayNames = new HashMap<>();
DescribeRegionsRequest describeRegionsRequest = new DescribeRegionsRequest();
DescribeRegionsResult describeRegionsResult = ec2Client.describeRegions(describeRegionsRequest);
String defaultRegion = awsZoneParameterDefault;
for (com.amazonaws.services.ec2.model.Region awsRegion : describeRegionsResult.getRegions()) {
if (region == null || Strings.isNullOrEmpty(region.value()) || awsRegion.getRegionName().equals(region.value())) {
DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest = new DescribeAvailabilityZonesRequest();
ec2Client.setRegion(RegionUtils.getRegion(awsRegion.getRegionName()));
Filter filter = new Filter();
filter.setName("region-name");
Collection<String> list = new ArrayList<>();
list.add(awsRegion.getRegionName());
filter.setValues(list);
describeAvailabilityZonesRequest.withFilters(filter);
DescribeAvailabilityZonesResult describeAvailabilityZonesResult = ec2Client.describeAvailabilityZones(describeAvailabilityZonesRequest);
List<AvailabilityZone> tmpAz = new ArrayList<>();
for (com.amazonaws.services.ec2.model.AvailabilityZone availabilityZone : describeAvailabilityZonesResult.getAvailabilityZones()) {
tmpAz.add(availabilityZone(availabilityZone.getZoneName()));
}
regionListMap.put(region(awsRegion.getRegionName()), tmpAz);
DisplayName displayName = regionDisplayNames.get(region(awsRegion.getRegionName()));
if (displayName == null || Strings.isNullOrEmpty(displayName.value())) {
displayNames.put(region(awsRegion.getRegionName()), awsRegion.getRegionName());
} else {
displayNames.put(region(awsRegion.getRegionName()), displayName.value());
}
}
}
if (region != null && !Strings.isNullOrEmpty(region.value())) {
defaultRegion = region.value();
}
return new CloudRegions(regionListMap, displayNames, defaultRegion);
}
Aggregations