Search in sources :

Example 1 with CreateLoadBalancerRequest

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);
}
Also used : CreateLoadBalancerResult(com.amazonaws.services.elasticloadbalancingv2.model.CreateLoadBalancerResult) CreateLoadBalancerRequest(com.amazonaws.services.elasticloadbalancingv2.model.CreateLoadBalancerRequest) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme)

Aggregations

CreateLoadBalancerRequest (com.amazonaws.services.elasticloadbalancingv2.model.CreateLoadBalancerRequest)1 CreateLoadBalancerResult (com.amazonaws.services.elasticloadbalancingv2.model.CreateLoadBalancerResult)1 AwsLoadBalancerScheme (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)1