Issue 628:expose properties to choose default Org and vDC in vCloud-based implementations

This commit is contained in:
Adrian Cole 2011-07-22 11:03:29 +10:00
parent c1ae4d06e6
commit 0f9dd50d7d
68 changed files with 2160 additions and 1310 deletions

View File

@ -44,6 +44,7 @@ import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringPayload; import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.Vm; import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.domain.network.FenceMode; import org.jclouds.vcloud.domain.network.FenceMode;
@ -70,7 +71,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
protected final String ns; protected final String ns;
protected final String schema; protected final String schema;
protected final BindToStringPayload stringBinder; protected final BindToStringPayload stringBinder;
protected final URI defaultNetwork; protected final ReferenceType defaultNetwork;
protected final FenceMode defaultFenceMode; protected final FenceMode defaultFenceMode;
protected final DefaultNetworkNameInTemplate defaultNetworkNameInTemplate; protected final DefaultNetworkNameInTemplate defaultNetworkNameInTemplate;
protected final VCloudClient client; protected final VCloudClient client;
@ -78,7 +79,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
@Inject @Inject
public BindInstantiateVAppTemplateParamsToXmlPayload(DefaultNetworkNameInTemplate defaultNetworkNameInTemplate, public BindInstantiateVAppTemplateParamsToXmlPayload(DefaultNetworkNameInTemplate defaultNetworkNameInTemplate,
BindToStringPayload stringBinder, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, BindToStringPayload stringBinder, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Network URI network, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Network ReferenceType network,
@Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode, VCloudClient client) { @Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode, VCloudClient client) {
this.defaultNetworkNameInTemplate = defaultNetworkNameInTemplate; this.defaultNetworkNameInTemplate = defaultNetworkNameInTemplate;
this.ns = ns; this.ns = ns;
@ -104,8 +105,8 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
Set<? extends NetworkConfig> networkConfig = null; Set<? extends NetworkConfig> networkConfig = null;
NetworkConfigDecorator networknetworkConfigDecorator = new NetworkConfigDecorator(template, defaultNetwork, NetworkConfigDecorator networknetworkConfigDecorator = new NetworkConfigDecorator(template,
defaultFenceMode, defaultNetworkNameInTemplate); defaultNetwork.getHref(), defaultFenceMode, defaultNetworkNameInTemplate);
InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest); InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest);

View File

