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;
}
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;
}
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);
}
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;
}
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());
}
Aggregations