Search in sources :

Example 1 with CreatedCloudNetwork

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

the class AzureNetworkConnector method createNetworkWithSubnets.

@Override
public CreatedCloudNetwork createNetworkWithSubnets(NetworkCreationRequest networkRequest) {
    AzureClient azureClient = azureClientService.getClient(networkRequest.getCloudCredential());
    String region = networkRequest.getRegion().value();
    List<SubnetRequest> subnetRequests = azureSubnetRequestProvider.provide(region, Lists.newArrayList(networkRequest.getPublicSubnets()), Lists.newArrayList(networkRequest.getPrivateSubnets()), networkRequest.isPrivateSubnetEnabled());
    Deployment templateDeployment;
    ResourceGroup resourceGroup;
    try {
        resourceGroup = getOrCreateResourceGroup(azureClient, networkRequest);
        String template = azureNetworkTemplateBuilder.build(networkRequest, subnetRequests, resourceGroup.name());
        String parametersMapAsString = new Json(Map.of()).getValue();
        templateDeployment = azureClient.createTemplateDeployment(resourceGroup.name(), networkRequest.getStackName(), template, parametersMapAsString);
    } catch (CloudException e) {
        throw azureUtils.convertToCloudConnectorException(e, "Network template deployment provisioning");
    } catch (Exception e) {
        LOGGER.warn("Provisioning error:", e);
        throw new CloudConnectorException(String.format("Error in provisioning network %s: %s", networkRequest.getStackName(), e.getMessage()));
    }
    Map<String, Map> outputMap = (HashMap) templateDeployment.outputs();
    String networkName = cropId((String) outputMap.get(NETWORK_ID_KEY).get("value"));
    Set<CreatedSubnet> subnets = createSubnets(subnetRequests, outputMap, region);
    return new CreatedCloudNetwork(networkRequest.getStackName(), networkName, subnets, createProperties(resourceGroup.name(), networkRequest.getStackName()));
}
Also used : SubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) HashMap(java.util.HashMap) Deployment(com.microsoft.azure.management.resources.Deployment) Json(com.sequenceiq.cloudbreak.common.json.Json) CloudException(com.microsoft.azure.CloudException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) BadRequestException(javax.ws.rs.BadRequestException) CloudException(com.microsoft.azure.CloudException) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) CreatedSubnet(com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet) HashMap(java.util.HashMap) Map(java.util.Map) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup)

Example 2 with CreatedCloudNetwork

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

the class GcpNetworkConnectorTest method testCreateNetworkWithSubnetsWhenCreationGoesFine.

@Test
public void testCreateNetworkWithSubnetsWhenCreationGoesFine() throws Exception {
    NetworkCreationRequest networkCreationRequest = new NetworkCreationRequest.Builder().withNetworkCidr("16.0.0.0/16").withAccountId("account-id").withCreatorCrn("creator-crn").withVariant("GCP").withEnvCrn("env-crn").withEnvName("super-env").withPrivateSubnetEnabled(true).withTags(new HashMap<>()).withCreatorCrn("creator-crn").withRegion(Region.region("us-west-1")).withPublicSubnets(new HashSet<>()).withPrivateSubnets(new HashSet<>()).build();
    GcpContext gcpContext = mock(GcpContext.class);
    PollTask pollTask = mock(PollTask.class);
    CloudResource cloudResource = mock(CloudResource.class);
    when(cloudResource.getName()).thenReturn("network");
    when(contextBuilders.contextInit(any(CloudContext.class), any(AuthenticatedContext.class), any(Network.class), any(), anyBoolean())).thenReturn(gcpContext);
    when(gcpNetworkResourceBuilder.create(any(GcpContext.class), any(AuthenticatedContext.class), any(Network.class))).thenReturn(cloudResource);
    when(gcpNetworkResourceBuilder.build(any(GcpContext.class), any(AuthenticatedContext.class), any(Network.class), any(Security.class), any(CloudResource.class))).thenReturn(cloudResource);
    when(statusCheckFactory.newPollResourceTask(any(ResourceChecker.class), any(AuthenticatedContext.class), anyList(), any(ResourceBuilderContext.class), anyBoolean())).thenReturn(pollTask);
    when(syncPollingScheduler.schedule(any(PollTask.class))).thenReturn(new ArrayList());
    when(gcpCloudSubnetProvider.provide(any(NetworkCreationRequest.class), anyList())).thenReturn(List.of(createdSubnet()));
    when(gcpSubnetResourceBuilder.create(any(GcpContext.class), any(AuthenticatedContext.class), any(Network.class))).thenReturn(cloudResource);
    when(gcpSubnetResourceBuilder.build(any(GcpContext.class), any(AuthenticatedContext.class), any(Network.class), any(Security.class), any(CloudResource.class))).thenReturn(cloudResource);
    CreatedCloudNetwork networkWithSubnets = underTest.createNetworkWithSubnets(networkCreationRequest);
    Assert.assertEquals(1, networkWithSubnets.getSubnets().size());
}
Also used : HashMap(java.util.HashMap) NetworkCreationRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkCreationRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Security(com.sequenceiq.cloudbreak.cloud.model.Security) ResourceChecker(com.sequenceiq.cloudbreak.cloud.template.ResourceChecker) PollTask(com.sequenceiq.cloudbreak.cloud.task.PollTask) GcpContext(com.sequenceiq.cloudbreak.cloud.gcp.context.GcpContext) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) ResourceBuilderContext(com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 3 with CreatedCloudNetwork

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

the class EnvironmentNetworkService method createCloudNetwork.

public BaseNetwork createCloudNetwork(EnvironmentDto environment, BaseNetwork baseNetwork) {
    NetworkConnector networkConnector = getNetworkConnector(environment.getCloudPlatform());
    NetworkCreationRequest networkCreationRequest = networkCreationRequestFactory.create(environment);
    EnvironmentNetworkConverter converter = environmentNetworkConverterMap.get(getCloudPlatform(environment));
    CreatedCloudNetwork createdCloudNetwork = networkConnector.createNetworkWithSubnets(networkCreationRequest);
    return converter.setCreatedCloudNetwork(baseNetwork, createdCloudNetwork);
}
Also used : NetworkCreationRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkCreationRequest) NetworkConnector(com.sequenceiq.cloudbreak.cloud.NetworkConnector) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) EnvironmentNetworkConverter(com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter)

