use of com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest 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.SubnetRequest 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.SubnetRequest in project cloudbreak by hortonworks.
the class AwsNetworkCfTemplateProvider method createInterfaceServiceEndpoints.
private List<AwsServiceEndpointView> createInterfaceServiceEndpoints(NetworkCreationRequest networkCreationRequest, List<SubnetRequest> subnets) {
Map<String, String> endpointNameMappings = interfaceServices.stream().collect(Collectors.toMap(s -> String.format(VPC_INTERFACE_SERVICE_ENDPOINT_NAME_PATTERN, networkCreationRequest.getRegion().value(), s), s -> s));
List<ServiceDetail> serviceDetails = describeVpcServiceDetails(networkCreationRequest, endpointNameMappings);
Map<String, SubnetRequest> subnetByZoneMap = createPublicSubnetByZoneMap(subnets);
List<AwsServiceEndpointView> interfaceServceEndpoints = new ArrayList<>();
for (ServiceDetail serviceDetail : serviceDetails) {
List<SubnetRequest> subnetRequests = serviceDetail.getAvailabilityZones().stream().filter(az -> subnetByZoneMap.containsKey(az)).map(az -> subnetByZoneMap.get(az)).collect(Collectors.toList());
if (!subnetRequests.isEmpty()) {
interfaceServceEndpoints.add(new AwsServiceEndpointView(endpointNameMappings.get(serviceDetail.getServiceName()), subnetRequests));
}
}
return interfaceServceEndpoints;
}
use of com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest in project cloudbreak by hortonworks.
the class AwsNetworkConnector method createNetworkWithSubnets.
@Override
public CreatedCloudNetwork createNetworkWithSubnets(NetworkCreationRequest networkRequest) {
AwsCredentialView credentialView = new AwsCredentialView(networkRequest.getCloudCredential());
AmazonCloudFormationClient cloudFormationClient = awsClient.createCloudFormationClient(credentialView, networkRequest.getRegion().value());
List<SubnetRequest> subnetRequests = getCloudSubNets(networkRequest);
String cfStackName = networkRequest.getStackName();
try {
cloudFormationClient.describeStacks(new DescribeStacksRequest().withStackName(cfStackName));
LOGGER.warn("AWS CloudFormation stack for Network with stack name: '{}' already exists. Attaching this one to the network.", cfStackName);
return getCreatedNetworkWithPolling(networkRequest, credentialView, cloudFormationClient, subnetRequests);
} catch (AmazonServiceException e) {
if (networkDoesNotExist(e)) {
LOGGER.warn("{} occurred during describe AWS CloudFormation stack for Network with stack name: '{}'. " + "Assuming the CF Stack does not exist, so creating a new one. Exception message: {}", e.getClass(), cfStackName, e.getMessage());
String cloudFormationTemplate = createTemplate(networkRequest, subnetRequests);
return createNewCfNetworkStack(networkRequest, credentialView, cloudFormationClient, cloudFormationTemplate, subnetRequests);
} else {
String region = networkRequest.getRegion().getRegionName();
String errorReason = awsCloudFormationErrorMessageProvider.getErrorReason(credentialView, region, cfStackName, ResourceStatus.CREATE_FAILED);
String message = String.format("Failed to create network: %s", errorReason);
LOGGER.debug(message, e);
throw new CloudConnectorException(message, e);
}
}
}
use of com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest in project cloudbreak by hortonworks.
the class AzureNetworkTemplateBuilderTest method publicSubnetRequest.
public SubnetRequest publicSubnetRequest(String cidr, int index) {
SubnetRequest subnetRequest = new SubnetRequest();
subnetRequest.setIndex(index);
subnetRequest.setPublicSubnetCidr(cidr);
subnetRequest.setSubnetGroup(index % 3);
subnetRequest.setAvailabilityZone("az");
return subnetRequest;
}
Aggregations