merged changes from upstream

This commit is contained in:
David Ribeiro Alves 2012-03-04 18:08:19 +00:00
commit af662850a9
343 changed files with 22172 additions and 3476 deletions

1
.gitignore vendored
View File

@ -13,3 +13,4 @@ bin/
*.iws *.iws
*.DS_STORE *.DS_STORE
TAGS TAGS
.metadata/

View File

@ -30,6 +30,11 @@
<artifactId>jclouds-allloadbalancer</artifactId> <artifactId>jclouds-allloadbalancer</artifactId>
<name>allloadbalancer</name> <name>allloadbalancer</name>
<dependencies> <dependencies>
<dependency>
<groupId>org.jclouds.provider</groupId>
<artifactId>cloudloadbalancers-uk</artifactId>
<version>${project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.jclouds.provider</groupId> <groupId>org.jclouds.provider</groupId>
<artifactId>cloudloadbalancers-us</artifactId> <artifactId>cloudloadbalancers-us</artifactId>

View File

@ -72,7 +72,7 @@
<dependency> <dependency>
<groupId>org.yaml</groupId> <groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId> <artifactId>snakeyaml</artifactId>
<version>1.8</version> <version>1.10</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -62,6 +62,7 @@ import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.collect.ImmutableSet.Builder; import com.google.common.collect.ImmutableSet.Builder;
import com.google.common.util.concurrent.UncheckedExecutionException; import com.google.common.util.concurrent.UncheckedExecutionException;
@ -186,21 +187,28 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
@VisibleForTesting @VisibleForTesting
String getGroupForInstance(final RunningInstance instance) { String getGroupForInstance(final RunningInstance instance) {
String group = parseGroupFrom(instance, instance.getGroupIds());
if(group == null && instance.getKeyName() != null) {
// when not using a generated security group, e.g. in VPC, try from key:
group = parseGroupFrom(instance, Sets.newHashSet(instance.getKeyName()));
}
return group;
}
private String parseGroupFrom(final RunningInstance instance, final Set<String> data) {
String group = null; String group = null;
try { try {
group = Iterables.getOnlyElement(Iterables.filter(instance.getGroupIds(), new Predicate<String>() { group = Iterables.getOnlyElement(Iterables.filter(data, new Predicate<String>() {
@Override @Override
public boolean apply(String input) { public boolean apply(String input) {
return input.startsWith("jclouds#") && input.endsWith("#" + instance.getRegion()); return input.startsWith("jclouds#") && input.contains("#" + instance.getRegion());
} }
})).split("#")[1];
})).substring(8).replaceAll("#" + instance.getRegion() + "$", "");
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
logger.debug("no group parsed from %s's security groups: %s", instance.getId(), instance.getGroupIds()); logger.debug("no group parsed from %s's data: %s", instance.getId(), data);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
logger.debug("too many groups match %s; %s's security groups: %s", "jclouds#", instance.getId(), instance logger.debug("too many groups match %s; %s's data: %s", "jclouds#", instance.getId(), data);
.getGroupIds());
} }
return group; return group;
} }

View File

@ -217,6 +217,20 @@ public class RunningInstanceToNodeMetadataTest {
.hardware(m1_small32().build()).location(provider).build()); .hardware(m1_small32().build()).location(provider).build());
} }
@Test
public void testGroupNameIsSetWhenCustomKeyNameIsSetAndSecurityGroupIsGenerated() {
checkGroupName(RunningInstance.builder().instanceId("id").imageId("image").instanceType("m1.small")
.instanceState(InstanceState.RUNNING).region("us-east-1").keyName("custom-key")
.groupId("jclouds#groupname#us-east-1").build());
}
@Test
public void testGroupNameIsSetWhenCustomSecurityGroupIsSetAndKeyNameIsGenerated() {
checkGroupName(RunningInstance.builder().instanceId("id").imageId("image").instanceType("m1.small")
.instanceState(InstanceState.RUNNING).region("us-east-1").groupId("custom-sec")
.keyName("jclouds#groupname#us-east-1#23").build());
}
protected RunningInstance firstInstanceFromResource(String resource) { protected RunningInstance firstInstanceFromResource(String resource) {
RunningInstance server = Iterables.get(Iterables.get(DescribeInstancesResponseHandlerTest RunningInstance server = Iterables.get(Iterables.get(DescribeInstancesResponseHandlerTest
.parseRunningInstances(resource), 0), 0); .parseRunningInstances(resource), 0), 0);
@ -239,6 +253,12 @@ public class RunningInstanceToNodeMetadataTest {
return createNodeParser(hardware, locations, credentialStore, instanceToNodeState, instanceToImage); return createNodeParser(hardware, locations, credentialStore, instanceToNodeState, instanceToImage);
} }
private void checkGroupName(RunningInstance instance) {
assertEquals("groupname", createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet
.<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of())
.apply(instance).getGroup());
}
private RunningInstanceToNodeMetadata createNodeParser(final ImmutableSet<Hardware> hardware, private RunningInstanceToNodeMetadata createNodeParser(final ImmutableSet<Hardware> hardware,
final ImmutableSet<Location> locations, Map<String, Credentials> credentialStore, final ImmutableSet<Location> locations, Map<String, Credentials> credentialStore,
Map<InstanceState, NodeState> instanceToNodeState, LoadingCache<RegionAndName, Image> instanceToImage) { Map<InstanceState, NodeState> instanceToNodeState, LoadingCache<RegionAndName, Image> instanceToImage) {

View File

@ -46,7 +46,7 @@
<dependency> <dependency>
<groupId>com.jamesmurty.utils</groupId> <groupId>com.jamesmurty.utils</groupId>
<artifactId>java-xmlbuilder</artifactId> <artifactId>java-xmlbuilder</artifactId>
<version>0.3</version> <version>0.4</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jclouds.common</groupId> <groupId>org.jclouds.common</groupId>

View File

@ -48,7 +48,7 @@
<dependency> <dependency>
<groupId>com.jamesmurty.utils</groupId> <groupId>com.jamesmurty.utils</groupId>
<artifactId>java-xmlbuilder</artifactId> <artifactId>java-xmlbuilder</artifactId>
<version>0.3</version> <version>0.4</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jclouds</groupId> <groupId>org.jclouds</groupId>

View File

@ -52,6 +52,7 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.jamesmurty.utils.XMLBuilder; import com.jamesmurty.utils.XMLBuilder;
@ -67,7 +68,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
protected final String ns; protected final String ns;
protected final String schema; protected final String schema;
protected final BindToStringPayload stringBinder; protected final BindToStringPayload stringBinder;
protected final ReferenceType defaultNetwork; protected final Supplier<ReferenceType> defaultNetwork;
protected final FenceMode defaultFenceMode; protected final FenceMode defaultFenceMode;
protected final LoadingCache<URI, VAppTemplate> templateCache; protected final LoadingCache<URI, VAppTemplate> templateCache;
protected final Function<VAppTemplate, String> defaultNetworkNameInTemplate; protected final Function<VAppTemplate, String> defaultNetworkNameInTemplate;
@ -76,7 +77,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
public BindInstantiateVAppTemplateParamsToXmlPayload(LoadingCache<URI, VAppTemplate> templateCache, public BindInstantiateVAppTemplateParamsToXmlPayload(LoadingCache<URI, VAppTemplate> templateCache,
@Network Function<VAppTemplate, String> defaultNetworkNameInTemplate, BindToStringPayload stringBinder, @Network Function<VAppTemplate, String> defaultNetworkNameInTemplate, BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema,
@Network ReferenceType network, FenceMode fenceMode) { @Network Supplier<ReferenceType> network, FenceMode fenceMode) {
this.templateCache = templateCache; this.templateCache = templateCache;
this.defaultNetworkNameInTemplate = defaultNetworkNameInTemplate; this.defaultNetworkNameInTemplate = defaultNetworkNameInTemplate;
this.ns = ns; this.ns = ns;
@ -98,7 +99,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
Set<NetworkConfig> networkConfig = null; Set<NetworkConfig> networkConfig = null;
NetworkConfigDecorator networkConfigDecorator = new NetworkConfigDecorator(templateCache.getUnchecked(template), NetworkConfigDecorator networkConfigDecorator = new NetworkConfigDecorator(templateCache.getUnchecked(template),
defaultNetwork.getHref(), defaultFenceMode, defaultNetworkNameInTemplate); defaultNetwork.get().getHref(), defaultFenceMode, defaultNetworkNameInTemplate);
InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest); InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest);

View File

@ -51,6 +51,8 @@ import org.jclouds.vcloud.functions.VAppTemplatesInOrg;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Provides; import com.google.inject.Provides;
@ -108,8 +110,16 @@ public class VCloudComputeServiceDependenciesModule extends AbstractModule {
@Provides @Provides
@Singleton @Singleton
public NetworkConfig networkConfig(@Network ReferenceType network, FenceMode defaultFenceMode) { public Supplier<NetworkConfig> networkConfig(@Network Supplier<ReferenceType> network,
return new NetworkConfig(network.getName(), network.getHref(), defaultFenceMode); final FenceMode defaultFenceMode) {
return Suppliers.compose(new Function<ReferenceType, NetworkConfig>() {
@Override
public NetworkConfig apply(ReferenceType input) {
return new NetworkConfig(input.getName(), input.getHref(), defaultFenceMode);
}
}, network);
} }
} }

View File

@ -57,6 +57,7 @@ import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -72,13 +73,13 @@ public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployA
protected final VCloudClient client; protected final VCloudClient client;
protected final Predicate<URI> successTester; protected final Predicate<URI> successTester;
protected final LoadingCache<URI, VAppTemplate> vAppTemplates; protected final LoadingCache<URI, VAppTemplate> vAppTemplates;
protected final NetworkConfig defaultNetworkConfig; protected final Supplier<NetworkConfig> defaultNetworkConfig;
protected final String buildVersion; protected final String buildVersion;
@Inject @Inject
protected InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn(VCloudClient client, protected InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn(VCloudClient client,
Predicate<URI> successTester, LoadingCache<URI, VAppTemplate> vAppTemplates, Predicate<URI> successTester, LoadingCache<URI, VAppTemplate> vAppTemplates,
NetworkConfig defaultNetworkConfig, @Named(PROPERTY_BUILD_VERSION) String buildVersion) { Supplier<NetworkConfig> defaultNetworkConfig, @Named(PROPERTY_BUILD_VERSION) String buildVersion) {
this.client = client; this.client = client;
this.successTester = successTester; this.successTester = successTester;
this.vAppTemplates = vAppTemplates; this.vAppTemplates = vAppTemplates;
@ -142,9 +143,9 @@ public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployA
// if we only have a disconnected network, let's add a new section for the upstream // if we only have a disconnected network, let's add a new section for the upstream
// TODO: remove the disconnected entry // TODO: remove the disconnected entry
if (networkWithNoIpAllocation.apply(networkToConnect)) if (networkWithNoIpAllocation.apply(networkToConnect))
config = defaultNetworkConfig; config = defaultNetworkConfig.get();
else else
config = defaultNetworkConfig.toBuilder().networkName(networkToConnect.getName()).build(); config = defaultNetworkConfig.get().toBuilder().networkName(networkToConnect.getName()).build();
// note that in VCD 1.5, the network name after instantiation will be the same as the parent // note that in VCD 1.5, the network name after instantiation will be the same as the parent
InstantiateVAppTemplateOptions options = addNetworkConfig(config); InstantiateVAppTemplateOptions options = addNetworkConfig(config);

View File

@ -34,13 +34,14 @@ import org.jclouds.vcloud.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfig
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class DefaultOrgForUser implements Function<String, ReferenceType> { public class DefaultOrgForUser implements Function<String, Supplier<ReferenceType>> {
private final OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault selector; private final OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault selector;
private final Supplier<VCloudSession> sessionSupplier; private final Supplier<VCloudSession> sessionSupplier;
@ -55,10 +56,16 @@ public class DefaultOrgForUser implements Function<String, ReferenceType> {
} }
@Override @Override
public ReferenceType apply(String user) { public Supplier<ReferenceType> apply(final String user) {
VCloudSession session = sessionSupplier.get(); return Suppliers.compose(new Function<VCloudSession, ReferenceType>() {
@Override
public ReferenceType apply(VCloudSession session) {
checkState(session != null, "could not retrieve Session at %s", user); checkState(session != null, "could not retrieve Session at %s", user);
return selector.apply(session.getOrgs().values()); return selector.apply(session.getOrgs().values());
} }
}, sessionSupplier);
}
} }

View File

@ -57,7 +57,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
@Provides @Provides
@org.jclouds.vcloud.endpoints.Org @org.jclouds.vcloud.endpoints.Org
@Singleton @Singleton
protected ReferenceType provideDefaultOrg(DefaultOrgForUser defaultOrgURIForUser, protected Supplier<ReferenceType> provideDefaultOrg(DefaultOrgForUser defaultOrgURIForUser,
@Named(PROPERTY_IDENTITY) String user) { @Named(PROPERTY_IDENTITY) String user) {
return defaultOrgURIForUser.apply(user); return defaultOrgURIForUser.apply(user);
} }
@ -72,17 +72,17 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
@Provides @Provides
@org.jclouds.vcloud.endpoints.TasksList @org.jclouds.vcloud.endpoints.TasksList
@Singleton @Singleton
protected ReferenceType provideDefaultTasksList(DefaultTasksListForOrg defaultTasksListURIForOrg, protected Supplier<ReferenceType> provideDefaultTasksList(DefaultTasksListForOrg defaultTasksListURIForOrg,
@org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) { @org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) {
return defaultTasksListURIForOrg.apply(defaultOrg); return Suppliers.compose(defaultTasksListURIForOrg, defaultOrg);
} }
@Provides @Provides
@org.jclouds.vcloud.endpoints.Catalog @org.jclouds.vcloud.endpoints.Catalog
@Singleton @Singleton
protected ReferenceType provideDefaultCatalog(DefaultCatalogForOrg defaultCatalogURIForOrg, protected Supplier<ReferenceType> provideDefaultCatalog(DefaultCatalogForOrg defaultCatalogURIForOrg,
@org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) { @org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) {
return defaultCatalogURIForOrg.apply(defaultOrg); return Suppliers.compose(defaultCatalogURIForOrg, defaultOrg);
} }
@Provides @Provides
@ -146,9 +146,9 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
@Provides @Provides
@org.jclouds.vcloud.endpoints.VDC @org.jclouds.vcloud.endpoints.VDC
@Singleton @Singleton
protected ReferenceType provideDefaultVDC(DefaultVDCForOrg defaultVDCURIForOrg, protected Supplier<ReferenceType> provideDefaultVDC(DefaultVDCForOrg defaultVDCURIForOrg,
@org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) { @org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) {
return defaultVDCURIForOrg.apply(defaultOrg); return Suppliers.compose(defaultVDCURIForOrg, defaultOrg);
} }
@Provides @Provides
@ -161,9 +161,9 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
@Provides @Provides
@org.jclouds.vcloud.endpoints.Network @org.jclouds.vcloud.endpoints.Network
@Singleton @Singleton
protected ReferenceType provideDefaultNetwork(DefaultNetworkForVDC defaultNetworkURIForVDC, protected Supplier<ReferenceType> provideDefaultNetwork(DefaultNetworkForVDC defaultNetworkURIForVDC,
@org.jclouds.vcloud.endpoints.VDC ReferenceType defaultVDC) { @org.jclouds.vcloud.endpoints.VDC Supplier<ReferenceType> defaultVDC) {
return defaultNetworkURIForVDC.apply(defaultVDC); return Suppliers.compose(defaultNetworkURIForVDC, defaultVDC);
} }
@Provides @Provides

View File

@ -316,8 +316,15 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
@VCloudToken @VCloudToken
@Provides @Provides
String provideVCloudToken(Supplier<VCloudSession> cache) { @Singleton
return checkNotNull(cache.get().getVCloudToken(), "No token present in session"); Supplier<String> provideVCloudToken(Supplier<VCloudSession> cache) {
return Suppliers.compose(new Function<VCloudSession, String>() {
@Override
public String apply(VCloudSession input) {
return checkNotNull(input.getVCloudToken(), "No token present in session");
}
}, cache);
} }
@Provides @Provides
@ -419,9 +426,16 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
@Provides @Provides
@Singleton @Singleton
protected Org provideOrg(Supplier<Map<String, Org>> orgSupplier, protected Supplier<Org> provideOrg(final Supplier<Map<String, Org>> orgSupplier,
@org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) { @org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) {
return orgSupplier.get().get(defaultOrg.getName()); return Suppliers.compose(new Function<ReferenceType, Org>() {
@Override
public Org apply(ReferenceType input) {
return orgSupplier.get().get(input.getName());
}
}, defaultOrg);
} }
@Provides @Provides

View File

@ -19,7 +19,6 @@
package org.jclouds.vcloud.filters; package org.jclouds.vcloud.filters;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
@ -29,6 +28,8 @@ import org.jclouds.http.HttpRequestFilter;
import org.jclouds.http.utils.ModifyRequest; import org.jclouds.http.utils.ModifyRequest;
import org.jclouds.vcloud.VCloudToken; import org.jclouds.vcloud.VCloudToken;
import com.google.common.base.Supplier;
/** /**
* Adds the VCloud Token to the request as a cookie * Adds the VCloud Token to the request as a cookie
* *
@ -37,10 +38,10 @@ import org.jclouds.vcloud.VCloudToken;
*/ */
@Singleton @Singleton
public class SetVCloudTokenCookie implements HttpRequestFilter { public class SetVCloudTokenCookie implements HttpRequestFilter {
private Provider<String> vcloudTokenProvider; private Supplier<String> vcloudTokenProvider;
@Inject @Inject
public SetVCloudTokenCookie(@VCloudToken Provider<String> authTokenProvider) { public SetVCloudTokenCookie(@VCloudToken Supplier<String> authTokenProvider) {
this.vcloudTokenProvider = authTokenProvider; this.vcloudTokenProvider = authTokenProvider;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -41,11 +41,11 @@ import com.google.common.base.Supplier;
@Singleton @Singleton
public class OrgNameToTasksListEndpoint implements Function<Object, URI> { public class OrgNameToTasksListEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, Org>> orgMap; private final Supplier<Map<String, Org>> orgMap;
private final ReferenceType defaultTasksList; private final Supplier<ReferenceType> defaultTasksList;
@Inject @Inject
public OrgNameToTasksListEndpoint(Supplier<Map<String, Org>> orgMap, public OrgNameToTasksListEndpoint(Supplier<Map<String, Org>> orgMap,
@TasksList ReferenceType defaultTasksList) { @TasksList Supplier<ReferenceType> defaultTasksList) {
this.orgMap = orgMap; this.orgMap = orgMap;
this.defaultTasksList = defaultTasksList; this.defaultTasksList = defaultTasksList;
} }
@ -53,7 +53,7 @@ public class OrgNameToTasksListEndpoint implements Function<Object, URI> {
public URI apply(Object from) { public URI apply(Object from) {
Object org = from; Object org = from;
if (org == null) if (org == null)
return defaultTasksList.getHref(); return defaultTasksList.get().getHref();
try { try {
return checkNotNull(orgMap.get().get(org)).getTasksList().getHref(); return checkNotNull(orgMap.get().get(org)).getTasksList().getHref();
} catch (NullPointerException e) { } catch (NullPointerException e) {

View File

@ -40,7 +40,7 @@ public class OrgNameVDCNameNetworkNameToEndpoint extends OrgNameVDCNameResourceN
@Inject @Inject
public OrgNameVDCNameNetworkNameToEndpoint( public OrgNameVDCNameNetworkNameToEndpoint(
Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.VDC>>> orgVDCMap, Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.VDC>>> orgVDCMap,
@Org ReferenceType defaultOrg, @VDC ReferenceType defaultVDC) { @Org Supplier<ReferenceType> defaultOrg, @VDC Supplier<ReferenceType> defaultVDC) {
super(orgVDCMap, defaultOrg, defaultVDC); super(orgVDCMap, defaultOrg, defaultVDC);
} }

View File

@ -40,7 +40,7 @@ public class OrgNameVDCNameResourceEntityNameToEndpoint extends OrgNameVDCNameRe
@Inject @Inject
public OrgNameVDCNameResourceEntityNameToEndpoint( public OrgNameVDCNameResourceEntityNameToEndpoint(
Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.VDC>>> orgVDCMap, Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.VDC>>> orgVDCMap,
@Org ReferenceType defaultOrg, @VDC ReferenceType defaultVDC) { @Org Supplier<ReferenceType> defaultOrg, @VDC Supplier<ReferenceType> defaultVDC) {
super(orgVDCMap, defaultOrg, defaultVDC); super(orgVDCMap, defaultOrg, defaultVDC);
} }

View File

@ -41,13 +41,13 @@ import com.google.common.collect.Iterables;
public abstract class OrgNameVDCNameResourceNameToEndpoint implements Function<Object, URI>{ public abstract class OrgNameVDCNameResourceNameToEndpoint implements Function<Object, URI>{
protected final Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.VDC>>> orgVDCMap; protected final Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.VDC>>> orgVDCMap;
protected final ReferenceType defaultOrg; protected final Supplier<ReferenceType> defaultOrg;
protected final ReferenceType defaultVDC; protected final Supplier<ReferenceType> defaultVDC;
@Inject @Inject
public OrgNameVDCNameResourceNameToEndpoint( public OrgNameVDCNameResourceNameToEndpoint(
Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.VDC>>> orgVDCMap, Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.VDC>>> orgVDCMap,
@Org ReferenceType defaultOrg, @org.jclouds.vcloud.endpoints.VDC ReferenceType defaultVDC) { @Org Supplier<ReferenceType> defaultOrg, @org.jclouds.vcloud.endpoints.VDC Supplier<ReferenceType> defaultVDC) {
this.orgVDCMap = orgVDCMap; this.orgVDCMap = orgVDCMap;
this.defaultOrg = defaultOrg; this.defaultOrg = defaultOrg;
this.defaultVDC = defaultVDC; this.defaultVDC = defaultVDC;
@ -60,9 +60,9 @@ public abstract class OrgNameVDCNameResourceNameToEndpoint implements Function<
Object vDC = Iterables.get(orgVDC, 1); Object vDC = Iterables.get(orgVDC, 1);
Object resource = Iterables.get(orgVDC, 2); Object resource = Iterables.get(orgVDC, 2);
if (org == null) if (org == null)
org = defaultOrg.getName(); org = defaultOrg.get().getName();
if (vDC == null) if (vDC == null)
vDC = defaultVDC.getName(); vDC = defaultVDC.get().getName();
Map<String, Map<String, org.jclouds.vcloud.domain.VDC>> orgToVDCs = orgVDCMap.get(); Map<String, Map<String, org.jclouds.vcloud.domain.VDC>> orgToVDCs = orgVDCMap.get();
checkState(orgToVDCs != null, "could not get map of org name to vdcs!"); checkState(orgToVDCs != null, "could not get map of org name to vdcs!");
Map<String, org.jclouds.vcloud.domain.VDC> vDCs = orgToVDCs.get(org); Map<String, org.jclouds.vcloud.domain.VDC> vDCs = orgToVDCs.get(org);

View File

@ -55,15 +55,16 @@ public class DefaultVDC implements ImplicitLocationSupplier {
@Singleton @Singleton
public static class IsDefaultVDC implements Predicate<Location> { public static class IsDefaultVDC implements Predicate<Location> {
private final ReferenceType defaultVDC; private final Supplier<ReferenceType> defaultVDCSupplier;
@Inject @Inject
IsDefaultVDC(@VDC ReferenceType defaultVDC) { IsDefaultVDC(@VDC Supplier<ReferenceType> defaultVDCSupplier) {
this.defaultVDC = checkNotNull(defaultVDC, "defaultVDC"); this.defaultVDCSupplier = checkNotNull(defaultVDCSupplier, "defaultVDCSupplier");
} }
@Override @Override
public boolean apply(Location input) { public boolean apply(Location input) {
ReferenceType defaultVDC = defaultVDCSupplier.get();
return input.getScope() == LocationScope.ZONE && input.getId().equals(defaultVDC.getHref().toASCIIString()); return input.getScope() == LocationScope.ZONE && input.getId().equals(defaultVDC.getHref().toASCIIString());
} }

View File

@ -49,6 +49,8 @@ import org.testng.annotations.Test;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Functions; import com.google.common.base.Functions;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
@ -102,9 +104,9 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
@Network @Network
@Provides @Provides
@Singleton @Singleton
ReferenceType provideNetwork() { Supplier<ReferenceType> provideNetwork() {
return new ReferenceTypeImpl(null, null, URI return Suppliers.<ReferenceType>ofInstance(new ReferenceTypeImpl(null, null, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/network/1990")); .create("https://vcenterprise.bluelock.com/api/v1.0/network/1990")));
} }
})); }));
} }

View File

@ -22,7 +22,6 @@ import static org.testng.Assert.assertEquals;
import java.net.URI; import java.net.URI;
import javax.inject.Provider;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
@ -30,6 +29,8 @@ import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Supplier;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
@ -40,7 +41,7 @@ public class SetVCloudTokenCookieTest {
@BeforeTest @BeforeTest
void setUp() { void setUp() {
filter = new SetVCloudTokenCookie(new Provider<String>() { filter = new SetVCloudTokenCookie(new Supplier<String>() {
public String get() { public String get() {
return "token"; return "token";
} }

View File

@ -139,9 +139,9 @@ public abstract class BaseVCloudAsyncClientTest<T> extends RestClientTest<T> {
} }
@Override @Override
protected Org provideOrg(Supplier<Map<String, Org>> orgSupplier, protected Supplier<Org> provideOrg(Supplier<Map<String, Org>> orgSupplier,
@org.jclouds.vcloud.endpoints.Org ReferenceType defaultOrg) { @org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg) {
return ORG; return Suppliers.ofInstance(ORG);
} }
@Override @Override
@ -150,14 +150,18 @@ public abstract class BaseVCloudAsyncClientTest<T> extends RestClientTest<T> {
@Override @Override
protected void configure() { protected void configure() {
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.Org.class).toInstance(ORG_REF); TypeLiteral<Supplier<ReferenceType>> refTypeSupplier = new TypeLiteral<Supplier<ReferenceType>>() {
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.Catalog.class).toInstance( };
CATALOG_REF); bind(refTypeSupplier).annotatedWith(org.jclouds.vcloud.endpoints.Org.class).toInstance(
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.TasksList.class).toInstance( Suppliers.<ReferenceType> ofInstance(ORG_REF));
TASKSLIST_REF); bind(refTypeSupplier).annotatedWith(org.jclouds.vcloud.endpoints.Catalog.class).toInstance(
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.VDC.class).toInstance(VDC_REF); Suppliers.<ReferenceType> ofInstance(CATALOG_REF));
bind(ReferenceType.class).annotatedWith(org.jclouds.vcloud.endpoints.Network.class).toInstance( bind(refTypeSupplier).annotatedWith(org.jclouds.vcloud.endpoints.TasksList.class).toInstance(
NETWORK_REF); Suppliers.<ReferenceType> ofInstance(TASKSLIST_REF));
bind(refTypeSupplier).annotatedWith(org.jclouds.vcloud.endpoints.VDC.class).toInstance(
Suppliers.<ReferenceType> ofInstance(VDC_REF));
bind(refTypeSupplier).annotatedWith(org.jclouds.vcloud.endpoints.Network.class).toInstance(
Suppliers.<ReferenceType> ofInstance(NETWORK_REF));
} }
}); });

View File

@ -43,7 +43,7 @@
<dependency> <dependency>
<groupId>com.jamesmurty.utils</groupId> <groupId>com.jamesmurty.utils</groupId>
<artifactId>java-xmlbuilder</artifactId> <artifactId>java-xmlbuilder</artifactId>
<version>0.3</version> <version>0.4</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jclouds</groupId> <groupId>org.jclouds</groupId>

View File

@ -48,6 +48,7 @@ import org.jclouds.trmk.vcloud_0_8.endpoints.Network;
import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions; import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions;
import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions.NetworkConfig; import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions.NetworkConfig;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
@ -67,13 +68,13 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
private final BindToStringPayload stringBinder; private final BindToStringPayload stringBinder;
protected final Map<ResourceType, String> virtualHardwareToInstanceId = ImmutableMap.of(ResourceType.PROCESSOR, "1", protected final Map<ResourceType, String> virtualHardwareToInstanceId = ImmutableMap.of(ResourceType.PROCESSOR, "1",
ResourceType.MEMORY, "2", ResourceType.DISK_DRIVE, "9"); ResourceType.MEMORY, "2", ResourceType.DISK_DRIVE, "9");
private final ReferenceType defaultNetwork; private final Supplier<ReferenceType> defaultNetwork;
private final String defaultFenceMode; private final String defaultFenceMode;
@Inject @Inject
public BindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder, public BindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema,
@Network ReferenceType network, @Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode) { @Network Supplier<ReferenceType> network, @Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode) {
this.ns = ns; this.ns = ns;
this.schema = schema; this.schema = schema;
this.stringBinder = stringBinder; this.stringBinder = stringBinder;
@ -93,7 +94,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
SortedMap<ResourceType, String> virtualHardwareQuantity = Maps.newTreeMap(); SortedMap<ResourceType, String> virtualHardwareQuantity = Maps.newTreeMap();
InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest); InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest);
String network = (defaultNetwork != null) ? defaultNetwork.getHref().toASCIIString() : null; String network = (defaultNetwork != null) ? defaultNetwork.get().getHref().toASCIIString() : null;
String fenceMode = defaultFenceMode; String fenceMode = defaultFenceMode;
String networkName = name; String networkName = name;
if (options != null) { if (options != null) {

View File

@ -34,13 +34,14 @@ import org.jclouds.trmk.vcloud_0_8.suppliers.OnlyReferenceTypeFirstWithNameMatch
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class DefaultOrgForUser implements Function<String, ReferenceType> { public class DefaultOrgForUser implements Function<String, Supplier<ReferenceType>> {
private final OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault selector; private final OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault selector;
private final Supplier<VCloudSession> sessionSupplier; private final Supplier<VCloudSession> sessionSupplier;
@ -55,10 +56,16 @@ public class DefaultOrgForUser implements Function<String, ReferenceType> {
} }
@Override @Override
public ReferenceType apply(String user) { public Supplier<ReferenceType> apply(final String user) {
VCloudSession session = sessionSupplier.get(); return Suppliers.compose(new Function<VCloudSession, ReferenceType>() {
@Override
public ReferenceType apply(VCloudSession session) {
checkState(session != null, "could not retrieve Session at %s", user); checkState(session != null, "could not retrieve Session at %s", user);
return selector.apply(session.getOrgs().values()); return selector.apply(session.getOrgs().values());
} }
}, sessionSupplier);
}
} }

View File

@ -54,7 +54,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
@Provides @Provides
@org.jclouds.trmk.vcloud_0_8.endpoints.Org @org.jclouds.trmk.vcloud_0_8.endpoints.Org
@Singleton @Singleton
protected ReferenceType provideDefaultOrg(DefaultOrgForUser defaultOrgURIForUser, protected Supplier<ReferenceType> provideDefaultOrg(DefaultOrgForUser defaultOrgURIForUser,
@Named(PROPERTY_IDENTITY) String user) { @Named(PROPERTY_IDENTITY) String user) {
return defaultOrgURIForUser.apply(user); return defaultOrgURIForUser.apply(user);
} }
@ -69,9 +69,9 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
@Provides @Provides
@org.jclouds.trmk.vcloud_0_8.endpoints.TasksList @org.jclouds.trmk.vcloud_0_8.endpoints.TasksList
@Singleton @Singleton
protected ReferenceType provideDefaultTasksList(DefaultTasksListForOrg defaultTasksListURIForOrg, protected Supplier<ReferenceType> provideDefaultTasksList(DefaultTasksListForOrg defaultTasksListURIForOrg,
@org.jclouds.trmk.vcloud_0_8.endpoints.Org ReferenceType defaultOrg) { @org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) {
return defaultTasksListURIForOrg.apply(defaultOrg); return Suppliers.compose(defaultTasksListURIForOrg, defaultOrg);
} }
@Provides @Provides
@ -84,9 +84,9 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
@Provides @Provides
@org.jclouds.trmk.vcloud_0_8.endpoints.Catalog @org.jclouds.trmk.vcloud_0_8.endpoints.Catalog
@Singleton @Singleton
protected ReferenceType provideDefaultCatalog(DefaultCatalogForOrg defaultCatalogURIForOrg, protected Supplier<ReferenceType> provideDefaultCatalog(DefaultCatalogForOrg defaultCatalogURIForOrg,
@org.jclouds.trmk.vcloud_0_8.endpoints.Org ReferenceType defaultOrg) { @org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) {
return defaultCatalogURIForOrg.apply(defaultOrg); return Suppliers.compose(defaultCatalogURIForOrg, defaultOrg);
} }
@Provides @Provides
@ -121,9 +121,9 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
@Provides @Provides
@org.jclouds.trmk.vcloud_0_8.endpoints.VDC @org.jclouds.trmk.vcloud_0_8.endpoints.VDC
@Singleton @Singleton
protected ReferenceType provideDefaultVDC(DefaultVDCForOrg defaultVDCURIForOrg, protected Supplier<ReferenceType> provideDefaultVDC(DefaultVDCForOrg defaultVDCURIForOrg,
@org.jclouds.trmk.vcloud_0_8.endpoints.Org ReferenceType defaultOrg) { @org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) {
return defaultVDCURIForOrg.apply(defaultOrg); return Suppliers.compose(defaultVDCURIForOrg, defaultOrg);
} }
@Provides @Provides
@ -136,9 +136,9 @@ public class DefaultVCloudReferencesModule extends AbstractModule {
@Provides @Provides
@org.jclouds.trmk.vcloud_0_8.endpoints.Network @org.jclouds.trmk.vcloud_0_8.endpoints.Network
@Singleton @Singleton
protected ReferenceType provideDefaultNetwork(DefaultNetworkForVDC defaultNetworkURIForVDC, protected Supplier<ReferenceType> provideDefaultNetwork(DefaultNetworkForVDC defaultNetworkURIForVDC,
@org.jclouds.trmk.vcloud_0_8.endpoints.VDC ReferenceType defaultVDC) { @org.jclouds.trmk.vcloud_0_8.endpoints.VDC Supplier<ReferenceType> defaultVDC) {
return defaultNetworkURIForVDC.apply(defaultVDC); return Suppliers.compose(defaultNetworkURIForVDC, defaultVDC);
} }
@Provides @Provides

View File

@ -352,10 +352,17 @@ public class TerremarkVCloudRestClientModule<S extends TerremarkVCloudClient, A
@Provides @Provides
@Singleton @Singleton
protected org.jclouds.trmk.vcloud_0_8.domain.Org provideOrg( protected Supplier<org.jclouds.trmk.vcloud_0_8.domain.Org> provideOrg(
Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> orgSupplier, final Supplier<Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.Org>> orgSupplier,
@org.jclouds.trmk.vcloud_0_8.endpoints.Org ReferenceType defaultOrg) { @org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg) {
return orgSupplier.get().get(defaultOrg.getName()); return Suppliers.compose(new Function<ReferenceType, org.jclouds.trmk.vcloud_0_8.domain.Org>() {
@Override
public org.jclouds.trmk.vcloud_0_8.domain.Org apply(ReferenceType input) {
return orgSupplier.get().get(input.getName());
}
}, defaultOrg);
} }
@Provides @Provides

View File

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

View File

@ -42,12 +42,12 @@ import com.google.common.collect.Iterables;
@Singleton @Singleton
public class OrgNameAndTasksListNameToEndpoint implements Function<Object, URI> { public class OrgNameAndTasksListNameToEndpoint implements Function<Object, URI> {
private final Supplier<Map<String, ? extends Org>> orgMap; private final Supplier<Map<String, ? extends Org>> orgMap;
private final ReferenceType defaultOrg; private final Supplier<ReferenceType> defaultOrg;
private final ReferenceType defaultTasksList; private final Supplier<ReferenceType> defaultTasksList;
@Inject @Inject
public OrgNameAndTasksListNameToEndpoint(Supplier<Map<String, ? extends Org>> orgMap, public OrgNameAndTasksListNameToEndpoint(Supplier<Map<String, ? extends Org>> orgMap,
@org.jclouds.trmk.vcloud_0_8.endpoints.Org ReferenceType defaultOrg, @TasksList ReferenceType defaultTasksList) { @org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultOrg, @TasksList Supplier<ReferenceType> defaultTasksList) {
this.orgMap = orgMap; this.orgMap = orgMap;
this.defaultOrg = defaultOrg; this.defaultOrg = defaultOrg;
this.defaultTasksList = defaultTasksList; this.defaultTasksList = defaultTasksList;
@ -59,9 +59,9 @@ public class OrgNameAndTasksListNameToEndpoint implements Function<Object, URI>
Object org = Iterables.get(orgTasksList, 0); Object org = Iterables.get(orgTasksList, 0);
Object tasksList = Iterables.get(orgTasksList, 1); Object tasksList = Iterables.get(orgTasksList, 1);
if (org == null && tasksList == null) if (org == null && tasksList == null)
return defaultTasksList.getHref(); return defaultTasksList.get().getHref();
else if (org == null) else if (org == null)
org = defaultOrg.getName(); org = defaultOrg.get().getName();
try { try {
Map<String, ReferenceType> tasksLists = checkNotNull(orgMap.get().get(org)).getTasksLists(); Map<String, ReferenceType> tasksLists = checkNotNull(orgMap.get().get(org)).getTasksLists();

View File

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

View File

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

View File

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

View File

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

View File

@ -40,7 +40,7 @@ public class OrgNameVDCNameNetworkNameToEndpoint extends OrgNameVDCNameResourceN
@Inject @Inject
public OrgNameVDCNameNetworkNameToEndpoint( public OrgNameVDCNameNetworkNameToEndpoint(
Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>> orgVDCMap, Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>> orgVDCMap,
@Org ReferenceType defaultOrg, @VDC ReferenceType defaultVDC) { @Org Supplier<ReferenceType> defaultOrg, @VDC Supplier<ReferenceType> defaultVDC) {
super(orgVDCMap, defaultOrg, defaultVDC); super(orgVDCMap, defaultOrg, defaultVDC);
} }

View File

@ -40,7 +40,7 @@ public class OrgNameVDCNameResourceEntityNameToEndpoint extends OrgNameVDCNameRe
@Inject @Inject
public OrgNameVDCNameResourceEntityNameToEndpoint( public OrgNameVDCNameResourceEntityNameToEndpoint(
Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>> orgVDCMap, Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>> orgVDCMap,
@Org ReferenceType defaultOrg, @VDC ReferenceType defaultVDC) { @Org Supplier<ReferenceType> defaultOrg, @VDC Supplier<ReferenceType> defaultVDC) {
super(orgVDCMap, defaultOrg, defaultVDC); super(orgVDCMap, defaultOrg, defaultVDC);
} }

View File

@ -41,13 +41,13 @@ import com.google.common.collect.Iterables;
public abstract class OrgNameVDCNameResourceNameToEndpoint implements Function<Object, URI>{ public abstract class OrgNameVDCNameResourceNameToEndpoint implements Function<Object, URI>{
protected final Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>> orgVDCMap; protected final Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>> orgVDCMap;
protected final ReferenceType defaultOrg; protected final Supplier<ReferenceType> defaultOrg;
protected final ReferenceType defaultVDC; protected final Supplier<ReferenceType> defaultVDC;
@Inject @Inject
public OrgNameVDCNameResourceNameToEndpoint( public OrgNameVDCNameResourceNameToEndpoint(
Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>> orgVDCMap, Supplier<Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>>> orgVDCMap,
@Org ReferenceType defaultOrg, @org.jclouds.trmk.vcloud_0_8.endpoints.VDC ReferenceType defaultVDC) { @Org Supplier<ReferenceType> defaultOrg, @org.jclouds.trmk.vcloud_0_8.endpoints.VDC Supplier<ReferenceType> defaultVDC) {
this.orgVDCMap = orgVDCMap; this.orgVDCMap = orgVDCMap;
this.defaultOrg = defaultOrg; this.defaultOrg = defaultOrg;
this.defaultVDC = defaultVDC; this.defaultVDC = defaultVDC;
@ -60,9 +60,9 @@ public abstract class OrgNameVDCNameResourceNameToEndpoint implements Function<
Object vDC = Iterables.get(orgVDC, 1); Object vDC = Iterables.get(orgVDC, 1);
Object resource = Iterables.get(orgVDC, 2); Object resource = Iterables.get(orgVDC, 2);
if (org == null) if (org == null)
org = defaultOrg.getName(); org = defaultOrg.get().getName();
if (vDC == null) if (vDC == null)
vDC = defaultVDC.getName(); vDC = defaultVDC.get().getName();
Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>> orgToVDCs = orgVDCMap.get(); Map<String, Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>> orgToVDCs = orgVDCMap.get();
checkState(orgToVDCs != null, "could not get map of org name to vdcs!"); checkState(orgToVDCs != null, "could not get map of org name to vdcs!");
Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC> vDCs = orgToVDCs.get(org); Map<String, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC> vDCs = orgToVDCs.get(org);

View File

@ -36,10 +36,10 @@ import com.google.common.collect.Maps;
public abstract class OrgURIToEndpoint implements Function<Object, URI> { public abstract class OrgURIToEndpoint implements Function<Object, URI> {
protected final Supplier<Map<String, ? extends Org>> orgMap; protected final Supplier<Map<String, ? extends Org>> orgMap;
protected final ReferenceType defaultOrg; protected final Supplier<ReferenceType> defaultOrg;
public OrgURIToEndpoint(Supplier<Map<String, ? extends Org>> orgMap, public OrgURIToEndpoint(Supplier<Map<String, ? extends Org>> orgMap,
@org.jclouds.trmk.vcloud_0_8.endpoints.Org ReferenceType defaultUri) { @org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultUri) {
this.orgMap = orgMap; this.orgMap = orgMap;
this.defaultOrg = defaultUri; this.defaultOrg = defaultUri;
} }
@ -54,7 +54,7 @@ public abstract class OrgURIToEndpoint implements Function<Object, URI> {
}); });
try { try {
Org org = uriToOrg.get(from == null ? defaultOrg.getHref() : from); Org org = uriToOrg.get(from == null ? defaultOrg.get().getHref() : from);
return getUriFromOrg(org); return getUriFromOrg(org);
} catch (NullPointerException e) { } catch (NullPointerException e) {
throw new ResourceNotFoundException("org " + from + " not found in: " + uriToOrg, e); throw new ResourceNotFoundException("org " + from + " not found in: " + uriToOrg, e);

View File

@ -38,7 +38,7 @@ import com.google.common.base.Supplier;
public class OrgURIToKeysListEndpoint extends OrgURIToEndpoint implements Function<Object, URI> { public class OrgURIToKeysListEndpoint extends OrgURIToEndpoint implements Function<Object, URI> {
@Inject @Inject
public OrgURIToKeysListEndpoint(Supplier<Map<String, ? extends Org>> orgMap, public OrgURIToKeysListEndpoint(Supplier<Map<String, ? extends Org>> orgMap,
@org.jclouds.trmk.vcloud_0_8.endpoints.Org ReferenceType defaultUri) { @org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier<ReferenceType> defaultUri) {
super(orgMap, defaultUri); super(orgMap, defaultUri);
} }

View File

@ -38,18 +38,18 @@ import com.google.common.base.Supplier;
@Singleton @Singleton
public class VDCURIToInternetServicesEndpoint implements Function<Object, URI> { public class VDCURIToInternetServicesEndpoint implements Function<Object, URI> {
private final Supplier<Map<URI, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>> orgVDCMap; private final Supplier<Map<URI, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>> orgVDCMap;
private final ReferenceType defaultVDC; private final Supplier<ReferenceType> defaultVDC;
@Inject @Inject
public VDCURIToInternetServicesEndpoint( public VDCURIToInternetServicesEndpoint(
Supplier<Map<URI, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>> orgVDCMap, @VDC ReferenceType defaultVDC) { Supplier<Map<URI, ? extends org.jclouds.trmk.vcloud_0_8.domain.VDC>> orgVDCMap, @VDC Supplier<ReferenceType> defaultVDC) {
this.orgVDCMap = orgVDCMap; this.orgVDCMap = orgVDCMap;
this.defaultVDC = defaultVDC; this.defaultVDC = defaultVDC;
} }
public URI apply(Object from) { public URI apply(Object from) {
try { try {
return orgVDCMap.get().get(from == null ? defaultVDC.getHref() : from).getInternetServices().getHref(); return orgVDCMap.get().get(from == null ? defaultVDC.get().getHref() : from).getInternetServices().getHref();
} catch (NullPointerException e) { } catch (NullPointerException e) {
throw new ResourceNotFoundException("vdc " + from + " not found in " + orgVDCMap.get()); throw new ResourceNotFoundException("vdc " + from + " not found in " + orgVDCMap.get());
} }

View File

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

View File

@ -40,16 +40,16 @@ import com.google.common.base.Supplier;
public class DefaultVDC implements ImplicitLocationSupplier { public class DefaultVDC implements ImplicitLocationSupplier {
@Singleton @Singleton
public static final class IsDefaultVDC implements Predicate<Location> { public static final class IsDefaultVDC implements Predicate<Location> {
private final ReferenceType defaultVDC; private final Supplier<ReferenceType> defaultVDC;
@Inject @Inject
IsDefaultVDC(@VDC ReferenceType defaultVDC) { IsDefaultVDC(@VDC Supplier<ReferenceType> defaultVDC) {
this.defaultVDC = checkNotNull(defaultVDC, "defaultVDC"); this.defaultVDC = checkNotNull(defaultVDC, "defaultVDC");
} }
@Override @Override
public boolean apply(Location input) { public boolean apply(Location input) {
return input.getScope() == LocationScope.ZONE && input.getId().equals(defaultVDC.getHref().toASCIIString()); return input.getScope() == LocationScope.ZONE && input.getId().equals(defaultVDC.get().getHref().toASCIIString());
} }
@Override @Override

View File

@ -41,6 +41,8 @@ import org.nnsoft.guice.rocoto.Rocoto;
import org.nnsoft.guice.rocoto.configuration.ConfigurationModule; import org.nnsoft.guice.rocoto.configuration.ConfigurationModule;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.HashMultimap; import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
@ -68,8 +70,9 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
@Network @Network
@Provides @Provides
@Singleton @Singleton
ReferenceType provideNetwork() { Supplier<ReferenceType> provideNetwork() {
return new ReferenceTypeImpl(null, null, URI.create("https://vcloud.safesecureweb.com/network/1990")); return Suppliers.<ReferenceType>ofInstance(new ReferenceTypeImpl(null, null, URI
.create("https://vcloud.safesecureweb.com/network/1990")));
} }
})); }));

View File

@ -676,8 +676,8 @@ public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiv
format("ls %s/bundles/org/jboss/as/osgi/configadmin/main|sed -e 's/.*-//g' -e 's/.jar//g'", format("ls %s/bundles/org/jboss/as/osgi/configadmin/main|sed -e 's/.*-//g' -e 's/.jar//g'",
JBOSS_HOME)), configureSeconds)); JBOSS_HOME)), configureSeconds));
for (Entry<String, URI> download : ImmutableMap.<String, URI> of("jboss7", JBOSS7_URL, "jdk7", InstallJDK.FromURL.JDK7_URL) for (Entry<String, URI> download : ImmutableMap.<String, URI> of("jboss7", JBOSS7_URL, "jdk7",
.entrySet()) { URI.create("http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.tar.gz")).entrySet()) {
// note we cannot use nslookup until we've configured the system, as // note we cannot use nslookup until we've configured the system, as
// it may have not been present checking the address of the download // it may have not been present checking the address of the download
// host using the local node's DNS config // host using the local node's DNS config

View File

@ -133,6 +133,42 @@ function setupPublicCurl() {
ensure_can_resolve_public_dns ensure_can_resolve_public_dns
return 0 return 0
} }
function installJDK() {
if hash curl 2>/dev/null; then
if [ `uname -m` == 'x86_64' ]; then
local url=${1:-http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.tar.gz}
else
local url=${1:-http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-i586.tar.gz}
fi
curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET $url |(mkdir -p /usr/local &&cd /usr/local &&tar -xpzf -)
mv /usr/local/jdk* /usr/local/jdk/
test -n \"$SUDO_USER\" && cat >> /home/$SUDO_USER/.bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
cat >> /etc/bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
cat >> $HOME/.bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
cat >> /etc/skel/.bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
# TODO: eventhough we are setting the above, sometimes images (ex.
# cloudservers ubuntu) kick out of .bashrc (ex. [ -z "$PS1" ] &&
# return), for this reason, we should also explicitly link.
# A better way would be to update using alternatives or the like
ln -fs /usr/local/jdk/bin/java /usr/bin/java
/usr/bin/java -version || abort "cannot run /usr/bin/java"
else
abort "curl not available.. cannot install openjdk"
fi
return 0
}
END_OF_JCLOUDS_SCRIPT END_OF_JCLOUDS_SCRIPT
@ -162,26 +198,7 @@ END_OF_JCLOUDS_SCRIPT
awk -v user=^${SUDO_USER:=${USER}}: -v password='crypt(randompassword)' 'BEGIN { FS=OFS=":" } $0 ~ user { $2 = password } 1' /etc/shadow >/etc/shadow.${SUDO_USER:=${USER}} awk -v user=^${SUDO_USER:=${USER}}: -v password='crypt(randompassword)' 'BEGIN { FS=OFS=":" } $0 ~ user { $2 = password } 1' /etc/shadow >/etc/shadow.${SUDO_USER:=${USER}}
test -f /etc/shadow.${SUDO_USER:=${USER}} && mv /etc/shadow.${SUDO_USER:=${USER}} /etc/shadow test -f /etc/shadow.${SUDO_USER:=${USER}} && mv /etc/shadow.${SUDO_USER:=${USER}} /etc/shadow
setupPublicCurl || return 1 setupPublicCurl || return 1
curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.tar.gz |(mkdir -p /usr/local &&cd /usr/local &&tar -xpzf -) installJDK || return 1
mv /usr/local/jdk* /usr/local/jdk/
test -n "$SUDO_USER" &&
cat >> /home/$SUDO_USER/.bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
cat >> /etc/bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
cat >> $HOME/.bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
cat >> /etc/skel/.bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
ln -fs /usr/local/jdk/bin/java /usr/bin/java
END_OF_JCLOUDS_SCRIPT END_OF_JCLOUDS_SCRIPT

View File

@ -133,6 +133,42 @@ function setupPublicCurl() {
ensure_can_resolve_public_dns ensure_can_resolve_public_dns
return 0 return 0
} }
function installJDK() {
if hash curl 2>/dev/null; then
if [ `uname -m` == 'x86_64' ]; then
local url=${1:-http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.tar.gz}
else
local url=${1:-http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-i586.tar.gz}
fi
curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET $url |(mkdir -p /usr/local &&cd /usr/local &&tar -xpzf -)
mv /usr/local/jdk* /usr/local/jdk/
test -n \"$SUDO_USER\" && cat >> /home/$SUDO_USER/.bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
cat >> /etc/bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
cat >> $HOME/.bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
cat >> /etc/skel/.bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
# TODO: eventhough we are setting the above, sometimes images (ex.
# cloudservers ubuntu) kick out of .bashrc (ex. [ -z "$PS1" ] &&
# return), for this reason, we should also explicitly link.
# A better way would be to update using alternatives or the like
ln -fs /usr/local/jdk/bin/java /usr/bin/java
/usr/bin/java -version || abort "cannot run /usr/bin/java"
else
abort "curl not available.. cannot install openjdk"
fi
return 0
}
END_OF_JCLOUDS_SCRIPT END_OF_JCLOUDS_SCRIPT
@ -162,26 +198,7 @@ END_OF_JCLOUDS_SCRIPT
awk -v user=^${SUDO_USER:=${USER}}: -v password='crypt(randompassword)' 'BEGIN { FS=OFS=":" } $0 ~ user { $2 = password } 1' /etc/shadow >/etc/shadow.${SUDO_USER:=${USER}} awk -v user=^${SUDO_USER:=${USER}}: -v password='crypt(randompassword)' 'BEGIN { FS=OFS=":" } $0 ~ user { $2 = password } 1' /etc/shadow >/etc/shadow.${SUDO_USER:=${USER}}
test -f /etc/shadow.${SUDO_USER:=${USER}} && mv /etc/shadow.${SUDO_USER:=${USER}} /etc/shadow test -f /etc/shadow.${SUDO_USER:=${USER}} && mv /etc/shadow.${SUDO_USER:=${USER}} /etc/shadow
setupPublicCurl || return 1 setupPublicCurl || return 1
curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.tar.gz |(mkdir -p /usr/local &&cd /usr/local &&tar -xpzf -) installJDK || return 1
mv /usr/local/jdk* /usr/local/jdk/
test -n "$SUDO_USER" &&
cat >> /home/$SUDO_USER/.bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
cat >> /etc/bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
cat >> $HOME/.bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
cat >> /etc/skel/.bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
ln -fs /usr/local/jdk/bin/java /usr/bin/java
iptables -I INPUT 1 -p tcp --dport 22 -j ACCEPT iptables -I INPUT 1 -p tcp --dport 22 -j ACCEPT
iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT
iptables-save iptables-save

View File

@ -133,6 +133,42 @@ function setupPublicCurl() {
ensure_can_resolve_public_dns ensure_can_resolve_public_dns
return 0 return 0
} }
function installJDK() {
if hash curl 2>/dev/null; then
if [ `uname -m` == 'x86_64' ]; then
local url=${1:-http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.tar.gz}
else
local url=${1:-http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-i586.tar.gz}
fi
curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET $url |(mkdir -p /usr/local &&cd /usr/local &&tar -xpzf -)
mv /usr/local/jdk* /usr/local/jdk/
test -n \"$SUDO_USER\" && cat >> /home/$SUDO_USER/.bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
cat >> /etc/bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
cat >> $HOME/.bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
cat >> /etc/skel/.bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
# TODO: eventhough we are setting the above, sometimes images (ex.
# cloudservers ubuntu) kick out of .bashrc (ex. [ -z "$PS1" ] &&
# return), for this reason, we should also explicitly link.
# A better way would be to update using alternatives or the like
ln -fs /usr/local/jdk/bin/java /usr/bin/java
/usr/bin/java -version || abort "cannot run /usr/bin/java"
else
abort "curl not available.. cannot install openjdk"
fi
return 0
}
END_OF_JCLOUDS_SCRIPT END_OF_JCLOUDS_SCRIPT
@ -142,26 +178,7 @@ END_OF_JCLOUDS_SCRIPT
rm -f $INSTANCE_HOME/rc rm -f $INSTANCE_HOME/rc
trap 'echo $?>$INSTANCE_HOME/rc' 0 1 2 3 15 trap 'echo $?>$INSTANCE_HOME/rc' 0 1 2 3 15
setupPublicCurl || exit 1 setupPublicCurl || exit 1
curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.tar.gz |(mkdir -p /usr/local &&cd /usr/local &&tar -xpzf -) installJDK || exit 1
mv /usr/local/jdk* /usr/local/jdk/
test -n "$SUDO_USER" &&
cat >> /home/$SUDO_USER/.bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
cat >> /etc/bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
cat >> $HOME/.bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
cat >> /etc/skel/.bashrc <<-'END_OF_JCLOUDS_FILE'
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
END_OF_JCLOUDS_FILE
ln -fs /usr/local/jdk/bin/java /usr/bin/java
END_OF_JCLOUDS_SCRIPT END_OF_JCLOUDS_SCRIPT

View File

@ -47,8 +47,8 @@
<!-- only required for Pems.java and only writing a private key file --> <!-- only required for Pems.java and only writing a private key file -->
<dependency> <dependency>
<groupId>org.bouncycastle</groupId> <groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15</artifactId> <artifactId>bcprov-jdk16</artifactId>
<version>1.44</version> <version>1.46</version>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
@ -59,7 +59,7 @@
<dependency> <dependency>
<groupId>com.sun.jersey</groupId> <groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId> <artifactId>jersey-core</artifactId>
<version>1.11</version> <version>1.12</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.inject.extensions</groupId> <groupId>com.google.inject.extensions</groupId>
@ -99,7 +99,7 @@
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
<version>11.0.1</version> <version>11.0.2</version>
</dependency> </dependency>
</dependencies> </dependencies>
@ -107,7 +107,7 @@
<plugins> <plugins>
<plugin> <plugin>
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version> <version>2.4</version>
<executions> <executions>
<execution> <execution>
<goals> <goals>

View File

@ -106,10 +106,10 @@ public class BackoffLimitedRetryHandler implements HttpRetryHandler, IOException
command.incrementFailureCount(); command.incrementFailureCount();
if (!command.isReplayable()) { if (!command.isReplayable()) {
logger.warn("Cannot retry after server error, command is not replayable: %1$s", command); logger.error("Cannot retry after server error, command is not replayable: %1$s", command);
return false; return false;
} else if (command.getFailureCount() > retryCountLimit) { } else if (command.getFailureCount() > retryCountLimit) {
logger.warn("Cannot retry after server error, command has exceeded retry limit %1$d: %2$s", retryCountLimit, logger.error("Cannot retry after server error, command has exceeded retry limit %1$d: %2$s", retryCountLimit,
command); command);
return false; return false;
} else { } else {

View File

@ -22,6 +22,9 @@ aws-simpledb.propertiesbuilder=org.jclouds.aws.simpledb.AWSSimpleDBPropertiesBui
aws-sqs.contextbuilder=org.jclouds.sqs.SQSContextBuilder aws-sqs.contextbuilder=org.jclouds.sqs.SQSContextBuilder
aws-sqs.propertiesbuilder=org.jclouds.aws.sqs.AWSSQSPropertiesBuilder aws-sqs.propertiesbuilder=org.jclouds.aws.sqs.AWSSQSPropertiesBuilder
elb.contextbuilder=org.jclouds.elb.ELBContextBuilder
elb.propertiesbuilder=org.jclouds.elb.ELBPropertiesBuilder
aws-elb.contextbuilder=org.jclouds.elb.ELBContextBuilder aws-elb.contextbuilder=org.jclouds.elb.ELBContextBuilder
aws-elb.propertiesbuilder=org.jclouds.aws.elb.AWSELBPropertiesBuilder aws-elb.propertiesbuilder=org.jclouds.aws.elb.AWSELBPropertiesBuilder
@ -183,6 +186,9 @@ softlayer.propertiesbuilder=org.jclouds.softlayer.SoftLayerPropertiesBuilder
glesys.contextbuilder=org.jclouds.glesys.GleSYSContextBuilder glesys.contextbuilder=org.jclouds.glesys.GleSYSContextBuilder
glesys.propertiesbuilder=org.jclouds.glesys.GleSYSPropertiesBuilder glesys.propertiesbuilder=org.jclouds.glesys.GleSYSPropertiesBuilder
opsource-servers.contextbuilder=org.jclouds.opsource.servers.OpSourceServersContextBuilder
opsource-servers.propertiesbuilder=org.jclouds.opsource.servers.OpSourceServersPropertiesBuilder
savvis-symphonyvpdc.contextbuilder=org.jclouds.savvis.vpdc.VPDCContextBuilder savvis-symphonyvpdc.contextbuilder=org.jclouds.savvis.vpdc.VPDCContextBuilder
savvis-symphonyvpdc.propertiesbuilder=org.jclouds.savvis.vpdc.VPDCPropertiesBuilder savvis-symphonyvpdc.propertiesbuilder=org.jclouds.savvis.vpdc.VPDCPropertiesBuilder

View File

@ -45,13 +45,13 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
import org.eclipse.jetty.http.ssl.SslContextFactory;
import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.ssl.SslSelectChannelConnector; import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.crypto.CryptoStreams; import org.jclouds.crypto.CryptoStreams;
import org.jclouds.io.InputSuppliers; import org.jclouds.io.InputSuppliers;

View File

@ -39,6 +39,11 @@ import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.Difference;
import org.custommonkey.xmlunit.DifferenceConstants;
import org.custommonkey.xmlunit.DifferenceListener;
import org.custommonkey.xmlunit.XMLUnit;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.concurrent.MoreExecutors; import org.jclouds.concurrent.MoreExecutors;
import org.jclouds.concurrent.SingleThreaded; import org.jclouds.concurrent.SingleThreaded;
@ -58,14 +63,18 @@ import org.jclouds.io.Payloads;
import org.jclouds.logging.config.NullLoggingModule; import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.util.Strings2; import org.jclouds.util.Strings2;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.w3c.dom.Node;
import com.google.common.annotations.Beta; import com.google.common.annotations.Beta;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Binder; import com.google.inject.Binder;
import com.google.inject.Module; import com.google.inject.Module;
@ -324,7 +333,9 @@ public abstract class BaseRestClientExpectTest<S> {
return HttpResponse.builder().statusCode(500).message( return HttpResponse.builder().statusCode(500).message(
String.format("request %s is out of range (%s)", index, requests.size())).payload( String.format("request %s is out of range (%s)", index, requests.size())).payload(
Payloads.newStringPayload(renderRequest(input))).build(); Payloads.newStringPayload(renderRequest(input))).build();
if (!httpRequestsAreEqual(input, requests.get(index))) {
assertEquals(renderRequest(input), renderRequest(requests.get(index))); assertEquals(renderRequest(input), renderRequest(requests.get(index)));
}
return responses.get(index); return responses.get(index);
} }
}); });
@ -342,14 +353,81 @@ public abstract class BaseRestClientExpectTest<S> {
return requestsSendResponses(requestToResponse, createModule()); return requestsSendResponses(requestToResponse, createModule());
} }
protected enum HttpRequestComparisonType {
XML, JSON, DEFAULT;
}
/**
* How should this HttpRequest be compared with others?
*/
protected HttpRequestComparisonType compareHttpRequestAsType(HttpRequest input) {
return HttpRequestComparisonType.DEFAULT;
}
/**
* Compare two requests as instructed by {@link #compareHttpRequestAsType(HttpRequest)} - default is to compare using Objects.equal
*/
public boolean httpRequestsAreEqual(HttpRequest a, HttpRequest b) {
try {
switch (compareHttpRequestAsType(a)) {
case XML: {
if (a == null || b == null || a.getPayload() == null || b.getPayload() == null) {
return false;
}
Diff diff = XMLUnit.compareXML(Strings2.toStringAndClose(a.getPayload().getInput()),
Strings2.toStringAndClose(b.getPayload().getInput()));
// Ignoring xsi:schemaLocation and differences in namespace prefixes
diff.overrideDifferenceListener(new DifferenceListener() {
@Override
public int differenceFound(Difference difference) {
if (difference.getId() == DifferenceConstants.SCHEMA_LOCATION_ID ||
difference.getId() == DifferenceConstants.NAMESPACE_PREFIX_ID) {
return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
}
return RETURN_ACCEPT_DIFFERENCE;
}
@Override
public void skippedComparison(Node node, Node node1) {
}
});
return diff.identical() && Objects.equal(a.getHeaders(), b.getHeaders());
}
case JSON: {
if (a == null || b == null || a.getPayload() == null || b.getPayload() == null) {
return false;
}
JsonParser parser = new JsonParser();
JsonElement payloadA = parser.parse(Strings2.toStringAndClose(a.getPayload().getInput()));
JsonElement payloadB = parser.parse(Strings2.toStringAndClose(b.getPayload().getInput()));
return Objects.equal(payloadA, payloadB) && Objects.equal(a.getHeaders(), b.getHeaders());
}
default: {
return Objects.equal(a, b);
}
}
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
public S requestsSendResponses(final Map<HttpRequest, HttpResponse> requestToResponse, Module module) { public S requestsSendResponses(final Map<HttpRequest, HttpResponse> requestToResponse, Module module) {
return createClient(new Function<HttpRequest, HttpResponse>() { return createClient(new Function<HttpRequest, HttpResponse>() {
ImmutableBiMap<HttpRequest, HttpResponse> bimap = ImmutableBiMap.copyOf(requestToResponse); ImmutableBiMap<HttpRequest, HttpResponse> bimap = ImmutableBiMap.copyOf(requestToResponse);
@Override @Override
public HttpResponse apply(HttpRequest input) { public HttpResponse apply(HttpRequest input) {
if (!(requestToResponse.containsKey(input))) { HttpResponse response = null;
for (HttpRequest request : requestToResponse.keySet()) {
if (httpRequestsAreEqual(input, request)) {
response = requestToResponse.get(request);
}
}
if (response == null) {
StringBuilder payload = new StringBuilder("\n"); StringBuilder payload = new StringBuilder("\n");
payload.append("the following request is not configured:\n"); payload.append("the following request is not configured:\n");
payload.append("----------------------------------------\n"); payload.append("----------------------------------------\n");
@ -360,13 +438,14 @@ public abstract class BaseRestClientExpectTest<S> {
payload.append("----------------------------------------\n"); payload.append("----------------------------------------\n");
payload.append(renderRequest(request)); payload.append(renderRequest(request));
} }
return HttpResponse.builder().statusCode(500).message("no response configured for request").payload( response = HttpResponse.builder().statusCode(500).message("no response configured for request").payload(
Payloads.newStringPayload(payload.toString())).build(); Payloads.newStringPayload(payload.toString())).build();
} } else if (compareHttpRequestAsType(input) == HttpRequestComparisonType.DEFAULT) {
HttpResponse response = requestToResponse.get(input);
// in case hashCode/equals doesn't do a full content check // in case hashCode/equals doesn't do a full content check
assertEquals(renderRequest(input), renderRequest(bimap.inverse().get(response))); assertEquals(renderRequest(input), renderRequest(bimap.inverse().get(response)));
}
return response; return response;
} }
}, module); }, module);

View File

@ -60,7 +60,7 @@
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
<version>4.1.1</version> <version>4.1.3</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -60,7 +60,7 @@
<dependency> <dependency>
<groupId>joda-time</groupId> <groupId>joda-time</groupId>
<artifactId>joda-time</artifactId> <artifactId>joda-time</artifactId>
<version>1.6.2</version> <version>2.1</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -78,7 +78,7 @@
<dependency> <dependency>
<groupId>ch.qos.logback</groupId> <groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId> <artifactId>logback-classic</artifactId>
<version>0.9.30</version> <version>1.0.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -33,30 +33,6 @@
<description>jclouds netty payload module</description> <description>jclouds netty payload module</description>
<packaging>bundle</packaging> <packaging>bundle</packaging>
<!-- bootstrapping: need to fetch the project POM -->
<repositories>
<repository>
<id>jclouds-sona-snapshots-nexus</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>jboss-public-releases</id>
<url>https://repository.jboss.org/nexus/content/groups/public-jboss</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.jclouds</groupId> <groupId>org.jclouds</groupId>
@ -71,9 +47,9 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jboss.netty</groupId> <groupId>io.netty</groupId>
<artifactId>netty</artifactId> <artifactId>netty</artifactId>
<version>3.2.4.Final</version> <version>3.3.1.Final</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -60,7 +60,7 @@
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
<version>1.6.1</version> <version>1.6.4</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -71,7 +71,7 @@
<dependency> <dependency>
<groupId>ch.qos.logback</groupId> <groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId> <artifactId>logback-classic</artifactId>
<version>0.9.30</version> <version>1.0.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -27,7 +27,7 @@
<version>1.5.0-SNAPSHOT</version> <version>1.5.0-SNAPSHOT</version>
<relativePath>../../project/pom.xml</relativePath> <relativePath>../../project/pom.xml</relativePath>
</parent> </parent>
<groupId>org.jclouds.provider</groupId> <groupId>org.jclouds.labs</groupId>
<artifactId>aws-elb</artifactId> <artifactId>aws-elb</artifactId>
<name>jclouds Amazon Elastic Load Balancer provider</name> <name>jclouds Amazon Elastic Load Balancer provider</name>
<description>Elastic Load Balancer implementation targeted to Amazon Web Services</description> <description>Elastic Load Balancer implementation targeted to Amazon Web Services</description>
@ -50,13 +50,13 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.jclouds.api</groupId> <groupId>org.jclouds.labs</groupId>
<artifactId>elb</artifactId> <artifactId>elb</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<type>jar</type> <type>jar</type>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jclouds.api</groupId> <groupId>org.jclouds.labs</groupId>
<artifactId>elb</artifactId> <artifactId>elb</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<type>test-jar</type> <type>test-jar</type>

View File

@ -69,10 +69,6 @@ public class AWSELBPropertiesBuilder extends ELBPropertiesBuilder {
return properties; return properties;
} }
public AWSELBPropertiesBuilder() {
super();
}
public AWSELBPropertiesBuilder(Properties properties) { public AWSELBPropertiesBuilder(Properties properties) {
super(properties); super(properties);
} }

View File

@ -27,7 +27,7 @@ import org.testng.annotations.Test;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "live", sequential = true, testName = "AWSELBClientLiveTest") @Test(groups = "live", singleThreaded = true, testName = "AWSELBClientLiveTest")
public class AWSELBClientLiveTest extends ELBClientLiveTest { public class AWSELBClientLiveTest extends ELBClientLiveTest {
public AWSELBClientLiveTest() { public AWSELBClientLiveTest() {
provider = "aws-elb"; provider = "aws-elb";
@ -47,7 +47,7 @@ public class AWSELBClientLiveTest extends ELBClientLiveTest {
} }
} }
@Test @Test(dependsOnMethods = "testDescribeLoadBalancers")
public void testDeleteLoadBalancer() { public void testDeleteLoadBalancer() {
for (String region : Region.DEFAULT_REGIONS) { for (String region : Region.DEFAULT_REGIONS) {
deleteLoadBalancerInRegion(region); deleteLoadBalancerInRegion(region);

View File

@ -27,7 +27,7 @@
<version>1.5.0-SNAPSHOT</version> <version>1.5.0-SNAPSHOT</version>
<relativePath>../../project/pom.xml</relativePath> <relativePath>../../project/pom.xml</relativePath>
</parent> </parent>
<groupId>org.jclouds.api</groupId> <groupId>org.jclouds.labs</groupId>
<artifactId>elb</artifactId> <artifactId>elb</artifactId>
<name>jcloud elb api</name> <name>jcloud elb api</name>
<description>jclouds components to access an implementation of Elastic Load Balancer</description> <description>jclouds components to access an implementation of Elastic Load Balancer</description>
@ -40,7 +40,7 @@
<test.elb.build-version></test.elb.build-version> <test.elb.build-version></test.elb.build-version>
<test.elb.identity>${test.aws.identity}</test.elb.identity> <test.elb.identity>${test.aws.identity}</test.elb.identity>
<test.elb.credential>${test.aws.credential}</test.elb.credential> <test.elb.credential>${test.aws.credential}</test.elb.credential>
<test.elb.compute.provider>ec2</test.elb.compute.provider> <test.elb.compute.provider>aws-ec2</test.elb.compute.provider>
<test.elb.compute.endpoint>https://ec2.us-east-1.amazonaws.com</test.elb.compute.endpoint> <test.elb.compute.endpoint>https://ec2.us-east-1.amazonaws.com</test.elb.compute.endpoint>
<test.elb.compute.api-version>2010-06-15</test.elb.compute.api-version> <test.elb.compute.api-version>2010-06-15</test.elb.compute.api-version>
<test.elb.compute.build-version></test.elb.compute.build-version> <test.elb.compute.build-version></test.elb.compute.build-version>
@ -75,6 +75,12 @@
<type>test-jar</type> <type>test-jar</type>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.jclouds.provider</groupId>
<artifactId>aws-ec2</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.jclouds.driver</groupId> <groupId>org.jclouds.driver</groupId>
<artifactId>jclouds-sshj</artifactId> <artifactId>jclouds-sshj</artifactId>

View File

@ -43,9 +43,6 @@ public class ELBPropertiesBuilder extends PropertiesBuilder {
return properties; return properties;
} }
public ELBPropertiesBuilder() {
super();
}
public ELBPropertiesBuilder(Properties properties) { public ELBPropertiesBuilder(Properties properties) {
super(properties); super(properties);

View File

@ -30,7 +30,6 @@ public class ELBLoadBalancerContextModule extends BaseLoadBalancerServiceContext
@Override @Override
protected void configure() { protected void configure() {
install(new ELBBindLoadBalancerSuppliersByClass());
install(new ELBBindLoadBalancerStrategiesByClass()); install(new ELBBindLoadBalancerStrategiesByClass());
install(new ELBLoadBalancerServiceDependenciesModule()); install(new ELBLoadBalancerServiceDependenciesModule());
super.configure(); super.configure();

View File

@ -18,21 +18,27 @@
*/ */
package org.jclouds.elb.loadbalancer.functions; package org.jclouds.elb.loadbalancer.functions;
import java.util.Map; import java.util.NoSuchElementException;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.collect.Memoized;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.elb.domain.LoadBalancer; import org.jclouds.elb.domain.LoadBalancer;
import org.jclouds.loadbalancer.domain.LoadBalancerMetadata; import org.jclouds.loadbalancer.domain.LoadBalancerMetadata;
import org.jclouds.loadbalancer.domain.LoadBalancerType; import org.jclouds.loadbalancer.domain.LoadBalancerType;
import org.jclouds.loadbalancer.domain.internal.LoadBalancerMetadataImpl; import org.jclouds.loadbalancer.domain.internal.LoadBalancerMetadataImpl;
import org.jclouds.logging.Logger;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
/** /**
* *
@ -40,25 +46,49 @@ import com.google.common.collect.ImmutableSet;
*/ */
@Singleton @Singleton
public class LoadBalancerToLoadBalancerMetadata implements Function<LoadBalancer, LoadBalancerMetadata> { public class LoadBalancerToLoadBalancerMetadata implements Function<LoadBalancer, LoadBalancerMetadata> {
protected final Supplier<Map<String, ? extends Location>> locationMap; @Resource
protected static Logger logger = Logger.NULL;
protected final Supplier<Set<? extends Location>> locations;
protected final Supplier<Location> defaultLocationSupplier; protected final Supplier<Location> defaultLocationSupplier;
@Inject @Inject
public LoadBalancerToLoadBalancerMetadata(Supplier<Location> defaultLocationSupplier, public LoadBalancerToLoadBalancerMetadata(Supplier<Location> defaultLocationSupplier,
Supplier<Map<String, ? extends Location>> locationMap) { @Memoized Supplier<Set<? extends Location>> locations) {
this.locationMap = locationMap; this.locations = locations;
this.defaultLocationSupplier = defaultLocationSupplier; this.defaultLocationSupplier = defaultLocationSupplier;
} }
@Override @Override
public LoadBalancerMetadata apply(LoadBalancer input) { public LoadBalancerMetadata apply(LoadBalancer input) {
Location location = input.getRegion() != null ? locationMap.get().get(input.getRegion()) Location location = input.getRegion() != null ? findLocationWithId(input.getRegion()) : defaultLocationSupplier
: defaultLocationSupplier.get(); .get();
String id = input.getRegion() != null ? input.getRegion() + "/" + input.getName() : input.getName(); String id = input.getRegion() != null ? input.getRegion() + "/" + input.getName() : input.getName();
// TODO Builder // TODO Builder
return new LoadBalancerMetadataImpl(LoadBalancerType.LB, input.getName(), input.getName(), id, location, null, return new LoadBalancerMetadataImpl(LoadBalancerType.LB, input.getName(), input.getName(), id, location, null,
ImmutableMap.<String, String> of(), ImmutableSet.of(input.getDnsName())); ImmutableMap.<String, String> of(), ImmutableSet.of(input.getDnsName()));
} }
private Location findLocationWithId(final String locationId) {
if (locationId == null)
return null;
try {
Location location = Iterables.find(locations.get(), new Predicate<Location>() {
@Override
public boolean apply(Location input) {
return input.getId().equals(locationId);
}
});
return location;
} catch (NoSuchElementException e) {
logger.debug("couldn't match instance location %s in: %s", locationId, locations.get());
return null;
}
}
} }

View File

@ -27,7 +27,6 @@ import java.util.Set;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import javax.annotation.Nullable;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -44,6 +43,7 @@ import org.jclouds.location.Region;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
/** /**
@ -60,12 +60,12 @@ public class ELBListLoadBalancersStrategy implements ListLoadBalancersStrategy {
private final ELBAsyncClient aclient; private final ELBAsyncClient aclient;
private final Function<LoadBalancer, LoadBalancerMetadata> converter; private final Function<LoadBalancer, LoadBalancerMetadata> converter;
private final ExecutorService executor; private final ExecutorService executor;
private final Set<String> regions; private final Supplier<Set<String>> regions;
@Inject @Inject
protected ELBListLoadBalancersStrategy(ELBClient client, ELBAsyncClient aclient, protected ELBListLoadBalancersStrategy(ELBClient client, ELBAsyncClient aclient,
Function<LoadBalancer, LoadBalancerMetadata> converter, Function<LoadBalancer, LoadBalancerMetadata> converter,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, @Nullable @Region Set<String> regions) { @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, @Region Supplier<Set<String>> regions) {
this.client = checkNotNull(client, "client"); this.client = checkNotNull(client, "client");
this.aclient = checkNotNull(aclient, "aclient"); this.aclient = checkNotNull(aclient, "aclient");
this.regions = checkNotNull(regions, "regions"); this.regions = checkNotNull(regions, "regions");
@ -76,7 +76,8 @@ public class ELBListLoadBalancersStrategy implements ListLoadBalancersStrategy {
@Override @Override
public Iterable<? extends LoadBalancerMetadata> listLoadBalancers() { public Iterable<? extends LoadBalancerMetadata> listLoadBalancers() {
Iterable<? extends LoadBalancer> loadBalancers; Iterable<? extends LoadBalancer> loadBalancers;
if (regions != null) Set<String> regions = this.regions.get();
if (regions.size() > 0)
loadBalancers = concat(transformParallel(regions, new Function<String, Future<Set<? extends LoadBalancer>>>() { loadBalancers = concat(transformParallel(regions, new Function<String, Future<Set<? extends LoadBalancer>>>() {
@Override @Override

View File

@ -179,18 +179,10 @@ public class ELBAsyncClientTest extends RestClientTest<ELBAsyncClient> {
protected String provider = "elb"; protected String provider = "elb";
@Override
protected Properties getProperties() {
Properties overrides = new Properties();
overrides.setProperty(provider + ".endpoint", "https://elasticloadbalancing.us-east-1.amazonaws.com");
overrides.setProperty(provider + ".propertiesbuilder", ELBPropertiesBuilder.class.getName());
overrides.setProperty(provider + ".contextbuilder", ELBContextBuilder.class.getName());
return overrides;
}
@Override @Override
public RestContextSpec<?, ?> createContextSpec() { public RestContextSpec<?, ?> createContextSpec() {
return new RestContextFactory(getProperties()).createContextSpec(provider, "identity", "credential", return new RestContextFactory(setupRestProperties()).createContextSpec(provider, "identity", "credential",
new Properties()); new Properties());
} }

View File

@ -24,12 +24,12 @@ import static org.testng.Assert.assertNotNull;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import org.jclouds.Constants;
import org.jclouds.elb.domain.LoadBalancer; import org.jclouds.elb.domain.LoadBalancer;
import org.jclouds.loadbalancer.LoadBalancerServiceContextFactory; import org.jclouds.loadbalancer.LoadBalancerServiceContextFactory;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.BaseRestClientLiveTest;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.testng.annotations.AfterTest; import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -41,41 +41,19 @@ import com.google.inject.Module;
* *
* @author Lili Nader * @author Lili Nader
*/ */
@Test(groups = "live", sequential = true) @Test(groups = "live", singleThreaded = true, testName = "ELBClientLiveTest")
public class ELBClientLiveTest { public class ELBClientLiveTest extends BaseRestClientLiveTest {
public ELBClientLiveTest() {
provider = "elb";
}
private ELBClient client; private ELBClient client;
private RestContext<ELBClient, ELBAsyncClient> context; private RestContext<ELBClient, ELBAsyncClient> context;
protected String provider = "elb";
protected String identity;
protected String credential;
protected String endpoint;
protected String apiVersion;
protected String name = "TestLoadBalancer"; protected String name = "TestLoadBalancer";
protected void setupCredentials() { @BeforeGroups(groups = "live")
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider
+ ".credential");
endpoint = System.getProperty("test." + provider + ".endpoint");
apiVersion = System.getProperty("test." + provider + ".api-version");
}
protected Properties setupProperties() {
Properties overrides = new Properties();
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
overrides.setProperty(provider + ".identity", identity);
if (credential != null)
overrides.setProperty(provider + ".credential", credential);
if (endpoint != null)
overrides.setProperty(provider + ".endpoint", endpoint);
if (apiVersion != null)
overrides.setProperty(provider + ".api-version", apiVersion);
return overrides;
}
@BeforeGroups(groups = { "live" })
public void setupClient() { public void setupClient() {
setupCredentials(); setupCredentials();
Properties overrides = setupProperties(); Properties overrides = setupProperties();
@ -86,8 +64,8 @@ public class ELBClientLiveTest {
@Test @Test
public void testCreateLoadBalancer() { public void testCreateLoadBalancer() {
createLoadBalancerInRegionZone(null, createLoadBalancerInRegionZone(null, checkNotNull(System.getProperty("test." + provider + ".zone"), "test."
checkNotNull(System.getProperty("test." + provider + ".zone"), "test." + provider + ".zone"), name); + provider + ".zone"), name);
} }
protected void createLoadBalancerInRegionZone(String region, String zone, String name) { protected void createLoadBalancerInRegionZone(String region, String zone, String name) {
@ -107,7 +85,7 @@ public class ELBClientLiveTest {
assert (allResults.size() >= 1) : region; assert (allResults.size() >= 1) : region;
} }
@Test @Test(dependsOnMethods = "testDescribeLoadBalancers")
public void testDeleteLoadBalancer() { public void testDeleteLoadBalancer() {
deleteLoadBalancerInRegion(null); deleteLoadBalancerInRegion(null);
} }
@ -116,8 +94,12 @@ public class ELBClientLiveTest {
client.deleteLoadBalancerInRegion(region, name); client.deleteLoadBalancerInRegion(region, name);
} }
@AfterTest @AfterGroups(groups = "live")
public void shutdown() { public void shutdown() {
try {
testDeleteLoadBalancer();
} finally {
context.close(); context.close();
} }
}
} }

View File

@ -37,7 +37,7 @@ import org.testng.annotations.Test;
* *
* @author Lili Nadar * @author Lili Nadar
*/ */
@Test(groups = "live", sequential = true) @Test(groups = "live", singleThreaded = true, testName = "ELBLoadBalancerServiceLiveTest")
public class ELBLoadBalancerServiceLiveTest extends BaseLoadBalancerServiceLiveTest { public class ELBLoadBalancerServiceLiveTest extends BaseLoadBalancerServiceLiveTest {
public ELBLoadBalancerServiceLiveTest() { public ELBLoadBalancerServiceLiveTest() {

Some files were not shown because too many files have changed in this diff Show More