mirror of https://github.com/apache/jclouds.git
Issue 628:expose properties to choose default Org and vDC in vCloud-based implementations
This commit is contained in:
parent
c1ae4d06e6
commit
0f9dd50d7d
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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,7 +49,8 @@ import com.google.inject.Provides;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the VCloud authentication service connection, including logging and http transport.
|
* Configures the VCloud authentication service connection, including logging
|
||||||
|
* and http transport.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
|
@ -67,29 +68,12 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
|
||||||
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,7 +86,7 @@ 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>() {
|
||||||
|
|
||||||
|
|
|
@ -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,16 +213,17 @@ 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",
|
||||||
|
new ReferenceTypeImpl("item", "application/vnd.vmware.vcloud.catalogItem+xml", URI
|
||||||
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/1")),
|
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/1")),
|
||||||
"template", new ReferenceTypeImpl("template",
|
"template",
|
||||||
"application/vnd.vmware.vcloud.vAppTemplate+xml", URI
|
new ReferenceTypeImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml",
|
||||||
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"))),
|
URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"))),
|
||||||
ImmutableList.<Task> of(), true, false)));
|
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(
|
|
||||||
"catalog",
|
|
||||||
ImmutableMap
|
|
||||||
.<String, org.jclouds.vcloud.domain.CatalogItem> of(
|
|
||||||
"template",
|
"template",
|
||||||
new CatalogItemImpl(
|
new CatalogItemImpl("template", URI
|
||||||
"template",
|
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"), "description",
|
||||||
URI
|
new ReferenceTypeImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml",
|
||||||
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"),
|
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/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()))));
|
ImmutableMap.<String, String> of()))));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Iterable<ReferenceType> provideOrgs(Supplier<VCloudSession> cache, String user) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,20 +43,32 @@ 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()) {
|
||||||
|
@ -70,10 +85,11 @@ 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()) {
|
||||||
|
@ -90,10 +106,11 @@ public class DeprecatedVCloudClientLiveTest extends CommonVCloudClientLiveTest<V
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetVApp() throws Exception {
|
public void testGetVApp() 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 item : response.getResourceEntities().values()) {
|
for (ReferenceType item : response.getResourceEntities().values()) {
|
||||||
|
@ -108,10 +125,11 @@ public class DeprecatedVCloudClientLiveTest extends CommonVCloudClientLiveTest<V
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetThumbnailOfVm() throws Exception {
|
public void testGetThumbnailOfVm() 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 item : response.getResourceEntities().values()) {
|
for (ReferenceType item : response.getResourceEntities().values()) {
|
||||||
|
@ -129,10 +147,11 @@ public class DeprecatedVCloudClientLiveTest extends CommonVCloudClientLiveTest<V
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetVm() throws Exception {
|
public void testGetVm() 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 item : response.getResourceEntities().values()) {
|
for (ReferenceType item : response.getResourceEntities().values()) {
|
||||||
|
@ -140,9 +159,7 @@ public class DeprecatedVCloudClientLiveTest extends CommonVCloudClientLiveTest<V
|
||||||
try {
|
try {
|
||||||
VApp app = connection.getVApp(item.getHref());
|
VApp app = connection.getVApp(item.getHref());
|
||||||
assertNotNull(app);
|
assertNotNull(app);
|
||||||
for (Vm vm : app.getChildren()) {
|
assert app.getChildren().size() > 0;
|
||||||
// assertEquals(connection.getVm(vm.getHref()), vm);
|
|
||||||
}
|
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -150,10 +167,11 @@ public class DeprecatedVCloudClientLiveTest extends CommonVCloudClientLiveTest<V
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindVAppTemplate() throws Exception {
|
public void testFindVAppTemplate() 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()) {
|
||||||
|
@ -161,8 +179,8 @@ public class DeprecatedVCloudClientLiveTest extends CommonVCloudClientLiveTest<V
|
||||||
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.findVAppTemplateInOrgCatalogNamed(org.getName(), response.getName(), item
|
assertNotNull(connection.findVAppTemplateInOrgCatalogNamed(org.getName(), response.getName(),
|
||||||
.getEntity().getName()));
|
item.getEntity().getName()));
|
||||||
} catch (AuthorizationException e) {
|
} catch (AuthorizationException e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -172,3 +190,5 @@ public class DeprecatedVCloudClientLiveTest extends CommonVCloudClientLiveTest<V
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -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"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,6 +79,13 @@ 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
|
||||||
|
|
|
@ -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,6 +42,11 @@ 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);
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -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()));
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -59,6 +63,16 @@ public abstract class BaseVCloudExpressRestClientModule<S extends VCloudExpressC
|
||||||
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>() {
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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);
|
||||||
|
@ -323,6 +333,21 @@ 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", URI
|
new ReferenceTypeImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml",
|
||||||
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"))), ImmutableList
|
URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"))),
|
||||||
.<Task> of(), true, false)));
|
ImmutableList.<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",
|
||||||
|
|
|
@ -28,18 +28,33 @@ 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()) {
|
||||||
|
@ -52,10 +67,11 @@ 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()) {
|
||||||
|
@ -70,10 +86,11 @@ 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()) {
|
||||||
|
@ -88,3 +105,4 @@ public abstract class VCloudExpressClientLiveTest extends
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -61,26 +64,21 @@ public abstract class TerremarkRestClientModule<S extends TerremarkVCloudClient,
|
||||||
@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
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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());
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -101,60 +104,80 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
|
||||||
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()) {
|
||||||
|
for (InternetService service : tmClient.getAllInternetServicesInVDC(vdc.getHref())) {
|
||||||
assertNotNull(tmClient.getNodes(service.getId()));
|
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) {
|
||||||
|
for (ReferenceType vdc : org.getVDCs().values()) {
|
||||||
Set<PublicIpAddress> publicIpAddresses = tmClient.getPublicIpsAssociatedWithVDC(vdc.getHref());
|
Set<PublicIpAddress> publicIpAddresses = tmClient.getPublicIpsAssociatedWithVDC(vdc.getHref());
|
||||||
PublicIpAddress publicIp = publicIpAddresses.iterator().next();
|
PublicIpAddress publicIp = publicIpAddresses.iterator().next();
|
||||||
|
InternetService service = tmClient.addInternetServiceToExistingIp(publicIp.getId(), PREFIX
|
||||||
InternetService service = tmClient.addInternetServiceToExistingIp(publicIp.getId(), PREFIX + "-no-monitoring",
|
+ "-no-monitoring", Protocol.TCP, 1234, AddInternetServiceOptions.Builder.monitorDisabled());
|
||||||
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()) {
|
||||||
|
for (PublicIpAddress ip : tmClient.getPublicIpsAssociatedWithVDC(vdc.getHref())) {
|
||||||
assertNotNull(tmClient.getInternetServicesOnPublicIp(ip.getId()));
|
assertNotNull(tmClient.getInternetServicesOnPublicIp(ip.getId()));
|
||||||
assertNotNull(tmClient.getPublicIp(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 catalog : org.getCatalogs().values()) {
|
||||||
|
Catalog response = connection.getCatalog(catalog.getHref());
|
||||||
for (ReferenceType resource : response.values()) {
|
for (ReferenceType resource : response.values()) {
|
||||||
if (resource.getType().equals(VCloudExpressMediaType.CATALOGITEM_XML)) {
|
if (resource.getType().equals(VCloudExpressMediaType.CATALOGITEM_XML)) {
|
||||||
TerremarkCatalogItem item = tmClient.findCatalogItemInOrgCatalogNamed(null, null, resource.getName());
|
TerremarkCatalogItem item = tmClient.findCatalogItemInOrgCatalogNamed(org.getName(),
|
||||||
|
catalog.getName(), resource.getName());
|
||||||
assert tmClient.getCustomizationOptions(item.getCustomizationOptions().getHref()) != null;
|
assert tmClient.getCustomizationOptions(item.getCustomizationOptions().getHref()) != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@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) {
|
||||||
|
for (ReferenceType vdc : org.getVDCs().values()) {
|
||||||
|
TerremarkVDC response = (TerremarkVDC) tmClient.getVDC(vdc.getHref());
|
||||||
assertNotNull(response);
|
assertNotNull(response);
|
||||||
assertNotNull(response.getCatalog());
|
assertNotNull(response.getCatalog());
|
||||||
assertNotNull(response.getInternetServices());
|
assertNotNull(response.getInternetServices());
|
||||||
assertNotNull(response.getPublicIps());
|
assertNotNull(response.getPublicIps());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test(enabled = true)
|
@Test(enabled = true)
|
||||||
public void testInstantiateAndPowerOn() throws InterruptedException, ExecutionException, TimeoutException,
|
public void testInstantiateAndPowerOn() throws InterruptedException, ExecutionException, TimeoutException,
|
||||||
|
@ -373,8 +396,8 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
|
||||||
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());
|
||||||
|
|
||||||
|
@ -392,8 +415,9 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
|
||||||
.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);
|
||||||
|
|
||||||
|
|
|
@ -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"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -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,18 +77,17 @@ 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
|
||||||
*/
|
*/
|
||||||
|
@ -118,8 +107,11 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
||||||
|
|
||||||
@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
|
@Override
|
||||||
public Map<String, String> get() {
|
public Map<String, String> apply(Map<String, ? extends Org> arg0) {
|
||||||
Map<String, String> returnVal = newLinkedHashMap();
|
Builder<String, String> returnVal = ImmutableMap.<String, String> builder();
|
||||||
for (Entry<String, ? extends Org> orgr : orgToVDCSupplier.get().entrySet()) {
|
for (Entry<String, ? extends Org> orgr : arg0.entrySet()) {
|
||||||
for (String vdc : orgr.getValue().getVDCs().keySet()) {
|
for (String vdc : orgr.getValue().getVDCs().keySet()) {
|
||||||
returnVal.put(vdc, orgr.getKey());
|
returnVal.put(vdc, orgr.getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returnVal;
|
return returnVal.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,29 +180,13 @@ 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,
|
||||||
|
@ -264,11 +201,15 @@ 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,
|
||||||
|
@ -293,54 +234,28 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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
|
||||||
|
@ -377,17 +292,6 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@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,59 +336,10 @@ 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
|
||||||
|
@ -498,31 +352,19 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
||||||
@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
|
||||||
|
@ -558,7 +400,7 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
||||||
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(
|
||||||
|
@ -582,8 +424,7 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
||||||
new Function<org.jclouds.vcloud.domain.Catalog, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>() {
|
new Function<org.jclouds.vcloud.domain.Catalog, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, ? extends CatalogItem> apply(
|
public Map<String, ? extends CatalogItem> apply(org.jclouds.vcloud.domain.Catalog from) {
|
||||||
org.jclouds.vcloud.domain.Catalog from) {
|
|
||||||
return uniqueIndex(allCatalogItemsInCatalog.apply(from), name);
|
return uniqueIndex(allCatalogItemsInCatalog.apply(from), name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -596,22 +437,10 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
||||||
@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
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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();
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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))
|
||||||
|
|
|
@ -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());
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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 + ")";
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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,38 +52,79 @@ 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());
|
||||||
|
@ -87,17 +132,22 @@ public abstract class CommonVCloudClientLiveTest<S extends CommonVCloudClient, A
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@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);
|
||||||
|
assertNotNull(net.getName());
|
||||||
|
assertNotNull(net.getHref());
|
||||||
|
assertEquals(
|
||||||
|
connection.findNetworkInOrgVDCNamed(org.getName(), response.getName(), net.getName()), net);
|
||||||
} catch (AuthorizationException e) {
|
} catch (AuthorizationException e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -105,10 +155,33 @@ public abstract class CommonVCloudClientLiveTest<S extends CommonVCloudClient, A
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@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()) {
|
||||||
|
@ -119,6 +192,7 @@ public abstract class CommonVCloudClientLiveTest<S extends CommonVCloudClient, A
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void verifyCatalogItem(CatalogItem item) {
|
protected void verifyCatalogItem(CatalogItem item) {
|
||||||
assertNotNull(item);
|
assertNotNull(item);
|
||||||
|
@ -131,7 +205,7 @@ 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()) {
|
||||||
|
@ -143,10 +217,11 @@ 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);
|
||||||
|
@ -157,19 +232,40 @@ public abstract class CommonVCloudClientLiveTest<S extends CommonVCloudClient, A
|
||||||
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) {
|
||||||
|
org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(org.getName());
|
||||||
assertNotNull(response);
|
assertNotNull(response);
|
||||||
assertNotNull(response.getLocation());
|
assertNotNull(response.getLocation());
|
||||||
assertNotNull(response.getTasks());
|
assertNotNull(response.getTasks());
|
||||||
assertEquals(connection.getTasksList(response.getLocation()).getLocation(), response.getLocation());
|
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) {
|
||||||
|
org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(org.getName());
|
||||||
assertNotNull(response);
|
assertNotNull(response);
|
||||||
assertNotNull(response.getLocation());
|
assertNotNull(response.getLocation());
|
||||||
assertNotNull(response.getTasks());
|
assertNotNull(response.getTasks());
|
||||||
|
@ -178,12 +274,14 @@ public abstract class CommonVCloudClientLiveTest<S extends CommonVCloudClient, A
|
||||||
assertEquals(connection.getTask(task.getHref()).getHref(), task.getHref());
|
assertEquals(connection.getTask(task.getHref()).getHref(), task.getHref());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected String provider = "vcloud";
|
protected String provider = "vcloud";
|
||||||
protected String identity;
|
protected String identity;
|
||||||
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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,12 +44,12 @@ 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
|
||||||
*/
|
*/
|
||||||
|
@ -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.
|
@Inject
|
||||||
// Each VDC will have differnt network subnets. So we cannot assume the default VDC's
|
public IsDMZNetwork(TerremarkECloudClient client) {
|
||||||
// networks will
|
this.client = client;
|
||||||
// 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
|
@Override
|
||||||
public boolean apply(ReferenceType input) {
|
public boolean apply(ReferenceType arg0) {
|
||||||
TerremarkOrgNetwork network = injector.getInstance(TerremarkECloudClient.class).getNetwork(
|
// TODO FIXME XXX: In Terremark Enterprise environment with multiple
|
||||||
input.getHref());
|
// VDC's
|
||||||
TerremarkNetwork terremarkNetwork = injector.getInstance(TerremarkECloudClient.class)
|
// this does not
|
||||||
.getTerremarkNetwork(
|
// work well.
|
||||||
checkNotNull(checkNotNull(network, "network at: " + input).getNetworkExtension(),
|
// Each VDC will have differnt network subnets. So we cannot assume the
|
||||||
"network extension for: " + input).getHref());
|
// default VDC's
|
||||||
return checkNotNull(terremarkNetwork, "terremark network extension at: " + network.getNetworkExtension())
|
// 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;
|
.getNetworkType() == TerremarkNetwork.Type.DMZ;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}).getHref();
|
@Override
|
||||||
} catch (NoSuchElementException e) {
|
protected void installDefaultVCloudEndpointsModule() {
|
||||||
throw new ResourceNotFoundException("no dmz networks in vdc " + vDC.getName() + ": " + networks);
|
install(new DefaultVCloudReferencesModule() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Predicate<ReferenceType> provideDefaultNetworkSelector(Injector i) {
|
||||||
|
return i.getInstance(IsDMZNetwork.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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() {
|
|
||||||
super(null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
protected static final ReferenceTypeImpl CATALOG_REF = new ReferenceTypeImpl("catalog", VCloudMediaType.CATALOG_XML,
|
||||||
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
|
URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"));
|
||||||
return ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> of("org",
|
|
||||||
|
|
||||||
ImmutableMap.<String, org.jclouds.vcloud.domain.VDC> of(
|
protected static final ReferenceTypeImpl TASKSLIST_REF = new ReferenceTypeImpl("tasksList",
|
||||||
"vdc",
|
VCloudMediaType.TASKSLIST_XML, URI.create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1"));
|
||||||
new TerremarkVDCImpl("vdc", null, URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"),
|
|
||||||
VDCStatus.READY, null, "description", ImmutableSet.<Task> of(), AllocationModel.UNRECOGNIZED,
|
protected static final ReferenceTypeImpl VDC_REF = new ReferenceTypeImpl("vdc", VCloudMediaType.VDC_XML,
|
||||||
new Capacity("MB", 0, 0, 0, 0), new Capacity("MB", 0, 0, 0, 0), new Capacity("MB", 0, 0, 0, 0),
|
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"));
|
||||||
ImmutableMap.<String, ReferenceType> of(
|
|
||||||
|
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",
|
"vapp",
|
||||||
new ReferenceTypeImpl("vapp", "application/vnd.vmware.vcloud.vApp+xml", URI
|
new ReferenceTypeImpl("vapp", "application/vnd.vmware.vcloud.vApp+xml", URI
|
||||||
.create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1")),
|
.create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1")),
|
||||||
"network",
|
"network",
|
||||||
new ReferenceTypeImpl("network", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
|
new ReferenceTypeImpl("network", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
|
||||||
.create("https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2"))), ImmutableMap
|
.create("https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2"))),
|
||||||
.<String, ReferenceType> of(), 0, 0, 0, false, new ReferenceTypeImpl("catalog",
|
ImmutableMap.<String, ReferenceType> of(NETWORK_REF.getName(), NETWORK_REF), 0, 0, 0, false, CATALOG_REF,
|
||||||
TerremarkVCloudMediaType.CATALOG_XML, URI
|
PUBLICIPS_REF, INTERNETSERVICES_REF);
|
||||||
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1")),
|
|
||||||
new ReferenceTypeImpl("publicIps", TerremarkVCloudMediaType.PUBLICIPSLIST_XML, URI
|
@RequiresHttp
|
||||||
.create("https://vcloud.safesecureweb.com/api/v0.8/publicIps/1")), new ReferenceTypeImpl(
|
@ConfiguresRestClient
|
||||||
"internetServices", TerremarkVCloudMediaType.INTERNETSERVICESLIST_XML, URI
|
protected static class TerremarkECloudRestClientModuleExtension extends TerremarkECloudRestClientModule {
|
||||||
.create("https://vcloud.safesecureweb.com/api/v0.8/internetServices/1")))));
|
|
||||||
|
@Override
|
||||||
|
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService, String version) {
|
||||||
|
return URI.create("https://vcloud.safesecureweb.com/api/v0.8/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
|
||||||
|
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()))));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -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());
|
||||||
|
|
|
@ -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());
|
||||||
|
|
|
@ -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,18 +58,24 @@ 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>>() {
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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";
|
||||||
|
|
|
@ -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()) {
|
||||||
|
|
|
@ -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";
|
||||||
|
|
|
@ -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
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
super.configure();
|
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.Org.class).toInstance(ORG_REF);
|
||||||
bind(OrgNameToKeysListSupplier.class).to(TestOrgNameToKeysListSupplier.class);
|
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.Catalog.class).toInstance(
|
||||||
bind(OrgMapSupplier.class).to(TestTerremarkOrgMapSupplier.class);
|
CATALOG_REF);
|
||||||
bind(OrgCatalogSupplier.class).to(TestOrgCatalogSupplier.class);
|
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.TasksList.class).toInstance(
|
||||||
bind(OrgCatalogItemSupplier.class).to(TestOrgCatalogItemSupplier.class);
|
TASKSLIST_REF);
|
||||||
bind(OrgVDCSupplier.class).to(TestTerremarkOrgVDCSupplier.class);
|
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
|
@Override
|
||||||
protected URI provideOrg(@org.jclouds.vcloud.endpoints.Org Iterable<ReferenceType> orgs) {
|
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||||
return URI.create("https://vcloud.safesecureweb.com/api/v0.8/org/1");
|
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
|
@Override
|
||||||
protected String provideOrgName(@org.jclouds.vcloud.endpoints.Org Iterable<ReferenceType> orgs) {
|
public String getVCloudToken() {
|
||||||
return "org";
|
return "token";
|
||||||
}
|
|
||||||
|
|
||||||
@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
|
|
||||||
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(), TerremarkVCloudExpressMediaType.KEYSLIST_XML, URI
|
|
||||||
.create(from.getHref().toASCIIString() + "/keysList"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Singleton
|
||||||
public static class TestTerremarkOrgMapSupplier extends OrgMapSupplier {
|
public static class TestOrgMapSupplier extends OrgMapSupplier {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected TestTerremarkOrgMapSupplier() {
|
protected TestOrgMapSupplier() {
|
||||||
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")))));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public static class TestOrgCatalogItemSupplier extends OrgCatalogItemSupplier {
|
||||||
|
protected TestOrgCatalogItemSupplier() {
|
||||||
|
super(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected URI provideDefaultTasksList(Org org) {
|
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
|
||||||
return URI.create("https://taskslist");
|
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");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -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,7 +63,6 @@ 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());
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()) {
|
||||||
|
|
Loading…
Reference in New Issue