standardize listPage across all GCE resources.
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/commit/d7403236 Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/tree/d7403236 Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/diff/d7403236 Branch: refs/heads/master Commit: d74032369fbef26972b5f8b996f8e98c3be4b84a Parents: 8b5d3d3 Author: Adrian Cole <[email protected]> Authored: Tue Nov 4 22:26:51 2014 -0800 Committer: Adrian Cole <[email protected]> Committed: Wed Nov 5 11:26:31 2014 -0800 ---------------------------------------------------------------------- .../GoogleComputeEngineApi.java | 49 ++--- .../binders/DiskCreationBinder.java | 65 +++---- .../TargetPoolChangeHealthChecksBinder.java | 9 +- .../TargetPoolChangeInstancesBinder.java | 9 +- .../TargetPoolMapofListofMapGenericBinder.java | 63 +++---- .../compute/GoogleComputeEngineService.java | 12 +- .../GoogleComputeEngineServiceAdapter.java | 19 +- ...ogleComputeEngineSecurityGroupExtension.java | 10 +- .../functions/NetworkToSecurityGroup.java | 22 +-- .../features/AddressApi.java | 82 +++----- .../googlecomputeengine/features/DiskApi.java | 131 +++++-------- .../features/DiskTypeApi.java | 111 +++++------ .../features/FirewallApi.java | 76 +++----- .../features/ForwardingRuleApi.java | 95 +++++----- .../features/GlobalOperationApi.java | 60 +++--- .../features/HttpHealthCheckApi.java | 92 ++++----- .../googlecomputeengine/features/ImageApi.java | 87 +++------ .../features/InstanceApi.java | 13 +- .../features/MachineTypeApi.java | 45 ++--- .../features/NetworkApi.java | 58 ++---- .../features/ProjectApi.java | 22 +-- .../googlecomputeengine/features/RegionApi.java | 44 ++--- .../features/RegionOperationApi.java | 70 +++---- .../googlecomputeengine/features/RouteApi.java | 111 +++++------ .../features/SnapshotApi.java | 56 ++---- .../features/TargetPoolApi.java | 107 ++++++----- .../googlecomputeengine/features/ZoneApi.java | 44 ++--- .../features/ZoneOperationApi.java | 67 +++---- .../internal/BaseToIteratorOfListPage.java | 14 +- .../BaseWithRegionToIteratorOfListPage.java | 16 +- .../BaseWithZoneToIteratorOfListPage.java | 16 +- .../functions/internal/ParseAddresses.java | 2 +- .../functions/internal/ParseDiskTypes.java | 2 +- .../functions/internal/ParseDisks.java | 2 +- .../functions/internal/ParseFirewalls.java | 2 +- .../internal/ParseForwardingRules.java | 2 +- .../internal/ParseGlobalOperations.java | 2 +- .../internal/ParseHttpHealthChecks.java | 2 +- .../functions/internal/ParseImages.java | 2 +- .../functions/internal/ParseMachineTypes.java | 5 +- .../functions/internal/ParseNetworks.java | 2 +- .../internal/ParseRegionOperations.java | 2 +- .../functions/internal/ParseRegions.java | 2 +- .../functions/internal/ParseRoutes.java | 2 +- .../functions/internal/ParseSnapshots.java | 2 +- .../functions/internal/ParseTargetPools.java | 2 +- .../functions/internal/ParseZoneOperations.java | 2 +- .../functions/internal/ParseZones.java | 2 +- .../options/AttachDiskOptions.java | 50 ++--- .../options/DiskCreationOptions.java | 22 +-- .../options/ListOptions.java | 7 +- .../RegionOperationDonePredicate.java | 13 +- .../predicates/ZoneOperationDonePredicate.java | 2 +- .../PageSystemExpectTest.java | 111 ----------- .../binders/DiskCreationBinderTest.java | 19 +- .../ForwardingRuleCreationBinderTest.java | 12 -- .../HttpHealthCheckCreationBinderTest.java | 12 -- .../TargetPoolAddInstanceBinderTest.java | 15 +- .../binders/TargetPoolCreationBinderTest.java | 12 -- .../GoogleComputeEngineServiceLiveTest.java | 9 +- .../functions/NetworkToSecurityGroupTest.java | 4 +- .../features/AddressApiExpectTest.java | 30 ++- .../features/AddressApiLiveTest.java | 14 +- .../features/DiskApiExpectTest.java | 46 +++-- .../features/DiskApiLiveTest.java | 26 +-- .../features/DiskTypeApiExpectTest.java | 37 ++-- .../features/DiskTypeApiLiveTest.java | 9 +- .../features/FirewallApiLiveTest.java | 5 +- .../features/ForwardingRuleApiLiveTest.java | 14 +- .../features/GlobalOperationApiExpectTest.java | 8 +- .../features/GlobalOperationApiLiveTest.java | 6 +- .../features/HttpHealthCheckApiLiveTest.java | 5 +- .../features/ImageApiExpectTest.java | 4 +- .../features/ImageApiLiveTest.java | 15 +- .../features/InstanceApiLiveTest.java | 39 ++-- .../features/MachineTypeApiExpectTest.java | 20 +- .../features/MachineTypeApiLiveTest.java | 9 +- .../features/NetworkApiLiveTest.java | 8 +- .../features/RegionApiLiveTest.java | 4 +- .../features/RegionOperationApiExpectTest.java | 36 ++-- .../features/RegionOperationApiLiveTest.java | 10 +- .../features/SnapshotApiLiveTest.java | 18 +- .../features/TargetPoolApiExpectTest.java | 3 +- .../features/TargetPoolApiLiveTest.java | 18 +- .../features/ZoneApiLiveTest.java | 5 +- .../features/ZoneOperationApiExpectTest.java | 39 ++-- .../features/ZoneOperationApiLiveTest.java | 10 +- .../ToIteratorOfListPageExpectTest.java | 185 +++++++++++++++++++ 88 files changed, 1085 insertions(+), 1538 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d7403236/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java index 19e178b..095f8c8 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java @@ -58,28 +58,31 @@ public interface GoogleComputeEngineApi extends Closeable { * Provides access to Address features * * @param projectName the name of the project + * @param region the name of the region scoping this request. */ @Delegate - @Path("/projects/{project}") - AddressApi getAddressApi(@PathParam("project") String projectName); + @Path("/projects/{project}/regions/{region}") + AddressApi getAddressApi(@PathParam("project") String projectName, @PathParam("region") String region); /** * Provides access to Disk features * * @param projectName the name of the project + * @param zone the name of the zone scoping this request. */ @Delegate - @Path("/projects/{project}") - DiskApi getDiskApi(@PathParam("project") String projectName); + @Path("/projects/{project}/zones/{zone}") + DiskApi getDiskApi(@PathParam("project") String projectName, @PathParam("zone") String zone); /** * Provides access to DiskType features * - * @param projectName the name of the project + * @param projectName the name of the project + * @param zone the name of the zone scoping this request. */ @Delegate - @Path("/projects/{project}") - DiskTypeApi getDiskTypeApi(@PathParam("project") String projectName); + @Path("/projects/{project}/zones/{zone}") + DiskTypeApi getDiskTypeApi(@PathParam("project") String projectName, @PathParam("zone") String zone); /** * Provides access to Firewall features @@ -87,7 +90,7 @@ public interface GoogleComputeEngineApi extends Closeable { * @param projectName the name of the project */ @Delegate - @Path("/projects/{project}") + @Path("/projects/{project}/global") FirewallApi getFirewallApi(@PathParam("project") String projectName); /** @@ -106,7 +109,7 @@ public interface GoogleComputeEngineApi extends Closeable { * @param projectName the name of the project */ @Delegate - @Path("/projects/{project}") + @Path("/projects/{project}/global") GlobalOperationApi getGlobalOperationApi(@PathParam("project") String projectName); /** @@ -115,7 +118,7 @@ public interface GoogleComputeEngineApi extends Closeable { * @param projectName the name of the project */ @Delegate - @Path("/projects/{project}/global/httpHealthChecks") + @Path("/projects/{project}/global") HttpHealthCheckApi getHttpHealthCheckApi(@PathParam("project") String projectName); /** @@ -124,7 +127,7 @@ public interface GoogleComputeEngineApi extends Closeable { * @param projectName the name of the project */ @Delegate - @Path("/projects/{project}") + @Path("/projects/{project}/global") ImageApi getImageApi(@PathParam("project") String projectName); /** @@ -141,10 +144,11 @@ public interface GoogleComputeEngineApi extends Closeable { * Provides access to MachineType features * * @param projectName the name of the project + * @param zone the name of the zone scoping this request. */ @Delegate - @Path("/projects/{project}") - MachineTypeApi getMachineTypeApi(@PathParam("project") String projectName); + @Path("/projects/{project}/zones/{zone}") + MachineTypeApi getMachineTypeApi(@PathParam("project") String projectName, @PathParam("zone") String zone); /** * Provides access to Network features @@ -152,7 +156,7 @@ public interface GoogleComputeEngineApi extends Closeable { * @param projectName the name of the project */ @Delegate - @Path("/projects/{project}") + @Path("/projects/{project}/global") NetworkApi getNetworkApi(@PathParam("project") String projectName); /** @@ -173,11 +177,12 @@ public interface GoogleComputeEngineApi extends Closeable { /** * Provides access to Region Operation features * - * @param projectName the name of the project + * @param project the name of the project + * @param region the name of the region scoping this request. */ @Delegate - @Path("/projects/{project}") - RegionOperationApi getRegionOperationApi(@PathParam("project") String projectName); + @Path("/projects/{project}/regions/{region}") + RegionOperationApi getRegionOperationApi(@PathParam("project") String project, @PathParam("region") String region); /** * Provides access to Route features @@ -185,7 +190,7 @@ public interface GoogleComputeEngineApi extends Closeable { * @param projectName the name of the project */ @Delegate - @Path("/projects/{project}") + @Path("/projects/{project}/global") RouteApi getRouteApi(@PathParam("project") String projectName); /** @@ -194,7 +199,7 @@ public interface GoogleComputeEngineApi extends Closeable { * @param projectName the name of the project */ @Delegate - @Path("/projects/{project}") + @Path("/projects/{project}/global") SnapshotApi getSnapshotApi(@PathParam("project") String projectName); /** @@ -220,9 +225,9 @@ public interface GoogleComputeEngineApi extends Closeable { * Provides access to Zone Operation features * * @param projectName the name of the project + * @param zone the name of the zone scoping this request. */ @Delegate - @Path("/projects/{project}") - ZoneOperationApi getZoneOperationApi(@PathParam("project") String projectName); - + @Path("/projects/{project}/zones/{zone}") + ZoneOperationApi getZoneOperationApi(@PathParam("project") String projectName, @PathParam("zone") String zone); } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d7403236/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/DiskCreationBinder.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/DiskCreationBinder.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/DiskCreationBinder.java index 37aa9b6..16825e5 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/DiskCreationBinder.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/DiskCreationBinder.java @@ -16,54 +16,43 @@ */ package org.jclouds.googlecomputeengine.binders; -import java.net.URI; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; import java.util.Map; -import javax.inject.Inject; - import org.jclouds.googlecomputeengine.options.DiskCreationOptions; import org.jclouds.http.HttpRequest; -import org.jclouds.json.Json; -import org.jclouds.rest.binders.BindToJsonPayload; - +import org.jclouds.rest.MapBinder; -public class DiskCreationBinder extends BindToJsonPayload { - - @Inject DiskCreationBinder(Json jsonBinder) { - super(jsonBinder); - } +import com.google.gson.stream.JsonWriter; +public final class DiskCreationBinder implements MapBinder { @Override public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) { DiskCreationOptions options = (DiskCreationOptions) postParams.get("options"); - String name = postParams.get("name").toString(); - int sizeGb = (Integer) postParams.get("sizeGb"); - DiskCreationBinderHelper diskCreationOptionsExtended = new DiskCreationBinderHelper(name, sizeGb, options); - return super.bindToRequest(request, diskCreationOptionsExtended); + Writer out = new StringWriter(); + JsonWriter json = new JsonWriter(out); + json.setSerializeNulls(false); + try { + json.beginObject(); + json.name("name").value(postParams.get("name").toString()); + json.name("sizeGb").value((Integer) postParams.get("sizeGb")); + json.name("type").value(options.type() != null ? options.type().toString() : null); + json.name("sourceImage").value(options.sourceImage() != null ? options.sourceImage().toString() : null); + json.name("sourceSnapshot") + .value(options.sourceSnapshot() != null ? options.sourceSnapshot().toString() : null); + json.endObject(); + json.close(); + } catch (IOException e) { + throw new AssertionError(e); // should be impossible as we are writing a string! + } + request.setPayload(out.toString()); + request.getPayload().getContentMetadata().setContentType("application/json"); + return request; } - private class DiskCreationBinderHelper{ - - /** - * Values used to bind DiskCreationOptions to json request. - */ - @SuppressWarnings("unused") - private String name; - @SuppressWarnings("unused") - private int sizeGb; - @SuppressWarnings("unused") - private URI type; - @SuppressWarnings("unused") - private URI sourceImage; - @SuppressWarnings("unused") - private URI sourceSnapshot; - - private DiskCreationBinderHelper(String name, int sizeGb, DiskCreationOptions diskCreationOptions){ - this.name = name; - this.sizeGb = sizeGb; - this.type = diskCreationOptions.getType(); - this.sourceImage = diskCreationOptions.getSourceImage(); - this.sourceSnapshot = diskCreationOptions.getSourceSnapshot(); - } + @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { + throw new UnsupportedOperationException(); } } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d7403236/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeHealthChecksBinder.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeHealthChecksBinder.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeHealthChecksBinder.java index 7834803..6c0e0e2 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeHealthChecksBinder.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeHealthChecksBinder.java @@ -18,16 +18,11 @@ package org.jclouds.googlecomputeengine.binders; import javax.inject.Inject; -import org.jclouds.json.Json; - /** * Binder used for adding and deleting healthChecks from a target pool. */ public final class TargetPoolChangeHealthChecksBinder extends TargetPoolMapofListofMapGenericBinder { - - @Inject TargetPoolChangeHealthChecksBinder(Json jsonBinder) { - super(jsonBinder); - super.outerString("healthChecks"); - super.innerString("healthCheck"); + @Inject TargetPoolChangeHealthChecksBinder() { + super("healthChecks", "healthCheck"); } } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d7403236/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeInstancesBinder.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeInstancesBinder.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeInstancesBinder.java index 603654a..4572505 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeInstancesBinder.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeInstancesBinder.java @@ -18,16 +18,11 @@ package org.jclouds.googlecomputeengine.binders; import javax.inject.Inject; -import org.jclouds.json.Json; - /** * Binder used for adding and deleting instances from a target pool. */ public final class TargetPoolChangeInstancesBinder extends TargetPoolMapofListofMapGenericBinder { - - @Inject TargetPoolChangeInstancesBinder(Json jsonBinder) { - super(jsonBinder); - super.outerString("instances"); - super.innerString("instance"); + @Inject TargetPoolChangeInstancesBinder() { + super("instances", "instance"); } } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d7403236/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolMapofListofMapGenericBinder.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolMapofListofMapGenericBinder.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolMapofListofMapGenericBinder.java index 007b06f..fa611f1 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolMapofListofMapGenericBinder.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolMapofListofMapGenericBinder.java @@ -16,50 +16,51 @@ */ package org.jclouds.googlecomputeengine.binders; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; import java.net.URI; import java.util.List; import java.util.Map; -import javax.inject.Inject; - import org.jclouds.http.HttpRequest; -import org.jclouds.json.Json; -import org.jclouds.rest.binders.BindToJsonPayload; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; +import org.jclouds.rest.MapBinder; -class TargetPoolMapofListofMapGenericBinder extends BindToJsonPayload { - - @Inject TargetPoolMapofListofMapGenericBinder(Json jsonBinder) { - super(jsonBinder); - } +import com.google.gson.stream.JsonWriter; - private String outterString; - private String innerString; +class TargetPoolMapofListofMapGenericBinder implements MapBinder { + private final String outterString; + private final String innerString; - public void outerString(String outterString) { + TargetPoolMapofListofMapGenericBinder(String outterString, String innerString) { this.outterString = outterString; - } - - public void innerString(String innerString) { this.innerString = innerString; } - /** - * For the addInstance request the request body is in an atypical form. - * - * @see <a href="https://cloud.google.com/compute/docs/reference/latest/targetPools/addInstance"/> - */ @Override public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) { - List<URI> instances = (List<URI>) postParams.get(outterString); - Map<String, List<Map<String, URI>>> finalInstances = Maps.newLinkedHashMap(); - List<Map<String, URI>> innerInstances = Lists.newArrayList(); - for (URI instance : instances) { - innerInstances.add(ImmutableMap.of(innerString, instance)); + Writer out = new StringWriter(); + JsonWriter json = new JsonWriter(out); + try { + json.beginObject(); + json.name(outterString); + json.beginArray(); + for (URI uri : (List<URI>) postParams.get(outterString)) { + json.beginObject(); + json.name(innerString).value(uri.toString()); + json.endObject(); + } + json.endArray(); + json.endObject(); + json.close(); + } catch (IOException e) { + throw new AssertionError(e); // should be impossible as we are writing a string! } - finalInstances.put(outterString, innerInstances); - return super.bindToRequest(request, finalInstances); + request.setPayload(out.toString()); + request.getPayload().getContentMetadata().setContentType("application/json"); + return request; + } + + @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { + throw new UnsupportedOperationException(); } } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d7403236/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineService.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineService.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineService.java index a523e64..34b8a87 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineService.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineService.java @@ -76,7 +76,7 @@ import com.google.common.base.Supplier; import com.google.common.util.concurrent.Atomics; import com.google.common.util.concurrent.ListeningExecutorService; -public class GoogleComputeEngineService extends BaseComputeService { +public final class GoogleComputeEngineService extends BaseComputeService { private final Function<Set<? extends NodeMetadata>, Set<String>> findOrphanedGroups; private final GroupNamingConvention.Factory namingConvention; @@ -86,8 +86,7 @@ public class GoogleComputeEngineService extends BaseComputeService { private final long operationCompleteCheckInterval; private final long operationCompleteCheckTimeout; - @Inject - protected GoogleComputeEngineService(ComputeServiceContext context, + @Inject GoogleComputeEngineService(ComputeServiceContext context, Map<String, Credentials> credentialStore, @Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> hardwareProfiles, @@ -148,8 +147,7 @@ public class GoogleComputeEngineService extends BaseComputeService { } } - - protected void cleanUpNetworksAndFirewallsForGroup(final String groupName) { + private void cleanUpNetworksAndFirewallsForGroup(final String groupName) { String resourceName = namingConvention.create().sharedNameForGroup(groupName); Network network = api.getNetworkApi(project.get()).get(resourceName); FirewallApi firewallApi = api.getFirewallApi(project.get()); @@ -181,10 +179,6 @@ public class GoogleComputeEngineService extends BaseComputeService { } } - - /** - * returns template options, except of type {@link org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions}. - */ @Override public GoogleComputeEngineTemplateOptions templateOptions() { return GoogleComputeEngineTemplateOptions.class.cast(super.templateOptions()); http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d7403236/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java index c330eda..0a2bc7d 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java @@ -72,6 +72,7 @@ import org.jclouds.googlecomputeengine.domain.Operation; import org.jclouds.googlecomputeengine.domain.Zone; import org.jclouds.googlecomputeengine.domain.templates.InstanceTemplate; import org.jclouds.googlecomputeengine.domain.templates.InstanceTemplate.PersistentDisk; +import org.jclouds.googlecomputeengine.features.DiskApi; import org.jclouds.googlecomputeengine.features.InstanceApi; import org.jclouds.googlecomputeengine.options.DiskCreationOptions; @@ -228,15 +229,12 @@ public final class GoogleComputeEngineServiceAdapter implements ComputeServiceAd String diskName = instanceName + "-" + GCE_BOOT_DISK_SUFFIX; DiskCreationOptions diskCreationOptions = new DiskCreationOptions().sourceImage(imageUri); - Operation diskOperation = api.getDiskApi(userProject.get()) - .createInZone(diskName, - diskSize, - template.getLocation().getId(), - diskCreationOptions); + DiskApi diskApi = api.getDiskApi(userProject.get(), template.getLocation().getId()); + Operation diskOperation = diskApi.create(diskName, diskSize, diskCreationOptions); waitOperationDone(diskOperation); - return api.getDiskApi(userProject.get()).getInZone(template.getLocation().getId(), diskName); + return diskApi.get(diskName); } @Override @@ -244,7 +242,7 @@ public final class GoogleComputeEngineServiceAdapter implements ComputeServiceAd ImmutableList.Builder<MachineTypeInZone> builder = ImmutableList.builder(); for (final Location zone : zones.get().values()) { - for (Iterator<ListPage<MachineType>> i = api.getMachineTypeApi(userProject.get()).listInZone(zone.getId()); + for (Iterator<ListPage<MachineType>> i = api.getMachineTypeApi(userProject.get(), zone.getId()).list(); i.hasNext(); ) { builder.addAll(FluentIterable.from(i.next()).filter(new Predicate<MachineType>() { @Override public boolean apply(MachineType input) { @@ -328,8 +326,9 @@ public final class GoogleComputeEngineServiceAdapter implements ComputeServiceAd @Override public void destroyNode(final String name) { SlashEncodedIds zoneAndId = SlashEncodedIds.fromSlashEncoded(name); + InstanceApi instanceApi = api.getInstanceApi(userProject.get(), zoneAndId.left()); String diskName = null; - Instance instance = api.getInstanceApi(userProject.get(), zoneAndId.left()).get(zoneAndId.right()); + Instance instance = instanceApi.get(zoneAndId.right()); if (instance != null && "true".equals(instance.metadata().items().get(GCE_DELETE_BOOT_DISK_METADATA_KEY))) { for (AttachedDisk input : instance.disks()) { @@ -339,10 +338,10 @@ public final class GoogleComputeEngineServiceAdapter implements ComputeServiceAd } } } - waitOperationDone(api.getInstanceApi(userProject.get(), zoneAndId.left()).delete(zoneAndId.right())); + waitOperationDone(instanceApi.delete(zoneAndId.right())); if (diskName != null) { - waitOperationDone(api.getDiskApi(userProject.get()).deleteInZone(zoneAndId.left(), diskName)); + waitOperationDone(api.getDiskApi(userProject.get(), zoneAndId.left()).delete(diskName)); } } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d7403236/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/extensions/GoogleComputeEngineSecurityGroupExtension.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/extensions/GoogleComputeEngineSecurityGroupExtension.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/extensions/GoogleComputeEngineSecurityGroupExtension.java index d40db68..28ee3eb 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/extensions/GoogleComputeEngineSecurityGroupExtension.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/extensions/GoogleComputeEngineSecurityGroupExtension.java @@ -23,6 +23,7 @@ import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERA import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_TIMEOUT; import static org.jclouds.googlecomputeengine.compute.strategy.CreateNodesWithGroupEncodedIntoNameThenAddToSet.DEFAULT_INTERNAL_NETWORK_RANGE; import static org.jclouds.googlecomputeengine.internal.ListPages.concat; +import static org.jclouds.googlecomputeengine.options.ListOptions.Builder.filter; import static org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicates.equalsIpPermission; import static org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicates.providesIpPermission; import static org.jclouds.util.Predicates2.retry; @@ -50,7 +51,6 @@ import org.jclouds.googlecomputeengine.domain.Network; import org.jclouds.googlecomputeengine.domain.Operation; import org.jclouds.googlecomputeengine.options.FirewallOptions; import org.jclouds.googlecomputeengine.options.ListOptions; -import org.jclouds.googlecomputeengine.options.ListOptions.Builder; import org.jclouds.net.domain.IpPermission; import org.jclouds.net.domain.IpProtocol; @@ -169,7 +169,7 @@ public class GoogleComputeEngineSecurityGroupExtension implements SecurityGroupE return false; } - ListOptions options = new ListOptions.Builder().filter("network eq .*/" + id); + ListOptions options = filter("network eq .*/" + id); FluentIterable<Firewall> fws = FluentIterable.from(concat(api.getFirewallApi(userProject.get()).list(options))); @@ -202,7 +202,7 @@ public class GoogleComputeEngineSecurityGroupExtension implements SecurityGroupE checkNotNull(api.getNetworkApi(userProject.get()).get(group.getId()) == null, "network for group is null"); - ListOptions options = new ListOptions.Builder().filter("network eq .*/" + group.getName()); + ListOptions options = filter("network eq .*/" + group.getName()); if (Iterables .any(concat(api.getFirewallApi(userProject.get()).list(options)), providesIpPermission(ipPermission))) { @@ -265,7 +265,7 @@ public class GoogleComputeEngineSecurityGroupExtension implements SecurityGroupE checkNotNull(api.getNetworkApi(userProject.get()).get(group.getId()) == null, "network for group is null"); - ListOptions options = new ListOptions.Builder().filter("network eq .*/" + group.getName()); + ListOptions options = filter("network eq .*/" + group.getName()); FluentIterable<Firewall> fws = FluentIterable.from(concat(api.getFirewallApi(userProject.get()).list(options))); @@ -327,7 +327,7 @@ public class GoogleComputeEngineSecurityGroupExtension implements SecurityGroupE } private SecurityGroup groupForTagsInNetwork(Network nw, final Collection<String> tags) { - ListOptions opts = new Builder().filter("network eq .*/" + nw.name()); + ListOptions opts = filter("network eq .*/" + nw.name()); List<Firewall> fws = FluentIterable.from(concat(api.getFirewallApi(userProject.get()).list(opts))) .filter(new Predicate<Firewall>() { @Override public boolean apply(final Firewall input) { http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d7403236/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/NetworkToSecurityGroup.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/NetworkToSecurityGroup.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/NetworkToSecurityGroup.java index 5c4d8ce..1bd4811 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/NetworkToSecurityGroup.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/NetworkToSecurityGroup.java @@ -17,41 +17,34 @@ package org.jclouds.googlecomputeengine.compute.functions; import static org.jclouds.googlecomputeengine.internal.ListPages.concat; +import static org.jclouds.googlecomputeengine.options.ListOptions.Builder.filter; -import javax.annotation.Resource; import javax.inject.Inject; -import javax.inject.Named; import org.jclouds.compute.domain.SecurityGroup; import org.jclouds.compute.domain.SecurityGroupBuilder; -import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; import org.jclouds.googlecomputeengine.config.UserProject; import org.jclouds.googlecomputeengine.domain.Firewall; import org.jclouds.googlecomputeengine.domain.Network; import org.jclouds.googlecomputeengine.options.ListOptions; -import org.jclouds.logging.Logger; import org.jclouds.net.domain.IpPermission; import com.google.common.base.Function; import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableList; /** * A function for transforming a GCE-specific Network into a generic * SecurityGroup object. */ -public class NetworkToSecurityGroup implements Function<Network, SecurityGroup> { - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - protected Logger logger = Logger.NULL; +public final class NetworkToSecurityGroup implements Function<Network, SecurityGroup> { private final Function<Firewall, Iterable<IpPermission>> firewallToPerms; private final GoogleComputeEngineApi api; private final Supplier<String> project; - @Inject - public NetworkToSecurityGroup(Function<Firewall, Iterable<IpPermission>> firewallToPerms, + @Inject NetworkToSecurityGroup(Function<Firewall, Iterable<IpPermission>> firewallToPerms, GoogleComputeEngineApi api, @UserProject Supplier<String> project) { this.firewallToPerms = firewallToPerms; @@ -59,8 +52,7 @@ public class NetworkToSecurityGroup implements Function<Network, SecurityGroup> this.project = project; } - @Override - public SecurityGroup apply(Network network) { + @Override public SecurityGroup apply(Network network) { SecurityGroupBuilder builder = new SecurityGroupBuilder(); builder.id(network.name()); @@ -68,9 +60,9 @@ public class NetworkToSecurityGroup implements Function<Network, SecurityGroup> builder.name(network.name()); builder.uri(network.selfLink()); - ImmutableSet.Builder permBuilder = ImmutableSet.builder(); + ImmutableList.Builder permBuilder = ImmutableList.builder(); - ListOptions options = new ListOptions.Builder().filter("network eq .*/" + network.name()); + ListOptions options = filter("network eq .*/" + network.name()); for (Firewall fw : concat(api.getFirewallApi(project.get()).list(options))) { permBuilder.addAll(firewallToPerms.apply(fw)); http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d7403236/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/AddressApi.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/AddressApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/AddressApi.java index 8babee2..71bd2bb 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/AddressApi.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/AddressApi.java @@ -16,6 +16,7 @@ */ 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; @@ -30,7 +31,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; @@ -52,109 +52,79 @@ import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.Transform; import org.jclouds.rest.binders.BindToJsonPayload; -/** - * Provides access to Addresses via their REST API. - */ @SkipEncoding({'/', '='}) @RequestFilters(OAuthAuthenticationFilter.class) +@Path("/addresses") +@Consumes(APPLICATION_JSON) public interface AddressApi { - /** - * Returns the specified address resource. - * - * @param region Name of the region the address is in. - * @param addressName name of the address resource to return. - * @return a Address resource. - */ + /** Returns an address by name or null if not found. */ @Named("Addresses:get") @GET - @Consumes(MediaType.APPLICATION_JSON) - @Path("/regions/{region}/addresses/{address}") + @Path("/{address}") @OAuthScopes(COMPUTE_READONLY_SCOPE) @Fallback(NullOnNotFoundOr404.class) @Nullable - Address getInRegion(@PathParam("region") String region, @PathParam("address") String addressName); + Address get(@PathParam("address") String address); /** - * Creates a address resource in the specified project specifying the size of the address. - * - * - * @param region the name of the region where the address is to be created. - * @param addressName the name of address. + * Creates an address resource in the specified project specifying the size of the address. + * + * @param address the name of address. * @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("Addresses:insert") @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("/regions/{region}/addresses") + @Produces(APPLICATION_JSON) @OAuthScopes({COMPUTE_SCOPE}) @MapBinder(BindToJsonPayload.class) - Operation createInRegion(@PathParam("region") String region, @PayloadParam("name") String addressName); + Operation create(@PayloadParam("name") String address); - /** - * Deletes the specified address resource. - * - * @param region the region the address is in. - * @param addressName name of the address 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. - */ + /** Deletes an address by name and returns the operation in progress, or null if not found. */ @Named("Addresses:delete") @DELETE - @Consumes(MediaType.APPLICATION_JSON) - @Path("/regions/{region}/addresses/{address}") + @Path("/{address}") @OAuthScopes(COMPUTE_SCOPE) @Fallback(NullOnNotFoundOr404.class) @Nullable - Operation deleteInRegion(@PathParam("region") String region, @PathParam("address") String addressName); + Operation delete(@PathParam("address") String address); /** - * Retrieves the listPage of address resources contained within the specified project and region. - * By default the listPage as a maximum size of 100, if no options are provided or ListOptions#getMaxResults() has - * not been set. + * Retrieves the list of address 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 region the region to search 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 listPage - * @see org.jclouds.googlecomputeengine.options.ListOptions - * @see org.jclouds.googlecomputeengine.domain.ListPage + * @return a page of the list */ @Named("Addresses:list") @GET - @Consumes(MediaType.APPLICATION_JSON) - @Path("/regions/{region}/addresses") @OAuthScopes(COMPUTE_READONLY_SCOPE) @ResponseParser(ParseAddresses.class) @Fallback(EmptyListPageOnNotFoundOr404.class) - ListPage<Address> listAtMarkerInRegion(@PathParam("region") String region, @QueryParam("pageToken") @Nullable String marker, ListOptions listOptions); + ListPage<Address> listPage(@Nullable @QueryParam("pageToken") String token, ListOptions listOptions); /** - * A paged version of AddressApi#listPageInRegion(String) - * - * @param region the region to list in - * @return an Iterator that is able to fetch additional pages when required - * @see #listAtMarkerInRegion(String, String, org.jclouds.googlecomputeengine.options.ListOptions) + * @see #list(org.jclouds.googlecomputeengine.options.ListOptions) */ @Named("Addresses:list") @GET - @Consumes(MediaType.APPLICATION_JSON) - @Path("/regions/{region}/addresses") @OAuthScopes(COMPUTE_READONLY_SCOPE) @ResponseParser(ParseAddresses.class) @Transform(ParseAddresses.ToIteratorOfListPage.class) @Fallback(EmptyIteratorOnNotFoundOr404.class) - Iterator<ListPage<Address>> listInRegion(@PathParam("region") String region); + Iterator<ListPage<Address>> list(); + /** + * @see #list(org.jclouds.googlecomputeengine.options.ListOptions) + */ @Named("Addresses:list") @GET - @Consumes(MediaType.APPLICATION_JSON) - @Path("/regions/{region}/addresses") @OAuthScopes(COMPUTE_READONLY_SCOPE) @ResponseParser(ParseAddresses.class) @Transform(ParseAddresses.ToIteratorOfListPage.class) @Fallback(EmptyIteratorOnNotFoundOr404.class) - Iterator<ListPage<Address>> listInRegion(@PathParam("region") String region, ListOptions options); + Iterator<ListPage<Address>> list(ListOptions options); } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d7403236/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/DiskApi.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/DiskApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/DiskApi.java index d38c48a..8b485de 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/DiskApi.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/DiskApi.java @@ -16,6 +16,7 @@ */ 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; @@ -30,7 +31,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; @@ -54,155 +54,114 @@ import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.Transform; import org.jclouds.rest.binders.BindToJsonPayload; -/** - * Provides access to Disks via their REST API. - */ @SkipEncoding({'/', '='}) @RequestFilters(OAuthAuthenticationFilter.class) +@Path("/disks") +@Consumes(APPLICATION_JSON) public interface DiskApi { - /** - * Returns the specified persistent disk resource. - * - * @param zone Name of the zone the disk is in. - * @param diskName name of the persistent disk resource to return. - * @return a Disk resource. - */ + /** Returns a persistent disk by name or null if not found. */ @Named("Disks:get") @GET - @Consumes(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/disks/{disk}") + @Path("/{disk}") @OAuthScopes(COMPUTE_READONLY_SCOPE) @Fallback(NullOnNotFoundOr404.class) @Nullable - Disk getInZone(@PathParam("zone") String zone, @PathParam("disk") String diskName); + Disk get(@PathParam("disk") String disk); /** * Creates a persistent disk resource in the specified project specifying the size of the disk. * * @param diskName the name of disk. * @param sizeGb the size of the disk - * @param zone the name of the zone where the disk is to be created. * @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("Disks:insert") @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/disks") - @OAuthScopes({COMPUTE_SCOPE}) + @Produces(APPLICATION_JSON) + @OAuthScopes(COMPUTE_SCOPE) @MapBinder(BindToJsonPayload.class) - Operation createInZone(@PayloadParam("name") String diskName, - @PayloadParam("sizeGb") int sizeGb, - @PathParam("zone") String zone); + Operation create(@PayloadParam("name") String diskName, @PayloadParam("sizeGb") int sizeGb); /** - * Creates a persistent disk resource, in the specified project, - * specifying the size of the disk and other options. + * Creates a persistent disk resource, in the specified project, specifying the size of the disk and other options. * * @param diskName the name of disk. * @param sizeGb the size of the disk - * @param zone the name of the zone where the disk is to be created. * @param options the options of the disk to create. * @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("Disks:insert") @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/disks") - @OAuthScopes({COMPUTE_SCOPE}) + @Produces(APPLICATION_JSON) + @OAuthScopes(COMPUTE_SCOPE) @MapBinder(DiskCreationBinder.class) - Operation createInZone(@PayloadParam("name") String diskName, - @PayloadParam("sizeGb") int sizeGb, - @PathParam("zone") String zone, - @PayloadParam("options") DiskCreationOptions options); + Operation create(@PayloadParam("name") String diskName, + @PayloadParam("sizeGb") int sizeGb, + @PayloadParam("options") DiskCreationOptions options); + + /** Deletes a persistent disk by name and returns the operation in progress, or null if not found. */ + @Named("Disks:delete") + @DELETE + @Path("/{disk}") + @OAuthScopes(COMPUTE_SCOPE) + @Fallback(NullOnNotFoundOr404.class) + @Nullable + Operation delete(@PathParam("disk") String disk); /** - * Deletes the specified persistent disk resource. + * Create a snapshot of a given disk in a zone. + * + * @param diskName the name of the disk. + * @param snapshotName the name for the snapshot to be created. * - * @param zone the zone the disk is in. - * @param diskName name of the persistent disk 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. */ - @Named("Disks:delete") - @DELETE - @Consumes(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/disks/{disk}") + @Named("Disks:createSnapshot") + @POST + @Path("/{disk}/createSnapshot") @OAuthScopes(COMPUTE_SCOPE) - @Fallback(NullOnNotFoundOr404.class) - @Nullable - Operation deleteInZone(@PathParam("zone") String zone, @PathParam("disk") String diskName); + @MapBinder(BindToJsonPayload.class) + Operation createSnapshot(@PathParam("disk") String diskName, @PayloadParam("name") String snapshotName); /** - * Retrieves the listPage of persistent disk resources contained within the specified project and zone. - * By default the listPage as a maximum size of 100, if no options are provided or ListOptions#getMaxResults() has - * not been set. + * Retrieves the list of persistent disk 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 the zone to search 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 listPage - * @see ListOptions - * @see org.jclouds.googlecomputeengine.domain.ListPage + * @return a page of the list */ @Named("Disks:list") @GET - @Consumes(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/disks") @OAuthScopes(COMPUTE_READONLY_SCOPE) @ResponseParser(ParseDisks.class) @Fallback(EmptyListPageOnNotFoundOr404.class) - ListPage<Disk> listAtMarkerInZone(@PathParam("zone") String zone, @QueryParam("pageToken") @Nullable String marker, ListOptions listOptions); + ListPage<Disk> listPage(@Nullable @QueryParam("pageToken") String token, ListOptions listOptions); /** - * A paged version of DiskApi#listPageInZone(String) - * - * @param zone the zone to list in - * @return an Iterator that is able to fetch additional pages when required - * @see DiskApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions) + * @see #list(org.jclouds.googlecomputeengine.options.ListOptions) */ @Named("Disks:list") @GET - @Consumes(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/disks") @OAuthScopes(COMPUTE_READONLY_SCOPE) @ResponseParser(ParseDisks.class) @Transform(ParseDisks.ToIteratorOfListPage.class) @Fallback(EmptyIteratorOnNotFoundOr404.class) - Iterator<ListPage<Disk>> listInZone(@PathParam("zone") String zone); + Iterator<ListPage<Disk>> list(); + /** + * @see #list(org.jclouds.googlecomputeengine.options.ListOptions) + */ @Named("Disks:list") @GET - @Consumes(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/disks") @OAuthScopes(COMPUTE_READONLY_SCOPE) @ResponseParser(ParseDisks.class) @Transform(ParseDisks.ToIteratorOfListPage.class) @Fallback(EmptyIteratorOnNotFoundOr404.class) - Iterator<ListPage<Disk>> listInZone(@PathParam("zone") String zone, ListOptions options); - - /** - * Create a snapshot of a given disk in a zone. - * - * @param zone the zone the disk is in. - * @param diskName the name of the disk. - * @param snapshotName the name for the snapshot to be created. - * - * @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("Disks:createSnapshot") - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/disks/{disk}/createSnapshot") - @OAuthScopes(COMPUTE_SCOPE) - @MapBinder(BindToJsonPayload.class) - Operation createSnapshotInZone(@PathParam("zone") String zone, - @PathParam("disk") String diskName, - @PayloadParam("name") String snapshotName); - + Iterator<ListPage<Disk>> list(ListOptions options); } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d7403236/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/DiskTypeApi.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/DiskTypeApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/DiskTypeApi.java index 32cf465..b16939f 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/DiskTypeApi.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/DiskTypeApi.java @@ -16,6 +16,7 @@ */ package org.jclouds.googlecomputeengine.features; +import static javax.ws.rs.core.MediaType.APPLICATION_JSON; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; import java.util.Iterator; @@ -26,7 +27,6 @@ import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; import org.jclouds.Fallbacks.NullOnNotFoundOr404; import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404; @@ -44,76 +44,55 @@ import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.Transform; -/** - * Provides access to DiskTypes via their REST API. - * - * @see <a href="https://cloud.google.com/compute/docs/reference/v1/diskTypes"/> - */ @SkipEncoding({'/', '='}) @RequestFilters(OAuthAuthenticationFilter.class) -@Consumes(MediaType.APPLICATION_JSON) +@Path("/diskTypes") +@Consumes(APPLICATION_JSON) public interface DiskTypeApi { - /** - * Returns the specified disk type resource. - * - * @param zone the name of the zone the disk type is in - * @param diskType name of the disk type resource to return. - * @return If successful, this method returns a DiskType resource - */ - @Named("DiskTypes:get") - @GET - @Path("/zones/{zone}/diskTypes/{diskType}") - @OAuthScopes(COMPUTE_READONLY_SCOPE) - @Fallback(NullOnNotFoundOr404.class) - DiskType getInZone(@PathParam("zone") String zone, @PathParam("diskType") String diskType); + /** Returns a disk type by name or null if not found. */ + @Named("DiskTypes:get") + @GET + @Path("/{diskType}") + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @Fallback(NullOnNotFoundOr404.class) + DiskType get(@PathParam("diskType") String diskType); - /** - * Retrieves the list of disk type 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 The name of the zone to list in. - * @param marker marks the beginning of the next list page - * @param listOptions listing options - * @return a page of the list - * @see ListOptions - * @see org.jclouds.googlecomputeengine.domain.ListPage - */ - @Named("DiskTypes:list") - @GET - @Path("/zones/{zone}/diskTypes") - @OAuthScopes(COMPUTE_READONLY_SCOPE) - @ResponseParser(ParseDiskTypes.class) - @Fallback(EmptyListPageOnNotFoundOr404.class) - ListPage<DiskType> listAtMarkerInZone(@PathParam("zone") String zone, - @QueryParam("pageToken") @Nullable String marker, - ListOptions listOptions); + /** + * Retrieves the list of disk type 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 token marks the beginning of the next list page + * @param listOptions listing options + * @return a page of the list + */ + @Named("DiskTypes:list") + @GET + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseDiskTypes.class) + @Fallback(EmptyListPageOnNotFoundOr404.class) + ListPage<DiskType> listPage(@Nullable @QueryParam("pageToken") String token, ListOptions listOptions); - /** - * @see DiskTypeApi#listInZone(String, org.jclouds.googlecomputeengine.options.ListOptions) - */ - @Named("DiskTypes:list") - @GET - @Path("/zones/{zone}/diskTypes") - @OAuthScopes(COMPUTE_READONLY_SCOPE) - @ResponseParser(ParseDiskTypes.class) - @Transform(ParseDiskTypes.ToIteratorOfListPage.class) - @Fallback(EmptyIteratorOnNotFoundOr404.class) - Iterator<ListPage<DiskType>> listInZone(@PathParam("zone") String zone); + /** + * @see #list(org.jclouds.googlecomputeengine.options.ListOptions) + */ + @Named("DiskTypes:list") + @GET + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseDiskTypes.class) + @Transform(ParseDiskTypes.ToIteratorOfListPage.class) + @Fallback(EmptyIteratorOnNotFoundOr404.class) + Iterator<ListPage<DiskType>> list(); - /** - * @see DiskTypeApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions) - * - * @param zone the zone to list in - * @return an Iterator that is able to fetch additional pages when required - */ - @Named("DiskTypes:list") - @GET - @Path("/zones/{zone}/diskTypes") - @OAuthScopes(COMPUTE_READONLY_SCOPE) - @ResponseParser(ParseDiskTypes.class) - @Transform(ParseDiskTypes.ToIteratorOfListPage.class) - @Fallback(EmptyIteratorOnNotFoundOr404.class) - Iterator<ListPage<DiskType>> listInZone(@PathParam("zone") String zone, ListOptions listOptions); + /** + * @see #list(org.jclouds.googlecomputeengine.options.ListOptions) + */ + @Named("DiskTypes:list") + @GET + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseDiskTypes.class) + @Transform(ParseDiskTypes.ToIteratorOfListPage.class) + @Fallback(EmptyIteratorOnNotFoundOr404.class) + Iterator<ListPage<DiskType>> list(ListOptions options); } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d7403236/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/FirewallApi.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/FirewallApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/FirewallApi.java index 5a6567d..883d647 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/FirewallApi.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/FirewallApi.java @@ -16,6 +16,7 @@ */ 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; @@ -32,7 +33,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; @@ -58,26 +58,20 @@ import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.Transform; import org.jclouds.rest.binders.BindToJsonPayload; -/** - * Provides access to Firewalls via their REST API. - */ @SkipEncoding({'/', '='}) @RequestFilters(OAuthAuthenticationFilter.class) +@Path("/firewalls") +@Consumes(APPLICATION_JSON) public interface FirewallApi { - /** - * Returns the specified image resource. - * - * @param firewallName name of the firewall resource to return. - * @return an Firewall resource - */ + + /** Returns a firewall by name or null if not found. */ @Named("Firewalls:get") @GET - @Consumes(MediaType.APPLICATION_JSON) - @Path("/global/firewalls/{firewall}") + @Path("/{firewall}") @OAuthScopes(COMPUTE_READONLY_SCOPE) @Fallback(NullOnNotFoundOr404.class) @Nullable - Firewall get(@PathParam("firewall") String firewallName); + Firewall get(@PathParam("firewall") String firewall); /** * Creates a firewall resource in the specified project using the data included in the request. @@ -90,9 +84,7 @@ public interface FirewallApi { */ @Named("Firewalls:insert") @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("/global/firewalls") + @Produces(APPLICATION_JSON) @OAuthScopes({COMPUTE_SCOPE}) @MapBinder(FirewallBinder.class) Operation createInNetwork(@PayloadParam("name") String name, @@ -102,79 +94,64 @@ public interface FirewallApi { /** * Updates the specified firewall resource with the data included in the request. * - * @param firewallName the name firewall to be updated. + * @param firewall the name firewall to be updated. * @param firewallOptions the new firewall. * @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("Firewalls:update") @PUT - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("/global/firewalls/{firewall}") + @Produces(APPLICATION_JSON) + @Path("/{firewall}") @OAuthScopes({COMPUTE_SCOPE}) - Operation update(@PathParam("firewall") String firewallName, + Operation update(@PathParam("firewall") String firewall, @BinderParam(BindToJsonPayload.class) FirewallOptions firewallOptions); /** * Updates the specified firewall resource, with patch semantics, with the data included in the request. * - * @param firewallName the name firewall to be updated. + * @param firewall the name firewall to be updated. * @param firewallOptions the new firewall. * @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("Firewalls:patch") @PATCH - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @Path("/global/firewalls/{firewall}") + @Produces(APPLICATION_JSON) + @Path("/{firewall}") @OAuthScopes({COMPUTE_SCOPE}) - Operation patch(@PathParam("firewall") String firewallName, + Operation patch(@PathParam("firewall") String firewall, @BinderParam(BindToJsonPayload.class) FirewallOptions firewallOptions); - /** - * Deletes the specified image resource. - * - * @param firewallName name of the firewall 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 image did not exist the result is null. - */ + /** Deletes a firewall by name and returns the operation in progress, or null if not found. */ @Named("Firewalls:delete") @DELETE - @Consumes(MediaType.APPLICATION_JSON) - @Path("/global/firewalls/{firewall}") + @Path("/{firewall}") @OAuthScopes(COMPUTE_SCOPE) @Fallback(NullOnNotFoundOr404.class) - Operation delete(@PathParam("firewall") String firewallName); + Operation delete(@PathParam("firewall") String firewall); /** * Retrieves the list of firewall 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 marker marks the beginning of the next list page - * @param options listing options + * @param token marks the beginning of the next list page + * @param listOptions listing options * @return a page of the list - * @see ListOptions - * @see org.jclouds.googlecomputeengine.domain.ListPage */ @Named("Firewalls:list") @GET - @Consumes(MediaType.APPLICATION_JSON) - @Path("/global/firewalls") @OAuthScopes(COMPUTE_READONLY_SCOPE) @ResponseParser(ParseFirewalls.class) @Fallback(EmptyListPageOnNotFoundOr404.class) - ListPage<Firewall> listAtMarker(@QueryParam("pageToken") @Nullable String marker, ListOptions options); + ListPage<Firewall> listPage(@Nullable @QueryParam("pageToken") String token, ListOptions listOptions); /** - * @see FirewallApi#list(org.jclouds.googlecomputeengine.options.ListOptions) + * @see #list(org.jclouds.googlecomputeengine.options.ListOptions) */ @Named("Firewalls:list") @GET - @Consumes(MediaType.APPLICATION_JSON) - @Path("/global/firewalls") @OAuthScopes(COMPUTE_READONLY_SCOPE) @ResponseParser(ParseFirewalls.class) @Transform(ParseFirewalls.ToIteratorOfListPage.class) @@ -182,15 +159,10 @@ public interface FirewallApi { Iterator<ListPage<Firewall>> list(); /** - * A paged version of FirewallApi#list() - * - * @return an Iterator that is able to fetch additional pages when required - * @see FirewallApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions) + * @see #list(org.jclouds.googlecomputeengine.options.ListOptions) */ @Named("Firewalls:list") @GET - @Consumes(MediaType.APPLICATION_JSON) - @Path("/global/firewalls") @OAuthScopes(COMPUTE_READONLY_SCOPE) @ResponseParser(ParseFirewalls.class) @Transform(ParseFirewalls.ToIteratorOfListPage.class) http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d7403236/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApi.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApi.java index 95009c0..5e8b4ab 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApi.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApi.java @@ -16,6 +16,7 @@ */ 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; @@ -30,7 +31,7 @@ import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; +import javax.ws.rs.QueryParam; import org.jclouds.Fallbacks.NullOnNotFoundOr404; import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404; @@ -54,23 +55,16 @@ import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.Transform; import org.jclouds.rest.binders.BindToJsonPayload; -/** - * Provides access to ForwardingRules via their REST API. - */ @SkipEncoding({'/', '='}) @RequestFilters(OAuthAuthenticator.class) -@Consumes(MediaType.APPLICATION_JSON) +@Path("/forwardingRules") +@Consumes(APPLICATION_JSON) public interface ForwardingRuleApi { - /** - * Returns the specified ForwardingRule resource. - * - * @param forwardingRule the name of the ForwardingRule resource to return. - * @return a ForwardingRule resource. - */ + /** Returns a forwarding rule by name or null if not found. */ @Named("ForwardingRules:get") @GET - @Path("/forwardingRules/{forwardingRule}") + @Path("/{forwardingRule}") @OAuthScopes(COMPUTE_READONLY_SCOPE) @Fallback(NullOnNotFoundOr404.class) @Nullable @@ -85,51 +79,23 @@ public interface ForwardingRuleApi { */ @Named("ForwardingRules:insert") @POST - @Produces(MediaType.APPLICATION_JSON) - @Path("/forwardingRules") + @Produces(APPLICATION_JSON) @OAuthScopes(COMPUTE_SCOPE) @MapBinder(ForwardingRuleCreationBinder.class) Operation create(@PayloadParam("name") String forwardingRuleName, @PayloadParam("options") ForwardingRuleCreationOptions options); - /** - * Deletes the specified TargetPool resource. - * - * @param forwardingRule name of the persistent forwarding rule 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. - */ + /** Deletes a forwarding rule by name and returns the operation in progress, or null if not found. */ @Named("ForwardingRules:delete") @DELETE - @Path("/forwardingRules/{forwardingRule}") + @Path("/{forwardingRule}") @OAuthScopes(COMPUTE_SCOPE) @Fallback(NullOnNotFoundOr404.class) @Nullable Operation delete(@PathParam("forwardingRule") String forwardingRule); /** - * @return an Iterator that is able to fetch additional pages when required - * @see org.jclouds.collect.PagedIterable - */ - @Named("ForwardingRules:list") - @GET - @Path("/forwardingRules") - @OAuthScopes(COMPUTE_READONLY_SCOPE) - @ResponseParser(ParseForwardingRules.class) - @Transform(ParseForwardingRules.ToIteratorOfListPage.class) - @Fallback(EmptyIteratorOnNotFoundOr404.class) - Iterator<ListPage<ForwardingRule>> list(); - - @Named("ForwardingRules:list") - @GET - @Path("/forwardingRules") - @OAuthScopes(COMPUTE_READONLY_SCOPE) - @ResponseParser(ParseForwardingRules.class) - @Fallback(EmptyListPageOnNotFoundOr404.class) - ListPage<ForwardingRule> list(ListOptions options); - - /** * Changes the target url for a forwarding rule. * * @param forwardingRule the name of the ForwardingRule resource in which target is to be set. @@ -141,11 +107,48 @@ public interface ForwardingRuleApi { */ @Named("ForwardingRules:setTarget") @POST - @Path("/forwardingRules/{forwardingRule}/setTarget") + @Path("/{forwardingRule}/setTarget") @OAuthScopes(COMPUTE_SCOPE) @Fallback(NullOnNotFoundOr404.class) @MapBinder(BindToJsonPayload.class) @Nullable - Operation setTarget(@PathParam("forwardingRule") String forwardingRule, - @PayloadParam("target") URI target); + Operation setTarget(@PathParam("forwardingRule") String forwardingRule, @PayloadParam("target") URI target); + + /** + * Retrieves the list of forwarding rule 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 token marks the beginning of the next list page + * @param listOptions listing options + * @return a page of the list + */ + @Named("ForwardingRules:list") + @GET + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseForwardingRules.class) + @Fallback(EmptyListPageOnNotFoundOr404.class) + ListPage<ForwardingRule> listPage(@Nullable @QueryParam("pageToken") String token, ListOptions listOptions); + + /** + * @see #list(org.jclouds.googlecomputeengine.options.ListOptions) + */ + @Named("ForwardingRules:list") + @GET + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseForwardingRules.class) + @Transform(ParseForwardingRules.ToIteratorOfListPage.class) + @Fallback(EmptyIteratorOnNotFoundOr404.class) + Iterator<ListPage<ForwardingRule>> list(); + + /** + * @see #list(org.jclouds.googlecomputeengine.options.ListOptions) + */ + @Named("ForwardingRules:list") + @GET + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseForwardingRules.class) + @Transform(ParseForwardingRules.ToIteratorOfListPage.class) + @Fallback(EmptyIteratorOnNotFoundOr404.class) + Iterator<ListPage<ForwardingRule>> list(ListOptions options); } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d7403236/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/GlobalOperationApi.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/GlobalOperationApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/GlobalOperationApi.java index 0d23b03..892a8d8 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/GlobalOperationApi.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/GlobalOperationApi.java @@ -16,6 +16,8 @@ */ package org.jclouds.googlecomputeengine.features; +import static javax.ws.rs.core.MediaType.APPLICATION_JSON; +import static org.jclouds.Fallbacks.VoidOnNotFoundOr404; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE; @@ -28,7 +30,6 @@ import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; import org.jclouds.Fallbacks.NullOnNotFoundOr404; import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404; @@ -46,83 +47,64 @@ import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.Transform; -/** - * Provides access to Global Operations via their REST API. - */ @SkipEncoding({'/', '='}) @RequestFilters(OAuthAuthenticationFilter.class) +@Path("/operations") +@Consumes(APPLICATION_JSON) public interface GlobalOperationApi { - /** - * Retrieves the specified operation resource. - * - * @param operationName name of the operation resource to return. - * @return If successful, this method returns an Operation resource - */ + /** Returns an operation by name or null if not found. */ @Named("GlobalOperations:get") @GET - @Path("/global/operations/{operation}") + @Path("/{operation}") @OAuthScopes(COMPUTE_READONLY_SCOPE) - @Consumes(MediaType.APPLICATION_JSON) @Fallback(NullOnNotFoundOr404.class) - Operation get(@PathParam("operation") String operationName); + @Nullable + Operation get(@PathParam("operation") String operation); - /** - * Deletes the specified operation resource. - * - * @param operationName name of the operation resource to delete. - */ + /** Deletes an operation by name. */ @Named("GlobalOperations:delete") @DELETE - @Path("/global/operations/{operation}") + @Path("/{operation}") @OAuthScopes(COMPUTE_SCOPE) - @Fallback(NullOnNotFoundOr404.class) - void delete(@PathParam("operation") String operationName); + @Fallback(VoidOnNotFoundOr404.class) + void delete(@PathParam("operation") String operation); /** - * Retrieves the listFirstPage of operation resources contained within the specified project. - * By default the listFirstPage as a maximum size of 100, if no options are provided or ListOptions#getMaxResults() - * has not been set. + * Retrieves the list of operation 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 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, starting at marker + * @return a page of the list */ @Named("GlobalOperations:list") @GET - @Path("/global/operations") @OAuthScopes(COMPUTE_READONLY_SCOPE) - @Consumes(MediaType.APPLICATION_JSON) @ResponseParser(ParseGlobalOperations.class) @Fallback(EmptyListPageOnNotFoundOr404.class) - ListPage<Operation> listAtMarker(@QueryParam("pageToken") @Nullable String marker, ListOptions listOptions); + ListPage<Operation> listPage(@Nullable @QueryParam("pageToken") String token, ListOptions listOptions); /** - * @see GlobalOperationApi#list(org.jclouds.googlecomputeengine.options.ListOptions) + * @see #list(org.jclouds.googlecomputeengine.options.ListOptions) */ @Named("GlobalOperations:list") @GET - @Path("/global/operations") @OAuthScopes(COMPUTE_READONLY_SCOPE) - @Consumes(MediaType.APPLICATION_JSON) @ResponseParser(ParseGlobalOperations.class) @Transform(ParseGlobalOperations.ToIteratorOfListPage.class) @Fallback(EmptyIteratorOnNotFoundOr404.class) Iterator<ListPage<Operation>> list(); /** - * A paged version of GlobalOperationApi#listFirstPage() - * - * @return an Iterator that is able to fetch additional pages when required - * @see GlobalOperationApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions) + * @see #list(org.jclouds.googlecomputeengine.options.ListOptions) */ @Named("GlobalOperations:list") @GET - @Path("/global/operations") @OAuthScopes(COMPUTE_READONLY_SCOPE) - @Consumes(MediaType.APPLICATION_JSON) @ResponseParser(ParseGlobalOperations.class) @Transform(ParseGlobalOperations.ToIteratorOfListPage.class) @Fallback(EmptyIteratorOnNotFoundOr404.class) - Iterator<ListPage<Operation>> list(ListOptions listOptions); + Iterator<ListPage<Operation>> list(ListOptions options); } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d7403236/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApi.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApi.java index 892bba3..1e61ce3 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApi.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApi.java @@ -16,9 +16,9 @@ */ 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.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404; import java.util.Iterator; @@ -31,10 +31,11 @@ import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; +import javax.ws.rs.QueryParam; import org.jclouds.Fallbacks.NullOnNotFoundOr404; import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404; +import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404; import org.jclouds.googlecomputeengine.binders.HttpHealthCheckCreationBinder; import org.jclouds.googlecomputeengine.domain.HttpHealthCheck; import org.jclouds.googlecomputeengine.domain.ListPage; @@ -55,20 +56,13 @@ import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.Transform; import org.jclouds.rest.binders.BindToJsonPayload; -/** - * Provides access to HttpHealthChecks via their REST API. - */ @SkipEncoding({'/', '='}) @RequestFilters(OAuthAuthenticator.class) -@Consumes(MediaType.APPLICATION_JSON) +@Path("/httpHealthChecks") +@Consumes(APPLICATION_JSON) public interface HttpHealthCheckApi { - /** - * Returns the specified HttpHealthCheck resource. - * - * @param httpHealthCheck the name of the HttpHealthCheck resource to return. - * @return a HttpHealthCheck resource. - */ + /** Returns a health check by name or null if not found. */ @Named("HttpHealthChecks:get") @GET @Path("/{httpHealthCheck}") @@ -86,7 +80,7 @@ public interface HttpHealthCheckApi { */ @Named("HttpHealthChecks:insert") @POST - @Produces(MediaType.APPLICATION_JSON) + @Produces(APPLICATION_JSON) @OAuthScopes(COMPUTE_SCOPE) @MapBinder(BindToJsonPayload.class) Operation insert(@PayloadParam("name") String httpHealthCheckName); @@ -100,18 +94,12 @@ public interface HttpHealthCheckApi { */ @Named("HttpHealthChecks:insert") @POST - @Produces(MediaType.APPLICATION_JSON) + @Produces(APPLICATION_JSON) @OAuthScopes(COMPUTE_SCOPE) @MapBinder(HttpHealthCheckCreationBinder.class) Operation insert(@PayloadParam("name") String name, @PayloadParam("options") HttpHealthCheckCreationOptions options); - /** - * Deletes the specified TargetPool resource. - * - * @param httpHealthCheck name of the persistent forwarding rule 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. - */ + /** Deletes a health check by name and returns the operation in progress, or null if not found. */ @Named("HttpHealthChecks:delete") @DELETE @Path("/{httpHealthCheck}") @@ -121,29 +109,6 @@ public interface HttpHealthCheckApi { Operation delete(@PathParam("httpHealthCheck") String httpHealthCheck); /** - * @return an Iterator that is able to fetch additional pages when required - * @see org.jclouds.collect.PagedIterable - */ - @Named("HttpHealthChecks:list") - @GET - @OAuthScopes(COMPUTE_READONLY_SCOPE) - @ResponseParser(ParseHttpHealthChecks.class) - @Transform(ParseHttpHealthChecks.ToIteratorOfListPage.class) - @Fallback(EmptyIteratorOnNotFoundOr404.class) - Iterator<ListPage<HttpHealthCheck>> list(); - - /** - * @param options @see org.jclouds.googlecomputeengine.options.ListOptions - * @return ListPage - */ - @Named("HttpHealthChecks:list") - @GET - @OAuthScopes(COMPUTE_READONLY_SCOPE) - @ResponseParser(ParseHttpHealthChecks.class) - @Fallback(EmptyListPageOnNotFoundOr404.class) - ListPage<HttpHealthCheck> list(ListOptions options); - - /** * Updates a HttpHealthCheck resource in the specified project * using the data included in the request. This method supports patch semantics. * @@ -173,10 +138,47 @@ public interface HttpHealthCheckApi { @Named("HttpHealthChecks:update") @PUT @Path("/{httpHealthCheck}") - @Produces(MediaType.APPLICATION_JSON) + @Produces(APPLICATION_JSON) @OAuthScopes(COMPUTE_SCOPE) @MapBinder(HttpHealthCheckCreationBinder.class) Operation update(@PathParam("httpHealthCheck") @PayloadParam("name") String name, @PayloadParam("options") HttpHealthCheckCreationOptions options); + /** + * Retrieves the list of persistent http health check 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 token marks the beginning of the next list page + * @param listOptions listing options + * @return a page of the list + */ + @Named("HttpHealthChecks:list") + @GET + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseHttpHealthChecks.class) + @Fallback(EmptyListPageOnNotFoundOr404.class) + ListPage<HttpHealthCheck> listPage(@Nullable @QueryParam("pageToken") String token, ListOptions listOptions); + + /** + * @see #list(org.jclouds.googlecomputeengine.options.ListOptions) + */ + @Named("HttpHealthChecks:list") + @GET + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseHttpHealthChecks.class) + @Transform(ParseHttpHealthChecks.ToIteratorOfListPage.class) + @Fallback(EmptyIteratorOnNotFoundOr404.class) + Iterator<ListPage<HttpHealthCheck>> list(); + + /** + * @see #list(org.jclouds.googlecomputeengine.options.ListOptions) + */ + @Named("HttpHealthChecks:list") + @GET + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseHttpHealthChecks.class) + @Transform(ParseHttpHealthChecks.ToIteratorOfListPage.class) + @Fallback(EmptyIteratorOnNotFoundOr404.class) + Iterator<ListPage<HttpHealthCheck>> list(ListOptions options); }
