use of com.amazonaws.services.elasticloadbalancingv2.model.CreateLoadBalancerRequest in project cloudbreak by hortonworks.
the class AwsNativeLoadBalancerLaunchService method createLoadBalancer.
private void createLoadBalancer(ResourceCreationContext context, AwsLoadBalancer awsLoadBalancer) {
CloudResource loadBalancerResource;
Optional<CloudResource> existingLoadBalancer = persistenceRetriever.retrieveFirstByTypeAndStatusForStack(ResourceType.ELASTIC_LOAD_BALANCER, CommonStatus.CREATED, context.getStackId());
String loadBalancerArn;
if (existingLoadBalancer.isPresent()) {
loadBalancerResource = existingLoadBalancer.get();
loadBalancerArn = loadBalancerResource.getReference();
LOGGER.info("Elastic load balancer resource has already been created for stack proceeding forward with existing resource '{}'", loadBalancerArn);
} else {
AwsLoadBalancerScheme scheme = awsLoadBalancer.getScheme();
Set<String> subnetIds = awsLoadBalancer.getSubnetIds();
String loadBalancerName = resourceNameService.resourceName(ResourceType.ELASTIC_LOAD_BALANCER, context.getStackName(), scheme.resourceName());
LOGGER.info("Creating load balancer with name '{}', subnet ids: '{}' and scheme: '{}'", loadBalancerName, String.join(",", subnetIds), scheme);
CreateLoadBalancerRequest request = new CreateLoadBalancerRequest().withName(loadBalancerName).withSubnets(subnetIds).withScheme(scheme.awsScheme()).withType(LoadBalancerTypeEnum.Network).withIpAddressType(IpAddressType.Ipv4).withTags(context.getTags());
CreateLoadBalancerResult loadBalancerResult = createOrGetLoadBalancer(context, request);
loadBalancerArn = loadBalancerResult.getLoadBalancers().stream().findFirst().orElseThrow().getLoadBalancerArn();
context.setLoadBalancerArn(loadBalancerArn);
loadBalancerResource = new CloudResource.Builder().name(loadBalancerName).type(ResourceType.ELASTIC_LOAD_BALANCER).reference(loadBalancerArn).status(CommonStatus.CREATED).build();
context.getPersistenceNotifier().notifyAllocation(loadBalancerResource, context.getCloudContext());
}
context.setLoadBalancerArn(loadBalancerArn);
CloudResourceStatus cloudResourceStatus = new CloudResourceStatus(loadBalancerResource, ResourceStatus.CREATED);
context.addResourceStatus(cloudResourceStatus);
}
Aggregations