Search in sources :

Example 1 with CloudNetworks

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

the class PlatformParameterV1Controller method getCloudNetworks.

@Override
public PlatformNetworksResponse getCloudNetworks(PlatformResourceRequestJson resourceRequestJson) {
    resourceRequestJson = prepareAccountAndOwner(resourceRequestJson, authenticatedUserService.getCbUser());
    PlatformResourceRequest convert = conversionService.convert(resourceRequestJson, PlatformResourceRequest.class);
    CloudNetworks cloudNetworks = cloudParameterService.getCloudNetworks(convert.getCredential(), convert.getRegion(), convert.getPlatformVariant(), convert.getFilters());
    return conversionService.convert(cloudNetworks, PlatformNetworksResponse.class);
}
Also used : CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) PlatformResourceRequest(com.sequenceiq.cloudbreak.domain.PlatformResourceRequest)

Example 2 with CloudNetworks

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

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

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

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

the class GetPlatformNetworksHandler method accept.

@Override
public void accept(Event<GetPlatformNetworksRequest> getPlatformNetworksRequest) {
    LOGGER.info("Received event: {}", getPlatformNetworksRequest);
    GetPlatformNetworksRequest request = getPlatformNetworksRequest.getData();
    try {
        CloudPlatformVariant cloudPlatformVariant = new CloudPlatformVariant(Platform.platform(request.getExtendedCloudCredential().getCloudPlatform()), Variant.variant(request.getVariant()));
        CloudNetworks networks = cloudPlatformConnectors.get(cloudPlatformVariant).platformResources().networks(request.getCloudCredential(), Region.region(request.getRegion()), request.getFilters());
        GetPlatformNetworksResult getPlatformNetworksResult = new GetPlatformNetworksResult(request, networks);
        request.getResult().onNext(getPlatformNetworksResult);
        LOGGER.info("Query platform networks types finished.");
    } catch (Exception e) {
        request.getResult().onNext(new GetPlatformNetworksResult(e.getMessage(), e, request));
    }
}
Also used : GetPlatformNetworksResult(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformNetworksResult) GetPlatformNetworksRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformNetworksRequest) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks)

Aggregations

CloudNetworks (com.sequenceiq.cloudbreak.cloud.model.CloudNetworks)6 CloudNetwork (com.sequenceiq.cloudbreak.cloud.model.CloudNetwork)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Set (java.util.Set)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 PlatformResources (com.sequenceiq.cloudbreak.cloud.PlatformResources)1 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)1