use of com.amazonaws.services.ec2.model.DescribeInstanceTypesRequest in project cloudbreak by hortonworks.
the class AwsPlatformResources method getCloudVmTypes.
private CloudVmTypes getCloudVmTypes(ExtendedCloudCredential cloudCredential, Region region, Map<String, String> filters, Predicate<VmType> enabledInstanceTypeFilter, boolean enableMinimalHardwareFilter) {
Map<String, Set<VmType>> cloudVmResponses = new HashMap<>();
Map<String, VmType> defaultCloudVmResponses = new HashMap<>();
if (region != null && !Strings.isNullOrEmpty(region.value())) {
CloudRegions regions = regions(cloudCredential, region, filters, true);
AwsCredentialView awsCredentialView = new AwsCredentialView(cloudCredential);
AmazonEc2Client ec2Client = awsClient.createEc2Client(awsCredentialView, region.getRegionName());
List<String> instanceTypes = ec2Client.describeInstanceTypeOfferings(getOfferingsRequest(region)).getInstanceTypeOfferings().stream().map(e -> e.getInstanceType()).collect(Collectors.toList());
Set<VmType> awsInstances = new HashSet<>();
for (int actualSegment = 0; actualSegment < instanceTypes.size(); actualSegment += SEGMENT) {
DescribeInstanceTypesRequest request = new DescribeInstanceTypesRequest();
request.setInstanceTypes(getInstanceTypes(instanceTypes, actualSegment));
getVmTypesWithAwsCall(awsInstances, ec2Client.describeInstanceTypes(request));
}
if (enableMinimalHardwareFilter) {
awsInstances = awsInstances.stream().filter(e -> minimalHardwareFilter.suitableAsMinimumHardware(e.getMetaData().getCPU(), e.getMetaData().getMemoryInGb())).collect(Collectors.toSet());
}
fillUpAvailabilityZones(region, enabledInstanceTypeFilter, regions, cloudVmResponses, defaultCloudVmResponses, awsInstances);
filterInstancesByFilters(enabledInstanceTypeFilter, cloudVmResponses);
}
return new CloudVmTypes(cloudVmResponses, defaultCloudVmResponses);
}
Aggregations