use of com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone in project cloudbreak by hortonworks.
the class OpenStackClientTest method testGetZones.
@Test
public void testGetZones() {
OSClient<?> osClient = mock(OSClient.class);
ComputeService computeService = mock(ComputeService.class);
ZoneService zoneService = mock(ZoneService.class);
List availabilityZones = newArrayList(availabilityZone("zone1"));
when(osClient.compute()).thenReturn(computeService);
when(computeService.zones()).thenReturn(zoneService);
when(zoneService.list()).thenReturn(availabilityZones);
List<AvailabilityZone> actual = underTest.getZones(osClient, "region");
Assert.assertEquals(1, actual.size());
Assert.assertEquals("zone1", actual.get(0).value());
}
use of com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone in project cloudbreak by hortonworks.
the class PlatformRegionsToRegionResponseConverter method convert.
@Override
public RegionResponse convert(CloudRegions source) {
RegionResponse json = new RegionResponse();
Set<String> regions = new HashSet<>();
for (Region region : source.getCloudRegions().keySet()) {
regions.add(region.value());
}
Map<String, Collection<String>> availabilityZones = new HashMap<>();
for (Entry<Region, List<AvailabilityZone>> regionListEntry : source.getCloudRegions().entrySet()) {
Collection<String> azs = new ArrayList<>();
for (AvailabilityZone availabilityZone : regionListEntry.getValue()) {
azs.add(availabilityZone.value());
}
availabilityZones.put(regionListEntry.getKey().value(), azs);
}
Map<String, String> displayNames = new HashMap<>();
for (Entry<Region, String> regionStringEntry : source.getDisplayNames().entrySet()) {
displayNames.put(regionStringEntry.getKey().value(), regionStringEntry.getValue());
}
json.setRegions(regions);
json.setAvailabilityZones(availabilityZones);
json.setDefaultRegion(source.getDefaultRegion());
json.setDisplayNames(displayNames);
return json;
}
use of com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone 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.AvailabilityZone 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.AvailabilityZone in project cloudbreak by hortonworks.
the class PlatformParameters method readRegions.
default Map<Region, List<AvailabilityZone>> readRegions(String zone) {
Map<Region, List<AvailabilityZone>> regions = new HashMap<>();
try {
RegionsSpecification oRegions = JsonUtil.readValue(zone, RegionsSpecification.class);
for (RegionSpecification regionSpecification : oRegions.getItems()) {
List<AvailabilityZone> av = new ArrayList<>();
for (String s : regionSpecification.getZones()) {
av.add(AvailabilityZone.availabilityZone(s));
}
av.sort(new StringTypesCompare());
regions.put(Region.region(regionSpecification.getName()), av);
}
} catch (IOException ignored) {
return regions;
}
return sortMap(regions);
}
Aggregations