Search in sources :

Example 6 with CreatedSubnet

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

the class GcpEnvironmentNetworkConverter method setCreatedCloudNetwork.

@Override
public BaseNetwork setCreatedCloudNetwork(BaseNetwork baseNetwork, CreatedCloudNetwork createdCloudNetwork) {
    GcpNetwork gcpNetwork = (GcpNetwork) baseNetwork;
    gcpNetwork.setNetworkId(createdCloudNetwork.getNetworkId());
    Map<String, Object> properties = createdCloudNetwork.getProperties();
    if (properties == null) {
        properties = new HashMap<>();
    }
    Object sharedProjectId = properties.get("sharedProjectId");
    gcpNetwork.setSharedProjectId(sharedProjectId == null ? null : sharedProjectId.toString());
    Object noFirewallRules = properties.get("noFirewallRules");
    gcpNetwork.setNoFirewallRules(noFirewallRules != null && Boolean.parseBoolean(noFirewallRules.toString()));
    Object noPublicIp = properties.get("noPublicIp");
    gcpNetwork.setNoPublicIp(noPublicIp != null && Boolean.parseBoolean(noPublicIp.toString()));
    gcpNetwork.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.isIgwAvailable() ? PUBLIC : PRIVATE))));
    return gcpNetwork;
}
Also used : GcpNetwork(com.sequenceiq.environment.network.dao.domain.GcpNetwork) CreatedSubnet(com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)

Example 7 with CreatedSubnet

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

the class AzureEnvironmentNetworkConverter method setCreatedCloudNetwork.

@Override
public BaseNetwork setCreatedCloudNetwork(BaseNetwork baseNetwork, CreatedCloudNetwork createdCloudNetwork) {
    AzureNetwork azureNetwork = (AzureNetwork) baseNetwork;
    azureNetwork.setName(createdCloudNetwork.getStackName());
    azureNetwork.setNetworkId(createdCloudNetwork.getNetworkId());
    azureNetwork.setResourceGroupName(String.valueOf(createdCloudNetwork.getProperties().get("resourceGroupName")));
    azureNetwork.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 azureNetwork;
}
Also used : CreatedSubnet(com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet) AzureNetwork(com.sequenceiq.environment.network.dao.domain.AzureNetwork) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)

Example 8 with CreatedSubnet

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

the class AzureEnvironmentNetworkConverterTest method createCreatedSubnets.

private Set<CreatedSubnet> createCreatedSubnets() {
    CreatedSubnet createdSubnet1 = new CreatedSubnet();
    createdSubnet1.setSubnetId(SUBNET_1);
    createdSubnet1.setAvailabilityZone(AZ_1);
    createdSubnet1.setCidr(SUBNET_CIDR_1);
    createdSubnet1.setPublicSubnet(true);
    CreatedSubnet createdSubnet2 = new CreatedSubnet();
    createdSubnet2.setSubnetId(SUBNET_2);
    createdSubnet2.setAvailabilityZone(AZ_2);
    createdSubnet2.setCidr(SUBNET_CIDR_2);
    createdSubnet2.setPublicSubnet(true);
    CreatedSubnet createdSubnet3 = new CreatedSubnet();
    createdSubnet3.setSubnetId(SUBNET_3);
    createdSubnet3.setAvailabilityZone(AZ_3);
    createdSubnet3.setCidr(SUBNET_CIDR_3);
    createdSubnet3.setPublicSubnet(true);
    return Set.of(createdSubnet1, createdSubnet2, createdSubnet3);
}
Also used : CreatedSubnet(com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet)

Example 9 with CreatedSubnet

use of com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet 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 10 with CreatedSubnet

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

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