Search in sources :

Example 1 with LoadBalancerSchemeEnum

use of com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancerSchemeEnum in project datarouter by hotpads.

the class AwsElbConfigScanner method getAlbSchemeForEc2Instance.

private Map<String, Boolean> getAlbSchemeForEc2Instance(String serverType, String ec2InstanceId) {
    Map<String, Boolean> privatePublicAlbsMap = new HashMap<>();
    boolean unknownAlb = true;
    boolean instanceHasPublicAlb = false;
    boolean instanceHasPrivateAlb = false;
    for (LoadBalancer loadBalancer : elbService.getLoadBalancers()) {
        // exact ALB name
        if (!loadBalancer.getLoadBalancerName().equals(serverType) && !loadBalancer.getLoadBalancerName().startsWith(serverType + "-privat")) {
            continue;
        }
        for (String targetGroupArn : elbService.getTargetGroupsArn(loadBalancer.getLoadBalancerArn())) {
            for (String targetEc2InstanceId : elbService.getTargetEc2InstancesId(targetGroupArn)) {
                if (!targetEc2InstanceId.equals(ec2InstanceId)) {
                    continue;
                }
                LoadBalancerSchemeEnum loadBalancerScheme = LoadBalancerSchemeEnum.fromValue(loadBalancer.getScheme());
                if (LoadBalancerSchemeEnum.InternetFacing == loadBalancerScheme) {
                    instanceHasPublicAlb = true;
                }
                if (LoadBalancerSchemeEnum.Internal == loadBalancerScheme) {
                    instanceHasPrivateAlb = true;
                }
                unknownAlb = false;
            }
        }
    }
    privatePublicAlbsMap.put(HAS_PUBLIC_LOAD_BALANCER_KEY, instanceHasPublicAlb);
    privatePublicAlbsMap.put(HAS_PRIVATE_LOAD_BALANCER_KEY, instanceHasPrivateAlb);
    privatePublicAlbsMap.put(UNKNOWN_LOAD_BALANCER, unknownAlb);
    return privatePublicAlbsMap;
}
Also used : HashMap(java.util.HashMap) LoadBalancer(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer) LoadBalancerSchemeEnum(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancerSchemeEnum)

Aggregations

LoadBalancer (com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer)1 LoadBalancerSchemeEnum (com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancerSchemeEnum)1 HashMap (java.util.HashMap)1