@ -23,21 +23,21 @@ import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.cim.xml.ResourceAllocationSettingDataHandler; import org.jclouds.cim.xml.ResourceAllocationSettingDataHandler;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.AsyncClientFactory; import org.jclouds.rest.AsyncClientFactory;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier; import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.VCloudLoginAsyncClient; import org.jclouds.vcloud.VCloudLoginAsyncClient;
import org.jclouds.vcloud.domain.CatalogItem; import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VCloudSession; import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.functions.VAppTemplatesForCatalogItems; import org.jclouds.vcloud.functions.VAppTemplatesForCatalogItems;
@ -49,47 +49,31 @@ 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);
} }
public BaseVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType, public BaseVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType,
Map<Class<?>, Class<?>> delegateMap) { Map<Class<?>, Class<?>> delegateMap) {
super(syncClientType, asyncClientType, delegateMap); super(syncClientType, asyncClientType, delegateMap);
} }
@Singleton
public static class VCloudWritableCatalog extends WriteableCatalog {
private final VCloudClient client;
@Inject
public VCloudWritableCatalog(VCloudClient client) {
super(client);
this.client = client;
}
@Override
public boolean apply(ReferenceType arg0) {
return !client.getCatalogClient().getCatalog(arg0.getHref()).isReadOnly();
}
}
@Override @Override
protected void configure() { protected void configure() {
bind(new TypeLiteral<Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>>>() { bind(new TypeLiteral<Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>>>() {
}).to(new TypeLiteral<VAppTemplatesForCatalogItems>() { }).to(new TypeLiteral<VAppTemplatesForCatalogItems>() {
}); });
bind(ResourceAllocationSettingDataHandler.class).to(VCloudResourceAllocationSettingDataHandler.class); bind(ResourceAllocationSettingDataHandler.class).to(VCloudResourceAllocationSettingDataHandler.class);
bind(WriteableCatalog.class).to(VCloudWritableCatalog.class);
super.configure(); super.configure();
} }
@ -102,21 +86,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) { AtomicReference<AuthorizationException> authException, 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

@ -18,14 +18,13 @@
*/ */
package org.jclouds.vcloud; package org.jclouds.vcloud;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -33,6 +32,7 @@ import javax.inject.Singleton;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
@ -43,6 +43,7 @@ import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VCloudSession; import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.domain.VDCStatus; import org.jclouds.vcloud.domain.VDCStatus;
import org.jclouds.vcloud.domain.internal.CatalogImpl; import org.jclouds.vcloud.domain.internal.CatalogImpl;
import org.jclouds.vcloud.domain.internal.CatalogItemImpl; import org.jclouds.vcloud.domain.internal.CatalogItemImpl;
@ -57,7 +58,7 @@ import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.inject.Injector; import com.google.inject.AbstractModule;
import com.google.inject.Module; import com.google.inject.Module;
/** /**
@ -88,67 +89,79 @@ public abstract class BaseVCloudAsyncClientTest<T> extends RestClientTest<T> {
return new RestContextFactory().createContextSpec("vcloud", "identity", "credential", overrides); return new RestContextFactory().createContextSpec("vcloud", "identity", "credential", overrides);
} }
protected static final ReferenceTypeImpl ORG_REF = new ReferenceTypeImpl("org", VCloudMediaType.ORG_XML,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/org/1"));
protected static final ReferenceTypeImpl CATALOG_REF = new ReferenceTypeImpl("catalog", VCloudMediaType.CATALOG_XML,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"));
protected static final ReferenceTypeImpl TASKSLIST_REF = new ReferenceTypeImpl("tasksList",
VCloudMediaType.TASKSLIST_XML, URI.create("https://vcenterprise.bluelock.com/api/v1.0/tasksList/1"));
protected static final ReferenceTypeImpl VDC_REF = new ReferenceTypeImpl("vdc", VCloudMediaType.VDC_XML,
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"));
protected static final ReferenceTypeImpl NETWORK_REF = new ReferenceTypeImpl("network", VCloudMediaType.NETWORK_XML,
URI.create("https://vcloud.safesecureweb.com/network/1990"));
protected static final Org ORG = new OrgImpl(ORG_REF.getName(), ORG_REF.getType(), ORG_REF.getHref(), "org", null,
ImmutableMap.<String, ReferenceType> of(CATALOG_REF.getName(), CATALOG_REF),
ImmutableMap.<String, ReferenceType> of(VDC_REF.getName(), VDC_REF), ImmutableMap.<String, ReferenceType> of(
NETWORK_REF.getName(), NETWORK_REF), TASKSLIST_REF, ImmutableList.<Task> of());
protected static final VDC VDC = new VDCImpl(VDC_REF.getName(), VDC_REF.getType(), VDC_REF.getHref(),
VDCStatus.READY, null, "description", ImmutableSet.<Task> of(), AllocationModel.ALLOCATION_POOL, null, null,
null, ImmutableMap.<String, ReferenceType> of(
"vapp",
new ReferenceTypeImpl("vapp", "application/vnd.vmware.vcloud.vApp+xml", URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/188849-1")),
"network",
new ReferenceTypeImpl("network", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdcItem/2"))),
ImmutableMap.<String, ReferenceType> of(NETWORK_REF.getName(), NETWORK_REF), 0, 0, 0, false);
@RequiresHttp @RequiresHttp
@ConfiguresRestClient @ConfiguresRestClient
public static class VCloudRestClientModuleExtension extends VCloudRestClientModule { public static class VCloudRestClientModuleExtension extends VCloudRestClientModule {
@Override @Override
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService, protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService, String version) {
@Named(PROPERTY_API_VERSION) String version) {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/login"); return URI.create("https://vcenterprise.bluelock.com/api/v1.0/login");
} }
@Override @Override
protected URI provideOrg(@org.jclouds.vcloud.endpoints.Org Iterable<ReferenceType> orgs) { protected Org provideOrg(Supplier<Map<String, ? extends Org>> orgSupplier,
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/org"); @org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) {
return ORG;
} }
@Override @Override
protected String provideOrgName(@org.jclouds.vcloud.endpoints.Org Iterable<ReferenceType> orgs) { protected void installDefaultVCloudEndpointsModule() {
return "org"; install(new AbstractModule() {
}
@Override @Override
protected URI provideCatalog(Org org, @Named(PROPERTY_IDENTITY) String user, WriteableCatalog writableCatalog) { protected void configure() {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalog"); bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.Org.class).toInstance(ORG_REF);
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.Catalog.class).toInstance(
CATALOG_REF);
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.TasksList.class).toInstance(
TASKSLIST_REF);
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.VDC.class).toInstance(VDC_REF);
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.Network.class).toInstance(
NETWORK_REF);
}
} });
@Override
protected Org provideOrg(CommonVCloudClient discovery) {
return null;
}
@Override
protected URI provideDefaultTasksList(Org org) {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/taskslist");
}
@Override
protected URI provideDefaultVDC(Org org, @org.jclouds.vcloud.endpoints.VDC String defaultVDC) {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1");
}
@Override
protected String provideDefaultVDCName(
@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
return "vdc";
}
@Override
protected URI provideDefaultNetwork(URI vdc, Injector injector) {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1990");
} }
@Override @Override
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final VCloudLoginAsyncClient login) { AtomicReference<AuthorizationException> authException, final VCloudLoginAsyncClient login) {
return Suppliers.<VCloudSession> ofInstance(new VCloudSession() { return Suppliers.<VCloudSession> ofInstance(new VCloudSession() {
@Override @Override
public Map<String, ReferenceType> getOrgs() { public Map<String, ReferenceType> getOrgs() {
return ImmutableMap.<String, ReferenceType> of("org", new ReferenceTypeImpl("org", return ImmutableMap.<String, ReferenceType> of(ORG_REF.getName(), ORG_REF);
VCloudMediaType.ORG_XML, URI.create("https://vcenterprise.bluelock.com/api/v1.0/org/1")));
} }
@Override @Override
@ -168,51 +181,18 @@ public abstract class BaseVCloudAsyncClientTest<T> extends RestClientTest<T> {
bind(OrgCatalogItemSupplier.class).to(TestOrgCatalogItemSupplier.class); bind(OrgCatalogItemSupplier.class).to(TestOrgCatalogItemSupplier.class);
} }
@Override
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, AtomicReference<AuthorizationException> authException,
OrgVDCSupplier supplier) {
return Suppliers return Suppliers.<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> ofInstance(ImmutableMap
.<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> ofInstance(ImmutableMap .<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> of(ORG_REF.getName(),
.<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> of( ImmutableMap.<String, org.jclouds.vcloud.domain.VDC> of(VDC.getName(), VDC)));
"org",
ImmutableMap
.<String, org.jclouds.vcloud.domain.VDC> of(
"vdc",
new VDCImpl(
"vdc",
null,
URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"),
VDCStatus.READY,
null,
"description",
ImmutableSet.<Task> of(),
AllocationModel.ALLOCATION_POOL,
null,
null,
null,
ImmutableMap
.<String, ReferenceType> of(
"vapp",
new ReferenceTypeImpl(
"vapp",
"application/vnd.vmware.vcloud.vApp+xml",
URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/188849-1")),
"network",
new ReferenceTypeImpl(
"network",
"application/vnd.vmware.vcloud.vAppTemplate+xml",
URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdcItem/2"))),
ImmutableMap.<String, ReferenceType> of(), 0, 0, 0,
false))));
} }
@Singleton @Singleton
public static class TestOrgMapSupplier extends OrgMapSupplier { public static class TestOrgMapSupplier extends OrgMapSupplier {
@Inject @Inject
protected TestOrgMapSupplier() { protected TestOrgMapSupplier() {
super(null, null); super(null, null);
@ -220,19 +200,7 @@ public abstract class BaseVCloudAsyncClientTest<T> extends RestClientTest<T> {
@Override @Override
public Map<String, Org> get() { public Map<String, Org> get() {
return ImmutableMap.<String, Org> of("org", new OrgImpl("org", null, URI return ImmutableMap.<String, Org> of(ORG.getName(), ORG);
.create("https://vcenterprise.bluelock.com/api/v1.0/org/1"), "org", "description", ImmutableMap
.<String, ReferenceType> of("catalog", new ReferenceTypeImpl("catalog",
VCloudMediaType.CATALOG_XML, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"))), ImmutableMap
.<String, ReferenceType> of("vdc", new ReferenceTypeImpl("vdc", VCloudMediaType.VDC_XML, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"))), ImmutableMap
.<String, ReferenceType> of("network", new ReferenceTypeImpl("network",
VCloudMediaType.NETWORK_XML, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/network/1"))),
new ReferenceTypeImpl("tasksList", VCloudMediaType.TASKSLIST_XML, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/tasksList/1")), ImmutableList
.<Task> of()));
} }
} }
@ -245,17 +213,18 @@ public abstract class BaseVCloudAsyncClientTest<T> extends RestClientTest<T> {
@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 ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> of("org", return ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> of(
ORG_REF.getName(), ImmutableMap.<String, org.jclouds.vcloud.domain.Catalog> of(
ImmutableMap.<String, org.jclouds.vcloud.domain.Catalog> of("catalog", new CatalogImpl("catalog", "type", CATALOG_REF.getName(),
URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"), null, "description", new CatalogImpl(CATALOG_REF.getName(), CATALOG_REF.getType(), CATALOG_REF.getHref(), null,
ImmutableMap.<String, ReferenceType> of("item", new ReferenceTypeImpl("item", "description", ImmutableMap.<String, ReferenceType> of(
"application/vnd.vmware.vcloud.catalogItem+xml", URI "item",
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/1")), new ReferenceTypeImpl("item", "application/vnd.vmware.vcloud.catalogItem+xml", URI
"template", new ReferenceTypeImpl("template", .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/1")),
"application/vnd.vmware.vcloud.vAppTemplate+xml", URI "template",
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"))), new ReferenceTypeImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml",
ImmutableList.<Task> of(), true, false))); URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"))),
ImmutableList.<Task> of(), true, false)));
} }
} }
@ -267,35 +236,20 @@ public abstract class BaseVCloudAsyncClientTest<T> extends RestClientTest<T> {
@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 ImmutableMap return ImmutableMap.<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> of(
.<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> of( ORG_REF.getName(), ImmutableMap
"org", .<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>> of(CATALOG_REF
ImmutableMap .getName(), ImmutableMap.<String, org.jclouds.vcloud.domain.CatalogItem> of(
.<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>> of( "template",
"catalog", new CatalogItemImpl("template", URI
ImmutableMap .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"), "description",
.<String, org.jclouds.vcloud.domain.CatalogItem> of( new ReferenceTypeImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml",
"template", URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2")),
new CatalogItemImpl( ImmutableMap.<String, String> of()))));
"template",
URI
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"),
"description",
new ReferenceTypeImpl(
"template",
"application/vnd.vmware.vcloud.vAppTemplate+xml",
URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2")),
ImmutableMap.<String, String> of()))));
} }
} }
@Override
protected Iterable<ReferenceType> provideOrgs(Supplier<VCloudSession> cache, String user) {
return null;
}
} }
} }

View File

@ -31,6 +31,9 @@ import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.domain.Vm; import org.jclouds.vcloud.domain.Vm;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
/** /**
* Tests behavior of deprecated {@code VCloudClient} features * Tests behavior of deprecated {@code VCloudClient} features
* *
@ -40,30 +43,43 @@ import org.testng.annotations.Test;
@Test(groups = "live", singleThreaded = true) @Test(groups = "live", singleThreaded = true)
public class DeprecatedVCloudClientLiveTest extends CommonVCloudClientLiveTest<VCloudClient, VCloudAsyncClient> { public class DeprecatedVCloudClientLiveTest extends CommonVCloudClientLiveTest<VCloudClient, VCloudAsyncClient> {
@Override
protected Iterable<Org> listOrgs() {
return Iterables.transform(connection.listOrgs().values(), new Function<ReferenceType, Org>(){
@Override
public Org apply(ReferenceType arg0) {
return connection.getOrg(arg0.getHref());
}
});
}
@Test @Test
public void testListOrgs() throws Exception { public void testListOrgs() throws Exception {
for (ReferenceType response : connection.listOrgs().values()) { for (Org org : orgs) {
assertNotNull(response); assertNotNull(org);
assertNotNull(response.getName()); assertNotNull(org.getName());
assertNotNull(response.getHref()); assertNotNull(org.getHref());
assertEquals(connection.getOrg(response.getHref()).getName(), response.getName()); assertEquals(connection.getOrg(org.getHref()).getName(), org.getName());
assertEquals(connection.findOrgNamed(response.getName()).getName(), response.getName()); assertEquals(connection.findOrgNamed(org.getName()).getName(), org.getName());
} }
} }
@Test @Test
public void testGetVAppTemplate() throws Exception { public void testGetVAppTemplate() throws Exception {
Org org = connection.findOrgNamed(null); for (Org org : orgs) {
for (ReferenceType cat : org.getCatalogs().values()) { for (ReferenceType cat : org.getCatalogs().values()) {
Catalog response = connection.getCatalog(cat.getHref()); Catalog response = connection.getCatalog(cat.getHref());
for (ReferenceType resource : response.values()) { for (ReferenceType resource : response.values()) {
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
CatalogItem item = connection.getCatalogItem(resource.getHref()); CatalogItem item = connection.getCatalogItem(resource.getHref());
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) { if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
try { try {
assertNotNull(connection.getVAppTemplate(item.getEntity().getHref())); assertNotNull(connection.getVAppTemplate(item.getEntity().getHref()));
} catch (AuthorizationException e) { } catch (AuthorizationException e) {
}
} }
} }
} }
@ -73,96 +89,16 @@ public class DeprecatedVCloudClientLiveTest extends CommonVCloudClientLiveTest<V
@Test @Test
public void testGetOvfEnvelopeForVAppTemplate() throws Exception { public void testGetOvfEnvelopeForVAppTemplate() throws Exception {
Org org = connection.findOrgNamed(null); for (Org org : orgs) {
for (ReferenceType cat : org.getCatalogs().values()) { for (ReferenceType cat : org.getCatalogs().values()) {
Catalog response = connection.getCatalog(cat.getHref()); Catalog response = connection.getCatalog(cat.getHref());
for (ReferenceType resource : response.values()) { for (ReferenceType resource : response.values()) {
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
try {
CatalogItem item = connection.getCatalogItem(resource.getHref());
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
assertNotNull(connection.getOvfEnvelopeForVAppTemplate(item.getEntity().getHref()));
}
} catch (AuthorizationException e) {
}
}
}
}
}
@Test
public void testGetVApp() throws Exception {
Org org = connection.findOrgNamed(null);
for (ReferenceType vdc : org.getVDCs().values()) {
VDC response = connection.getVDC(vdc.getHref());
for (ReferenceType item : response.getResourceEntities().values()) {
if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
try {
VApp app = connection.getVApp(item.getHref());
assertNotNull(app);
} catch (RuntimeException e) {
}
}
}
}
}
@Test
public void testGetThumbnailOfVm() throws Exception {
Org org = connection.findOrgNamed(null);
for (ReferenceType vdc : org.getVDCs().values()) {
VDC response = connection.getVDC(vdc.getHref());
for (ReferenceType item : response.getResourceEntities().values()) {
if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
try {
VApp app = connection.getVApp(item.getHref());
assertNotNull(app);
for (Vm vm : app.getChildren()) {
assert connection.getThumbnailOfVm(vm.getHref()) != null;
}
} catch (RuntimeException e) {
}
}
}
}
}
@Test
public void testGetVm() throws Exception {
Org org = connection.findOrgNamed(null);
for (ReferenceType vdc : org.getVDCs().values()) {
VDC response = connection.getVDC(vdc.getHref());
for (ReferenceType item : response.getResourceEntities().values()) {
if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
try {
VApp app = connection.getVApp(item.getHref());
assertNotNull(app);
for (Vm vm : app.getChildren()) {
// assertEquals(connection.getVm(vm.getHref()), vm);
}
} catch (RuntimeException e) {
}
}
}
}
}
@Test
public void testFindVAppTemplate() throws Exception {
Org org = connection.findOrgNamed(null);
for (ReferenceType cat : org.getCatalogs().values()) {
Catalog response = connection.getCatalog(cat.getHref());
for (ReferenceType resource : response.values()) {
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
CatalogItem item = connection.getCatalogItem(resource.getHref());
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
try { try {
assertNotNull(connection.findVAppTemplateInOrgCatalogNamed(org.getName(), response.getName(), item CatalogItem item = connection.getCatalogItem(resource.getHref());
.getEntity().getName())); if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
assertNotNull(connection.getOvfEnvelopeForVAppTemplate(item.getEntity().getHref()));
}
} catch (AuthorizationException e) { } catch (AuthorizationException e) {
} }
@ -171,4 +107,88 @@ public class DeprecatedVCloudClientLiveTest extends CommonVCloudClientLiveTest<V
} }
} }
} }
@Test
public void testGetVApp() throws Exception {
for (Org org : orgs) {
for (ReferenceType vdc : org.getVDCs().values()) {
VDC response = connection.getVDC(vdc.getHref());
for (ReferenceType item : response.getResourceEntities().values()) {
if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
try {
VApp app = connection.getVApp(item.getHref());
assertNotNull(app);
} catch (RuntimeException e) {
}
}
}
}
}
}
@Test
public void testGetThumbnailOfVm() throws Exception {
for (Org org : orgs) {
for (ReferenceType vdc : org.getVDCs().values()) {
VDC response = connection.getVDC(vdc.getHref());
for (ReferenceType item : response.getResourceEntities().values()) {
if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
try {
VApp app = connection.getVApp(item.getHref());
assertNotNull(app);
for (Vm vm : app.getChildren()) {
assert connection.getThumbnailOfVm(vm.getHref()) != null;
}
} catch (RuntimeException e) {
}
}
}
}
}
}
@Test
public void testGetVm() throws Exception {
for (Org org : orgs) {
for (ReferenceType vdc : org.getVDCs().values()) {
VDC response = connection.getVDC(vdc.getHref());
for (ReferenceType item : response.getResourceEntities().values()) {
if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
try {
VApp app = connection.getVApp(item.getHref());
assertNotNull(app);
assert app.getChildren().size() > 0;
} catch (RuntimeException e) {
}
}
}
}
}
}
@Test
public void testFindVAppTemplate() throws Exception {
for (Org org : orgs) {
for (ReferenceType cat : org.getCatalogs().values()) {
Catalog response = connection.getCatalog(cat.getHref());
for (ReferenceType resource : response.values()) {
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
CatalogItem item = connection.getCatalogItem(resource.getHref());
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
try {
assertNotNull(connection.findVAppTemplateInOrgCatalogNamed(org.getName(), response.getName(),
item.getEntity().getName()));
} catch (AuthorizationException e) {
}
}
}
}
}
}
}
} }

View File

@ -37,7 +37,9 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.util.Strings2; import org.jclouds.util.Strings2;
import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.VCloudPropertiesBuilder; import org.jclouds.vcloud.VCloudPropertiesBuilder;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import org.jclouds.vcloud.domain.network.FenceMode; import org.jclouds.vcloud.domain.network.FenceMode;
import org.jclouds.vcloud.domain.network.NetworkConfig; import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.domain.ovf.VCloudNetworkSection; import org.jclouds.vcloud.domain.ovf.VCloudNetworkSection;
@ -84,8 +86,8 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
@Network @Network
@Provides @Provides
@Singleton @Singleton
URI provideNetwork() { ReferenceType provideNetwork() {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1990"); return new ReferenceTypeImpl(null, null, URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1990"));
} }
}); });
} }

View File

@ -25,6 +25,7 @@ import static org.jclouds.vcloud.VCloudMediaType.VAPPTEMPLATE_XML;
import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML; import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML;
import java.net.URI; import java.net.URI;
import java.util.Map;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
@ -47,10 +48,12 @@ import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.vcloud.binders.BindCloneVCloudExpressVAppParamsToXmlPayload; import org.jclouds.vcloud.binders.BindCloneVCloudExpressVAppParamsToXmlPayload;
import org.jclouds.vcloud.binders.BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload; import org.jclouds.vcloud.binders.BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload;
import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VCloudExpressVApp; import org.jclouds.vcloud.domain.VCloudExpressVApp;
import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate;
import org.jclouds.vcloud.domain.network.OrgNetwork; import org.jclouds.vcloud.domain.network.OrgNetwork;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.OrgNameAndCatalogNameToEndpoint; import org.jclouds.vcloud.functions.OrgNameAndCatalogNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint; import org.jclouds.vcloud.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint;
@ -65,6 +68,7 @@ import org.jclouds.vcloud.xml.VCloudExpressVAppHandler;
import org.jclouds.vcloud.xml.VCloudExpressVAppTemplateHandler; import org.jclouds.vcloud.xml.VCloudExpressVAppTemplateHandler;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.Provides;
/** /**
* Provides access to VCloud resources via their REST API. * Provides access to VCloud resources via their REST API.
@ -75,7 +79,14 @@ import com.google.common.util.concurrent.ListenableFuture;
*/ */
@RequestFilters(SetVCloudTokenCookie.class) @RequestFilters(SetVCloudTokenCookie.class)
public interface VCloudExpressAsyncClient extends CommonVCloudAsyncClient { public interface VCloudExpressAsyncClient extends CommonVCloudAsyncClient {
/**
*
* @return a listing of all orgs that the current user has access to.
*/
@Provides
@Org
Map<String, ReferenceType> listOrgs();
/** /**
* @see CommonVCloudClient#getCatalog * @see CommonVCloudClient#getCatalog
*/ */

View File

@ -19,12 +19,14 @@
package org.jclouds.vcloud; package org.jclouds.vcloud;
import java.net.URI; import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VCloudExpressVApp; import org.jclouds.vcloud.domain.VCloudExpressVApp;
import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate;
@ -40,7 +42,12 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
*/ */
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface VCloudExpressClient extends CommonVCloudClient { public interface VCloudExpressClient extends CommonVCloudClient {
/**
*
* @return a listing of all orgs that the current user has access to.
*/
Map<String, ReferenceType> listOrgs();
VCloudExpressVApp instantiateVAppTemplateInVDC(URI vDC, URI template, String appName, VCloudExpressVApp instantiateVAppTemplateInVDC(URI vDC, URI template, String appName,
InstantiateVAppTemplateOptions... options); InstantiateVAppTemplateOptions... options);

View File

@ -44,6 +44,7 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder; import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringPayload; import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.network.NetworkConfig; import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.endpoints.Network; import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
@ -67,14 +68,14 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload implemen
private final BindToStringPayload stringBinder; private final BindToStringPayload stringBinder;
protected final Map<ResourceType, String> virtualHardwareToInstanceId = ImmutableMap.of(ResourceType.PROCESSOR, "1", protected final Map<ResourceType, String> virtualHardwareToInstanceId = ImmutableMap.of(ResourceType.PROCESSOR, "1",
ResourceType.MEMORY, "2", ResourceType.DISK_DRIVE, "9"); ResourceType.MEMORY, "2", ResourceType.DISK_DRIVE, "9");
private final URI defaultNetwork; private final ReferenceType defaultNetwork;
private final String defaultFenceMode; private final String defaultFenceMode;
private final String apiVersion; private final String apiVersion;
@Inject @Inject
public BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder, public BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_API_VERSION) String apiVersion, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_API_VERSION) String apiVersion, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Network URI network, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Network ReferenceType network,
@Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode) { @Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode) {
this.ns = ns; this.ns = ns;
this.apiVersion = apiVersion; this.apiVersion = apiVersion;
@ -96,7 +97,7 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload implemen
SortedMap<ResourceType, String> virtualHardwareQuantity = Maps.newTreeMap(); SortedMap<ResourceType, String> virtualHardwareQuantity = Maps.newTreeMap();
InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest); InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest);
String network = (defaultNetwork != null) ? defaultNetwork.toASCIIString() : null; String network = (defaultNetwork != null) ? defaultNetwork.getHref().toASCIIString() : null;
String fenceMode = defaultFenceMode; String fenceMode = defaultFenceMode;
String networkName = name; String networkName = name;
if (options != null) { if (options != null) {

View File

@ -34,6 +34,8 @@ import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeMetadataBuilder; import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.util.ComputeServiceUtils;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.vcloud.compute.VCloudExpressComputeClient; import org.jclouds.vcloud.compute.VCloudExpressComputeClient;
import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.Status;
@ -57,9 +59,9 @@ public class VCloudExpressVAppToNodeMetadata implements Function<VCloudExpressVA
@Inject @Inject
protected VCloudExpressVAppToNodeMetadata(VCloudExpressComputeClient computeClient, protected VCloudExpressVAppToNodeMetadata(VCloudExpressComputeClient computeClient,
Map<String, Credentials> credentialStore, Map<Status, NodeState> vAppStatusToNodeState, Map<String, Credentials> credentialStore, Map<Status, NodeState> vAppStatusToNodeState,
HardwareForVCloudExpressVApp hardwareForVCloudExpressVApp, HardwareForVCloudExpressVApp hardwareForVCloudExpressVApp,
FindLocationForResource findLocationForResourceInVDC, @Memoized Supplier<Set<? extends Image>> images) { FindLocationForResource findLocationForResourceInVDC, @Memoized Supplier<Set<? extends Image>> images) {
this.images = checkNotNull(images, "images"); this.images = checkNotNull(images, "images");
this.hardwareForVCloudExpressVApp = checkNotNull(hardwareForVCloudExpressVApp, "hardwareForVCloudExpressVApp"); this.hardwareForVCloudExpressVApp = checkNotNull(hardwareForVCloudExpressVApp, "hardwareForVCloudExpressVApp");
this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC"); this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC");
@ -76,8 +78,19 @@ public class VCloudExpressVAppToNodeMetadata implements Function<VCloudExpressVA
builder.name(from.getName()); builder.name(from.getName());
builder.location(findLocationForResourceInVDC.apply(from.getVDC())); builder.location(findLocationForResourceInVDC.apply(from.getVDC()));
builder.group(parseGroupFromName(from.getName())); builder.group(parseGroupFromName(from.getName()));
builder.operatingSystem(from.getOsType() != null ? new CIMOperatingSystem(OSType if (from.getOsType() != null && OSType.fromValue(from.getOsType()) != OSType.UNRECOGNIZED) {
.fromValue(from.getOsType()), null, null, from.getOperatingSystemDescription()) : null); builder.operatingSystem(new CIMOperatingSystem(OSType.fromValue(from.getOsType()), "", null, from
.getOperatingSystemDescription()));
} else if (from.getOperatingSystemDescription() != null) {
OperatingSystem.Builder osBuilder = new OperatingSystem.Builder();
if (from.getOsType() != null)
osBuilder.name(from.getOsType() + "");
osBuilder.family(ComputeServiceUtils.parseOsFamilyOrUnrecognized(from.getOperatingSystemDescription()));
osBuilder.version("");
osBuilder.is64Bit(from.getOperatingSystemDescription().indexOf("64") != -1);
osBuilder.description(from.getOperatingSystemDescription());
builder.operatingSystem(osBuilder.build());
}
builder.hardware(hardwareForVCloudExpressVApp.apply(from)); builder.hardware(hardwareForVCloudExpressVApp.apply(from));
builder.state(vAppStatusToNodeState.get(from.getStatus())); builder.state(vAppStatusToNodeState.get(from.getStatus()));
builder.publicAddresses(computeClient.getPublicAddresses(from.getHref())); builder.publicAddresses(computeClient.getPublicAddresses(from.getHref()));

View File

@ -23,20 +23,24 @@ import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.AsyncClientFactory; import org.jclouds.rest.AsyncClientFactory;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier; import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.vcloud.VCloudExpressAsyncClient; import org.jclouds.vcloud.VCloudExpressAsyncClient;
import org.jclouds.vcloud.VCloudExpressClient; import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.VCloudExpressLoginAsyncClient; import org.jclouds.vcloud.VCloudExpressLoginAsyncClient;
import org.jclouds.vcloud.domain.CatalogItem; import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate;
import org.jclouds.vcloud.domain.VCloudSession; import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.functions.VCloudExpressVAppTemplatesForCatalogItems; import org.jclouds.vcloud.functions.VCloudExpressVAppTemplatesForCatalogItems;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -58,7 +62,17 @@ public abstract class BaseVCloudExpressRestClientModule<S extends VCloudExpressC
public BaseVCloudExpressRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) { public BaseVCloudExpressRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
super(syncClientType, asyncClientType); super(syncClientType, asyncClientType);
} }
/**
*
* @return a listing of all orgs that the current user has access to.
*/
@Provides
@Org
Map<String, ReferenceType> listOrgs(Supplier<VCloudSession> sessionSupplier) {
return sessionSupplier.get().getOrgs();
}
public BaseVCloudExpressRestClientModule(Class<S> syncClientType, Class<A> asyncClientType, public BaseVCloudExpressRestClientModule(Class<S> syncClientType, Class<A> asyncClientType,
Map<Class<?>, Class<?>> delegateMap) { Map<Class<?>, Class<?>> delegateMap) {
super(syncClientType, asyncClientType, delegateMap); super(syncClientType, asyncClientType, delegateMap);
@ -81,7 +95,7 @@ public abstract class BaseVCloudExpressRestClientModule<S extends VCloudExpressC
@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 VCloudExpressLoginAsyncClient login) { AtomicReference<AuthorizationException> authException, final VCloudExpressLoginAsyncClient login) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<VCloudSession>(authException, seconds, return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<VCloudSession>(authException, seconds,
new Supplier<VCloudSession>() { new Supplier<VCloudSession>() {

View File

@ -51,9 +51,6 @@ public class VCloudExpressVAppImpl implements VCloudExpressVApp {
private final Set<ResourceAllocationSettingData> resourceAllocations; private final Set<ResourceAllocationSettingData> resourceAllocations;
private final Integer osType; private final Integer osType;
/** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L;
public VCloudExpressVAppImpl(String name, URI href, Status status, Long size, ReferenceType vDC, public VCloudExpressVAppImpl(String name, URI href, Status status, Long size, ReferenceType vDC,
ListMultimap<String, String> networkToAddresses, Integer osType, String operatingSystemDescription, ListMultimap<String, String> networkToAddresses, Integer osType, String operatingSystemDescription,
VirtualSystemSettingData system, Set<ResourceAllocationSettingData> resourceAllocations) { VirtualSystemSettingData system, Set<ResourceAllocationSettingData> resourceAllocations) {

View File

@ -33,8 +33,6 @@ import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate;
*/ */
public class VCloudExpressVAppTemplateImpl extends ReferenceTypeImpl implements VCloudExpressVAppTemplate { public class VCloudExpressVAppTemplateImpl extends ReferenceTypeImpl implements VCloudExpressVAppTemplate {
/** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L;
private final String description; private final String description;
private final Status status; private final Status status;

View File

@ -40,8 +40,6 @@ import com.google.common.collect.Sets;
*/ */
public class VCloudExpressNetworkImpl extends ReferenceTypeImpl implements VCloudExpressNetwork { public class VCloudExpressNetworkImpl extends ReferenceTypeImpl implements VCloudExpressNetwork {
/** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L;
protected final String description; protected final String description;
protected final Set<String> dnsServers = Sets.newHashSet(); protected final Set<String> dnsServers = Sets.newHashSet();
protected final String gateway; protected final String gateway;

View File

@ -18,8 +18,6 @@
*/ */
package org.jclouds.vcloud; package org.jclouds.vcloud;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
@ -30,6 +28,7 @@ import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -39,6 +38,7 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReleasePayloadAndReturn; import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
@ -47,10 +47,13 @@ import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Strings2; import org.jclouds.util.Strings2;
import org.jclouds.vcloud.config.VCloudExpressRestClientModule; import org.jclouds.vcloud.config.VCloudExpressRestClientModule;
import org.jclouds.vcloud.domain.AllocationModel;
import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VCloudSession; import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.domain.VDCStatus;
import org.jclouds.vcloud.domain.internal.CatalogImpl; import org.jclouds.vcloud.domain.internal.CatalogImpl;
import org.jclouds.vcloud.domain.internal.CatalogItemImpl; import org.jclouds.vcloud.domain.internal.CatalogItemImpl;
import org.jclouds.vcloud.domain.internal.OrgImpl; import org.jclouds.vcloud.domain.internal.OrgImpl;
@ -62,12 +65,12 @@ import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.ParseTaskFromLocationHeader; import org.jclouds.vcloud.functions.ParseTaskFromLocationHeader;
import org.jclouds.vcloud.options.CloneVAppOptions; import org.jclouds.vcloud.options.CloneVAppOptions;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.xml.VCloudExpressCatalogHandler;
import org.jclouds.vcloud.xml.CatalogItemHandler; import org.jclouds.vcloud.xml.CatalogItemHandler;
import org.jclouds.vcloud.xml.OrgHandler; import org.jclouds.vcloud.xml.OrgHandler;
import org.jclouds.vcloud.xml.OrgNetworkFromVCloudExpressNetworkHandler; import org.jclouds.vcloud.xml.OrgNetworkFromVCloudExpressNetworkHandler;
import org.jclouds.vcloud.xml.TaskHandler; import org.jclouds.vcloud.xml.TaskHandler;
import org.jclouds.vcloud.xml.TasksListHandler; import org.jclouds.vcloud.xml.TasksListHandler;
import org.jclouds.vcloud.xml.VCloudExpressCatalogHandler;
import org.jclouds.vcloud.xml.VCloudExpressVAppHandler; import org.jclouds.vcloud.xml.VCloudExpressVAppHandler;
import org.jclouds.vcloud.xml.VCloudExpressVAppTemplateHandler; import org.jclouds.vcloud.xml.VCloudExpressVAppTemplateHandler;
import org.jclouds.vcloud.xml.VDCHandler; import org.jclouds.vcloud.xml.VDCHandler;
@ -77,7 +80,8 @@ import com.google.common.base.Supplier;
import com.google.common.base.Suppliers; import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.inject.Injector; import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
@ -86,10 +90,16 @@ import com.google.inject.TypeLiteral;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire // NOTE:without testName, this will not call @Before* and fail w/NPE during
// surefire
@Test(groups = "unit", testName = "VCloudExpressAsyncClientTest") @Test(groups = "unit", testName = "VCloudExpressAsyncClientTest")
public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAsyncClient> { public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAsyncClient> {
public void testListOrgs() {
assertEquals(injector.getInstance(VCloudExpressAsyncClient.class).listOrgs().toString(),
ImmutableMap.of(ORG_REF.getName(), ORG_REF).toString());
}
public void testInstantiateVAppTemplateInVDCURI() throws SecurityException, NoSuchMethodException, IOException { public void testInstantiateVAppTemplateInVDCURI() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudExpressAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class, Method method = VCloudExpressAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class,
String.class, InstantiateVAppTemplateOptions[].class); String.class, InstantiateVAppTemplateOptions[].class);
@ -322,7 +332,22 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
checkFilters(request); checkFilters(request);
} }
public void testFindVAppTemplateNulls() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudExpressAsyncClient.class.getMethod("findVAppTemplateInOrgCatalogNamed", String.class,
String.class, String.class);
HttpRequest request = processor.createRequest(method, null, null, "template");
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VCloudExpressVAppTemplateHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testVAppTemplateURI() throws SecurityException, NoSuchMethodException, IOException { public void testVAppTemplateURI() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudExpressAsyncClient.class.getMethod("getVAppTemplate", URI.class); Method method = VCloudExpressAsyncClient.class.getMethod("getVAppTemplate", URI.class);
HttpRequest request = processor.createRequest(method, HttpRequest request = processor.createRequest(method,
@ -658,71 +683,79 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
new Properties()); new Properties());
} }
protected static final ReferenceTypeImpl ORG_REF = new ReferenceTypeImpl("org", VCloudMediaType.ORG_XML,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"));
protected static final ReferenceTypeImpl CATALOG_REF = new ReferenceTypeImpl("catalog", VCloudMediaType.CATALOG_XML,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"));
protected static final ReferenceTypeImpl TASKSLIST_REF = new ReferenceTypeImpl("tasksList",
VCloudMediaType.TASKSLIST_XML, URI.create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1"));
protected static final ReferenceTypeImpl VDC_REF = new ReferenceTypeImpl("vdc", VCloudMediaType.VDC_XML,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"));
protected static final ReferenceTypeImpl NETWORK_REF = new ReferenceTypeImpl("network", VCloudMediaType.NETWORK_XML,
URI.create("https://vcloud.safesecureweb.com/network/1990"));
protected static final Org ORG = new OrgImpl(ORG_REF.getName(), ORG_REF.getType(), ORG_REF.getHref(), "org", null,
ImmutableMap.<String, ReferenceType> of(CATALOG_REF.getName(), CATALOG_REF),
ImmutableMap.<String, ReferenceType> of(VDC_REF.getName(), VDC_REF), ImmutableMap.<String, ReferenceType> of(
NETWORK_REF.getName(), NETWORK_REF), TASKSLIST_REF, ImmutableList.<Task> of());
protected static final VDC VDC = new VDCImpl(VDC_REF.getName(), VDC_REF.getType(), VDC_REF.getHref(),
VDCStatus.READY, null, "description", ImmutableSet.<Task> of(), AllocationModel.ALLOCATION_POOL, null, null,
null, ImmutableMap.<String, ReferenceType> of(
"vapp",
new ReferenceTypeImpl("vapp", "application/vnd.vmware.vcloud.vApp+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1")),
"network",
new ReferenceTypeImpl("network", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2"))),
ImmutableMap.<String, ReferenceType> of(NETWORK_REF.getName(), NETWORK_REF), 0, 0, 0, false);
@RequiresHttp @RequiresHttp
@ConfiguresRestClient @ConfiguresRestClient
public static class VCloudRestClientModuleExtension extends VCloudExpressRestClientModule { public static class VCloudRestClientModuleExtension extends VCloudExpressRestClientModule {
@Override @Override
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService, protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService, String version) {
@Named(PROPERTY_API_VERSION) String version) {
return URI.create("https://vcloud.safesecureweb.com/api/v0.8/login"); return URI.create("https://vcloud.safesecureweb.com/api/v0.8/login");
} }
@Override @Override
protected URI provideOrg(@org.jclouds.vcloud.endpoints.Org Iterable<ReferenceType> orgs) { protected Org provideOrg(Supplier<Map<String, ? extends Org>> orgSupplier,
return URI.create("https://vcloud.safesecureweb.com/api/v0.8/org"); @org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) {
return ORG;
} }
@Override @Override
protected String provideOrgName(@org.jclouds.vcloud.endpoints.Org Iterable<ReferenceType> orgs) { protected void installDefaultVCloudEndpointsModule() {
return "org"; install(new AbstractModule() {
}
@Override @Override
protected URI provideCatalog(Org org, @Named(PROPERTY_IDENTITY) String user, WriteableCatalog write) { protected void configure() {
return URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalog"); bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.Org.class).toInstance(ORG_REF);
} bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.Catalog.class).toInstance(
CATALOG_REF);
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.TasksList.class).toInstance(
TASKSLIST_REF);
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.VDC.class).toInstance(VDC_REF);
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.Network.class).toInstance(
NETWORK_REF);
}
@Override });
protected Org provideOrg(CommonVCloudClient discovery) {
return null;
}
@Override
protected Iterable<ReferenceType> provideOrgs(Supplier<VCloudSession> cache, @Named(PROPERTY_IDENTITY) String user) {
return null;
}
@Override
protected URI provideDefaultTasksList(Org org) {
return URI.create("https://vcloud.safesecureweb.com/api/v0.8/taskslist");
}
@Override
protected URI provideDefaultVDC(Org org, @org.jclouds.vcloud.endpoints.VDC String defaultVDC) {
return URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1");
}
@Override
protected String provideDefaultVDCName(
@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
return "vdc";
}
@Override
protected URI provideDefaultNetwork(URI vdc, Injector injector) {
return URI.create("https://vcloud.safesecureweb.com/network/1990");
} }
@Override @Override
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final VCloudExpressLoginAsyncClient login) { AtomicReference<AuthorizationException> authException, VCloudExpressLoginAsyncClient login) {
return Suppliers.<VCloudSession> ofInstance(new VCloudSession() { return Suppliers.<VCloudSession> ofInstance(new VCloudSession() {
@Override @Override
public Map<String, ReferenceType> getOrgs() { public Map<String, ReferenceType> getOrgs() {
return ImmutableMap.<String, ReferenceType> of("org", new ReferenceTypeImpl("org", return ImmutableMap.<String, ReferenceType> of(ORG_REF.getName(), ORG_REF);
VCloudExpressMediaType.ORG_XML, URI.create("https://vcloud.safesecureweb.com/api/v0.8/org/1")));
} }
@Override @Override
@ -744,26 +777,14 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
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 Suppliers.<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> ofInstance(ImmutableMap return Suppliers.<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> ofInstance(ImmutableMap
.<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> of("org", .<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> of(ORG_REF.getName(),
ImmutableMap.<String, org.jclouds.vcloud.domain.VDC> of(VDC.getName(), VDC)));
ImmutableMap.<String, org.jclouds.vcloud.domain.VDC> of(
"vdc",
new VDCImpl("vdc", null, URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), null,
null, "description", null, null, null, null, null, ImmutableMap.<String, ReferenceType> of(
"vapp",
new ReferenceTypeImpl("vapp", "application/vnd.vmware.vcloud.vApp+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1")),
"network",
new ReferenceTypeImpl("network", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2"))), null, 0, 0, 0,
false))));
} }
@Singleton @Singleton
public static class TestOrgMapSupplier extends OrgMapSupplier { public static class TestOrgMapSupplier extends OrgMapSupplier {
@Inject @Inject
protected TestOrgMapSupplier() { protected TestOrgMapSupplier() {
super(null, null); super(null, null);
@ -771,21 +792,7 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
@Override @Override
public Map<String, Org> get() { public Map<String, Org> get() {
return ImmutableMap.<String, Org> of( return ImmutableMap.<String, Org> of(ORG.getName(), ORG);
"org",
new OrgImpl("org", null, URI.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"), "org", null,
ImmutableMap.<String, ReferenceType> of(
"catalog",
new ReferenceTypeImpl("catalog", VCloudExpressMediaType.CATALOG_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))), ImmutableMap
.<String, ReferenceType> of(
"vdc",
new ReferenceTypeImpl("vdc", VCloudExpressMediaType.VDC_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"))), ImmutableMap
.<String, ReferenceType> of(), new ReferenceTypeImpl("tasksList",
VCloudExpressMediaType.TASKSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1")), ImmutableList
.<Task> of()));
} }
} }
@ -798,19 +805,18 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
@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 ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> of("org", return ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> of(
ORG_REF.getName(), ImmutableMap.<String, org.jclouds.vcloud.domain.Catalog> of(
ImmutableMap.<String, org.jclouds.vcloud.domain.Catalog> of( CATALOG_REF.getName(),
"catalog", new CatalogImpl(CATALOG_REF.getName(), CATALOG_REF.getType(), CATALOG_REF.getHref(), null,
new CatalogImpl("catalog", "type", URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"), "description", ImmutableMap.<String, ReferenceType> of(
null, "description", ImmutableMap.<String, ReferenceType> of( "item",
"item", new ReferenceTypeImpl("item", "application/vnd.vmware.vcloud.catalogItem+xml", URI
new ReferenceTypeImpl("item", "application/vnd.vmware.vcloud.catalogItem+xml", URI .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1")),
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1")), "template",
"template", new ReferenceTypeImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml",
new ReferenceTypeImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"))),
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"))), ImmutableList ImmutableList.<Task> of(), true, false)));
.<Task> of(), true, false)));
} }
} }
@ -823,8 +829,9 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
@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 ImmutableMap.<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> of( return ImmutableMap.<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> of(
"org", ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>> of( ORG_REF.getName(), ImmutableMap
"catalog", ImmutableMap.<String, org.jclouds.vcloud.domain.CatalogItem> of( .<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>> of(CATALOG_REF
.getName(), ImmutableMap.<String, org.jclouds.vcloud.domain.CatalogItem> of(
"template", "template",
new CatalogItemImpl("template", URI new CatalogItemImpl("template", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"), "description", .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"), "description",

View File

@ -28,25 +28,41 @@ import org.jclouds.vcloud.domain.VCloudExpressVApp;
import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.domain.VDC;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
/** /**
* Tests behavior of {@code VCloudExpressClient} * Tests behavior of {@code VCloudExpressClient}
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "live", sequential = true) @Test(groups = "live", singleThreaded = true)
public abstract class VCloudExpressClientLiveTest extends public abstract class VCloudExpressClientLiveTest extends
CommonVCloudClientLiveTest<VCloudExpressClient, VCloudExpressAsyncClient> { CommonVCloudClientLiveTest<VCloudExpressClient, VCloudExpressAsyncClient> {
@Override
protected Iterable<Org> listOrgs() {
return Iterables.transform(connection.listOrgs().values(), new Function<ReferenceType, Org>(){
@Override
public Org apply(ReferenceType arg0) {
return connection.getOrg(arg0.getHref());
}
});
}
@Test @Test
public void testGetVAppTemplate() throws Exception { public void testGetVAppTemplate() throws Exception {
Org org = connection.findOrgNamed(null); for (Org org : orgs) {
for (ReferenceType cat : org.getCatalogs().values()) { for (ReferenceType cat : org.getCatalogs().values()) {
Catalog response = connection.getCatalog(cat.getHref()); Catalog response = connection.getCatalog(cat.getHref());
for (ReferenceType resource : response.values()) { for (ReferenceType resource : response.values()) {
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
CatalogItem item = connection.getCatalogItem(resource.getHref()); CatalogItem item = connection.getCatalogItem(resource.getHref());
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) { if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
assertNotNull(connection.getVAppTemplate(item.getEntity().getHref())); assertNotNull(connection.getVAppTemplate(item.getEntity().getHref()));
}
} }
} }
} }
@ -55,16 +71,17 @@ public abstract class VCloudExpressClientLiveTest extends
@Test @Test
public void testGetVApp() throws Exception { public void testGetVApp() throws Exception {
Org org = connection.findOrgNamed(null); for (Org org : listOrgs()) {
for (ReferenceType vdc : org.getVDCs().values()) { for (ReferenceType vdc : org.getVDCs().values()) {
VDC response = connection.getVDC(vdc.getHref()); VDC response = connection.getVDC(vdc.getHref());
for (ReferenceType item : response.getResourceEntities().values()) { for (ReferenceType item : response.getResourceEntities().values()) {
if (item.getType().equals(VCloudMediaType.VAPP_XML)) { if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
try { try {
VCloudExpressVApp app = connection.getVApp(item.getHref()); VCloudExpressVApp app = connection.getVApp(item.getHref());
assertNotNull(app); assertNotNull(app);
} catch (RuntimeException e) { } catch (RuntimeException e) {
}
} }
} }
} }
@ -73,15 +90,16 @@ public abstract class VCloudExpressClientLiveTest extends
@Test @Test
public void testFindVAppTemplate() throws Exception { public void testFindVAppTemplate() throws Exception {
Org org = connection.findOrgNamed(null); for (Org org : listOrgs()) {
for (ReferenceType cat : org.getCatalogs().values()) { for (ReferenceType cat : org.getCatalogs().values()) {
Catalog response = connection.getCatalog(cat.getHref()); Catalog response = connection.getCatalog(cat.getHref());
for (ReferenceType resource : response.values()) { for (ReferenceType resource : response.values()) {
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
CatalogItem item = connection.getCatalogItem(resource.getHref()); CatalogItem item = connection.getCatalogItem(resource.getHref());
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) { if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
assertNotNull(connection.findVAppTemplateInOrgCatalogNamed(org.getName(), response.getName(), item assertNotNull(connection.findVAppTemplateInOrgCatalogNamed(org.getName(), response.getName(), item
.getEntity().getName())); .getEntity().getName()));
}
} }
} }
} }

View File

@ -34,6 +34,8 @@ import javax.inject.Singleton;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.util.Strings2; import org.jclouds.util.Strings2;
import org.jclouds.vcloud.VCloudExpressPropertiesBuilder; import org.jclouds.vcloud.VCloudExpressPropertiesBuilder;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import org.jclouds.vcloud.domain.network.FenceMode; import org.jclouds.vcloud.domain.network.FenceMode;
import org.jclouds.vcloud.endpoints.Network; import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
@ -66,8 +68,8 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayloadTest {
@Network @Network
@Provides @Provides
@Singleton @Singleton
URI provideNetwork() { ReferenceType provideNetwork() {
return URI.create("https://vcloud.safesecureweb.com/network/1990"); return new ReferenceTypeImpl(null, null, URI.create("https://vcloud.safesecureweb.com/network/1990"));
} }
}); });

View File

@ -57,11 +57,9 @@ import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.vcloud.VCloudExpressAsyncClient; import org.jclouds.vcloud.VCloudExpressAsyncClient;
import org.jclouds.vcloud.VCloudExpressClient; import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VCloudExpressVApp; import org.jclouds.vcloud.domain.VCloudExpressVApp;
import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint; import org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameCatalogNameItemNameToEndpoint; import org.jclouds.vcloud.functions.OrgNameCatalogNameItemNameToEndpoint;
@ -98,7 +96,6 @@ import org.jclouds.vcloud.xml.VCloudExpressCatalogHandler;
import org.jclouds.vcloud.xml.VCloudExpressVAppHandler; import org.jclouds.vcloud.xml.VCloudExpressVAppHandler;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.Provides;
/** /**
* Provides access to VCloud resources via their REST API. * Provides access to VCloud resources via their REST API.
@ -109,13 +106,6 @@ import com.google.inject.Provides;
*/ */
@RequestFilters(SetVCloudTokenCookie.class) @RequestFilters(SetVCloudTokenCookie.class)
public interface TerremarkVCloudAsyncClient extends VCloudExpressAsyncClient { public interface TerremarkVCloudAsyncClient extends VCloudExpressAsyncClient {
/**
*
* @return a listing of all orgs that the current user has access to.
*/
@Provides
@Org
Iterable<ReferenceType> listOrgs();
/** /**
* @see VCloudExpressClient#getCatalogItemInOrg * @see VCloudExpressClient#getCatalogItemInOrg

View File

@ -26,10 +26,8 @@ import javax.annotation.Nullable;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.VCloudExpressClient; import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VCloudExpressVApp; import org.jclouds.vcloud.domain.VCloudExpressVApp;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.terremark.domain.CustomizationParameters; import org.jclouds.vcloud.terremark.domain.CustomizationParameters;
import org.jclouds.vcloud.terremark.domain.InternetService; import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.KeyPair; import org.jclouds.vcloud.terremark.domain.KeyPair;
@ -43,8 +41,6 @@ import org.jclouds.vcloud.terremark.domain.VAppConfiguration;
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions; import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
import org.jclouds.vcloud.terremark.options.AddNodeOptions; import org.jclouds.vcloud.terremark.options.AddNodeOptions;
import com.google.inject.Provides;
/** /**
* Provides access to VCloud resources via their REST API. * Provides access to VCloud resources via their REST API.
* <p/> * <p/>
@ -54,13 +50,6 @@ import com.google.inject.Provides;
*/ */
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface TerremarkVCloudClient extends VCloudExpressClient { public interface TerremarkVCloudClient extends VCloudExpressClient {
/**
*
* @return a listing of all orgs that the current user has access to.
*/
@Provides
@Org
Iterable<ReferenceType> listOrgs();
/** /**
* {@inheritDoc} * {@inheritDoc}

View File

@ -23,10 +23,9 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAU
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
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 javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Inject; import javax.inject.Inject;
@ -37,6 +36,7 @@ import org.jclouds.cim.ResourceAllocationSettingData.ResourceType;
import org.jclouds.rest.binders.BindToStringPayload; import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.binders.BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload; import org.jclouds.vcloud.binders.BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.Network; import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions; import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
@ -55,7 +55,7 @@ public class TerremarkBindInstantiateVAppTemplateParamsToXmlPayload extends
@Inject @Inject
public TerremarkBindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder, public TerremarkBindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_API_VERSION) String apiVersion, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_API_VERSION) String apiVersion, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Nullable @Network URI network, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Nullable @Network ReferenceType network,
@Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode) { @Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode) {
super(stringBinder, apiVersion, ns, schema, network, fenceMode); super(stringBinder, apiVersion, ns, schema, network, fenceMode);
} }

View File

@ -17,10 +17,12 @@
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.vcloud.terremark.config; package org.jclouds.vcloud.terremark.config;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -30,6 +32,7 @@ import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.annotation.ClientError; import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError; import org.jclouds.http.annotation.ServerError;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier; import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.util.Strings2; import org.jclouds.util.Strings2;
import org.jclouds.vcloud.config.BaseVCloudExpressRestClientModule; import org.jclouds.vcloud.config.BaseVCloudExpressRestClientModule;
@ -46,7 +49,7 @@ import com.google.common.collect.Maps;
import com.google.inject.Provides; import com.google.inject.Provides;
public abstract class TerremarkRestClientModule<S extends TerremarkVCloudClient, A extends TerremarkVCloudAsyncClient> public abstract class TerremarkRestClientModule<S extends TerremarkVCloudClient, A extends TerremarkVCloudAsyncClient>
extends BaseVCloudExpressRestClientModule<S, A> { extends BaseVCloudExpressRestClientModule<S, A> {
public TerremarkRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) { public TerremarkRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
super(syncClientType, asyncClientType); super(syncClientType, asyncClientType);
@ -56,31 +59,26 @@ public abstract class TerremarkRestClientModule<S extends TerremarkVCloudClient,
Map<Class<?>, Class<?>> delegateMap) { Map<Class<?>, Class<?>> delegateMap) {
super(syncClientType, asyncClientType, delegateMap); super(syncClientType, asyncClientType, delegateMap);
} }
@Singleton @Singleton
@Provides @Provides
@Named("CreateInternetService") @Named("CreateInternetService")
String provideCreateInternetService() throws IOException { String provideCreateInternetService() throws IOException {
return Strings2.toStringAndClose(getClass().getResourceAsStream( return Strings2.toStringAndClose(getClass().getResourceAsStream("/terremark/CreateInternetService.xml"));
"/terremark/CreateInternetService.xml"));
} }
@Singleton @Singleton
@Provides @Provides
@Named("CreateNodeService") @Named("CreateNodeService")
String provideCreateNodeService() throws IOException { String provideCreateNodeService() throws IOException {
return Strings2.toStringAndClose(getClass().getResourceAsStream( return Strings2.toStringAndClose(getClass().getResourceAsStream("/terremark/CreateNodeService.xml"));
"/terremark/CreateNodeService.xml"));
} }
@Override @Override
protected void bindErrorHandlers() { protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to( bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseTerremarkVCloudErrorFromHttpResponse.class);
ParseTerremarkVCloudErrorFromHttpResponse.class); bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseTerremarkVCloudErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to( bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseTerremarkVCloudErrorFromHttpResponse.class);
ParseTerremarkVCloudErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(
ParseTerremarkVCloudErrorFromHttpResponse.class);
} }
@Singleton @Singleton
@ -111,14 +109,10 @@ public abstract class TerremarkRestClientModule<S extends TerremarkVCloudClient,
@Singleton @Singleton
@Keys @Keys
protected Supplier<Map<String, ReferenceType>> provideOrgToKeysListCache( protected Supplier<Map<String, ReferenceType>> provideOrgToKeysListCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgNameToKeysListSupplier supplier) { @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ReferenceType>>(authException, OrgNameToKeysListSupplier supplier) {
seconds, new Supplier<Map<String, ReferenceType>>() { return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ReferenceType>>(
@Override authException, seconds, supplier);
public Map<String, ReferenceType> get() {
return supplier.get();
}
});
} }
@Singleton @Singleton

View File

@ -23,6 +23,7 @@ import java.util.Map;
import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.terremark.domain.TerremarkOrg; import org.jclouds.vcloud.terremark.domain.TerremarkOrg;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -36,9 +37,10 @@ import com.google.common.collect.Maps;
public abstract class OrgURIToEndpoint implements Function<Object, URI> { public abstract class OrgURIToEndpoint implements Function<Object, URI> {
protected final Supplier<Map<String, ? extends Org>> orgMap; protected final Supplier<Map<String, ? extends Org>> orgMap;
protected final URI defaultOrg; protected final ReferenceType defaultOrg;
public OrgURIToEndpoint(Supplier<Map<String, ? extends Org>> orgMap, @org.jclouds.vcloud.endpoints.Org URI defaultUri) { public OrgURIToEndpoint(Supplier<Map<String, ? extends Org>> orgMap,
@org.jclouds.vcloud.endpoints.Org ReferenceType defaultUri) {
this.orgMap = orgMap; this.orgMap = orgMap;
this.defaultOrg = defaultUri; this.defaultOrg = defaultUri;
} }
@ -53,7 +55,7 @@ public abstract class OrgURIToEndpoint implements Function<Object, URI> {
}); });
try { try {
TerremarkOrg org = TerremarkOrg.class.cast(uriToOrg.get(from == null ? defaultOrg : from)); TerremarkOrg org = TerremarkOrg.class.cast(uriToOrg.get(from == null ? defaultOrg.getHref() : from));
return getUriFromOrg(org); return getUriFromOrg(org);
} catch (NullPointerException e) { } catch (NullPointerException e) {
throw new ResourceNotFoundException("org " + from + " not found in: " + uriToOrg, e); throw new ResourceNotFoundException("org " + from + " not found in: " + uriToOrg, e);

View File

@ -25,6 +25,7 @@ import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.terremark.domain.TerremarkOrg; import org.jclouds.vcloud.terremark.domain.TerremarkOrg;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -38,7 +39,7 @@ import com.google.common.base.Supplier;
public class OrgURIToKeysListEndpoint extends OrgURIToEndpoint implements Function<Object, URI> { public class OrgURIToKeysListEndpoint extends OrgURIToEndpoint implements Function<Object, URI> {
@Inject @Inject
public OrgURIToKeysListEndpoint(Supplier<Map<String, ? extends Org>> orgMap, public OrgURIToKeysListEndpoint(Supplier<Map<String, ? extends Org>> orgMap,
@org.jclouds.vcloud.endpoints.Org URI defaultUri) { @org.jclouds.vcloud.endpoints.Org ReferenceType defaultUri) {
super(orgMap, defaultUri); super(orgMap, defaultUri);
} }

View File

@ -25,6 +25,7 @@ import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.VDC; import org.jclouds.vcloud.endpoints.VDC;
import org.jclouds.vcloud.terremark.domain.TerremarkVDC; import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
@ -38,19 +39,19 @@ import com.google.common.base.Supplier;
@Singleton @Singleton
public class VDCURIToInternetServicesEndpoint implements Function<Object, URI> { public class VDCURIToInternetServicesEndpoint implements Function<Object, URI> {
private final Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> orgVDCMap; private final Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> orgVDCMap;
private final URI defaultVDC; private final ReferenceType defaultVDC;
@Inject @Inject
public VDCURIToInternetServicesEndpoint(Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> orgVDCMap, public VDCURIToInternetServicesEndpoint(Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> orgVDCMap,
@VDC URI defaultVDC) { @VDC ReferenceType defaultVDC) {
this.orgVDCMap = orgVDCMap; this.orgVDCMap = orgVDCMap;
this.defaultVDC = defaultVDC; this.defaultVDC = defaultVDC;
} }
public URI apply(Object from) { public URI apply(Object from) {
try { try {
return TerremarkVDC.class.cast(orgVDCMap.get().get(from == null ? defaultVDC : from)).getInternetServices() return TerremarkVDC.class.cast(orgVDCMap.get().get(from == null ? defaultVDC.getHref() : from))
.getHref(); .getInternetServices().getHref();
} catch (NullPointerException e) { } catch (NullPointerException e) {
throw new ResourceNotFoundException("vdc " + from + " not found in " + orgVDCMap.get()); throw new ResourceNotFoundException("vdc " + from + " not found in " + orgVDCMap.get());
} }

View File

@ -25,6 +25,7 @@ import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.VDC; import org.jclouds.vcloud.endpoints.VDC;
import org.jclouds.vcloud.terremark.domain.TerremarkVDC; import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
@ -38,18 +39,19 @@ import com.google.common.base.Supplier;
@Singleton @Singleton
public class VDCURIToPublicIPsEndpoint implements Function<Object, URI> { public class VDCURIToPublicIPsEndpoint implements Function<Object, URI> {
private final Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> orgVDCMap; private final Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> orgVDCMap;
private final URI defaultVDC; private final ReferenceType defaultVDC;
@Inject @Inject
public VDCURIToPublicIPsEndpoint(Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> orgVDCMap, public VDCURIToPublicIPsEndpoint(Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> orgVDCMap,
@VDC URI defaultVDC) { @VDC ReferenceType defaultVDC) {
this.orgVDCMap = orgVDCMap; this.orgVDCMap = orgVDCMap;
this.defaultVDC = defaultVDC; this.defaultVDC = defaultVDC;
} }
public URI apply(Object from) { public URI apply(Object from) {
try { try {
return TerremarkVDC.class.cast(orgVDCMap.get().get(from == null ? defaultVDC : from)).getPublicIps().getHref(); return TerremarkVDC.class.cast(orgVDCMap.get().get(from == null ? defaultVDC.getHref() : from)).getPublicIps()
.getHref();
} catch (NullPointerException e) { } catch (NullPointerException e) {
throw new ResourceNotFoundException("vdc " + from + " not found in " + orgVDCMap.get()); throw new ResourceNotFoundException("vdc " + from + " not found in " + orgVDCMap.get());
} }

View File

@ -54,6 +54,7 @@ import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.jclouds.vcloud.VCloudExpressClientLiveTest; import org.jclouds.vcloud.VCloudExpressClientLiveTest;
import org.jclouds.vcloud.VCloudExpressMediaType; import org.jclouds.vcloud.VCloudExpressMediaType;
import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
@ -64,10 +65,12 @@ import org.jclouds.vcloud.options.CloneVAppOptions;
import org.jclouds.vcloud.predicates.TaskSuccess; import org.jclouds.vcloud.predicates.TaskSuccess;
import org.jclouds.vcloud.terremark.domain.CustomizationParameters; import org.jclouds.vcloud.terremark.domain.CustomizationParameters;
import org.jclouds.vcloud.terremark.domain.InternetService; import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.KeyPair;
import org.jclouds.vcloud.terremark.domain.Node; import org.jclouds.vcloud.terremark.domain.Node;
import org.jclouds.vcloud.terremark.domain.Protocol; import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.domain.PublicIpAddress; import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
import org.jclouds.vcloud.terremark.domain.TerremarkCatalogItem; import org.jclouds.vcloud.terremark.domain.TerremarkCatalogItem;
import org.jclouds.vcloud.terremark.domain.TerremarkOrg;
import org.jclouds.vcloud.terremark.domain.TerremarkVDC; import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions; import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions; import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
@ -99,49 +102,65 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
protected VCloudExpressVApp clone; protected VCloudExpressVApp clone;
protected VDC vdc; protected VDC vdc;
public static final String PREFIX = System.getProperty("user.name") + "-terremark"; public static final String PREFIX = System.getProperty("user.name") + "-terremark";
@Test @Test
public void testListOrgs() throws Exception { public void testKeysList() throws Exception {
for (ReferenceType org : tmClient.listOrgs()) { for (Org oorg : orgs) {
assertNotNull(tmClient.getOrg(org.getHref())); TerremarkVCloudClient vCloudExpressClient = TerremarkVCloudClient.class.cast(tmClient);
TerremarkOrg org = (TerremarkOrg) oorg;
Set<KeyPair> response = vCloudExpressClient.listKeyPairsInOrg(org.getHref());
assertNotNull(response);
} }
} }
@Test @Test
public void testGetAllInternetServices() throws Exception { public void testGetAllInternetServices() throws Exception {
for (InternetService service : tmClient.getAllInternetServicesInVDC(tmClient.findVDCInOrgNamed(null, null) for (Org org : orgs) {
.getHref())) { for (ReferenceType vdc : org.getVDCs().values()) {
assertNotNull(tmClient.getNodes(service.getId())); for (InternetService service : tmClient.getAllInternetServicesInVDC(vdc.getHref())) {
assertNotNull(tmClient.getNodes(service.getId()));
}
}
} }
} }
@Test @Test
public void testCreateInternetServiceMonitorDisabled() throws Exception { public void testCreateInternetServiceMonitorDisabled() throws Exception {
VDC vdc = tmClient.findVDCInOrgNamed(null, null); for (Org org : orgs) {
Set<PublicIpAddress> publicIpAddresses = tmClient.getPublicIpsAssociatedWithVDC(vdc.getHref()); for (ReferenceType vdc : org.getVDCs().values()) {
PublicIpAddress publicIp = publicIpAddresses.iterator().next(); Set<PublicIpAddress> publicIpAddresses = tmClient.getPublicIpsAssociatedWithVDC(vdc.getHref());
PublicIpAddress publicIp = publicIpAddresses.iterator().next();
InternetService service = tmClient.addInternetServiceToExistingIp(publicIp.getId(), PREFIX + "-no-monitoring", InternetService service = tmClient.addInternetServiceToExistingIp(publicIp.getId(), PREFIX
Protocol.TCP, 1234, AddInternetServiceOptions.Builder.monitorDisabled()); + "-no-monitoring", Protocol.TCP, 1234, AddInternetServiceOptions.Builder.monitorDisabled());
tmClient.deleteInternetService(service.getId()); tmClient.deleteInternetService(service.getId());
}
}
} }
@Test @Test
public void testGetPublicIpsAssociatedWithVDC() throws Exception { public void testGetPublicIpsAssociatedWithVDC() throws Exception {
for (PublicIpAddress ip : tmClient for (Org org : orgs) {
.getPublicIpsAssociatedWithVDC(tmClient.findVDCInOrgNamed(null, null).getHref())) { for (ReferenceType vdc : org.getVDCs().values()) {
assertNotNull(tmClient.getInternetServicesOnPublicIp(ip.getId())); for (PublicIpAddress ip : tmClient.getPublicIpsAssociatedWithVDC(vdc.getHref())) {
assertNotNull(tmClient.getPublicIp(ip.getId())); assertNotNull(tmClient.getInternetServicesOnPublicIp(ip.getId()));
assertNotNull(tmClient.getPublicIp(ip.getId()));
}
}
} }
} }
@Test @Test
public void testGetConfigCustomizationOptions() throws Exception { public void testGetConfigCustomizationOptions() throws Exception {
Catalog response = connection.findCatalogInOrgNamed(null, null); for (Org org : orgs) {
for (ReferenceType resource : response.values()) { for (ReferenceType catalog : org.getCatalogs().values()) {
if (resource.getType().equals(VCloudExpressMediaType.CATALOGITEM_XML)) { Catalog response = connection.getCatalog(catalog.getHref());
TerremarkCatalogItem item = tmClient.findCatalogItemInOrgCatalogNamed(null, null, resource.getName()); for (ReferenceType resource : response.values()) {
assert tmClient.getCustomizationOptions(item.getCustomizationOptions().getHref()) != null; if (resource.getType().equals(VCloudExpressMediaType.CATALOGITEM_XML)) {
TerremarkCatalogItem item = tmClient.findCatalogItemInOrgCatalogNamed(org.getName(),
catalog.getName(), resource.getName());
assert tmClient.getCustomizationOptions(item.getCustomizationOptions().getHref()) != null;
}
}
} }
} }
} }
@ -149,16 +168,20 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
@Test @Test
public void testDefaultVDC() throws Exception { public void testDefaultVDC() throws Exception {
super.testDefaultVDC(); super.testDefaultVDC();
TerremarkVDC response = (TerremarkVDC) tmClient.findVDCInOrgNamed(null, null); for (Org org : orgs) {
assertNotNull(response); for (ReferenceType vdc : org.getVDCs().values()) {
assertNotNull(response.getCatalog()); TerremarkVDC response = (TerremarkVDC) tmClient.getVDC(vdc.getHref());
assertNotNull(response.getInternetServices()); assertNotNull(response);
assertNotNull(response.getPublicIps()); assertNotNull(response.getCatalog());
assertNotNull(response.getInternetServices());
assertNotNull(response.getPublicIps());
}
}
} }
@Test(enabled = true) @Test(enabled = true)
public void testInstantiateAndPowerOn() throws InterruptedException, ExecutionException, TimeoutException, public void testInstantiateAndPowerOn() throws InterruptedException, ExecutionException, TimeoutException,
IOException { IOException {
prepare(); prepare();
StringBuffer name = new StringBuffer(); StringBuffer name = new StringBuffer();
for (int i = 0; i < 15; i++) for (int i = 0; i < 15; i++)
@ -184,7 +207,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
// if this template supports setting the root password, let's add it to // if this template supports setting the root password, let's add it to
// our options // our options
CustomizationParameters customizationOptions = tmClient.getCustomizationOptions(item.getCustomizationOptions() CustomizationParameters customizationOptions = tmClient.getCustomizationOptions(item.getCustomizationOptions()
.getHref()); .getHref());
if (customizationOptions.canCustomizePassword()) if (customizationOptions.canCustomizePassword())
instantiateOptions.withPassword("robotsarefun"); instantiateOptions.withPassword("robotsarefun");
@ -194,7 +217,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
// instantiate, noting vApp returned has minimal details // instantiate, noting vApp returned has minimal details
vApp = tmClient.instantiateVAppTemplateInVDC(vdc.getHref(), vAppTemplate.getHref(), serverName, vApp = tmClient.instantiateVAppTemplateInVDC(vdc.getHref(), vAppTemplate.getHref(), serverName,
instantiateOptions); instantiateOptions);
assertEquals(vApp.getStatus(), Status.RESOLVED); assertEquals(vApp.getStatus(), Status.RESOLVED);
@ -286,7 +309,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
@Test(enabled = true, dependsOnMethods = { "testInstantiateAndPowerOn", "testAddInternetService" }) @Test(enabled = true, dependsOnMethods = { "testInstantiateAndPowerOn", "testAddInternetService" })
public void testPublicIp() throws InterruptedException, ExecutionException, TimeoutException, IOException { public void testPublicIp() throws InterruptedException, ExecutionException, TimeoutException, IOException {
node = tmClient.addNode(is.getId(), Iterables.getLast(vApp.getNetworkToAddresses().values()), vApp.getName() node = tmClient.addNode(is.getId(), Iterables.getLast(vApp.getNetworkToAddresses().values()), vApp.getName()
+ "-SSH", 22); + "-SSH", 22);
loopAndCheckPass(); loopAndCheckPass();
} }
@ -349,18 +372,18 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
vApp = tmClient.getVApp(vApp.getHref()); vApp = tmClient.getVApp(vApp.getHref());
Task task = tmClient.configureVApp(vApp, changeNameTo("eduardo").changeMemoryTo(1536).changeProcessorCountTo(1) Task task = tmClient.configureVApp(vApp, changeNameTo("eduardo").changeMemoryTo(1536).changeProcessorCountTo(1)
.addDisk(25 * 1048576).addDisk(25 * 1048576)); .addDisk(25 * 1048576).addDisk(25 * 1048576));
assert successTester.apply(task.getHref()); assert successTester.apply(task.getHref());
vApp = tmClient.getVApp(vApp.getHref()); vApp = tmClient.getVApp(vApp.getHref());
assertEquals(vApp.getName(), "eduardo"); assertEquals(vApp.getName(), "eduardo");
assertEquals(find(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.PROCESSOR)) assertEquals(find(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.PROCESSOR))
.getVirtualQuantity().longValue(), 1); .getVirtualQuantity().longValue(), 1);
assertEquals(find(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.MEMORY)) assertEquals(find(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.MEMORY))
.getVirtualQuantity().longValue(), 1536); .getVirtualQuantity().longValue(), 1536);
assertEquals(size(filter(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.DISK_DRIVE))), assertEquals(size(filter(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.DISK_DRIVE))),
3); 3);
assert successTester.apply(tmClient.powerOnVApp(vApp.getHref()).getHref()); assert successTester.apply(tmClient.powerOnVApp(vApp.getHref()).getHref());
@ -370,11 +393,11 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
// extract the disks on the vApp sorted by addressOnParent // extract the disks on the vApp sorted by addressOnParent
List<ResourceAllocationSettingData> disks = Lists.newArrayList(filter(vApp.getResourceAllocations(), List<ResourceAllocationSettingData> disks = Lists.newArrayList(filter(vApp.getResourceAllocations(),
CIMPredicates.resourceTypeIn(ResourceType.DISK_DRIVE))); CIMPredicates.resourceTypeIn(ResourceType.DISK_DRIVE)));
// delete the second disk // delete the second disk
task = tmClient.configureVApp(vApp, deleteDiskWithAddressOnParent(Integer.parseInt(disks.get(1) task = tmClient.configureVApp(vApp,
.getAddressOnParent()))); deleteDiskWithAddressOnParent(Integer.parseInt(disks.get(1).getAddressOnParent())));
assert successTester.apply(task.getHref()); assert successTester.apply(task.getHref());
@ -383,17 +406,18 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
} }
protected void verifyConfigurationOfVApp(VCloudExpressVApp vApp, String serverName, String expectedOs, protected void verifyConfigurationOfVApp(VCloudExpressVApp vApp, String serverName, String expectedOs,
int processorCount, long memory, long hardDisk) { int processorCount, long memory, long hardDisk) {
assertEquals(vApp.getName(), serverName); assertEquals(vApp.getName(), serverName);
assertEquals(vApp.getOperatingSystemDescription(), expectedOs); assertEquals(vApp.getOperatingSystemDescription(), expectedOs);
assertEquals((int) find(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.PROCESSOR)) assertEquals((int) find(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.PROCESSOR))
.getVirtualQuantity().longValue(), processorCount); .getVirtualQuantity().longValue(), processorCount);
assertEquals(find(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.MEMORY)) assertEquals(find(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.MEMORY))
.getVirtualQuantity().longValue(), memory); .getVirtualQuantity().longValue(), memory);
assertEquals(find(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.DISK_DRIVE)) assertEquals(find(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.DISK_DRIVE))
.getVirtualQuantity().longValue(), hardDisk); .getVirtualQuantity().longValue(), hardDisk);
assertEquals(vApp.getSize().longValue(), find(vApp.getResourceAllocations(), assertEquals(vApp.getSize().longValue(),
CIMPredicates.resourceTypeIn(ResourceType.DISK_DRIVE)).getVirtualQuantity().longValue()); find(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.DISK_DRIVE))
.getVirtualQuantity().longValue());
} }
protected void doCheckPass(String address) throws IOException { protected void doCheckPass(String address) throws IOException {
@ -476,8 +500,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
Properties overrides = setupProperties(); Properties overrides = setupProperties();
injector = new RestContextFactory().createContextBuilder(provider, injector = new RestContextFactory().createContextBuilder(provider,
ImmutableSet.<Module> of(new Log4JLoggingModule(), new JschSshClientModule()), overrides) ImmutableSet.<Module> of(new Log4JLoggingModule(), new JschSshClientModule()), overrides).buildInjector();
.buildInjector();
connection = tmClient = injector.getInstance(TerremarkVCloudClient.class); connection = tmClient = injector.getInstance(TerremarkVCloudClient.class);

View File

@ -32,6 +32,8 @@ import javax.inject.Singleton;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.util.Strings2; import org.jclouds.util.Strings2;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import org.jclouds.vcloud.domain.network.NetworkConfig; import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.endpoints.Network; import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.terremark.TerremarkVCloudPropertiesBuilder; import org.jclouds.vcloud.terremark.TerremarkVCloudPropertiesBuilder;
@ -68,8 +70,8 @@ public class TerremarkBindInstantiateVAppTemplateParamsToXmlPayloadTest {
@Network @Network
@Provides @Provides
@Singleton @Singleton
URI provideNetwork() { ReferenceType provideNetwork() {
return URI.create("https://vcloud.safesecureweb.com/network/1990"); return new ReferenceTypeImpl(null, null, URI.create("https://vcloud.safesecureweb.com/network/1990"));
} }
}); });

View File

@ -18,16 +18,27 @@
*/ */
package org.jclouds.vcloud.compute.config; package org.jclouds.vcloud.compute.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.find;
import java.util.Set; import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.collect.Memoized;
import org.jclouds.compute.config.BindComputeSuppliersByClass; import org.jclouds.compute.config.BindComputeSuppliersByClass;
import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.vcloud.compute.suppliers.OrgAndVDCToLocationSupplier; import org.jclouds.vcloud.compute.suppliers.OrgAndVDCToLocationSupplier;
import org.jclouds.vcloud.compute.suppliers.StaticHardwareSupplier; import org.jclouds.vcloud.compute.suppliers.StaticHardwareSupplier;
import org.jclouds.vcloud.compute.suppliers.VCloudImageSupplier; import org.jclouds.vcloud.compute.suppliers.VCloudImageSupplier;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.VDC;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
/** /**
@ -48,4 +59,47 @@ public class CommonVCloudBindComputeSuppliersByClass extends BindComputeSupplier
protected Class<? extends Supplier<Set<? extends Location>>> defineLocationSupplier() { protected Class<? extends Supplier<Set<? extends Location>>> defineLocationSupplier() {
return OrgAndVDCToLocationSupplier.class; return OrgAndVDCToLocationSupplier.class;
} }
@Override
protected Class<? extends Supplier<Location>> defineDefaultLocationSupplier() {
return DefaultVDC.class;
}
@Singleton
public static class DefaultVDC implements Supplier<Location> {
@Singleton
public static final class IsDefaultVDC implements Predicate<Location> {
private final ReferenceType defaultVDC;
@Inject
IsDefaultVDC(@VDC ReferenceType defaultVDC) {
this.defaultVDC = checkNotNull(defaultVDC, "defaultVDC");
}
@Override
public boolean apply(Location input) {
return input.getScope() == LocationScope.ZONE && input.getId().equals(defaultVDC.getHref().toASCIIString());
}
@Override
public String toString() {
return "isDefaultVDC()";
}
}
private final Supplier<Set<? extends Location>> locationsSupplier;
private final IsDefaultVDC isDefaultVDC;
@Inject
DefaultVDC(@Memoized Supplier<Set<? extends Location>> locationsSupplier, IsDefaultVDC isDefaultVDC) {
this.locationsSupplier = checkNotNull(locationsSupplier, "locationsSupplierSupplier");
this.isDefaultVDC = checkNotNull(isDefaultVDC, "isDefaultVDC");
}
@Override
public Location get() {
return find(locationsSupplier.get(), isDefaultVDC);
}
}
} }

View File

@ -21,30 +21,23 @@ package org.jclouds.vcloud.config;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.Iterables.concat; import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Iterables.find;
import static com.google.common.collect.Iterables.get;
import static com.google.common.collect.Iterables.getLast; import static com.google.common.collect.Iterables.getLast;
import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Maps.newLinkedHashMap;
import static com.google.common.collect.Maps.transformValues; import static com.google.common.collect.Maps.transformValues;
import static com.google.common.collect.Maps.uniqueIndex; import static com.google.common.collect.Maps.uniqueIndex;
import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException;
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;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -55,7 +48,6 @@ import org.jclouds.http.RequiresHttp;
import org.jclouds.http.annotation.ClientError; import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError; import org.jclouds.http.annotation.ServerError;
import org.jclouds.logging.Logger;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.AsyncClientFactory; import org.jclouds.rest.AsyncClientFactory;
import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.AuthorizationException;
@ -73,9 +65,7 @@ import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VCloudSession; import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.domain.VDC;
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.functions.AllCatalogItemsInCatalog; import org.jclouds.vcloud.functions.AllCatalogItemsInCatalog;
import org.jclouds.vcloud.functions.AllCatalogItemsInOrg; import org.jclouds.vcloud.functions.AllCatalogItemsInOrg;
import org.jclouds.vcloud.functions.AllCatalogsInOrg; import org.jclouds.vcloud.functions.AllCatalogsInOrg;
@ -87,39 +77,41 @@ import org.jclouds.vcloud.predicates.TaskSuccess;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.Iterables; import com.google.common.base.Suppliers;
import com.google.inject.ConfigurationException; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Provides; import com.google.inject.Provides;
import com.google.inject.TypeLiteral; 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 * @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);
} }
public CommonVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType, public CommonVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType,
Map<Class<?>, Class<?>> delegateMap) { Map<Class<?>, Class<?>> delegateMap) {
super(syncClientType, asyncClientType, delegateMap); super(syncClientType, asyncClientType, delegateMap);
} }
@Override @Override
protected void configure() { protected void configure() {
requestInjection(this);
super.configure(); super.configure();
// Ensures we don't retry on authorization failures
bind(new TypeLiteral<AtomicReference<AuthorizationException>>() {
}).toInstance(new AtomicReference<AuthorizationException>());
installDefaultVCloudEndpointsModule();
bind(new TypeLiteral<Function<ReferenceType, Location>>() { bind(new TypeLiteral<Function<ReferenceType, Location>>() {
}).to(new TypeLiteral<FindLocationForResource>() { }).to(new TypeLiteral<FindLocationForResource>() {
}); });
@ -158,68 +150,29 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
@Provides @Provides
@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(Supplier<Map<String, ? extends Org>> orgNameToOrgSuppier) {
final Supplier<Map<String, ? extends Org>> orgToVDCSupplier) { return Suppliers.compose(new Function<Map<String, ? extends Org>, Map<String, String>>() {
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;
}
});
} @Override
public Map<String, String> apply(Map<String, ? extends Org> arg0) {
Builder<String, String> returnVal = ImmutableMap.<String, String> builder();
for (Entry<String, ? extends Org> orgr : arg0.entrySet()) {
for (String vdc : orgr.getValue().getVDCs().keySet()) {
returnVal.put(vdc, orgr.getKey());
}
}
return returnVal.build();
}
}, orgNameToOrgSuppier);
@Provides
@org.jclouds.vcloud.endpoints.VDC
@Singleton
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();
}
@Provides
@org.jclouds.vcloud.endpoints.VDC
@Singleton
protected String provideDefaultVDCName(
@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);
}
@Provides
@org.jclouds.vcloud.endpoints.Catalog
@Singleton
protected URI provideCatalog(Org org, @Named(PROPERTY_IDENTITY) String user, WriteableCatalog writableCatalog) {
checkState(org.getCatalogs().size() > 0, "No catalogs present in org: " + org.getName());
try {
return find(org.getCatalogs().values(), writableCatalog).getHref();
} catch (NoSuchElementException e) {
throw new NoSuchElementException(String.format("no writable catalogs in org %s; catalogs %s", org, org
.getCatalogs()));
}
} }
@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) { AtomicReference<AuthorizationException> authException, OrgMapSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ? extends Org>>( return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ? extends Org>>(
authException, seconds, new Supplier<Map<String, ? extends Org>>() { authException, seconds, supplier);
@Override
public Map<String, ? extends Org> get() {
return supplier.get();
}
});
} }
@Provides @Provides
@ -227,33 +180,17 @@ 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(getLast(session.getOrgs().values()).getHref().toASCIIString().replaceAll("org/.*", "org"));
"org"));
}
@Singleton
public static class WriteableCatalog implements Predicate<ReferenceType> {
private final CommonVCloudClient client;
@Inject
public WriteableCatalog(CommonVCloudClient client) {
this.client = client;
}
@Override
public boolean apply(ReferenceType arg0) {
return !client.getCatalog(arg0.getHref()).isReadOnly();
}
} }
@Singleton @Singleton
public static class OrgMapSupplier implements Supplier<Map<String, ? extends Org>> { public static class OrgMapSupplier implements Supplier<Map<String, ? extends Org>> {
protected final Supplier<VCloudSession> sessionSupplier; protected final Supplier<VCloudSession> sessionSupplier;
private final Function<Iterable<String>, Iterable<? extends Org>> organizationsForNames; protected final Function<Iterable<String>, Iterable<? extends Org>> organizationsForNames;
@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;
} }
@ -264,15 +201,19 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
} }
} }
protected void installDefaultVCloudEndpointsModule() {
install(new DefaultVCloudReferencesModule());
}
@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; protected 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;
} }
@ -280,67 +221,41 @@ 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);
} }
}); });
} }
} }
@Resource
protected Logger logger = Logger.NULL;
@VCloudToken @VCloudToken
@Provides @Provides
String provideVCloudToken(Supplier<VCloudSession> cache) { String provideVCloudToken(Supplier<VCloudSession> cache) {
return checkNotNull(cache.get().getVCloudToken(), "No token present in session"); return checkNotNull(cache.get().getVCloudToken(), "No token present in session");
} }
@Provides
@org.jclouds.vcloud.endpoints.Org
@Singleton
protected URI provideOrg(@org.jclouds.vcloud.endpoints.Org Iterable<ReferenceType> orgs) {
return getLast(orgs).getHref();
}
@Provides
@org.jclouds.vcloud.endpoints.Org
@Singleton
protected String provideOrgName(@org.jclouds.vcloud.endpoints.Org Iterable<ReferenceType> orgs) {
return getLast(orgs).getName();
}
@Provides @Provides
@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) { AtomicReference<AuthorizationException> authException, OrgNameToOrgSupplier supplier) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ReferenceType>>( return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ReferenceType>>(
authException, seconds, new Supplier<Map<String, ReferenceType>>() { authException, seconds, supplier);
@Override
public Map<String, ReferenceType> 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, AtomicReference<AuthorizationException> authException,
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, supplier);
@Override
public Map<URI, ? extends org.jclouds.vcloud.domain.VDC> get() {
return supplier.get();
}
});
} }
@Singleton @Singleton
@ -355,39 +270,28 @@ 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();
} }
}); });
} }
} }
@Provides
@org.jclouds.vcloud.endpoints.Org
@Singleton
protected Iterable<ReferenceType> provideOrgs(Supplier<VCloudSession> cache, @Named(PROPERTY_IDENTITY) String user) {
VCloudSession discovery = cache.get();
checkState(discovery.getOrgs().size() > 0, "No orgs present for user: " + user);
return discovery.getOrgs().values();
}
protected AtomicReference<AuthorizationException> authException = new AtomicReference<AuthorizationException>();
final static Function<ReferenceType, String> name = new Function<ReferenceType, String>() { final static Function<ReferenceType, String> name = new Function<ReferenceType, String>() {
@Override @Override
@ -401,8 +305,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);
@ -433,107 +336,46 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
} }
@Provides @Provides
@org.jclouds.vcloud.endpoints.Catalog
@Singleton @Singleton
protected String provideCatalogName( protected Org provideOrg(Supplier<Map<String, ? extends Org>> orgSupplier,
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogs) { @org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) {
return getLast(getLast(catalogs.get().values()).keySet()); return orgSupplier.get().get(defaultOrg.getName());
}
@Provides
@Network
@Singleton
protected URI provideDefaultNetwork(@org.jclouds.vcloud.endpoints.VDC URI defaultVDC, Injector injector) {
if (authException.get() != null)
throw authException.get();
try {
org.jclouds.vcloud.domain.VDC vDC = injector.getInstance(CommonVCloudClient.class).getVDC(defaultVDC);
Map<String, ReferenceType> networks = vDC.getAvailableNetworks();
checkState(networks.size() > 0, "No networks present in vDC: " + vDC.getName());
if (networks.size() == 1)
return Iterables.getLast(networks.values()).getHref();
String networkName = null;
try {
networkName = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_VCLOUD_DEFAULT_NETWORK)));
ReferenceType network = networks.get(Iterables.find(networks.keySet(), Predicates
.containsPattern(networkName)));
return network.getHref();
} catch (NoSuchElementException e) {
throw new IllegalStateException(String.format("network matching [%s] not in %s", networkName, networks.keySet()));
} catch (ConfigurationException e) {
return findDefaultNetworkForVDC(vDC, networks, injector);
}
} catch (AuthorizationException e) {
authException.set(e);
throw e;
}
}
protected URI findDefaultNetworkForVDC(org.jclouds.vcloud.domain.VDC vDC, Map<String, ReferenceType> networks,
Injector injector) {
logger.warn("default network for vdc %s not set", vDC.getName());
return Iterables.getLast(networks.values()).getHref();
}
@Provides
@Singleton
protected Org provideOrg(CommonVCloudClient discovery) {
if (authException.get() != null)
throw authException.get();
try {
return discovery.findOrgNamed(null);
} catch (AuthorizationException e) {
authException.set(e);
throw e;
}
} }
@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, AtomicReference<AuthorizationException> authException,
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, supplier);
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 @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, AtomicReference<AuthorizationException> authException,
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, supplier);
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 @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;
} }
@ -541,29 +383,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; protected 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;
} }
@ -571,47 +413,34 @@ 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, AtomicReference<AuthorizationException> authException,
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, supplier);
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
@TasksList
@Singleton
protected URI provideDefaultTasksList(Org org) {
return org.getTasksList().getHref();
} }
@Override @Override

View File

@ -0,0 +1,65 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_CATALOG;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
/**
*
* @author Adrian Cole
*/
@Singleton
public class DefaultCatalogForOrg implements Function<ReferenceType, ReferenceType> {
private final OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault selector;
private final Supplier<Map<String, ? extends Org>> nameToOrg;
@Inject
public DefaultCatalogForOrg(ValueOfConfigurationKeyOrNull valueOfConfigurationKeyOrNull,
@Catalog Predicate<ReferenceType> defaultSelector, Supplier<Map<String, ? extends Org>> nameToOrg) {
this.selector = new OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault(checkNotNull(
valueOfConfigurationKeyOrNull, "valueOfConfigurationKeyOrNull"), PROPERTY_VCLOUD_DEFAULT_CATALOG,
checkNotNull(defaultSelector, "defaultSelector"));
this.nameToOrg = checkNotNull(nameToOrg, "nameToOrg");
}
@Override
public ReferenceType apply(ReferenceType defaultOrg) {
org.jclouds.vcloud.domain.Org org = nameToOrg.get().get(defaultOrg.getName());
checkState(org != null, "could not retrieve Org at %s", defaultOrg);
return selector.apply(org.getCatalogs().values());
}
}

View File

@ -0,0 +1,68 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
import java.net.URI;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
/**
*
* @author Adrian Cole
*/
@Singleton
public class DefaultNetworkForVDC implements Function<ReferenceType, ReferenceType> {
private final OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault selector;
private final Supplier<Map<URI, ? extends VDC>> uriToVDC;
@Inject
public DefaultNetworkForVDC(ValueOfConfigurationKeyOrNull valueOfConfigurationKeyOrNull,
@Network Predicate<ReferenceType> defaultSelector,
Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> uriToVDC) {
this.selector = new OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault(checkNotNull(
valueOfConfigurationKeyOrNull, "valueOfConfigurationKeyOrNull"), PROPERTY_VCLOUD_DEFAULT_NETWORK,
checkNotNull(defaultSelector, "defaultSelector"));
this.uriToVDC = checkNotNull(uriToVDC, "uriToVDC");
}
@Override
public ReferenceType apply(ReferenceType defaultVDC) {
org.jclouds.vcloud.domain.VDC vDC = uriToVDC.get().get(defaultVDC.getHref());
checkState(vDC != null, "could not retrieve VDC at %s", defaultVDC);
return selector.apply(vDC.getAvailableNetworks().values());
}
}

View File

@ -0,0 +1,64 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.session/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
/**
*
* @author Adrian Cole
*/
@Singleton
public class DefaultOrgForUser implements Function<String, ReferenceType> {
private final OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault selector;
private final Supplier<VCloudSession> sessionSupplier;
@Inject
public DefaultOrgForUser(ValueOfConfigurationKeyOrNull valueOfConfigurationKeyOrNull,
@Org Predicate<ReferenceType> defaultSelector, Supplier<VCloudSession> sessionSupplier) {
this.selector = new OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault(checkNotNull(
valueOfConfigurationKeyOrNull, "valueOfConfigurationKeyOrNull"), PROPERTY_VCLOUD_DEFAULT_ORG, checkNotNull(
defaultSelector, "defaultSelector"));
this.sessionSupplier = checkNotNull(sessionSupplier, "sessionSupplier");
}
@Override
public ReferenceType apply(String user) {
VCloudSession session = sessionSupplier.get();
checkState(session != null, "could not retrieve Session at %s", user);
return selector.apply(session.getOrgs().values());
}
}

View File

@ -0,0 +1,55 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
/**
*
* @author Adrian Cole
*/
@Singleton
public class DefaultTasksListForOrg implements Function<ReferenceType, ReferenceType> {
private final Supplier<Map<String, ? extends Org>> nameToOrg;
@Inject
public DefaultTasksListForOrg(Supplier<Map<String, ? extends Org>> nameToOrg) {
this.nameToOrg = checkNotNull(nameToOrg, "nameToOrg");
}
@Override
public ReferenceType apply(ReferenceType defaultOrg) {
org.jclouds.vcloud.domain.Org org = nameToOrg.get().get(defaultOrg.getName());
checkState(org != null, "could not retrieve Org at %s", defaultOrg);
return org.getTasksList();
}
}

View File

@ -0,0 +1,175 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.config;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import java.net.URI;
import java.util.Map;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.ReferenceType;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.inject.AbstractModule;
import com.google.inject.Injector;
import com.google.inject.Provides;
/**
*
* @author Adrian Cole
*/
public class DefaultVCloudReferencesModule extends AbstractModule {
@Override
protected void configure() {
}
@Provides
@org.jclouds.vcloud.endpoints.Org
@Singleton
protected ReferenceType provideDefaultOrg(DefaultOrgForUser defaultOrgURIForUser,
@Named(PROPERTY_IDENTITY) String user) {
return defaultOrgURIForUser.apply(user);
}
@Provides
@Singleton
@org.jclouds.vcloud.endpoints.Org
protected Predicate<ReferenceType> provideDefaultOrgSelector(Injector i) {
return Predicates.alwaysTrue();
}
@Provides
@org.jclouds.vcloud.endpoints.TasksList
@Singleton
protected ReferenceType provideDefaultTasksList(DefaultTasksListForOrg defaultTasksListURIForOrg,
@org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) {
return defaultTasksListURIForOrg.apply(defaultOrg);
}
@Provides
@org.jclouds.vcloud.endpoints.Catalog
@Singleton
protected ReferenceType provideDefaultCatalog(DefaultCatalogForOrg defaultCatalogURIForOrg,
@org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) {
return defaultCatalogURIForOrg.apply(defaultOrg);
}
@Provides
@Singleton
@org.jclouds.vcloud.endpoints.Catalog
protected Predicate<ReferenceType> provideDefaultCatalogSelector(Injector i) {
return i.getInstance(WriteableCatalog.class);
}
@Provides
@Singleton
protected Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.Catalog>> provideCatalogsById(
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> supplier) {
return Suppliers
.compose(
new Function<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>, Map<URI, ? extends org.jclouds.vcloud.domain.Catalog>>() {
@Override
public Map<URI, ? extends Catalog> apply(Map<String, Map<String, ? extends Catalog>> arg0) {
Builder<URI, Catalog> builder = ImmutableMap.<URI, Catalog> builder();
for (Map<String, ? extends Catalog> v1 : arg0.values()) {
for (Catalog v2 : v1.values()) {
builder.put(v2.getHref(), v2);
}
}
return builder.build();
}
}, supplier);
}
@Singleton
public static class WriteableCatalog implements Predicate<ReferenceType> {
@Resource
protected Logger logger = Logger.NULL;
private final Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.Catalog>> catalogsByIdSupplier;
@Inject
public WriteableCatalog(Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.Catalog>> catalogsByIdSupplier) {
this.catalogsByIdSupplier = catalogsByIdSupplier;
}
@Override
public boolean apply(ReferenceType arg0) {
// TODO: this is inefficient, calculating the index each time, but
// shouldn't be added to constructor as the supplier is an expensive
// call
Map<URI, ? extends Catalog> index = catalogsByIdSupplier.get();
Catalog catalog = index.get(arg0.getHref());
if (catalog == null) {
if (logger.isTraceEnabled())
logger.trace("didn't find catalog %s", arg0);
return false;
} else
return !catalog.isReadOnly();
}
}
@Provides
@org.jclouds.vcloud.endpoints.VDC
@Singleton
protected ReferenceType provideDefaultVDC(DefaultVDCForOrg defaultVDCURIForOrg,
@org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) {
return defaultVDCURIForOrg.apply(defaultOrg);
}
@Provides
@Singleton
@org.jclouds.vcloud.endpoints.VDC
protected Predicate<ReferenceType> provideDefaultVDCSelector(Injector i) {
return Predicates.alwaysTrue();
}
@Provides
@org.jclouds.vcloud.endpoints.Network
@Singleton
protected ReferenceType provideDefaultNetwork(DefaultNetworkForVDC defaultNetworkURIForVDC,
@org.jclouds.vcloud.endpoints.VDC ReferenceType defaultVDC) {
return defaultNetworkURIForVDC.apply(defaultVDC);
}
@Provides
@Singleton
@org.jclouds.vcloud.endpoints.Network
protected Predicate<ReferenceType> provideDefaultNetworkSelector(Injector i) {
return Predicates.alwaysTrue();
}
}

View File

@ -0,0 +1,65 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_VDC;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.VDC;
import org.jclouds.vcloud.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
/**
*
* @author Adrian Cole
*/
@Singleton
public class DefaultVDCForOrg implements Function<ReferenceType, ReferenceType> {
private final OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault selector;
private final Supplier<Map<String, ? extends Org>> nameToOrg;
@Inject
public DefaultVDCForOrg(ValueOfConfigurationKeyOrNull valueOfConfigurationKeyOrNull,
@VDC Predicate<ReferenceType> defaultSelector, Supplier<Map<String, ? extends Org>> nameToOrg) {
this.selector = new OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault(checkNotNull(
valueOfConfigurationKeyOrNull, "valueOfConfigurationKeyOrNull"), PROPERTY_VCLOUD_DEFAULT_VDC, checkNotNull(
defaultSelector, "defaultSelector"));
this.nameToOrg = checkNotNull(nameToOrg, "nameToOrg");
}
@Override
public ReferenceType apply(ReferenceType defaultOrg) {
org.jclouds.vcloud.domain.Org org = nameToOrg.get().get(defaultOrg.getName());
checkState(org != null, "could not retrieve Org at %s", defaultOrg);
return selector.apply(org.getVDCs().values());
}
}

View File

@ -38,8 +38,6 @@ import com.google.common.collect.Maps;
*/ */
public class CatalogItemImpl extends ReferenceTypeImpl implements CatalogItem { public class CatalogItemImpl extends ReferenceTypeImpl implements CatalogItem {
/** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L;
private final String description; private final String description;
private final ReferenceType entity; private final ReferenceType entity;
private final Map<String, String> properties = Maps.newLinkedHashMap(); private final Map<String, String> properties = Maps.newLinkedHashMap();

View File

@ -32,10 +32,7 @@ import org.jclouds.vcloud.domain.TasksList;
*/ */
public class TasksListImpl implements TasksList { public class TasksListImpl implements TasksList {
private final SortedSet<Task> tasks; private final SortedSet<Task> tasks;
private final URI id; private final URI id;
/** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L;
public TasksListImpl(URI id, SortedSet<Task> tasks) { public TasksListImpl(URI id, SortedSet<Task> tasks) {
this.id = id; this.id = id;

View File

@ -42,15 +42,15 @@ import com.google.common.collect.Iterables;
@Singleton @Singleton
public class OrgNameAndCatalogNameToEndpoint implements Function<Object, URI> { public class OrgNameAndCatalogNameToEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, ? extends Org>> orgMap; private final Supplier<Map<String, ? extends Org>> orgMap;
private final String defaultOrg; private final ReferenceType defaultOrg;
private final URI defaultUri; private final ReferenceType defaultCatalog;
@Inject @Inject
public OrgNameAndCatalogNameToEndpoint(Supplier<Map<String, ? extends Org>> orgMap, public OrgNameAndCatalogNameToEndpoint(Supplier<Map<String, ? extends Org>> orgMap,
@org.jclouds.vcloud.endpoints.Org String defaultOrg, @Catalog URI defaultUri) { @org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg, @Catalog ReferenceType defaultCatalog) {
this.orgMap = orgMap; this.orgMap = orgMap;
this.defaultOrg = defaultOrg; this.defaultOrg = defaultOrg;
this.defaultUri = defaultUri; this.defaultCatalog = defaultCatalog;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -59,9 +59,9 @@ public class OrgNameAndCatalogNameToEndpoint implements Function<Object, URI> {
Object org = Iterables.get(orgCatalog, 0); Object org = Iterables.get(orgCatalog, 0);
Object catalog = Iterables.get(orgCatalog, 1); Object catalog = Iterables.get(orgCatalog, 1);
if (org == null && catalog == null) if (org == null && catalog == null)
return defaultUri; return defaultCatalog.getHref();
else if (org == null) else if (org == null)
org = defaultOrg; org = defaultOrg.getName();
try { try {
Map<String, ReferenceType> catalogs = checkNotNull(orgMap.get().get(org)).getCatalogs(); Map<String, ReferenceType> catalogs = checkNotNull(orgMap.get().get(org)).getCatalogs();

View File

@ -42,15 +42,15 @@ import com.google.common.collect.Iterables;
@Singleton @Singleton
public class OrgNameAndVDCNameToEndpoint implements Function<Object, URI> { public class OrgNameAndVDCNameToEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, ? extends Org>> orgNameToVDCEndpoint; private final Supplier<Map<String, ? extends Org>> orgNameToVDCEndpoint;
private final String defaultOrg; private final ReferenceType defaultOrg;
private final URI defaultUri; private final ReferenceType defaultVDC;
@Inject @Inject
public OrgNameAndVDCNameToEndpoint(Supplier<Map<String, ? extends Org>> orgNameToVDCEndpoint, public OrgNameAndVDCNameToEndpoint(Supplier<Map<String, ? extends Org>> orgNameToVDCEndpoint,
@org.jclouds.vcloud.endpoints.Org String defaultOrg, @VDC URI defaultUri) { @org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg, @VDC ReferenceType defaultVDC) {
this.orgNameToVDCEndpoint = orgNameToVDCEndpoint; this.orgNameToVDCEndpoint = orgNameToVDCEndpoint;
this.defaultOrg = defaultOrg; this.defaultOrg = defaultOrg;
this.defaultUri = defaultUri; this.defaultVDC = defaultVDC;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -59,9 +59,9 @@ public class OrgNameAndVDCNameToEndpoint implements Function<Object, URI> {
Object org = Iterables.get(orgVdc, 0); Object org = Iterables.get(orgVdc, 0);
Object vdc = Iterables.get(orgVdc, 1); Object vdc = Iterables.get(orgVdc, 1);
if (org == null && vdc == null) if (org == null && vdc == null)
return defaultUri; return defaultVDC.getHref();
else if (org == null) else if (org == null)
org = defaultOrg; org = defaultOrg.getName();
try { try {
Map<String, ReferenceType> vdcs = checkNotNull(orgNameToVDCEndpoint.get().get(org)).getVDCs(); Map<String, ReferenceType> vdcs = checkNotNull(orgNameToVDCEndpoint.get().get(org)).getVDCs();

View File

@ -27,6 +27,7 @@ import java.util.NoSuchElementException;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.Catalog; import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.endpoints.Org; import org.jclouds.vcloud.endpoints.Org;
@ -41,13 +42,13 @@ import com.google.common.collect.Iterables;
@Singleton @Singleton
public class OrgNameCatalogNameItemNameToEndpoint implements Function<Object, URI> { public class OrgNameCatalogNameItemNameToEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> orgCatalogMap; private final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> orgCatalogMap;
private final String defaultOrg; private final ReferenceType defaultOrg;
private final String defaultCatalog; private final ReferenceType defaultCatalog;
@Inject @Inject
public OrgNameCatalogNameItemNameToEndpoint( public OrgNameCatalogNameItemNameToEndpoint(
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> orgCatalogMap, Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> orgCatalogMap,
@Org String defaultOrg, @Catalog String defaultCatalog) { @Org ReferenceType defaultOrg, @Catalog ReferenceType defaultCatalog) {
this.orgCatalogMap = orgCatalogMap; this.orgCatalogMap = orgCatalogMap;
this.defaultOrg = defaultOrg; this.defaultOrg = defaultOrg;
this.defaultCatalog = defaultCatalog; this.defaultCatalog = defaultCatalog;
@ -60,9 +61,9 @@ public class OrgNameCatalogNameItemNameToEndpoint implements Function<Object, UR
Object catalog = Iterables.get(orgCatalog, 1); Object catalog = Iterables.get(orgCatalog, 1);
Object catalogItem = Iterables.get(orgCatalog, 2); Object catalogItem = Iterables.get(orgCatalog, 2);
if (org == null) if (org == null)
org = defaultOrg; org = defaultOrg.getName();
if (catalog == null) if (catalog == null)
catalog = defaultCatalog; catalog = defaultCatalog.getName();
try { try {
Map<String, ? extends org.jclouds.vcloud.domain.Catalog> catalogs = checkNotNull(orgCatalogMap.get().get(org)); Map<String, ? extends org.jclouds.vcloud.domain.Catalog> catalogs = checkNotNull(orgCatalogMap.get().get(org));
return catalogs.get(catalog).get(catalogItem).getHref(); return catalogs.get(catalog).get(catalogItem).getHref();

View File

@ -28,6 +28,7 @@ import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.vcloud.domain.CatalogItem; import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.Catalog; import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.endpoints.Org; import org.jclouds.vcloud.endpoints.Org;
@ -42,13 +43,13 @@ import com.google.common.collect.Iterables;
@Singleton @Singleton
public class OrgNameCatalogNameVAppTemplateNameToEndpoint implements Function<Object, URI> { public class OrgNameCatalogNameVAppTemplateNameToEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> orgCatalogItemMap; private final Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> orgCatalogItemMap;
private final String defaultOrg; private final ReferenceType defaultOrg;
private final String defaultCatalog; private final ReferenceType defaultCatalog;
@Inject @Inject
public OrgNameCatalogNameVAppTemplateNameToEndpoint( public OrgNameCatalogNameVAppTemplateNameToEndpoint(
Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> orgCatalogItemMap, Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> orgCatalogItemMap,
@Org String defaultOrg, @Catalog String defaultCatalog) { @Org ReferenceType defaultOrg, @Catalog ReferenceType defaultCatalog) {
this.orgCatalogItemMap = orgCatalogItemMap; this.orgCatalogItemMap = orgCatalogItemMap;
this.defaultOrg = defaultOrg; this.defaultOrg = defaultOrg;
this.defaultCatalog = defaultCatalog; this.defaultCatalog = defaultCatalog;
@ -61,9 +62,9 @@ public class OrgNameCatalogNameVAppTemplateNameToEndpoint implements Function<Ob
Object catalog = Iterables.get(orgCatalog, 1); Object catalog = Iterables.get(orgCatalog, 1);
Object catalogItem = Iterables.get(orgCatalog, 2); Object catalogItem = Iterables.get(orgCatalog, 2);
if (org == null) if (org == null)
org = defaultOrg; org = defaultOrg.getName();
if (catalog == null) if (catalog == null)
catalog = defaultCatalog; catalog = defaultCatalog.getName();
Map<String, Map<String, Map<String, ? extends CatalogItem>>> orgCatalogItemMap = this.orgCatalogItemMap.get(); Map<String, Map<String, Map<String, ? extends CatalogItem>>> orgCatalogItemMap = this.orgCatalogItemMap.get();
if (!orgCatalogItemMap.containsKey(org)) if (!orgCatalogItemMap.containsKey(org))

View File

@ -38,18 +38,19 @@ import com.google.common.base.Supplier;
@Singleton @Singleton
public class OrgNameToEndpoint implements Function<Object, URI> { public class OrgNameToEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, ReferenceType>> orgNameToEndpointSupplier; private final Supplier<Map<String, ReferenceType>> orgNameToEndpointSupplier;
private final URI defaultUri; private final ReferenceType defaultOrg;
@Inject @Inject
public OrgNameToEndpoint(@Org Supplier<Map<String, ReferenceType>> orgNameToEndpointSupplier, @Org URI defaultUri) { public OrgNameToEndpoint(@Org Supplier<Map<String, ReferenceType>> orgNameToEndpointSupplier,
@Org ReferenceType defaultOrg) {
this.orgNameToEndpointSupplier = orgNameToEndpointSupplier; this.orgNameToEndpointSupplier = orgNameToEndpointSupplier;
this.defaultUri = defaultUri; this.defaultOrg = defaultOrg;
} }
public URI apply(Object from) { public URI apply(Object from) {
try { try {
Map<String, ReferenceType> orgNameToEndpoint = orgNameToEndpointSupplier.get(); Map<String, ReferenceType> orgNameToEndpoint = orgNameToEndpointSupplier.get();
return from == null ? defaultUri : orgNameToEndpoint.get(from).getHref(); return from == null ? defaultOrg.getHref() : orgNameToEndpoint.get(from).getHref();
} catch (NullPointerException e) { } catch (NullPointerException e) {
throw new NoSuchElementException("org " + from + " not found in " + orgNameToEndpointSupplier.get().keySet()); throw new NoSuchElementException("org " + from + " not found in " + orgNameToEndpointSupplier.get().keySet());
} }

View File

@ -28,6 +28,7 @@ import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.TasksList; import org.jclouds.vcloud.endpoints.TasksList;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -40,18 +41,19 @@ import com.google.common.base.Supplier;
@Singleton @Singleton
public class OrgNameToTasksListEndpoint implements Function<Object, URI> { public class OrgNameToTasksListEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, ? extends Org>> orgMap; private final Supplier<Map<String, ? extends Org>> orgMap;
private final URI defaultUri; private final ReferenceType defaultTasksList;
@Inject @Inject
public OrgNameToTasksListEndpoint(Supplier<Map<String, ? extends Org>> orgMap, @TasksList URI defaultUri) { public OrgNameToTasksListEndpoint(Supplier<Map<String, ? extends Org>> orgMap,
@TasksList ReferenceType defaultTasksList) {
this.orgMap = orgMap; this.orgMap = orgMap;
this.defaultUri = defaultUri; this.defaultTasksList = defaultTasksList;
} }
public URI apply(Object from) { public URI apply(Object from) {
Object org = from; Object org = from;
if (org == null) if (org == null)
return defaultUri; return defaultTasksList.getHref();
try { try {
return checkNotNull(orgMap.get().get(org)).getTasksList().getHref(); return checkNotNull(orgMap.get().get(org)).getTasksList().getHref();
} catch (NullPointerException e) { } catch (NullPointerException e) {

View File

@ -27,6 +27,7 @@ import java.util.NoSuchElementException;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.Org; import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.endpoints.VDC; import org.jclouds.vcloud.endpoints.VDC;
@ -41,13 +42,13 @@ import com.google.common.collect.Iterables;
@Singleton @Singleton
public class OrgNameVDCNameResourceEntityNameToEndpoint implements Function<Object, URI> { public class OrgNameVDCNameResourceEntityNameToEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap; private final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap;
private final String defaultOrg; private final ReferenceType defaultOrg;
private final String defaultVDC; private final ReferenceType defaultVDC;
@Inject @Inject
public OrgNameVDCNameResourceEntityNameToEndpoint( public OrgNameVDCNameResourceEntityNameToEndpoint(
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap, @Org String defaultOrg, Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap, @Org ReferenceType defaultOrg,
@VDC String defaultVDC) { @VDC ReferenceType defaultVDC) {
this.orgVDCMap = orgVDCMap; this.orgVDCMap = orgVDCMap;
this.defaultOrg = defaultOrg; this.defaultOrg = defaultOrg;
this.defaultVDC = defaultVDC; this.defaultVDC = defaultVDC;
@ -60,9 +61,9 @@ public class OrgNameVDCNameResourceEntityNameToEndpoint implements Function<Obje
Object vDC = Iterables.get(orgVDC, 1); Object vDC = Iterables.get(orgVDC, 1);
Object entityName = Iterables.get(orgVDC, 2); Object entityName = Iterables.get(orgVDC, 2);
if (org == null) if (org == null)
org = defaultOrg; org = defaultOrg.getName();
if (vDC == null) if (vDC == null)
vDC = defaultVDC; vDC = defaultVDC.getName();
try { try {
Map<String, ? extends org.jclouds.vcloud.domain.VDC> vDCs = checkNotNull(orgVDCMap.get().get(org)); Map<String, ? extends org.jclouds.vcloud.domain.VDC> vDCs = checkNotNull(orgVDCMap.get().get(org));
return vDCs.get(vDC).getResourceEntities().get(entityName).getHref(); return vDCs.get(vDC).getResourceEntities().get(entityName).getHref();

View File

@ -17,7 +17,7 @@
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.vcloud.functions; package org.jclouds.vcloud.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.http.HttpUtils.releasePayload; import static org.jclouds.http.HttpUtils.releasePayload;
import java.util.Map; import java.util.Map;
@ -69,7 +69,7 @@ public class ParseLoginResponseFromHeaders implements Function<HttpResponse, VCl
try { try {
final String token = parseTokenFromHeaders(from); final String token = parseTokenFromHeaders(from);
final Map<String, ReferenceType> org = factory.create(orgHandlerProvider.get()).parse( final Map<String, ReferenceType> org = factory.create(orgHandlerProvider.get()).parse(
from.getPayload().getInput()); checkNotNull(from.getPayload().getInput(), "no payload in http response to login request %s", from));
return new VCloudSession() { return new VCloudSession() {
@VCloudToken @VCloudToken

View File

@ -25,7 +25,20 @@ package org.jclouds.vcloud.reference;
*/ */
public interface VCloudConstants { public interface VCloudConstants {
public static final String PROPERTY_VCLOUD_VERSION_SCHEMA = "jclouds.vcloud.version.schema"; public static final String PROPERTY_VCLOUD_VERSION_SCHEMA = "jclouds.vcloud.version.schema";
/**
* name of the default org that your vApp will join, if an org isn't
* explicitly specified.
*/
public static final String PROPERTY_VCLOUD_DEFAULT_ORG = "jclouds.vcloud.defaults.org";
/**
* name of the default catalog to query, if it isn't explicitly specified.
*/
public static final String PROPERTY_VCLOUD_DEFAULT_CATALOG = "jclouds.vcloud.defaults.catalog";
/**
* name of the VDC that your vApp will join, if a vDC isn't explicitly
* specified.
*/
public static final String PROPERTY_VCLOUD_DEFAULT_VDC = "jclouds.vcloud.defaults.vdc";
/** /**
* name of the default network, in the default VDC that your vApp will join. * name of the default network, in the default VDC that your vApp will join.
*/ */

View File

@ -0,0 +1,101 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.suppliers;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.NoSuchElementException;
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
import org.jclouds.vcloud.domain.ReferenceType;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
public class OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault implements
Function<Iterable<ReferenceType>, ReferenceType> {
protected final ValueOfConfigurationKeyOrNull valueOfConfigurationKeyOrNull;
protected final String configurationKey;
protected final Predicate<ReferenceType> defaultSelector;
public OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault(
ValueOfConfigurationKeyOrNull valueOfConfigurationKeyOrNull, String configurationKey,
Predicate<ReferenceType> defaultSelector) {
this.configurationKey = checkNotNull(configurationKey, "configurationKey");
this.valueOfConfigurationKeyOrNull = checkNotNull(valueOfConfigurationKeyOrNull, "valueOfConfigurationKeyOrNull");
this.defaultSelector = checkNotNull(defaultSelector, "defaultSelector");
}
@Override
public ReferenceType apply(Iterable<ReferenceType> referenceTypes) {
checkNotNull(referenceTypes, "referenceTypes");
checkArgument(Iterables.size(referenceTypes) > 0,
"No referenceTypes corresponding to configuration key %s present", configurationKey);
if (Iterables.size(referenceTypes) == 1)
return Iterables.getLast(referenceTypes);
String namingPattern = valueOfConfigurationKeyOrNull.apply(configurationKey);
if (namingPattern != null) {
return findReferenceTypeWithNameMatchingPattern(referenceTypes, namingPattern);
} else {
return defaultReferenceType(referenceTypes);
}
}
public ReferenceType defaultReferenceType(Iterable<ReferenceType> referenceTypes) {
return Iterables.find(referenceTypes, defaultSelector);
}
public ReferenceType findReferenceTypeWithNameMatchingPattern(Iterable<ReferenceType> referenceTypes,
String namingPattern) {
try {
return Iterables.find(referenceTypes, new ReferenceTypeNameMatchesPattern(namingPattern));
} catch (NoSuchElementException e) {
throw new NoSuchElementException(String.format(
"referenceType matching pattern [%s], corresponding to configuration key %s, not in %s", namingPattern,
configurationKey, referenceTypes));
}
}
static class ReferenceTypeNameMatchesPattern implements Predicate<ReferenceType> {
private final String namingPattern;
public ReferenceTypeNameMatchesPattern(String namingPattern) {
this.namingPattern = checkNotNull(namingPattern, "namingPattern");
}
@Override
public boolean apply(ReferenceType arg0) {
return arg0.getName().matches(namingPattern);
}
@Override
public String toString() {
return "nameMatchesPattern(" + namingPattern + ")";
}
}
}

View File

@ -22,6 +22,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.jclouds.Constants; import org.jclouds.Constants;
@ -37,9 +38,12 @@ import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.domain.network.OrgNetwork; import org.jclouds.vcloud.domain.network.OrgNetwork;
import org.jclouds.vcloud.reference.VCloudConstants;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.inject.Module; import com.google.inject.Module;
@ -48,58 +52,127 @@ import com.google.inject.Module;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "live", sequential = true) @Test(groups = "live", singleThreaded = true)
public abstract class CommonVCloudClientLiveTest<S extends CommonVCloudClient, A extends CommonVCloudAsyncClient> { public abstract class CommonVCloudClientLiveTest<S extends CommonVCloudClient, A extends CommonVCloudAsyncClient> {
protected S connection; protected S connection;
protected RestContext<S, A> context; protected RestContext<S, A> context;
protected abstract Iterable<Org> listOrgs();
@Test @Test
public void testOrg() throws Exception { public void testOrg() throws Exception {
Org response = connection.findOrgNamed(null); for (Org org : orgs) {
assertNotNull(response); assertNotNull(org);
assertNotNull(response.getName()); assertNotNull(org.getName());
assert response.getCatalogs().size() >= 1; assert org.getCatalogs().size() >= 1;
assert response.getTasksList() != null; assert org.getTasksList() != null;
assert response.getVDCs().size() >= 1; assert org.getVDCs().size() >= 1;
assertEquals(connection.findOrgNamed(response.getName()), response); assertEquals(connection.findOrgNamed(org.getName()), org);
}
}
@Test
public void testPropertiesCanOverrideDefaultOrg() throws Exception {
for (Org org : orgs) {
RestContext<S, A> newContext = null;
try {
newContext = createContextWithProperties(overrideDefaults(ImmutableMap.of(
VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName())));
assertEquals(newContext.getApi().findOrgNamed(null), org);
} finally {
newContext.close();
}
}
}
public Properties overrideDefaults(Map<String, String> overrides) {
Properties properties = setupProperties();
properties.putAll(overrides);
return properties;
} }
@Test @Test
public void testCatalog() throws Exception { public void testCatalog() throws Exception {
Org org = connection.findOrgNamed(null); for (Org org : orgs) {
for (ReferenceType cat : org.getCatalogs().values()) { for (ReferenceType cat : org.getCatalogs().values()) {
Catalog response = connection.getCatalog(cat.getHref()); Catalog response = connection.getCatalog(cat.getHref());
assertNotNull(response); assertNotNull(response);
assertNotNull(response.getName()); assertNotNull(response.getName());
assertNotNull(response.getHref()); assertNotNull(response.getHref());
assertEquals(connection.findCatalogInOrgNamed(null, response.getName()), response); assertEquals(connection.findCatalogInOrgNamed(org.getName(), response.getName()), response);
}
}
}
@Test
public void testPropertiesCanOverrideDefaultCatalog() throws Exception {
for (Org org : orgs) {
for (ReferenceType cat : org.getCatalogs().values()) {
RestContext<S, A> newContext = null;
try {
newContext = createContextWithProperties(overrideDefaults(ImmutableMap.of(
VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName(),
VCloudConstants.PROPERTY_VCLOUD_DEFAULT_CATALOG, cat.getName())));
assertEquals(newContext.getApi().findCatalogInOrgNamed(null, null), connection.getCatalog(cat.getHref()));
} finally {
newContext.close();
}
}
} }
} }
@Test @Test
public void testGetOrgNetwork() throws Exception { public void testGetOrgNetwork() throws Exception {
Org org = connection.findOrgNamed(null); for (Org org : orgs) {
for (ReferenceType resource : org.getNetworks().values()) { for (ReferenceType resource : org.getNetworks().values()) {
if (resource.getType().equals(VCloudMediaType.NETWORK_XML)) { if (resource.getType().equals(VCloudMediaType.NETWORK_XML)) {
OrgNetwork item = connection.getNetwork(resource.getHref()); OrgNetwork item = connection.getNetwork(resource.getHref());
assertNotNull(item); assertNotNull(item);
}
} }
} }
} }
@Test @Test
public void testGetVDCNetwork() throws Exception { public void testGetVDCNetwork() throws Exception {
Org org = connection.findOrgNamed(null); for (Org org : orgs) {
for (ReferenceType vdc : org.getVDCs().values()) { for (ReferenceType vdc : org.getVDCs().values()) {
VDC response = connection.getVDC(vdc.getHref()); VDC response = connection.getVDC(vdc.getHref());
for (ReferenceType resource : response.getAvailableNetworks().values()) { for (ReferenceType resource : response.getAvailableNetworks().values()) {
if (resource.getType().equals(VCloudMediaType.NETWORK_XML)) { if (resource.getType().equals(VCloudMediaType.NETWORK_XML)) {
try { try {
OrgNetwork item = connection.getNetwork(resource.getHref()); OrgNetwork net = connection.getNetwork(resource.getHref());
assertNotNull(item); assertNotNull(net);
} catch (AuthorizationException e) { assertNotNull(net.getName());
assertNotNull(net.getHref());
assertEquals(
connection.findNetworkInOrgVDCNamed(org.getName(), response.getName(), net.getName()), net);
} catch (AuthorizationException e) {
}
}
}
}
}
}
@Test
public void testPropertiesCanOverrideDefaultNetwork() throws Exception {
for (Org org : orgs) {
for (ReferenceType vdc : org.getVDCs().values()) {
VDC response = connection.getVDC(vdc.getHref());
for (ReferenceType net : response.getAvailableNetworks().values()) {
RestContext<S, A> newContext = null;
try {
newContext = createContextWithProperties(overrideDefaults(ImmutableMap.of(
VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName(),
VCloudConstants.PROPERTY_VCLOUD_DEFAULT_VDC, vdc.getName(),
VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK, net.getName())));
assertEquals(newContext.getApi().findNetworkInOrgVDCNamed(null, null, null),
connection.getNetwork(net.getHref()));
} finally {
newContext.close();
} }
} }
} }
@ -108,13 +181,14 @@ public abstract class CommonVCloudClientLiveTest<S extends CommonVCloudClient, A
@Test @Test
public void testGetCatalogItem() throws Exception { public void testGetCatalogItem() throws Exception {
Org org = connection.findOrgNamed(null); for (Org org : orgs) {
for (ReferenceType cat : org.getCatalogs().values()) { for (ReferenceType cat : org.getCatalogs().values()) {
Catalog response = connection.getCatalog(cat.getHref()); Catalog response = connection.getCatalog(cat.getHref());
for (ReferenceType resource : response.values()) { for (ReferenceType resource : response.values()) {
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
CatalogItem item = connection.getCatalogItem(resource.getHref()); CatalogItem item = connection.getCatalogItem(resource.getHref());
verifyCatalogItem(item); verifyCatalogItem(item);
}
} }
} }
} }
@ -131,14 +205,15 @@ public abstract class CommonVCloudClientLiveTest<S extends CommonVCloudClient, A
@Test @Test
public void testFindCatalogItem() throws Exception { public void testFindCatalogItem() throws Exception {
Org org = connection.findOrgNamed(null); for (Org org : orgs) {
for (ReferenceType cat : org.getCatalogs().values()) { for (ReferenceType cat : org.getCatalogs().values()) {
Catalog response = connection.getCatalog(cat.getHref()); Catalog response = connection.getCatalog(cat.getHref());
for (ReferenceType resource : response.values()) { for (ReferenceType resource : response.values()) {
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
CatalogItem item = connection.findCatalogItemInOrgCatalogNamed(org.getName(), response.getName(), CatalogItem item = connection.findCatalogItemInOrgCatalogNamed(org.getName(), response.getName(),
resource.getName()); resource.getName());
verifyCatalogItem(item); verifyCatalogItem(item);
}
} }
} }
} }
@ -146,36 +221,58 @@ public abstract class CommonVCloudClientLiveTest<S extends CommonVCloudClient, A
@Test @Test
public void testDefaultVDC() throws Exception { public void testDefaultVDC() throws Exception {
Org org = connection.findOrgNamed(null); for (Org org : orgs) {
for (ReferenceType vdc : org.getVDCs().values()) { for (ReferenceType vdc : org.getVDCs().values()) {
VDC response = connection.getVDC(vdc.getHref()); VDC response = connection.getVDC(vdc.getHref());
assertNotNull(response); assertNotNull(response);
assertNotNull(response.getName()); assertNotNull(response.getName());
assertNotNull(response.getHref()); assertNotNull(response.getHref());
assertNotNull(response.getResourceEntities()); assertNotNull(response.getResourceEntities());
assertNotNull(response.getAvailableNetworks()); assertNotNull(response.getAvailableNetworks());
assertEquals(connection.getVDC(response.getHref()), response); assertEquals(connection.getVDC(response.getHref()), response);
}
}
}
@Test
public void testPropertiesCanOverrideDefaultVDC() throws Exception {
for (Org org : orgs) {
for (ReferenceType vdc : org.getVDCs().values()) {
RestContext<S, A> newContext = null;
try {
newContext = createContextWithProperties(overrideDefaults(ImmutableMap.of(
VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName(),
VCloudConstants.PROPERTY_VCLOUD_DEFAULT_VDC, vdc.getName())));
assertEquals(newContext.getApi().findVDCInOrgNamed(null, null), connection.getVDC(vdc.getHref()));
} finally {
newContext.close();
}
}
} }
} }
@Test @Test
public void testDefaultTasksList() throws Exception { public void testDefaultTasksList() throws Exception {
org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(null); for (Org org : orgs) {
assertNotNull(response); org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(org.getName());
assertNotNull(response.getLocation()); assertNotNull(response);
assertNotNull(response.getTasks()); assertNotNull(response.getLocation());
assertEquals(connection.getTasksList(response.getLocation()).getLocation(), response.getLocation()); assertNotNull(response.getTasks());
assertEquals(connection.getTasksList(response.getLocation()).getLocation(), response.getLocation());
}
} }
@Test @Test
public void testGetTask() throws Exception { public void testGetTask() throws Exception {
org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(null); for (Org org : orgs) {
assertNotNull(response); org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(org.getName());
assertNotNull(response.getLocation()); assertNotNull(response);
assertNotNull(response.getTasks()); assertNotNull(response.getLocation());
if (response.getTasks().size() > 0) { assertNotNull(response.getTasks());
Task task = response.getTasks().last(); if (response.getTasks().size() > 0) {
assertEquals(connection.getTask(task.getHref()).getHref(), task.getHref()); Task task = response.getTasks().last();
assertEquals(connection.getTask(task.getHref()).getHref(), task.getHref());
}
} }
} }
@ -184,6 +281,7 @@ public abstract class CommonVCloudClientLiveTest<S extends CommonVCloudClient, A
protected String credential; protected String credential;
protected String endpoint; protected String endpoint;
protected String apiversion; protected String apiversion;
protected Iterable<Org> orgs;
protected void setupCredentials() { protected void setupCredentials() {
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
@ -213,10 +311,19 @@ public abstract class CommonVCloudClientLiveTest<S extends CommonVCloudClient, A
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })
public void setupClient() { public void setupClient() {
setupCredentials(); setupCredentials();
Properties overrides = setupProperties(); context = createContextWithProperties(setupProperties());
context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider,
ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides).getProviderSpecificContext();
connection = context.getApi(); connection = context.getApi();
orgs = listOrgs();
} }
public RestContext<S, A> createContextWithProperties(Properties overrides) {
return new ComputeServiceContextFactory(setupRestProperties()).createContext(provider,
ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides).getProviderSpecificContext();
}
@AfterGroups(groups = { "live" })
public void teardownClient() {
context.close();
}
} }

View File

@ -0,0 +1,124 @@
/**
*
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.suppliers;
import static org.easymock.classextension.EasyMock.createMock;
import static org.testng.Assert.assertEquals;
import java.util.NoSuchElementException;
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import org.testng.annotations.Test;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.name.Names;
/**
* Tests behavior of
* {@code OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during
// surefire
@Test(groups = "unit", testName = "OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefaultTest")
public class OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefaultTest {
ValueOfConfigurationKeyOrNull valueOfConfigurationKeyOrNull = new ValueOfConfigurationKeyOrNull(
Guice.createInjector());
@Test(expectedExceptions = IllegalArgumentException.class)
public void testIllegalArgumentWhenResourcesEmpty() {
new OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault(valueOfConfigurationKeyOrNull, "foo",
Predicates.<ReferenceType> alwaysTrue()).apply(ImmutableSet.<ReferenceType> of());
}
@Test
public void testReturnsOnlyResource() {
ReferenceType reference = createMock(ReferenceType.class);
assertEquals(new OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault(valueOfConfigurationKeyOrNull,
"foo", Predicates.<ReferenceType> alwaysTrue()).apply(ImmutableSet.<ReferenceType> of(reference)),
reference);
}
@Test
public void testReturnsFirstResourceWhenConfigurationUnspecified() {
ReferenceType reference1 = createMock(ReferenceType.class);
ReferenceType reference2 = createMock(ReferenceType.class);
assertEquals(new OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault(valueOfConfigurationKeyOrNull,
"foo", Predicates.<ReferenceType> alwaysTrue()).apply(ImmutableList.<ReferenceType> of(reference1,
reference2)), reference1);
}
@Test
public void testReturnsResourceMatchingDefaultPredicateWhenConfigurationUnspecified() {
ReferenceType reference1 = createMock(ReferenceType.class);
ReferenceType reference2 = createMock(ReferenceType.class);
assertEquals(new OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault(valueOfConfigurationKeyOrNull,
"foo", Predicates.equalTo(reference2)).apply(ImmutableList.<ReferenceType> of(reference1, reference2)),
reference2);
}
@Test
public void testReturnsResourceWithNameMatchingConfigurationKey() {
ReferenceType reference1 = new ReferenceTypeImpl("travis tritt", null, null);
ReferenceType reference2 = new ReferenceTypeImpl("hail mary", null, null);
assertEquals(new OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault(
new ValueOfConfigurationKeyOrNull(Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(Names.named("foo")).to(".*mary.*");
}
})), "foo", Predicates.<ReferenceType> alwaysTrue()).apply(ImmutableList.<ReferenceType> of(reference1,
reference2)), reference2);
}
@Test(expectedExceptions = NoSuchElementException.class)
public void testThrowsNoSuchElementWhenNoneMatchConfigurationKey() {
ReferenceType reference1 = new ReferenceTypeImpl("travis tritt", null, null);
ReferenceType reference2 = new ReferenceTypeImpl("hail mary", null, null);
new OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault(new ValueOfConfigurationKeyOrNull(
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(Names.named("foo")).to(".*happy.*");
}
})), "foo", Predicates.<ReferenceType> alwaysTrue()).apply(ImmutableList.<ReferenceType> of(reference1,
reference2));
}
}

View File

@ -40,7 +40,7 @@ public class BluelockVCloudDirectorPropertiesBuilder extends VCloudPropertiesBui
Properties properties = super.defaultProperties(); Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ISO3166_CODES, "US-IN"); properties.setProperty(PROPERTY_ISO3166_CODES, "US-IN");
properties.setProperty(PROPERTY_ENDPOINT, "https://vcenterprise.bluelock.com/api"); properties.setProperty(PROPERTY_ENDPOINT, "https://vcenterprise.bluelock.com/api");
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_NETWORK, "internet01"); properties.setProperty(PROPERTY_VCLOUD_DEFAULT_NETWORK, "internet01-.*");
return properties; return properties;
} }

View File

@ -37,7 +37,7 @@ public class BluelockVCloudEnterprisePropertiesBuilder extends VCloudPropertiesB
Properties properties = super.defaultProperties(); Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ISO3166_CODES, "US-IN"); properties.setProperty(PROPERTY_ISO3166_CODES, "US-IN");
properties.setProperty(PROPERTY_ENDPOINT, "https://vcenterprise.bluelock.com/api"); properties.setProperty(PROPERTY_ENDPOINT, "https://vcenterprise.bluelock.com/api");
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_NETWORK, "internet01"); properties.setProperty(PROPERTY_VCLOUD_DEFAULT_NETWORK, "internet01-.*");
return properties; return properties;
} }

View File

@ -37,7 +37,7 @@ public class BluelockVCloudZone01PropertiesBuilder extends VCloudPropertiesBuild
Properties properties = super.defaultProperties(); Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ISO3166_CODES, "US-IN"); properties.setProperty(PROPERTY_ISO3166_CODES, "US-IN");
properties.setProperty(PROPERTY_ENDPOINT, "https://zone01.bluelock.com/api"); properties.setProperty(PROPERTY_ENDPOINT, "https://zone01.bluelock.com/api");
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_NETWORK, "internet01"); properties.setProperty(PROPERTY_VCLOUD_DEFAULT_NETWORK, "internet01-.*");
return properties; return properties;
} }

View File

@ -36,6 +36,7 @@
<properties> <properties>
<test.trmk-ecloud.endpoint>https://services.enterprisecloud.terremark.com/api</test.trmk-ecloud.endpoint> <test.trmk-ecloud.endpoint>https://services.enterprisecloud.terremark.com/api</test.trmk-ecloud.endpoint>
<test.trmk-ecloud.datacenter>MIA</test.trmk-ecloud.datacenter>
<test.trmk-ecloud.apiversion>0.8b-ext2.8</test.trmk-ecloud.apiversion> <test.trmk-ecloud.apiversion>0.8b-ext2.8</test.trmk-ecloud.apiversion>
<test.trmk-ecloud.identity>FIXME</test.trmk-ecloud.identity> <test.trmk-ecloud.identity>FIXME</test.trmk-ecloud.identity>
<test.trmk-ecloud.credential>FIXME</test.trmk-ecloud.credential> <test.trmk-ecloud.credential>FIXME</test.trmk-ecloud.credential>
@ -141,6 +142,10 @@
<name>test.trmk-ecloud.credential</name> <name>test.trmk-ecloud.credential</name>
<value>${test.trmk-ecloud.credential}</value> <value>${test.trmk-ecloud.credential}</value>
</property> </property>
<property>
<name>test.trmk-ecloud.datacenter</name>
<value>${test.trmk-ecloud.datacenter}</value>
</property>
</systemProperties> </systemProperties>
</configuration> </configuration>
</execution> </execution>

View File

@ -26,6 +26,7 @@ import javax.inject.Singleton;
import org.jclouds.terremark.ecloud.domain.TerremarkECloudOrg; import org.jclouds.terremark.ecloud.domain.TerremarkECloudOrg;
import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.terremark.domain.TerremarkOrg; import org.jclouds.vcloud.terremark.domain.TerremarkOrg;
import org.jclouds.vcloud.terremark.functions.OrgURIToEndpoint; import org.jclouds.vcloud.terremark.functions.OrgURIToEndpoint;
@ -40,7 +41,7 @@ import com.google.common.base.Supplier;
public class OrgURIToDataCentersListEndpoint extends OrgURIToEndpoint implements Function<Object, URI> { public class OrgURIToDataCentersListEndpoint extends OrgURIToEndpoint implements Function<Object, URI> {
@Inject @Inject
public OrgURIToDataCentersListEndpoint(Supplier<Map<String, ? extends Org>> orgMap, public OrgURIToDataCentersListEndpoint(Supplier<Map<String, ? extends Org>> orgMap,
@org.jclouds.vcloud.endpoints.Org URI defaultUri) { @org.jclouds.vcloud.endpoints.Org ReferenceType defaultUri) {
super(orgMap, defaultUri); super(orgMap, defaultUri);
} }

View File

@ -26,6 +26,7 @@ import javax.inject.Singleton;
import org.jclouds.terremark.ecloud.domain.TerremarkECloudOrg; import org.jclouds.terremark.ecloud.domain.TerremarkECloudOrg;
import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.terremark.domain.TerremarkOrg; import org.jclouds.vcloud.terremark.domain.TerremarkOrg;
import org.jclouds.vcloud.terremark.functions.OrgURIToEndpoint; import org.jclouds.vcloud.terremark.functions.OrgURIToEndpoint;
@ -40,7 +41,7 @@ import com.google.common.base.Supplier;
public class OrgURIToTagsListEndpoint extends OrgURIToEndpoint implements Function<Object, URI> { public class OrgURIToTagsListEndpoint extends OrgURIToEndpoint implements Function<Object, URI> {
@Inject @Inject
public OrgURIToTagsListEndpoint(Supplier<Map<String, ? extends Org>> orgMap, public OrgURIToTagsListEndpoint(Supplier<Map<String, ? extends Org>> orgMap,
@org.jclouds.vcloud.endpoints.Org URI defaultUri) { @org.jclouds.vcloud.endpoints.Org ReferenceType defaultUri) {
super(orgMap, defaultUri); super(orgMap, defaultUri);
} }

View File

@ -76,7 +76,7 @@ import org.jclouds.vcloud.terremark.xml.IpAddressesHandler;
import org.jclouds.vcloud.terremark.xml.KeyPairByNameHandler; import org.jclouds.vcloud.terremark.xml.KeyPairByNameHandler;
import org.jclouds.vcloud.terremark.xml.KeyPairHandler; import org.jclouds.vcloud.terremark.xml.KeyPairHandler;
import org.jclouds.vcloud.terremark.xml.KeyPairsHandler; import org.jclouds.vcloud.terremark.xml.KeyPairsHandler;
import org.jclouds.vcloud.terremark.xml.PublicIpAddressesHandler; import org.jclouds.vcloud.terremark.xml.PublicIpAddressHandler;
import org.jclouds.vcloud.terremark.xml.TerremarkNetworkHandler; import org.jclouds.vcloud.terremark.xml.TerremarkNetworkHandler;
import org.jclouds.vcloud.terremark.xml.TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler; import org.jclouds.vcloud.terremark.xml.TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler;
import org.jclouds.vcloud.terremark.xml.VAppExtendedInfoHandler; import org.jclouds.vcloud.terremark.xml.VAppExtendedInfoHandler;
@ -137,8 +137,8 @@ public interface TerremarkECloudAsyncClient extends TerremarkVCloudAsyncClient {
*/ */
@POST @POST
@Consumes(PUBLICIP_XML) @Consumes(PUBLICIP_XML)
@XMLResponseParser(PublicIpAddressesHandler.class) @XMLResponseParser(PublicIpAddressHandler.class)
@ExceptionParser(ReturnVoidOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<PublicIpAddress> activatePublicIpInVDC( ListenableFuture<PublicIpAddress> activatePublicIpInVDC(
@EndpointParam(parser = VDCURIToPublicIPsEndpoint.class) URI vDCId); @EndpointParam(parser = VDCURIToPublicIPsEndpoint.class) URI vDCId);

View File

@ -20,21 +20,20 @@ package org.jclouds.vcloud.terremark.config;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.terremark.ecloud.features.DataCenterOperationsAsyncClient; import org.jclouds.terremark.ecloud.features.DataCenterOperationsAsyncClient;
import org.jclouds.terremark.ecloud.features.DataCenterOperationsClient; import org.jclouds.terremark.ecloud.features.DataCenterOperationsClient;
import org.jclouds.terremark.ecloud.features.TagOperationsAsyncClient; import org.jclouds.terremark.ecloud.features.TagOperationsAsyncClient;
import org.jclouds.terremark.ecloud.features.TagOperationsClient; import org.jclouds.terremark.ecloud.features.TagOperationsClient;
import org.jclouds.vcloud.VCloudExpressAsyncClient; import org.jclouds.vcloud.VCloudExpressAsyncClient;
import org.jclouds.vcloud.VCloudExpressClient; import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.config.DefaultVCloudReferencesModule;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.terremark.TerremarkECloudAsyncClient; import org.jclouds.vcloud.terremark.TerremarkECloudAsyncClient;
import org.jclouds.vcloud.terremark.TerremarkECloudClient; import org.jclouds.vcloud.terremark.TerremarkECloudClient;
@ -45,24 +44,24 @@ import org.jclouds.vcloud.terremark.domain.TerremarkOrgNetwork;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Provides; import com.google.inject.Provides;
/** /**
* 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 TerremarkECloudRestClientModule extends public class TerremarkECloudRestClientModule extends
TerremarkRestClientModule<TerremarkECloudClient, TerremarkECloudAsyncClient> { TerremarkRestClientModule<TerremarkECloudClient, TerremarkECloudAsyncClient> {
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()// public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()//
.put(DataCenterOperationsClient.class, DataCenterOperationsAsyncClient.class)// .put(DataCenterOperationsClient.class, DataCenterOperationsAsyncClient.class)//
.put(TagOperationsClient.class, TagOperationsAsyncClient.class)// .put(TagOperationsClient.class, TagOperationsAsyncClient.class)//
.build(); .build();
public TerremarkECloudRestClientModule() { public TerremarkECloudRestClientModule() {
super(TerremarkECloudClient.class, TerremarkECloudAsyncClient.class, DELEGATE_MAP); super(TerremarkECloudClient.class, TerremarkECloudAsyncClient.class, DELEGATE_MAP);
@ -92,36 +91,51 @@ public class TerremarkECloudRestClientModule extends
return in; return in;
} }
@Override @Singleton
protected URI findDefaultNetworkForVDC(org.jclouds.vcloud.domain.VDC vDC, Map<String, ReferenceType> networks, public static class IsDMZNetwork implements Predicate<ReferenceType> {
final Injector injector) { private final TerremarkECloudClient client;
// TODO FIXME XXX: In Terremark Enterprise environment with multiple VDC's this does not
// work well.
// Each VDC will have differnt network subnets. So we cannot assume the default VDC's
// networks will
// work with non-default VDC's. So make PROPERTY_VCLOUD_DEFAULT_NETWORK optional. If
// this property
// is not set, they are expected to add NetworkConfig to the options when launching a
// server.
logger.warn("default network for vdc %s not set", vDC.getName());
try {
return Iterables.find(networks.values(), new Predicate<ReferenceType>() {
@Override @Inject
public boolean apply(ReferenceType input) { public IsDMZNetwork(TerremarkECloudClient client) {
TerremarkOrgNetwork network = injector.getInstance(TerremarkECloudClient.class).getNetwork( this.client = client;
input.getHref()); }
TerremarkNetwork terremarkNetwork = injector.getInstance(TerremarkECloudClient.class)
.getTerremarkNetwork(
checkNotNull(checkNotNull(network, "network at: " + input).getNetworkExtension(),
"network extension for: " + input).getHref());
return checkNotNull(terremarkNetwork, "terremark network extension at: " + network.getNetworkExtension())
.getNetworkType() == TerremarkNetwork.Type.DMZ;
}
}).getHref(); @Override
} catch (NoSuchElementException e) { public boolean apply(ReferenceType arg0) {
throw new ResourceNotFoundException("no dmz networks in vdc " + vDC.getName() + ": " + networks); // TODO FIXME XXX: In Terremark Enterprise environment with multiple
// VDC's
// this does not
// work well.
// Each VDC will have differnt network subnets. So we cannot assume the
// default VDC's
// networks will
// work with non-default VDC's. So make PROPERTY_VCLOUD_DEFAULT_NETWORK
// optional. If
// this property
// is not set, they are expected to add NetworkConfig to the options
// when
// launching a
// server.
TerremarkOrgNetwork orgNetwork = client.getNetwork(arg0.getHref());
TerremarkNetwork terremarkNetwork = client.getTerremarkNetwork(checkNotNull(
checkNotNull(orgNetwork, "network at: " + arg0).getNetworkExtension(), "network extension for: " + arg0)
.getHref());
return checkNotNull(terremarkNetwork, "terremark network extension at: " + orgNetwork.getNetworkExtension())
.getNetworkType() == TerremarkNetwork.Type.DMZ;
} }
} }
@Override
protected void installDefaultVCloudEndpointsModule() {
install(new DefaultVCloudReferencesModule() {
@Override
protected Predicate<ReferenceType> provideDefaultNetworkSelector(Injector i) {
return i.getInstance(IsDMZNetwork.class);
}
});
}
} }

View File

@ -61,7 +61,7 @@ public class TerremarkECloudInternetServiceAndPublicIpAddressSupplier implements
@Override @Override
public Entry<InternetService, PublicIpAddress> getNewInternetServiceAndIp(VCloudExpressVApp vApp, int port, public Entry<InternetService, PublicIpAddress> getNewInternetServiceAndIp(VCloudExpressVApp vApp, int port,
Protocol protocol) { Protocol protocol) {
logger.debug(">> creating InternetService in vDC %s:%s:%d", vApp.getVDC().getName(), protocol, port); logger.debug(">> creating InternetService in vDC %s:%s:%d", vApp.getVDC().getHref(), protocol, port);
InternetService is = null; InternetService is = null;
PublicIpAddress ip = null; PublicIpAddress ip = null;
try { try {

View File

@ -18,13 +18,13 @@
*/ */
package org.jclouds.terremark.ecloud; package org.jclouds.terremark.ecloud;
import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -32,36 +32,36 @@ import javax.inject.Singleton;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.RestContextSpec;
import org.jclouds.terremark.ecloud.domain.internal.TerremarkECloudOrgImpl; import org.jclouds.terremark.ecloud.domain.internal.TerremarkECloudOrgImpl;
import org.jclouds.vcloud.CommonVCloudClient; import org.jclouds.vcloud.VCloudExpressLoginAsyncClient;
import org.jclouds.vcloud.VCloudExpressAsyncClientTest.VCloudRestClientModuleExtension.TestOrgCatalogItemSupplier; import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.VCloudExpressAsyncClientTest.VCloudRestClientModuleExtension.TestOrgCatalogSupplier;
import org.jclouds.vcloud.VCloudVersionsAsyncClient; import org.jclouds.vcloud.VCloudVersionsAsyncClient;
import org.jclouds.vcloud.config.CommonVCloudRestClientModule.OrgVDCSupplier;
import org.jclouds.vcloud.domain.AllocationModel; import org.jclouds.vcloud.domain.AllocationModel;
import org.jclouds.vcloud.domain.Capacity;
import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VCloudSession; import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.domain.VDCStatus; import org.jclouds.vcloud.domain.VDCStatus;
import org.jclouds.vcloud.domain.internal.CatalogImpl;
import org.jclouds.vcloud.domain.internal.CatalogItemImpl;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.terremark.TerremarkECloudMediaType; import org.jclouds.vcloud.terremark.TerremarkECloudMediaType;
import org.jclouds.vcloud.terremark.TerremarkVCloudMediaType;
import org.jclouds.vcloud.terremark.config.TerremarkECloudRestClientModule; import org.jclouds.vcloud.terremark.config.TerremarkECloudRestClientModule;
import org.jclouds.vcloud.terremark.domain.internal.TerremarkVDCImpl; import org.jclouds.vcloud.terremark.domain.internal.TerremarkVDCImpl;
import com.google.common.base.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps; import com.google.inject.AbstractModule;
import com.google.inject.Injector;
import com.google.inject.Module; import com.google.inject.Module;
/** /**
@ -69,128 +69,6 @@ import com.google.inject.Module;
*/ */
public abstract class BaseTerremarkECloudAsyncClientTest<T> extends RestClientTest<T> { public abstract class BaseTerremarkECloudAsyncClientTest<T> extends RestClientTest<T> {
@RequiresHttp
@ConfiguresRestClient
protected static class TerremarkVCloudRestClientModuleExtension extends TerremarkECloudRestClientModule {
@Override
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService,
@Named(PROPERTY_API_VERSION) String version) {
return URI.create("https://vcloud/login");
}
@Override
protected void configure() {
super.configure();
bind(OrgNameToKeysListSupplier.class).to(TestOrgNameToKeysListSupplier.class);
bind(OrgMapSupplier.class).to(TestTerremarkOrgMapSupplier.class);
bind(OrgCatalogSupplier.class).to(TestOrgCatalogSupplier.class);
bind(OrgCatalogItemSupplier.class).to(TestOrgCatalogItemSupplier.class);
bind(OrgVDCSupplier.class).to(TestTerremarkOrgVDCSupplier.class);
}
@Singleton
public static class TestOrgNameToKeysListSupplier extends OrgNameToKeysListSupplier {
@Inject
protected TestOrgNameToKeysListSupplier(Supplier<VCloudSession> sessionSupplier) {
super(sessionSupplier, null);
}
@Override
public Map<String, ReferenceType> get() {
return Maps.transformValues(sessionSupplier.get().getOrgs(), new Function<ReferenceType, ReferenceType>() {
@Override
public ReferenceType apply(ReferenceType from) {
return new ReferenceTypeImpl(from.getName(), TerremarkECloudMediaType.KEYSLIST_XML, URI.create(from
.getHref().toASCIIString() + "/keysList"));
}
});
}
}
@Singleton
public static class TestTerremarkOrgMapSupplier extends OrgMapSupplier {
@Inject
protected TestTerremarkOrgMapSupplier() {
super(null, null);
}
@Override
public Map<String, Org> get() {
return ImmutableMap.<String, Org> of(
"org",
new TerremarkECloudOrgImpl("org", null,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"), null, ImmutableMap
.<String, ReferenceType> of(
"catalog",
new ReferenceTypeImpl("catalog", TerremarkECloudMediaType.CATALOG_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))),
ImmutableMap.<String, ReferenceType> of(
"vdc",
new ReferenceTypeImpl("vdc", TerremarkECloudMediaType.VDC_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"))), ImmutableMap
.<String, ReferenceType> of(), ImmutableMap.<String, ReferenceType> of(
"tasksList",
new ReferenceTypeImpl("tasksList", TerremarkECloudMediaType.TASKSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1"))),
new ReferenceTypeImpl("keysList", TerremarkECloudMediaType.KEYSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/keysList/1")), new ReferenceTypeImpl(
"deviceTags", TerremarkECloudMediaType.TAGSLISTLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/deviceTags/1")),
new ReferenceTypeImpl("vappCatalog", TerremarkECloudMediaType.VAPPCATALOGLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vappCatalog/1")),
new ReferenceTypeImpl("dataCentersList", TerremarkECloudMediaType.DATACENTERSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/datacentersList/1"))));
}
}
@Override
protected URI provideOrg(@org.jclouds.vcloud.endpoints.Org Iterable<ReferenceType> orgs) {
return URI.create("https://org");
}
@Override
protected String provideOrgName(@org.jclouds.vcloud.endpoints.Org Iterable<ReferenceType> orgs) {
return "org";
}
@Override
protected URI provideCatalog(Org org, @Named(PROPERTY_IDENTITY) String user, WriteableCatalog write) {
return URI.create("https://catalog");
}
@Override
protected Org provideOrg(CommonVCloudClient discovery) {
return null;
}
@Override
protected Iterable<ReferenceType> provideOrgs(Supplier<VCloudSession> cache, String user) {
return null;
}
@Override
protected URI provideDefaultTasksList(Org org) {
return URI.create("https://taskslist");
}
@Override
protected URI provideDefaultVDC(Org org, @org.jclouds.vcloud.endpoints.VDC String defaultVDC) {
return URI.create("https://vdc/1");
}
@Override
protected String provideDefaultVDCName(
@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
return "vdc";
}
@Override
protected URI provideDefaultNetwork(URI vdc, Injector injector) {
return URI.create("https://vcloud.safesecureweb.com/network/1990");
}
}
@Override @Override
protected void checkFilters(HttpRequest request) { protected void checkFilters(HttpRequest request) {
assertEquals(request.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);
@ -199,7 +77,7 @@ public abstract class BaseTerremarkECloudAsyncClientTest<T> extends RestClientTe
@Override @Override
protected Module createModule() { protected Module createModule() {
return new TerremarkVCloudRestClientModuleExtension(); return new TerremarkECloudRestClientModuleExtension();
} }
@Override @Override
@ -207,37 +85,187 @@ public abstract class BaseTerremarkECloudAsyncClientTest<T> extends RestClientTe
return new RestContextFactory().createContextSpec("trmk-ecloud", "identity", "credential", new Properties()); return new RestContextFactory().createContextSpec("trmk-ecloud", "identity", "credential", new Properties());
} }
@Singleton protected static final ReferenceTypeImpl ORG_REF = new ReferenceTypeImpl("org", VCloudMediaType.ORG_XML,
public static class TestTerremarkOrgVDCSupplier extends OrgVDCSupplier { URI.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"));
@Inject
protected TestTerremarkOrgVDCSupplier() { protected static final ReferenceTypeImpl CATALOG_REF = new ReferenceTypeImpl("catalog", VCloudMediaType.CATALOG_XML,
super(null, null); URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"));
protected static final ReferenceTypeImpl TASKSLIST_REF = new ReferenceTypeImpl("tasksList",
VCloudMediaType.TASKSLIST_XML, URI.create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1"));
protected static final ReferenceTypeImpl VDC_REF = new ReferenceTypeImpl("vdc", VCloudMediaType.VDC_XML,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"));
protected static final ReferenceTypeImpl KEYSLIST_REF = new ReferenceTypeImpl("keysList",
TerremarkECloudMediaType.KEYSLIST_XML, URI.create("https://vcloud.safesecureweb.com/api/v0.8/keysList/1"));
protected static final ReferenceTypeImpl TAGSLIST_REF = new ReferenceTypeImpl("deviceTags",
TerremarkECloudMediaType.TAGSLISTLIST_XML,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/deviceTags/1"));
protected static final ReferenceTypeImpl VAPPCATALOGLIST_REF = new ReferenceTypeImpl("vappCatalog",
TerremarkECloudMediaType.VAPPCATALOGLIST_XML,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vappCatalog/1"));
protected static final ReferenceTypeImpl DATACENTERSLIST_REF = new ReferenceTypeImpl("dataCentersList",
TerremarkECloudMediaType.DATACENTERSLIST_XML,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/datacentersList/1"));
protected static final ReferenceTypeImpl NETWORK_REF = new ReferenceTypeImpl("network", VCloudMediaType.NETWORK_XML,
URI.create("https://vcloud.safesecureweb.com/network/1990"));
protected static final ReferenceTypeImpl PUBLICIPS_REF = new ReferenceTypeImpl("publicIps",
TerremarkECloudMediaType.PUBLICIPSLIST_XML,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/publicIps/1"));
protected static final ReferenceTypeImpl INTERNETSERVICES_REF = new ReferenceTypeImpl("internetServices",
TerremarkECloudMediaType.INTERNETSERVICESLIST_XML,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/internetServices/1"));
protected static final Org ORG = new TerremarkECloudOrgImpl(ORG_REF.getName(), ORG_REF.getType(), ORG_REF.getHref(),
"org", ImmutableMap.<String, ReferenceType> of(CATALOG_REF.getName(), CATALOG_REF),
ImmutableMap.<String, ReferenceType> of(VDC_REF.getName(), VDC_REF), ImmutableMap.<String, ReferenceType> of(
NETWORK_REF.getName(), NETWORK_REF), ImmutableMap.<String, ReferenceType> of(TASKSLIST_REF.getName(),
TASKSLIST_REF), KEYSLIST_REF, TAGSLIST_REF, VAPPCATALOGLIST_REF, DATACENTERSLIST_REF);
protected static final VDC VDC = new TerremarkVDCImpl(VDC_REF.getName(), VDC_REF.getType(), VDC_REF.getHref(),
VDCStatus.READY, null, "description", ImmutableSet.<Task> of(), AllocationModel.ALLOCATION_POOL, null, null,
null, ImmutableMap.<String, ReferenceType> of(
"vapp",
new ReferenceTypeImpl("vapp", "application/vnd.vmware.vcloud.vApp+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1")),
"network",
new ReferenceTypeImpl("network", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2"))),
ImmutableMap.<String, ReferenceType> of(NETWORK_REF.getName(), NETWORK_REF), 0, 0, 0, false, CATALOG_REF,
PUBLICIPS_REF, INTERNETSERVICES_REF);
@RequiresHttp
@ConfiguresRestClient
protected static class TerremarkECloudRestClientModuleExtension extends TerremarkECloudRestClientModule {
@Override
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService, String version) {
return URI.create("https://vcloud.safesecureweb.com/api/v0.8/login");
} }
@Override @Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() { protected Org provideOrg(Supplier<Map<String, ? extends Org>> orgSupplier,
return ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> of("org", @org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) {
return ORG;
ImmutableMap.<String, org.jclouds.vcloud.domain.VDC> of(
"vdc",
new TerremarkVDCImpl("vdc", null, URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"),
VDCStatus.READY, null, "description", ImmutableSet.<Task> of(), AllocationModel.UNRECOGNIZED,
new Capacity("MB", 0, 0, 0, 0), new Capacity("MB", 0, 0, 0, 0), new Capacity("MB", 0, 0, 0, 0),
ImmutableMap.<String, ReferenceType> of(
"vapp",
new ReferenceTypeImpl("vapp", "application/vnd.vmware.vcloud.vApp+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1")),
"network",
new ReferenceTypeImpl("network", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2"))), ImmutableMap
.<String, ReferenceType> of(), 0, 0, 0, false, new ReferenceTypeImpl("catalog",
TerremarkVCloudMediaType.CATALOG_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1")),
new ReferenceTypeImpl("publicIps", TerremarkVCloudMediaType.PUBLICIPSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/publicIps/1")), new ReferenceTypeImpl(
"internetServices", TerremarkVCloudMediaType.INTERNETSERVICESLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/internetServices/1")))));
} }
}
@Override
protected void installDefaultVCloudEndpointsModule() {
install(new AbstractModule() {
@Override
protected void configure() {
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.Org.class).toInstance(ORG_REF);
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.Catalog.class).toInstance(
CATALOG_REF);
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.TasksList.class).toInstance(
TASKSLIST_REF);
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.VDC.class).toInstance(VDC_REF);
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.Network.class).toInstance(
NETWORK_REF);
}
});
}
@Override
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
AtomicReference<AuthorizationException> authException, VCloudExpressLoginAsyncClient login) {
return Suppliers.<VCloudSession> ofInstance(new VCloudSession() {
@Override
public Map<String, ReferenceType> getOrgs() {
return ImmutableMap.<String, ReferenceType> of(ORG_REF.getName(), ORG_REF);
}
@Override
public String getVCloudToken() {
return "token";
}
});
}
@Override
protected void configure() {
super.configure();
bind(OrgMapSupplier.class).to(TestOrgMapSupplier.class);
bind(OrgCatalogSupplier.class).to(TestOrgCatalogSupplier.class);
bind(OrgCatalogItemSupplier.class).to(TestOrgCatalogItemSupplier.class);
}
@Override
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> provideOrgVDCSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
OrgVDCSupplier supplier) {
return Suppliers.<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> ofInstance(ImmutableMap
.<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> of(ORG_REF.getName(),
ImmutableMap.<String, org.jclouds.vcloud.domain.VDC> of(VDC.getName(), VDC)));
}
@Singleton
public static class TestOrgMapSupplier extends OrgMapSupplier {
@Inject
protected TestOrgMapSupplier() {
super(null, null);
}
@Override
public Map<String, Org> get() {
return ImmutableMap.<String, Org> of(ORG.getName(), ORG);
}
}
@Singleton
public static class TestOrgCatalogSupplier extends OrgCatalogSupplier {
@Inject
protected TestOrgCatalogSupplier() {
super(null, null);
}
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
return ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> of(
ORG_REF.getName(), ImmutableMap.<String, org.jclouds.vcloud.domain.Catalog> of(
CATALOG_REF.getName(),
new CatalogImpl(CATALOG_REF.getName(), CATALOG_REF.getType(), CATALOG_REF.getHref(), null,
"description", ImmutableMap.<String, ReferenceType> of(
"item",
new ReferenceTypeImpl("item", "application/vnd.vmware.vcloud.catalogItem+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1")),
"template",
new ReferenceTypeImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml",
URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"))),
ImmutableList.<Task> of(), true, false)));
}
}
@Singleton
public static class TestOrgCatalogItemSupplier extends OrgCatalogItemSupplier {
protected TestOrgCatalogItemSupplier() {
super(null, null);
}
@Override
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
return ImmutableMap.<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> of(
ORG_REF.getName(), ImmutableMap
.<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>> of(CATALOG_REF
.getName(), ImmutableMap.<String, org.jclouds.vcloud.domain.CatalogItem> of(
"template",
new CatalogItemImpl("template", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"), "description",
new ReferenceTypeImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml",
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2")),
ImmutableMap.<String, String> of()))));
}
}
}
} }

View File

@ -18,6 +18,9 @@
*/ */
package org.jclouds.terremark.ecloud; package org.jclouds.terremark.ecloud;
import java.util.Properties;
import org.jclouds.vcloud.reference.VCloudConstants;
import org.jclouds.vcloud.terremark.BaseTerremarkClientLiveTest; import org.jclouds.vcloud.terremark.BaseTerremarkClientLiveTest;
import org.jclouds.vcloud.terremark.TerremarkECloudClient; import org.jclouds.vcloud.terremark.TerremarkECloudClient;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -27,5 +30,11 @@ import org.testng.annotations.Test;
*/ */
@Test(groups = "live", enabled = true, singleThreaded = true) @Test(groups = "live", enabled = true, singleThreaded = true)
public class BaseTerremarkECloudClientLiveTest extends BaseTerremarkClientLiveTest<TerremarkECloudClient> { public class BaseTerremarkECloudClientLiveTest extends BaseTerremarkClientLiveTest<TerremarkECloudClient> {
@Override
protected Properties setupProperties() {
Properties props = super.setupProperties();
props.setProperty(VCloudConstants.PROPERTY_VCLOUD_DEFAULT_VDC,
".* - " + System.getProperty("test.trmk-ecloud.datacenter", "MIA"));
return props;
}
} }

View File

@ -33,7 +33,7 @@ import org.testng.annotations.Test;
public class DataCenterOperationsClientLiveTest extends BaseTerremarkECloudClientLiveTest { public class DataCenterOperationsClientLiveTest extends BaseTerremarkECloudClientLiveTest {
@Test @Test
public void testListDataCentersInOrg() throws Exception { public void testListDataCentersInOrg() throws Exception {
for (ReferenceType response : getApi().listOrgs()) { for (ReferenceType response : getApi().listOrgs().values()) {
TerremarkECloudOrg org = getApi().getOrg(response.getHref()); TerremarkECloudOrg org = getApi().getOrg(response.getHref());
assertNotNull(response); assertNotNull(response);
assertNotNull(response.getName()); assertNotNull(response.getName());

View File

@ -33,7 +33,7 @@ import org.testng.annotations.Test;
public class TagOperationsClientLiveTest extends BaseTerremarkECloudClientLiveTest { public class TagOperationsClientLiveTest extends BaseTerremarkECloudClientLiveTest {
@Test @Test
public void testListTagsInOrg() throws Exception { public void testListTagsInOrg() throws Exception {
for (ReferenceType response : getApi().listOrgs()) { for (ReferenceType response : getApi().listOrgs().values()) {
TerremarkECloudOrg org = getApi().getOrg(response.getHref()); TerremarkECloudOrg org = getApi().getOrg(response.getHref());
assertNotNull(response); assertNotNull(response);
assertNotNull(response.getName()); assertNotNull(response.getName());

View File

@ -19,12 +19,12 @@
package org.jclouds.vcloud.terremark; package org.jclouds.vcloud.terremark;
import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.disabled; import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.disabled;
import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URI; import java.net.URI;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReleasePayloadAndReturn; import org.jclouds.http.functions.ReleasePayloadAndReturn;
@ -50,7 +50,7 @@ import org.jclouds.vcloud.terremark.xml.KeyPairHandler;
import org.jclouds.vcloud.terremark.xml.KeyPairsHandler; import org.jclouds.vcloud.terremark.xml.KeyPairsHandler;
import org.jclouds.vcloud.terremark.xml.NodeHandler; import org.jclouds.vcloud.terremark.xml.NodeHandler;
import org.jclouds.vcloud.terremark.xml.NodesHandler; import org.jclouds.vcloud.terremark.xml.NodesHandler;
import org.jclouds.vcloud.terremark.xml.PublicIpAddressesHandler; import org.jclouds.vcloud.terremark.xml.PublicIpAddressHandler;
import org.jclouds.vcloud.terremark.xml.TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler; import org.jclouds.vcloud.terremark.xml.TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler;
import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler; import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler;
import org.jclouds.vcloud.terremark.xml.VAppExtendedInfoHandler; import org.jclouds.vcloud.terremark.xml.VAppExtendedInfoHandler;
@ -58,24 +58,30 @@ import org.jclouds.vcloud.xml.VCloudExpressCatalogHandler;
import org.jclouds.vcloud.xml.VCloudExpressVAppHandler; import org.jclouds.vcloud.xml.VCloudExpressVAppHandler;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
/** /**
* Tests behavior of {@code TerremarkECloudAsyncClient} * Tests behavior of {@code TerremarkECloudAsyncClient}
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire // NOTE:without testName, this will not call @Before* and fail w/NPE during
// surefire
@Test(groups = "unit", singleThreaded = true, testName = "TerremarkECloudAsyncClientTest") @Test(groups = "unit", singleThreaded = true, testName = "TerremarkECloudAsyncClientTest")
public class TerremarkECloudAsyncClientTest extends BaseTerremarkECloudAsyncClientTest<TerremarkECloudAsyncClient> { public class TerremarkECloudAsyncClientTest extends BaseTerremarkECloudAsyncClientTest<TerremarkECloudAsyncClient> {
public void testListOrgs() {
assertEquals(injector.getInstance(TerremarkECloudAsyncClient.class).listOrgs().toString(),
ImmutableMap.of(ORG_REF.getName(), ORG_REF).toString());
}
@Override @Override
protected TypeLiteral<RestAnnotationProcessor<TerremarkECloudAsyncClient>> createTypeLiteral() { protected TypeLiteral<RestAnnotationProcessor<TerremarkECloudAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<TerremarkECloudAsyncClient>>() { return new TypeLiteral<RestAnnotationProcessor<TerremarkECloudAsyncClient>>() {
}; };
} }
public void testNetwork() throws SecurityException, NoSuchMethodException, IOException { public void testNetwork() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkECloudAsyncClient.class.getMethod("getNetwork", URI.class); Method method = TerremarkECloudAsyncClient.class.getMethod("getNetwork", URI.class);
HttpRequest request = processor.createRequest(method, HttpRequest request = processor.createRequest(method,
@ -219,8 +225,8 @@ public class TerremarkECloudAsyncClientTest extends BaseTerremarkECloudAsyncClie
assertPayloadEquals(request, null, null, false); assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, PublicIpAddressesHandler.class); assertSaxResponseParserClassEquals(method, PublicIpAddressHandler.class);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request); checkFilters(request);
} }

View File

@ -21,11 +21,13 @@ package org.jclouds.vcloud.terremark;
import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.processorCount; import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.processorCount;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Properties;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.net.IPSocket; import org.jclouds.net.IPSocket;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.vcloud.domain.VCloudExpressVApp; import org.jclouds.vcloud.domain.VCloudExpressVApp;
import org.jclouds.vcloud.reference.VCloudConstants;
import org.jclouds.vcloud.terremark.domain.InternetService; import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.Protocol; import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.domain.PublicIpAddress; import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
@ -41,6 +43,14 @@ import org.testng.annotations.Test;
*/ */
@Test(groups = "live", enabled = true, singleThreaded = true, testName = "TerremarkECloudClientLiveTest") @Test(groups = "live", enabled = true, singleThreaded = true, testName = "TerremarkECloudClientLiveTest")
public class TerremarkECloudClientLiveTest extends TerremarkClientLiveTest { public class TerremarkECloudClientLiveTest extends TerremarkClientLiveTest {
@Override
protected Properties setupProperties() {
Properties props = super.setupProperties();
props.setProperty(VCloudConstants.PROPERTY_VCLOUD_DEFAULT_VDC,
".* - " + System.getProperty("test.trmk-ecloud.datacenter", "MIA"));
return props;
}
@BeforeClass @BeforeClass
void setProvider() { void setProvider() {
this.provider = "trmk-ecloud"; this.provider = "trmk-ecloud";
@ -61,7 +71,7 @@ public class TerremarkECloudClientLiveTest extends TerremarkClientLiveTest {
@Override @Override
protected Entry<InternetService, PublicIpAddress> getNewInternetServiceAndIpForSSH(VCloudExpressVApp vApp) { protected Entry<InternetService, PublicIpAddress> getNewInternetServiceAndIpForSSH(VCloudExpressVApp vApp) {
return new TerremarkECloudInternetServiceAndPublicIpAddressSupplier(TerremarkECloudClient.class.cast(tmClient)) return new TerremarkECloudInternetServiceAndPublicIpAddressSupplier(TerremarkECloudClient.class.cast(tmClient))
.getNewInternetServiceAndIp(vApp, 22, Protocol.TCP); .getNewInternetServiceAndIp(vApp, 22, Protocol.TCP);
} }
} }

View File

@ -20,6 +20,8 @@ package org.jclouds.vcloud.terremark.compute;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.util.Properties;
import org.jclouds.compute.BaseComputeServiceLiveTest; import org.jclouds.compute.BaseComputeServiceLiveTest;
import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.ComputeMetadata;
@ -32,16 +34,27 @@ import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.jclouds.vcloud.domain.VCloudExpressVApp; import org.jclouds.vcloud.domain.VCloudExpressVApp;
import org.jclouds.vcloud.reference.VCloudConstants;
import org.jclouds.vcloud.terremark.TerremarkVCloudClient; import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**
* This test is disabled, as it doesn't work while there are too few public ip addresses. * This test is disabled, as it doesn't work while there are too few public ip
* addresses.
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "live", enabled = true, sequential = true) @Test(groups = "live", enabled = true, singleThreaded = true)
public class TerremarkECloudComputeServiceLiveTest extends BaseComputeServiceLiveTest { public class TerremarkECloudComputeServiceLiveTest extends BaseComputeServiceLiveTest {
@Override
protected Properties setupProperties() {
Properties props = super.setupProperties();
props.setProperty(VCloudConstants.PROPERTY_VCLOUD_DEFAULT_VDC,
".* - " + System.getProperty("test.trmk-ecloud.datacenter", "MIA"));
return props;
}
public TerremarkECloudComputeServiceLiveTest() { public TerremarkECloudComputeServiceLiveTest() {
provider = "trmk-ecloud"; provider = "trmk-ecloud";
} }
@ -60,13 +73,6 @@ public class TerremarkECloudComputeServiceLiveTest extends BaseComputeServiceLiv
return template; return template;
} }
// currently, the wrong CIM OSType data is coming back.
@Override
protected void checkOsMatchesTemplate(NodeMetadata node) {
if (node.getOperatingSystem() != null)
assertEquals(node.getOperatingSystem().getFamily(), null);
}
@Override @Override
public void testListImages() throws Exception { public void testListImages() throws Exception {
for (Image image : client.listImages()) { for (Image image : client.listImages()) {
@ -74,7 +80,7 @@ public class TerremarkECloudComputeServiceLiveTest extends BaseComputeServiceLiv
// image.getLocationId() can be null, if it is a location-free image // image.getLocationId() can be null, if it is a location-free image
assertEquals(image.getType(), ComputeType.IMAGE); assertEquals(image.getType(), ComputeType.IMAGE);
if (image.getOperatingSystem().getFamily() != OsFamily.WINDOWS if (image.getOperatingSystem().getFamily() != OsFamily.WINDOWS
&& image.getOperatingSystem().getFamily() != OsFamily.SOLARIS) { && image.getOperatingSystem().getFamily() != OsFamily.SOLARIS) {
assert image.getDefaultCredentials() != null && image.getDefaultCredentials().identity != null : image; assert image.getDefaultCredentials() != null && image.getDefaultCredentials().identity != null : image;
assert image.getDefaultCredentials().credential != null : image; assert image.getDefaultCredentials().credential != null : image;
} }
@ -90,7 +96,7 @@ public class TerremarkECloudComputeServiceLiveTest extends BaseComputeServiceLiv
NodeMetadata allData = client.getNodeMetadata(node.getId()); NodeMetadata allData = client.getNodeMetadata(node.getId());
System.out.println(allData.getHardware()); System.out.println(allData.getHardware());
RestContext<TerremarkVCloudClient, TerremarkVCloudClient> tmContext = new ComputeServiceContextFactory() RestContext<TerremarkVCloudClient, TerremarkVCloudClient> tmContext = new ComputeServiceContextFactory()
.createContext(provider, identity, credential).getProviderSpecificContext(); .createContext(provider, identity, credential).getProviderSpecificContext();
VCloudExpressVApp vApp = tmContext.getApi().findVAppInOrgVDCNamed(null, null, allData.getName()); VCloudExpressVApp vApp = tmContext.getApi().findVAppInOrgVDCNamed(null, null, allData.getName());
assertEquals(vApp.getName(), allData.getName()); assertEquals(vApp.getName(), allData.getName());
} }

View File

@ -22,12 +22,14 @@ import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.util.Properties;
import java.util.Set; import java.util.Set;
import org.jclouds.compute.BaseTemplateBuilderLiveTest; import org.jclouds.compute.BaseTemplateBuilderLiveTest;
import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.OsFamilyVersion64Bit; import org.jclouds.compute.domain.OsFamilyVersion64Bit;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.vcloud.reference.VCloudConstants;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -39,6 +41,13 @@ import com.google.common.collect.ImmutableSet;
*/ */
@Test(groups = "live") @Test(groups = "live")
public class TerremarkECloudTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { public class TerremarkECloudTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
@Override
protected Properties setupProperties() {
Properties props = super.setupProperties();
props.setProperty(VCloudConstants.PROPERTY_VCLOUD_DEFAULT_VDC,
".* - " + System.getProperty("test.trmk-ecloud.datacenter", "MIA"));
return props;
}
public TerremarkECloudTemplateBuilderLiveTest() { public TerremarkECloudTemplateBuilderLiveTest() {
provider = "trmk-ecloud"; provider = "trmk-ecloud";
@ -51,20 +60,20 @@ public class TerremarkECloudTemplateBuilderLiveTest extends BaseTemplateBuilderL
@Override @Override
public boolean apply(OsFamilyVersion64Bit input) { public boolean apply(OsFamilyVersion64Bit input) {
switch (input.family) { switch (input.family) {
case RHEL: case RHEL:
return !input.version.equals("") && !input.version.matches("5.[50]"); return !input.version.equals("") && !input.version.matches("5.[50]");
case SOLARIS: case SOLARIS:
return !input.is64Bit; return !input.is64Bit;
case CENTOS: case CENTOS:
return !input.version.equals("") && !input.version.matches("5.[50]"); return !input.version.equals("") && !input.version.matches("5.[50]");
case UBUNTU: case UBUNTU:
return !input.version.equals("") && !input.version.equals("10.04") && !input.version.equals("8.04"); return !input.version.equals("") && !input.version.equals("10.04") && !input.version.equals("8.04");
case WINDOWS: case WINDOWS:
return !input.version.equals("") && !input.version.equals("2003 R2") // return !input.version.equals("") && !input.version.equals("2003 R2") //
&& !(input.version.equals("2008") && !input.is64Bit) // && !(input.version.equals("2008") && !input.is64Bit) //
&& !(input.version.matches("2008( R2)?") && input.is64Bit); && !(input.version.matches("2008( R2)?") && input.is64Bit);
default: default:
return true; return true;
} }
} }
}; };

View File

@ -18,8 +18,7 @@
*/ */
package org.jclouds.vcloud.terremark; package org.jclouds.vcloud.terremark;
import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.disabled; import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.disabled;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
@ -28,6 +27,7 @@ import java.lang.reflect.Method;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -37,6 +37,7 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReleasePayloadAndReturn; import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
@ -47,18 +48,18 @@ import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Strings2; import org.jclouds.util.Strings2;
import org.jclouds.vcloud.CommonVCloudClient; import org.jclouds.vcloud.VCloudExpressLoginAsyncClient;
import org.jclouds.vcloud.VCloudExpressAsyncClientTest.VCloudRestClientModuleExtension.TestOrgCatalogItemSupplier; import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.VCloudExpressAsyncClientTest.VCloudRestClientModuleExtension.TestOrgCatalogSupplier;
import org.jclouds.vcloud.VCloudVersionsAsyncClient; import org.jclouds.vcloud.VCloudVersionsAsyncClient;
import org.jclouds.vcloud.domain.AllocationModel; import org.jclouds.vcloud.domain.AllocationModel;
import org.jclouds.vcloud.domain.Capacity;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VCloudSession; import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.domain.VDCStatus; import org.jclouds.vcloud.domain.VDCStatus;
import org.jclouds.vcloud.domain.internal.CatalogImpl;
import org.jclouds.vcloud.domain.internal.CatalogItemImpl;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import org.jclouds.vcloud.domain.network.NetworkConfig; import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
@ -85,12 +86,12 @@ import org.jclouds.vcloud.xml.VCloudExpressCatalogHandler;
import org.jclouds.vcloud.xml.VCloudExpressVAppHandler; import org.jclouds.vcloud.xml.VCloudExpressVAppHandler;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps; import com.google.inject.AbstractModule;
import com.google.inject.Injector;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
@ -99,10 +100,16 @@ import com.google.inject.TypeLiteral;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire // NOTE:without testName, this will not call @Before* and fail w/NPE during
// surefire
@Test(groups = "unit", singleThreaded = true, testName = "TerremarkVCloudExpressAsyncClientTest") @Test(groups = "unit", singleThreaded = true, testName = "TerremarkVCloudExpressAsyncClientTest")
public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<TerremarkVCloudExpressAsyncClient> { public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<TerremarkVCloudExpressAsyncClient> {
public void testListOrgs() {
assertEquals(injector.getInstance(TerremarkVCloudExpressAsyncClient.class).listOrgs().toString(),
ImmutableMap.of(ORG_REF.getName(), ORG_REF).toString());
}
public void testCatalogItemURI() throws SecurityException, NoSuchMethodException, IOException { public void testCatalogItemURI() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("getCatalogItem", URI.class); Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("getCatalogItem", URI.class);
HttpRequest request = processor.createRequest(method, HttpRequest request = processor.createRequest(method,
@ -631,160 +638,181 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
new Properties()); new Properties());
} }
protected static final ReferenceTypeImpl ORG_REF = new ReferenceTypeImpl("org", VCloudMediaType.ORG_XML,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"));
protected static final ReferenceTypeImpl CATALOG_REF = new ReferenceTypeImpl("catalog", VCloudMediaType.CATALOG_XML,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"));
protected static final ReferenceTypeImpl TASKSLIST_REF = new ReferenceTypeImpl("tasksList",
VCloudMediaType.TASKSLIST_XML, URI.create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1"));
protected static final ReferenceTypeImpl VDC_REF = new ReferenceTypeImpl("vdc", VCloudMediaType.VDC_XML,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"));
protected static final ReferenceTypeImpl KEYSLIST_REF = new ReferenceTypeImpl("keysList",
TerremarkVCloudExpressMediaType.KEYSLIST_XML,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/keysList/1"));
protected static final ReferenceTypeImpl NETWORK_REF = new ReferenceTypeImpl("network", VCloudMediaType.NETWORK_XML,
URI.create("https://vcloud.safesecureweb.com/network/1990"));
protected static final ReferenceTypeImpl PUBLICIPS_REF = new ReferenceTypeImpl("publicIps",
TerremarkVCloudExpressMediaType.PUBLICIPSLIST_XML,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/publicIps/1"));
protected static final ReferenceTypeImpl INTERNETSERVICES_REF = new ReferenceTypeImpl("internetServices",
TerremarkVCloudExpressMediaType.INTERNETSERVICESLIST_XML,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/internetServices/1"));
protected static final Org ORG = new TerremarkOrgImpl(ORG_REF.getName(), ORG_REF.getType(), ORG_REF.getHref(),
"org", ImmutableMap.<String, ReferenceType> of(CATALOG_REF.getName(), CATALOG_REF),
ImmutableMap.<String, ReferenceType> of(VDC_REF.getName(), VDC_REF), ImmutableMap.<String, ReferenceType> of(
NETWORK_REF.getName(), NETWORK_REF), ImmutableMap.<String, ReferenceType> of(TASKSLIST_REF.getName(),
TASKSLIST_REF), KEYSLIST_REF);
protected static final VDC VDC = new TerremarkVDCImpl(VDC_REF.getName(), VDC_REF.getType(), VDC_REF.getHref(),
VDCStatus.READY, null, "description", ImmutableSet.<Task> of(), AllocationModel.ALLOCATION_POOL, null, null,
null, ImmutableMap.<String, ReferenceType> of(
"vapp",
new ReferenceTypeImpl("vapp", "application/vnd.vmware.vcloud.vApp+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1")),
"network",
new ReferenceTypeImpl("network", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2"))),
ImmutableMap.<String, ReferenceType> of(NETWORK_REF.getName(), NETWORK_REF), 0, 0, 0, false, CATALOG_REF,
PUBLICIPS_REF, INTERNETSERVICES_REF);
@RequiresHttp @RequiresHttp
@ConfiguresRestClient @ConfiguresRestClient
protected static class TerremarkVCloudRestClientModuleExtension extends TerremarkVCloudExpressRestClientModule { protected static class TerremarkVCloudRestClientModuleExtension extends TerremarkVCloudExpressRestClientModule {
@Override @Override
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService, protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService, String version) {
@Named(PROPERTY_API_VERSION) String version) { return URI.create("https://vcloud.safesecureweb.com/api/v0.8/login");
return URI.create("https://vcloud/login"); }
@Override
protected Org provideOrg(Supplier<Map<String, ? extends Org>> orgSupplier,
@org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) {
return ORG;
}
@Override
protected void installDefaultVCloudEndpointsModule() {
install(new AbstractModule() {
@Override
protected void configure() {
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.Org.class).toInstance(ORG_REF);
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.Catalog.class).toInstance(
CATALOG_REF);
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.TasksList.class).toInstance(
TASKSLIST_REF);
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.VDC.class).toInstance(VDC_REF);
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.Network.class).toInstance(
NETWORK_REF);
}
});
}
@Override
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
AtomicReference<AuthorizationException> authException, VCloudExpressLoginAsyncClient login) {
return Suppliers.<VCloudSession> ofInstance(new VCloudSession() {
@Override
public Map<String, ReferenceType> getOrgs() {
return ImmutableMap.<String, ReferenceType> of(ORG_REF.getName(), ORG_REF);
}
@Override
public String getVCloudToken() {
return "token";
}
});
} }
@Override @Override
protected void configure() { protected void configure() {
super.configure(); super.configure();
bind(OrgNameToKeysListSupplier.class).to(TestOrgNameToKeysListSupplier.class); bind(OrgMapSupplier.class).to(TestOrgMapSupplier.class);
bind(OrgMapSupplier.class).to(TestTerremarkOrgMapSupplier.class);
bind(OrgCatalogSupplier.class).to(TestOrgCatalogSupplier.class); bind(OrgCatalogSupplier.class).to(TestOrgCatalogSupplier.class);
bind(OrgCatalogItemSupplier.class).to(TestOrgCatalogItemSupplier.class); bind(OrgCatalogItemSupplier.class).to(TestOrgCatalogItemSupplier.class);
bind(OrgVDCSupplier.class).to(TestTerremarkOrgVDCSupplier.class);
} }
@Override @Override
protected URI provideOrg(@org.jclouds.vcloud.endpoints.Org Iterable<ReferenceType> orgs) { protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> provideOrgVDCSupplierCache(
return URI.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"); @Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
} OrgVDCSupplier supplier) {
return Suppliers.<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> ofInstance(ImmutableMap
@Override .<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> of(ORG_REF.getName(),
protected String provideOrgName(@org.jclouds.vcloud.endpoints.Org Iterable<ReferenceType> orgs) { ImmutableMap.<String, org.jclouds.vcloud.domain.VDC> of(VDC.getName(), VDC)));
return "org";
}
@Override
protected URI provideCatalog(Org org, @Named(PROPERTY_IDENTITY) String user, WriteableCatalog write) {
return URI.create("https://catalog");
}
@Override
protected Org provideOrg(CommonVCloudClient discovery) {
return null;
}
@Override
protected Iterable<ReferenceType> provideOrgs(Supplier<VCloudSession> cache, @Named(PROPERTY_IDENTITY) String user) {
return null;
} }
@Singleton @Singleton
public static class TestOrgNameToKeysListSupplier extends OrgNameToKeysListSupplier { public static class TestOrgMapSupplier extends OrgMapSupplier {
@Inject @Inject
protected TestOrgNameToKeysListSupplier(Supplier<VCloudSession> sessionSupplier) { protected TestOrgMapSupplier() {
super(sessionSupplier, null);
}
@Override
public Map<String, ReferenceType> get() {
return Maps.transformValues(sessionSupplier.get().getOrgs(), new Function<ReferenceType, ReferenceType>() {
@Override
public ReferenceType apply(ReferenceType from) {
return new ReferenceTypeImpl(from.getName(), TerremarkVCloudExpressMediaType.KEYSLIST_XML, URI
.create(from.getHref().toASCIIString() + "/keysList"));
}
});
}
}
@Singleton
public static class TestTerremarkOrgMapSupplier extends OrgMapSupplier {
@Inject
protected TestTerremarkOrgMapSupplier() {
super(null, null); super(null, null);
} }
@Override @Override
public Map<String, Org> get() { public Map<String, Org> get() {
return ImmutableMap.<String, Org> of( return ImmutableMap.<String, Org> of(ORG.getName(), ORG);
"org",
new TerremarkOrgImpl("org", null, URI.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"),
null, ImmutableMap.<String, ReferenceType> of(
"catalog",
new ReferenceTypeImpl("catalog", TerremarkVCloudExpressMediaType.CATALOG_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))), ImmutableMap
.<String, ReferenceType> of(
"vdc",
new ReferenceTypeImpl("vdc", TerremarkVCloudExpressMediaType.VDC_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"))), ImmutableMap
.<String, ReferenceType> of(), ImmutableMap.<String, ReferenceType> of(
"tasksList",
new ReferenceTypeImpl("tasksList", TerremarkVCloudExpressMediaType.TASKSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1"))),
new ReferenceTypeImpl("keysList", TerremarkVCloudExpressMediaType.KEYSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/keysList/1"))));
} }
} }
@Singleton @Singleton
public static class TestTerremarkOrgVDCSupplier extends OrgVDCSupplier { public static class TestOrgCatalogSupplier extends OrgCatalogSupplier {
@Inject @Inject
protected TestTerremarkOrgVDCSupplier() { protected TestOrgCatalogSupplier() {
super(null, null); super(null, null);
} }
@Override @Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() { public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
return ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> of("org", return ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> of(
ORG_REF.getName(), ImmutableMap.<String, org.jclouds.vcloud.domain.Catalog> of(
ImmutableMap.<String, org.jclouds.vcloud.domain.VDC> of( CATALOG_REF.getName(),
"vdc", new CatalogImpl(CATALOG_REF.getName(), CATALOG_REF.getType(), CATALOG_REF.getHref(), null,
new TerremarkVDCImpl("vdc", null, URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), "description", ImmutableMap.<String, ReferenceType> of(
VDCStatus.READY, null, "description", ImmutableSet.<Task> of(), AllocationModel.UNRECOGNIZED, "item",
new Capacity("MB", 0, 0, 0, 0), new Capacity("MB", 0, 0, 0, 0), new Capacity("MB", 0, 0, 0, 0), new ReferenceTypeImpl("item", "application/vnd.vmware.vcloud.catalogItem+xml", URI
ImmutableMap.<String, ReferenceType> of( .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1")),
"vapp", "template",
new ReferenceTypeImpl("vapp", "application/vnd.vmware.vcloud.vApp+xml", URI new ReferenceTypeImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml",
.create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1")), URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"))),
"network", ImmutableList.<Task> of(), true, false)));
new ReferenceTypeImpl("network", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2"))), ImmutableMap
.<String, ReferenceType> of(), 0, 0, 0, false, new ReferenceTypeImpl("catalog",
TerremarkVCloudExpressMediaType.CATALOG_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1")),
new ReferenceTypeImpl("publicIps", TerremarkVCloudExpressMediaType.PUBLICIPSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/publicIps/1")), new ReferenceTypeImpl(
"internetServices", TerremarkVCloudExpressMediaType.INTERNETSERVICESLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/internetServices/1")))));
} }
} }
@Override @Singleton
protected URI provideDefaultTasksList(Org org) { public static class TestOrgCatalogItemSupplier extends OrgCatalogItemSupplier {
return URI.create("https://taskslist"); protected TestOrgCatalogItemSupplier() {
super(null, null);
}
@Override
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
return ImmutableMap.<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> of(
ORG_REF.getName(), ImmutableMap
.<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>> of(CATALOG_REF
.getName(), ImmutableMap.<String, org.jclouds.vcloud.domain.CatalogItem> of(
"template",
new CatalogItemImpl("template", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"), "description",
new ReferenceTypeImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml",
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2")),
ImmutableMap.<String, String> of()))));
}
} }
@Override
protected URI provideDefaultVDC(Org org, @org.jclouds.vcloud.endpoints.VDC String defaultVDC) {
return URI.create("https://vdc/1");
}
@Override
protected String provideDefaultVDCName(
@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
return "vdc";
}
@Override
protected String provideCatalogName(Supplier<Map<String, Map<String, ? extends Catalog>>> catalogs) {
return "catalog";
}
@Override
protected URI provideDefaultNetwork(URI vdc, Injector injector) {
return URI.create("https://vcloud.safesecureweb.com/network/1990");
}
} }
} }

View File

@ -22,7 +22,6 @@ import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTempl
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import java.util.Set;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
@ -51,16 +50,6 @@ public class TerremarkVCloudExpressClientLiveTest extends TerremarkClientLiveTes
KeyPair key; KeyPair key;
@Test
public void testKeysList() throws Exception {
TerremarkVCloudExpressClient vCloudExpressClient = TerremarkVCloudExpressClient.class.cast(tmClient);
TerremarkOrg org = vCloudExpressClient.findOrgNamed(null);
Set<KeyPair> response = vCloudExpressClient.listKeyPairsInOrg(null);
assertNotNull(response);
System.err.println(response);
assertEquals(response, vCloudExpressClient.listKeyPairsInOrg(org.getHref()));
}
@Override @Override
protected void prepare() { protected void prepare() {
TerremarkVCloudExpressClient vCloudExpressClient = TerremarkVCloudExpressClient.class.cast(tmClient); TerremarkVCloudExpressClient vCloudExpressClient = TerremarkVCloudExpressClient.class.cast(tmClient);
@ -74,13 +63,12 @@ public class TerremarkVCloudExpressClientLiveTest extends TerremarkClientLiveTes
key = vCloudExpressClient.generateKeyPairInOrg(org.getHref(), "livetest", false); key = vCloudExpressClient.generateKeyPairInOrg(org.getHref(), "livetest", false);
} }
assertNotNull(key); assertNotNull(key);
System.err.println(key);
assertEquals(key.getName(), "livetest"); assertEquals(key.getName(), "livetest");
assertNotNull(key.getPrivateKey()); assertNotNull(key.getPrivateKey());
assertNotNull(key.getFingerPrint()); assertNotNull(key.getFingerPrint());
assertEquals(key.isDefault(), false); assertEquals(key.isDefault(), false);
assertEquals(key.getFingerPrint(), vCloudExpressClient.findKeyPairInOrg(org.getHref(), key.getName()) assertEquals(key.getFingerPrint(), vCloudExpressClient.findKeyPairInOrg(org.getHref(), key.getName())
.getFingerPrint()); .getFingerPrint());
} }
@AfterTest @AfterTest
@ -103,7 +91,7 @@ public class TerremarkVCloudExpressClientLiveTest extends TerremarkClientLiveTes
@Override @Override
protected Entry<InternetService, PublicIpAddress> getNewInternetServiceAndIpForSSH(VCloudExpressVApp vApp) { protected Entry<InternetService, PublicIpAddress> getNewInternetServiceAndIpForSSH(VCloudExpressVApp vApp) {
return new TerremarkVCloudExpressInternetServiceAndPublicIpAddressSupplier(TerremarkVCloudExpressClient.class return new TerremarkVCloudExpressInternetServiceAndPublicIpAddressSupplier(
.cast(tmClient)).getNewInternetServiceAndIp(vApp, 22, Protocol.TCP); TerremarkVCloudExpressClient.class.cast(tmClient)).getNewInternetServiceAndIp(vApp, 22, Protocol.TCP);
} }
} }

View File

@ -60,13 +60,6 @@ public class TerremarkVCloudExpressComputeServiceLiveTest extends BaseComputeSer
return template; return template;
} }
// currently, the wrong CIM OSType data is coming back.
@Override
protected void checkOsMatchesTemplate(NodeMetadata node) {
if (node.getOperatingSystem() != null)
assertEquals(node.getOperatingSystem().getFamily(), null);
}
@Override @Override
public void testListImages() throws Exception { public void testListImages() throws Exception {
for (Image image : client.listImages()) { for (Image image : client.listImages()) {