From a9554762d964359963ef45104b0b9e77e381bc6e Mon Sep 17 00:00:00 2001 From: Martin Harris Date: Mon, 8 Jun 2015 17:26:20 +0530 Subject: [PATCH] Fixes incorrect 'PublicIp a.b.c.d is not valid' in log when multiple gateways are present --- .../networking/vclouddirector/NatService.java | 41 +++++-------------- 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/vcloud-director/src/main/java/brooklyn/networking/vclouddirector/NatService.java b/vcloud-director/src/main/java/brooklyn/networking/vclouddirector/NatService.java index 9ff85df6..161439a8 100644 --- a/vcloud-director/src/main/java/brooklyn/networking/vclouddirector/NatService.java +++ b/vcloud-director/src/main/java/brooklyn/networking/vclouddirector/NatService.java @@ -549,37 +549,17 @@ private boolean includesPublicIp(final String publicIp, List publicIps, List subnetParticipations) { + private boolean checkPublicIps(Iterable publicIps, List subnetParticipations) { for (String publicIp : publicIps) { - checkPublicIp(publicIp, subnetParticipations); - } - } - - private void checkPublicIp(final String publicIp, List subnetParticipations) { - boolean found = includesPublicIp(publicIp, subnetParticipations); - if (!found) { - StringBuilder builder = new StringBuilder(); - builder.append("PublicIp '" + publicIp + "' is not valid. Public IP must fall in the following ranges: "); - if (subnetParticipations == null) { - for (SubnetParticipationType subnetParticipation : subnetParticipations) { - IpRangesType range = subnetParticipation.getIpRanges(); - if (range != null && range.getIpRange() != null) { - for (IpRangeType ipRangeType : range.getIpRange()) { - builder.append(ipRangeType.getStartAddress()); - builder.append(" - "); - builder.append(ipRangeType.getEndAddress()); - builder.append(", "); - } - } else { - builder.append(", "); - } - } - } else { - builder.append(""); + if (!checkPublicIp(publicIp, subnetParticipations)) { + return false; } - LOG.error(builder.toString()+" (rethrowing)"); - throw new IllegalArgumentException(builder.toString()); } + return true; + } + + private boolean checkPublicIp(final String publicIp, List subnetParticipations) { + return includesPublicIp(publicIp, subnetParticipations); } private static long ipToLong(InetAddress ip) { @@ -615,8 +595,9 @@ protected EdgeGateway getEdgeGatewayForPublicIp(Iterable publicIps) thro subnetParticipations.addAll(gatewayInterfaceType.getSubnetParticipation()); } try { - checkPublicIps(publicIps, subnetParticipations); - return edgeGateway; + if (checkPublicIps(publicIps, subnetParticipations)) { + return edgeGateway; + } } catch (IllegalArgumentException e) { errs.put(edgeGateway, e.getMessage()); }