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

View File

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

View File

@ -46,14 +46,15 @@ import com.google.inject.Provides;
import com.google.inject.TypeLiteral; 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 * @author Adrian Cole
*/ */
@RequiresHttp @RequiresHttp
@ConfiguresRestClient @ConfiguresRestClient
public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A extends VCloudAsyncClient> extends 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) { public BaseVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
super(syncClientType, asyncClientType); super(syncClientType, asyncClientType);
@ -77,21 +78,21 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
@Provides @Provides
@Singleton @Singleton
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final VCloudLoginAsyncClient login) { final VCloudLoginAsyncClient login) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<VCloudSession>(authException, seconds, return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<VCloudSession>(authException, seconds,
new Supplier<VCloudSession>() { new Supplier<VCloudSession>() {
@Override @Override
public VCloudSession get() { public VCloudSession get() {
try { try {
return login.login().get(10, TimeUnit.SECONDS); return login.login().get(10, TimeUnit.SECONDS);
} catch (Exception e) { } catch (Exception e) {
propagate(e); propagate(e);
assert false : e; assert false : e;
return null; 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.http.functions.config.SaxParserModule;
import org.jclouds.vcloud.VCloudPropertiesBuilder; import org.jclouds.vcloud.VCloudPropertiesBuilder;
import org.jclouds.vcloud.compute.config.CommonVCloudComputeServiceContextModule; import org.jclouds.vcloud.compute.config.CommonVCloudComputeServiceContextModule;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.xml.VAppHandler; import org.jclouds.vcloud.xml.VAppHandler;
@ -76,6 +77,9 @@ public class VAppToNodeMetadataTest {
protected void configure() { protected void configure() {
Properties props = new Properties(); Properties props = new Properties();
Names.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(), "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>>() { bind(new TypeLiteral<Function<VApp, Hardware>>() {
}).to(new TypeLiteral<HardwareForVApp>() { }).to(new TypeLiteral<HardwareForVApp>() {
}); });
@ -108,8 +112,8 @@ public class VAppToNodeMetadataTest {
} }
public void testWhenVDCIsLocation() { public void testWhenVDCIsLocation() {
Location location = new LocationBuilder().id("https://1.1.1.1/api/v1.0/vdc/1").description("description").scope( Location location = new LocationBuilder().id("https://1.1.1.1/api/v1.0/vdc/1").description("description")
LocationScope.PROVIDER).build(); .scope(LocationScope.PROVIDER).build();
Injector injector = createInjectorWithLocation(location); Injector injector = createInjectorWithLocation(location);
InputStream is = getClass().getResourceAsStream("/vapp-pool.xml"); InputStream is = getClass().getResourceAsStream("/vapp-pool.xml");
Factory factory = injector.getInstance(ParseSax.Factory.class); Factory factory = injector.getInstance(ParseSax.Factory.class);
@ -122,8 +126,8 @@ public class VAppToNodeMetadataTest {
} }
public void testGracefulWhenNoIPs() { public void testGracefulWhenNoIPs() {
Location location = new LocationBuilder().id("https://1.1.1.1/api/v1.0/vdc/1").description("description").scope( Location location = new LocationBuilder().id("https://1.1.1.1/api/v1.0/vdc/1").description("description")
LocationScope.PROVIDER).build(); .scope(LocationScope.PROVIDER).build();
Injector injector = createInjectorWithLocation(location); Injector injector = createInjectorWithLocation(location);
InputStream is = getClass().getResourceAsStream("/vapp-none.xml"); InputStream is = getClass().getResourceAsStream("/vapp-none.xml");
Factory factory = injector.getInstance(ParseSax.Factory.class); Factory factory = injector.getInstance(ParseSax.Factory.class);
@ -138,7 +142,7 @@ public class VAppToNodeMetadataTest {
@Test(expectedExceptions = NoSuchElementException.class) @Test(expectedExceptions = NoSuchElementException.class)
public void testGracefulWhenVDCIsNotLocation() { public void testGracefulWhenVDCIsNotLocation() {
Location location = new LocationBuilder().id("https://1.1.1.1/api/v1.0/vdc/11111").description("description") 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); Injector injector = createInjectorWithLocation(location);
InputStream is = getClass().getResourceAsStream("/vapp-pool.xml"); InputStream is = getClass().getResourceAsStream("/vapp-pool.xml");
Factory factory = injector.getInstance(ParseSax.Factory.class); 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.Hardware;
import org.jclouds.compute.domain.HardwareBuilder; import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VCloudExpressVApp; import org.jclouds.vcloud.domain.VCloudExpressVApp;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -42,12 +44,12 @@ public class HardwareForVCloudExpressVApp implements Function<VCloudExpressVApp,
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private final FindLocationForResource findLocationForResource; private final Function<ReferenceType, Location> findLocationForResource;
private final HardwareBuilderFromResourceAllocations rasdToHardwareBuilder; private final HardwareBuilderFromResourceAllocations rasdToHardwareBuilder;
@Inject @Inject
protected HardwareForVCloudExpressVApp(FindLocationForResource findLocationForResource, protected HardwareForVCloudExpressVApp(Function<ReferenceType, Location> findLocationForResource,
HardwareBuilderFromResourceAllocations rasdToHardwareBuilder) { HardwareBuilderFromResourceAllocations rasdToHardwareBuilder) {
this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource"); this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource");
this.rasdToHardwareBuilder = checkNotNull(rasdToHardwareBuilder, "rasdToHardwareBuilder"); this.rasdToHardwareBuilder = checkNotNull(rasdToHardwareBuilder, "rasdToHardwareBuilder");
} }
@ -58,8 +60,8 @@ public class HardwareForVCloudExpressVApp implements Function<VCloudExpressVApp,
try { try {
HardwareBuilder builder = rasdToHardwareBuilder.apply(from.getResourceAllocations()); HardwareBuilder builder = rasdToHardwareBuilder.apply(from.getResourceAllocations());
builder.location(findLocationForResource.apply(checkNotNull(from, "from").getVDC())); builder.location(findLocationForResource.apply(checkNotNull(from, "from").getVDC()));
builder.ids(from.getHref().toASCIIString()).name(from.getName()).supportsImage( builder.ids(from.getHref().toASCIIString()).name(from.getName())
ImagePredicates.idEquals(from.getHref().toASCIIString())); .supportsImage(ImagePredicates.idEquals(from.getHref().toASCIIString()));
return builder.build(); return builder.build();
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
logger.debug("incomplete data to form vApp %s", from.getHref()); 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.logging.Logger;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import com.google.common.base.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class FindLocationForResource { public class FindLocationForResource implements Function<ReferenceType, Location> {
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@ -64,7 +65,7 @@ public class FindLocationForResource {
return input; return input;
} while ((input = input.getParent()) != null); } while ((input = input.getParent()) != null);
} }
throw new NoSuchElementException(String.format("resource: %s not found in locations: %s", resource, locations throw new NoSuchElementException(String.format("resource: %s not found in locations: %s", resource,
.get())); locations.get()));
} }
} }

View File

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