cleaned up vcloud ctr args

This commit is contained in:
Adrian Cole 2011-05-27 19:56:16 -07:00
parent a3a97d02b8
commit 6ea4c96e0f
7 changed files with 173 additions and 158 deletions

View File

@ -26,8 +26,10 @@ import javax.inject.Inject;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.ovf.VirtualHardwareSection;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.Vm;
@ -42,11 +44,11 @@ public class HardwareForVApp implements Function<VApp, Hardware> {
@Resource
protected Logger logger = Logger.NULL;
private final FindLocationForResource findLocationForResource;
private final Function<ReferenceType, Location> findLocationForResource;
private final VCloudHardwareBuilderFromResourceAllocations rasdToHardwareBuilder;
@Inject
protected HardwareForVApp(FindLocationForResource findLocationForResource,
protected HardwareForVApp(Function<ReferenceType, Location> findLocationForResource,
VCloudHardwareBuilderFromResourceAllocations rasdToHardwareBuilder) {
this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource");
this.rasdToHardwareBuilder = checkNotNull(rasdToHardwareBuilder, "rasdToHardwareBuilder");

View File

@ -38,7 +38,7 @@ import com.google.common.collect.Iterables;
@Singleton
public class HardwareInOrg implements Function<Org, Iterable<? extends Hardware>> {
private final AllCatalogItemsInOrg allCatalogItemsInOrg;
private final Function<Org, Iterable<? extends CatalogItem>> allCatalogItemsInOrg;
private final Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>> vAppTemplatesForCatalogItems;
private final Provider<HardwareForVAppTemplate> sizeForVAppTemplateProvider;

View File

@ -46,14 +46,15 @@ import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
/**
* Configures the VCloud authentication service connection, including logging and http transport.
* Configures the VCloud authentication service connection, including logging
* and http transport.
*
* @author Adrian Cole
*/
@RequiresHttp
@ConfiguresRestClient
public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A extends VCloudAsyncClient> extends
CommonVCloudRestClientModule<S, A> {
CommonVCloudRestClientModule<S, A> {
public BaseVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
super(syncClientType, asyncClientType);
@ -77,21 +78,21 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
@Provides
@Singleton
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final VCloudLoginAsyncClient login) {
final VCloudLoginAsyncClient login) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<VCloudSession>(authException, seconds,
new Supplier<VCloudSession>() {
new Supplier<VCloudSession>() {
@Override
public VCloudSession get() {
try {
return login.login().get(10, TimeUnit.SECONDS);
} catch (Exception e) {
propagate(e);
assert false : e;
return null;
}
@Override
public VCloudSession get() {
try {
return login.login().get(10, TimeUnit.SECONDS);
} catch (Exception e) {
propagate(e);
assert false : e;
return null;
}
}
});
});
}
}

View File

@ -43,6 +43,7 @@ import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.vcloud.VCloudPropertiesBuilder;
import org.jclouds.vcloud.compute.config.CommonVCloudComputeServiceContextModule;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.xml.VAppHandler;
@ -76,6 +77,9 @@ public class VAppToNodeMetadataTest {
protected void configure() {
Properties props = new Properties();
Names.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(), "properties"));
bind(new TypeLiteral<Function<ReferenceType, Location>>() {
}).to(new TypeLiteral<FindLocationForResource>() {
});
bind(new TypeLiteral<Function<VApp, Hardware>>() {
}).to(new TypeLiteral<HardwareForVApp>() {
});
@ -108,8 +112,8 @@ public class VAppToNodeMetadataTest {
}
public void testWhenVDCIsLocation() {
Location location = new LocationBuilder().id("https://1.1.1.1/api/v1.0/vdc/1").description("description").scope(
LocationScope.PROVIDER).build();
Location location = new LocationBuilder().id("https://1.1.1.1/api/v1.0/vdc/1").description("description")
.scope(LocationScope.PROVIDER).build();
Injector injector = createInjectorWithLocation(location);
InputStream is = getClass().getResourceAsStream("/vapp-pool.xml");
Factory factory = injector.getInstance(ParseSax.Factory.class);
@ -122,8 +126,8 @@ public class VAppToNodeMetadataTest {
}
public void testGracefulWhenNoIPs() {
Location location = new LocationBuilder().id("https://1.1.1.1/api/v1.0/vdc/1").description("description").scope(
LocationScope.PROVIDER).build();
Location location = new LocationBuilder().id("https://1.1.1.1/api/v1.0/vdc/1").description("description")
.scope(LocationScope.PROVIDER).build();
Injector injector = createInjectorWithLocation(location);
InputStream is = getClass().getResourceAsStream("/vapp-none.xml");
Factory factory = injector.getInstance(ParseSax.Factory.class);
@ -138,7 +142,7 @@ public class VAppToNodeMetadataTest {
@Test(expectedExceptions = NoSuchElementException.class)
public void testGracefulWhenVDCIsNotLocation() {
Location location = new LocationBuilder().id("https://1.1.1.1/api/v1.0/vdc/11111").description("description")
.scope(LocationScope.PROVIDER).build();
.scope(LocationScope.PROVIDER).build();
Injector injector = createInjectorWithLocation(location);
InputStream is = getClass().getResourceAsStream("/vapp-pool.xml");
Factory factory = injector.getInstance(ParseSax.Factory.class);

View File

@ -29,7 +29,9 @@ import org.jclouds.cim.functions.HardwareBuilderFromResourceAllocations;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VCloudExpressVApp;
import com.google.common.base.Function;
@ -42,12 +44,12 @@ public class HardwareForVCloudExpressVApp implements Function<VCloudExpressVApp,
@Resource
protected Logger logger = Logger.NULL;
private final FindLocationForResource findLocationForResource;
private final Function<ReferenceType, Location> findLocationForResource;
private final HardwareBuilderFromResourceAllocations rasdToHardwareBuilder;
@Inject
protected HardwareForVCloudExpressVApp(FindLocationForResource findLocationForResource,
HardwareBuilderFromResourceAllocations rasdToHardwareBuilder) {
protected HardwareForVCloudExpressVApp(Function<ReferenceType, Location> findLocationForResource,
HardwareBuilderFromResourceAllocations rasdToHardwareBuilder) {
this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource");
this.rasdToHardwareBuilder = checkNotNull(rasdToHardwareBuilder, "rasdToHardwareBuilder");
}
@ -58,8 +60,8 @@ public class HardwareForVCloudExpressVApp implements Function<VCloudExpressVApp,
try {
HardwareBuilder builder = rasdToHardwareBuilder.apply(from.getResourceAllocations());
builder.location(findLocationForResource.apply(checkNotNull(from, "from").getVDC()));
builder.ids(from.getHref().toASCIIString()).name(from.getName()).supportsImage(
ImagePredicates.idEquals(from.getHref().toASCIIString()));
builder.ids(from.getHref().toASCIIString()).name(from.getName())
.supportsImage(ImagePredicates.idEquals(from.getHref().toASCIIString()));
return builder.build();
} catch (NoSuchElementException e) {
logger.debug("incomplete data to form vApp %s", from.getHref());

View File

@ -31,13 +31,14 @@ import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.domain.ReferenceType;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
/**
* @author Adrian Cole
*/
@Singleton
public class FindLocationForResource {
public class FindLocationForResource implements Function<ReferenceType, Location> {
@Resource
protected Logger logger = Logger.NULL;
@ -64,7 +65,7 @@ public class FindLocationForResource {
return input;
} while ((input = input.getParent()) != null);
}
throw new NoSuchElementException(String.format("resource: %s not found in locations: %s", resource, locations
.get()));
throw new NoSuchElementException(String.format("resource: %s not found in locations: %s", resource,
locations.get()));
}
}

View File

@ -35,8 +35,8 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEO
import java.net.URI;
import java.util.Map;
import java.util.SortedMap;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@ -64,6 +64,7 @@ import org.jclouds.vcloud.CommonVCloudAsyncClient;
import org.jclouds.vcloud.CommonVCloudClient;
import org.jclouds.vcloud.VCloudToken;
import org.jclouds.vcloud.VCloudVersionsAsyncClient;
import org.jclouds.vcloud.compute.functions.FindLocationForResource;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.Org;
@ -74,6 +75,7 @@ import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.endpoints.OrgList;
import org.jclouds.vcloud.endpoints.TasksList;
import org.jclouds.vcloud.functions.AllCatalogItemsInCatalog;
import org.jclouds.vcloud.functions.AllCatalogItemsInOrg;
import org.jclouds.vcloud.functions.AllCatalogsInOrg;
import org.jclouds.vcloud.functions.AllVDCsInOrg;
import org.jclouds.vcloud.functions.OrgsForLocations;
@ -92,16 +94,16 @@ import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
/**
* Configures the VCloud authentication service connection, including logging and http transport.
* Configures the VCloud authentication service connection, including logging
* and http transport.
*
* @author Adrian Cole
*/
@RequiresHttp
@ConfiguresRestClient
public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extends CommonVCloudAsyncClient> extends
RestClientModule<S, A> {
RestClientModule<S, A> {
public CommonVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
super(syncClientType, asyncClientType);
@ -111,6 +113,9 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
protected void configure() {
requestInjection(this);
super.configure();
bind(new TypeLiteral<Function<ReferenceType, Location>>() {
}).to(new TypeLiteral<FindLocationForResource>() {
});
bind(new TypeLiteral<Function<Org, Iterable<? extends Catalog>>>() {
}).to(new TypeLiteral<AllCatalogsInOrg>() {
});
@ -126,6 +131,9 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
bind(new TypeLiteral<Function<Catalog, Iterable<? extends CatalogItem>>>() {
}).to(new TypeLiteral<AllCatalogItemsInCatalog>() {
});
bind(new TypeLiteral<Function<Org, Iterable<? extends CatalogItem>>>() {
}).to(new TypeLiteral<AllCatalogItemsInOrg>() {
});
}
@Singleton
@ -144,20 +152,20 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@Singleton
@org.jclouds.vcloud.endpoints.VDC
protected Supplier<Map<String, String>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final Supplier<Map<String, ? extends Org>> orgToVDCSupplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, String>>(authException, seconds,
new Supplier<Map<String, String>>() {
@Override
public Map<String, String> get() {
Map<String, String> returnVal = newLinkedHashMap();
for (Entry<String, ? extends Org> orgr : orgToVDCSupplier.get().entrySet()) {
for (String vdc : orgr.getValue().getVDCs().keySet()) {
returnVal.put(vdc, orgr.getKey());
}
final Supplier<Map<String, ? extends Org>> orgToVDCSupplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, String>>(authException,
seconds, new Supplier<Map<String, String>>() {
@Override
public Map<String, String> get() {
Map<String, String> returnVal = newLinkedHashMap();
for (Entry<String, ? extends Org> orgr : orgToVDCSupplier.get().entrySet()) {
for (String vdc : orgr.getValue().getVDCs().keySet()) {
returnVal.put(vdc, orgr.getKey());
}
return returnVal;
}
});
return returnVal;
}
});
}
@ -167,14 +175,14 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
protected URI provideDefaultVDC(Org org, @org.jclouds.vcloud.endpoints.VDC String defaultVDC) {
checkState(org.getVDCs().size() > 0, "No vdcs present in org %s", org.getName());
return checkNotNull(org.getVDCs().get(defaultVDC), "vdc %s not present in org %s", defaultVDC, org.getName())
.getHref();
.getHref();
}
@Provides
@org.jclouds.vcloud.endpoints.VDC
@Singleton
protected String provideDefaultVDCName(
@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
Map<String, String> vDCtoOrg = vDCtoOrgSupplier.get();
checkState(vDCtoOrg.keySet().size() > 0, "No vdcs present!");
return get(vDCtoOrg.keySet(), 0);
@ -191,15 +199,15 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@Provides
@Singleton
protected Supplier<Map<String, ? extends Org>> provideOrgMapCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final OrgMapSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ? extends Org>>(authException,
seconds, new Supplier<Map<String, ? extends Org>>() {
@Override
public Map<String, ? extends Org> get() {
return supplier.get();
}
final OrgMapSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ? extends Org>>(
authException, seconds, new Supplier<Map<String, ? extends Org>>() {
@Override
public Map<String, ? extends Org> get() {
return supplier.get();
}
});
});
}
@Provides
@ -207,8 +215,8 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@OrgList
URI provideOrgListURI(Supplier<VCloudSession> sessionSupplier) {
VCloudSession session = sessionSupplier.get();
return URI.create(Iterables.getLast(session.getOrgs().values()).getHref().toASCIIString().replaceAll("org/.*",
"org"));
return URI.create(Iterables.getLast(session.getOrgs().values()).getHref().toASCIIString()
.replaceAll("org/.*", "org"));
}
@Singleton
@ -218,7 +226,7 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@Inject
protected OrgMapSupplier(Supplier<VCloudSession> sessionSupplier,
Function<Iterable<String>, Iterable<? extends Org>> organizationsForNames) {
Function<Iterable<String>, Iterable<? extends Org>> organizationsForNames) {
this.sessionSupplier = sessionSupplier;
this.organizationsForNames = organizationsForNames;
}
@ -231,13 +239,13 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@Singleton
public static class OrgCatalogSupplier implements
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> {
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> {
protected final Supplier<Map<String, ? extends Org>> orgSupplier;
private final Function<Org, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg;
@Inject
protected OrgCatalogSupplier(Supplier<Map<String, ? extends Org>> orgSupplier,
Function<Org, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg) {
Function<Org, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg) {
this.orgSupplier = orgSupplier;
this.allCatalogsInOrg = allCatalogsInOrg;
}
@ -245,16 +253,16 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
return transformValues(
transformValues(orgSupplier.get(), allCatalogsInOrg),
new Function<Iterable<? extends org.jclouds.vcloud.domain.Catalog>, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>() {
transformValues(orgSupplier.get(), allCatalogsInOrg),
new Function<Iterable<? extends org.jclouds.vcloud.domain.Catalog>, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>() {
@Override
public Map<String, ? extends org.jclouds.vcloud.domain.Catalog> apply(
Iterable<? extends org.jclouds.vcloud.domain.Catalog> from) {
return uniqueIndex(from, name);
}
@Override
public Map<String, ? extends org.jclouds.vcloud.domain.Catalog> apply(
Iterable<? extends org.jclouds.vcloud.domain.Catalog> from) {
return uniqueIndex(from, name);
}
});
});
}
}
@ -285,27 +293,27 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@org.jclouds.vcloud.endpoints.Org
@Singleton
protected Supplier<Map<String, ReferenceType>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final OrgNameToOrgSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ReferenceType>>(authException,
seconds, new Supplier<Map<String, ReferenceType>>() {
@Override
public Map<String, ReferenceType> get() {
return supplier.get();
}
});
final OrgNameToOrgSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ReferenceType>>(
authException, seconds, new Supplier<Map<String, ReferenceType>>() {
@Override
public Map<String, ReferenceType> get() {
return supplier.get();
}
});
}
@Provides
@Singleton
protected Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> provideURIToVDC(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final URItoVDC supplier) {
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final URItoVDC supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>>(
authException, seconds, new Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>>() {
@Override
public Map<URI, ? extends org.jclouds.vcloud.domain.VDC> get() {
return supplier.get();
}
});
authException, seconds, new Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>>() {
@Override
public Map<URI, ? extends org.jclouds.vcloud.domain.VDC> get() {
return supplier.get();
}
});
}
@Singleton
@ -320,24 +328,24 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@Override
public Map<URI, ? extends org.jclouds.vcloud.domain.VDC> get() {
return uniqueIndex(
concat(transform(
orgVDCMap.get().values(),
new Function<Map<String, ? extends org.jclouds.vcloud.domain.VDC>, Iterable<? extends org.jclouds.vcloud.domain.VDC>>() {
concat(transform(
orgVDCMap.get().values(),
new Function<Map<String, ? extends org.jclouds.vcloud.domain.VDC>, Iterable<? extends org.jclouds.vcloud.domain.VDC>>() {
@Override
public Iterable<? extends org.jclouds.vcloud.domain.VDC> apply(
Map<String, ? extends org.jclouds.vcloud.domain.VDC> from) {
return from.values();
}
@Override
public Iterable<? extends org.jclouds.vcloud.domain.VDC> apply(
Map<String, ? extends org.jclouds.vcloud.domain.VDC> from) {
return from.values();
}
})), new Function<org.jclouds.vcloud.domain.VDC, URI>() {
})), new Function<org.jclouds.vcloud.domain.VDC, URI>() {
@Override
public URI apply(org.jclouds.vcloud.domain.VDC from) {
return from.getHref();
}
@Override
public URI apply(org.jclouds.vcloud.domain.VDC from) {
return from.getHref();
}
});
});
}
}
@ -366,8 +374,7 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@Singleton
@org.jclouds.vcloud.endpoints.VCloudLogin
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService,
@Named(PROPERTY_API_VERSION) String version) throws InterruptedException, ExecutionException,
TimeoutException {
@Named(PROPERTY_API_VERSION) String version) throws InterruptedException, ExecutionException, TimeoutException {
SortedMap<String, URI> versions = versionService.getSupportedVersions().get(180, TimeUnit.SECONDS);
checkState(versions.size() > 0, "No versions present");
checkState(versions.containsKey(version), "version " + version + " not present in: " + versions);
@ -401,7 +408,7 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@org.jclouds.vcloud.endpoints.Catalog
@Singleton
protected String provideCatalogName(
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogs) {
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogs) {
return getLast(getLast(catalogs.get().values()).keySet());
}
@ -418,8 +425,8 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
if (networks.size() == 1)
return Iterables.getLast(networks.values()).getHref();
try {
String networkName = injector.getInstance(Key.get(String.class, Names
.named(PROPERTY_VCLOUD_DEFAULT_NETWORK)));
String networkName = injector.getInstance(Key.get(String.class,
Names.named(PROPERTY_VCLOUD_DEFAULT_NETWORK)));
ReferenceType network = networks.get(networkName);
checkState(network != null, String.format("network named %s not in %s", networkName, networks.keySet()));
return network.getHref();
@ -433,7 +440,7 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
}
protected URI findDefaultNetworkForVDC(org.jclouds.vcloud.domain.VDC vDC, Map<String, ReferenceType> networks,
Injector injector) {
Injector injector) {
logger.warn("default network for vdc %s not set", vDC.getName());
return Iterables.getLast(networks.values()).getHref();
}
@ -454,49 +461,48 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@Provides
@Singleton
protected Predicate<URI> successTester(Injector injector,
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) {
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) {
return new RetryablePredicate<URI>(injector.getInstance(TaskSuccess.class), completed);
}
@Provides
@Singleton
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> provideOrgCatalogItemMapSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgCatalogSupplier supplier) {
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgCatalogSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>>(
authException, seconds,
new Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>>() {
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
return supplier.get();
}
authException, seconds,
new Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>>() {
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
return supplier.get();
}
});
});
}
@Provides
@Singleton
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> provideOrgVDCSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgVDCSupplier supplier) {
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgVDCSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>(
authException, seconds,
new Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>() {
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
return supplier.get();
}
authException, seconds, new Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>() {
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
return supplier.get();
}
});
});
}
@Singleton
public static class OrgVDCSupplier implements
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> {
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> {
protected final Supplier<Map<String, ? extends Org>> orgSupplier;
private final Function<Org, Iterable<? extends org.jclouds.vcloud.domain.VDC>> allVDCsInOrg;
@Inject
protected OrgVDCSupplier(Supplier<Map<String, ? extends Org>> orgSupplier,
Function<Org, Iterable<? extends org.jclouds.vcloud.domain.VDC>> allVDCsInOrg) {
Function<Org, Iterable<? extends org.jclouds.vcloud.domain.VDC>> allVDCsInOrg) {
this.orgSupplier = orgSupplier;
this.allVDCsInOrg = allVDCsInOrg;
}
@ -504,29 +510,29 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
return transformValues(
transformValues(orgSupplier.get(), allVDCsInOrg),
new Function<Iterable<? extends org.jclouds.vcloud.domain.VDC>, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>() {
transformValues(orgSupplier.get(), allVDCsInOrg),
new Function<Iterable<? extends org.jclouds.vcloud.domain.VDC>, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>() {
@Override
public Map<String, ? extends org.jclouds.vcloud.domain.VDC> apply(
Iterable<? extends org.jclouds.vcloud.domain.VDC> from) {
return uniqueIndex(from, name);
}
@Override
public Map<String, ? extends org.jclouds.vcloud.domain.VDC> apply(
Iterable<? extends org.jclouds.vcloud.domain.VDC> from) {
return uniqueIndex(from, name);
}
});
});
}
}
@Singleton
public static class OrgCatalogItemSupplier implements
Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> {
Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> {
protected final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogSupplier;
private final Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog;
@Inject
protected OrgCatalogItemSupplier(
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogSupplier,
Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog) {
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogSupplier,
Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog) {
this.catalogSupplier = catalogSupplier;
this.allCatalogItemsInCatalog = allCatalogItemsInCatalog;
}
@ -534,40 +540,39 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@Override
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
return transformValues(
catalogSupplier.get(),
new Function<Map<String, ? extends org.jclouds.vcloud.domain.Catalog>, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>() {
catalogSupplier.get(),
new Function<Map<String, ? extends org.jclouds.vcloud.domain.Catalog>, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>() {
@Override
public Map<String, Map<String, ? extends CatalogItem>> apply(
Map<String, ? extends org.jclouds.vcloud.domain.Catalog> from) {
return transformValues(
from,
new Function<org.jclouds.vcloud.domain.Catalog, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>() {
@Override
public Map<String, Map<String, ? extends CatalogItem>> apply(
Map<String, ? extends org.jclouds.vcloud.domain.Catalog> from) {
return transformValues(
from,
new Function<org.jclouds.vcloud.domain.Catalog, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>() {
@Override
public Map<String, ? extends CatalogItem> apply(
org.jclouds.vcloud.domain.Catalog from) {
return uniqueIndex(allCatalogItemsInCatalog.apply(from), name);
}
});
@Override
public Map<String, ? extends CatalogItem> apply(org.jclouds.vcloud.domain.Catalog from) {
return uniqueIndex(allCatalogItemsInCatalog.apply(from), name);
}
});
}
});
}
});
}
}
@Provides
@Singleton
protected Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> provideOrgCatalogItemSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgCatalogItemSupplier supplier) {
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgCatalogItemSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>>(
authException, seconds,
new Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>>() {
@Override
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
return supplier.get();
}
});
authException, seconds,
new Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>>() {
@Override
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
return supplier.get();
}
});
}
@Provides