use of com.amazonaws.services.s3.model.Filter in project cloudbreak by hortonworks.
the class AwsPlatformResources method securityGroups.
@Override
public CloudSecurityGroups securityGroups(ExtendedCloudCredential cloudCredential, Region region, Map<String, String> filters) {
Map<String, Set<CloudSecurityGroup>> result = new HashMap<>();
Set<CloudSecurityGroup> cloudSecurityGroups = new HashSet<>();
AmazonEc2Client ec2Client = awsClient.createEc2Client(new AwsCredentialView(cloudCredential), region.value());
// create securitygroup filter view
PlatformResourceSecurityGroupFilterView filter = new PlatformResourceSecurityGroupFilterView(filters);
DescribeSecurityGroupsRequest describeSecurityGroupsRequest = new DescribeSecurityGroupsRequest();
// If the filtervalue is provided then we should filter only for those securitygroups
if (!Strings.isNullOrEmpty(filter.getVpcId())) {
describeSecurityGroupsRequest.withFilters(new Filter("vpc-id", singletonList(filter.getVpcId())));
}
if (!Strings.isNullOrEmpty(filter.getGroupId())) {
describeSecurityGroupsRequest.withGroupIds(filter.getGroupId());
}
if (!Strings.isNullOrEmpty(filter.getGroupName())) {
describeSecurityGroupsRequest.withGroupNames(filter.getGroupName());
}
for (SecurityGroup securityGroup : fetchSecurityGroups(ec2Client, describeSecurityGroupsRequest)) {
Map<String, Object> properties = new HashMap<>();
properties.put("vpcId", securityGroup.getVpcId());
properties.put("description", securityGroup.getDescription());
properties.put("ipPermissions", securityGroup.getIpPermissions());
properties.put("ipPermissionsEgress", securityGroup.getIpPermissionsEgress());
cloudSecurityGroups.add(new CloudSecurityGroup(securityGroup.getGroupName(), securityGroup.getGroupId(), properties));
}
result.put(region.value(), cloudSecurityGroups);
return new CloudSecurityGroups(result);
}
use of com.amazonaws.services.s3.model.Filter in project cloudbreak by hortonworks.
the class AwsPlatformResources method getDescribeAvailabilityZonesRequest.
private DescribeAvailabilityZonesRequest getDescribeAvailabilityZonesRequest(com.amazonaws.services.ec2.model.Region awsRegion) {
DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest = new DescribeAvailabilityZonesRequest();
Filter filter = new Filter();
filter.setName("region-name");
Collection<String> list = new ArrayList<>();
list.add(awsRegion.getRegionName());
filter.setValues(list);
describeAvailabilityZonesRequest.withFilters(filter);
return describeAvailabilityZonesRequest;
}
use of com.amazonaws.services.s3.model.Filter 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);
}
use of com.amazonaws.services.s3.model.Filter in project cloudbreak by hortonworks.
the class AwsPlatformResources method getSubnets.
private List<Subnet> getSubnets(AmazonEc2Client ec2Client, Vpc vpc) {
List<Subnet> awsSubnets = new ArrayList<>();
DescribeSubnetsResult describeSubnetsResult = null;
do {
LOGGER.debug("Describing subnets for VPC {}{}", vpc.getVpcId(), describeSubnetsResult == null ? "" : " (continuation)");
DescribeSubnetsRequest describeSubnetsRequest = createSubnetsDescribeRequest(vpc, describeSubnetsResult == null ? null : describeSubnetsResult.getNextToken());
describeSubnetsResult = ec2Client.describeSubnets(describeSubnetsRequest);
describeSubnetsResult.getSubnets().stream().filter(subnet -> enabledAvailabilityZones.contains(availabilityZone(subnet.getAvailabilityZone()))).forEach(awsSubnets::add);
} while (!isNullOrEmpty(describeSubnetsResult.getNextToken()));
return awsSubnets;
}
use of com.amazonaws.services.s3.model.Filter in project cloudbreak by hortonworks.
the class AwsPlatformResources method collectInstanceStorageCount.
public InstanceStoreMetadata collectInstanceStorageCount(AuthenticatedContext ac, List<String> instanceTypes, List<String> entitlements) {
Location location = ac.getCloudContext().getLocation();
try {
String accountId = ac.getCloudContext().getAccountId();
ExtendedCloudCredential extendedCloudCredential = new ExtendedCloudCredential(ac.getCloudCredential(), ac.getCloudContext().getPlatform().value(), "", ac.getCloudContext().getCrn(), accountId, entitlements);
CloudVmTypes cloudVmTypes = virtualMachines(extendedCloudCredential, location.getRegion(), Map.of());
Map<String, Set<VmType>> cloudVmResponses = cloudVmTypes.getCloudVmResponses();
Map<String, VolumeParameterConfig> instanceTypeToInstanceStorageMap = cloudVmResponses.getOrDefault(location.getAvailabilityZone().value(), Set.of()).stream().filter(vmType -> instanceTypes.contains(vmType.value())).filter(vmType -> Objects.nonNull(vmType.getMetaData().getEphemeralConfig())).collect(Collectors.toMap(VmType::value, vmType -> vmType.getMetaData().getEphemeralConfig()));
return new InstanceStoreMetadata(instanceTypeToInstanceStorageMap);
} catch (Exception e) {
LOGGER.warn("Failed to get vm type data: {}", instanceTypes, e);
throw new CloudConnectorException(e.getMessage(), e);
}
}
Aggregations