better error message on service not available

This commit is contained in:
Adrian Cole 2012-02-09 18:31:44 +00:00
parent 74ded0302e
commit de1ecad1ca
1 changed files with 13 additions and 6 deletions

View File

@ -20,6 +20,7 @@ package org.jclouds.openstack.keystone.v2_0.suppliers;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -59,7 +60,9 @@ public class RegionIdToURIFromAccessForTypeAndVersionSupplier implements RegionI
@Override @Override
public Map<String, Supplier<URI>> get() { public Map<String, Supplier<URI>> get() {
Access accessResponse = access.get(); Access accessResponse = access.get();
Service service = Iterables.find(accessResponse.getServiceCatalog(), new Predicate<Service>() { Service service = null;
try {
service = Iterables.find(accessResponse.getServiceCatalog(), new Predicate<Service>() {
@Override @Override
public boolean apply(Service input) { public boolean apply(Service input) {
@ -67,6 +70,10 @@ public class RegionIdToURIFromAccessForTypeAndVersionSupplier implements RegionI
} }
}); });
} catch (NoSuchElementException e) {
throw new NoSuchElementException(String.format("apiType %s not found in catalog %s", apiType,
accessResponse.getServiceCatalog()));
}
Map<String, Endpoint> regionIdToEndpoint = Maps.uniqueIndex(Iterables.filter(service.getEndpoints(), Map<String, Endpoint> regionIdToEndpoint = Maps.uniqueIndex(Iterables.filter(service.getEndpoints(),
new Predicate<Endpoint>() { new Predicate<Endpoint>() {