Search in sources :

Example 6 with AvailabilityZone

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());
}
Also used : ZoneService(org.openstack4j.api.compute.ext.ZoneService) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ComputeService(org.openstack4j.api.compute.ComputeService) Test(org.junit.Test)

Example 7 with AvailabilityZone

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;
}
Also used : RegionResponse(com.sequenceiq.cloudbreak.api.model.RegionResponse) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 8 with AvailabilityZone

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);
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) DescribeInternetGatewaysResult(com.amazonaws.services.ec2.model.DescribeInternetGatewaysResult) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CloudGateWays(com.sequenceiq.cloudbreak.cloud.model.CloudGateWays) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) InternetGatewayAttachment(com.amazonaws.services.ec2.model.InternetGatewayAttachment) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) DescribeInternetGatewaysRequest(com.amazonaws.services.ec2.model.DescribeInternetGatewaysRequest) CloudGateWay(com.sequenceiq.cloudbreak.cloud.model.CloudGateWay) InternetGateway(com.amazonaws.services.ec2.model.InternetGateway) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 9 with AvailabilityZone

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);
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) HashMap(java.util.HashMap) DescribeAvailabilityZonesRequest(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest) ArrayList(java.util.ArrayList) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) DescribeRegionsRequest(com.amazonaws.services.ec2.model.DescribeRegionsRequest) DescribeAvailabilityZonesResult(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult) DescribeRegionsResult(com.amazonaws.services.ec2.model.DescribeRegionsResult) Filter(com.amazonaws.services.ec2.model.Filter) DisplayName(com.sequenceiq.cloudbreak.cloud.model.DisplayName) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 10 with AvailabilityZone

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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Region(com.sequenceiq.cloudbreak.cloud.model.Region) RegionSpecification(com.sequenceiq.cloudbreak.cloud.model.RegionSpecification) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) ArrayList(java.util.ArrayList) List(java.util.List) StringTypesCompare(com.sequenceiq.cloudbreak.cloud.model.StringTypesCompare) RegionsSpecification(com.sequenceiq.cloudbreak.cloud.model.RegionsSpecification) IOException(java.io.IOException)

Aggregations

AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)17 HashMap (java.util.HashMap)13 List (java.util.List)10 Region (com.sequenceiq.cloudbreak.cloud.model.Region)9 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)8 HashSet (java.util.HashSet)7 ArrayList (java.util.ArrayList)6 Set (java.util.Set)6 Cacheable (org.springframework.cache.annotation.Cacheable)5 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)4 Test (org.junit.Test)4 VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)3 IOException (java.io.IOException)3 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)2 Compute (com.google.api.services.compute.Compute)2 MachineTypeList (com.google.api.services.compute.model.MachineTypeList)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 CloudGateWay (com.sequenceiq.cloudbreak.cloud.model.CloudGateWay)2 CloudGateWays (com.sequenceiq.cloudbreak.cloud.model.CloudGateWays)2 Collections.singletonList (java.util.Collections.singletonList)2