diff --git a/.gitignore b/.gitignore index 006f24f892..a695d7202d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ bin/ .project .idea/ *.iml +*.eml *.ipr *.iws TAGS diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/config/CloudStackComputeServiceContextModule.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/config/CloudStackComputeServiceContextModule.java index 77682a28f8..daf3ef54ae 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/config/CloudStackComputeServiceContextModule.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/config/CloudStackComputeServiceContextModule.java @@ -22,12 +22,14 @@ import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; import java.util.Map; +import java.util.Set; import java.util.concurrent.TimeUnit; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; +import com.google.common.collect.ImmutableSet; import org.jclouds.cloudstack.CloudStackAsyncClient; import org.jclouds.cloudstack.CloudStackClient; import org.jclouds.cloudstack.compute.functions.ServiceOfferingToHardware; @@ -104,8 +106,8 @@ public class CloudStackComputeServiceContextModule bind(new TypeLiteral>() { }).to(TemplateToOperatingSystem.class); install(new FactoryModuleBuilder().build(StaticNATVirtualMachineInNetwork.Factory.class)); - bind(new TypeLiteral>() { - }).to(GetIPForwardingRuleByVirtualMachine.class); + bind(new TypeLiteral>>() { + }).to(GetIPForwardingRulesByVirtualMachine.class); } @Provides @@ -171,17 +173,17 @@ public class CloudStackComputeServiceContextModule @Provides @Singleton - protected Cache getIPForwardingRuleByVirtualMachine( - CacheLoader getIPForwardingRule) { - return CacheBuilder.newBuilder().build(getIPForwardingRule); + protected Cache> getIPForwardingRulesByVirtualMachine( + CacheLoader> getIPForwardingRules) { + return CacheBuilder.newBuilder().build(getIPForwardingRules); } @Singleton - public static class GetIPForwardingRuleByVirtualMachine extends CacheLoader { + public static class GetIPForwardingRulesByVirtualMachine extends CacheLoader> { private final CloudStackClient client; @Inject - public GetIPForwardingRuleByVirtualMachine(CloudStackClient client) { + public GetIPForwardingRulesByVirtualMachine(CloudStackClient client) { this.client = checkNotNull(client, "client"); } @@ -190,11 +192,9 @@ public class CloudStackComputeServiceContextModule * when there is no ip forwarding rule available for the VM */ @Override - public IPForwardingRule load(Long input) { - IPForwardingRule rule = client.getNATClient().getIPForwardingRuleForVirtualMachine(input); - if (rule == null) - throw new ResourceNotFoundException("no ip forwarding rule for: " + input); - return rule; + public Set load(Long input) { + Set rules = client.getNATClient().getIPForwardingRulesForVirtualMachine(input); + return rules != null ? rules : ImmutableSet.of(); } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/functions/VirtualMachineToNodeMetadata.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/functions/VirtualMachineToNodeMetadata.java index e1732f15a4..e7cd005e15 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/functions/VirtualMachineToNodeMetadata.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/functions/VirtualMachineToNodeMetadata.java @@ -19,14 +19,19 @@ package org.jclouds.cloudstack.compute.functions; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; +import static com.google.common.collect.Iterables.transform; import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName; import java.util.Map; import java.util.Set; +import javax.annotation.Nullable; import javax.inject.Inject; import javax.inject.Singleton; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; import org.jclouds.cloudstack.domain.IPForwardingRule; import org.jclouds.cloudstack.domain.VirtualMachine; import org.jclouds.collect.FindResourceInSet; @@ -56,32 +61,32 @@ import com.google.common.util.concurrent.UncheckedExecutionException; public class VirtualMachineToNodeMetadata implements Function { public static final Map vmStateToNodeState = ImmutableMap - . builder().put(VirtualMachine.State.STARTING, NodeState.PENDING) - .put(VirtualMachine.State.RUNNING, NodeState.RUNNING).put(VirtualMachine.State.STOPPING, NodeState.SUSPENDED) - .put(VirtualMachine.State.STOPPED, NodeState.PENDING) - .put(VirtualMachine.State.DESTROYED, NodeState.TERMINATED) - .put(VirtualMachine.State.EXPUNGING, NodeState.TERMINATED) - .put(VirtualMachine.State.MIGRATING, NodeState.PENDING).put(VirtualMachine.State.ERROR, NodeState.ERROR) - .put(VirtualMachine.State.UNKNOWN, NodeState.UNRECOGNIZED) + .builder().put(VirtualMachine.State.STARTING, NodeState.PENDING) + .put(VirtualMachine.State.RUNNING, NodeState.RUNNING).put(VirtualMachine.State.STOPPING, NodeState.SUSPENDED) + .put(VirtualMachine.State.STOPPED, NodeState.PENDING) + .put(VirtualMachine.State.DESTROYED, NodeState.TERMINATED) + .put(VirtualMachine.State.EXPUNGING, NodeState.TERMINATED) + .put(VirtualMachine.State.MIGRATING, NodeState.PENDING).put(VirtualMachine.State.ERROR, NodeState.ERROR) + .put(VirtualMachine.State.UNKNOWN, NodeState.UNRECOGNIZED) // TODO: is this really a state? - .put(VirtualMachine.State.SHUTDOWNED, NodeState.PENDING) - .put(VirtualMachine.State.UNRECOGNIZED, NodeState.UNRECOGNIZED).build(); + .put(VirtualMachine.State.SHUTDOWNED, NodeState.PENDING) + .put(VirtualMachine.State.UNRECOGNIZED, NodeState.UNRECOGNIZED).build(); private final FindLocationForVirtualMachine findLocationForVirtualMachine; private final FindHardwareForVirtualMachine findHardwareForVirtualMachine; private final FindImageForVirtualMachine findImageForVirtualMachine; - private final Cache getIPForwardingRuleByVirtualMachine; + private final Cache> getIPForwardingRulesByVirtualMachine; @Inject VirtualMachineToNodeMetadata(FindLocationForVirtualMachine findLocationForVirtualMachine, - FindHardwareForVirtualMachine findHardwareForVirtualMachine, - FindImageForVirtualMachine findImageForVirtualMachine, - Cache getIPForwardingRuleByVirtualMachine) { + FindHardwareForVirtualMachine findHardwareForVirtualMachine, + FindImageForVirtualMachine findImageForVirtualMachine, + Cache> getIPForwardingRulesByVirtualMachine) { this.findLocationForVirtualMachine = checkNotNull(findLocationForVirtualMachine, "findLocationForVirtualMachine"); this.findHardwareForVirtualMachine = checkNotNull(findHardwareForVirtualMachine, "findHardwareForVirtualMachine"); this.findImageForVirtualMachine = checkNotNull(findImageForVirtualMachine, "findImageForVirtualMachine"); - this.getIPForwardingRuleByVirtualMachine = checkNotNull(getIPForwardingRuleByVirtualMachine, - "getIPForwardingRuleByVirtualMachine"); + this.getIPForwardingRulesByVirtualMachine = checkNotNull(getIPForwardingRulesByVirtualMachine, + "getIPForwardingRulesByVirtualMachine"); } @Override @@ -108,15 +113,27 @@ public class VirtualMachineToNodeMetadata implements Function addresses = ImmutableSet. of(from.getIPAddress()); + Set addresses = ImmutableSet.of(from.getIPAddress()); if (isPrivate) builder.privateAddresses(addresses); else builder.publicAddresses(addresses); } try { - IPForwardingRule rule = getIPForwardingRuleByVirtualMachine.getUnchecked(from.getId()); - builder.publicAddresses(ImmutableSet. of(rule.getIPAddress())); + + builder.publicAddresses(transform(filter(getIPForwardingRulesByVirtualMachine.getUnchecked(from.getId()), + new Predicate() { + @Override + public boolean apply(@Nullable IPForwardingRule rule) { + return !"Deleting".equals(rule.getState()); + } + }), + new Function() { + @Override + public String apply(@Nullable IPForwardingRule rule) { + return rule.getIPAddress(); + } + })); } catch (UncheckedExecutionException e) { if (Throwables2.getFirstThrowableOfType(e, ResourceNotFoundException.class) == null) { Throwables.propagateIfPossible(e.getCause()); @@ -165,9 +182,9 @@ public class VirtualMachineToNodeMetadata implements Function forwardingRules = client.getNATClient().getIPForwardingRulesForVirtualMachine(guestId); + for(IPForwardingRule rule : forwardingRules) { + job = client.getNATClient().deleteIPForwardingRule(rule.getId()); + jobComplete.apply(job); + } } @Override diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/TemplateExtraction.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/TemplateExtraction.java index 5972ea53dd..48197be699 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/TemplateExtraction.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/TemplateExtraction.java @@ -18,6 +18,7 @@ */ package org.jclouds.cloudstack.domain; +import com.google.common.base.Objects; import com.google.gson.annotations.SerializedName; import java.util.Date; @@ -151,6 +152,11 @@ public class TemplateExtraction implements Comparable { return this; } + public TemplateExtraction build() { + return new TemplateExtraction(id, accountId, created, extractId, + extractMode, name, state, status, storageType, uploadPercentage, + url,zoneId, zoneName); + } } private long id; @@ -169,9 +175,33 @@ public class TemplateExtraction implements Comparable { private String url; @SerializedName("zoneid") private long zoneId; + + /** + * Construct a new TemplateExtraction instance + */ + public TemplateExtraction(long id, long accountId, Date created, long extractId, + ExtractMode extractMode, String name, String state, String status, + String storageType, int uploadPercentage, String url, + long zoneId, String zoneName) { + this.id = id; + this.accountId = accountId; + this.created = created; + this.extractId = extractId; + this.extractMode = extractMode; + this.name = name; + this.state = state; + this.status = status; + this.storageType = storageType; + this.uploadPercentage = uploadPercentage; + this.url = url; + this.zoneId = zoneId; + this.zoneName = zoneName; + } + @SerializedName("zonename") private String zoneName; + /** * present only for serializer */ @@ -270,23 +300,48 @@ public class TemplateExtraction implements Comparable { } @Override - public boolean equals(Object o) { - throw new RuntimeException("FIXME: Implement me"); + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + + TemplateExtraction other = (TemplateExtraction) obj; + return id == other.id + && accountId == other.accountId + && Objects.equal(created, other.created) + && extractId == other.extractId + && Objects.equal(extractMode, other.extractMode) + && Objects.equal(name, other.name) + && Objects.equal(state, other.state) + && Objects.equal(status, other.status) + && Objects.equal(storageType, other.storageType) + && uploadPercentage == other.uploadPercentage + && Objects.equal(url, other.url) + && zoneId == other.zoneId + && Objects.equal(zoneName, other.zoneName); } @Override public int hashCode() { - throw new RuntimeException("FIXME: Implement me"); + return Objects.hashCode(id, accountId, created, extractId, extractMode, + name, state, status, storageType, uploadPercentage, url, zoneId, zoneName); } @Override public String toString() { - throw new RuntimeException("FIXME: Implement me"); + return "[id=" + id + ", accountId=" + accountId + ", created=" + created + + ", extractId=" + extractId + ", extractMode=" + extractMode + + ", name=" + name + ", state=" + state + ", status=" + status + + ", storageType=" + storageType + ", uploadPercentage=" + uploadPercentage + + ", url=" + url + ", zoneId=" + zoneId + ", zoneName=" + zoneName; } @Override public int compareTo(TemplateExtraction other) { - throw new RuntimeException("FIXME: Implement me"); + return new Long(id).compareTo(other.id); } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NATAsyncClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NATAsyncClient.java index 23a96a5d30..352d387b9b 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NATAsyncClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NATAsyncClient.java @@ -78,26 +78,24 @@ public interface NATAsyncClient { ListenableFuture getIPForwardingRule(@QueryParam("id") long id); /** - * @see NATClient#getIPForwardingRuleForIPAddress + * @see NATClient#getIPForwardingRulesForIPAddress */ @GET @QueryParams(keys = "command", values = "listIpForwardingRules") @SelectJson("ipforwardingrule") - @OnlyElement @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getIPForwardingRuleForIPAddress(@QueryParam("ipaddressid") long id); + ListenableFuture> getIPForwardingRulesForIPAddress(@QueryParam("ipaddressid") long id); /** - * @see NATClient#getIPForwardingRuleForVirtualMachine + * @see NATClient#getIPForwardingRulesForVirtualMachine */ @GET @QueryParams(keys = "command", values = "listIpForwardingRules") @SelectJson("ipforwardingrule") - @OnlyElement @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getIPForwardingRuleForVirtualMachine(@QueryParam("virtualmachineid") long id); + ListenableFuture> getIPForwardingRulesForVirtualMachine(@QueryParam("virtualmachineid") long id); /** * @see NATClient#createIPForwardingRule diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NATClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NATClient.java index 42e7c1c5e6..9fafec7909 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NATClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/NATClient.java @@ -59,22 +59,22 @@ public interface NATClient { IPForwardingRule getIPForwardingRule(long id); /** - * get a specific IPForwardingRule by ipaddress id + * get a set of IPForwardingRules by ipaddress id * * @param id * IPAddress of rule to get - * @return IPForwardingRule or null if not found + * @return IPForwardingRule matching query or empty if not found */ - IPForwardingRule getIPForwardingRuleForIPAddress(long id); + Set getIPForwardingRulesForIPAddress(long id); /** - * get a specific IPForwardingRule by virtual machine id + * get a set of IPForwardingRules by virtual machine id * * @param id * virtual machine of rule to get - * @return IPForwardingRule or null if not found + * @return IPForwardingRule matching query or empty set if not found */ - IPForwardingRule getIPForwardingRuleForVirtualMachine(long id); + Set getIPForwardingRulesForVirtualMachine(long id); /** * Creates an ip forwarding rule diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SnapshotAsyncClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SnapshotAsyncClient.java index 7e57cacb99..ca1d993dee 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SnapshotAsyncClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SnapshotAsyncClient.java @@ -80,6 +80,7 @@ public interface SnapshotAsyncClient { @GET @Consumes(MediaType.APPLICATION_JSON) @QueryParams(keys = "command", values = "listSnapshots") + @SelectJson("snapshot") @Unwrap @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) ListenableFuture> listSnapshots(ListSnapshotsOptions... options); @@ -162,5 +163,4 @@ public interface SnapshotAsyncClient { @Unwrap @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) ListenableFuture> listSnapshotPolicies(@QueryParam("volumeid") long volumeId, ListSnapshotPoliciesOptions... options); - } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VolumeAsyncClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VolumeAsyncClient.java index 28271b08f6..3f7a6d0a72 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VolumeAsyncClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VolumeAsyncClient.java @@ -29,12 +29,9 @@ import org.jclouds.cloudstack.domain.AsyncCreateResponse; import org.jclouds.cloudstack.domain.Volume; import org.jclouds.cloudstack.filters.QuerySigner; import org.jclouds.cloudstack.options.ListVolumesOptions; -import org.jclouds.rest.annotations.ExceptionParser; -import org.jclouds.rest.annotations.QueryParams; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.SelectJson; -import org.jclouds.rest.annotations.Unwrap; +import org.jclouds.rest.annotations.*; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; /** @@ -58,6 +55,17 @@ public interface VolumeAsyncClient { @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) ListenableFuture> listVolumes(ListVolumesOptions... options); + /** + * @see VolumeClient#getVolume(long) + */ + @GET + @Consumes(MediaType.APPLICATION_JSON) + @QueryParams(keys = "command", values = "listVolumes") + @SelectJson("volume") + @OnlyElement + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getVolume(@QueryParam("id") long id); + /** * @see VolumeClient#createVolumeFromDiskOfferingInZone(String, long, long) diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VolumeClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VolumeClient.java index 2a71a3b605..f0d57f3bac 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VolumeClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VolumeClient.java @@ -59,10 +59,18 @@ public interface VolumeClient { /** * List volumes * - * @return volume list or null if not found + * @return volume list, empty if not found */ Set listVolumes(ListVolumesOptions... options); + /** + * Get volume by id + * + * @param id the volume id to retrieve + * @return volume or null if not found + */ + Volume getVolume(long id); + /** * Deletes a attached disk volume * diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/StaticNATVirtualMachineInNetwork.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/StaticNATVirtualMachineInNetwork.java index 5d2d076a0c..c15bc0c952 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/StaticNATVirtualMachineInNetwork.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/StaticNATVirtualMachineInNetwork.java @@ -24,6 +24,7 @@ import static com.google.common.base.Preconditions.checkState; import javax.inject.Inject; import javax.inject.Singleton; +import com.google.common.collect.ImmutableSet; import org.jclouds.cloudstack.CloudStackClient; import org.jclouds.cloudstack.domain.AsyncCreateResponse; import org.jclouds.cloudstack.domain.AsyncJob; @@ -37,6 +38,8 @@ import com.google.common.base.Predicate; import com.google.common.cache.Cache; import com.google.inject.assistedinject.Assisted; +import java.util.Set; + /** * * @author Adrian Cole @@ -51,17 +54,17 @@ public class StaticNATVirtualMachineInNetwork implements Function jobComplete; - private final Cache getIPForwardingRuleByVirtualMachine; + private final Cache> getIPForwardingRulesByVirtualMachine; @Inject public StaticNATVirtualMachineInNetwork(CloudStackClient client, ReuseOrAssociateNewPublicIPAddress reuseOrAssociate, Predicate jobComplete, - Cache getIPForwardingRuleByVirtualMachine, @Assisted Network network) { + Cache> getIPForwardingRulesByVirtualMachine, @Assisted Network network) { this.client = checkNotNull(client, "client"); this.reuseOrAssociate = checkNotNull(reuseOrAssociate, "reuseOrAssociate"); this.jobComplete = checkNotNull(jobComplete, "jobComplete"); - this.getIPForwardingRuleByVirtualMachine = checkNotNull(getIPForwardingRuleByVirtualMachine, - "getIPForwardingRuleByVirtualMachine"); + this.getIPForwardingRulesByVirtualMachine = checkNotNull(getIPForwardingRulesByVirtualMachine, + "getIPForwardingRulesByVirtualMachine"); this.network = checkNotNull(network, "network"); } @@ -86,7 +89,7 @@ public class StaticNATVirtualMachineInNetwork implements Function response = client.getAsyncJobClient().getAsyncJob(job.getJobId()); checkState(response.getResult() != null, "No result after creating IP forwarding rule: ", response); - getIPForwardingRuleByVirtualMachine.asMap().put(vm.getId(), response.getResult()); + getIPForwardingRulesByVirtualMachine.asMap().put(vm.getId(), ImmutableSet.of(response.getResult())); return ip; } } \ No newline at end of file diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java index 8248b6d049..22b0fe803d 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java @@ -18,6 +18,7 @@ */ package org.jclouds.cloudstack.compute; +import static com.google.common.collect.Iterables.getFirst; import static com.google.inject.name.Names.bindProperties; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; @@ -26,12 +27,13 @@ import static org.testng.Assert.fail; import java.io.IOException; import java.util.Map; import java.util.Random; +import java.util.Set; import java.util.concurrent.TimeUnit; import javax.inject.Singleton; import org.jclouds.cloudstack.CloudStackClient; -import org.jclouds.cloudstack.compute.config.CloudStackComputeServiceContextModule.GetIPForwardingRuleByVirtualMachine; +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.domain.IPForwardingRule; @@ -117,8 +119,8 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien @SuppressWarnings("unused") @Provides @Singleton - protected Cache getIPForwardingRuleByVirtualMachine( - GetIPForwardingRuleByVirtualMachine getIPForwardingRule) { + protected Cache> getIPForwardingRuleByVirtualMachine( + GetIPForwardingRulesByVirtualMachine getIPForwardingRule) { return CacheBuilder.newBuilder().build(getIPForwardingRule); } }; @@ -160,7 +162,8 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien assertEquals(vm.getNode().getDisplayName(), name); // check to see if we setup a NAT rule (conceding we could check this from // cache) - IPForwardingRule rule = client.getNATClient().getIPForwardingRuleForVirtualMachine(vm.getNode().getId()); + IPForwardingRule rule = getFirst( + client.getNATClient().getIPForwardingRulesForVirtualMachine(vm.getNode().getId()), null); String address = rule != null ? rule.getIPAddress() : vm.getNode().getIPAddress(); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/functions/VirtualMachineToNodeMetadataTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/functions/VirtualMachineToNodeMetadataTest.java index 2958cafcdd..0fa4331d21 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/functions/VirtualMachineToNodeMetadataTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/functions/VirtualMachineToNodeMetadataTest.java @@ -64,12 +64,12 @@ public class VirtualMachineToNodeMetadataTest { . of(TemplateToImageTest.one, TemplateToImageTest.two)); VirtualMachineToNodeMetadata parser = new VirtualMachineToNodeMetadata(new FindLocationForVirtualMachine( locationSupplier), new FindHardwareForVirtualMachine(hardwareSupplier), new FindImageForVirtualMachine( - imageSupplier), CacheBuilder.newBuilder(). build( - new CacheLoader() { + imageSupplier), CacheBuilder.newBuilder().> build( + new CacheLoader>() { @Override - public IPForwardingRule load(Long arg0) throws Exception { - return IPForwardingRule.builder().id(1234l).IPAddress("1.1.1.1").build(); + public Set load(Long arg0) throws Exception { + return ImmutableSet.of(IPForwardingRule.builder().id(1234l).IPAddress("1.1.1.1").build()); } })); @@ -102,11 +102,11 @@ public class VirtualMachineToNodeMetadataTest { . of(TemplateToImageTest.one, TemplateToImageTest.two)); VirtualMachineToNodeMetadata parser = new VirtualMachineToNodeMetadata(new FindLocationForVirtualMachine( locationSupplier), new FindHardwareForVirtualMachine(hardwareSupplier), new FindImageForVirtualMachine( - imageSupplier), CacheBuilder.newBuilder(). build( - new CacheLoader() { + imageSupplier), CacheBuilder.newBuilder().> build( + new CacheLoader>() { @Override - public IPForwardingRule load(Long arg0) throws Exception { + public Set load(Long arg0) throws Exception { throw new ResourceNotFoundException("no ip forwarding rule for: " + arg0); } diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkClientLiveTest.java index 310f949c4f..fb8800756f 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/NetworkClientLiveTest.java @@ -115,7 +115,7 @@ public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest { .getNetworkClient() // startIP/endIP/netmask/gateway must be specified together .createNetworkInZone(zone.getId(), offering.getId(), name, name, - vlan("2").startIP("192.168.1.2").netmask("255.255.255.0").gateway("192.168.1.1")); + vlan("65").startIP("192.168.1.2").netmask("255.255.255.0").gateway("192.168.1.1")); checkNetwork(network); } catch (IllegalStateException e) { Logger.getAnonymousLogger().log(Level.SEVERE, "couldn't create a network, skipping test", e); @@ -173,7 +173,7 @@ public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest { break; case DIRECT: // TODO: I've found a network that doesn't have a netmask associated - // assert network.getNetmask() != null : network; + assert network.getNetmask() != null : network; assert network.getGateway() != null : network; assert network.getVLAN() != null : network; assertEquals(network.getBroadcastURI(), URI.create("vlan://" + network.getVLAN())); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SnapshotAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SnapshotAsyncClientTest.java index f50ad8c4e6..63d1926412 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SnapshotAsyncClientTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SnapshotAsyncClientTest.java @@ -18,9 +18,8 @@ */ package org.jclouds.cloudstack.features; -import com.google.common.base.Functions; -import com.google.common.collect.ImmutableSet; -import com.google.inject.TypeLiteral; +import java.lang.reflect.Method; + import org.jclouds.cloudstack.domain.Snapshot; import org.jclouds.cloudstack.domain.SnapshotPolicySchedule; import org.jclouds.cloudstack.options.CreateSnapshotOptions; @@ -29,6 +28,7 @@ import org.jclouds.cloudstack.options.ListSnapshotsOptions; import org.jclouds.cloudstack.util.SnapshotPolicySchedules; import org.jclouds.functions.IdentityFunction; import org.jclouds.http.HttpRequest; +import org.jclouds.http.functions.ParseFirstJsonValueNamed; import org.jclouds.http.functions.ReleasePayloadAndReturn; import org.jclouds.http.functions.UnwrapOnlyJsonValue; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; @@ -38,7 +38,9 @@ import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; -import java.lang.reflect.Method; +import com.google.common.base.Functions; +import com.google.common.collect.ImmutableSet; +import com.google.inject.TypeLiteral; /** * Tests the behaviour of SnapshotAsyncClient. @@ -92,7 +94,7 @@ public class SnapshotAsyncClientTest extends BaseCloudStackAsyncClientTest zones = client.getZoneClient().listZones(); + assertNotNull(zones); + assertFalse(zones.isEmpty()); + zoneId = Iterables.get(zones, 0).getId(); + } + + public void testListSnapshots() { + Set snapshots = client.getSnapshotClient().listSnapshots(); + assertNotNull(snapshots); + assertFalse(snapshots.isEmpty()); + + for (Snapshot snapshot : snapshots) { + checkSnapshot(snapshot); + } + } + + public void testListSnapshotsById() { + Iterable snapshotIds = Iterables.transform(client.getSnapshotClient().listSnapshots(), new Function() { + public Long apply(Snapshot input) { + return input.getId(); + } + }); + assertNotNull(snapshotIds); + assertFalse(Iterables.isEmpty(snapshotIds)); + + for (Long id : snapshotIds) { + Set found = client.getSnapshotClient().listSnapshots(ListSnapshotsOptions.Builder.id(id)); + assertNotNull(found); + assertEquals(1, found.size()); + Snapshot snapshot = Iterables.getOnlyElement(found); + assertEquals(id.longValue(), snapshot.getId()); + checkSnapshot(snapshot); + } + } + + public void testListSnapshotsNonexistantId() { + Set found = client.getSnapshotClient().listSnapshots(ListSnapshotsOptions.Builder.id(-1)); + assertNotNull(found); + assertTrue(found.isEmpty()); + } + + public void testGetSnapshotById() { + Iterable snapshotIds = Iterables.transform(client.getSnapshotClient().listSnapshots(), new Function() { + public Long apply(Snapshot input) { + return input.getId(); + } + }); + assertNotNull(snapshotIds); + assertFalse(Iterables.isEmpty(snapshotIds)); + + for (Long id : snapshotIds) { + Snapshot found = client.getSnapshotClient().getSnapshot(id); + assertNotNull(found); + assertEquals(id.longValue(), found.getId()); + checkSnapshot(found); + } + } + + public void testGetSnapshotNonexistantId() { + Snapshot found = client.getSnapshotClient().getSnapshot(-1); + assertNull(found); + } + + public void testCreateSnapshotFromVolume() { + // Pick some volume + long volumeId = Iterables.get(client.getVolumeClient().listVolumes(), 0).getId(); + + Snapshot snapshot = null; + while (snapshot == null) { + try { + AsyncCreateResponse job = client.getSnapshotClient().createSnapshot(volumeId); + assertTrue(jobComplete.apply(job.getJobId())); + snapshot = findSnapshotWithId(job.getId()); + } catch (IllegalStateException e) { + // TODO snapshot creation failed - retry? + } + } + + checkSnapshot(snapshot); + + // Delete the snapshot + client.getSnapshotClient().deleteSnapshot(snapshot.getId()); + } + + private void checkSnapshot(final Snapshot snapshot) { + assertNotNull(snapshot.getId()); + assertNotNull(snapshot.getName()); + assertNotSame(Snapshot.Type.UNRECOGNIZED, snapshot.getSnapshotType()); + } + + private Snapshot findSnapshotWithId(final long id) { + return find(client.getSnapshotClient().listSnapshots(), new Predicate() { + @Override + public boolean apply(Snapshot arg0) { + return arg0.getId() == id; + } + }); + } +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/TemplateClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/TemplateClientLiveTest.java index 9c7d11cc57..eeab3c9511 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/TemplateClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/TemplateClientLiveTest.java @@ -48,6 +48,7 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest { private VirtualMachine vm; private Template template; + @Test public void testListTemplates() throws Exception { Set