Search in sources :

Example 1 with CreateListenerRequest

use of com.amazonaws.services.elasticloadbalancingv2.model.CreateListenerRequest in project cloudbreak by hortonworks.

the class AwsNativeLoadBalancerLaunchService method createListener.

private void createListener(ResourceCreationContext context, AwsListener listener) {
    CloudResource listenerResource;
    Optional<CloudResource> existingLoadBalancer = persistenceRetriever.retrieveFirstByTypeAndStatusForStack(ResourceType.ELASTIC_LOAD_BALANCER_LISTENER, CommonStatus.CREATED, context.getStackId());
    if (existingLoadBalancer.isPresent()) {
        listenerResource = existingLoadBalancer.get();
        LOGGER.info("Elastic load balancer listener resource has already been created for stack proceeding forward with existing resource '{}'", listenerResource.getReference());
    } else {
        String loadBalancerArn = context.getLoadBalancerArn();
        String targetGroupArn = context.getTargetGroupArn();
        LOGGER.info("Creating listener for load balancer('{}') on target group('{}')", loadBalancerArn, targetGroupArn);
        Action defaultAction = new Action().withType(ActionTypeEnum.Forward).withOrder(1).withTargetGroupArn(targetGroupArn);
        CreateListenerRequest listenerRequest = new CreateListenerRequest().withLoadBalancerArn(loadBalancerArn).withProtocol(ProtocolEnum.TCP).withPort(listener.getPort()).withDefaultActions(defaultAction).withTags(context.getTags());
        CreateListenerResult registerListenerResult = createOrGetListener(context, listenerRequest);
        String listenerArn = registerListenerResult.getListeners().stream().findFirst().orElseThrow().getListenerArn();
        listenerResource = new CloudResource.Builder().name(context.getTargetGroupName()).type(ResourceType.ELASTIC_LOAD_BALANCER_LISTENER).reference(listenerArn).status(CommonStatus.CREATED).instanceId(loadBalancerArn).build();
        context.getPersistenceNotifier().notifyAllocation(listenerResource, context.getCloudContext());
    }
    CloudResourceStatus cloudResourceStatus = new CloudResourceStatus(listenerResource, ResourceStatus.CREATED);
    context.addResourceStatus(cloudResourceStatus);
}
Also used : Action(com.amazonaws.services.elasticloadbalancingv2.model.Action) CreateListenerRequest(com.amazonaws.services.elasticloadbalancingv2.model.CreateListenerRequest) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CreateListenerResult(com.amazonaws.services.elasticloadbalancingv2.model.CreateListenerResult) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Aggregations

Action (com.amazonaws.services.elasticloadbalancingv2.model.Action)1 CreateListenerRequest (com.amazonaws.services.elasticloadbalancingv2.model.CreateListenerRequest)1 CreateListenerResult (com.amazonaws.services.elasticloadbalancingv2.model.CreateListenerResult)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)1