use of com.sequenceiq.cloudbreak.cloud.model.network.SubnetType.PRIVATE 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.sequenceiq.cloudbreak.cloud.model.network.SubnetType.PRIVATE 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.sequenceiq.cloudbreak.cloud.model.network.SubnetType.PRIVATE in project cloudbreak by hortonworks.
the class AwsPlatformResources method readRegionCoordinates.
private Map<Region, Coordinate> readRegionCoordinates(String displayNames) {
Map<Region, Coordinate> regionCoordinates = new HashMap<>();
try {
RegionCoordinateSpecifications regionCoordinateSpecifications = JsonUtil.readValue(displayNames, RegionCoordinateSpecifications.class);
for (RegionCoordinateSpecification regionCoordinateSpecification : regionCoordinateSpecifications.getItems()) {
Region region = region(regionCoordinateSpecification.getName());
if (!enabledRegions.contains(region)) {
continue;
}
Optional<Entry<Region, DisplayName>> regionEntry = regionDisplayNames.entrySet().stream().filter(e -> e.getKey().getRegionName().equalsIgnoreCase(regionCoordinateSpecification.getName())).findFirst();
regionCoordinates.put(region, coordinate(regionCoordinateSpecification.getLongitude(), regionCoordinateSpecification.getLatitude(), regionCoordinateSpecification.getDisplayName(), regionEntry.isPresent() ? regionEntry.get().getKey().value() : regionCoordinateSpecification.getDisplayName(), regionCoordinateSpecification.isK8sSupported(), regionCoordinateSpecification.getEntitlements()));
}
} catch (IOException ignored) {
return regionCoordinates;
}
return regionCoordinates;
}
use of com.sequenceiq.cloudbreak.cloud.model.network.SubnetType.PRIVATE in project cloudbreak by hortonworks.
the class GcpPlatformResources method networks.
@Override
public CloudNetworks networks(ExtendedCloudCredential cloudCredential, Region region, Map<String, String> filters) throws Exception {
Compute compute = gcpComputeFactory.buildCompute(cloudCredential);
String projectId = gcpStackUtil.getProjectId(cloudCredential);
Map<String, Set<CloudNetwork>> result = new HashMap<>();
String networkId = null;
List<String> subnetIds = new ArrayList<>();
String sharedProjectId = null;
if (filters != null) {
networkId = filters.getOrDefault("networkId", null);
subnetIds = getSubnetIds(filters);
sharedProjectId = filters.getOrDefault("sharedProjectId", null);
}
LOGGER.debug("Get subnets with filter values, networkId : {}, subnetId : {}", networkId, subnetIds);
Set<CloudNetwork> cloudNetworks = new HashSet<>();
NetworkList networkList = getNetworkList(compute, projectId, networkId, sharedProjectId);
SubnetworkList subnetworkList = getSubnetworkList(region, compute, projectId, subnetIds, sharedProjectId);
// GCP VPCs are global. Subnets have a global scope in region. So picking the first availability zone in the region for subnet.
String zone = compute.regions().get(projectId, region.value()).execute().getZones().stream().findFirst().map(tmpZone -> tmpZone.substring(tmpZone.lastIndexOf('/') + 1)).orElse(null);
LOGGER.debug("Zone chosen for the subnets is {}", zone);
for (Network network : networkList.getItems()) {
Map<String, Object> properties = new HashMap<>();
properties.put("gatewayIPv4", Strings.nullToEmpty(network.getGatewayIPv4()));
properties.put("description", Strings.nullToEmpty(network.getDescription()));
properties.put("IPv4Range", Strings.nullToEmpty(network.getIPv4Range()));
properties.put("creationTimestamp", Strings.nullToEmpty(network.getCreationTimestamp()));
Set<CloudSubnet> subnets = new HashSet<>();
if (subnetworkList != null && network.getSubnetworks() != null && subnetworkList.getItems() != null) {
for (Subnetwork subnetwork : subnetworkList.getItems()) {
if (network.getSubnetworks().contains(subnetwork.getSelfLink())) {
boolean igwAvailable = !Strings.isNullOrEmpty(subnetwork.getGatewayAddress());
subnets.add(new CloudSubnet(subnetwork.getId().toString(), subnetwork.getName(), zone, subnetwork.getIpCidrRange(), subnetwork.getPrivateIpGoogleAccess(), !subnetwork.getPrivateIpGoogleAccess(), igwAvailable, igwAvailable ? PUBLIC : PRIVATE));
}
}
}
CloudNetwork cloudNetwork = new CloudNetwork(network.getName(), network.getId().toString(), subnets, properties);
cloudNetworks.add(cloudNetwork);
}
result.put(region.value(), cloudNetworks);
return new CloudNetworks(result);
}
use of com.sequenceiq.cloudbreak.cloud.model.network.SubnetType.PRIVATE in project cloudbreak by hortonworks.
the class AwsPlatformResources method readEnabledRegionsAndAvailabilityZones.
private void readEnabledRegionsAndAvailabilityZones() {
try {
String fileName = resourceDefinition(ENABLED_AVAILABILITY_ZONES_FILE);
RegionsSpecification regionCoordinateSpecifications = JsonUtil.readValue(fileName, RegionsSpecification.class);
enabledRegions = regionCoordinateSpecifications.getItems().stream().map(RegionSpecification::getName).map(Region::region).collect(Collectors.toSet());
enabledAvailabilityZones = regionCoordinateSpecifications.getItems().stream().flatMap(region -> region.getZones().stream()).map(AvailabilityZone::availabilityZone).collect(Collectors.toSet());
} catch (IOException e) {
LOGGER.error("Failed to read enabled AWS regions and availability zones from file.", e);
enabledRegions = new HashSet<>();
enabledAvailabilityZones = new HashSet<>();
}
}
Aggregations