use of com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet 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()));
}
use of com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet in project cloudbreak by hortonworks.
the class AzureNetworkConnector method createSubnets.
private Set<CreatedSubnet> createSubnets(List<SubnetRequest> subnetRequests, Map<String, Map> outputMap, String region) {
Set<CreatedSubnet> createdSubnets = new HashSet<>();
for (SubnetRequest subnetRequest : subnetRequests) {
if (outputMap.containsKey(SUBNET_ID_KEY + subnetRequest.getIndex())) {
CreatedSubnet createdSubnet = new CreatedSubnet();
createdSubnet.setSubnetId(cropId((String) outputMap.get(SUBNET_ID_KEY + subnetRequest.getIndex()).get("value")));
if (!Strings.isNullOrEmpty(subnetRequest.getPrivateSubnetCidr())) {
createdSubnet.setCidr(subnetRequest.getPrivateSubnetCidr());
} else {
createdSubnet.setCidr(subnetRequest.getPublicSubnetCidr());
}
createdSubnet.setAvailabilityZone(region);
createdSubnet.setType(subnetRequest.getType());
createdSubnets.add(createdSubnet);
} else {
throw new CloudConnectorException("Subnet could not be found in the Azure deployment output.");
}
}
return createdSubnets;
}
use of com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet in project cloudbreak by hortonworks.
the class GcpCloudSubnetProvider method provide.
public List<CreatedSubnet> provide(NetworkCreationRequest request, List<String> subnetCidrs) throws IOException {
Compute compute = gcpComputeFactory.buildCompute(request.getCloudCredential());
String projectId = gcpStackUtil.getProjectId(request.getCloudCredential());
List<String> az = getAvailabilityZones(compute, projectId, request.getRegion());
List<CreatedSubnet> subnets = new ArrayList<>(subnetCidrs.size());
for (int i = 0; i < subnetCidrs.size(); i++) {
CreatedSubnet createdSubnet = new CreatedSubnet();
createdSubnet.setCidr(subnetCidrs.get(i));
if (i < az.size()) {
createdSubnet.setAvailabilityZone(az.get(i));
} else {
createdSubnet.setAvailabilityZone(az.get(az.size() - 1));
}
subnets.add(createdSubnet);
}
return subnets;
}
use of com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet in project cloudbreak by hortonworks.
the class GcpCloudSubnetProviderTest method testProvideCloudSubnetsWhen2Subnet2AZIsProvidedShouldCreate2NewSubnetWithDifferentAzShouldBeProvided.
@Test
public void testProvideCloudSubnetsWhen2Subnet2AZIsProvidedShouldCreate2NewSubnetWithDifferentAzShouldBeProvided() throws IOException {
NetworkCreationRequest request = new NetworkCreationRequest.Builder().withEnvName("envName").withEnvId(1L).withNetworkCidr("10.0.0.0/16").withRegion(Region.region("euwest1")).withPrivateSubnetEnabled(true).withCloudCredential(mock(CloudCredential.class)).withEndpointType(PrivateEndpointType.USE_VPC_ENDPOINT).build();
Compute compute = mock(Compute.class);
Compute.Regions regions = mock(Compute.Regions.class);
Compute.Regions.List regionsList = mock(Compute.Regions.List.class);
RegionList regionListObject = mock(RegionList.class);
com.google.api.services.compute.model.Region regionObject = new com.google.api.services.compute.model.Region();
regionObject.setName("euwest1");
regionObject.setZones(List.of("euwest1/euwest1a", "euwest1/euwest1b"));
when(gcpComputeFactory.buildCompute(any(CloudCredential.class))).thenReturn(compute);
when(gcpStackUtil.getProjectId(any(CloudCredential.class))).thenReturn("project-id");
when(compute.regions()).thenReturn(regions);
when(regions.list(anyString())).thenReturn(regionsList);
when(regionsList.execute()).thenReturn(regionListObject);
when(regionListObject.getItems()).thenReturn(List.of(regionObject));
List<CreatedSubnet> provide = underTest.provide(request, List.of("10.0.0.0/16", "10.0.0.1/16"));
Assert.assertEquals(2, provide.size());
Assert.assertTrue(provide.stream().map(e -> e.getAvailabilityZone()).filter(e -> e.equals("euwest1a")).findFirst().isPresent());
Assert.assertTrue(provide.stream().map(e -> e.getAvailabilityZone()).filter(e -> e.equals("euwest1b")).findFirst().isPresent());
}
use of com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet in project cloudbreak by hortonworks.
the class GcpNetworkConnectorTest method createdSubnet.
private CreatedSubnet createdSubnet() {
CreatedSubnet createdSubnet = new CreatedSubnet();
createdSubnet.setCidr("0.0.0.0/0");
createdSubnet.setSubnetId("subnet-1");
createdSubnet.setPublicSubnet(true);
createdSubnet.setIgwAvailable(true);
createdSubnet.setMapPublicIpOnLaunch(true);
createdSubnet.setType(SubnetType.DWX);
return createdSubnet;
}
Aggregations