mirror of https://github.com/apache/jclouds.git
Fix guice cache binding issue for live tests
This commit is contained in:
parent
72493161ab
commit
16afe38477
|
@ -52,6 +52,8 @@ import org.jclouds.cloudstack.domain.User;
|
|||
import org.jclouds.cloudstack.domain.VirtualMachine;
|
||||
import org.jclouds.cloudstack.domain.Zone;
|
||||
import org.jclouds.cloudstack.features.GuestOSClient;
|
||||
import org.jclouds.cloudstack.functions.GetFirewallRulesByVirtualMachine;
|
||||
import org.jclouds.cloudstack.functions.GetIPForwardingRulesByVirtualMachine;
|
||||
import org.jclouds.cloudstack.functions.StaticNATVirtualMachineInNetwork;
|
||||
import org.jclouds.cloudstack.functions.ZoneIdToZone;
|
||||
import org.jclouds.cloudstack.options.ListFirewallRulesOptions;
|
||||
|
@ -188,25 +190,6 @@ public class CloudStackComputeServiceContextModule extends
|
|||
return CacheBuilder.newBuilder().build(getIPForwardingRules);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class GetIPForwardingRulesByVirtualMachine extends CacheLoader<String, Set<IPForwardingRule>> {
|
||||
private final CloudStackClient client;
|
||||
|
||||
@Inject
|
||||
public GetIPForwardingRulesByVirtualMachine(CloudStackClient client) {
|
||||
this.client = checkNotNull(client, "client");
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ResourceNotFoundException
|
||||
* when there is no ip forwarding rule available for the VM
|
||||
*/
|
||||
@Override
|
||||
public Set<IPForwardingRule> load(String input) {
|
||||
Set<IPForwardingRule> rules = client.getNATClient().getIPForwardingRulesForVirtualMachine(input);
|
||||
return rules != null ? rules : ImmutableSet.<IPForwardingRule>of();
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
|
@ -215,27 +198,6 @@ public class CloudStackComputeServiceContextModule extends
|
|||
return CacheBuilder.newBuilder().build(getFirewallRules);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class GetFirewallRulesByVirtualMachine extends CacheLoader<String, Set<FirewallRule>> {
|
||||
private final CloudStackClient client;
|
||||
|
||||
@Inject
|
||||
public GetFirewallRulesByVirtualMachine(CloudStackClient client) {
|
||||
this.client = checkNotNull(client, "client");
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ResourceNotFoundException
|
||||
* when there is no ip forwarding rule available for the VM
|
||||
*/
|
||||
@Override
|
||||
public Set<FirewallRule> load(String input) {
|
||||
String publicIPId = client.getVirtualMachineClient().getVirtualMachine(input).getPublicIPId();
|
||||
Set<FirewallRule> rules = client.getFirewallClient().listFirewallRules(ListFirewallRulesOptions.Builder.ipAddressId(publicIPId));
|
||||
return rules != null ? rules : ImmutableSet.<FirewallRule>of();
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public Map<NetworkType, ? extends OptionsConverter> optionsConverters(){
|
||||
|
|
|
@ -77,7 +77,6 @@ import com.google.common.primitives.Ints;
|
|||
/**
|
||||
* defines the connection between the {@link CloudStackClient} implementation
|
||||
* and the jclouds {@link ComputeService}
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class CloudStackComputeServiceAdapter implements
|
||||
|
@ -107,7 +106,8 @@ public class CloudStackComputeServiceAdapter implements
|
|||
CreatePortForwardingRulesForIP setupPortForwardingRulesForIP,
|
||||
CreateFirewallRulesForIP setupFirewallRulesForIP,
|
||||
LoadingCache<String, Set<IPForwardingRule>> vmToRules,
|
||||
Map<String, Credentials> credentialStore, Map<NetworkType, ? extends OptionsConverter> optionsConverters,
|
||||
Map<String, Credentials> credentialStore,
|
||||
Map<NetworkType, ? extends OptionsConverter> optionsConverters,
|
||||
Supplier<LoadingCache<String, Zone>> zoneIdToZone) {
|
||||
this.client = checkNotNull(client, "client");
|
||||
this.jobComplete = checkNotNull(jobComplete, "jobComplete");
|
||||
|
@ -143,7 +143,7 @@ public class CloudStackComputeServiceAdapter implements
|
|||
|
||||
CloudStackTemplateOptions templateOptions = template.getOptions().as(CloudStackTemplateOptions.class);
|
||||
|
||||
checkState(optionsConverters.containsKey(zone.getNetworkType()), "no options converter configured for network type %s",zone.getNetworkType());
|
||||
checkState(optionsConverters.containsKey(zone.getNetworkType()), "no options converter configured for network type %s", zone.getNetworkType());
|
||||
DeployVirtualMachineOptions options = displayName(name).name(name);
|
||||
OptionsConverter optionsConverter = optionsConverters.get(zone.getNetworkType());
|
||||
options = optionsConverter.apply(templateOptions, networks, zoneId, options);
|
||||
|
@ -173,7 +173,7 @@ public class CloudStackComputeServiceAdapter implements
|
|||
zoneId, options);
|
||||
AsyncCreateResponse job = client.getVirtualMachineClient().deployVirtualMachineInZone(zoneId, serviceOfferingId,
|
||||
templateId, options);
|
||||
VirtualMachine vm = blockUntilJobCompletesAndReturnResult.<VirtualMachine> apply(job);
|
||||
VirtualMachine vm = blockUntilJobCompletesAndReturnResult.<VirtualMachine>apply(job);
|
||||
logger.debug("--- virtualmachine: %s", vm);
|
||||
LoginCredentials credentials = null;
|
||||
if (vm.isPasswordEnabled()) {
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package org.jclouds.cloudstack.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import java.util.Set;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import org.jclouds.cloudstack.CloudStackClient;
|
||||
import org.jclouds.cloudstack.domain.FirewallRule;
|
||||
import org.jclouds.cloudstack.options.ListFirewallRulesOptions;
|
||||
|
||||
@Singleton
|
||||
public class GetFirewallRulesByVirtualMachine extends CacheLoader<String, Set<FirewallRule>> {
|
||||
private final CloudStackClient client;
|
||||
|
||||
@Inject
|
||||
public GetFirewallRulesByVirtualMachine(CloudStackClient client) {
|
||||
this.client = checkNotNull(client, "client");
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws org.jclouds.rest.ResourceNotFoundException
|
||||
* when there is no ip forwarding rule available for the VM
|
||||
*/
|
||||
@Override
|
||||
public Set<FirewallRule> load(String input) {
|
||||
String publicIPId = client.getVirtualMachineClient().getVirtualMachine(input).getPublicIPId();
|
||||
Set<FirewallRule> rules = client.getFirewallClient()
|
||||
.listFirewallRules(ListFirewallRulesOptions.Builder.ipAddressId(publicIPId));
|
||||
return rules != null ? rules : ImmutableSet.<FirewallRule>of();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package org.jclouds.cloudstack.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import java.util.Set;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import org.jclouds.cloudstack.CloudStackClient;
|
||||
import org.jclouds.cloudstack.domain.IPForwardingRule;
|
||||
|
||||
@Singleton
|
||||
public class GetIPForwardingRulesByVirtualMachine extends CacheLoader<String, Set<IPForwardingRule>> {
|
||||
private final CloudStackClient client;
|
||||
|
||||
@Inject
|
||||
public GetIPForwardingRulesByVirtualMachine(CloudStackClient client) {
|
||||
this.client = checkNotNull(client, "client");
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws org.jclouds.rest.ResourceNotFoundException
|
||||
* when there is no ip forwarding rule available for the VM
|
||||
*/
|
||||
@Override
|
||||
public Set<IPForwardingRule> load(String input) {
|
||||
Set<IPForwardingRule> rules = client.getNATClient().getIPForwardingRulesForVirtualMachine(input);
|
||||
return rules != null ? rules : ImmutableSet.<IPForwardingRule>of();
|
||||
}
|
||||
}
|
|
@ -21,6 +21,9 @@ package org.jclouds.cloudstack.compute;
|
|||
import static com.google.common.collect.Iterables.getFirst;
|
||||
import static com.google.inject.name.Names.bindProperties;
|
||||
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
||||
import org.jclouds.cloudstack.domain.FirewallRule;
|
||||
import org.jclouds.cloudstack.functions.GetFirewallRulesByVirtualMachine;
|
||||
import org.jclouds.cloudstack.functions.GetIPForwardingRulesByVirtualMachine;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
|
||||
|
@ -33,7 +36,6 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.jclouds.cloudstack.CloudStackClient;
|
||||
import org.jclouds.cloudstack.compute.config.CloudStackComputeServiceContextModule;
|
||||
import org.jclouds.cloudstack.compute.config.CloudStackComputeServiceContextModule.GetIPForwardingRulesByVirtualMachine;
|
||||
import org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions;
|
||||
import org.jclouds.cloudstack.compute.strategy.CloudStackComputeServiceAdapter;
|
||||
import org.jclouds.cloudstack.compute.strategy.OptionsConverter;
|
||||
|
@ -113,6 +115,10 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien
|
|||
bind(new TypeLiteral<Map<NetworkType, ? extends OptionsConverter>>() {}).
|
||||
toInstance(new CloudStackComputeServiceContextModule().optionsConverters());
|
||||
bind(String.class).annotatedWith(Names.named(PROPERTY_SESSION_INTERVAL)).toInstance("60");
|
||||
bind(new TypeLiteral<CacheLoader<String, Set<IPForwardingRule>>>() {
|
||||
}).to(GetIPForwardingRulesByVirtualMachine.class);
|
||||
bind(new TypeLiteral<CacheLoader<String, Set<FirewallRule>>>() {
|
||||
}).to(GetFirewallRulesByVirtualMachine.class);
|
||||
bind(new TypeLiteral<CacheLoader<String, Zone>>() {}).
|
||||
to(ZoneIdToZone.class);
|
||||
bind(new TypeLiteral<Supplier<LoadingCache<String, Zone>>>() {}).
|
||||
|
@ -127,12 +133,19 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien
|
|||
return new RetryablePredicate<String>(jobComplete, 1200, 1, 5, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Provides
|
||||
@Singleton
|
||||
protected LoadingCache<String, Set<IPForwardingRule>> getIPForwardingRuleByVirtualMachine(
|
||||
GetIPForwardingRulesByVirtualMachine getIPForwardingRule) {
|
||||
return CacheBuilder.newBuilder().build(getIPForwardingRule);
|
||||
protected LoadingCache<String, Set<IPForwardingRule>> getIPForwardingRulesByVirtualMachine(
|
||||
GetIPForwardingRulesByVirtualMachine getIPForwardingRules) {
|
||||
return CacheBuilder.newBuilder().build(getIPForwardingRules);
|
||||
}
|
||||
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected LoadingCache<String, Set<FirewallRule>> getFirewallRulesByVirtualMachine(
|
||||
GetFirewallRulesByVirtualMachine getFirewallRules) {
|
||||
return CacheBuilder.newBuilder().build(getFirewallRules);
|
||||
}
|
||||
};
|
||||
adapter = Guice.createInjector(module, new SLF4JLoggingModule()).getInstance(
|
||||
|
|
|
@ -28,7 +28,6 @@ import java.util.Set;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.jclouds.cloudstack.compute.config.CloudStackComputeServiceContextModule.GetIPForwardingRulesByVirtualMachine;
|
||||
import org.jclouds.cloudstack.domain.IPForwardingRule;
|
||||
import org.jclouds.cloudstack.domain.Network;
|
||||
import org.jclouds.cloudstack.domain.PublicIPAddress;
|
||||
|
|
Loading…
Reference in New Issue