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,7 +46,8 @@ 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
*/ */

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);

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,11 +44,11 @@ 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,9 +94,9 @@ 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
*/ */
@ -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
@ -145,8 +153,8 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@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();
@ -192,8 +200,8 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@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();
@ -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
@ -286,8 +294,8 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@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();
@ -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);
@ -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();
@ -478,8 +485,7 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
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();
@ -545,8 +551,7 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
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);
} }
}); });