Search in sources :

Example 1 with Region

use of com.sequenceiq.cloudbreak.cloud.model.Region in project cloudbreak by hortonworks.

the class OpenStackPlatformResources method regions.

@Override
@Cacheable(cacheNames = "cloudResourceRegionCache", key = "#cloudCredential?.id")
public CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    Set<String> regionsFromOpenStack = openStackClient.getRegion(cloudCredential);
    OSClient<?> osClient = openStackClient.createOSClient(cloudCredential);
    Map<Region, List<AvailabilityZone>> cloudRegions = new HashMap<>();
    Map<Region, String> displayNames = new HashMap<>();
    for (String regionFromOpenStack : regionsFromOpenStack) {
        List<AvailabilityZone> availabilityZones = openStackClient.getZones(osClient, regionFromOpenStack);
        cloudRegions.put(region(regionFromOpenStack), availabilityZones);
        displayNames.put(region(regionFromOpenStack), regionFromOpenStack);
    }
    String defaultRegion = null;
    if (!cloudRegions.keySet().isEmpty()) {
        defaultRegion = ((StringType) cloudRegions.keySet().toArray()[0]).value();
    }
    CloudRegions regions = new CloudRegions(cloudRegions, displayNames, defaultRegion);
    LOGGER.info("openstack regions result: {}", regions);
    return regions;
}
Also used : HashMap(java.util.HashMap) Region(com.sequenceiq.cloudbreak.cloud.model.Region) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) List(java.util.List) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 2 with Region

use of com.sequenceiq.cloudbreak.cloud.model.Region in project cloudbreak by hortonworks.

the class OpenStackPlatformResources method gateways.

@Override
public CloudGateWays gateways(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    OSClient<?> osClient = openStackClient.createOSClient(cloudCredential);
    Map<String, Set<CloudGateWay>> resultCloudGateWayMap = new HashMap<>();
    CloudRegions regions = regions(cloudCredential, region, filters);
    for (Entry<Region, List<AvailabilityZone>> regionListEntry : regions.getCloudRegions().entrySet()) {
        Set<CloudGateWay> cloudGateWays = new HashSet<>();
        List<? extends Router> routerList = osClient.networking().router().list();
        LOGGER.info("routers from openstack: {}", routerList);
        for (Router router : routerList) {
            CloudGateWay cloudGateWay = new CloudGateWay();
            cloudGateWay.setId(router.getId());
            cloudGateWay.setName(router.getName());
            Map<String, Object> properties = new HashMap<>();
            properties.put("tenantId", router.getTenantId());
            cloudGateWay.setProperties(properties);
            cloudGateWays.add(cloudGateWay);
        }
        for (AvailabilityZone availabilityZone : regionListEntry.getValue()) {
            resultCloudGateWayMap.put(availabilityZone.value(), cloudGateWays);
        }
    }
    CloudGateWays cloudGateWays = new CloudGateWays(resultCloudGateWayMap);
    LOGGER.info("openstack cloudgateway result: {}", cloudGateWays);
    return cloudGateWays;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) CloudGateWays(com.sequenceiq.cloudbreak.cloud.model.CloudGateWays) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) Router(org.openstack4j.model.network.Router) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) CloudGateWay(com.sequenceiq.cloudbreak.cloud.model.CloudGateWay) Region(com.sequenceiq.cloudbreak.cloud.model.Region) List(java.util.List) HashSet(java.util.HashSet)

Example 3 with Region

use of com.sequenceiq.cloudbreak.cloud.model.Region 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 4 with Region

use of com.sequenceiq.cloudbreak.cloud.model.Region 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 5 with Region

use of com.sequenceiq.cloudbreak.cloud.model.Region in project cloudbreak by hortonworks.

the class AwsPlatformResources method sshKeys.

@Override
public CloudSshKeys sshKeys(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    Map<String, Set<CloudSshKey>> result = new HashMap<>();
    for (Region actualRegion : regions(cloudCredential, region, new HashMap<>()).getCloudRegions().keySet()) {
        // If region is provided then should filter for those region
        if (regionMatch(actualRegion, region)) {
            Set<CloudSshKey> cloudSshKeys = new HashSet<>();
            AmazonEC2Client ec2Client = awsClient.createAccess(new AwsCredentialView(cloudCredential), actualRegion.value());
            // create sshkey filter view
            PlatformResourceSshKeyFilterView filter = new PlatformResourceSshKeyFilterView(filters);
            DescribeKeyPairsRequest describeKeyPairsRequest = new DescribeKeyPairsRequest();
            // If the filtervalue is provided then we should filter only for those securitygroups
            if (!Strings.isNullOrEmpty(filter.getKeyName())) {
                describeKeyPairsRequest.withKeyNames(filter.getKeyName());
            }
            for (KeyPairInfo keyPairInfo : ec2Client.describeKeyPairs(describeKeyPairsRequest).getKeyPairs()) {
                Map<String, Object> properties = new HashMap<>();
                properties.put("fingerPrint", keyPairInfo.getKeyFingerprint());
                cloudSshKeys.add(new CloudSshKey(keyPairInfo.getKeyName(), properties));
            }
            result.put(actualRegion.value(), cloudSshKeys);
        }
    }
    return new CloudSshKeys(result);
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) PlatformResourceSshKeyFilterView(com.sequenceiq.cloudbreak.cloud.model.view.PlatformResourceSshKeyFilterView) Set(java.util.Set) HashSet(java.util.HashSet) DescribeKeyPairsRequest(com.amazonaws.services.ec2.model.DescribeKeyPairsRequest) KeyPairInfo(com.amazonaws.services.ec2.model.KeyPairInfo) HashMap(java.util.HashMap) CloudSshKeys(com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys) CloudSshKey(com.sequenceiq.cloudbreak.cloud.model.CloudSshKey) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) Region(com.sequenceiq.cloudbreak.cloud.model.Region) HashSet(java.util.HashSet)

Aggregations

Region (com.sequenceiq.cloudbreak.cloud.model.Region)16 HashMap (java.util.HashMap)14 List (java.util.List)13 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)12 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)10 ArrayList (java.util.ArrayList)10 HashSet (java.util.HashSet)9 Set (java.util.Set)8 Cacheable (org.springframework.cache.annotation.Cacheable)7 CloudGateWays (com.sequenceiq.cloudbreak.cloud.model.CloudGateWays)5 CloudIpPools (com.sequenceiq.cloudbreak.cloud.model.CloudIpPools)4 CloudNetwork (com.sequenceiq.cloudbreak.cloud.model.CloudNetwork)4 CloudSshKeys (com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys)4 VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)4 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)3 Strings (com.google.common.base.Strings)3 PlatformResources (com.sequenceiq.cloudbreak.cloud.PlatformResources)3 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)3 CloudAccessConfigs (com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs)3 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)3