Search in sources :

Example 16 with CreatedSubnet

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

the class AwsEnvironmentNetworkConverter method setCreatedCloudNetwork.

@Override
public BaseNetwork setCreatedCloudNetwork(BaseNetwork baseNetwork, CreatedCloudNetwork createdCloudNetwork) {
    AwsNetwork awsNetwork = (AwsNetwork) baseNetwork;
    awsNetwork.setName(createdCloudNetwork.getStackName());
    awsNetwork.setVpcId(createdCloudNetwork.getNetworkId());
    awsNetwork.setSubnetMetas(createdCloudNetwork.getSubnets().stream().collect(Collectors.toMap(CreatedSubnet::getSubnetId, subnet -> new CloudSubnet(subnet.getSubnetId(), subnet.getSubnetId(), subnet.getAvailabilityZone(), subnet.getCidr(), !subnet.isPublicSubnet(), subnet.isMapPublicIpOnLaunch(), subnet.isIgwAvailable(), subnet.getType()))));
    return awsNetwork;
}
Also used : AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) CreatedSubnet(com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)

Example 17 with CreatedSubnet

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

the class MockEnvironmentNetworkConverter method setCreatedCloudNetwork.

@Override
public BaseNetwork setCreatedCloudNetwork(BaseNetwork baseNetwork, CreatedCloudNetwork createdCloudNetwork) {
    MockNetwork mockNetwork = (MockNetwork) baseNetwork;
    mockNetwork.setName(createdCloudNetwork.getStackName());
    mockNetwork.setVpcId(createdCloudNetwork.getNetworkId());
    mockNetwork.setSubnetMetas(createdCloudNetwork.getSubnets().stream().collect(Collectors.toMap(CreatedSubnet::getSubnetId, subnet -> new CloudSubnet(subnet.getSubnetId(), subnet.getSubnetId(), subnet.getAvailabilityZone(), subnet.getCidr(), !subnet.isPublicSubnet(), subnet.isMapPublicIpOnLaunch(), subnet.isIgwAvailable(), subnet.getType()))));
    return mockNetwork;
}
Also used : MockNetwork(com.sequenceiq.environment.network.dao.domain.MockNetwork) CreatedSubnet(com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)

Example 18 with CreatedSubnet

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

the class GcpNetworkConnector method createNetworkWithSubnets.

@Override
public CreatedCloudNetwork createNetworkWithSubnets(NetworkCreationRequest networkCreationRequest) {
    CloudContext cloudContext = getCloudContext(networkCreationRequest);
    AuthenticatedContext auth = new AuthenticatedContext(cloudContext, networkCreationRequest.getCloudCredential());
    Network network = buildNetworkForCreation(networkCreationRequest);
    GcpContext context = contextBuilders.contextInit(cloudContext, auth, network, null, true);
    try {
        CloudResource networkResource = createNetwork(context, auth, network);
        List<CreatedSubnet> subnetList = getCloudSubNets(networkCreationRequest);
        for (CreatedSubnet createdSubnet : subnetList) {
            createSubnet(context, auth, buildSubnetForCreation(networkCreationRequest, createdSubnet.getCidr()), createdSubnet);
        }
        return new CreatedCloudNetwork(networkCreationRequest.getEnvName(), networkResource.getName(), getCreatedSubnets(subnetList));
    } catch (TokenResponseException e) {
        throw gcpStackUtil.getMissingServiceAccountKeyError(e, context.getProjectId());
    } catch (GoogleJsonResponseException e) {
        throw new GcpResourceException(checkException(e), GCP_NETWORK, networkCreationRequest.getEnvName());
    } catch (IOException e) {
        throw new GcpResourceException("Network creation failed due to IO exception", GCP_NETWORK, networkCreationRequest.getEnvName());
    }
}
Also used : GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) GcpContext(com.sequenceiq.cloudbreak.cloud.gcp.context.GcpContext) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CreatedSubnet(com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet) IOException(java.io.IOException) TokenResponseException(com.google.api.client.auth.oauth2.TokenResponseException)

Example 19 with CreatedSubnet

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

the class GcpNetworkConnector method getCreatedSubnets.

private Set<CreatedSubnet> getCreatedSubnets(List<CreatedSubnet> createdSubnetList) {
    Set<CreatedSubnet> subnets = new HashSet<>();
    for (int i = 0; i < createdSubnetList.size(); i++) {
        CreatedSubnet createdSubnetIndexed = createdSubnetList.get(i);
        CreatedSubnet createdSubnet = new CreatedSubnet();
        createdSubnet.setSubnetId(createdSubnetIndexed.getSubnetId());
        createdSubnet.setCidr(createdSubnetList.get(i).getCidr());
        createdSubnet.setAvailabilityZone(createdSubnetList.get(i).getAvailabilityZone());
        createdSubnet.setMapPublicIpOnLaunch(true);
        createdSubnet.setIgwAvailable(true);
        subnets.add(createdSubnet);
    }
    return subnets;
}
Also used : CreatedSubnet(com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet) HashSet(java.util.HashSet)

Example 20 with CreatedSubnet

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

the class AwsCreatedSubnetProvider method provide.

Set<CreatedSubnet> provide(Map<String, String> output, List<SubnetRequest> subnetRequests, boolean privateSubnetEnabled) {
    Set<CreatedSubnet> subnets = new HashSet<>();
    for (SubnetRequest subnetRequest : subnetRequests) {
        CreatedSubnet createdPublicSubnet = new CreatedSubnet();
        createdPublicSubnet.setSubnetId(getValue(output, "id" + subnetRequest.getIndex()));
        createdPublicSubnet.setAvailabilityZone(subnetRequest.getAvailabilityZone());
        if (!Strings.isNullOrEmpty(subnetRequest.getPrivateSubnetCidr()) && privateSubnetEnabled) {
            createdPublicSubnet.setCidr(subnetRequest.getPrivateSubnetCidr());
            createdPublicSubnet.setPublicSubnet(false);
            createdPublicSubnet.setMapPublicIpOnLaunch(false);
            createdPublicSubnet.setIgwAvailable(false);
        } else {
            createdPublicSubnet.setCidr(subnetRequest.getPublicSubnetCidr());
            createdPublicSubnet.setPublicSubnet(true);
            createdPublicSubnet.setMapPublicIpOnLaunch(true);
            createdPublicSubnet.setIgwAvailable(true);
        }
        createdPublicSubnet.setType(subnetRequest.getType());
        subnets.add(createdPublicSubnet);
    }
    return subnets;
}
Also used : SubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest) CreatedSubnet(com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet) HashSet(java.util.HashSet)

Aggregations

CreatedSubnet (com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet)20 CreatedCloudNetwork (com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork)7 SubnetRequest (com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest)5 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)4 NetworkCreationRequest (com.sequenceiq.cloudbreak.cloud.model.network.NetworkCreationRequest)4 Test (org.junit.jupiter.api.Test)4 Compute (com.google.api.services.compute.Compute)3 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 CreateStackRequest (com.amazonaws.services.cloudformation.model.CreateStackRequest)2 RegionList (com.google.api.services.compute.model.RegionList)2 AmazonCloudFormationClient (com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient)2 AmazonEc2Client (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client)2 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)2 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)2 GcpComputeFactory (com.sequenceiq.cloudbreak.cloud.gcp.client.GcpComputeFactory)2 GcpStackUtil (com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 Region (com.sequenceiq.cloudbreak.cloud.model.Region)2 NetworkSubnetRequest (com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest)2