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