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