use of com.sequenceiq.cloudbreak.cloud.model.CloudRegions in project cloudbreak by hortonworks.
the class AwsPlatformResources method gateways.
@Override
public CloudGateWays gateways(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
AmazonEC2Client ec2Client = awsClient.createAccess(cloudCredential);
Map<String, Set<CloudGateWay>> resultCloudGateWayMap = new HashMap<>();
CloudRegions regions = regions(cloudCredential, region, filters);
for (Entry<Region, List<AvailabilityZone>> regionListEntry : regions.getCloudRegions().entrySet()) {
if (region == null || Strings.isNullOrEmpty(region.value()) || regionListEntry.getKey().value().equals(region.value())) {
ec2Client.setRegion(RegionUtils.getRegion(regionListEntry.getKey().value()));
DescribeInternetGatewaysRequest describeInternetGatewaysRequest = new DescribeInternetGatewaysRequest();
DescribeInternetGatewaysResult describeInternetGatewaysResult = ec2Client.describeInternetGateways(describeInternetGatewaysRequest);
Set<CloudGateWay> gateWays = new HashSet<>();
for (InternetGateway internetGateway : describeInternetGatewaysResult.getInternetGateways()) {
CloudGateWay cloudGateWay = new CloudGateWay();
cloudGateWay.setId(internetGateway.getInternetGatewayId());
cloudGateWay.setName(internetGateway.getInternetGatewayId());
Collection<String> vpcs = new ArrayList<>();
for (InternetGatewayAttachment internetGatewayAttachment : internetGateway.getAttachments()) {
vpcs.add(internetGatewayAttachment.getVpcId());
}
Map<String, Object> properties = new HashMap<>();
properties.put("attachment", vpcs);
cloudGateWay.setProperties(properties);
gateWays.add(cloudGateWay);
}
for (AvailabilityZone availabilityZone : regionListEntry.getValue()) {
resultCloudGateWayMap.put(availabilityZone.value(), gateWays);
}
}
}
return new CloudGateWays(resultCloudGateWayMap);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudRegions 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);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudRegions in project cloudbreak by hortonworks.
the class PlatformParameterV2Controller method getRegionsByCredentialId.
@Override
public RegionResponse getRegionsByCredentialId(PlatformResourceRequestJson resourceRequestJson) {
resourceRequestJson = prepareAccountAndOwner(resourceRequestJson, authenticatedUserService.getCbUser());
PlatformResourceRequest convert = conversionService.convert(resourceRequestJson, PlatformResourceRequest.class);
CloudRegions cloudRegions = cloudParameterService.getRegionsV2(convert.getCredential(), convert.getRegion(), convert.getPlatformVariant(), convert.getFilters());
return conversionService.convert(cloudRegions, RegionResponse.class);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudRegions in project cloudbreak by hortonworks.
the class GcpPlatformResources method virtualMachines.
@Override
@Cacheable(cacheNames = "cloudResourceVmTypeCache", key = "#cloudCredential?.id + #region.getRegionName()")
public CloudVmTypes virtualMachines(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
Compute compute = GcpStackUtil.buildCompute(cloudCredential);
String projectId = GcpStackUtil.getProjectId(cloudCredential);
Map<String, Set<VmType>> cloudVmResponses = new HashMap<>();
Map<String, VmType> defaultCloudVmResponses = new HashMap<>();
try {
Set<VmType> types = new HashSet<>();
VmType defaultVmType = null;
CloudRegions regions = regions(cloudCredential, region, filters);
for (AvailabilityZone availabilityZone : regions.getCloudRegions().get(region)) {
MachineTypeList machineTypeList = compute.machineTypes().list(projectId, availabilityZone.value()).execute();
for (MachineType machineType : machineTypeList.getItems()) {
VmTypeMeta vmTypeMeta = VmTypeMetaBuilder.builder().withCpuAndMemory(machineType.getGuestCpus(), machineType.getMemoryMb().floatValue() / THOUSAND).withMagneticConfig(TEN, machineType.getMaximumPersistentDisksSizeGb().intValue(), 1, machineType.getMaximumPersistentDisksSizeGb().intValue()).withSsdConfig(TEN, machineType.getMaximumPersistentDisksSizeGb().intValue(), 1, machineType.getMaximumPersistentDisks()).withMaximumPersistentDisksSizeGb(machineType.getMaximumPersistentDisksSizeGb().toString()).create();
VmType vmType = VmType.vmTypeWithMeta(machineType.getName(), vmTypeMeta, true);
types.add(vmType);
if (machineType.getName().equals(gcpVmDefault)) {
defaultVmType = vmType;
}
}
cloudVmResponses.put(availabilityZone.value(), types);
defaultCloudVmResponses.put(availabilityZone.value(), defaultVmType);
}
return new CloudVmTypes(cloudVmResponses, defaultCloudVmResponses);
} catch (Exception e) {
return new CloudVmTypes(new HashMap<>(), new HashMap<>());
}
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudRegions in project cloudbreak by hortonworks.
the class GcpPlatformResources method regions.
@Override
@Cacheable(cacheNames = "cloudResourceRegionCache", key = "#cloudCredential?.id")
public CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters) throws Exception {
Compute compute = GcpStackUtil.buildCompute(cloudCredential);
String projectId = GcpStackUtil.getProjectId(cloudCredential);
Map<Region, List<AvailabilityZone>> regionListMap = new HashMap<>();
Map<Region, String> displayNames = new HashMap<>();
String defaultRegion = gcpZoneParameterDefault;
RegionList regionList = compute.regions().list(projectId).execute();
for (com.google.api.services.compute.model.Region gcpRegion : regionList.getItems()) {
if (region == null || Strings.isNullOrEmpty(region.value()) || gcpRegion.getName().equals(region.value())) {
List<AvailabilityZone> availabilityZones = new ArrayList<>();
for (String s : gcpRegion.getZones()) {
String[] split = s.split("/");
if (split.length > 0) {
availabilityZones.add(AvailabilityZone.availabilityZone(split[split.length - 1]));
}
}
regionListMap.put(region(gcpRegion.getName()), availabilityZones);
displayNames.put(region(gcpRegion.getName()), displayName(gcpRegion.getName()));
}
}
if (region != null && !Strings.isNullOrEmpty(region.value())) {
defaultRegion = region.value();
}
return new CloudRegions(regionListMap, displayNames, defaultRegion);
}
Aggregations