Search in sources :

Example 1 with CloudNetwork

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

the class CloudNetworksToPlatformNetworksResponseConverter method convert.

@Override
public PlatformNetworksResponse convert(CloudNetworks source) {
    Map<String, Set<PlatformNetworkResponse>> result = new HashMap<>();
    for (Entry<String, Set<CloudNetwork>> entry : source.getCloudNetworkResponses().entrySet()) {
        Set<PlatformNetworkResponse> networks = new HashSet<>();
        for (CloudNetwork cloudNetwork : entry.getValue()) {
            PlatformNetworkResponse actual = new PlatformNetworkResponse(cloudNetwork.getName(), cloudNetwork.getId(), cloudNetwork.getSubnets(), cloudNetwork.getProperties());
            networks.add(actual);
        }
        result.put(entry.getKey(), networks);
    }
    return new PlatformNetworksResponse(result);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) PlatformNetworkResponse(com.sequenceiq.cloudbreak.api.model.PlatformNetworkResponse) PlatformNetworksResponse(com.sequenceiq.cloudbreak.api.model.PlatformNetworksResponse) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) HashSet(java.util.HashSet)

Example 2 with CloudNetwork

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

the class AwsPlatformResources method networks.

@Override
public CloudNetworks networks(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    Map<String, Set<CloudNetwork>> result = new HashMap<>();
    Set<CloudNetwork> cloudNetworks = new HashSet<>();
    AmazonEC2Client ec2Client = awsClient.createAccess(new AwsCredentialView(cloudCredential), region.value());
    // create vpc filter view
    PlatformResourceVpcFilterView filter = new PlatformResourceVpcFilterView(filters);
    DescribeVpcsRequest describeVpcsRequest = new DescribeVpcsRequest();
    // If the filtervalue is provided then we should filter only for those vpc
    if (!Strings.isNullOrEmpty(filter.getVpcId())) {
        describeVpcsRequest.withVpcIds(filter.getVpcId());
    }
    for (Vpc vpc : ec2Client.describeVpcs(describeVpcsRequest).getVpcs()) {
        Map<String, String> subnetMap = new HashMap<>();
        List<Subnet> subnets = ec2Client.describeSubnets(createVpcDescribeRequest(vpc)).getSubnets();
        Map<String, Object> properties = new HashMap<>();
        properties.put("cidrBlock", vpc.getCidrBlock());
        properties.put("default", vpc.getIsDefault());
        properties.put("dhcpOptionsId", vpc.getDhcpOptionsId());
        properties.put("instanceTenancy", vpc.getInstanceTenancy());
        properties.put("state", vpc.getState());
        for (Subnet subnet : subnets) {
            subnetMap.put(subnet.getSubnetId(), subnet.getSubnetId());
        }
        cloudNetworks.add(new CloudNetwork(vpc.getVpcId(), vpc.getVpcId(), subnetMap, properties));
    }
    result.put(region.value(), cloudNetworks);
    return new CloudNetworks(result);
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) PlatformResourceVpcFilterView(com.sequenceiq.cloudbreak.cloud.model.view.PlatformResourceVpcFilterView) Vpc(com.amazonaws.services.ec2.model.Vpc) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) DescribeVpcsRequest(com.amazonaws.services.ec2.model.DescribeVpcsRequest) Subnet(com.amazonaws.services.ec2.model.Subnet) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) HashSet(java.util.HashSet)

Example 3 with CloudNetwork

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

the class GcpPlatformResources method networks.

@Override
public CloudNetworks networks(CloudCredential cloudCredential, Region region, Map<String, String> filters) throws Exception {
    Compute compute = GcpStackUtil.buildCompute(cloudCredential);
    String projectId = GcpStackUtil.getProjectId(cloudCredential);
    Map<String, Set<CloudNetwork>> result = new HashMap<>();
    Set<CloudNetwork> cloudNetworks = new HashSet<>();
    if (compute != null) {
        NetworkList networkList = compute.networks().list(projectId).execute();
        List<Subnetwork> subnetworkList = compute.subnetworks().list(projectId, region.value()).execute().getItems();
        for (Network network : networkList.getItems()) {
            Map<String, Object> properties = new HashMap<>();
            properties.put("gatewayIPv4", Strings.nullToEmpty(network.getGatewayIPv4()));
            properties.put("description", Strings.nullToEmpty(network.getDescription()));
            properties.put("IPv4Range", Strings.nullToEmpty(network.getIPv4Range()));
            properties.put("creationTimestamp", Strings.nullToEmpty(network.getCreationTimestamp()));
            Map<String, String> subnets = new HashMap<>();
            if (subnetworkList != null && network.getSubnetworks() != null) {
                for (Subnetwork subnetwork : subnetworkList) {
                    if (network.getSubnetworks().contains(subnetwork.getSelfLink())) {
                        subnets.put(subnetwork.getName(), subnetwork.getName());
                    }
                }
            }
            CloudNetwork cloudNetwork = new CloudNetwork(network.getName(), network.getId().toString(), subnets, properties);
            cloudNetworks.add(cloudNetwork);
        }
        result.put(region.value(), cloudNetworks);
    }
    return new CloudNetworks(result);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Subnetwork(com.google.api.services.compute.model.Subnetwork) HashMap(java.util.HashMap) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) NetworkList(com.google.api.services.compute.model.NetworkList) Compute(com.google.api.services.compute.Compute) Network(com.google.api.services.compute.model.Network) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) HashSet(java.util.HashSet)

Example 4 with CloudNetwork

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

the class OpenStackPlatformResources method networks.