Example 4 with CreatedCloudNetwork

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

the class MockNetworkConnector method createNetworkWithSubnets.

@Override
public CreatedCloudNetwork createNetworkWithSubnets(NetworkCreationRequest request) {
    CreatedSubnet subnet1 = new CreatedSubnet();
    CreatedSubnet subnet2 = new CreatedSubnet();
    subnet1.setAvailabilityZone("europe-a");
    subnet2.setAvailabilityZone("europe-b");
    subnet1.setCidr("172.16.0.0/16");
    subnet2.setCidr("172.17.0.0/16");
    subnet2.setPublicSubnet(true);
    subnet1.setSubnetId("1");
    subnet2.setSubnetId("2");
    subnet1.setType(PUBLIC);
    subnet2.setType(PUBLIC);
    CreatedCloudNetwork result = new CreatedCloudNetwork(request.getStackName(), "mockedNetwork1", Set.of(subnet1, subnet2));
    return result;
}
Also used : CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) CreatedSubnet(com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet)

Example 5 with CreatedCloudNetwork

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

the class AwsNetworkConnectorTest method testCreateNetworkWithSubnetsShouldReturnTheNetworkAndSubnets.

@Test
public void testCreateNetworkWithSubnetsShouldReturnTheNetworkAndSubnets() {
    String networkCidr = "0.0.0.0/16";
    Set<NetworkSubnetRequest> subnets = Set.of(new NetworkSubnetRequest("1.1.1.1/8", PUBLIC), new NetworkSubnetRequest("1.1.1.2/8", PUBLIC));
    AmazonCloudFormationClient cfClient = mock(AmazonCloudFormationClient.class);
    AmazonEc2Client ec2Client = mock(AmazonEc2Client.class);
    Map<String, String> output = createOutput();
    NetworkCreationRequest networkCreationRequest = createNetworkRequest(networkCidr, subnets);
    List<SubnetRequest> subnetRequestList = createSubnetRequestList();
    Set<CreatedSubnet> createdSubnets = Set.of(new CreatedSubnet(), new CreatedSubnet(), new CreatedSubnet());
    when(awsClient.createEc2Client(any(), any())).thenReturn(ec2Client);
    when(awsSubnetRequestProvider.provide(ec2Client, new ArrayList<>(subnets), new ArrayList<>(subnets))).thenReturn(subnetRequestList);
    when(awsClient.createCloudFormationClient(any(AwsCredentialView.class), eq(REGION.value()))).thenReturn(cfClient);
    when(cfClient.waiters()).thenReturn(cfWaiters);
    when(cfWaiters.stackCreateComplete()).thenReturn(creationWaiter);
    when(cfStackUtil.getOutputs(NETWORK_ID, cfClient)).thenReturn(output);
    when(awsCreatedSubnetProvider.provide(output, subnetRequestList, true)).thenReturn(createdSubnets);
    CreatedCloudNetwork actual = underTest.createNetworkWithSubnets(networkCreationRequest);
    verify(awsClient).createCloudFormationClient(any(AwsCredentialView.class), eq(REGION.value()));
    verify(creationWaiter, times(1)).run(any());
    verify(cfStackUtil).getOutputs(NETWORK_ID, cfClient);
    verify(awsTaggingService, never()).prepareCloudformationTags(any(), any());
    verify(cfClient, never()).createStack(any(CreateStackRequest.class));
    assertEquals(VPC_ID, actual.getNetworkId());
    assertEquals(NUMBER_OF_SUBNETS, actual.getSubnets().size());
}
Also used : NetworkSubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest) SubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest) NetworkCreationRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkCreationRequest) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) NetworkSubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) CreatedSubnet(com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet) AmazonCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient) CreateStackRequest(com.amazonaws.services.cloudformation.model.CreateStackRequest) Test(org.junit.Test)

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