Search in sources :

Example 11 with CreatedCloudNetwork

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

Aggregations

CreatedCloudNetwork (com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork)11 CreatedSubnet (com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet)7 NetworkCreationRequest (com.sequenceiq.cloudbreak.cloud.model.network.NetworkCreationRequest)6 SubnetRequest (com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest)4 Test (org.junit.jupiter.api.Test)4 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)3 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)3 Network (com.sequenceiq.cloudbreak.cloud.model.Network)3 NetworkSubnetRequest (com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest)3 CreateStackRequest (com.amazonaws.services.cloudformation.model.CreateStackRequest)2 CloudException (com.microsoft.azure.CloudException)2 Deployment (com.microsoft.azure.management.resources.Deployment)2 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)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 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)2 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)2 GcpContext (com.sequenceiq.cloudbreak.cloud.gcp.context.GcpContext)2 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)2