Search in sources :

Example 1 with CloudGateWay

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

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

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

the class CloudGatewayssToPlatformGatewaysResponseConverter method convert.

@Override
public PlatformGatewaysResponse convert(CloudGateWays source) {
    Map<String, Set<CloudGatewayJson>> result = new HashMap<>();
    for (Entry<String, Set<CloudGateWay>> entry : source.getCloudGateWayResponses().entrySet()) {
        Set<CloudGatewayJson> cloudGatewayJsons = new HashSet<>();
        for (CloudGateWay gateway : entry.getValue()) {
            CloudGatewayJson actual = new CloudGatewayJson(gateway.getName(), gateway.getId(), gateway.getProperties());
            cloudGatewayJsons.add(actual);
        }
        result.put(entry.getKey(), cloudGatewayJsons);
    }
    return new PlatformGatewaysResponse(result);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) CloudGatewayJson(com.sequenceiq.cloudbreak.api.model.CloudGatewayJson) PlatformGatewaysResponse(com.sequenceiq.cloudbreak.api.model.PlatformGatewaysResponse) HashSet(java.util.HashSet) CloudGateWay(com.sequenceiq.cloudbreak.cloud.model.CloudGateWay)

Aggregations

CloudGateWay (com.sequenceiq.cloudbreak.cloud.model.CloudGateWay)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)2 CloudGateWays (com.sequenceiq.cloudbreak.cloud.model.CloudGateWays)2 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)2 Region (com.sequenceiq.cloudbreak.cloud.model.Region)2 List (java.util.List)2 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)1 DescribeInternetGatewaysRequest (com.amazonaws.services.ec2.model.DescribeInternetGatewaysRequest)1 DescribeInternetGatewaysResult (com.amazonaws.services.ec2.model.DescribeInternetGatewaysResult)1 InternetGateway (com.amazonaws.services.ec2.model.InternetGateway)1 InternetGatewayAttachment (com.amazonaws.services.ec2.model.InternetGatewayAttachment)1 CloudGatewayJson (com.sequenceiq.cloudbreak.api.model.CloudGatewayJson)1 PlatformGatewaysResponse (com.sequenceiq.cloudbreak.api.model.PlatformGatewaysResponse)1 ArrayList (java.util.ArrayList)1 Collections.singletonList (java.util.Collections.singletonList)1 Router (org.openstack4j.model.network.Router)1