diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java index 56b7c042da..19e178b6de 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java @@ -131,10 +131,11 @@ public interface GoogleComputeEngineApi extends Closeable { * Provides access to Instance features * * @param projectName the name of the project + * @param zone zone the instances are in. */ @Delegate - @Path("/projects/{project}") - InstanceApi getInstanceApi(@PathParam("project") String projectName); + @Path("/projects/{project}/zones/{zone}") + InstanceApi getInstanceApi(@PathParam("project") String projectName, @PathParam("zone") String zone); /** * Provides access to MachineType features diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java index 3a80beaeff..bedace7a18 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java @@ -139,9 +139,9 @@ public final class GoogleComputeEngineServiceAdapter implements ComputeServiceAd disks.add(new PersistentDisk(Mode.READ_WRITE, bootDisk.selfLink(), - null, - true, - true)); + null, // deviceName + true, // autoDelete + true)); // boot } disks.addAll(options.getDisks()); @@ -169,9 +169,9 @@ public final class GoogleComputeEngineServiceAdapter implements ComputeServiceAd instanceTemplate.metadata(metadataBuilder.build()); instanceTemplate.serviceAccounts(options.getServiceAccounts()); - final InstanceApi instanceApi = api.getInstanceApi(userProject.get()); - final String zone = template.getLocation().getId(); - Operation operation = instanceApi.createInZone(name, zone, instanceTemplate); + String zone = template.getLocation().getId(); + final InstanceApi instanceApi = api.getInstanceApi(userProject.get(), zone); + Operation operation = instanceApi.create(name, instanceTemplate); if (options.shouldBlockUntilRunning()) { waitOperationDone(operation); @@ -181,23 +181,20 @@ public final class GoogleComputeEngineServiceAdapter implements ComputeServiceAd AtomicReference instance = Atomics.newReference(); retry(new Predicate>() { - @Override - public boolean apply(AtomicReference input) { - input.set(instanceApi.getInZone(zone, name)); + @Override public boolean apply(AtomicReference input) { + input.set(instanceApi.get(name)); return input.get() != null; } }, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS).apply(instance); if (!options.getTags().isEmpty()) { - Operation tagsOperation = instanceApi - .setTagsInZone(zone, name, options.getTags(), instance.get().tags().fingerprint()); + Operation tagsOperation = instanceApi.setTags(name, options.getTags(), instance.get().tags().fingerprint()); waitOperationDone(tagsOperation); retry(new Predicate>() { - @Override - public boolean apply(AtomicReference input) { - input.set(instanceApi.getInZone(zone, name)); + @Override public boolean apply(AtomicReference input) { + input.set(instanceApi.get(name)); return input.get() != null; } }, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS).apply(instance); @@ -206,18 +203,14 @@ public final class GoogleComputeEngineServiceAdapter implements ComputeServiceAd // Add tags for security groups final FirewallTagNamingConvention naming = firewallTagNamingConvention.get(group); Set tags = FluentIterable.from(Ints.asList(options.getInboundPorts())) - .transform(new Function(){ - @Override - public String apply(Integer input) { - return input != null - ? naming.name(input) - : null; - } - }) - .toSet(); - instanceApi.setTagsInZone(zone, instance.get().name(), tags, instance.get().tags().fingerprint()); + .transform(new Function() { + @Override public String apply(Integer input) { + return input != null ? naming.name(input) : null; + } + }).toSet(); + instanceApi.setTags(instance.get().name(), tags, instance.get().tags().fingerprint()); - InstanceInZone instanceInZone = new InstanceInZone(instance.get(), zone); + InstanceInZone instanceInZone = InstanceInZone.create(instance.get(), zone); return new NodeAndInitialCredentials(instanceInZone, instanceInZone.slashEncode(), credentials); } @@ -240,8 +233,7 @@ public final class GoogleComputeEngineServiceAdapter implements ComputeServiceAd waitOperationDone(diskOperation); - return api.getDiskApi(userProject.get()).getInZone(template.getLocation().getId(), - diskName); + return api.getDiskApi(userProject.get()).getInZone(template.getLocation().getId(), diskName); } @Override @@ -252,15 +244,12 @@ public final class GoogleComputeEngineServiceAdapter implements ComputeServiceAd for (Iterator> i = api.getMachineTypeApi(userProject.get()).listInZone(zone.getId()); i.hasNext(); ) { builder.addAll(FluentIterable.from(i.next()).filter(new Predicate() { - @Override - public boolean apply(MachineType input) { + @Override public boolean apply(MachineType input) { return input.deprecated() == null; } }).transform(new Function() { - - @Override - public MachineTypeInZone apply(MachineType arg0) { - return new MachineTypeInZone(arg0, arg0.zone()); + @Override public MachineTypeInZone apply(MachineType arg0) { + return MachineTypeInZone.create(arg0, arg0.zone()); } })); } @@ -294,24 +283,20 @@ public final class GoogleComputeEngineServiceAdapter implements ComputeServiceAd @Override public InstanceInZone getNode(String name) { - SlashEncodedIds slashEncodedIds = SlashEncodedIds.fromSlashEncoded(name); - - Instance instance = api.getInstanceApi(userProject.get()).getInZone(slashEncodedIds.getFirstId(), - slashEncodedIds.getSecondId()); - - return instance == null ? null : new InstanceInZone(instance, slashEncodedIds.getFirstId()); + SlashEncodedIds zoneAndId = SlashEncodedIds.fromSlashEncoded(name); + Instance instance = api.getInstanceApi(userProject.get(), zoneAndId.left()).get(zoneAndId.right()); + return instance == null ? null : InstanceInZone.create(instance, zoneAndId.left()); } @Override public Iterable listNodes() { return FluentIterable.from(zones.get().values()) .transformAndConcat(new Function>() { - @Override - public Iterable apply(final Location input) { - return transform(concat(api.getInstanceApi(userProject.get()).listInZone(input.getId())), + @Override public Iterable apply(final Location input) { + return transform(concat(api.getInstanceApi(userProject.get(), input.getId()).list()), new Function() { @Override public InstanceInZone apply(Instance arg0) { - return new InstanceInZone(arg0, input.getId()); + return InstanceInZone.create(arg0, input.getId()); } }); } @@ -319,22 +304,19 @@ public final class GoogleComputeEngineServiceAdapter implements ComputeServiceAd } @Override - public Iterable listNodesByIds(final Iterable ids) { + public Iterable listNodesByIds(final Iterable zoneAndId) { return filter(listNodes(), new Predicate() { - - @Override - public boolean apply(InstanceInZone instanceInZone) { - return contains(ids, instanceInZone.getInstance().name()); + @Override public boolean apply(InstanceInZone instanceInZone) { + return contains(zoneAndId, instanceInZone.instance().name()); } }); } @Override public void destroyNode(final String name) { - SlashEncodedIds slashEncodedIds = SlashEncodedIds.fromSlashEncoded(name); + SlashEncodedIds zoneAndId = SlashEncodedIds.fromSlashEncoded(name); String diskName = null; - Instance instance = api.getInstanceApi(userProject.get()).getInZone(slashEncodedIds.getFirstId(), - slashEncodedIds.getSecondId()); + Instance instance = api.getInstanceApi(userProject.get(), zoneAndId.left()).get(zoneAndId.right()); if (instance != null && "true".equals(instance.metadata().items().get(GCE_DELETE_BOOT_DISK_METADATA_KEY))) { for (AttachedDisk input : instance.disks()) { @@ -344,20 +326,17 @@ public final class GoogleComputeEngineServiceAdapter implements ComputeServiceAd } } } - waitOperationDone(api.getInstanceApi(userProject.get()).deleteInZone(slashEncodedIds.getFirstId(), - slashEncodedIds.getSecondId())); + waitOperationDone(api.getInstanceApi(userProject.get(), zoneAndId.left()).delete(zoneAndId.right())); if (diskName != null) { - waitOperationDone(api.getDiskApi(userProject.get()).deleteInZone(slashEncodedIds.getFirstId(), diskName)); + waitOperationDone(api.getDiskApi(userProject.get()).deleteInZone(zoneAndId.left(), diskName)); } } @Override public void rebootNode(final String name) { - SlashEncodedIds slashEncodedIds = SlashEncodedIds.fromSlashEncoded(name); - - waitOperationDone(api.getInstanceApi(userProject.get()).resetInZone(slashEncodedIds.getFirstId(), - slashEncodedIds.getSecondId())); + SlashEncodedIds zoneAndId = SlashEncodedIds.fromSlashEncoded(name); + waitOperationDone(api.getInstanceApi(userProject.get(), zoneAndId.left()).reset(zoneAndId.right())); } @Override diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/InstanceInZone.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/InstanceInZone.java index b9cdb8f83c..b748cad818 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/InstanceInZone.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/InstanceInZone.java @@ -16,39 +16,24 @@ */ package org.jclouds.googlecomputeengine.compute.domain; -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Preconditions.checkNotNull; - import org.jclouds.googlecomputeengine.domain.Instance; -public class InstanceInZone extends SlashEncodedIds { - protected final Instance instance; +import com.google.auto.value.AutoValue; - public InstanceInZone(Instance instance, String zoneId) { - super(zoneId, checkNotNull(instance, "instance").name()); - this.instance = instance; +@AutoValue +public abstract class InstanceInZone { + public abstract Instance instance(); + + public abstract String zoneId(); + + public static InstanceInZone create(Instance instance, String zoneId) { + return new AutoValue_InstanceInZone(instance, zoneId); } - public Instance getInstance() { - return instance; + InstanceInZone(){ } - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - InstanceInZone that = InstanceInZone.class.cast(obj); - return equal(this.instance, that.instance) - && equal(this.firstId, that.firstId) - && equal(this.secondId, that.secondId); + public String slashEncode() { + return zoneId() + "/" + instance().name(); } - - @Override - public String toString() { - return "[instance=" + instance + ", zoneId=" + firstId + "]"; - } - } diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/MachineTypeInZone.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/MachineTypeInZone.java index 25d491a870..ac82f941c6 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/MachineTypeInZone.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/MachineTypeInZone.java @@ -16,39 +16,20 @@ */ package org.jclouds.googlecomputeengine.compute.domain; -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Preconditions.checkNotNull; - import org.jclouds.googlecomputeengine.domain.MachineType; -public class MachineTypeInZone extends SlashEncodedIds { - protected final MachineType machineType; +import com.google.auto.value.AutoValue; - public MachineTypeInZone(MachineType machineType, String zoneId) { - super(zoneId, checkNotNull(machineType, "machineType").name()); - this.machineType = machineType; +@AutoValue +public abstract class MachineTypeInZone { + public abstract MachineType machineType(); + + public abstract String zoneId(); + + public static MachineTypeInZone create(MachineType machineType, String zoneId) { + return new AutoValue_MachineTypeInZone(machineType, zoneId); } - public MachineType machineType() { - return machineType; + MachineTypeInZone(){ } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - MachineTypeInZone that = MachineTypeInZone.class.cast(obj); - return equal(this.machineType, that.machineType) - && equal(this.firstId, that.firstId) - && equal(this.secondId, that.secondId); - } - - @Override - public String toString() { - return "[machineType=" + machineType + ", zoneId=" + firstId + "]"; - } - } diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/SlashEncodedIds.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/SlashEncodedIds.java index ceb5fa4657..aa7fb7f406 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/SlashEncodedIds.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/SlashEncodedIds.java @@ -19,65 +19,31 @@ package org.jclouds.googlecomputeengine.compute.domain; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import com.google.common.base.Objects; +import com.google.auto.value.AutoValue; import com.google.common.base.Splitter; import com.google.common.collect.Iterables; -public class SlashEncodedIds { +@AutoValue +public abstract class SlashEncodedIds { + + public abstract String left(); + + public abstract String right(); + public static SlashEncodedIds fromSlashEncoded(String id) { Iterable parts = Splitter.on('/').split(checkNotNull(id, "id")); - checkArgument(Iterables.size(parts) == 2, "id must be in format firstId/secondId"); - return new SlashEncodedIds(Iterables.get(parts, 0), Iterables.get(parts, 1)); + checkArgument(Iterables.size(parts) == 2, "id must be in format left/right"); + return from(Iterables.get(parts, 0), Iterables.get(parts, 1)); } - public static SlashEncodedIds fromTwoIds(String firstId, String secondId) { - return new SlashEncodedIds(firstId, secondId); + SlashEncodedIds() { } - private static String slashEncodeTwoIds(String firstId, String secondId) { - return checkNotNull(firstId, "firstId") + "/" + checkNotNull(secondId, "secondId"); + public static SlashEncodedIds from(String left, String right) { + return new AutoValue_SlashEncodedIds(left, right); } public String slashEncode() { - return slashEncodeTwoIds(firstId, secondId); + return left() + "/" + right(); } - - protected final String firstId; - protected final String secondId; - - protected SlashEncodedIds(String firstId, String secondId) { - this.firstId = checkNotNull(firstId, "firstId"); - this.secondId = checkNotNull(secondId, "secondId"); - } - - @Override - public int hashCode() { - return Objects.hashCode(firstId, secondId); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - SlashEncodedIds other = (SlashEncodedIds) obj; - return Objects.equal(firstId, other.firstId) && Objects.equal(secondId, other.secondId); - } - - public String getFirstId() { - return firstId; - } - - public String getSecondId() { - return secondId; - } - - @Override - public String toString() { - return "[firstId=" + firstId + ", secondId=" + secondId + "]"; - } - } diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/extensions/GoogleComputeEngineSecurityGroupExtension.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/extensions/GoogleComputeEngineSecurityGroupExtension.java index 98abf0e7b6..d40db68253 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/extensions/GoogleComputeEngineSecurityGroupExtension.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/extensions/GoogleComputeEngineSecurityGroupExtension.java @@ -73,17 +73,16 @@ import com.google.common.util.concurrent.Atomics; */ public class GoogleComputeEngineSecurityGroupExtension implements SecurityGroupExtension { - protected final Supplier userProject; - protected final GroupNamingConvention.Factory namingConvention; - protected final LoadingCache networkCreator; - protected final Function groupConverter; - protected final GoogleComputeEngineApi api; - protected final Predicate> operationDonePredicate; - protected final long operationCompleteCheckInterval; - protected final long operationCompleteCheckTimeout; + private final Supplier userProject; + private final GroupNamingConvention.Factory namingConvention; + private final LoadingCache networkCreator; + private final Function groupConverter; + private final GoogleComputeEngineApi api; + private final Predicate> operationDonePredicate; + private final long operationCompleteCheckInterval; + private final long operationCompleteCheckTimeout; - @Inject - public GoogleComputeEngineSecurityGroupExtension(GoogleComputeEngineApi api, + @Inject GoogleComputeEngineSecurityGroupExtension(GoogleComputeEngineApi api, @UserProject Supplier userProject, GroupNamingConvention.Factory namingConvention, LoadingCache networkCreator, Function groupConverter, @Named("global") Predicate> operationDonePredicate, @@ -113,10 +112,9 @@ public class GoogleComputeEngineSecurityGroupExtension implements SecurityGroupE @Override public Set listSecurityGroupsForNode(String id) { - SlashEncodedIds slashEncodedIds = SlashEncodedIds.fromSlashEncoded(id); + SlashEncodedIds zoneAndId = SlashEncodedIds.fromSlashEncoded(id); - Instance instance = api.getInstanceApi(userProject.get()) - .getInZone(slashEncodedIds.getFirstId(), slashEncodedIds.getSecondId()); + Instance instance = api.getInstanceApi(userProject.get(), zoneAndId.left()).get(zoneAndId.right()); if (instance == null) { return ImmutableSet.of(); diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadata.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadata.java index 11897a0803..977c9ab97e 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadata.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadata.java @@ -43,9 +43,6 @@ import com.google.common.base.Supplier; import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; -/** - * Transforms a google compute domain Instance into a generic NodeMetatada object. - */ public final class InstanceInZoneToNodeMetadata implements Function { private final Map toPortableNodeStatus; @@ -56,11 +53,11 @@ public final class InstanceInZoneToNodeMetadata implements Function toPortableNodeStatus, - GroupNamingConvention.Factory namingConvention, - @Memoized Supplier> images, - @Memoized Supplier> hardwares, - @Memoized Supplier> locations, - FirewallTagNamingConvention.Factory firewallTagNamingConvention) { + GroupNamingConvention.Factory namingConvention, + @Memoized Supplier> images, + @Memoized Supplier> hardwares, + @Memoized Supplier> locations, + FirewallTagNamingConvention.Factory firewallTagNamingConvention) { this.toPortableNodeStatus = toPortableNodeStatus; this.nodeNamingConvention = namingConvention.createWithoutPrefix(); this.images = images; @@ -70,10 +67,9 @@ public final class InstanceInZoneToNodeMetadata implements Function tags = FluentIterable.from(input.tags().items()); if (group != null) { tags = tags.filter(Predicates.not(firewallTagNamingConvention.get(group).isFirewallTag())); @@ -81,13 +77,12 @@ public final class InstanceInZoneToNodeMetadata implements Function imagesMap = images.get(); diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/MachineTypeInZoneToHardware.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/MachineTypeInZoneToHardware.java index b17fb23155..4ed2a115ef 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/MachineTypeInZoneToHardware.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/MachineTypeInZoneToHardware.java @@ -68,7 +68,7 @@ public class MachineTypeInZoneToHardware implements Function() { @Override public URI apply(String input) { - SlashEncodedIds slashEncodedIds = SlashEncodedIds.fromSlashEncoded(input); + SlashEncodedIds zoneAndMachineType = SlashEncodedIds.fromSlashEncoded(input); return Uris.uriBuilder(endpoint.get()).appendPath("/projects/").appendPath(userProject.get()) - .appendPath("/zones/").appendPath(slashEncodedIds.getFirstId()) - .appendPath("/machineTypes/").appendPath(slashEncodedIds.getSecondId()).build(); + .appendPath("/zones/").appendPath(zoneAndMachineType.left()) + .appendPath("/machineTypes/").appendPath(zoneAndMachineType.right()).build(); } }; } diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/InstanceApi.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/InstanceApi.java index 35f12d9174..09dc36d628 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/InstanceApi.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/InstanceApi.java @@ -16,8 +16,11 @@ */ package org.jclouds.googlecomputeengine.features; +import static javax.ws.rs.core.MediaType.APPLICATION_JSON; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE; +import static org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig; +import static org.jclouds.googlecomputeengine.domain.Instance.SerialPortOutput; import java.util.Iterator; import java.util.Map; @@ -31,7 +34,6 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; import org.jclouds.Fallbacks.NullOnNotFoundOr404; import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404; @@ -64,69 +66,50 @@ import org.jclouds.rest.binders.BindToJsonPayload; */ @SkipEncoding({'/', '='}) @RequestFilters(OAuthAuthenticationFilter.class) +@Path("/instances") +@Consumes(APPLICATION_JSON) public interface InstanceApi { - /** - * Returns the specified instance resource. - * - * @param zone zone the instance is in. - * @param instanceName name of the instance resource to return. - * @return an Instance resource - */ + /** Returns an instance by name or null if not found. */ @Named("Instances:get") @GET - @Consumes(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/instances/{instance}") + @Path("/{instance}") @OAuthScopes(COMPUTE_READONLY_SCOPE) @Fallback(NullOnNotFoundOr404.class) @Nullable - Instance getInZone(@PathParam("zone") String zone, @PathParam("instance") String instanceName); + Instance get(@PathParam("instance") String instance); /** * Creates a instance resource in the specified project using the data included in the request. * * - * @param instanceName this name of the instance to be created - * @param zone the name of the zone where the instance will be created + * @param instance this name of the instance to be created * @param template the instance template * @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to * you, and look for the status field. */ @Named("Instances:insert") @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/instances") + @Produces(APPLICATION_JSON) @OAuthScopes({COMPUTE_SCOPE}) @MapBinder(InstanceBinder.class) - Operation createInZone(@PayloadParam("name") String instanceName, @PathParam("zone") String zone, - @PayloadParam("template") InstanceTemplate template); - + Operation create(@PayloadParam("name") String instance, @PayloadParam("template") InstanceTemplate template); - /** - * Deletes the specified instance resource. - * - * @param zone the instance is in. - * @param instanceName name of the instance resource to delete. - * @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to - * you, and look for the status field. If the instance did not exist the result is null. - */ + /** Deletes an instance by name and returns the operation in progress, or null if not found. */ @Named("Instances:delete") @DELETE - @Consumes(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/instances/{instance}") + @Path("/{instance}") @OAuthScopes(COMPUTE_SCOPE) @Fallback(NullOnNotFoundOr404.class) @Nullable - Operation deleteInZone(@PathParam("zone") String zone, @PathParam("instance") String instanceName); + Operation delete(@PathParam("instance") String instance); /** * Retrieves the list of instance resources available to the specified project. * By default the list as a maximum size of 100, if no options are provided or ListOptions#getMaxResults() has not * been set. * - * @param zone zone instances are in - * @param marker marks the beginning of the next list page + * @param token marks the beginning of the next list page * @param listOptions listing options * @return a page of the list * @see ListOptions @@ -134,45 +117,37 @@ public interface InstanceApi { */ @Named("Instances:list") @GET - @Consumes(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/instances") @OAuthScopes(COMPUTE_READONLY_SCOPE) @ResponseParser(ParseInstances.class) @Fallback(EmptyListPageOnNotFoundOr404.class) - ListPage listAtMarkerInZone(@PathParam("zone") String zone, @Nullable String marker, - ListOptions listOptions); + ListPage listPage(@Nullable String token, ListOptions listOptions); /** - * @see InstanceApi#listInZone(String, org.jclouds.googlecomputeengine.options.ListOptions) + * @see InstanceApi#list(org.jclouds.googlecomputeengine.options.ListOptions) */ @Named("Instances:list") @GET - @Consumes(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/instances") @OAuthScopes(COMPUTE_READONLY_SCOPE) @ResponseParser(ParseInstances.class) @Transform(ParseInstances.ToIteratorOfListPage.class) @Fallback(EmptyIteratorOnNotFoundOr404.class) - Iterator> listInZone(@PathParam("zone") String zone); + Iterator> list(); /** - * @see InstanceApi#listInZone(String, org.jclouds.googlecomputeengine.options.ListOptions) + * @see InstanceApi#list(org.jclouds.googlecomputeengine.options.ListOptions) */ @Named("Instances:list") @GET - @Consumes(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/instances") @OAuthScopes(COMPUTE_READONLY_SCOPE) @ResponseParser(ParseInstances.class) @Transform(ParseInstances.ToIteratorOfListPage.class) @Fallback(EmptyIteratorOnNotFoundOr404.class) - Iterator> listInZone(@PathParam("zone") String zone, ListOptions options); + Iterator> list(ListOptions options); /** * Adds an access config to an instance's network interface. * - * @param zone zone instance is in - * @param instanceName the instance name. + * @param instance the instance name. * @param accessConfig the AccessConfig to add. * @param networkInterfaceName network interface name. * @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to @@ -180,21 +155,18 @@ public interface InstanceApi { */ @Named("Instances:addAccessConfig") @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/instances/{instance}/addAccessConfig") + @Produces(APPLICATION_JSON) + @Path("/{instance}/addAccessConfig") @OAuthScopes({COMPUTE_SCOPE}) - Operation addAccessConfigToNicInZone(@PathParam("zone") String zone, - @PathParam("instance") String instanceName, - @BinderParam(BindToJsonPayload.class) - Instance.NetworkInterface.AccessConfig accessConfig, - @QueryParam("network_interface") String networkInterfaceName); + Operation addAccessConfigToNic(@PathParam("instance") String instance, + @BinderParam(BindToJsonPayload.class) + AccessConfig accessConfig, + @QueryParam("network_interface") String networkInterfaceName); /** * Deletes an access config from an instance's network interface. * - * @param zone zone instance is in - * @param instanceName the instance name. + * @param instance the instance name. * @param accessConfigName the name of the access config to delete * @param networkInterfaceName network interface name. * @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to @@ -202,50 +174,41 @@ public interface InstanceApi { */ @Named("Instances:deleteAccessConfig") @DELETE - @Consumes(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/instances/{instance}/deleteAccessConfig") + @Path("/{instance}/deleteAccessConfig") @OAuthScopes(COMPUTE_SCOPE) - Operation deleteAccessConfigFromNicInZone(@PathParam("zone") String zone, - @PathParam("instance") String instanceName, - @QueryParam("access_config") String accessConfigName, - @QueryParam("network_interface") String networkInterfaceName); + Operation deleteAccessConfigFromNic(@PathParam("instance") String instance, + @QueryParam("access_config") String accessConfigName, + @QueryParam("network_interface") String networkInterfaceName); /** * Returns the specified instance's serial port output. * - * @param zone zone instance is in - * @param instanceName the instance name. + * @param instance the instance name. * @return if successful, this method returns a SerialPortOutput containing the instance's serial output. */ @Named("Instances:serialPort") @GET - @Consumes(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/instances/{instance}/serialPort") + @Path("/{instance}/serialPort") @OAuthScopes(COMPUTE_READONLY_SCOPE) - Instance.SerialPortOutput getSerialPortOutputInZone(@PathParam("zone") String zone, - @PathParam("instance") String instanceName); + SerialPortOutput getSerialPortOutput(@PathParam("instance") String instance); /** * Hard-resets the instance. * - * @param zone the zone the instance is in - * @param instanceName the instance name + * @param instance the instance name * @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to * you, and look for the status field. */ @Named("Instances:reset") @POST - @Consumes(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/instances/{instance}/reset") + @Path("/{instance}/reset") @OAuthScopes(COMPUTE_SCOPE) - Operation resetInZone(@PathParam("zone") String zone, - @PathParam("instance") String instanceName); + Operation reset(@PathParam("instance") String instance); /** * Attaches a disk to an instance * - * @param zone The zone the instance is in. - * @param instanceName The instance name to attach to + * @param instance The instance name to attach to * @param attachDiskOptions The options for attaching the disk. * * @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to @@ -253,19 +216,16 @@ public interface InstanceApi { */ @Named("Instances:attachDisk") @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/instances/{instance}/attachDisk") + @Produces(APPLICATION_JSON) + @Path("/{instance}/attachDisk") @OAuthScopes(COMPUTE_SCOPE) - Operation attachDiskInZone(@PathParam("zone") String zone, - @PathParam("instance") String instanceName, - @BinderParam(BindToJsonPayload.class) AttachDiskOptions attachDiskOptions); + Operation attachDisk(@PathParam("instance") String instance, + @BinderParam(BindToJsonPayload.class) AttachDiskOptions attachDiskOptions); /** * Detaches an attached disk from an instance * - * @param zone The zone the instance is in. - * @param instanceName The instance name to attach to + * @param instance The instance name to attach to * @param deviceName The device name of the disk to detach. * * @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to @@ -273,12 +233,9 @@ public interface InstanceApi { */ @Named("Instances:detachDisk") @POST - @Consumes(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/instances/{instance}/detachDisk") + @Path("/{instance}/detachDisk") @OAuthScopes(COMPUTE_SCOPE) - Operation detachDiskInZone(@PathParam("zone") String zone, - @PathParam("instance") String instanceName, - @QueryParam("deviceName") String deviceName); + Operation detachDisk(@PathParam("instance") String instance, @QueryParam("deviceName") String deviceName); /** * Sets metadata for an instance using the data included in the request. @@ -287,13 +244,12 @@ public interface InstanceApi { * if there are pre-existing metadata items that must be kept these must be fetched first and then re-set on the * new Metadata, e.g. *

-    *    Metadata.Builder current = instanceApi.getInZone("us-central1-a", "myInstance").getMetadata().toBuilder();
+    *    Metadata.Builder current = instanceApi.get("us-central1-a", "myInstance").getMetadata().toBuilder();
     *    current.addItem("newItem","newItemValue");
-    *    instanceApi.setMetadataInZone("us-central1-a", "myInstance", current.build());
+    *    instanceApi.setMetadata("us-central1-a", "myInstance", current.build());
     * 
* - * @param zone The zone the instance is in - * @param instanceName The name of the instance + * @param instance The name of the instance * @param metadata the metadata to set * @param fingerprint The current fingerprint for the items * @@ -302,21 +258,18 @@ public interface InstanceApi { */ @Named("Instances:setMetadata") @POST - @Path("/zones/{zone}/instances/{instance}/setMetadata") + @Path("/{instance}/setMetadata") @OAuthScopes(COMPUTE_SCOPE) - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) + @Produces(APPLICATION_JSON) @MapBinder(MetadataBinder.class) - Operation setMetadataInZone(@PathParam("zone") String zone, - @PathParam("instance") String instanceName, - @PayloadParam("items") Map metadata, - @PayloadParam("fingerprint") String fingerprint); + Operation setMetadata(@PathParam("instance") String instance, + @PayloadParam("items") Map metadata, + @PayloadParam("fingerprint") String fingerprint); /** * Lists items for an instance * - * @param zone The zone the instance is in - * @param instanceName the name of the instance + * @param instance the name of the instance * @param items A set of items * @param fingerprint The current fingerprint for the items * @return an Operations resource. To check on the status of an operation, poll the Operations resource returned @@ -324,15 +277,12 @@ public interface InstanceApi { */ @Named("Instances:setTags") @POST - @Path("/zones/{zone}/instances/{instance}/setTags") + @Path("/{instance}/setTags") @OAuthScopes(COMPUTE_SCOPE) - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) + @Produces(APPLICATION_JSON) @MapBinder(BindToJsonPayload.class) - Operation setTagsInZone(@PathParam("zone") String zone, - @PathParam("instance") String instanceName, - @PayloadParam("items") Iterable items, - @PayloadParam("fingerprint") String fingerprint); - + Operation setTags(@PathParam("instance") String instance, + @PayloadParam("items") Iterable items, + @PayloadParam("fingerprint") String fingerprint); } diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseInstances.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseInstances.java index dbf6ff6ec5..e581ec44aa 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseInstances.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseInstances.java @@ -44,12 +44,11 @@ public final class ParseInstances extends ParseJson> { this.api = api; } - @Override - protected Function> fetchNextPage(final String project, final String zone, + @Override protected Function> fetchNextPage(final String project, final String zone, final ListOptions options) { return new Function>() { @Override public ListPage apply(String input) { - return api.getInstanceApi(project).listAtMarkerInZone(zone, input, options); + return api.getInstanceApi(project, zone).listPage(input, options); } }; } diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ListOptions.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ListOptions.java index 08b4367de6..39444864c5 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ListOptions.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ListOptions.java @@ -70,35 +70,20 @@ public class ListOptions extends BaseHttpRequestOptions { return this; } - /** - * Marks the beginning of the next list page - */ - public ListOptions marker(String marker) { - this.queryParameters.put("pageToken", checkNotNull(marker, "marker")); - return this; - } - public static class Builder { /** * @see ListOptions#filter(String) */ - public ListOptions filter(String filter) { + public static ListOptions filter(String filter) { return new ListOptions().filter(filter); } /** * @see ListOptions#maxResults(Integer) */ - public ListOptions maxResults(Integer maxResults) { + public static ListOptions maxResults(Integer maxResults) { return new ListOptions().maxResults(maxResults); } - - /** - * @see ListOptions#marker(String) - */ - public ListOptions marker(String marker) { - return new ListOptions().marker(marker); - } } } diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadataTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadataTest.java index a0229ed494..7d5b4fb556 100644 --- a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadataTest.java +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadataTest.java @@ -218,7 +218,7 @@ public class InstanceInZoneToNodeMetadataTest { @Test public final void testTagFilteringWorks() { - InstanceInZone instanceInZone = new InstanceInZone(instance, "zoneId"); + InstanceInZone instanceInZone = InstanceInZone.create(instance, "zoneId"); NodeMetadata nodeMetadata = groupGroupNodeParser.apply(instanceInZone); assertEquals(nodeMetadata.getId(), "id/test-0"); assertEquals(nodeMetadata.getTags(), ImmutableSet.of( @@ -229,7 +229,7 @@ public class InstanceInZoneToNodeMetadataTest { @Test public final void testInstanceWithGroupNull() { - InstanceInZone instanceInZone = new InstanceInZone(instance, "zoneId"); + InstanceInZone instanceInZone = InstanceInZone.create(instance, "zoneId"); NodeMetadata nodeMetadata = groupNullNodeParser.apply(instanceInZone); assertEquals(nodeMetadata.getId(), "id/test-0"); assertEquals(nodeMetadata.getTags(), ImmutableSet.of("aTag", "Group-port-42")); diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java index 17d7d92d7e..03c6876d84 100644 --- a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java @@ -88,9 +88,9 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest InstanceApi api = requestsSendResponses( requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, - GET_INSTANCE_REQUEST, GET_INSTANCE_RESPONSE).getInstanceApi("myproject"); + GET_INSTANCE_REQUEST, GET_INSTANCE_RESPONSE).getInstanceApi("myproject", "us-central1-a"); - assertEquals(api.getInZone("us-central1-a", "test-1"), new ParseInstanceTest().expected()); + assertEquals(api.get("test-1"), new ParseInstanceTest().expected()); } public void testGetInstanceResponseIs4xx() throws Exception { @@ -98,9 +98,9 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, GET_INSTANCE_REQUEST, operationResponse).getInstanceApi("myproject"); + TOKEN_RESPONSE, GET_INSTANCE_REQUEST, operationResponse).getInstanceApi("myproject", "us-central1-a"); - assertNull(api.getInZone("us-central1-a", "test-1")); + assertNull(api.get("test-1")); } public void testGetInstanceSerialPortOutput() throws Exception { @@ -116,9 +116,9 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, get, operationResponse).getInstanceApi("myproject"); + TOKEN_RESPONSE, get, operationResponse).getInstanceApi("myproject", "us-central1-a"); - assertEquals(api.getSerialPortOutputInZone("us-central1-a", "test-1"), new ParseInstanceSerialOutputTest().expected()); + assertEquals(api.getSerialPortOutput("test-1"), new ParseInstanceSerialOutputTest().expected()); } public void testInsertInstanceResponseIs2xxNoOptions() { @@ -135,12 +135,12 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest TOKEN_RESPONSE, GET_PROJECT_REQUEST, GET_PROJECT_RESPONSE, requestForScopes(COMPUTE_SCOPE), TOKEN_RESPONSE, insert, - CREATE_INSTANCE_RESPONSE)).getInstanceApi("myproject"); + CREATE_INSTANCE_RESPONSE)).getInstanceApi("myproject", "us-central1-a"); InstanceTemplate options = new InstanceTemplate().machineTypeName("us-central1-a/n1-standard-1") .addNetworkInterface(URI.create(BASE_URL + "/myproject/global/networks/default")); - assertEquals(api.createInZone("test-1", "us-central1-a", options), new ParseZoneOperationTest().expected()); + assertEquals(api.create("test-1", options), new ParseZoneOperationTest().expected()); } public void testInsertInstanceResponseIs2xxAllOptions() { @@ -159,7 +159,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest InstanceApi api = requestsSendResponses(ImmutableMap.of(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, GET_PROJECT_REQUEST, GET_PROJECT_RESPONSE, requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, insert, insertInstanceResponse)).getInstanceApi("myproject"); + TOKEN_RESPONSE, insert, insertInstanceResponse)).getInstanceApi("myproject", "us-central1-a"); InstanceTemplate options = new InstanceTemplate().machineTypeName("us-central1-a/n1-standard-1") .addNetworkInterface( @@ -172,8 +172,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest .addServiceAccount(Instance.ServiceAccount.create("default", ImmutableList.of("myscope"))) .addMetadata("aKey", "aValue"); - assertEquals(api.createInZone("test-0", "us-central1-a", options), - new ParseZoneOperationTest().expected()); + assertEquals(api.create("test-0", options), new ParseZoneOperationTest().expected()); } public void testDeleteInstanceResponseIs2xx() { @@ -188,9 +187,9 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest .payload(payloadFromResource("/zone_operation.json")).build(); InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, delete, deleteResponse).getInstanceApi("myproject"); + TOKEN_RESPONSE, delete, deleteResponse).getInstanceApi("myproject", "us-central1-a"); - assertEquals(api.deleteInZone("us-central1-a", "test-1"), + assertEquals(api.delete("test-1"), new ParseZoneOperationTest().expected()); } @@ -205,19 +204,18 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build(); InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, delete, deleteResponse).getInstanceApi("myproject"); + TOKEN_RESPONSE, delete, deleteResponse).getInstanceApi("myproject", "us-central1-a"); - assertNull(api.deleteInZone("us-central1-a", "test-1")); + assertNull(api.delete("test-1")); } public void testListInstancesResponseIs2xx() { InstanceApi api = requestsSendResponses( requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, - LIST_INSTANCES_REQUEST, LIST_INSTANCES_RESPONSE).getInstanceApi("myproject"); + LIST_INSTANCES_REQUEST, LIST_INSTANCES_RESPONSE).getInstanceApi("myproject", "us-central1-a"); - assertEquals(api.listInZone("us-central1-a").next().toString(), - new ParseInstanceListTest().expected().toString()); + assertEquals(api.list().next().toString(), new ParseInstanceListTest().expected().toString()); } public void testListInstancesResponseIs4xx() { @@ -231,9 +229,9 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, list, operationResponse).getInstanceApi("myproject"); + TOKEN_RESPONSE, list, operationResponse).getInstanceApi("myproject", "us-central1-a"); - assertFalse(api.listInZone("us-central1-a").hasNext()); + assertFalse(api.list().hasNext()); } public void testSetInstanceMetadataResponseIs2xx() { @@ -250,9 +248,9 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest .payload(payloadFromResource("/zone_operation.json")).build(); InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, setMetadata, setMetadataResponse).getInstanceApi("myproject"); + TOKEN_RESPONSE, setMetadata, setMetadataResponse).getInstanceApi("myproject", "us-central1-a"); - assertEquals(api.setMetadataInZone("us-central1-a", "test-1", ImmutableMap.of("foo", "bar"), "efgh"), + assertEquals(api.setMetadata("test-1", ImmutableMap.of("foo", "bar"), "efgh"), new ParseZoneOperationTest().expected()); } @@ -270,9 +268,9 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest HttpResponse setMetadataResponse = HttpResponse.builder().statusCode(404).build(); InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, setMetadata, setMetadataResponse).getInstanceApi("myproject"); + TOKEN_RESPONSE, setMetadata, setMetadataResponse).getInstanceApi("myproject", "us-central1-a"); - api.setMetadataInZone("us-central1-a", "test-1", ImmutableMap.of("foo", "bar"), "efgh"); + api.setMetadata("test-1", ImmutableMap.of("foo", "bar"), "efgh"); } public void testSetInstanceTagsResponseIs2xx() { @@ -289,9 +287,9 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest .payload(payloadFromResource("/zone_operation.json")).build(); InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, setTags, setTagsResponse).getInstanceApi("myproject"); + TOKEN_RESPONSE, setTags, setTagsResponse).getInstanceApi("myproject", "us-central1-a"); - assertEquals(api.setTagsInZone("us-central1-a", "test-1", ImmutableList.of("foo", "bar"), "efgh"), + assertEquals(api.setTags("test-1", ImmutableList.of("foo", "bar"), "efgh"), new ParseZoneOperationTest().expected()); } @@ -309,9 +307,9 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest HttpResponse setTagsResponse = HttpResponse.builder().statusCode(404).build(); InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, setTags, setTagsResponse).getInstanceApi("myproject"); + TOKEN_RESPONSE, setTags, setTagsResponse).getInstanceApi("myproject", "us-central1-a"); - api.setTagsInZone("us-central1-a", "test-1", ImmutableList.of("foo", "bar"), "efgh"); + api.setTags("test-1", ImmutableList.of("foo", "bar"), "efgh"); } public void testResetInstanceResponseIs2xx() { @@ -326,9 +324,9 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest .payload(payloadFromResource("/zone_operation.json")).build(); InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, reset, resetResponse).getInstanceApi("myproject"); + TOKEN_RESPONSE, reset, resetResponse).getInstanceApi("myproject", "us-central1-a"); - assertEquals(api.resetInZone("us-central1-a", "test-1"), + assertEquals(api.reset("test-1"), new ParseZoneOperationTest().expected()); } @@ -344,9 +342,9 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest HttpResponse resetResponse = HttpResponse.builder().statusCode(404).build(); InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, reset, resetResponse).getInstanceApi("myproject"); + TOKEN_RESPONSE, reset, resetResponse).getInstanceApi("myproject", "us-central1-a"); - api.resetInZone("us-central1-a", "test-1"); + api.reset("test-1"); } public void testAttachDiskResponseIs2xx() { @@ -363,9 +361,9 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest .payload(payloadFromResource("/zone_operation.json")).build(); InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, attach, attachResponse).getInstanceApi("myproject"); + TOKEN_RESPONSE, attach, attachResponse).getInstanceApi("myproject", "us-central1-a"); - assertEquals(api.attachDiskInZone("us-central1-a", "test-1", + assertEquals(api.attachDisk("test-1", new AttachDiskOptions() .mode(DiskMode.READ_ONLY) .source(URI.create(BASE_URL + "/myproject/zones/us-central1-a/disks/testimage1")) @@ -387,9 +385,9 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest HttpResponse attachResponse = HttpResponse.builder().statusCode(404).build(); InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, attach, attachResponse).getInstanceApi("myproject"); + TOKEN_RESPONSE, attach, attachResponse).getInstanceApi("myproject", "us-central1-a"); - api.attachDiskInZone("us-central1-a", "test-1", + api.attachDisk("test-1", new AttachDiskOptions() .mode(DiskMode.READ_ONLY) .source(URI.create(BASE_URL + "/myproject/zones/us-central1-a/disks/testimage1")) @@ -410,9 +408,9 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest .payload(payloadFromResource("/zone_operation.json")).build(); InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, detach, detachResponse).getInstanceApi("myproject"); + TOKEN_RESPONSE, detach, detachResponse).getInstanceApi("myproject", "us-central1-a"); - assertEquals(api.detachDiskInZone("us-central1-a", "test-1", "test-disk-1"), + assertEquals(api.detachDisk("test-1", "test-disk-1"), new ParseZoneOperationTest().expected()); } @@ -429,9 +427,9 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest HttpResponse detachResponse = HttpResponse.builder().statusCode(404).build(); InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, detach, detachResponse).getInstanceApi("myproject"); + TOKEN_RESPONSE, detach, detachResponse).getInstanceApi("myproject", "us-central1-a"); - api.detachDiskInZone("us-central1-a", "test-1", "test-disk-1"); + api.detachDisk("test-1", "test-disk-1"); } } diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java index 11f49152c6..4fcdfa9843 100644 --- a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java @@ -16,6 +16,7 @@ */ package org.jclouds.googlecomputeengine.features; +import static org.jclouds.googlecomputeengine.options.ListOptions.Builder.filter; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; @@ -97,7 +98,7 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { } private InstanceApi api() { - return api.getInstanceApi(userProject.get()); + return api.getInstanceApi(userProject.get(), DEFAULT_ZONE_NAME); } private DiskApi diskApi() { @@ -120,26 +121,26 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { assertZoneOperationDoneSuccessfully( diskApi().createInZone("instance-live-test-disk", DEFAULT_DISK_SIZE_GB, DEFAULT_ZONE_NAME), TIME_WAIT); - assertZoneOperationDoneSuccessfully(api().createInZone(INSTANCE_NAME, DEFAULT_ZONE_NAME, instance), TIME_WAIT); + assertZoneOperationDoneSuccessfully(api().create(INSTANCE_NAME, instance), TIME_WAIT); } @Test(groups = "live", dependsOnMethods = "testInsertInstance") public void testGetInstance() { - Instance instance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); + Instance instance = api().get(INSTANCE_NAME); assertNotNull(instance); assertInstanceEquals(instance, this.instance); } @Test(groups = "live", dependsOnMethods = "testListInstance") public void testSetMetadataForInstance() { - Instance originalInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); - assertZoneOperationDoneSuccessfully(api().setMetadataInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME, + Instance originalInstance = api().get(INSTANCE_NAME); + assertZoneOperationDoneSuccessfully(api().setMetadata(INSTANCE_NAME, ImmutableMap.of(METADATA_ITEM_KEY, METADATA_ITEM_VALUE), originalInstance.metadata().fingerprint()), TIME_WAIT); - Instance modifiedInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); + Instance modifiedInstance = api().get(INSTANCE_NAME); assertTrue(modifiedInstance.metadata().items().containsKey(METADATA_ITEM_KEY)); assertEquals(modifiedInstance.metadata().items().get(METADATA_ITEM_KEY), @@ -149,12 +150,11 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live", dependsOnMethods = "testListInstance") public void testSetTagsForInstance() { - Instance originalInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); + Instance originalInstance = api().get(INSTANCE_NAME); assertZoneOperationDoneSuccessfully( - api().setTagsInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME, TAGS, originalInstance.tags().fingerprint()), - TIME_WAIT); + api().setTags(INSTANCE_NAME, TAGS, originalInstance.tags().fingerprint()), TIME_WAIT); - Instance modifiedInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); + Instance modifiedInstance = api().get(INSTANCE_NAME); assertTrue(modifiedInstance.tags().items().containsAll(TAGS)); assertNotNull(modifiedInstance.tags().fingerprint()); @@ -164,13 +164,13 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { public void testAttachDiskToInstance() { assertZoneOperationDoneSuccessfully(diskApi().createInZone(ATTACH_DISK_NAME, 1, DEFAULT_ZONE_NAME), TIME_WAIT); - Instance originalInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); - assertZoneOperationDoneSuccessfully(api().attachDiskInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME, + Instance originalInstance = api().get(INSTANCE_NAME); + assertZoneOperationDoneSuccessfully(api().attachDisk(INSTANCE_NAME, new AttachDiskOptions().type(DiskType.PERSISTENT) .source(getDiskUrl(userProject.get(), ATTACH_DISK_NAME)).mode(DiskMode.READ_ONLY) .deviceName(ATTACH_DISK_DEVICE_NAME)), TIME_WAIT); - Instance modifiedInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); + Instance modifiedInstance = api().get(INSTANCE_NAME); assertTrue(modifiedInstance.disks().size() > originalInstance.disks().size()); assertTrue(Iterables.any(modifiedInstance.disks(), new Predicate() { @@ -185,11 +185,10 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live", dependsOnMethods = "testAttachDiskToInstance") public void testDetachDiskFromInstance() { - Instance originalInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); - assertZoneOperationDoneSuccessfully( - api().detachDiskInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME, ATTACH_DISK_DEVICE_NAME), TIME_WAIT); + Instance originalInstance = api().get(INSTANCE_NAME); + assertZoneOperationDoneSuccessfully(api().detachDisk(INSTANCE_NAME, ATTACH_DISK_DEVICE_NAME), TIME_WAIT); - Instance modifiedInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); + Instance modifiedInstance = api().get(INSTANCE_NAME); assertTrue(modifiedInstance.disks().size() < originalInstance.disks().size()); @@ -199,8 +198,7 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live", dependsOnMethods = "testInsertInstance") public void testListInstance() { - Iterator> instances = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder() - .filter("name eq " + INSTANCE_NAME)); + Iterator> instances = api().list(filter("name eq " + INSTANCE_NAME)); List instancesAsList = instances.next(); @@ -212,12 +210,12 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live", dependsOnMethods = "testDetachDiskFromInstance") public void testResetInstance() { - assertZoneOperationDoneSuccessfully(api().resetInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME), TIME_WAIT); + assertZoneOperationDoneSuccessfully(api().reset(INSTANCE_NAME), TIME_WAIT); } @Test(groups = "live", dependsOnMethods = "testResetInstance") public void testDeleteInstance() { - assertZoneOperationDoneSuccessfully(api().deleteInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME), TIME_WAIT); + assertZoneOperationDoneSuccessfully(api().delete(INSTANCE_NAME), TIME_WAIT); assertZoneOperationDoneSuccessfully(api.getDiskApi(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME), TIME_WAIT); assertZoneOperationDoneSuccessfully( @@ -234,7 +232,7 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @AfterClass(groups = { "integration", "live" }) protected void tearDownContext() { try { - waitZoneOperationDone(api().deleteInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME), TIME_WAIT); + waitZoneOperationDone(api().delete(INSTANCE_NAME), TIME_WAIT); waitZoneOperationDone(api.getDiskApi(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME), TIME_WAIT); waitZoneOperationDone(api.getDiskApi(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME, BOOT_DISK_NAME), diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiLiveTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiLiveTest.java index 172a153053..41d5fa339e 100644 --- a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiLiveTest.java +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiLiveTest.java @@ -70,7 +70,7 @@ public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live") public void testCreateInstanceAndHealthCheck(){ - InstanceApi instanceApi = api.getInstanceApi(userProject.get()); + InstanceApi instanceApi = api.getInstanceApi(userProject.get(), DEFAULT_ZONE_NAME); HttpHealthCheckApi httpHealthCheckApi = api.getHttpHealthCheckApi(userProject.get()); ListPage list = api.getImageApi("centos-cloud").list(new ListOptions.Builder().filter("name eq centos.*")) @@ -109,9 +109,9 @@ public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { TIME_WAIT_LONG); // Create an instance. - assertZoneOperationDoneSuccessfully(instanceApi.createInZone(INSTANCE_NAME, DEFAULT_ZONE_NAME, instanceTemplate), + assertZoneOperationDoneSuccessfully(instanceApi.create(INSTANCE_NAME, instanceTemplate), TIME_WAIT_LONG); - Instance instance = instanceApi.getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); + Instance instance = instanceApi.get(INSTANCE_NAME); instances = new ArrayList(); instances.add(instance.selfLink()); @@ -244,11 +244,11 @@ public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @AfterClass(groups = { "integration", "live" }) public void testCleanup(){ - InstanceApi instanceApi = api.getInstanceApi(userProject.get()); + InstanceApi instanceApi = api.getInstanceApi(userProject.get(), DEFAULT_ZONE_NAME); HttpHealthCheckApi httpHealthCheckApi = api.getHttpHealthCheckApi(userProject.get()); try { - waitZoneOperationDone(instanceApi.deleteInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME), TIME_WAIT_LONG); + waitZoneOperationDone(instanceApi.delete(INSTANCE_NAME), TIME_WAIT_LONG); waitZoneOperationDone(api.getDiskApi(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME, BOOT_DISK_NAME), TIME_WAIT);