@Override
public CloudNetworks networks(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    OSClient<?> osClient = openStackClient.createOSClient(cloudCredential);
    KeystoneCredentialView osCredential = openStackClient.createKeystoneCredential(cloudCredential);
    Set<CloudNetwork> cloudNetworks = new HashSet<>();
    List<? extends Network> networks = getNetworks(osClient);
    for (Network network : networks) {
        Map<String, Object> properties = new HashMap<>();
        properties.put("networkType", network.getNetworkType());
        properties.put("providerPhyNet", network.getProviderPhyNet());
        properties.put("providerSegID", network.getProviderSegID());
        properties.put("tenantId", network.getTenantId());
        Map<String, String> subnets = new HashMap<>();
        List<? extends Subnet> neutronSubnets = network.getNeutronSubnets();
        LOGGER.info("neutron subnets for {}: {}", network.getName(), neutronSubnets);
        if (neutronSubnets != null) {
            for (Subnet neutronSubnet : neutronSubnets) {
                if (neutronSubnet != null) {
                    subnets.put(neutronSubnet.getId(), neutronSubnet.getName());
                }
            }
        }
        CloudNetwork cloudNetwork = new CloudNetwork(network.getName(), network.getId(), subnets, properties);
        cloudNetworks.add(cloudNetwork);
    }
    Map<String, Set<CloudNetwork>> result = new HashMap<>(1);
    result.put(region.value() == null ? osCredential.getTenantName() : region.value(), cloudNetworks);
    LOGGER.info("openstack cloud networks result: {}", result);
    return new CloudNetworks(result);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) Network(org.openstack4j.model.network.Network) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) KeystoneCredentialView(com.sequenceiq.cloudbreak.cloud.openstack.view.KeystoneCredentialView) Subnet(org.openstack4j.model.network.Subnet) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) HashSet(java.util.HashSet)

Example 5 with CloudNetwork

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

the class AzurePlatformResources method networks.

@Override
public CloudNetworks networks(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    AzureClient client = azureClientService.getClient(cloudCredential);
    Map<String, Set<CloudNetwork>> result = new HashMap<>();
    for (Network network : client.getNetworks()) {
        String actualRegion = network.region().label();
        if (regionMatch(actualRegion, region)) {
            Map<String, String> subnets = new HashMap<>();
            for (Entry<String, Subnet> subnet : network.subnets().entrySet()) {
                subnets.put(subnet.getKey(), subnet.getKey());
            }
            Map<String, Object> properties = new HashMap<>();
            properties.put("addressSpaces", network.addressSpaces());
            properties.put("dnsServerIPs", network.dnsServerIPs());
            properties.put("resourceGroupName", network.resourceGroupName());
            CloudNetwork cloudNetwork = new CloudNetwork(network.name(), network.id(), subnets, properties);
            result.computeIfAbsent(actualRegion, s -> new HashSet<>()).add(cloudNetwork);
        }
    }
    if (result.isEmpty() && Objects.nonNull(region)) {
        result.put(region.value(), new HashSet<>());
    }
    return new CloudNetworks(result);
}
Also used : VolumeParameterType.values(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType.values) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) CloudIpPools(com.sequenceiq.cloudbreak.cloud.model.CloudIpPools) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Cacheable(org.springframework.cache.annotation.Cacheable) Subnet(com.microsoft.azure.management.network.Subnet) HashMap(java.util.HashMap) CloudGateWays(com.sequenceiq.cloudbreak.cloud.model.CloudGateWays) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) Strings(com.google.common.base.Strings) Network(com.microsoft.azure.management.network.Network) CloudSshKeys(com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys) Service(org.springframework.stereotype.Service) Map(java.util.Map) PlatformResources(com.sequenceiq.cloudbreak.cloud.PlatformResources) VmTypeMetaBuilder(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder) Region.region(com.sequenceiq.cloudbreak.cloud.model.Region.region) Set(java.util.Set) NetworkSecurityGroup(com.microsoft.azure.management.network.NetworkSecurityGroup) CloudAccessConfigs(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) Objects(java.util.Objects) List(java.util.List) VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) VolumeParameterType(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType) CloudSecurityGroups(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups) Entry(java.util.Map.Entry) AzureClientService(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClientService) VolumeParameterConfig(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) MAGNETIC(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType.MAGNETIC) CloudSecurityGroup(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) Network(com.microsoft.azure.management.network.Network) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) Subnet(com.microsoft.azure.management.network.Subnet) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) HashSet(java.util.HashSet)

Aggregations

CloudNetwork (com.sequenceiq.cloudbreak.cloud.model.CloudNetwork)5 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 Set (java.util.Set)5 CloudNetworks (com.sequenceiq.cloudbreak.cloud.model.CloudNetworks)4 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)1 DescribeVpcsRequest (com.amazonaws.services.ec2.model.DescribeVpcsRequest)1 Subnet (com.amazonaws.services.ec2.model.Subnet)1 Vpc (com.amazonaws.services.ec2.model.Vpc)1 Compute (com.google.api.services.compute.Compute)1 Network (com.google.api.services.compute.model.Network)1 NetworkList (com.google.api.services.compute.model.NetworkList)1 Subnetwork (com.google.api.services.compute.model.Subnetwork)1 Strings (com.google.common.base.Strings)1 VirtualMachineSize (com.microsoft.azure.management.compute.VirtualMachineSize)1 Network (com.microsoft.azure.management.network.Network)1 NetworkSecurityGroup (com.microsoft.azure.management.network.NetworkSecurityGroup)1 Subnet (com.microsoft.azure.management.network.Subnet)1 PlatformNetworkResponse (com.sequenceiq.cloudbreak.api.model.PlatformNetworkResponse)1 PlatformNetworksResponse (com.sequenceiq.cloudbreak.api.model.PlatformNetworksResponse)1