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