better error message when out of IPs

This commit is contained in:
Adrian Cole 2011-10-16 03:06:13 -07:00
parent 1668a708f4
commit 7cc010e449
1 changed files with 7 additions and 6 deletions

View File

@ -21,8 +21,8 @@ package org.jclouds.trmk.ecloud.suppliers;
import static org.jclouds.trmk.vcloud_0_8.options.AddInternetServiceOptions.Builder.withDescription; import static org.jclouds.trmk.vcloud_0_8.options.AddInternetServiceOptions.Builder.withDescription;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.Map.Entry;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
@ -60,8 +60,7 @@ public class TerremarkECloudInternetServiceAndPublicIpAddressSupplier implements
} }
@Override @Override
public Entry<InternetService, PublicIpAddress> getNewInternetServiceAndIp(VApp vApp, int port, public Entry<InternetService, PublicIpAddress> getNewInternetServiceAndIp(VApp vApp, int port, Protocol protocol) {
Protocol protocol) {
logger.debug(">> creating InternetService in vDC %s:%s:%d", vApp.getVDC().getHref(), protocol, port); logger.debug(">> creating InternetService in vDC %s:%s:%d", vApp.getVDC().getHref(), protocol, port);
InternetService is = null; InternetService is = null;
PublicIpAddress ip = null; PublicIpAddress ip = null;
@ -69,7 +68,8 @@ public class TerremarkECloudInternetServiceAndPublicIpAddressSupplier implements
ip = client.activatePublicIpInVDC(vApp.getVDC().getHref()); ip = client.activatePublicIpInVDC(vApp.getVDC().getHref());
} catch (InsufficientResourcesException e) { } catch (InsufficientResourcesException e) {
logger.warn(">> no more ip addresses available, looking for one to re-use"); logger.warn(">> no more ip addresses available, looking for one to re-use");
for (PublicIpAddress existingIp : client.getPublicIpsAssociatedWithVDC(vApp.getVDC().getHref())) { Set<PublicIpAddress> publicIps = client.getPublicIpsAssociatedWithVDC(vApp.getVDC().getHref());
for (PublicIpAddress existingIp : publicIps) {
Set<InternetService> services = client.getInternetServicesOnPublicIp(existingIp.getId()); Set<InternetService> services = client.getInternetServicesOnPublicIp(existingIp.getId());
if (services.size() == 0) { if (services.size() == 0) {
ip = existingIp; ip = existingIp;
@ -77,8 +77,9 @@ public class TerremarkECloudInternetServiceAndPublicIpAddressSupplier implements
} }
} }
if (ip == null) if (ip == null)
throw e; throw new InsufficientResourcesException(
"no more ip addresses available and existing ips all have services attached: " + publicIps, e
.getCause());
} }
is = client.addInternetServiceToExistingIp(ip.getId(), vApp.getName() + "-" + port, protocol, port, is = client.addInternetServiceToExistingIp(ip.getId(), vApp.getName() + "-" + port, protocol, port,
withDescription(String.format("port %d access to serverId: %s name: %s", port, vApp.getName(), vApp withDescription(String.format("port %d access to serverId: %s name: %s", port, vApp.getName(), vApp