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.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.vcloud.VCloudClient;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.domain.VAppTemplate;
|
||||
import org.jclouds.vcloud.domain.Vm;
|
||||
import org.jclouds.vcloud.domain.network.FenceMode;
|
||||
|
@ -70,7 +71,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
|
|||
protected final String ns;
|
||||
protected final String schema;
|
||||
protected final BindToStringPayload stringBinder;
|
||||
protected final URI defaultNetwork;
|
||||
protected final ReferenceType defaultNetwork;
|
||||
protected final FenceMode defaultFenceMode;
|
||||
protected final DefaultNetworkNameInTemplate defaultNetworkNameInTemplate;
|
||||
protected final VCloudClient client;
|
||||
|
@ -78,7 +79,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
|
|||
@Inject
|
||||
public BindInstantiateVAppTemplateParamsToXmlPayload(DefaultNetworkNameInTemplate defaultNetworkNameInTemplate,
|
||||
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) {
|
||||
this.defaultNetworkNameInTemplate = defaultNetworkNameInTemplate;
|
||||
this.ns = ns;
|
||||
|
@ -104,8 +105,8 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
|
|||
|
||||
Set<? extends NetworkConfig> networkConfig = null;
|
||||
|
||||
NetworkConfigDecorator networknetworkConfigDecorator = new NetworkConfigDecorator(template, defaultNetwork,
|
||||
defaultFenceMode, defaultNetworkNameInTemplate);
|
||||
NetworkConfigDecorator networknetworkConfigDecorator = new NetworkConfigDecorator(template,
|
||||
defaultNetwork.getHref(), defaultFenceMode, defaultNetworkNameInTemplate);
|
||||
|
||||
InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest);
|
||||
|
||||
|
|
|
@ -23,21 +23,21 @@ import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
|||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.cim.xml.ResourceAllocationSettingDataHandler;
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.rest.AsyncClientFactory;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
import org.jclouds.vcloud.VCloudAsyncClient;
|
||||
import org.jclouds.vcloud.VCloudClient;
|
||||
import org.jclouds.vcloud.VCloudLoginAsyncClient;
|
||||
import org.jclouds.vcloud.domain.CatalogItem;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.domain.VAppTemplate;
|
||||
import org.jclouds.vcloud.domain.VCloudSession;
|
||||
import org.jclouds.vcloud.functions.VAppTemplatesForCatalogItems;
|
||||
|
@ -49,47 +49,31 @@ import com.google.inject.Provides;
|
|||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Configures the VCloud authentication service connection, including logging and http transport.
|
||||
* Configures the VCloud authentication service connection, including logging
|
||||
* and http transport.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequiresHttp
|
||||
@ConfiguresRestClient
|
||||
public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A extends VCloudAsyncClient> extends
|
||||
CommonVCloudRestClientModule<S, A> {
|
||||
CommonVCloudRestClientModule<S, A> {
|
||||
|
||||
public BaseVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
|
||||
super(syncClientType, asyncClientType);
|
||||
}
|
||||
|
||||
public BaseVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType,
|
||||
Map<Class<?>, Class<?>> delegateMap) {
|
||||
Map<Class<?>, Class<?>> 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
|
||||
protected void configure() {
|
||||
bind(new TypeLiteral<Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>>>() {
|
||||
}).to(new TypeLiteral<VAppTemplatesForCatalogItems>() {
|
||||
});
|
||||
bind(ResourceAllocationSettingDataHandler.class).to(VCloudResourceAllocationSettingDataHandler.class);
|
||||
bind(WriteableCatalog.class).to(VCloudWritableCatalog.class);
|
||||
super.configure();
|
||||
}
|
||||
|
||||
|
@ -102,21 +86,21 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
|
|||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
final VCloudLoginAsyncClient login) {
|
||||
AtomicReference<AuthorizationException> authException, final VCloudLoginAsyncClient login) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<VCloudSession>(authException, seconds,
|
||||
new Supplier<VCloudSession>() {
|
||||
new Supplier<VCloudSession>() {
|
||||
|
||||
@Override
|
||||
public VCloudSession get() {
|
||||
try {
|
||||
return login.login().get(10, TimeUnit.SECONDS);
|
||||
} catch (Exception e) {
|
||||
propagate(e);
|
||||
assert false : e;
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public VCloudSession get() {
|
||||
try {
|
||||
return login.login().get(10, TimeUnit.SECONDS);
|
||||
} catch (Exception e) {
|
||||
propagate(e);
|
||||
assert false : e;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,14 +18,13 @@
|
|||
*/
|
||||
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.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
@ -33,6 +32,7 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.RestClientTest;
|
||||
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.Task;
|
||||
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.CatalogItemImpl;
|
||||
|
@ -57,7 +58,7 @@ import com.google.common.base.Suppliers;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.AbstractModule;
|
||||
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);
|
||||
}
|
||||
|
||||
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
|
||||
@ConfiguresRestClient
|
||||
public static class VCloudRestClientModuleExtension extends VCloudRestClientModule {
|
||||
|
||||
@Override
|
||||
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService,
|
||||
@Named(PROPERTY_API_VERSION) String version) {
|
||||
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService, String version) {
|
||||
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/login");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected URI provideOrg(@org.jclouds.vcloud.endpoints.Org Iterable<ReferenceType> orgs) {
|
||||
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/org");
|
||||
|
||||
protected Org provideOrg(Supplier<Map<String, ? extends Org>> orgSupplier,
|
||||
@org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) {
|
||||
return ORG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String provideOrgName(@org.jclouds.vcloud.endpoints.Org Iterable<ReferenceType> orgs) {
|
||||
return "org";
|
||||
}
|
||||
protected void installDefaultVCloudEndpointsModule() {
|
||||
install(new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected URI provideCatalog(Org org, @Named(PROPERTY_IDENTITY) String user, WriteableCatalog writableCatalog) {
|
||||
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalog");
|
||||
@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 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
|
||||
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() {
|
||||
|
||||
@Override
|
||||
public Map<String, ReferenceType> getOrgs() {
|
||||
return ImmutableMap.<String, ReferenceType> of("org", new ReferenceTypeImpl("org",
|
||||
VCloudMediaType.ORG_XML, URI.create("https://vcenterprise.bluelock.com/api/v1.0/org/1")));
|
||||
return ImmutableMap.<String, ReferenceType> of(ORG_REF.getName(), ORG_REF);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -168,51 +181,18 @@ public abstract class BaseVCloudAsyncClientTest<T> extends RestClientTest<T> {
|
|||
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, final 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",
|
||||
|
||||
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))));
|
||||
|
||||
@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);
|
||||
|
@ -220,19 +200,7 @@ public abstract class BaseVCloudAsyncClientTest<T> extends RestClientTest<T> {
|
|||
|
||||
@Override
|
||||
public Map<String, Org> get() {
|
||||
return ImmutableMap.<String, Org> of("org", new OrgImpl("org", null, URI
|
||||
.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()));
|
||||
return ImmutableMap.<String, Org> of(ORG.getName(), ORG);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -245,17 +213,18 @@ public abstract class BaseVCloudAsyncClientTest<T> extends RestClientTest<T> {
|
|||
|
||||
@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",
|
||||
|
||||
ImmutableMap.<String, org.jclouds.vcloud.domain.Catalog> of("catalog", new CatalogImpl("catalog", "type",
|
||||
URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"), null, "description",
|
||||
ImmutableMap.<String, ReferenceType> of("item", new ReferenceTypeImpl("item",
|
||||
"application/vnd.vmware.vcloud.catalogItem+xml", URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/1")),
|
||||
"template", new ReferenceTypeImpl("template",
|
||||
"application/vnd.vmware.vcloud.vAppTemplate+xml", URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"))),
|
||||
ImmutableList.<Task> of(), true, false)));
|
||||
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://vcenterprise.bluelock.com/api/v1.0/catalogItem/1")),
|
||||
"template",
|
||||
new ReferenceTypeImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml",
|
||||
URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"))),
|
||||
ImmutableList.<Task> of(), true, false)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -267,35 +236,20 @@ public abstract class BaseVCloudAsyncClientTest<T> extends RestClientTest<T> {
|
|||
|
||||
@Override
|
||||
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",
|
||||
ImmutableMap
|
||||
.<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>> of(
|
||||
"catalog",
|
||||
ImmutableMap
|
||||
.<String, org.jclouds.vcloud.domain.CatalogItem> of(
|
||||
"template",
|
||||
new CatalogItemImpl(
|
||||
"template",
|
||||
URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"),
|
||||
"description",
|
||||
new ReferenceTypeImpl(
|
||||
"template",
|
||||
"application/vnd.vmware.vcloud.vAppTemplate+xml",
|
||||
URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2")),
|
||||
ImmutableMap.<String, String> of()))));
|
||||
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://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"), "description",
|
||||
new ReferenceTypeImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml",
|
||||
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2")),
|
||||
ImmutableMap.<String, String> of()))));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Iterable<ReferenceType> provideOrgs(Supplier<VCloudSession> cache, String user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,6 +31,9 @@ import org.jclouds.vcloud.domain.VDC;
|
|||
import org.jclouds.vcloud.domain.Vm;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Tests behavior of deprecated {@code VCloudClient} features
|
||||
*
|
||||
|
@ -40,30 +43,43 @@ import org.testng.annotations.Test;
|
|||
@Test(groups = "live", singleThreaded = true)
|
||||
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
|
||||
public void testListOrgs() throws Exception {
|
||||
for (ReferenceType response : connection.listOrgs().values()) {
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getName());
|
||||
assertNotNull(response.getHref());
|
||||
assertEquals(connection.getOrg(response.getHref()).getName(), response.getName());
|
||||
assertEquals(connection.findOrgNamed(response.getName()).getName(), response.getName());
|
||||
for (Org org : orgs) {
|
||||
assertNotNull(org);
|
||||
assertNotNull(org.getName());
|
||||
assertNotNull(org.getHref());
|
||||
assertEquals(connection.getOrg(org.getHref()).getName(), org.getName());
|
||||
assertEquals(connection.findOrgNamed(org.getName()).getName(), org.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetVAppTemplate() throws Exception {
|
||||
Org org = connection.findOrgNamed(null);
|
||||
for (ReferenceType cat : org.getCatalogs().values()) {
|
||||
Catalog response = connection.getCatalog(cat.getHref());
|
||||
for (ReferenceType resource : response.values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
|
||||
CatalogItem item = connection.getCatalogItem(resource.getHref());
|
||||
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
|
||||
try {
|
||||
assertNotNull(connection.getVAppTemplate(item.getEntity().getHref()));
|
||||
} catch (AuthorizationException e) {
|
||||
for (Org org : orgs) {
|
||||
for (ReferenceType cat : org.getCatalogs().values()) {
|
||||
Catalog response = connection.getCatalog(cat.getHref());
|
||||
for (ReferenceType resource : response.values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
|
||||
CatalogItem item = connection.getCatalogItem(resource.getHref());
|
||||
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
|
||||
try {
|
||||
assertNotNull(connection.getVAppTemplate(item.getEntity().getHref()));
|
||||
} catch (AuthorizationException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,96 +89,16 @@ public class DeprecatedVCloudClientLiveTest extends CommonVCloudClientLiveTest<V
|
|||
|
||||
@Test
|
||||
public void testGetOvfEnvelopeForVAppTemplate() throws Exception {
|
||||
Org org = connection.findOrgNamed(null);
|
||||
for (ReferenceType cat : org.getCatalogs().values()) {
|
||||
Catalog response = connection.getCatalog(cat.getHref());
|
||||
for (ReferenceType resource : response.values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
|
||||
try {
|
||||
CatalogItem item = connection.getCatalogItem(resource.getHref());
|
||||
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
|
||||
assertNotNull(connection.getOvfEnvelopeForVAppTemplate(item.getEntity().getHref()));
|
||||
}
|
||||
} catch (AuthorizationException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetVApp() throws Exception {
|
||||
Org org = connection.findOrgNamed(null);
|
||||
for (ReferenceType vdc : org.getVDCs().values()) {
|
||||
VDC response = connection.getVDC(vdc.getHref());
|
||||
for (ReferenceType item : response.getResourceEntities().values()) {
|
||||
if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
|
||||
try {
|
||||
VApp app = connection.getVApp(item.getHref());
|
||||
assertNotNull(app);
|
||||
} catch (RuntimeException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetThumbnailOfVm() throws Exception {
|
||||
Org org = connection.findOrgNamed(null);
|
||||
for (ReferenceType vdc : org.getVDCs().values()) {
|
||||
VDC response = connection.getVDC(vdc.getHref());
|
||||
for (ReferenceType item : response.getResourceEntities().values()) {
|
||||
if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
|
||||
try {
|
||||
VApp app = connection.getVApp(item.getHref());
|
||||
assertNotNull(app);
|
||||
for (Vm vm : app.getChildren()) {
|
||||
assert connection.getThumbnailOfVm(vm.getHref()) != null;
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetVm() throws Exception {
|
||||
Org org = connection.findOrgNamed(null);
|
||||
for (ReferenceType vdc : org.getVDCs().values()) {
|
||||
VDC response = connection.getVDC(vdc.getHref());
|
||||
for (ReferenceType item : response.getResourceEntities().values()) {
|
||||
if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
|
||||
try {
|
||||
VApp app = connection.getVApp(item.getHref());
|
||||
assertNotNull(app);
|
||||
for (Vm vm : app.getChildren()) {
|
||||
// assertEquals(connection.getVm(vm.getHref()), vm);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindVAppTemplate() throws Exception {
|
||||
Org org = connection.findOrgNamed(null);
|
||||
for (ReferenceType cat : org.getCatalogs().values()) {
|
||||
Catalog response = connection.getCatalog(cat.getHref());
|
||||
for (ReferenceType resource : response.values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
|
||||
CatalogItem item = connection.getCatalogItem(resource.getHref());
|
||||
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
|
||||
for (Org org : orgs) {
|
||||
for (ReferenceType cat : org.getCatalogs().values()) {
|
||||
Catalog response = connection.getCatalog(cat.getHref());
|
||||
for (ReferenceType resource : response.values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
|
||||
try {
|
||||
assertNotNull(connection.findVAppTemplateInOrgCatalogNamed(org.getName(), response.getName(), item
|
||||
.getEntity().getName()));
|
||||
CatalogItem item = connection.getCatalogItem(resource.getHref());
|
||||
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
|
||||
assertNotNull(connection.getOvfEnvelopeForVAppTemplate(item.getEntity().getHref()));
|
||||
}
|
||||
} catch (AuthorizationException e) {
|
||||
|
||||
}
|
||||
|
@ -171,4 +107,88 @@ public class DeprecatedVCloudClientLiveTest extends CommonVCloudClientLiveTest<V
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetVApp() throws Exception {
|
||||
for (Org org : orgs) {
|
||||
for (ReferenceType vdc : org.getVDCs().values()) {
|
||||
VDC response = connection.getVDC(vdc.getHref());
|
||||
for (ReferenceType item : response.getResourceEntities().values()) {
|
||||
if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
|
||||
try {
|
||||
VApp app = connection.getVApp(item.getHref());
|
||||
assertNotNull(app);
|
||||
} catch (RuntimeException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetThumbnailOfVm() throws Exception {
|
||||
for (Org org : orgs) {
|
||||
for (ReferenceType vdc : org.getVDCs().values()) {
|
||||
VDC response = connection.getVDC(vdc.getHref());
|
||||
for (ReferenceType item : response.getResourceEntities().values()) {
|
||||
if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
|
||||
try {
|
||||
VApp app = connection.getVApp(item.getHref());
|
||||
assertNotNull(app);
|
||||
for (Vm vm : app.getChildren()) {
|
||||
assert connection.getThumbnailOfVm(vm.getHref()) != null;
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetVm() throws Exception {
|
||||
for (Org org : orgs) {
|
||||
for (ReferenceType vdc : org.getVDCs().values()) {
|
||||
VDC response = connection.getVDC(vdc.getHref());
|
||||
for (ReferenceType item : response.getResourceEntities().values()) {
|
||||
if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
|
||||
try {
|
||||
VApp app = connection.getVApp(item.getHref());
|
||||
assertNotNull(app);
|
||||
assert app.getChildren().size() > 0;
|
||||
} catch (RuntimeException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindVAppTemplate() throws Exception {
|
||||
for (Org org : orgs) {
|
||||
for (ReferenceType cat : org.getCatalogs().values()) {
|
||||
Catalog response = connection.getCatalog(cat.getHref());
|
||||
for (ReferenceType resource : response.values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
|
||||
CatalogItem item = connection.getCatalogItem(resource.getHref());
|
||||
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
|
||||
try {
|
||||
assertNotNull(connection.findVAppTemplateInOrgCatalogNamed(org.getName(), response.getName(),
|
||||
item.getEntity().getName()));
|
||||
} catch (AuthorizationException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,7 +37,9 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
|
|||
import org.jclouds.util.Strings2;
|
||||
import org.jclouds.vcloud.VCloudClient;
|
||||
import org.jclouds.vcloud.VCloudPropertiesBuilder;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
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.NetworkConfig;
|
||||
import org.jclouds.vcloud.domain.ovf.VCloudNetworkSection;
|
||||
|
@ -84,8 +86,8 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
|
|||
@Network
|
||||
@Provides
|
||||
@Singleton
|
||||
URI provideNetwork() {
|
||||
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1990");
|
||||
ReferenceType provideNetwork() {
|
||||
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 java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
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.BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload;
|
||||
import org.jclouds.vcloud.domain.Catalog;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
import org.jclouds.vcloud.domain.VCloudExpressVApp;
|
||||
import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate;
|
||||
import org.jclouds.vcloud.domain.network.OrgNetwork;
|
||||
import org.jclouds.vcloud.endpoints.Org;
|
||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
||||
import org.jclouds.vcloud.functions.OrgNameAndCatalogNameToEndpoint;
|
||||
import org.jclouds.vcloud.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint;
|
||||
|
@ -65,6 +68,7 @@ import org.jclouds.vcloud.xml.VCloudExpressVAppHandler;
|
|||
import org.jclouds.vcloud.xml.VCloudExpressVAppTemplateHandler;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* Provides access to VCloud resources via their REST API.
|
||||
|
@ -75,6 +79,13 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
*/
|
||||
@RequestFilters(SetVCloudTokenCookie.class)
|
||||
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
|
||||
|
|
|
@ -19,12 +19,14 @@
|
|||
package org.jclouds.vcloud;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
import org.jclouds.vcloud.domain.VCloudExpressVApp;
|
||||
import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate;
|
||||
|
@ -40,6 +42,11 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
|||
*/
|
||||
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
|
||||
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,
|
||||
InstantiateVAppTemplateOptions... options);
|
||||
|
|
|
@ -44,6 +44,7 @@ import org.jclouds.http.HttpRequest;
|
|||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.rest.binders.BindToStringPayload;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.domain.network.NetworkConfig;
|
||||
import org.jclouds.vcloud.endpoints.Network;
|
||||
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
||||
|
@ -67,14 +68,14 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload implemen
|
|||
private final BindToStringPayload stringBinder;
|
||||
protected final Map<ResourceType, String> virtualHardwareToInstanceId = ImmutableMap.of(ResourceType.PROCESSOR, "1",
|
||||
ResourceType.MEMORY, "2", ResourceType.DISK_DRIVE, "9");
|
||||
private final URI defaultNetwork;
|
||||
private final ReferenceType defaultNetwork;
|
||||
private final String defaultFenceMode;
|
||||
private final String apiVersion;
|
||||
|
||||
@Inject
|
||||
public BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder,
|
||||
@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) {
|
||||
this.ns = ns;
|
||||
this.apiVersion = apiVersion;
|
||||
|
@ -96,7 +97,7 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload implemen
|
|||
SortedMap<ResourceType, String> virtualHardwareQuantity = Maps.newTreeMap();
|
||||
|
||||
InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest);
|
||||
String network = (defaultNetwork != null) ? defaultNetwork.toASCIIString() : null;
|
||||
String network = (defaultNetwork != null) ? defaultNetwork.getHref().toASCIIString() : null;
|
||||
String fenceMode = defaultFenceMode;
|
||||
String networkName = name;
|
||||
if (options != null) {
|
||||
|
|
|
@ -34,6 +34,8 @@ import org.jclouds.compute.domain.Image;
|
|||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||
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.vcloud.compute.VCloudExpressComputeClient;
|
||||
import org.jclouds.vcloud.domain.Status;
|
||||
|
@ -57,9 +59,9 @@ public class VCloudExpressVAppToNodeMetadata implements Function<VCloudExpressVA
|
|||
|
||||
@Inject
|
||||
protected VCloudExpressVAppToNodeMetadata(VCloudExpressComputeClient computeClient,
|
||||
Map<String, Credentials> credentialStore, Map<Status, NodeState> vAppStatusToNodeState,
|
||||
HardwareForVCloudExpressVApp hardwareForVCloudExpressVApp,
|
||||
FindLocationForResource findLocationForResourceInVDC, @Memoized Supplier<Set<? extends Image>> images) {
|
||||
Map<String, Credentials> credentialStore, Map<Status, NodeState> vAppStatusToNodeState,
|
||||
HardwareForVCloudExpressVApp hardwareForVCloudExpressVApp,
|
||||
FindLocationForResource findLocationForResourceInVDC, @Memoized Supplier<Set<? extends Image>> images) {
|
||||
this.images = checkNotNull(images, "images");
|
||||
this.hardwareForVCloudExpressVApp = checkNotNull(hardwareForVCloudExpressVApp, "hardwareForVCloudExpressVApp");
|
||||
this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC");
|
||||
|
@ -76,8 +78,19 @@ public class VCloudExpressVAppToNodeMetadata implements Function<VCloudExpressVA
|
|||
builder.name(from.getName());
|
||||
builder.location(findLocationForResourceInVDC.apply(from.getVDC()));
|
||||
builder.group(parseGroupFromName(from.getName()));
|
||||
builder.operatingSystem(from.getOsType() != null ? new CIMOperatingSystem(OSType
|
||||
.fromValue(from.getOsType()), null, null, from.getOperatingSystemDescription()) : null);
|
||||
if (from.getOsType() != null && OSType.fromValue(from.getOsType()) != OSType.UNRECOGNIZED) {
|
||||
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.state(vAppStatusToNodeState.get(from.getStatus()));
|
||||
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.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.rest.AsyncClientFactory;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
import org.jclouds.vcloud.VCloudExpressAsyncClient;
|
||||
import org.jclouds.vcloud.VCloudExpressClient;
|
||||
import org.jclouds.vcloud.VCloudExpressLoginAsyncClient;
|
||||
import org.jclouds.vcloud.domain.CatalogItem;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate;
|
||||
import org.jclouds.vcloud.domain.VCloudSession;
|
||||
import org.jclouds.vcloud.endpoints.Org;
|
||||
import org.jclouds.vcloud.functions.VCloudExpressVAppTemplatesForCatalogItems;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
@ -59,6 +63,16 @@ public abstract class BaseVCloudExpressRestClientModule<S extends VCloudExpressC
|
|||
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,
|
||||
Map<Class<?>, Class<?>> delegateMap) {
|
||||
super(syncClientType, asyncClientType, delegateMap);
|
||||
|
@ -81,7 +95,7 @@ public abstract class BaseVCloudExpressRestClientModule<S extends VCloudExpressC
|
|||
@Provides
|
||||
@Singleton
|
||||
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,
|
||||
new Supplier<VCloudSession>() {
|
||||
|
||||
|
|
|
@ -51,9 +51,6 @@ public class VCloudExpressVAppImpl implements VCloudExpressVApp {
|
|||
private final Set<ResourceAllocationSettingData> resourceAllocations;
|
||||
private final Integer osType;
|
||||
|
||||
/** The serialVersionUID */
|
||||
private static final long serialVersionUID = 8464716396538298809L;
|
||||
|
||||
public VCloudExpressVAppImpl(String name, URI href, Status status, Long size, ReferenceType vDC,
|
||||
ListMultimap<String, String> networkToAddresses, Integer osType, String operatingSystemDescription,
|
||||
VirtualSystemSettingData system, Set<ResourceAllocationSettingData> resourceAllocations) {
|
||||
|
|
|
@ -33,8 +33,6 @@ import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate;
|
|||
*/
|
||||
public class VCloudExpressVAppTemplateImpl extends ReferenceTypeImpl implements VCloudExpressVAppTemplate {
|
||||
|
||||
/** The serialVersionUID */
|
||||
private static final long serialVersionUID = 8464716396538298809L;
|
||||
private final String description;
|
||||
private final Status status;
|
||||
|
||||
|
|
|
@ -40,8 +40,6 @@ import com.google.common.collect.Sets;
|
|||
*/
|
||||
public class VCloudExpressNetworkImpl extends ReferenceTypeImpl implements VCloudExpressNetwork {
|
||||
|
||||
/** The serialVersionUID */
|
||||
private static final long serialVersionUID = 8464716396538298809L;
|
||||
protected final String description;
|
||||
protected final Set<String> dnsServers = Sets.newHashSet();
|
||||
protected final String gateway;
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
*/
|
||||
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.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
@ -30,6 +28,7 @@ import java.net.URI;
|
|||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
@ -39,6 +38,7 @@ import org.jclouds.http.HttpRequest;
|
|||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.RestClientTest;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
|
@ -47,10 +47,13 @@ import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
|||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.jclouds.vcloud.config.VCloudExpressRestClientModule;
|
||||
import org.jclouds.vcloud.domain.AllocationModel;
|
||||
import org.jclouds.vcloud.domain.Org;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
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.CatalogItemImpl;
|
||||
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.options.CloneVAppOptions;
|
||||
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
||||
import org.jclouds.vcloud.xml.VCloudExpressCatalogHandler;
|
||||
import org.jclouds.vcloud.xml.CatalogItemHandler;
|
||||
import org.jclouds.vcloud.xml.OrgHandler;
|
||||
import org.jclouds.vcloud.xml.OrgNetworkFromVCloudExpressNetworkHandler;
|
||||
import org.jclouds.vcloud.xml.TaskHandler;
|
||||
import org.jclouds.vcloud.xml.TasksListHandler;
|
||||
import org.jclouds.vcloud.xml.VCloudExpressCatalogHandler;
|
||||
import org.jclouds.vcloud.xml.VCloudExpressVAppHandler;
|
||||
import org.jclouds.vcloud.xml.VCloudExpressVAppTemplateHandler;
|
||||
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.collect.ImmutableList;
|
||||
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.TypeLiteral;
|
||||
|
||||
|
@ -86,10 +90,16 @@ import com.google.inject.TypeLiteral;
|
|||
*
|
||||
* @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")
|
||||
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 {
|
||||
Method method = VCloudExpressAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class,
|
||||
String.class, InstantiateVAppTemplateOptions[].class);
|
||||
|
@ -323,6 +333,21 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
|
|||
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 {
|
||||
Method method = VCloudExpressAsyncClient.class.getMethod("getVAppTemplate", URI.class);
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
|
@ -658,71 +683,79 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
|
|||
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
|
||||
@ConfiguresRestClient
|
||||
public static class VCloudRestClientModuleExtension extends VCloudExpressRestClientModule {
|
||||
|
||||
@Override
|
||||
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService,
|
||||
@Named(PROPERTY_API_VERSION) String version) {
|
||||
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService, String version) {
|
||||
return URI.create("https://vcloud.safesecureweb.com/api/v0.8/login");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected URI provideOrg(@org.jclouds.vcloud.endpoints.Org Iterable<ReferenceType> orgs) {
|
||||
return URI.create("https://vcloud.safesecureweb.com/api/v0.8/org");
|
||||
|
||||
protected Org provideOrg(Supplier<Map<String, ? extends Org>> orgSupplier,
|
||||
@org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) {
|
||||
return ORG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String provideOrgName(@org.jclouds.vcloud.endpoints.Org Iterable<ReferenceType> orgs) {
|
||||
return "org";
|
||||
}
|
||||
protected void installDefaultVCloudEndpointsModule() {
|
||||
install(new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected URI provideCatalog(Org org, @Named(PROPERTY_IDENTITY) String user, WriteableCatalog write) {
|
||||
return URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalog");
|
||||
}
|
||||
@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 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
|
||||
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
final VCloudExpressLoginAsyncClient login) {
|
||||
AtomicReference<AuthorizationException> authException, VCloudExpressLoginAsyncClient login) {
|
||||
return Suppliers.<VCloudSession> ofInstance(new VCloudSession() {
|
||||
|
||||
@Override
|
||||
public Map<String, ReferenceType> getOrgs() {
|
||||
return ImmutableMap.<String, ReferenceType> of("org", new ReferenceTypeImpl("org",
|
||||
VCloudExpressMediaType.ORG_XML, URI.create("https://vcloud.safesecureweb.com/api/v0.8/org/1")));
|
||||
return ImmutableMap.<String, ReferenceType> of(ORG_REF.getName(), ORG_REF);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -744,26 +777,14 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
|
|||
|
||||
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> provideOrgVDCSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final 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",
|
||||
|
||||
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))));
|
||||
|
||||
.<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);
|
||||
|
@ -771,21 +792,7 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
|
|||
|
||||
@Override
|
||||
public Map<String, Org> get() {
|
||||
return ImmutableMap.<String, Org> of(
|
||||
"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()));
|
||||
return ImmutableMap.<String, Org> of(ORG.getName(), ORG);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -798,19 +805,18 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
|
|||
|
||||
@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",
|
||||
|
||||
ImmutableMap.<String, org.jclouds.vcloud.domain.Catalog> of(
|
||||
"catalog",
|
||||
new CatalogImpl("catalog", "type", URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"),
|
||||
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)));
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -823,8 +829,9 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
|
|||
@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", ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>> of(
|
||||
"catalog", ImmutableMap.<String, 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",
|
||||
|
|
|
@ -28,25 +28,41 @@ import org.jclouds.vcloud.domain.VCloudExpressVApp;
|
|||
import org.jclouds.vcloud.domain.VDC;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code VCloudExpressClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true)
|
||||
@Test(groups = "live", singleThreaded = true)
|
||||
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
|
||||
public void testGetVAppTemplate() throws Exception {
|
||||
Org org = connection.findOrgNamed(null);
|
||||
for (ReferenceType cat : org.getCatalogs().values()) {
|
||||
Catalog response = connection.getCatalog(cat.getHref());
|
||||
for (ReferenceType resource : response.values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
|
||||
CatalogItem item = connection.getCatalogItem(resource.getHref());
|
||||
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
|
||||
assertNotNull(connection.getVAppTemplate(item.getEntity().getHref()));
|
||||
for (Org org : orgs) {
|
||||
for (ReferenceType cat : org.getCatalogs().values()) {
|
||||
Catalog response = connection.getCatalog(cat.getHref());
|
||||
for (ReferenceType resource : response.values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
|
||||
CatalogItem item = connection.getCatalogItem(resource.getHref());
|
||||
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
|
||||
assertNotNull(connection.getVAppTemplate(item.getEntity().getHref()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,16 +71,17 @@ public abstract class VCloudExpressClientLiveTest extends
|
|||
|
||||
@Test
|
||||
public void testGetVApp() throws Exception {
|
||||
Org org = connection.findOrgNamed(null);
|
||||
for (ReferenceType vdc : org.getVDCs().values()) {
|
||||
VDC response = connection.getVDC(vdc.getHref());
|
||||
for (ReferenceType item : response.getResourceEntities().values()) {
|
||||
if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
|
||||
try {
|
||||
VCloudExpressVApp app = connection.getVApp(item.getHref());
|
||||
assertNotNull(app);
|
||||
} catch (RuntimeException e) {
|
||||
for (Org org : listOrgs()) {
|
||||
for (ReferenceType vdc : org.getVDCs().values()) {
|
||||
VDC response = connection.getVDC(vdc.getHref());
|
||||
for (ReferenceType item : response.getResourceEntities().values()) {
|
||||
if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
|
||||
try {
|
||||
VCloudExpressVApp app = connection.getVApp(item.getHref());
|
||||
assertNotNull(app);
|
||||
} catch (RuntimeException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,15 +90,16 @@ public abstract class VCloudExpressClientLiveTest extends
|
|||
|
||||
@Test
|
||||
public void testFindVAppTemplate() throws Exception {
|
||||
Org org = connection.findOrgNamed(null);
|
||||
for (ReferenceType cat : org.getCatalogs().values()) {
|
||||
Catalog response = connection.getCatalog(cat.getHref());
|
||||
for (ReferenceType resource : response.values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
|
||||
CatalogItem item = connection.getCatalogItem(resource.getHref());
|
||||
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
|
||||
assertNotNull(connection.findVAppTemplateInOrgCatalogNamed(org.getName(), response.getName(), item
|
||||
for (Org org : listOrgs()) {
|
||||
for (ReferenceType cat : org.getCatalogs().values()) {
|
||||
Catalog response = connection.getCatalog(cat.getHref());
|
||||
for (ReferenceType resource : response.values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
|
||||
CatalogItem item = connection.getCatalogItem(resource.getHref());
|
||||
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
|
||||
assertNotNull(connection.findVAppTemplateInOrgCatalogNamed(org.getName(), response.getName(), item
|
||||
.getEntity().getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ import javax.inject.Singleton;
|
|||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.util.Strings2;
|
||||
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.endpoints.Network;
|
||||
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
||||
|
@ -66,8 +68,8 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayloadTest {
|
|||
@Network
|
||||
@Provides
|
||||
@Singleton
|
||||
URI provideNetwork() {
|
||||
return URI.create("https://vcloud.safesecureweb.com/network/1990");
|
||||
ReferenceType provideNetwork() {
|
||||
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.VCloudExpressClient;
|
||||
import org.jclouds.vcloud.domain.Catalog;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
import org.jclouds.vcloud.domain.VCloudExpressVApp;
|
||||
import org.jclouds.vcloud.domain.VDC;
|
||||
import org.jclouds.vcloud.endpoints.Org;
|
||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
||||
import org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint;
|
||||
import org.jclouds.vcloud.functions.OrgNameCatalogNameItemNameToEndpoint;
|
||||
|
@ -98,7 +96,6 @@ import org.jclouds.vcloud.xml.VCloudExpressCatalogHandler;
|
|||
import org.jclouds.vcloud.xml.VCloudExpressVAppHandler;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* Provides access to VCloud resources via their REST API.
|
||||
|
@ -109,13 +106,6 @@ import com.google.inject.Provides;
|
|||
*/
|
||||
@RequestFilters(SetVCloudTokenCookie.class)
|
||||
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
|
||||
|
|
|
@ -26,10 +26,8 @@ import javax.annotation.Nullable;
|
|||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.vcloud.VCloudExpressClient;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
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.InternetService;
|
||||
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.AddNodeOptions;
|
||||
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* Provides access to VCloud resources via their REST API.
|
||||
* <p/>
|
||||
|
@ -54,13 +50,6 @@ import com.google.inject.Provides;
|
|||
*/
|
||||
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
|
||||
public interface TerremarkVCloudClient extends VCloudExpressClient {
|
||||
/**
|
||||
*
|
||||
* @return a listing of all orgs that the current user has access to.
|
||||
*/
|
||||
@Provides
|
||||
@Org
|
||||
Iterable<ReferenceType> listOrgs();
|
||||
|
||||
/**
|
||||
* {@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_SCHEMA;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.SortedMap;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
|
@ -37,6 +36,7 @@ import org.jclouds.cim.ResourceAllocationSettingData.ResourceType;
|
|||
import org.jclouds.rest.binders.BindToStringPayload;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.vcloud.binders.BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.endpoints.Network;
|
||||
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
||||
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
|
||||
|
@ -55,7 +55,7 @@ public class TerremarkBindInstantiateVAppTemplateParamsToXmlPayload extends
|
|||
@Inject
|
||||
public TerremarkBindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder,
|
||||
@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) {
|
||||
super(stringBinder, apiVersion, ns, schema, network, fenceMode);
|
||||
}
|
||||
|
|
|
@ -17,10 +17,12 @@
|
|||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.terremark.config;
|
||||
|
||||
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
@ -30,6 +32,7 @@ import org.jclouds.http.HttpErrorHandler;
|
|||
import org.jclouds.http.annotation.ClientError;
|
||||
import org.jclouds.http.annotation.Redirection;
|
||||
import org.jclouds.http.annotation.ServerError;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.jclouds.vcloud.config.BaseVCloudExpressRestClientModule;
|
||||
|
@ -46,7 +49,7 @@ import com.google.common.collect.Maps;
|
|||
import com.google.inject.Provides;
|
||||
|
||||
public abstract class TerremarkRestClientModule<S extends TerremarkVCloudClient, A extends TerremarkVCloudAsyncClient>
|
||||
extends BaseVCloudExpressRestClientModule<S, A> {
|
||||
extends BaseVCloudExpressRestClientModule<S, A> {
|
||||
|
||||
public TerremarkRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
|
||||
super(syncClientType, asyncClientType);
|
||||
|
@ -61,26 +64,21 @@ public abstract class TerremarkRestClientModule<S extends TerremarkVCloudClient,
|
|||
@Provides
|
||||
@Named("CreateInternetService")
|
||||
String provideCreateInternetService() throws IOException {
|
||||
return Strings2.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/CreateInternetService.xml"));
|
||||
return Strings2.toStringAndClose(getClass().getResourceAsStream("/terremark/CreateInternetService.xml"));
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
@Named("CreateNodeService")
|
||||
String provideCreateNodeService() throws IOException {
|
||||
return Strings2.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/CreateNodeService.xml"));
|
||||
return Strings2.toStringAndClose(getClass().getResourceAsStream("/terremark/CreateNodeService.xml"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bindErrorHandlers() {
|
||||
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(
|
||||
ParseTerremarkVCloudErrorFromHttpResponse.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(
|
||||
ParseTerremarkVCloudErrorFromHttpResponse.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(
|
||||
ParseTerremarkVCloudErrorFromHttpResponse.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseTerremarkVCloudErrorFromHttpResponse.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseTerremarkVCloudErrorFromHttpResponse.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseTerremarkVCloudErrorFromHttpResponse.class);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
|
@ -111,14 +109,10 @@ public abstract class TerremarkRestClientModule<S extends TerremarkVCloudClient,
|
|||
@Singleton
|
||||
@Keys
|
||||
protected Supplier<Map<String, ReferenceType>> provideOrgToKeysListCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgNameToKeysListSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ReferenceType>>(authException,
|
||||
seconds, new Supplier<Map<String, ReferenceType>>() {
|
||||
@Override
|
||||
public Map<String, ReferenceType> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
});
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
OrgNameToKeysListSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ReferenceType>>(
|
||||
authException, seconds, supplier);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Map;
|
|||
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.jclouds.vcloud.domain.Org;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkOrg;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
@ -36,9 +37,10 @@ import com.google.common.collect.Maps;
|
|||
public abstract class OrgURIToEndpoint implements Function<Object, URI> {
|
||||
|
||||
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.defaultOrg = defaultUri;
|
||||
}
|
||||
|
@ -53,7 +55,7 @@ public abstract class OrgURIToEndpoint implements Function<Object, URI> {
|
|||
|
||||
});
|
||||
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);
|
||||
} catch (NullPointerException e) {
|
||||
throw new ResourceNotFoundException("org " + from + " not found in: " + uriToOrg, e);
|
||||
|
|
|
@ -25,6 +25,7 @@ import javax.inject.Inject;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.vcloud.domain.Org;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkOrg;
|
||||
|
||||
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> {
|
||||
@Inject
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import javax.inject.Inject;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.endpoints.VDC;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
|
||||
|
||||
|
@ -38,19 +39,19 @@ import com.google.common.base.Supplier;
|
|||
@Singleton
|
||||
public class VDCURIToInternetServicesEndpoint implements Function<Object, URI> {
|
||||
private final Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> orgVDCMap;
|
||||
private final URI defaultVDC;
|
||||
private final ReferenceType defaultVDC;
|
||||
|
||||
@Inject
|
||||
public VDCURIToInternetServicesEndpoint(Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> orgVDCMap,
|
||||
@VDC URI defaultVDC) {
|
||||
@VDC ReferenceType defaultVDC) {
|
||||
this.orgVDCMap = orgVDCMap;
|
||||
this.defaultVDC = defaultVDC;
|
||||
}
|
||||
|
||||
public URI apply(Object from) {
|
||||
try {
|
||||
return TerremarkVDC.class.cast(orgVDCMap.get().get(from == null ? defaultVDC : from)).getInternetServices()
|
||||
.getHref();
|
||||
return TerremarkVDC.class.cast(orgVDCMap.get().get(from == null ? defaultVDC.getHref() : from))
|
||||
.getInternetServices().getHref();
|
||||
} catch (NullPointerException e) {
|
||||
throw new ResourceNotFoundException("vdc " + from + " not found in " + orgVDCMap.get());
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import javax.inject.Inject;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.endpoints.VDC;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
|
||||
|
||||
|
@ -38,18 +39,19 @@ import com.google.common.base.Supplier;
|
|||
@Singleton
|
||||
public class VDCURIToPublicIPsEndpoint implements Function<Object, URI> {
|
||||
private final Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> orgVDCMap;
|
||||
private final URI defaultVDC;
|
||||
private final ReferenceType defaultVDC;
|
||||
|
||||
@Inject
|
||||
public VDCURIToPublicIPsEndpoint(Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> orgVDCMap,
|
||||
@VDC URI defaultVDC) {
|
||||
@VDC ReferenceType defaultVDC) {
|
||||
this.orgVDCMap = orgVDCMap;
|
||||
this.defaultVDC = defaultVDC;
|
||||
}
|
||||
|
||||
public URI apply(Object from) {
|
||||
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) {
|
||||
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.VCloudExpressMediaType;
|
||||
import org.jclouds.vcloud.domain.Catalog;
|
||||
import org.jclouds.vcloud.domain.Org;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.domain.Status;
|
||||
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.terremark.domain.CustomizationParameters;
|
||||
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.Protocol;
|
||||
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
|
||||
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.options.AddInternetServiceOptions;
|
||||
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
|
||||
|
@ -101,47 +104,63 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
|
|||
public static final String PREFIX = System.getProperty("user.name") + "-terremark";
|
||||
|
||||
@Test
|
||||
public void testListOrgs() throws Exception {
|
||||
for (ReferenceType org : tmClient.listOrgs()) {
|
||||
assertNotNull(tmClient.getOrg(org.getHref()));
|
||||
public void testKeysList() throws Exception {
|
||||
for (Org oorg : orgs) {
|
||||
TerremarkVCloudClient vCloudExpressClient = TerremarkVCloudClient.class.cast(tmClient);
|
||||
TerremarkOrg org = (TerremarkOrg) oorg;
|
||||
Set<KeyPair> response = vCloudExpressClient.listKeyPairsInOrg(org.getHref());
|
||||
assertNotNull(response);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllInternetServices() throws Exception {
|
||||
for (InternetService service : tmClient.getAllInternetServicesInVDC(tmClient.findVDCInOrgNamed(null, null)
|
||||
.getHref())) {
|
||||
assertNotNull(tmClient.getNodes(service.getId()));
|
||||
for (Org org : orgs) {
|
||||
for (ReferenceType vdc : org.getVDCs().values()) {
|
||||
for (InternetService service : tmClient.getAllInternetServicesInVDC(vdc.getHref())) {
|
||||
assertNotNull(tmClient.getNodes(service.getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateInternetServiceMonitorDisabled() throws Exception {
|
||||
VDC vdc = tmClient.findVDCInOrgNamed(null, null);
|
||||
Set<PublicIpAddress> publicIpAddresses = tmClient.getPublicIpsAssociatedWithVDC(vdc.getHref());
|
||||
PublicIpAddress publicIp = publicIpAddresses.iterator().next();
|
||||
|
||||
InternetService service = tmClient.addInternetServiceToExistingIp(publicIp.getId(), PREFIX + "-no-monitoring",
|
||||
Protocol.TCP, 1234, AddInternetServiceOptions.Builder.monitorDisabled());
|
||||
tmClient.deleteInternetService(service.getId());
|
||||
for (Org org : orgs) {
|
||||
for (ReferenceType vdc : org.getVDCs().values()) {
|
||||
Set<PublicIpAddress> publicIpAddresses = tmClient.getPublicIpsAssociatedWithVDC(vdc.getHref());
|
||||
PublicIpAddress publicIp = publicIpAddresses.iterator().next();
|
||||
InternetService service = tmClient.addInternetServiceToExistingIp(publicIp.getId(), PREFIX
|
||||
+ "-no-monitoring", Protocol.TCP, 1234, AddInternetServiceOptions.Builder.monitorDisabled());
|
||||
tmClient.deleteInternetService(service.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPublicIpsAssociatedWithVDC() throws Exception {
|
||||
for (PublicIpAddress ip : tmClient
|
||||
.getPublicIpsAssociatedWithVDC(tmClient.findVDCInOrgNamed(null, null).getHref())) {
|
||||
assertNotNull(tmClient.getInternetServicesOnPublicIp(ip.getId()));
|
||||
assertNotNull(tmClient.getPublicIp(ip.getId()));
|
||||
for (Org org : orgs) {
|
||||
for (ReferenceType vdc : org.getVDCs().values()) {
|
||||
for (PublicIpAddress ip : tmClient.getPublicIpsAssociatedWithVDC(vdc.getHref())) {
|
||||
assertNotNull(tmClient.getInternetServicesOnPublicIp(ip.getId()));
|
||||
assertNotNull(tmClient.getPublicIp(ip.getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConfigCustomizationOptions() throws Exception {
|
||||
Catalog response = connection.findCatalogInOrgNamed(null, null);
|
||||
for (ReferenceType resource : response.values()) {
|
||||
if (resource.getType().equals(VCloudExpressMediaType.CATALOGITEM_XML)) {
|
||||
TerremarkCatalogItem item = tmClient.findCatalogItemInOrgCatalogNamed(null, null, resource.getName());
|
||||
assert tmClient.getCustomizationOptions(item.getCustomizationOptions().getHref()) != null;
|
||||
for (Org org : orgs) {
|
||||
for (ReferenceType catalog : org.getCatalogs().values()) {
|
||||
Catalog response = connection.getCatalog(catalog.getHref());
|
||||
for (ReferenceType resource : response.values()) {
|
||||
if (resource.getType().equals(VCloudExpressMediaType.CATALOGITEM_XML)) {
|
||||
TerremarkCatalogItem item = tmClient.findCatalogItemInOrgCatalogNamed(org.getName(),
|
||||
catalog.getName(), resource.getName());
|
||||
assert tmClient.getCustomizationOptions(item.getCustomizationOptions().getHref()) != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -149,16 +168,20 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
|
|||
@Test
|
||||
public void testDefaultVDC() throws Exception {
|
||||
super.testDefaultVDC();
|
||||
TerremarkVDC response = (TerremarkVDC) tmClient.findVDCInOrgNamed(null, null);
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getCatalog());
|
||||
assertNotNull(response.getInternetServices());
|
||||
assertNotNull(response.getPublicIps());
|
||||
for (Org org : orgs) {
|
||||
for (ReferenceType vdc : org.getVDCs().values()) {
|
||||
TerremarkVDC response = (TerremarkVDC) tmClient.getVDC(vdc.getHref());
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getCatalog());
|
||||
assertNotNull(response.getInternetServices());
|
||||
assertNotNull(response.getPublicIps());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(enabled = true)
|
||||
public void testInstantiateAndPowerOn() throws InterruptedException, ExecutionException, TimeoutException,
|
||||
IOException {
|
||||
IOException {
|
||||
prepare();
|
||||
StringBuffer name = new StringBuffer();
|
||||
for (int i = 0; i < 15; i++)
|
||||
|
@ -184,7 +207,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
|
|||
// if this template supports setting the root password, let's add it to
|
||||
// our options
|
||||
CustomizationParameters customizationOptions = tmClient.getCustomizationOptions(item.getCustomizationOptions()
|
||||
.getHref());
|
||||
.getHref());
|
||||
if (customizationOptions.canCustomizePassword())
|
||||
instantiateOptions.withPassword("robotsarefun");
|
||||
|
||||
|
@ -194,7 +217,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
|
|||
|
||||
// instantiate, noting vApp returned has minimal details
|
||||
vApp = tmClient.instantiateVAppTemplateInVDC(vdc.getHref(), vAppTemplate.getHref(), serverName,
|
||||
instantiateOptions);
|
||||
instantiateOptions);
|
||||
|
||||
assertEquals(vApp.getStatus(), Status.RESOLVED);
|
||||
|
||||
|
@ -286,7 +309,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
|
|||
@Test(enabled = true, dependsOnMethods = { "testInstantiateAndPowerOn", "testAddInternetService" })
|
||||
public void testPublicIp() throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
||||
node = tmClient.addNode(is.getId(), Iterables.getLast(vApp.getNetworkToAddresses().values()), vApp.getName()
|
||||
+ "-SSH", 22);
|
||||
+ "-SSH", 22);
|
||||
loopAndCheckPass();
|
||||
}
|
||||
|
||||
|
@ -349,18 +372,18 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
|
|||
vApp = tmClient.getVApp(vApp.getHref());
|
||||
|
||||
Task task = tmClient.configureVApp(vApp, changeNameTo("eduardo").changeMemoryTo(1536).changeProcessorCountTo(1)
|
||||
.addDisk(25 * 1048576).addDisk(25 * 1048576));
|
||||
.addDisk(25 * 1048576).addDisk(25 * 1048576));
|
||||
|
||||
assert successTester.apply(task.getHref());
|
||||
|
||||
vApp = tmClient.getVApp(vApp.getHref());
|
||||
assertEquals(vApp.getName(), "eduardo");
|
||||
assertEquals(find(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.PROCESSOR))
|
||||
.getVirtualQuantity().longValue(), 1);
|
||||
.getVirtualQuantity().longValue(), 1);
|
||||
assertEquals(find(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.MEMORY))
|
||||
.getVirtualQuantity().longValue(), 1536);
|
||||
.getVirtualQuantity().longValue(), 1536);
|
||||
assertEquals(size(filter(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.DISK_DRIVE))),
|
||||
3);
|
||||
3);
|
||||
|
||||
assert successTester.apply(tmClient.powerOnVApp(vApp.getHref()).getHref());
|
||||
|
||||
|
@ -370,11 +393,11 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
|
|||
|
||||
// extract the disks on the vApp sorted by addressOnParent
|
||||
List<ResourceAllocationSettingData> disks = Lists.newArrayList(filter(vApp.getResourceAllocations(),
|
||||
CIMPredicates.resourceTypeIn(ResourceType.DISK_DRIVE)));
|
||||
CIMPredicates.resourceTypeIn(ResourceType.DISK_DRIVE)));
|
||||
|
||||
// delete the second disk
|
||||
task = tmClient.configureVApp(vApp, deleteDiskWithAddressOnParent(Integer.parseInt(disks.get(1)
|
||||
.getAddressOnParent())));
|
||||
task = tmClient.configureVApp(vApp,
|
||||
deleteDiskWithAddressOnParent(Integer.parseInt(disks.get(1).getAddressOnParent())));
|
||||
|
||||
assert successTester.apply(task.getHref());
|
||||
|
||||
|
@ -383,17 +406,18 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
|
|||
}
|
||||
|
||||
protected void verifyConfigurationOfVApp(VCloudExpressVApp vApp, String serverName, String expectedOs,
|
||||
int processorCount, long memory, long hardDisk) {
|
||||
int processorCount, long memory, long hardDisk) {
|
||||
assertEquals(vApp.getName(), serverName);
|
||||
assertEquals(vApp.getOperatingSystemDescription(), expectedOs);
|
||||
assertEquals((int) find(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.PROCESSOR))
|
||||
.getVirtualQuantity().longValue(), processorCount);
|
||||
.getVirtualQuantity().longValue(), processorCount);
|
||||
assertEquals(find(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.MEMORY))
|
||||
.getVirtualQuantity().longValue(), memory);
|
||||
.getVirtualQuantity().longValue(), memory);
|
||||
assertEquals(find(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.DISK_DRIVE))
|
||||
.getVirtualQuantity().longValue(), hardDisk);
|
||||
assertEquals(vApp.getSize().longValue(), find(vApp.getResourceAllocations(),
|
||||
CIMPredicates.resourceTypeIn(ResourceType.DISK_DRIVE)).getVirtualQuantity().longValue());
|
||||
.getVirtualQuantity().longValue(), hardDisk);
|
||||
assertEquals(vApp.getSize().longValue(),
|
||||
find(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.DISK_DRIVE))
|
||||
.getVirtualQuantity().longValue());
|
||||
}
|
||||
|
||||
protected void doCheckPass(String address) throws IOException {
|
||||
|
@ -476,8 +500,7 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
|
|||
Properties overrides = setupProperties();
|
||||
|
||||
injector = new RestContextFactory().createContextBuilder(provider,
|
||||
ImmutableSet.<Module> of(new Log4JLoggingModule(), new JschSshClientModule()), overrides)
|
||||
.buildInjector();
|
||||
ImmutableSet.<Module> of(new Log4JLoggingModule(), new JschSshClientModule()), overrides).buildInjector();
|
||||
|
||||
connection = tmClient = injector.getInstance(TerremarkVCloudClient.class);
|
||||
|
||||
|
|
|
@ -32,6 +32,8 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
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.endpoints.Network;
|
||||
import org.jclouds.vcloud.terremark.TerremarkVCloudPropertiesBuilder;
|
||||
|
@ -68,8 +70,8 @@ public class TerremarkBindInstantiateVAppTemplateParamsToXmlPayloadTest {
|
|||
@Network
|
||||
@Provides
|
||||
@Singleton
|
||||
URI provideNetwork() {
|
||||
return URI.create("https://vcloud.safesecureweb.com/network/1990");
|
||||
ReferenceType provideNetwork() {
|
||||
return new ReferenceTypeImpl(null, null, URI.create("https://vcloud.safesecureweb.com/network/1990"));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -18,16 +18,27 @@
|
|||
*/
|
||||
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 javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.compute.config.BindComputeSuppliersByClass;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.vcloud.compute.suppliers.OrgAndVDCToLocationSupplier;
|
||||
import org.jclouds.vcloud.compute.suppliers.StaticHardwareSupplier;
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -48,4 +59,47 @@ public class CommonVCloudBindComputeSuppliersByClass extends BindComputeSupplier
|
|||
protected Class<? extends Supplier<Set<? extends Location>>> defineLocationSupplier() {
|
||||
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.checkState;
|
||||
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.transform;
|
||||
import static com.google.common.collect.Maps.newLinkedHashMap;
|
||||
import static com.google.common.collect.Maps.transformValues;
|
||||
import static com.google.common.collect.Maps.uniqueIndex;
|
||||
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.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.SortedMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.SortedMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
@ -55,7 +48,6 @@ import org.jclouds.http.RequiresHttp;
|
|||
import org.jclouds.http.annotation.ClientError;
|
||||
import org.jclouds.http.annotation.Redirection;
|
||||
import org.jclouds.http.annotation.ServerError;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.rest.AsyncClientFactory;
|
||||
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.VCloudSession;
|
||||
import org.jclouds.vcloud.domain.VDC;
|
||||
import org.jclouds.vcloud.endpoints.Network;
|
||||
import org.jclouds.vcloud.endpoints.OrgList;
|
||||
import org.jclouds.vcloud.endpoints.TasksList;
|
||||
import org.jclouds.vcloud.functions.AllCatalogItemsInCatalog;
|
||||
import org.jclouds.vcloud.functions.AllCatalogItemsInOrg;
|
||||
import org.jclouds.vcloud.functions.AllCatalogsInOrg;
|
||||
|
@ -87,39 +77,41 @@ import org.jclouds.vcloud.predicates.TaskSuccess;
|
|||
|
||||
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.collect.Iterables;
|
||||
import com.google.inject.ConfigurationException;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.name.Names;
|
||||
|
||||
/**
|
||||
* Configures the VCloud authentication service connection, including logging and http transport.
|
||||
* Configures the VCloud authentication service connection, including logging
|
||||
* and http transport.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequiresHttp
|
||||
@ConfiguresRestClient
|
||||
public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extends CommonVCloudAsyncClient> extends
|
||||
RestClientModule<S, A> {
|
||||
RestClientModule<S, A> {
|
||||
|
||||
public CommonVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
|
||||
super(syncClientType, asyncClientType);
|
||||
}
|
||||
|
||||
public CommonVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType,
|
||||
Map<Class<?>, Class<?>> delegateMap) {
|
||||
Map<Class<?>, Class<?>> delegateMap) {
|
||||
super(syncClientType, asyncClientType, delegateMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
requestInjection(this);
|
||||
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>>() {
|
||||
}).to(new TypeLiteral<FindLocationForResource>() {
|
||||
});
|
||||
|
@ -158,68 +150,29 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
@Provides
|
||||
@Singleton
|
||||
@org.jclouds.vcloud.endpoints.VDC
|
||||
protected Supplier<Map<String, String>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
final Supplier<Map<String, ? extends Org>> orgToVDCSupplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, String>>(authException,
|
||||
seconds, new Supplier<Map<String, String>>() {
|
||||
@Override
|
||||
public Map<String, String> get() {
|
||||
Map<String, String> returnVal = newLinkedHashMap();
|
||||
for (Entry<String, ? extends Org> orgr : orgToVDCSupplier.get().entrySet()) {
|
||||
for (String vdc : orgr.getValue().getVDCs().keySet()) {
|
||||
returnVal.put(vdc, orgr.getKey());
|
||||
}
|
||||
}
|
||||
return returnVal;
|
||||
}
|
||||
});
|
||||
protected Supplier<Map<String, String>> provideVDCtoORG(Supplier<Map<String, ? extends Org>> orgNameToOrgSuppier) {
|
||||
return Suppliers.compose(new Function<Map<String, ? extends Org>, Map<String, String>>() {
|
||||
|
||||
}
|
||||
@Override
|
||||
public Map<String, String> apply(Map<String, ? extends Org> arg0) {
|
||||
Builder<String, String> returnVal = ImmutableMap.<String, String> builder();
|
||||
for (Entry<String, ? extends Org> orgr : arg0.entrySet()) {
|
||||
for (String vdc : orgr.getValue().getVDCs().keySet()) {
|
||||
returnVal.put(vdc, orgr.getKey());
|
||||
}
|
||||
}
|
||||
return returnVal.build();
|
||||
}
|
||||
}, orgNameToOrgSuppier);
|
||||
|
||||
@Provides
|
||||
@org.jclouds.vcloud.endpoints.VDC
|
||||
@Singleton
|
||||
protected URI provideDefaultVDC(Org org, @org.jclouds.vcloud.endpoints.VDC String defaultVDC) {
|
||||
checkState(org.getVDCs().size() > 0, "No vdcs present in org %s", org.getName());
|
||||
return checkNotNull(org.getVDCs().get(defaultVDC), "vdc %s not present in org %s", defaultVDC, org.getName())
|
||||
.getHref();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@org.jclouds.vcloud.endpoints.VDC
|
||||
@Singleton
|
||||
protected String provideDefaultVDCName(
|
||||
@org.jclouds.vcloud.endpoints.VDC Supplier<Map<String, String>> vDCtoOrgSupplier) {
|
||||
Map<String, String> vDCtoOrg = vDCtoOrgSupplier.get();
|
||||
checkState(vDCtoOrg.keySet().size() > 0, "No vdcs present!");
|
||||
return get(vDCtoOrg.keySet(), 0);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@org.jclouds.vcloud.endpoints.Catalog
|
||||
@Singleton
|
||||
protected URI provideCatalog(Org org, @Named(PROPERTY_IDENTITY) String user, WriteableCatalog writableCatalog) {
|
||||
checkState(org.getCatalogs().size() > 0, "No catalogs present in org: " + org.getName());
|
||||
try {
|
||||
return find(org.getCatalogs().values(), writableCatalog).getHref();
|
||||
} catch (NoSuchElementException e) {
|
||||
throw new NoSuchElementException(String.format("no writable catalogs in org %s; catalogs %s", org, org
|
||||
.getCatalogs()));
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
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>>(
|
||||
authException, seconds, new Supplier<Map<String, ? extends Org>>() {
|
||||
@Override
|
||||
public Map<String, ? extends Org> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
|
||||
});
|
||||
authException, seconds, supplier);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -227,33 +180,17 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
@OrgList
|
||||
URI provideOrgListURI(Supplier<VCloudSession> sessionSupplier) {
|
||||
VCloudSession session = sessionSupplier.get();
|
||||
return URI.create(Iterables.getLast(session.getOrgs().values()).getHref().toASCIIString().replaceAll("org/.*",
|
||||
"org"));
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
return URI.create(getLast(session.getOrgs().values()).getHref().toASCIIString().replaceAll("org/.*", "org"));
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class OrgMapSupplier implements Supplier<Map<String, ? extends Org>> {
|
||||
protected final Supplier<VCloudSession> sessionSupplier;
|
||||
private final Function<Iterable<String>, Iterable<? extends Org>> organizationsForNames;
|
||||
protected final Function<Iterable<String>, Iterable<? extends Org>> organizationsForNames;
|
||||
|
||||
@Inject
|
||||
protected OrgMapSupplier(Supplier<VCloudSession> sessionSupplier,
|
||||
Function<Iterable<String>, Iterable<? extends Org>> organizationsForNames) {
|
||||
Function<Iterable<String>, Iterable<? extends Org>> organizationsForNames) {
|
||||
this.sessionSupplier = sessionSupplier;
|
||||
this.organizationsForNames = organizationsForNames;
|
||||
}
|
||||
|
@ -264,15 +201,19 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
}
|
||||
}
|
||||
|
||||
protected void installDefaultVCloudEndpointsModule() {
|
||||
install(new DefaultVCloudReferencesModule());
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class OrgCatalogSupplier implements
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> {
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> {
|
||||
protected final Supplier<Map<String, ? extends Org>> orgSupplier;
|
||||
private final Function<Org, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg;
|
||||
protected final Function<Org, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg;
|
||||
|
||||
@Inject
|
||||
protected OrgCatalogSupplier(Supplier<Map<String, ? extends Org>> orgSupplier,
|
||||
Function<Org, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg) {
|
||||
Function<Org, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg) {
|
||||
this.orgSupplier = orgSupplier;
|
||||
this.allCatalogsInOrg = allCatalogsInOrg;
|
||||
}
|
||||
|
@ -280,67 +221,41 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
@Override
|
||||
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
|
||||
return transformValues(
|
||||
transformValues(orgSupplier.get(), allCatalogsInOrg),
|
||||
new Function<Iterable<? extends org.jclouds.vcloud.domain.Catalog>, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>() {
|
||||
transformValues(orgSupplier.get(), allCatalogsInOrg),
|
||||
new Function<Iterable<? extends org.jclouds.vcloud.domain.Catalog>, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends org.jclouds.vcloud.domain.Catalog> apply(
|
||||
Iterable<? extends org.jclouds.vcloud.domain.Catalog> from) {
|
||||
return uniqueIndex(from, name);
|
||||
}
|
||||
@Override
|
||||
public Map<String, ? extends org.jclouds.vcloud.domain.Catalog> apply(
|
||||
Iterable<? extends org.jclouds.vcloud.domain.Catalog> from) {
|
||||
return uniqueIndex(from, name);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
@VCloudToken
|
||||
@Provides
|
||||
String provideVCloudToken(Supplier<VCloudSession> cache) {
|
||||
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
|
||||
@org.jclouds.vcloud.endpoints.Org
|
||||
@Singleton
|
||||
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>>(
|
||||
authException, seconds, new Supplier<Map<String, ReferenceType>>() {
|
||||
@Override
|
||||
public Map<String, ReferenceType> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
});
|
||||
authException, seconds, supplier);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> provideURIToVDC(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final URItoVDC supplier) {
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
URItoVDC supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>>(
|
||||
authException, seconds, new Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>>() {
|
||||
@Override
|
||||
public Map<URI, ? extends org.jclouds.vcloud.domain.VDC> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
});
|
||||
authException, seconds, supplier);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
|
@ -355,39 +270,28 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
@Override
|
||||
public Map<URI, ? extends org.jclouds.vcloud.domain.VDC> get() {
|
||||
return uniqueIndex(
|
||||
concat(transform(
|
||||
orgVDCMap.get().values(),
|
||||
new Function<Map<String, ? extends org.jclouds.vcloud.domain.VDC>, Iterable<? extends org.jclouds.vcloud.domain.VDC>>() {
|
||||
concat(transform(
|
||||
orgVDCMap.get().values(),
|
||||
new Function<Map<String, ? extends org.jclouds.vcloud.domain.VDC>, Iterable<? extends org.jclouds.vcloud.domain.VDC>>() {
|
||||
|
||||
@Override
|
||||
public Iterable<? extends org.jclouds.vcloud.domain.VDC> apply(
|
||||
Map<String, ? extends org.jclouds.vcloud.domain.VDC> from) {
|
||||
return from.values();
|
||||
}
|
||||
@Override
|
||||
public Iterable<? extends org.jclouds.vcloud.domain.VDC> apply(
|
||||
Map<String, ? extends org.jclouds.vcloud.domain.VDC> from) {
|
||||
return from.values();
|
||||
}
|
||||
|
||||
})), new Function<org.jclouds.vcloud.domain.VDC, URI>() {
|
||||
})), new Function<org.jclouds.vcloud.domain.VDC, URI>() {
|
||||
|
||||
@Override
|
||||
public URI apply(org.jclouds.vcloud.domain.VDC from) {
|
||||
return from.getHref();
|
||||
}
|
||||
@Override
|
||||
public URI apply(org.jclouds.vcloud.domain.VDC from) {
|
||||
return from.getHref();
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@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>() {
|
||||
|
||||
@Override
|
||||
|
@ -401,8 +305,7 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
@Singleton
|
||||
@org.jclouds.vcloud.endpoints.VCloudLogin
|
||||
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService,
|
||||
@Named(PROPERTY_API_VERSION) String version) throws InterruptedException, ExecutionException,
|
||||
TimeoutException {
|
||||
@Named(PROPERTY_API_VERSION) String version) throws InterruptedException, ExecutionException, TimeoutException {
|
||||
SortedMap<String, URI> versions = versionService.getSupportedVersions().get(180, TimeUnit.SECONDS);
|
||||
checkState(versions.size() > 0, "No versions present");
|
||||
checkState(versions.containsKey(version), "version " + version + " not present in: " + versions);
|
||||
|
@ -433,107 +336,46 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
}
|
||||
|
||||
@Provides
|
||||
@org.jclouds.vcloud.endpoints.Catalog
|
||||
@Singleton
|
||||
protected String provideCatalogName(
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogs) {
|
||||
return getLast(getLast(catalogs.get().values()).keySet());
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
protected Org provideOrg(Supplier<Map<String, ? extends Org>> orgSupplier,
|
||||
@org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) {
|
||||
return orgSupplier.get().get(defaultOrg.getName());
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Predicate<URI> successTester(Injector injector,
|
||||
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) {
|
||||
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) {
|
||||
return new RetryablePredicate<URI>(injector.getInstance(TaskSuccess.class), completed);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> provideOrgCatalogItemMapSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgCatalogSupplier supplier) {
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
OrgCatalogSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>>(
|
||||
authException, seconds,
|
||||
new Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>>() {
|
||||
@Override
|
||||
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
|
||||
});
|
||||
authException, seconds, supplier);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> provideOrgVDCSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgVDCSupplier supplier) {
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
OrgVDCSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>(
|
||||
authException, seconds,
|
||||
new Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>() {
|
||||
@Override
|
||||
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
|
||||
});
|
||||
authException, seconds, supplier);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class OrgVDCSupplier implements
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> {
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> {
|
||||
protected final Supplier<Map<String, ? extends Org>> orgSupplier;
|
||||
private final Function<Org, Iterable<? extends org.jclouds.vcloud.domain.VDC>> allVDCsInOrg;
|
||||
|
||||
@Inject
|
||||
protected OrgVDCSupplier(Supplier<Map<String, ? extends Org>> orgSupplier,
|
||||
Function<Org, Iterable<? extends org.jclouds.vcloud.domain.VDC>> allVDCsInOrg) {
|
||||
Function<Org, Iterable<? extends org.jclouds.vcloud.domain.VDC>> allVDCsInOrg) {
|
||||
this.orgSupplier = orgSupplier;
|
||||
this.allVDCsInOrg = allVDCsInOrg;
|
||||
}
|
||||
|
@ -541,29 +383,29 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
@Override
|
||||
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
|
||||
return transformValues(
|
||||
transformValues(orgSupplier.get(), allVDCsInOrg),
|
||||
new Function<Iterable<? extends org.jclouds.vcloud.domain.VDC>, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>() {
|
||||
transformValues(orgSupplier.get(), allVDCsInOrg),
|
||||
new Function<Iterable<? extends org.jclouds.vcloud.domain.VDC>, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends org.jclouds.vcloud.domain.VDC> apply(
|
||||
Iterable<? extends org.jclouds.vcloud.domain.VDC> from) {
|
||||
return uniqueIndex(from, name);
|
||||
}
|
||||
@Override
|
||||
public Map<String, ? extends org.jclouds.vcloud.domain.VDC> apply(
|
||||
Iterable<? extends org.jclouds.vcloud.domain.VDC> from) {
|
||||
return uniqueIndex(from, name);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class OrgCatalogItemSupplier implements
|
||||
Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> {
|
||||
Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> {
|
||||
protected final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogSupplier;
|
||||
private final Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog;
|
||||
protected final Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog;
|
||||
|
||||
@Inject
|
||||
protected OrgCatalogItemSupplier(
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogSupplier,
|
||||
Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog) {
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogSupplier,
|
||||
Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog) {
|
||||
this.catalogSupplier = catalogSupplier;
|
||||
this.allCatalogItemsInCatalog = allCatalogItemsInCatalog;
|
||||
}
|
||||
|
@ -571,47 +413,34 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
|
|||
@Override
|
||||
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
|
||||
return transformValues(
|
||||
catalogSupplier.get(),
|
||||
new Function<Map<String, ? extends org.jclouds.vcloud.domain.Catalog>, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>() {
|
||||
catalogSupplier.get(),
|
||||
new Function<Map<String, ? extends org.jclouds.vcloud.domain.Catalog>, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, ? extends CatalogItem>> apply(
|
||||
Map<String, ? extends org.jclouds.vcloud.domain.Catalog> from) {
|
||||
return transformValues(
|
||||
from,
|
||||
new Function<org.jclouds.vcloud.domain.Catalog, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>() {
|
||||
@Override
|
||||
public Map<String, Map<String, ? extends CatalogItem>> apply(
|
||||
Map<String, ? extends org.jclouds.vcloud.domain.Catalog> from) {
|
||||
return transformValues(
|
||||
from,
|
||||
new Function<org.jclouds.vcloud.domain.Catalog, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>() {
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends CatalogItem> apply(
|
||||
org.jclouds.vcloud.domain.Catalog from) {
|
||||
return uniqueIndex(allCatalogItemsInCatalog.apply(from), name);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public Map<String, ? extends CatalogItem> apply(org.jclouds.vcloud.domain.Catalog from) {
|
||||
return uniqueIndex(allCatalogItemsInCatalog.apply(from), name);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> provideOrgCatalogItemSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgCatalogItemSupplier supplier) {
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, AtomicReference<AuthorizationException> authException,
|
||||
OrgCatalogItemSupplier supplier) {
|
||||
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>>(
|
||||
authException, seconds,
|
||||
new Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>>() {
|
||||
@Override
|
||||
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Provides
|
||||
@TasksList
|
||||
@Singleton
|
||||
protected URI provideDefaultTasksList(Org org) {
|
||||
return org.getTasksList().getHref();
|
||||
authException, seconds, supplier);
|
||||
}
|
||||
|
||||
@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 {
|
||||
|
||||
/** The serialVersionUID */
|
||||
private static final long serialVersionUID = 8464716396538298809L;
|
||||
private final String description;
|
||||
private final ReferenceType entity;
|
||||
private final Map<String, String> properties = Maps.newLinkedHashMap();
|
||||
|
|
|
@ -32,10 +32,7 @@ import org.jclouds.vcloud.domain.TasksList;
|
|||
*/
|
||||
public class TasksListImpl implements TasksList {
|
||||
private final SortedSet<Task> tasks;
|
||||
|
||||
private final URI id;
|
||||
/** The serialVersionUID */
|
||||
private static final long serialVersionUID = 8464716396538298809L;
|
||||
|
||||
public TasksListImpl(URI id, SortedSet<Task> tasks) {
|
||||
this.id = id;
|
||||
|
|
|
@ -42,15 +42,15 @@ import com.google.common.collect.Iterables;
|
|||
@Singleton
|
||||
public class OrgNameAndCatalogNameToEndpoint implements Function<Object, URI> {
|
||||
private final Supplier<Map<String, ? extends Org>> orgMap;
|
||||
private final String defaultOrg;
|
||||
private final URI defaultUri;
|
||||
private final ReferenceType defaultOrg;
|
||||
private final ReferenceType defaultCatalog;
|
||||
|
||||
@Inject
|
||||
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.defaultOrg = defaultOrg;
|
||||
this.defaultUri = defaultUri;
|
||||
this.defaultCatalog = defaultCatalog;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -59,9 +59,9 @@ public class OrgNameAndCatalogNameToEndpoint implements Function<Object, URI> {
|
|||
Object org = Iterables.get(orgCatalog, 0);
|
||||
Object catalog = Iterables.get(orgCatalog, 1);
|
||||
if (org == null && catalog == null)
|
||||
return defaultUri;
|
||||
return defaultCatalog.getHref();
|
||||
else if (org == null)
|
||||
org = defaultOrg;
|
||||
org = defaultOrg.getName();
|
||||
|
||||
try {
|
||||
Map<String, ReferenceType> catalogs = checkNotNull(orgMap.get().get(org)).getCatalogs();
|
||||
|
|
|
@ -42,15 +42,15 @@ import com.google.common.collect.Iterables;
|
|||
@Singleton
|
||||
public class OrgNameAndVDCNameToEndpoint implements Function<Object, URI> {
|
||||
private final Supplier<Map<String, ? extends Org>> orgNameToVDCEndpoint;
|
||||
private final String defaultOrg;
|
||||
private final URI defaultUri;
|
||||
private final ReferenceType defaultOrg;
|
||||
private final ReferenceType defaultVDC;
|
||||
|
||||
@Inject
|
||||
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.defaultOrg = defaultOrg;
|
||||
this.defaultUri = defaultUri;
|
||||
this.defaultVDC = defaultVDC;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -59,9 +59,9 @@ public class OrgNameAndVDCNameToEndpoint implements Function<Object, URI> {
|
|||
Object org = Iterables.get(orgVdc, 0);
|
||||
Object vdc = Iterables.get(orgVdc, 1);
|
||||
if (org == null && vdc == null)
|
||||
return defaultUri;
|
||||
return defaultVDC.getHref();
|
||||
else if (org == null)
|
||||
org = defaultOrg;
|
||||
org = defaultOrg.getName();
|
||||
|
||||
try {
|
||||
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.Singleton;
|
||||
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.endpoints.Catalog;
|
||||
import org.jclouds.vcloud.endpoints.Org;
|
||||
|
||||
|
@ -41,13 +42,13 @@ import com.google.common.collect.Iterables;
|
|||
@Singleton
|
||||
public class OrgNameCatalogNameItemNameToEndpoint implements Function<Object, URI> {
|
||||
private final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> orgCatalogMap;
|
||||
private final String defaultOrg;
|
||||
private final String defaultCatalog;
|
||||
private final ReferenceType defaultOrg;
|
||||
private final ReferenceType defaultCatalog;
|
||||
|
||||
@Inject
|
||||
public OrgNameCatalogNameItemNameToEndpoint(
|
||||
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.defaultOrg = defaultOrg;
|
||||
this.defaultCatalog = defaultCatalog;
|
||||
|
@ -60,9 +61,9 @@ public class OrgNameCatalogNameItemNameToEndpoint implements Function<Object, UR
|
|||
Object catalog = Iterables.get(orgCatalog, 1);
|
||||
Object catalogItem = Iterables.get(orgCatalog, 2);
|
||||
if (org == null)
|
||||
org = defaultOrg;
|
||||
org = defaultOrg.getName();
|
||||
if (catalog == null)
|
||||
catalog = defaultCatalog;
|
||||
catalog = defaultCatalog.getName();
|
||||
try {
|
||||
Map<String, ? extends org.jclouds.vcloud.domain.Catalog> catalogs = checkNotNull(orgCatalogMap.get().get(org));
|
||||
return catalogs.get(catalog).get(catalogItem).getHref();
|
||||
|
|
|
@ -28,6 +28,7 @@ import javax.inject.Inject;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.vcloud.domain.CatalogItem;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.endpoints.Catalog;
|
||||
import org.jclouds.vcloud.endpoints.Org;
|
||||
|
||||
|
@ -42,13 +43,13 @@ import com.google.common.collect.Iterables;
|
|||
@Singleton
|
||||
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 String defaultOrg;
|
||||
private final String defaultCatalog;
|
||||
private final ReferenceType defaultOrg;
|
||||
private final ReferenceType defaultCatalog;
|
||||
|
||||
@Inject
|
||||
public OrgNameCatalogNameVAppTemplateNameToEndpoint(
|
||||
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.defaultOrg = defaultOrg;
|
||||
this.defaultCatalog = defaultCatalog;
|
||||
|
@ -61,9 +62,9 @@ public class OrgNameCatalogNameVAppTemplateNameToEndpoint implements Function<Ob
|
|||
Object catalog = Iterables.get(orgCatalog, 1);
|
||||
Object catalogItem = Iterables.get(orgCatalog, 2);
|
||||
if (org == null)
|
||||
org = defaultOrg;
|
||||
org = defaultOrg.getName();
|
||||
if (catalog == null)
|
||||
catalog = defaultCatalog;
|
||||
catalog = defaultCatalog.getName();
|
||||
Map<String, Map<String, Map<String, ? extends CatalogItem>>> orgCatalogItemMap = this.orgCatalogItemMap.get();
|
||||
|
||||
if (!orgCatalogItemMap.containsKey(org))
|
||||
|
|
|
@ -38,18 +38,19 @@ import com.google.common.base.Supplier;
|
|||
@Singleton
|
||||
public class OrgNameToEndpoint implements Function<Object, URI> {
|
||||
private final Supplier<Map<String, ReferenceType>> orgNameToEndpointSupplier;
|
||||
private final URI defaultUri;
|
||||
private final ReferenceType defaultOrg;
|
||||
|
||||
@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.defaultUri = defaultUri;
|
||||
this.defaultOrg = defaultOrg;
|
||||
}
|
||||
|
||||
public URI apply(Object from) {
|
||||
try {
|
||||
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) {
|
||||
throw new NoSuchElementException("org " + from + " not found in " + orgNameToEndpointSupplier.get().keySet());
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import javax.inject.Inject;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.vcloud.domain.Org;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.endpoints.TasksList;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
@ -40,18 +41,19 @@ import com.google.common.base.Supplier;
|
|||
@Singleton
|
||||
public class OrgNameToTasksListEndpoint implements Function<Object, URI> {
|
||||
private final Supplier<Map<String, ? extends Org>> orgMap;
|
||||
private final URI defaultUri;
|
||||
private final ReferenceType defaultTasksList;
|
||||
|
||||
@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.defaultUri = defaultUri;
|
||||
this.defaultTasksList = defaultTasksList;
|
||||
}
|
||||
|
||||
public URI apply(Object from) {
|
||||
Object org = from;
|
||||
if (org == null)
|
||||
return defaultUri;
|
||||
return defaultTasksList.getHref();
|
||||
try {
|
||||
return checkNotNull(orgMap.get().get(org)).getTasksList().getHref();
|
||||
} catch (NullPointerException e) {
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.util.NoSuchElementException;
|
|||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.endpoints.Org;
|
||||
import org.jclouds.vcloud.endpoints.VDC;
|
||||
|
||||
|
@ -41,13 +42,13 @@ import com.google.common.collect.Iterables;
|
|||
@Singleton
|
||||
public class OrgNameVDCNameResourceEntityNameToEndpoint implements Function<Object, URI> {
|
||||
private final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap;
|
||||
private final String defaultOrg;
|
||||
private final String defaultVDC;
|
||||
private final ReferenceType defaultOrg;
|
||||
private final ReferenceType defaultVDC;
|
||||
|
||||
@Inject
|
||||
public OrgNameVDCNameResourceEntityNameToEndpoint(
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap, @Org String defaultOrg,
|
||||
@VDC String defaultVDC) {
|
||||
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap, @Org ReferenceType defaultOrg,
|
||||
@VDC ReferenceType defaultVDC) {
|
||||
this.orgVDCMap = orgVDCMap;
|
||||
this.defaultOrg = defaultOrg;
|
||||
this.defaultVDC = defaultVDC;
|
||||
|
@ -60,9 +61,9 @@ public class OrgNameVDCNameResourceEntityNameToEndpoint implements Function<Obje
|
|||
Object vDC = Iterables.get(orgVDC, 1);
|
||||
Object entityName = Iterables.get(orgVDC, 2);
|
||||
if (org == null)
|
||||
org = defaultOrg;
|
||||
org = defaultOrg.getName();
|
||||
if (vDC == null)
|
||||
vDC = defaultVDC;
|
||||
vDC = defaultVDC.getName();
|
||||
try {
|
||||
Map<String, ? extends org.jclouds.vcloud.domain.VDC> vDCs = checkNotNull(orgVDCMap.get().get(org));
|
||||
return vDCs.get(vDC).getResourceEntities().get(entityName).getHref();
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.http.HttpUtils.releasePayload;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -69,7 +69,7 @@ public class ParseLoginResponseFromHeaders implements Function<HttpResponse, VCl
|
|||
try {
|
||||
final String token = parseTokenFromHeaders(from);
|
||||
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() {
|
||||
@VCloudToken
|
||||
|
|
|
@ -25,7 +25,20 @@ package org.jclouds.vcloud.reference;
|
|||
*/
|
||||
public interface VCloudConstants {
|
||||
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.
|
||||
*/
|
||||
|
|
|
@ -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.assertNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
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.VDC;
|
||||
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.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Module;
|
||||
|
||||
|
@ -48,58 +52,127 @@ import com.google.inject.Module;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true)
|
||||
@Test(groups = "live", singleThreaded = true)
|
||||
public abstract class CommonVCloudClientLiveTest<S extends CommonVCloudClient, A extends CommonVCloudAsyncClient> {
|
||||
|
||||
protected S connection;
|
||||
protected RestContext<S, A> context;
|
||||
|
||||
protected abstract Iterable<Org> listOrgs();
|
||||
|
||||
@Test
|
||||
public void testOrg() throws Exception {
|
||||
Org response = connection.findOrgNamed(null);
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getName());
|
||||
assert response.getCatalogs().size() >= 1;
|
||||
assert response.getTasksList() != null;
|
||||
assert response.getVDCs().size() >= 1;
|
||||
assertEquals(connection.findOrgNamed(response.getName()), response);
|
||||
for (Org org : orgs) {
|
||||
assertNotNull(org);
|
||||
assertNotNull(org.getName());
|
||||
assert org.getCatalogs().size() >= 1;
|
||||
assert org.getTasksList() != null;
|
||||
assert org.getVDCs().size() >= 1;
|
||||
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
|
||||
public void testCatalog() throws Exception {
|
||||
Org org = connection.findOrgNamed(null);
|
||||
for (ReferenceType cat : org.getCatalogs().values()) {
|
||||
Catalog response = connection.getCatalog(cat.getHref());
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getName());
|
||||
assertNotNull(response.getHref());
|
||||
assertEquals(connection.findCatalogInOrgNamed(null, response.getName()), response);
|
||||
for (Org org : orgs) {
|
||||
for (ReferenceType cat : org.getCatalogs().values()) {
|
||||
Catalog response = connection.getCatalog(cat.getHref());
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getName());
|
||||
assertNotNull(response.getHref());
|
||||
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
|
||||
public void testGetOrgNetwork() throws Exception {
|
||||
Org org = connection.findOrgNamed(null);
|
||||
for (ReferenceType resource : org.getNetworks().values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.NETWORK_XML)) {
|
||||
OrgNetwork item = connection.getNetwork(resource.getHref());
|
||||
assertNotNull(item);
|
||||
for (Org org : orgs) {
|
||||
for (ReferenceType resource : org.getNetworks().values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.NETWORK_XML)) {
|
||||
OrgNetwork item = connection.getNetwork(resource.getHref());
|
||||
assertNotNull(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetVDCNetwork() throws Exception {
|
||||
Org org = connection.findOrgNamed(null);
|
||||
for (ReferenceType vdc : org.getVDCs().values()) {
|
||||
VDC response = connection.getVDC(vdc.getHref());
|
||||
for (ReferenceType resource : response.getAvailableNetworks().values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.NETWORK_XML)) {
|
||||
try {
|
||||
OrgNetwork item = connection.getNetwork(resource.getHref());
|
||||
assertNotNull(item);
|
||||
} catch (AuthorizationException e) {
|
||||
for (Org org : orgs) {
|
||||
for (ReferenceType vdc : org.getVDCs().values()) {
|
||||
VDC response = connection.getVDC(vdc.getHref());
|
||||
for (ReferenceType resource : response.getAvailableNetworks().values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.NETWORK_XML)) {
|
||||
try {
|
||||
OrgNetwork net = connection.getNetwork(resource.getHref());
|
||||
assertNotNull(net);
|
||||
assertNotNull(net.getName());
|
||||
assertNotNull(net.getHref());
|
||||
assertEquals(
|
||||
connection.findNetworkInOrgVDCNamed(org.getName(), response.getName(), net.getName()), net);
|
||||
} catch (AuthorizationException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertiesCanOverrideDefaultNetwork() throws Exception {
|
||||
for (Org org : orgs) {
|
||||
for (ReferenceType vdc : org.getVDCs().values()) {
|
||||
VDC response = connection.getVDC(vdc.getHref());
|
||||
for (ReferenceType net : response.getAvailableNetworks().values()) {
|
||||
RestContext<S, A> newContext = null;
|
||||
try {
|
||||
newContext = createContextWithProperties(overrideDefaults(ImmutableMap.of(
|
||||
VCloudConstants.PROPERTY_VCLOUD_DEFAULT_ORG, org.getName(),
|
||||
VCloudConstants.PROPERTY_VCLOUD_DEFAULT_VDC, vdc.getName(),
|
||||
VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK, net.getName())));
|
||||
assertEquals(newContext.getApi().findNetworkInOrgVDCNamed(null, null, null),
|
||||
connection.getNetwork(net.getHref()));
|
||||
} finally {
|
||||
newContext.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -108,13 +181,14 @@ public abstract class CommonVCloudClientLiveTest<S extends CommonVCloudClient, A
|
|||
|
||||
@Test
|
||||
public void testGetCatalogItem() throws Exception {
|
||||
Org org = connection.findOrgNamed(null);
|
||||
for (ReferenceType cat : org.getCatalogs().values()) {
|
||||
Catalog response = connection.getCatalog(cat.getHref());
|
||||
for (ReferenceType resource : response.values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
|
||||
CatalogItem item = connection.getCatalogItem(resource.getHref());
|
||||
verifyCatalogItem(item);
|
||||
for (Org org : orgs) {
|
||||
for (ReferenceType cat : org.getCatalogs().values()) {
|
||||
Catalog response = connection.getCatalog(cat.getHref());
|
||||
for (ReferenceType resource : response.values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
|
||||
CatalogItem item = connection.getCatalogItem(resource.getHref());
|
||||
verifyCatalogItem(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -131,14 +205,15 @@ public abstract class CommonVCloudClientLiveTest<S extends CommonVCloudClient, A
|
|||
|
||||
@Test
|
||||
public void testFindCatalogItem() throws Exception {
|
||||
Org org = connection.findOrgNamed(null);
|
||||
for (ReferenceType cat : org.getCatalogs().values()) {
|
||||
Catalog response = connection.getCatalog(cat.getHref());
|
||||
for (ReferenceType resource : response.values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
|
||||
CatalogItem item = connection.findCatalogItemInOrgCatalogNamed(org.getName(), response.getName(),
|
||||
resource.getName());
|
||||
verifyCatalogItem(item);
|
||||
for (Org org : orgs) {
|
||||
for (ReferenceType cat : org.getCatalogs().values()) {
|
||||
Catalog response = connection.getCatalog(cat.getHref());
|
||||
for (ReferenceType resource : response.values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
|
||||
CatalogItem item = connection.findCatalogItemInOrgCatalogNamed(org.getName(), response.getName(),
|
||||
resource.getName());
|
||||
verifyCatalogItem(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -146,36 +221,58 @@ public abstract class CommonVCloudClientLiveTest<S extends CommonVCloudClient, A
|
|||
|
||||
@Test
|
||||
public void testDefaultVDC() throws Exception {
|
||||
Org org = connection.findOrgNamed(null);
|
||||
for (ReferenceType vdc : org.getVDCs().values()) {
|
||||
VDC response = connection.getVDC(vdc.getHref());
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getName());
|
||||
assertNotNull(response.getHref());
|
||||
assertNotNull(response.getResourceEntities());
|
||||
assertNotNull(response.getAvailableNetworks());
|
||||
assertEquals(connection.getVDC(response.getHref()), response);
|
||||
for (Org org : orgs) {
|
||||
for (ReferenceType vdc : org.getVDCs().values()) {
|
||||
VDC response = connection.getVDC(vdc.getHref());
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getName());
|
||||
assertNotNull(response.getHref());
|
||||
assertNotNull(response.getResourceEntities());
|
||||
assertNotNull(response.getAvailableNetworks());
|
||||
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
|
||||
public void testDefaultTasksList() throws Exception {
|
||||
org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(null);
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getLocation());
|
||||
assertNotNull(response.getTasks());
|
||||
assertEquals(connection.getTasksList(response.getLocation()).getLocation(), response.getLocation());
|
||||
for (Org org : orgs) {
|
||||
org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(org.getName());
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getLocation());
|
||||
assertNotNull(response.getTasks());
|
||||
assertEquals(connection.getTasksList(response.getLocation()).getLocation(), response.getLocation());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTask() throws Exception {
|
||||
org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(null);
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getLocation());
|
||||
assertNotNull(response.getTasks());
|
||||
if (response.getTasks().size() > 0) {
|
||||
Task task = response.getTasks().last();
|
||||
assertEquals(connection.getTask(task.getHref()).getHref(), task.getHref());
|
||||
for (Org org : orgs) {
|
||||
org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(org.getName());
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getLocation());
|
||||
assertNotNull(response.getTasks());
|
||||
if (response.getTasks().size() > 0) {
|
||||
Task task = response.getTasks().last();
|
||||
assertEquals(connection.getTask(task.getHref()).getHref(), task.getHref());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,6 +281,7 @@ public abstract class CommonVCloudClientLiveTest<S extends CommonVCloudClient, A
|
|||
protected String credential;
|
||||
protected String endpoint;
|
||||
protected String apiversion;
|
||||
protected Iterable<Org> orgs;
|
||||
|
||||
protected void setupCredentials() {
|
||||
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" })
|
||||
public void setupClient() {
|
||||
setupCredentials();
|
||||
Properties overrides = setupProperties();
|
||||
context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider,
|
||||
ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides).getProviderSpecificContext();
|
||||
|
||||
context = createContextWithProperties(setupProperties());
|
||||
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.setProperty(PROPERTY_ISO3166_CODES, "US-IN");
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ public class BluelockVCloudEnterprisePropertiesBuilder extends VCloudPropertiesB
|
|||
Properties properties = super.defaultProperties();
|
||||
properties.setProperty(PROPERTY_ISO3166_CODES, "US-IN");
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ public class BluelockVCloudZone01PropertiesBuilder extends VCloudPropertiesBuild
|
|||
Properties properties = super.defaultProperties();
|
||||
properties.setProperty(PROPERTY_ISO3166_CODES, "US-IN");
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
|
||||
<properties>
|
||||
<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.identity>FIXME</test.trmk-ecloud.identity>
|
||||
<test.trmk-ecloud.credential>FIXME</test.trmk-ecloud.credential>
|
||||
|
@ -141,6 +142,10 @@
|
|||
<name>test.trmk-ecloud.credential</name>
|
||||
<value>${test.trmk-ecloud.credential}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>test.trmk-ecloud.datacenter</name>
|
||||
<value>${test.trmk-ecloud.datacenter}</value>
|
||||
</property>
|
||||
</systemProperties>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
|
|
@ -26,6 +26,7 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.jclouds.terremark.ecloud.domain.TerremarkECloudOrg;
|
||||
import org.jclouds.vcloud.domain.Org;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkOrg;
|
||||
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> {
|
||||
@Inject
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.jclouds.terremark.ecloud.domain.TerremarkECloudOrg;
|
||||
import org.jclouds.vcloud.domain.Org;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkOrg;
|
||||
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> {
|
||||
@Inject
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ import org.jclouds.vcloud.terremark.xml.IpAddressesHandler;
|
|||
import org.jclouds.vcloud.terremark.xml.KeyPairByNameHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.KeyPairHandler;
|
||||
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.TerremarkOrgNetworkFromTerremarkVCloudExpressNetworkHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.VAppExtendedInfoHandler;
|
||||
|
@ -137,8 +137,8 @@ public interface TerremarkECloudAsyncClient extends TerremarkVCloudAsyncClient {
|
|||
*/
|
||||
@POST
|
||||
@Consumes(PUBLICIP_XML)
|
||||
@XMLResponseParser(PublicIpAddressesHandler.class)
|
||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||
@XMLResponseParser(PublicIpAddressHandler.class)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<PublicIpAddress> activatePublicIpInVDC(
|
||||
@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 java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.jclouds.terremark.ecloud.features.DataCenterOperationsAsyncClient;
|
||||
import org.jclouds.terremark.ecloud.features.DataCenterOperationsClient;
|
||||
import org.jclouds.terremark.ecloud.features.TagOperationsAsyncClient;
|
||||
import org.jclouds.terremark.ecloud.features.TagOperationsClient;
|
||||
import org.jclouds.vcloud.VCloudExpressAsyncClient;
|
||||
import org.jclouds.vcloud.VCloudExpressClient;
|
||||
import org.jclouds.vcloud.config.DefaultVCloudReferencesModule;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.terremark.TerremarkECloudAsyncClient;
|
||||
import org.jclouds.vcloud.terremark.TerremarkECloudClient;
|
||||
|
@ -45,24 +44,24 @@ import org.jclouds.vcloud.terremark.domain.TerremarkOrgNetwork;
|
|||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Injector;
|
||||
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
|
||||
*/
|
||||
@RequiresHttp
|
||||
@ConfiguresRestClient
|
||||
public class TerremarkECloudRestClientModule extends
|
||||
TerremarkRestClientModule<TerremarkECloudClient, TerremarkECloudAsyncClient> {
|
||||
TerremarkRestClientModule<TerremarkECloudClient, TerremarkECloudAsyncClient> {
|
||||
|
||||
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()//
|
||||
.put(DataCenterOperationsClient.class, DataCenterOperationsAsyncClient.class)//
|
||||
.put(TagOperationsClient.class, TagOperationsAsyncClient.class)//
|
||||
.build();
|
||||
.put(DataCenterOperationsClient.class, DataCenterOperationsAsyncClient.class)//
|
||||
.put(TagOperationsClient.class, TagOperationsAsyncClient.class)//
|
||||
.build();
|
||||
|
||||
public TerremarkECloudRestClientModule() {
|
||||
super(TerremarkECloudClient.class, TerremarkECloudAsyncClient.class, DELEGATE_MAP);
|
||||
|
@ -92,36 +91,51 @@ public class TerremarkECloudRestClientModule extends
|
|||
return in;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected URI findDefaultNetworkForVDC(org.jclouds.vcloud.domain.VDC vDC, Map<String, ReferenceType> networks,
|
||||
final Injector injector) {
|
||||
// TODO FIXME XXX: In Terremark Enterprise environment with multiple VDC's this does not
|
||||
// work well.
|
||||
// Each VDC will have differnt network subnets. So we cannot assume the default VDC's
|
||||
// networks will
|
||||
// work with non-default VDC's. So make PROPERTY_VCLOUD_DEFAULT_NETWORK optional. If
|
||||
// this property
|
||||
// is not set, they are expected to add NetworkConfig to the options when launching a
|
||||
// server.
|
||||
logger.warn("default network for vdc %s not set", vDC.getName());
|
||||
try {
|
||||
return Iterables.find(networks.values(), new Predicate<ReferenceType>() {
|
||||
@Singleton
|
||||
public static class IsDMZNetwork implements Predicate<ReferenceType> {
|
||||
private final TerremarkECloudClient client;
|
||||
|
||||
@Override
|
||||
public boolean apply(ReferenceType input) {
|
||||
TerremarkOrgNetwork network = injector.getInstance(TerremarkECloudClient.class).getNetwork(
|
||||
input.getHref());
|
||||
TerremarkNetwork terremarkNetwork = injector.getInstance(TerremarkECloudClient.class)
|
||||
.getTerremarkNetwork(
|
||||
checkNotNull(checkNotNull(network, "network at: " + input).getNetworkExtension(),
|
||||
"network extension for: " + input).getHref());
|
||||
return checkNotNull(terremarkNetwork, "terremark network extension at: " + network.getNetworkExtension())
|
||||
.getNetworkType() == TerremarkNetwork.Type.DMZ;
|
||||
}
|
||||
@Inject
|
||||
public IsDMZNetwork(TerremarkECloudClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
}).getHref();
|
||||
} catch (NoSuchElementException e) {
|
||||
throw new ResourceNotFoundException("no dmz networks in vdc " + vDC.getName() + ": " + networks);
|
||||
@Override
|
||||
public boolean apply(ReferenceType arg0) {
|
||||
// TODO FIXME XXX: In Terremark Enterprise environment with multiple
|
||||
// VDC's
|
||||
// this does not
|
||||
// work well.
|
||||
// Each VDC will have differnt network subnets. So we cannot assume the
|
||||
// default VDC's
|
||||
// networks will
|
||||
// work with non-default VDC's. So make PROPERTY_VCLOUD_DEFAULT_NETWORK
|
||||
// optional. If
|
||||
// this property
|
||||
// is not set, they are expected to add NetworkConfig to the options
|
||||
// when
|
||||
// launching a
|
||||
// server.
|
||||
TerremarkOrgNetwork orgNetwork = client.getNetwork(arg0.getHref());
|
||||
TerremarkNetwork terremarkNetwork = client.getTerremarkNetwork(checkNotNull(
|
||||
checkNotNull(orgNetwork, "network at: " + arg0).getNetworkExtension(), "network extension for: " + arg0)
|
||||
.getHref());
|
||||
return checkNotNull(terremarkNetwork, "terremark network extension at: " + orgNetwork.getNetworkExtension())
|
||||
.getNetworkType() == TerremarkNetwork.Type.DMZ;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void installDefaultVCloudEndpointsModule() {
|
||||
install(new DefaultVCloudReferencesModule() {
|
||||
|
||||
@Override
|
||||
protected Predicate<ReferenceType> provideDefaultNetworkSelector(Injector i) {
|
||||
return i.getInstance(IsDMZNetwork.class);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public class TerremarkECloudInternetServiceAndPublicIpAddressSupplier implements
|
|||
@Override
|
||||
public Entry<InternetService, PublicIpAddress> getNewInternetServiceAndIp(VCloudExpressVApp vApp, int port,
|
||||
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;
|
||||
PublicIpAddress ip = null;
|
||||
try {
|
||||
|
|
|
@ -18,13 +18,13 @@
|
|||
*/
|
||||
package org.jclouds.terremark.ecloud;
|
||||
|
||||
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.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
@ -32,36 +32,36 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.RestClientTest;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.rest.RestContextSpec;
|
||||
import org.jclouds.terremark.ecloud.domain.internal.TerremarkECloudOrgImpl;
|
||||
import org.jclouds.vcloud.CommonVCloudClient;
|
||||
import org.jclouds.vcloud.VCloudExpressAsyncClientTest.VCloudRestClientModuleExtension.TestOrgCatalogItemSupplier;
|
||||
import org.jclouds.vcloud.VCloudExpressAsyncClientTest.VCloudRestClientModuleExtension.TestOrgCatalogSupplier;
|
||||
import org.jclouds.vcloud.VCloudExpressLoginAsyncClient;
|
||||
import org.jclouds.vcloud.VCloudMediaType;
|
||||
import org.jclouds.vcloud.VCloudVersionsAsyncClient;
|
||||
import org.jclouds.vcloud.config.CommonVCloudRestClientModule.OrgVDCSupplier;
|
||||
import org.jclouds.vcloud.domain.AllocationModel;
|
||||
import org.jclouds.vcloud.domain.Capacity;
|
||||
import org.jclouds.vcloud.domain.Org;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
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.CatalogItemImpl;
|
||||
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
|
||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
||||
import org.jclouds.vcloud.terremark.TerremarkECloudMediaType;
|
||||
import org.jclouds.vcloud.terremark.TerremarkVCloudMediaType;
|
||||
import org.jclouds.vcloud.terremark.config.TerremarkECloudRestClientModule;
|
||||
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.Suppliers;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
|
@ -69,128 +69,6 @@ import com.google.inject.Module;
|
|||
*/
|
||||
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
|
||||
protected void checkFilters(HttpRequest request) {
|
||||
assertEquals(request.getFilters().size(), 1);
|
||||
|
@ -199,7 +77,7 @@ public abstract class BaseTerremarkECloudAsyncClientTest<T> extends RestClientTe
|
|||
|
||||
@Override
|
||||
protected Module createModule() {
|
||||
return new TerremarkVCloudRestClientModuleExtension();
|
||||
return new TerremarkECloudRestClientModuleExtension();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -207,37 +85,187 @@ public abstract class BaseTerremarkECloudAsyncClientTest<T> extends RestClientTe
|
|||
return new RestContextFactory().createContextSpec("trmk-ecloud", "identity", "credential", new Properties());
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class TestTerremarkOrgVDCSupplier extends OrgVDCSupplier {
|
||||
@Inject
|
||||
protected TestTerremarkOrgVDCSupplier() {
|
||||
super(null, null);
|
||||
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",
|
||||
TerremarkECloudMediaType.KEYSLIST_XML, URI.create("https://vcloud.safesecureweb.com/api/v0.8/keysList/1"));
|
||||
protected static final ReferenceTypeImpl TAGSLIST_REF = new ReferenceTypeImpl("deviceTags",
|
||||
TerremarkECloudMediaType.TAGSLISTLIST_XML,
|
||||
URI.create("https://vcloud.safesecureweb.com/api/v0.8/deviceTags/1"));
|
||||
protected static final ReferenceTypeImpl VAPPCATALOGLIST_REF = new ReferenceTypeImpl("vappCatalog",
|
||||
TerremarkECloudMediaType.VAPPCATALOGLIST_XML,
|
||||
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vappCatalog/1"));
|
||||
protected static final ReferenceTypeImpl DATACENTERSLIST_REF = new ReferenceTypeImpl("dataCentersList",
|
||||
TerremarkECloudMediaType.DATACENTERSLIST_XML,
|
||||
URI.create("https://vcloud.safesecureweb.com/api/v0.8/datacentersList/1"));
|
||||
protected static final ReferenceTypeImpl NETWORK_REF = new ReferenceTypeImpl("network", VCloudMediaType.NETWORK_XML,
|
||||
URI.create("https://vcloud.safesecureweb.com/network/1990"));
|
||||
|
||||
protected static final ReferenceTypeImpl PUBLICIPS_REF = new ReferenceTypeImpl("publicIps",
|
||||
TerremarkECloudMediaType.PUBLICIPSLIST_XML,
|
||||
URI.create("https://vcloud.safesecureweb.com/api/v0.8/publicIps/1"));
|
||||
|
||||
protected static final ReferenceTypeImpl INTERNETSERVICES_REF = new ReferenceTypeImpl("internetServices",
|
||||
TerremarkECloudMediaType.INTERNETSERVICESLIST_XML,
|
||||
URI.create("https://vcloud.safesecureweb.com/api/v0.8/internetServices/1"));
|
||||
|
||||
protected static final Org ORG = new TerremarkECloudOrgImpl(ORG_REF.getName(), ORG_REF.getType(), ORG_REF.getHref(),
|
||||
"org", ImmutableMap.<String, ReferenceType> of(CATALOG_REF.getName(), CATALOG_REF),
|
||||
ImmutableMap.<String, ReferenceType> of(VDC_REF.getName(), VDC_REF), ImmutableMap.<String, ReferenceType> of(
|
||||
NETWORK_REF.getName(), NETWORK_REF), ImmutableMap.<String, ReferenceType> of(TASKSLIST_REF.getName(),
|
||||
TASKSLIST_REF), KEYSLIST_REF, TAGSLIST_REF, VAPPCATALOGLIST_REF, DATACENTERSLIST_REF);
|
||||
|
||||
protected static final VDC VDC = new TerremarkVDCImpl(VDC_REF.getName(), VDC_REF.getType(), VDC_REF.getHref(),
|
||||
VDCStatus.READY, null, "description", ImmutableSet.<Task> of(), AllocationModel.ALLOCATION_POOL, null, null,
|
||||
null, ImmutableMap.<String, ReferenceType> of(
|
||||
"vapp",
|
||||
new ReferenceTypeImpl("vapp", "application/vnd.vmware.vcloud.vApp+xml", URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1")),
|
||||
"network",
|
||||
new ReferenceTypeImpl("network", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2"))),
|
||||
ImmutableMap.<String, ReferenceType> of(NETWORK_REF.getName(), NETWORK_REF), 0, 0, 0, false, CATALOG_REF,
|
||||
PUBLICIPS_REF, INTERNETSERVICES_REF);
|
||||
|
||||
@RequiresHttp
|
||||
@ConfiguresRestClient
|
||||
protected static class TerremarkECloudRestClientModuleExtension extends TerremarkECloudRestClientModule {
|
||||
|
||||
@Override
|
||||
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService, String version) {
|
||||
return URI.create("https://vcloud.safesecureweb.com/api/v0.8/login");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
|
||||
return ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> of("org",
|
||||
|
||||
ImmutableMap.<String, org.jclouds.vcloud.domain.VDC> of(
|
||||
"vdc",
|
||||
new TerremarkVDCImpl("vdc", null, URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"),
|
||||
VDCStatus.READY, null, "description", ImmutableSet.<Task> of(), AllocationModel.UNRECOGNIZED,
|
||||
new Capacity("MB", 0, 0, 0, 0), new Capacity("MB", 0, 0, 0, 0), new Capacity("MB", 0, 0, 0, 0),
|
||||
ImmutableMap.<String, ReferenceType> of(
|
||||
"vapp",
|
||||
new ReferenceTypeImpl("vapp", "application/vnd.vmware.vcloud.vApp+xml", URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1")),
|
||||
"network",
|
||||
new ReferenceTypeImpl("network", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2"))), ImmutableMap
|
||||
.<String, ReferenceType> of(), 0, 0, 0, false, new ReferenceTypeImpl("catalog",
|
||||
TerremarkVCloudMediaType.CATALOG_XML, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1")),
|
||||
new ReferenceTypeImpl("publicIps", TerremarkVCloudMediaType.PUBLICIPSLIST_XML, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/publicIps/1")), new ReferenceTypeImpl(
|
||||
"internetServices", TerremarkVCloudMediaType.INTERNETSERVICESLIST_XML, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/internetServices/1")))));
|
||||
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;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.vcloud.reference.VCloudConstants;
|
||||
import org.jclouds.vcloud.terremark.BaseTerremarkClientLiveTest;
|
||||
import org.jclouds.vcloud.terremark.TerremarkECloudClient;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -27,5 +30,11 @@ import org.testng.annotations.Test;
|
|||
*/
|
||||
@Test(groups = "live", enabled = true, singleThreaded = true)
|
||||
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 {
|
||||
@Test
|
||||
public void testListDataCentersInOrg() throws Exception {
|
||||
for (ReferenceType response : getApi().listOrgs()) {
|
||||
for (ReferenceType response : getApi().listOrgs().values()) {
|
||||
TerremarkECloudOrg org = getApi().getOrg(response.getHref());
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getName());
|
||||
|
|
|
@ -33,7 +33,7 @@ import org.testng.annotations.Test;
|
|||
public class TagOperationsClientLiveTest extends BaseTerremarkECloudClientLiveTest {
|
||||
@Test
|
||||
public void testListTagsInOrg() throws Exception {
|
||||
for (ReferenceType response : getApi().listOrgs()) {
|
||||
for (ReferenceType response : getApi().listOrgs().values()) {
|
||||
TerremarkECloudOrg org = getApi().getOrg(response.getHref());
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getName());
|
||||
|
|
|
@ -19,12 +19,12 @@
|
|||
package org.jclouds.vcloud.terremark;
|
||||
|
||||
import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.disabled;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
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.NodeHandler;
|
||||
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.TerremarkVDCHandler;
|
||||
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.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code TerremarkECloudAsyncClient}
|
||||
*
|
||||
* @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")
|
||||
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
|
||||
protected TypeLiteral<RestAnnotationProcessor<TerremarkECloudAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<TerremarkECloudAsyncClient>>() {
|
||||
|
@ -219,8 +225,8 @@ public class TerremarkECloudAsyncClientTest extends BaseTerremarkECloudAsyncClie
|
|||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, PublicIpAddressesHandler.class);
|
||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||
assertSaxResponseParserClassEquals(method, PublicIpAddressHandler.class);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
|
|
|
@ -21,11 +21,13 @@ package org.jclouds.vcloud.terremark;
|
|||
import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.processorCount;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.ssh.SshClient;
|
||||
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.Protocol;
|
||||
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")
|
||||
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
|
||||
void setProvider() {
|
||||
this.provider = "trmk-ecloud";
|
||||
|
@ -61,7 +71,7 @@ public class TerremarkECloudClientLiveTest extends TerremarkClientLiveTest {
|
|||
@Override
|
||||
protected Entry<InternetService, PublicIpAddress> getNewInternetServiceAndIpForSSH(VCloudExpressVApp vApp) {
|
||||
return new TerremarkECloudInternetServiceAndPublicIpAddressSupplier(TerremarkECloudClient.class.cast(tmClient))
|
||||
.getNewInternetServiceAndIp(vApp, 22, Protocol.TCP);
|
||||
.getNewInternetServiceAndIp(vApp, 22, Protocol.TCP);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ package org.jclouds.vcloud.terremark.compute;
|
|||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.compute.BaseComputeServiceLiveTest;
|
||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||
import org.jclouds.compute.domain.ComputeMetadata;
|
||||
|
@ -32,16 +34,27 @@ import org.jclouds.compute.domain.TemplateBuilder;
|
|||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||
import org.jclouds.vcloud.domain.VCloudExpressVApp;
|
||||
import org.jclouds.vcloud.reference.VCloudConstants;
|
||||
import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
|
||||
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
|
||||
*/
|
||||
@Test(groups = "live", enabled = true, sequential = true)
|
||||
@Test(groups = "live", enabled = true, singleThreaded = true)
|
||||
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() {
|
||||
provider = "trmk-ecloud";
|
||||
}
|
||||
|
@ -60,13 +73,6 @@ public class TerremarkECloudComputeServiceLiveTest extends BaseComputeServiceLiv
|
|||
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
|
||||
public void testListImages() throws Exception {
|
||||
for (Image image : client.listImages()) {
|
||||
|
@ -74,7 +80,7 @@ public class TerremarkECloudComputeServiceLiveTest extends BaseComputeServiceLiv
|
|||
// image.getLocationId() can be null, if it is a location-free image
|
||||
assertEquals(image.getType(), ComputeType.IMAGE);
|
||||
if (image.getOperatingSystem().getFamily() != OsFamily.WINDOWS
|
||||
&& image.getOperatingSystem().getFamily() != OsFamily.SOLARIS) {
|
||||
&& image.getOperatingSystem().getFamily() != OsFamily.SOLARIS) {
|
||||
assert image.getDefaultCredentials() != null && image.getDefaultCredentials().identity != null : image;
|
||||
assert image.getDefaultCredentials().credential != null : image;
|
||||
}
|
||||
|
@ -90,7 +96,7 @@ public class TerremarkECloudComputeServiceLiveTest extends BaseComputeServiceLiv
|
|||
NodeMetadata allData = client.getNodeMetadata(node.getId());
|
||||
System.out.println(allData.getHardware());
|
||||
RestContext<TerremarkVCloudClient, TerremarkVCloudClient> tmContext = new ComputeServiceContextFactory()
|
||||
.createContext(provider, identity, credential).getProviderSpecificContext();
|
||||
.createContext(provider, identity, credential).getProviderSpecificContext();
|
||||
VCloudExpressVApp vApp = tmContext.getApi().findVAppInOrgVDCNamed(null, null, allData.getName());
|
||||
assertEquals(vApp.getName(), allData.getName());
|
||||
}
|
||||
|
|
|
@ -22,12 +22,14 @@ import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.compute.BaseTemplateBuilderLiveTest;
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.compute.domain.OsFamilyVersion64Bit;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.vcloud.reference.VCloudConstants;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
@ -39,6 +41,13 @@ import com.google.common.collect.ImmutableSet;
|
|||
*/
|
||||
@Test(groups = "live")
|
||||
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() {
|
||||
provider = "trmk-ecloud";
|
||||
|
@ -51,20 +60,20 @@ public class TerremarkECloudTemplateBuilderLiveTest extends BaseTemplateBuilderL
|
|||
@Override
|
||||
public boolean apply(OsFamilyVersion64Bit input) {
|
||||
switch (input.family) {
|
||||
case RHEL:
|
||||
return !input.version.equals("") && !input.version.matches("5.[50]");
|
||||
case SOLARIS:
|
||||
return !input.is64Bit;
|
||||
case CENTOS:
|
||||
return !input.version.equals("") && !input.version.matches("5.[50]");
|
||||
case UBUNTU:
|
||||
return !input.version.equals("") && !input.version.equals("10.04") && !input.version.equals("8.04");
|
||||
case WINDOWS:
|
||||
return !input.version.equals("") && !input.version.equals("2003 R2") //
|
||||
&& !(input.version.equals("2008") && !input.is64Bit) //
|
||||
&& !(input.version.matches("2008( R2)?") && input.is64Bit);
|
||||
default:
|
||||
return true;
|
||||
case RHEL:
|
||||
return !input.version.equals("") && !input.version.matches("5.[50]");
|
||||
case SOLARIS:
|
||||
return !input.is64Bit;
|
||||
case CENTOS:
|
||||
return !input.version.equals("") && !input.version.matches("5.[50]");
|
||||
case UBUNTU:
|
||||
return !input.version.equals("") && !input.version.equals("10.04") && !input.version.equals("8.04");
|
||||
case WINDOWS:
|
||||
return !input.version.equals("") && !input.version.equals("2003 R2") //
|
||||
&& !(input.version.equals("2008") && !input.is64Bit) //
|
||||
&& !(input.version.matches("2008( R2)?") && input.is64Bit);
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -18,8 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.terremark;
|
||||
|
||||
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.vcloud.terremark.options.AddInternetServiceOptions.Builder.disabled;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
|
@ -28,6 +27,7 @@ import java.lang.reflect.Method;
|
|||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
@ -37,6 +37,7 @@ import org.jclouds.http.HttpRequest;
|
|||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
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.internal.RestAnnotationProcessor;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.jclouds.vcloud.CommonVCloudClient;
|
||||
import org.jclouds.vcloud.VCloudExpressAsyncClientTest.VCloudRestClientModuleExtension.TestOrgCatalogItemSupplier;
|
||||
import org.jclouds.vcloud.VCloudExpressAsyncClientTest.VCloudRestClientModuleExtension.TestOrgCatalogSupplier;
|
||||
import org.jclouds.vcloud.VCloudExpressLoginAsyncClient;
|
||||
import org.jclouds.vcloud.VCloudMediaType;
|
||||
import org.jclouds.vcloud.VCloudVersionsAsyncClient;
|
||||
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.ReferenceType;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
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.CatalogItemImpl;
|
||||
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
|
||||
import org.jclouds.vcloud.domain.network.NetworkConfig;
|
||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
||||
|
@ -85,12 +86,12 @@ import org.jclouds.vcloud.xml.VCloudExpressCatalogHandler;
|
|||
import org.jclouds.vcloud.xml.VCloudExpressVAppHandler;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
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.ImmutableSet;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
|
@ -99,10 +100,16 @@ import com.google.inject.TypeLiteral;
|
|||
*
|
||||
* @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")
|
||||
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 {
|
||||
Method method = TerremarkVCloudExpressAsyncClient.class.getMethod("getCatalogItem", URI.class);
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
|
@ -631,160 +638,181 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
|
|||
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
|
||||
@ConfiguresRestClient
|
||||
protected static class TerremarkVCloudRestClientModuleExtension extends TerremarkVCloudExpressRestClientModule {
|
||||
|
||||
@Override
|
||||
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService,
|
||||
@Named(PROPERTY_API_VERSION) String version) {
|
||||
return URI.create("https://vcloud/login");
|
||||
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(OrgNameToKeysListSupplier.class).to(TestOrgNameToKeysListSupplier.class);
|
||||
bind(OrgMapSupplier.class).to(TestTerremarkOrgMapSupplier.class);
|
||||
bind(OrgMapSupplier.class).to(TestOrgMapSupplier.class);
|
||||
bind(OrgCatalogSupplier.class).to(TestOrgCatalogSupplier.class);
|
||||
bind(OrgCatalogItemSupplier.class).to(TestOrgCatalogItemSupplier.class);
|
||||
bind(OrgVDCSupplier.class).to(TestTerremarkOrgVDCSupplier.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected URI provideOrg(@org.jclouds.vcloud.endpoints.Org Iterable<ReferenceType> orgs) {
|
||||
return URI.create("https://vcloud.safesecureweb.com/api/v0.8/org/1");
|
||||
}
|
||||
|
||||
@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, @Named(PROPERTY_IDENTITY) String user) {
|
||||
return null;
|
||||
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 TestOrgNameToKeysListSupplier extends OrgNameToKeysListSupplier {
|
||||
public static class TestOrgMapSupplier extends OrgMapSupplier {
|
||||
|
||||
@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"));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class TestTerremarkOrgMapSupplier extends OrgMapSupplier {
|
||||
@Inject
|
||||
protected TestTerremarkOrgMapSupplier() {
|
||||
protected TestOrgMapSupplier() {
|
||||
super(null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Org> get() {
|
||||
return ImmutableMap.<String, Org> of(
|
||||
"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"))));
|
||||
return ImmutableMap.<String, Org> of(ORG.getName(), ORG);
|
||||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class TestTerremarkOrgVDCSupplier extends OrgVDCSupplier {
|
||||
public static class TestOrgCatalogSupplier extends OrgCatalogSupplier {
|
||||
@Inject
|
||||
protected TestTerremarkOrgVDCSupplier() {
|
||||
protected TestOrgCatalogSupplier() {
|
||||
super(null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
|
||||
return ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> of("org",
|
||||
|
||||
ImmutableMap.<String, org.jclouds.vcloud.domain.VDC> of(
|
||||
"vdc",
|
||||
new TerremarkVDCImpl("vdc", null, URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"),
|
||||
VDCStatus.READY, null, "description", ImmutableSet.<Task> of(), AllocationModel.UNRECOGNIZED,
|
||||
new Capacity("MB", 0, 0, 0, 0), new Capacity("MB", 0, 0, 0, 0), new Capacity("MB", 0, 0, 0, 0),
|
||||
ImmutableMap.<String, ReferenceType> of(
|
||||
"vapp",
|
||||
new ReferenceTypeImpl("vapp", "application/vnd.vmware.vcloud.vApp+xml", URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1")),
|
||||
"network",
|
||||
new ReferenceTypeImpl("network", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2"))), ImmutableMap
|
||||
.<String, ReferenceType> of(), 0, 0, 0, false, new ReferenceTypeImpl("catalog",
|
||||
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")))));
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected URI provideDefaultTasksList(Org org) {
|
||||
return URI.create("https://taskslist");
|
||||
@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()))));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@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.assertNotNull;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
@ -51,16 +50,6 @@ public class TerremarkVCloudExpressClientLiveTest extends TerremarkClientLiveTes
|
|||
|
||||
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
|
||||
protected void prepare() {
|
||||
TerremarkVCloudExpressClient vCloudExpressClient = TerremarkVCloudExpressClient.class.cast(tmClient);
|
||||
|
@ -74,13 +63,12 @@ public class TerremarkVCloudExpressClientLiveTest extends TerremarkClientLiveTes
|
|||
key = vCloudExpressClient.generateKeyPairInOrg(org.getHref(), "livetest", false);
|
||||
}
|
||||
assertNotNull(key);
|
||||
System.err.println(key);
|
||||
assertEquals(key.getName(), "livetest");
|
||||
assertNotNull(key.getPrivateKey());
|
||||
assertNotNull(key.getFingerPrint());
|
||||
assertEquals(key.isDefault(), false);
|
||||
assertEquals(key.getFingerPrint(), vCloudExpressClient.findKeyPairInOrg(org.getHref(), key.getName())
|
||||
.getFingerPrint());
|
||||
.getFingerPrint());
|
||||
}
|
||||
|
||||
@AfterTest
|
||||
|
@ -103,7 +91,7 @@ public class TerremarkVCloudExpressClientLiveTest extends TerremarkClientLiveTes
|
|||
|
||||
@Override
|
||||
protected Entry<InternetService, PublicIpAddress> getNewInternetServiceAndIpForSSH(VCloudExpressVApp vApp) {
|
||||
return new TerremarkVCloudExpressInternetServiceAndPublicIpAddressSupplier(TerremarkVCloudExpressClient.class
|
||||
.cast(tmClient)).getNewInternetServiceAndIp(vApp, 22, Protocol.TCP);
|
||||
return new TerremarkVCloudExpressInternetServiceAndPublicIpAddressSupplier(
|
||||
TerremarkVCloudExpressClient.class.cast(tmClient)).getNewInternetServiceAndIp(vApp, 22, Protocol.TCP);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,13 +60,6 @@ public class TerremarkVCloudExpressComputeServiceLiveTest extends BaseComputeSer
|
|||
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
|
||||
public void testListImages() throws Exception {
|
||||
for (Image image : client.listImages()) {
|
||||
|
|
Loading…
Reference in New Issue