Search in sources :

Example 1 with CreateTargetGroupRequest

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

the class AwsNativeLoadBalancerLaunchService method createTargetGroup.

private void createTargetGroup(ResourceCreationContext context, AwsNetworkView awsNetworkView, AwsTargetGroup targetGroup) {
    CloudResource targetGroupResource;
    Optional<CloudResource> existingLoadBalancer = persistenceRetriever.retrieveFirstByTypeAndStatusForStack(ResourceType.ELASTIC_LOAD_BALANCER_TARGET_GROUP, CommonStatus.CREATED, context.getStackId());
    String targetGroupArn;
    if (existingLoadBalancer.isPresent()) {
        targetGroupResource = existingLoadBalancer.get();
        targetGroupArn = targetGroupResource.getReference();
        targetGroup.setArn(targetGroupArn);
        LOGGER.info("Elastic load balancer target group resource has already been created for stack proceeding forward with existing resource '{}'", targetGroupArn);
    } else {
        int targetGroupPort = targetGroup.getPort();
        String loadBalancerArn = context.getLoadBalancerArn();
        String targetGroupName = context.getTargetGroupName();
        LOGGER.info("Creating target group for load balancer('{}') with name: '{}' port: '{}'", loadBalancerArn, targetGroupName, targetGroupPort);
        CreateTargetGroupRequest targetGroupRequest = new CreateTargetGroupRequest().withName(targetGroupName).withPort(targetGroupPort).withProtocol(ProtocolEnum.TCP).withTargetType(TargetTypeEnum.Instance).withHealthCheckPort(targetGroup.getHealthCheckPort()).withHealthCheckIntervalSeconds(TARGET_GROUP_HEALTH_CHECK_INTERVAL_SECONDS).withHealthyThresholdCount(HEALTHY_THRESHOLD_COUNT).withUnhealthyThresholdCount(UNHEALTHY_THRESHOLD_COUNT).withVpcId(awsNetworkView.getExistingVpc()).withTags(context.getTags());
        CreateTargetGroupResult targetGroupResult = createOrGetTargetGroup(context, targetGroupRequest);
        targetGroupArn = targetGroupResult.getTargetGroups().stream().findFirst().orElseThrow().getTargetGroupArn();
        targetGroup.setArn(targetGroupArn);
        targetGroupResource = new CloudResource.Builder().name(targetGroupName).type(ResourceType.ELASTIC_LOAD_BALANCER_TARGET_GROUP).reference(targetGroupArn).status(CommonStatus.CREATED).instanceId(loadBalancerArn).build();
        context.getPersistenceNotifier().notifyAllocation(targetGroupResource, context.getCloudContext());
    }
    context.setTargetGroupArn(targetGroupArn);
    CloudResourceStatus cloudResourceStatus = new CloudResourceStatus(targetGroupResource, ResourceStatus.CREATED);
    context.addResourceStatus(cloudResourceStatus);
}
Also used : CreateTargetGroupResult(com.amazonaws.services.elasticloadbalancingv2.model.CreateTargetGroupResult) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CreateTargetGroupRequest(com.amazonaws.services.elasticloadbalancingv2.model.CreateTargetGroupRequest)

Aggregations

CreateTargetGroupRequest (com.amazonaws.services.elasticloadbalancingv2.model.CreateTargetGroupRequest)1 CreateTargetGroupResult (com.amazonaws.services.elasticloadbalancingv2.model.CreateTargetGroupResult)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)1