Migrate off PaginatedIterable to Iterator. Fix some live test bugs.

This commit is contained in:
Adrian Cole 2014-11-04 11:19:22 -08:00
parent a5ac88f1d7
commit a85dd6e0f9
86 changed files with 776 additions and 1281 deletions

View File

@ -23,9 +23,13 @@ import static com.google.common.primitives.Ints.asList;
import static org.jclouds.Fallbacks.valOnNotFoundOr404;
import static org.jclouds.http.HttpUtils.returnValueOnCodeOrNull;
import java.util.Iterator;
import org.jclouds.Fallback;
import org.jclouds.googlecomputeengine.domain.ListPage;
import com.google.common.collect.Iterators;
public final class GoogleComputeEngineFallbacks {
public static class NullOn400or404 implements Fallback<Object> {
@Override public Object createOrPropagate(Throwable t) throws Exception {
@ -35,9 +39,16 @@ public final class GoogleComputeEngineFallbacks {
throw propagate(t);
}
}
public static final class EmptyListPageOnNotFoundOr404 implements Fallback<Object> {
@Override public ListPage<Object> createOrPropagate(Throwable t) throws Exception {
return valOnNotFoundOr404(ListPage.create(null, null), t);
}
}
public static final class EmptyIteratorOnNotFoundOr404 implements Fallback<Object> {
@Override public Iterator<Object> createOrPropagate(Throwable t) throws Exception {
return valOnNotFoundOr404(Iterators.emptyIterator(), t);
}
}
}

View File

@ -23,6 +23,7 @@ import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_S
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_INTERVAL;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_TIMEOUT;
import static org.jclouds.googlecomputeengine.internal.ListPages.concat;
import static org.jclouds.util.Predicates2.retry;
import java.util.Map;
@ -72,7 +73,6 @@ import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.Atomics;
import com.google.common.util.concurrent.ListeningExecutorService;
@ -151,21 +151,14 @@ public class GoogleComputeEngineService extends BaseComputeService {
protected void cleanUpNetworksAndFirewallsForGroup(final String groupName) {
String resourceName = namingConvention.create().sharedNameForGroup(groupName);
final Network network = api.getNetworkApi(project.get()).get(resourceName);
Network network = api.getNetworkApi(project.get()).get(resourceName);
FirewallApi firewallApi = api.getFirewallApi(project.get());
Predicate<Firewall> firewallBelongsToNetwork = new Predicate<Firewall>() {
@Override
public boolean apply(Firewall input) {
return input != null && input.network().equals(network.selfLink());
for (Firewall firewall : concat(firewallApi.list())) {
if (firewall == null || !firewall.network().equals(network.selfLink())) {
continue;
}
};
Set<AtomicReference<Operation>> operations = Sets.newLinkedHashSet();
for (Firewall firewall : firewallApi.list().concat().filter(firewallBelongsToNetwork)) {
operations.add(new AtomicReference<Operation>(firewallApi.delete(firewall.name())));
}
for (AtomicReference<Operation> operation : operations) {
AtomicReference<Operation> operation = Atomics.newReference(firewallApi.delete(firewall.name()));
retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval,
MILLISECONDS).apply(operation);

View File

@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.Iterables.contains;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Iterables.tryFind;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.CENTOS_PROJECT;
@ -30,16 +31,19 @@ import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.GCE_I
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_INTERVAL;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_TIMEOUT;
import static org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig.Type;
import static org.jclouds.googlecomputeengine.internal.ListPages.concat;
import static org.jclouds.googlecomputeengine.predicates.InstancePredicates.isBootDisk;
import static org.jclouds.util.Predicates2.retry;
import java.net.URI;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject;
import javax.inject.Named;
import org.jclouds.collect.Memoized;
@ -61,6 +65,7 @@ import org.jclouds.googlecomputeengine.domain.Image;
import org.jclouds.googlecomputeengine.domain.Instance;
import org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk;
import org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk.Mode;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.MachineType;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.domain.Zone;
@ -74,13 +79,13 @@ import com.google.common.base.Objects;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.primitives.Ints;
import com.google.common.util.concurrent.Atomics;
import com.google.common.util.concurrent.UncheckedTimeoutException;
import com.google.inject.Inject;
public final class GoogleComputeEngineServiceAdapter implements ComputeServiceAdapter<InstanceInZone, MachineTypeInZone, Image, Zone> {
@ -241,25 +246,25 @@ public final class GoogleComputeEngineServiceAdapter implements ComputeServiceAd
@Override
public Iterable<MachineTypeInZone> listHardwareProfiles() {
ImmutableSet.Builder<MachineTypeInZone> builder = ImmutableSet.builder();
ImmutableList.Builder<MachineTypeInZone> builder = ImmutableList.builder();
for (final Location zone : zones.get().values()) {
builder.addAll(api.getMachineTypeApi(userProject.get())
.listInZone(zone.getId())
.concat()
.filter(new Predicate<MachineType>() {
@Override
public boolean apply(MachineType input) {
return input.deprecated() == null;
}
})
.transform(new Function<MachineType, MachineTypeInZone>() {
for (Iterator<ListPage<MachineType>> i = api.getMachineTypeApi(userProject.get()).listInZone(zone.getId());
i.hasNext(); ) {
builder.addAll(FluentIterable.from(i.next()).filter(new Predicate<MachineType>() {
@Override
public boolean apply(MachineType input) {
return input.deprecated() == null;
}
}).transform(new Function<MachineType, MachineTypeInZone>() {
@Override
public MachineTypeInZone apply(MachineType arg0) {
return new MachineTypeInZone(arg0, arg0.zone());
}
}));
}
@Override
public MachineTypeInZone apply(MachineType arg0) {
return new MachineTypeInZone(arg0, arg0.zone());
}
}));
}
return builder.build();
@ -267,15 +272,14 @@ public final class GoogleComputeEngineServiceAdapter implements ComputeServiceAd
@Override
public Iterable<Image> listImages() {
return ImmutableSet.<Image>builder()
.addAll(api.getImageApi(userProject.get()).list().concat())
.addAll(api.getImageApi(DEBIAN_PROJECT).list().concat())
.addAll(api.getImageApi(CENTOS_PROJECT).list().concat())
.build();
return Iterables.concat( //
concat(api.getImageApi(userProject.get()).list()), //
concat(api.getImageApi(DEBIAN_PROJECT).list()), //
concat(api.getImageApi(CENTOS_PROJECT).list()));
}
@SuppressWarnings("deprecation")
@Override
@Override
public Image getImage(String id) {
return Objects.firstNonNull(api.getImageApi(userProject.get()).get(id),
Objects.firstNonNull(api.getImageApi(DEBIAN_PROJECT).get(id),
@ -285,7 +289,7 @@ public final class GoogleComputeEngineServiceAdapter implements ComputeServiceAd
@Override
public Iterable<Zone> listLocations() {
return api.getZoneApi(userProject.get()).list().concat();
return concat(api.getZoneApi(userProject.get()).list());
}
@Override
@ -300,19 +304,18 @@ public final class GoogleComputeEngineServiceAdapter implements ComputeServiceAd
@Override
public Iterable<InstanceInZone> listNodes() {
return FluentIterable.from(zones.get().values()).transformAndConcat(new Function<Location, ImmutableSet<InstanceInZone>>() {
@Override
public ImmutableSet<InstanceInZone> apply(final Location input) {
return api.getInstanceApi(userProject.get()).listInZone(input.getId()).concat()
.transform(new Function<Instance, InstanceInZone>() {
@Override
public InstanceInZone apply(Instance arg0) {
return new InstanceInZone(arg0, input.getId());
}
}).toSet();
}
}).toSet();
return FluentIterable.from(zones.get().values())
.transformAndConcat(new Function<Location, Iterable<InstanceInZone>>() {
@Override
public Iterable<InstanceInZone> apply(final Location input) {
return transform(concat(api.getInstanceApi(userProject.get()).listInZone(input.getId())),
new Function<Instance, InstanceInZone>() {
@Override public InstanceInZone apply(Instance arg0) {
return new InstanceInZone(arg0, input.getId());
}
});
}
}).toList();
}
@Override

View File

@ -19,6 +19,7 @@ package org.jclouds.googlecomputeengine.compute.config;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Maps.uniqueIndex;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.googlecomputeengine.internal.ListPages.concat;
import java.net.URI;
import java.util.Map;
@ -212,7 +213,7 @@ public class GoogleComputeEngineServiceContextModule
new Supplier<Map<URI, ? extends Location>>() {
@Override
public Map<URI, ? extends Location> get() {
return uniqueIndex(transform(api.getZoneApi(userProject.get()).list().concat(), zoneToLocation),
return uniqueIndex(transform(concat(api.getZoneApi(userProject.get()).list()), zoneToLocation),
new Function<Location, URI>() {
@Override
public URI apply(Location input) {
@ -236,7 +237,7 @@ public class GoogleComputeEngineServiceContextModule
new Supplier<Map<URI, Region>>() {
@Override
public Map<URI, Region> get() {
return uniqueIndex(api.getRegionApi(userProject.get()).list().concat(),
return uniqueIndex(concat(api.getRegionApi(userProject.get()).list()),
new Function<Region, URI>() {
@Override
public URI apply(Region input) {

View File

@ -22,6 +22,7 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_INTERVAL;
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.predicates.NetworkFirewallPredicates.equalsIpPermission;
import static org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicates.providesIpPermission;
import static org.jclouds.util.Predicates2.retry;
@ -102,7 +103,7 @@ public class GoogleComputeEngineSecurityGroupExtension implements SecurityGroupE
@Override
public Set<SecurityGroup> listSecurityGroups() {
return api.getNetworkApi(userProject.get()).list().concat().transform(groupConverter).toSet();
return FluentIterable.from(concat(api.getNetworkApi(userProject.get()).list())).transform(groupConverter).toSet();
}
@Override
@ -172,7 +173,7 @@ public class GoogleComputeEngineSecurityGroupExtension implements SecurityGroupE
ListOptions options = new ListOptions.Builder().filter("network eq .*/" + id);
FluentIterable<Firewall> fws = api.getFirewallApi(userProject.get()).list(options).concat();
FluentIterable<Firewall> fws = FluentIterable.from(concat(api.getFirewallApi(userProject.get()).list(options)));
for (Firewall fw : fws) {
AtomicReference<Operation> operation = Atomics
@ -205,7 +206,8 @@ public class GoogleComputeEngineSecurityGroupExtension implements SecurityGroupE
ListOptions options = new ListOptions.Builder().filter("network eq .*/" + group.getName());
if (api.getFirewallApi(userProject.get()).list(options).concat().anyMatch(providesIpPermission(ipPermission))) {
if (Iterables
.any(concat(api.getFirewallApi(userProject.get()).list(options)), providesIpPermission(ipPermission))) {
// Permission already exists.
return group;
}
@ -267,7 +269,7 @@ public class GoogleComputeEngineSecurityGroupExtension implements SecurityGroupE
ListOptions options = new ListOptions.Builder().filter("network eq .*/" + group.getName());
FluentIterable<Firewall> fws = api.getFirewallApi(userProject.get()).list(options).concat();
FluentIterable<Firewall> fws = FluentIterable.from(concat(api.getFirewallApi(userProject.get()).list(options)));
for (Firewall fw : fws) {
if (equalsIpPermission(ipPermission).apply(fw)) {
@ -328,13 +330,14 @@ public class GoogleComputeEngineSecurityGroupExtension implements SecurityGroupE
private SecurityGroup groupForTagsInNetwork(Network nw, final Collection<String> tags) {
ListOptions opts = new Builder().filter("network eq .*/" + nw.name());
List<Firewall> fws = api.getFirewallApi(userProject.get()).list(opts).concat().filter(new Predicate<Firewall>() {
@Override public boolean apply(final Firewall input) {
// If any of the targetTags on the firewall apply or the firewall has no target tags...
return Iterables.any(input.targetTags(), Predicates.in(tags)) || Predicates.equalTo(0)
.apply(input.targetTags().size());
}
}).toList();
List<Firewall> fws = FluentIterable.from(concat(api.getFirewallApi(userProject.get()).list(opts)))
.filter(new Predicate<Firewall>() {
@Override public boolean apply(final Firewall input) {
// If any of the targetTags on the firewall apply or the firewall has no target tags...
return Iterables.any(input.targetTags(), Predicates.in(tags)) || Predicates.equalTo(0)
.apply(input.targetTags().size());
}
}).toList();
if (fws.isEmpty()) {
return null;

View File

@ -16,6 +16,8 @@
*/
package org.jclouds.googlecomputeengine.compute.functions;
import static org.jclouds.googlecomputeengine.internal.ListPages.concat;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
@ -70,7 +72,7 @@ public class NetworkToSecurityGroup implements Function<Network, SecurityGroup>
ListOptions options = new ListOptions.Builder().filter("network eq .*/" + network.name());
for (Firewall fw : api.getFirewallApi(project.get()).list(options).concat()) {
for (Firewall fw : concat(api.getFirewallApi(project.get()).list(options))) {
permBuilder.addAll(firewallToPerms.apply(fw));
}

View File

@ -19,6 +19,8 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import java.util.Iterator;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@ -30,9 +32,8 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.domain.Address;
import org.jclouds.googlecomputeengine.domain.ListPage;
@ -65,7 +66,7 @@ public interface AddressApi {
* @param addressName name of the address resource to return.
* @return a Address resource.
*/
@Named("Addresss:get")
@Named("Addresses:get")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Path("/regions/{region}/addresses/{address}")
@ -83,7 +84,7 @@ public interface AddressApi {
* @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("Addresss:insert")
@Named("Addresses:insert")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ -100,7 +101,7 @@ public interface AddressApi {
* @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("Addresss:delete")
@Named("Addresses:delete")
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Path("/regions/{region}/addresses/{address}")
@ -109,30 +110,6 @@ public interface AddressApi {
@Nullable
Operation deleteInRegion(@PathParam("region") String region, @PathParam("address") String addressName);
/**
* @see org.jclouds.googlecomputeengine.features.AddressApi#listAtMarkerInRegion(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Addresss:list")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Path("/regions/{region}/addresses")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseAddresses.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Address> listFirstPageInRegion(@PathParam("region") String region);
/**
* @see org.jclouds.googlecomputeengine.features.AddressApi#listAtMarkerInRegion(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Addresss: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);
/**
* 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
@ -145,7 +122,7 @@ public interface AddressApi {
* @see org.jclouds.googlecomputeengine.options.ListOptions
* @see org.jclouds.googlecomputeengine.domain.ListPage
*/
@Named("Addresss:list")
@Named("Addresses:list")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Path("/regions/{region}/addresses")
@ -158,27 +135,26 @@ public interface AddressApi {
* A paged version of AddressApi#listPageInRegion(String)
*
* @param region the region to list in
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required
* @see org.jclouds.collect.PagedIterable
* @see org.jclouds.googlecomputeengine.features.AddressApi#listAtMarkerInRegion(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
* @return an Iterator that is able to fetch additional pages when required
* @see #listAtMarkerInRegion(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Addresss:list")
@Named("Addresses:list")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Path("/regions/{region}/addresses")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseAddresses.class)
@Transform(ParseAddresses.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Address> listInRegion(@PathParam("region") String region);
@Transform(ParseAddresses.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Address>> listInRegion(@PathParam("region") String region);
@Named("Addresss:list")
@Named("Addresses:list")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Path("/regions/{region}/addresses")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseAddresses.class)
@Transform(ParseAddresses.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Address> listInRegion(@PathParam("region") String region, ListOptions options);
@Transform(ParseAddresses.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Address>> listInRegion(@PathParam("region") String region, ListOptions options);
}

View File

@ -19,6 +19,8 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import java.util.Iterator;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@ -30,9 +32,8 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.binders.DiskCreationBinder;
import org.jclouds.googlecomputeengine.domain.Disk;
@ -103,7 +104,7 @@ public interface DiskApi {
* @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 diskCreationOption the options of the disk to create.
* @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.
*/
@ -117,7 +118,7 @@ public interface DiskApi {
Operation createInZone(@PayloadParam("name") String diskName,
@PayloadParam("sizeGb") int sizeGb,
@PathParam("zone") String zone,
@PayloadParam("options") DiskCreationOptions diskCreationOptions);
@PayloadParam("options") DiskCreationOptions options);
/**
* Deletes the specified persistent disk resource.
@ -136,30 +137,6 @@ public interface DiskApi {
@Nullable
Operation deleteInZone(@PathParam("zone") String zone, @PathParam("disk") String diskName);
/**
* @see DiskApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Disks:list")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Path("/zones/{zone}/disks")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseDisks.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Disk> listFirstPageInZone(@PathParam("zone") String zone);
/**
* @see DiskApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@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);
/**
* 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
@ -185,8 +162,7 @@ public interface DiskApi {
* A paged version of DiskApi#listPageInZone(String)
*
* @param zone the zone to list in
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required
* @see PagedIterable
* @return an Iterator that is able to fetch additional pages when required
* @see DiskApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Disks:list")
@ -195,9 +171,9 @@ public interface DiskApi {
@Path("/zones/{zone}/disks")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseDisks.class)
@Transform(ParseDisks.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Disk> listInZone(@PathParam("zone") String zone);
@Transform(ParseDisks.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Disk>> listInZone(@PathParam("zone") String zone);
@Named("Disks:list")
@GET
@ -205,9 +181,9 @@ public interface DiskApi {
@Path("/zones/{zone}/disks")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseDisks.class)
@Transform(ParseDisks.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Disk> listInZone(@PathParam("zone") String zone, ListOptions options);
@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.

View File

@ -18,6 +18,8 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import java.util.Iterator;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
@ -26,9 +28,8 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.domain.DiskType;
import org.jclouds.googlecomputeengine.domain.ListPage;
@ -65,29 +66,7 @@ public interface DiskTypeApi {
@Path("/zones/{zone}/diskTypes/{diskType}")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
DiskType getInZone(@PathParam("zone") String zone, @PathParam("diskType") String diskTypeName);
/**
* @see DiskTypeApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("DiskTypes:list")
@GET
@Path("/zones/{zone}/diskTypes")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseDiskTypes.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<DiskType> listFirstPageInZone(@PathParam("zone") String zone);
/**
* @see DiskTypeApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("DiskTypes:list")
@GET
@Path("/zones/{zone}/diskType")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseDiskTypes.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<DiskType> listAtMarkerInZone(@PathParam("zone") String zone, @QueryParam("pageToken") @Nullable String marker);
DiskType getInZone(@PathParam("zone") String zone, @PathParam("diskType") String diskType);
/**
* Retrieves the list of disk type resources available to the specified project.
@ -119,24 +98,22 @@ public interface DiskTypeApi {
@Path("/zones/{zone}/diskTypes")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseDiskTypes.class)
@Transform(ParseDiskTypes.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<DiskType> listInZone(@PathParam("zone") String zone);
@Transform(ParseDiskTypes.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<DiskType>> listInZone(@PathParam("zone") String zone);
/**
* @see DiskTypeApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*
* @param zone the zone to list in
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required
* @see PagedIterable
* @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.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<DiskType> listInZone(@PathParam("zone") String zone, ListOptions listOptions);
@Transform(ParseDiskTypes.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<DiskType>> listInZone(@PathParam("zone") String zone, ListOptions listOptions);
}

View File

@ -20,6 +20,7 @@ import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPU
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import java.net.URI;
import java.util.Iterator;
import javax.inject.Named;
import javax.ws.rs.Consumes;
@ -33,9 +34,8 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.binders.FirewallBinder;
import org.jclouds.googlecomputeengine.domain.Firewall;
@ -148,37 +148,13 @@ public interface FirewallApi {
@Fallback(NullOnNotFoundOr404.class)
Operation delete(@PathParam("firewall") String firewallName);
/**
* @see FirewallApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Firewalls:list")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Path("/global/firewalls")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseFirewalls.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Firewall> listFirstPage();
/**
* @see FirewallApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@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);
/**
* 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 listOptions listing options
* @param marker marks the beginning of the next list page
* @param options listing options
* @return a page of the list
* @see ListOptions
* @see org.jclouds.googlecomputeengine.domain.ListPage
@ -201,15 +177,14 @@ public interface FirewallApi {
@Path("/global/firewalls")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseFirewalls.class)
@Transform(ParseFirewalls.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Firewall> list();
@Transform(ParseFirewalls.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Firewall>> list();
/**
* A paged version of FirewallApi#list()
*
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required
* @see PagedIterable
* @return an Iterator that is able to fetch additional pages when required
* @see FirewallApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Firewalls:list")
@ -218,7 +193,7 @@ public interface FirewallApi {
@Path("/global/firewalls")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseFirewalls.class)
@Transform(ParseFirewalls.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Firewall> list(ListOptions options);
@Transform(ParseFirewalls.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Firewall>> list(ListOptions options);
}

View File

@ -20,6 +20,7 @@ import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPU
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import java.net.URI;
import java.util.Iterator;
import javax.inject.Named;
import javax.ws.rs.Consumes;
@ -31,9 +32,8 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.binders.ForwardingRuleCreationBinder;
import org.jclouds.googlecomputeengine.domain.ForwardingRule;
@ -80,8 +80,6 @@ public interface ForwardingRuleApi {
* Creates a ForwardingRule resource in the specified project and region using the data included in the request.
*
* @param forwardingRuleName the name of the forwarding rule.
* @param targetSelfLink the URL of the target resource to receive the matched traffic. The target resource must live
* in the same region as this forwarding rule.
* @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.
*/
@ -110,9 +108,8 @@ public interface ForwardingRuleApi {
@Nullable
Operation delete(@PathParam("forwardingRule") String forwardingRule);
/**
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required
* @return an Iterator that is able to fetch additional pages when required
* @see org.jclouds.collect.PagedIterable
*/
@Named("ForwardingRules:list")
@ -120,9 +117,9 @@ public interface ForwardingRuleApi {
@Path("/forwardingRules")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseForwardingRules.class)
@Transform(ParseForwardingRules.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<ForwardingRule> list();
@Transform(ParseForwardingRules.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<ForwardingRule>> list();
@Named("ForwardingRules:list")
@GET

View File

@ -19,6 +19,8 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import java.util.Iterator;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@ -28,9 +30,8 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
@ -78,30 +79,6 @@ public interface GlobalOperationApi {
@Fallback(NullOnNotFoundOr404.class)
void delete(@PathParam("operation") String operationName);
/**
* @see org.jclouds.googlecomputeengine.features.GlobalOperationApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("GlobalOperations:list")
@GET
@Path("/global/operations")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseGlobalOperations.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Operation> listFirstPage();
/**
* @see org.jclouds.googlecomputeengine.features.GlobalOperationApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@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);
/**
* 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()
@ -110,8 +87,6 @@ public interface GlobalOperationApi {
* @param marker marks the beginning of the next list page
* @param listOptions listing options
* @return a page of the list, starting at marker
* @see org.jclouds.googlecomputeengine.options.ListOptions
* @see org.jclouds.googlecomputeengine.domain.ListPage
*/
@Named("GlobalOperations:list")
@GET
@ -120,11 +95,10 @@ public interface GlobalOperationApi {
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseGlobalOperations.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Operation> listAtMarker(@QueryParam("pageToken") @Nullable String marker,
ListOptions listOptions);
ListPage<Operation> listAtMarker(@QueryParam("pageToken") @Nullable String marker, ListOptions listOptions);
/**
* @see org.jclouds.googlecomputeengine.features.GlobalOperationApi#list(org.jclouds.googlecomputeengine.options.ListOptions)
* @see GlobalOperationApi#list(org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("GlobalOperations:list")
@GET
@ -132,16 +106,15 @@ public interface GlobalOperationApi {
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseGlobalOperations.class)
@Transform(ParseGlobalOperations.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Operation> list();
@Transform(ParseGlobalOperations.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Operation>> list();
/**
* A paged version of GlobalOperationApi#listFirstPage()
*
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required
* @see org.jclouds.collect.PagedIterable
* @see org.jclouds.googlecomputeengine.features.GlobalOperationApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
* @return an Iterator that is able to fetch additional pages when required
* @see GlobalOperationApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("GlobalOperations:list")
@GET
@ -149,8 +122,7 @@ public interface GlobalOperationApi {
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseGlobalOperations.class)
@Transform(ParseGlobalOperations.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Operation> list(ListOptions listOptions);
@Transform(ParseGlobalOperations.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Operation>> list(ListOptions listOptions);
}

View File

@ -20,6 +20,8 @@ import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPU
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import java.util.Iterator;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@ -31,9 +33,8 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404;
import org.jclouds.googlecomputeengine.binders.HttpHealthCheckCreationBinder;
import org.jclouds.googlecomputeengine.domain.HttpHealthCheck;
import org.jclouds.googlecomputeengine.domain.ListPage;
@ -120,16 +121,16 @@ public interface HttpHealthCheckApi {
Operation delete(@PathParam("httpHealthCheck") String httpHealthCheck);
/**
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required
* @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.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<HttpHealthCheck> list();
@Transform(ParseHttpHealthChecks.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<HttpHealthCheck>> list();
/**
* @param options @see org.jclouds.googlecomputeengine.options.ListOptions

View File

@ -19,6 +19,8 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import java.util.Iterator;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@ -30,9 +32,8 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.domain.Image;
import org.jclouds.googlecomputeengine.domain.ListPage;
@ -88,30 +89,6 @@ public interface ImageApi {
@Nullable
Operation delete(@PathParam("image") String imageName);
/**
* @see ImageApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Images:list")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Path("/global/images")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseImages.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Image> listFirstPage();
/**
* @see ImageApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Images:list")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Path("/global/images")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseImages.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Image> listAtMarker(@QueryParam("pageToken") @Nullable String marker);
/**
* Retrieves the list of image 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
@ -135,8 +112,7 @@ public interface ImageApi {
/**
* A paged version of ImageApi#list()
*
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required
* @see PagedIterable
* @return an Iterator that is able to fetch additional pages when required
* @see ImageApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Images:list")
@ -145,15 +121,14 @@ public interface ImageApi {
@Path("/global/images")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseImages.class)
@Transform(ParseImages.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Image> list();
@Transform(ParseImages.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Image>> list();
/**
* A paged version of ImageApi#list()
*
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required
* @see PagedIterable
* @return an Iterator that is able to fetch additional pages when required
* @see ImageApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Images:list")
@ -162,9 +137,9 @@ public interface ImageApi {
@Path("/global/images")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseImages.class)
@Transform(ParseImages.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Image> list(ListOptions options);
@Transform(ParseImages.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Image>> list(ListOptions options);
/**
* Creates an image resource in the specified project from the provided persistent disk.
@ -182,5 +157,4 @@ public interface ImageApi {
@OAuthScopes(COMPUTE_SCOPE)
@MapBinder(BindToJsonPayload.class)
Operation createImageFromPD(@PayloadParam("name") String imageName, @PayloadParam("sourceDisk") String sourceDisk);
}

View File

@ -19,6 +19,7 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import java.util.Iterator;
import java.util.Map;
import javax.inject.Named;
@ -32,9 +33,8 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.binders.InstanceBinder;
import org.jclouds.googlecomputeengine.binders.MetadataBinder;
@ -120,23 +120,6 @@ public interface InstanceApi {
@Nullable
Operation deleteInZone(@PathParam("zone") String zone, @PathParam("instance") String instanceName);
/**
* A paged version of InstanceApi#listInZone()
*
* @param zone zone instances are in
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required
* @see PagedIterable
* @see InstanceApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Instances:list")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Path("/zones/{zone}/instances")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseInstances.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Instance> listFirstPageInZone(@PathParam("zone") String zone);
/**
* 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
@ -160,7 +143,7 @@ public interface InstanceApi {
ListOptions listOptions);
/**
* @see InstanceApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
* @see InstanceApi#listInZone(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Instances:list")
@GET
@ -168,9 +151,9 @@ public interface InstanceApi {
@Path("/zones/{zone}/instances")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseInstances.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Instance> listAtMarkerInZone(@PathParam("zone") String zone,
@Nullable String marker);
@Transform(ParseInstances.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Instance>> listInZone(@PathParam("zone") String zone);
/**
* @see InstanceApi#listInZone(String, org.jclouds.googlecomputeengine.options.ListOptions)
@ -181,22 +164,9 @@ public interface InstanceApi {
@Path("/zones/{zone}/instances")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseInstances.class)
@Transform(ParseInstances.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Instance> listInZone(@PathParam("zone") String zone);
/**
* @see InstanceApi#listInZone(String, 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.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Instance> listInZone(@PathParam("zone") String zone, ListOptions options);
@Transform(ParseInstances.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Instance>> listInZone(@PathParam("zone") String zone, ListOptions options);
/**
* Adds an access config to an instance's network interface.

View File

@ -18,6 +18,8 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import java.util.Iterator;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
@ -26,9 +28,8 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.MachineType;
@ -65,28 +66,6 @@ public interface MachineTypeApi {
@Fallback(NullOnNotFoundOr404.class)
MachineType getInZone(@PathParam("zone") String zone, @PathParam("machineType") String machineTypeName);
/**
* @see MachineTypeApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("MachineTypes:list")
@GET
@Path("/zones/{zone}/machineTypes")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseMachineTypes.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<MachineType> listFirstPageInZone(@PathParam("zone") String zone);
/**
* @see MachineTypeApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("MachineTypes:list")
@GET
@Path("/zones/{zone}/machineTypes")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseMachineTypes.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<MachineType> listAtMarkerInZone(@PathParam("zone") String zone, @QueryParam("pageToken") @Nullable String marker);
/**
* Retrieves the list of machine 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
@ -117,16 +96,15 @@ public interface MachineTypeApi {
@Path("/zones/{zone}/machineTypes")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseMachineTypes.class)
@Transform(ParseMachineTypes.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<MachineType> listInZone(@PathParam("zone") String zone);
@Transform(ParseMachineTypes.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<MachineType>> listInZone(@PathParam("zone") String zone);
/**
* A paged version of MachineTypeApi#listInZone(String)
*
* @param zone the zone to list in
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required
* @see PagedIterable
* @return an Iterator that is able to fetch additional pages when required
* @see MachineTypeApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("MachineTypes:list")
@ -134,8 +112,8 @@ public interface MachineTypeApi {
@Path("/zones/{zone}/machineTypes")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseMachineTypes.class)
@Transform(ParseMachineTypes.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<MachineType> listInZone(@PathParam("zone") String zone, ListOptions listOptions);
@Transform(ParseMachineTypes.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<MachineType>> listInZone(@PathParam("zone") String zone, ListOptions listOptions);
}

View File

@ -19,6 +19,8 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import java.util.Iterator;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@ -30,9 +32,8 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Network;
@ -125,40 +126,15 @@ public interface NetworkApi {
@Fallback(NullOnNotFoundOr404.class)
Operation delete(@PathParam("network") String networkName);
/**
* @see NetworkApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Networks:list")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Path("/global/networks")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseNetworks.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Network> listFirstPage();
/**
* @see NetworkApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Networks:list")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Path("/global/networks")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseNetworks.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Network> listAtMarker(@QueryParam("pageToken") @Nullable String marker);
/**
* Retrieves the list of persistent network resources contained within 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 listOptions listing options
* @param options listing options
* @return a page of the list
* @see ListOptions
* @see org.jclouds.googlecomputeengine.domain.ListPage
*/
@Named("Networks:list")
@GET
@ -167,8 +143,7 @@ public interface NetworkApi {
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseNetworks.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Network> listAtMarker(@QueryParam("pageToken") @Nullable String marker,
ListOptions options);
ListPage<Network> listAtMarker(@QueryParam("pageToken") @Nullable String marker, ListOptions options);
/**
* @see NetworkApi#list(org.jclouds.googlecomputeengine.options.ListOptions)
@ -179,15 +154,14 @@ public interface NetworkApi {
@Path("/global/networks")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseNetworks.class)
@Transform(ParseNetworks.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Network> list();
@Transform(ParseNetworks.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Network>> list();
/**
* A paged version of NetworkApi#list()
*
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required
* @see PagedIterable
* @return an Iterator that is able to fetch additional pages when required
* @see NetworkApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Networks:list")
@ -196,7 +170,7 @@ public interface NetworkApi {
@Path("/global/networks")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseNetworks.class)
@Transform(ParseNetworks.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Network> list(ListOptions options);
@Transform(ParseNetworks.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Network>> list(ListOptions options);
}

View File

@ -18,6 +18,8 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import java.util.Iterator;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
@ -25,9 +27,8 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Region;
@ -62,28 +63,6 @@ public interface RegionApi {
@Fallback(NullOnNotFoundOr404.class)
Region get(@PathParam("region") String regionName);
/**
* @see org.jclouds.googlecomputeengine.features.RegionApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Regions:list")
@GET
@Path("/regions")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseRegions.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Region> listFirstPage();
/**
* @see org.jclouds.googlecomputeengine.features.RegionApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Regions:list")
@GET
@Path("/regions")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseRegions.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Region> listAtMarker(String marker);
/**
* Retrieves the listFirstPage of region resources available to the specified project.
* By default the listFirstPage as a maximum size of 100, if no options are provided or ListOptions#getMaxResults()
@ -91,9 +70,6 @@ public interface RegionApi {
*
* @param marker marks the beginning of the next list page
* @param listOptions listing options
* @return a page of the listFirstPage
* @see org.jclouds.googlecomputeengine.options.ListOptions
* @see org.jclouds.googlecomputeengine.domain.ListPage
*/
@Named("Regions:list")
@GET
@ -104,30 +80,29 @@ public interface RegionApi {
ListPage<Region> listAtMarker(String marker, ListOptions listOptions);
/**
* @see org.jclouds.googlecomputeengine.features.RegionApi#list(org.jclouds.googlecomputeengine.options.ListOptions)
* @see RegionApi#list(org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Regions:list")
@GET
@Path("/regions")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseRegions.class)
@Transform(ParseRegions.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Region> list();
@Transform(ParseRegions.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Region>> list();
/**
* A paged version of RegionApi#listFirstPage()
*
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required
* @see org.jclouds.googlecomputeengine.features.RegionApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
* @see org.jclouds.collect.PagedIterable
* @return an Iterator that is able to fetch additional pages when required
* @see RegionApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Regions:list")
@GET
@Path("/regions")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseRegions.class)
@Transform(ParseRegions.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Region> list(ListOptions listOptions);
@Transform(ParseRegions.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Region>> list(ListOptions listOptions);
}

View File

@ -19,6 +19,8 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import java.util.Iterator;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@ -28,9 +30,8 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
@ -80,31 +81,6 @@ public interface RegionOperationApi {
@Fallback(NullOnNotFoundOr404.class)
void deleteInRegion(@PathParam("region") String region, @PathParam("operation") String operationName);
/**
* @see org.jclouds.googlecomputeengine.features.RegionOperationApi#listAtMarkerInRegion(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("RegionOperations:list")
@GET
@Path("/regions/{region}/operations")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseRegionOperations.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Operation> listFirstPageInRegion(@PathParam("region") String region);
/**
* @see org.jclouds.googlecomputeengine.features.RegionOperationApi#listAtMarkerInRegion(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("RegionOperations:list")
@GET
@Path("/regions/{region}/operations")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseRegionOperations.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Operation> listAtMarkerInRegion(@PathParam("region") String region,
@QueryParam("pageToken") @Nullable String marker);
/**
* 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()
@ -129,7 +105,7 @@ public interface RegionOperationApi {
ListOptions listOptions);
/**
* @see org.jclouds.googlecomputeengine.features.RegionOperationApi#listInRegion(String, org.jclouds.googlecomputeengine.options.ListOptions)
* @see RegionOperationApi#listInRegion(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("RegionOperations:list")
@GET
@ -137,16 +113,16 @@ public interface RegionOperationApi {
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseRegionOperations.class)
@Transform(ParseRegionOperations.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Operation> listInRegion(@PathParam("region") String region);
@Transform(ParseRegionOperations.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Operation>> listInRegion(@PathParam("region") String region);
/**
* A paged version of RegionOperationApi#listFirstPage(String)
*
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required
* @return an Iterator that is able to fetch additional pages when required
* @see org.jclouds.collect.PagedIterable
* @see org.jclouds.googlecomputeengine.features.RegionOperationApi#listAtMarkerInRegion(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
* @see RegionOperationApi#listAtMarkerInRegion(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("RegionOperations:list")
@GET
@ -154,8 +130,7 @@ public interface RegionOperationApi {
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseRegionOperations.class)
@Transform(ParseRegionOperations.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Operation> listInRegion(@PathParam("region") String region, ListOptions listOptions);
@Transform(ParseRegionOperations.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Operation>> listInRegion(@PathParam("region") String region, ListOptions listOptions);
}

View File

@ -20,6 +20,7 @@ import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPU
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import java.net.URI;
import java.util.Iterator;
import javax.inject.Named;
import javax.ws.rs.Consumes;
@ -31,9 +32,8 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.binders.RouteBinder;
import org.jclouds.googlecomputeengine.domain.ListPage;
@ -74,28 +74,6 @@ public interface RouteApi {
@Fallback(NullOnNotFoundOr404.class)
Route get(@PathParam("route") String routeName);
/**
* @see org.jclouds.googlecomputeengine.features.RouteApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Routes:list")
@GET
@Path("/global/routes")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseRoutes.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Route> listFirstPage();
/**
* @see org.jclouds.googlecomputeengine.features.RouteApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Routes:list")
@GET
@Path("/global/routes")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseRoutes.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Route> listAtMarker(String marker);
/**
* Retrieves the listFirstPage of route resources available to the specified project.
* By default the listFirstPage as a maximum size of 100, if no options are provided or ListOptions#getMaxResults()
@ -116,22 +94,22 @@ public interface RouteApi {
ListPage<Route> listAtMarker(String marker, ListOptions listOptions);
/**
* @see org.jclouds.googlecomputeengine.features.RouteApi#list(org.jclouds.googlecomputeengine.options.ListOptions)
* @see RouteApi#list(org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Routes:list")
@GET
@Path("/global/routes")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseRoutes.class)
@Transform(ParseRoutes.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Route> list();
@Transform(ParseRoutes.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Route>> list();
/**
* A paged version of RegionApi#listFirstPage()
*
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required
* @see org.jclouds.googlecomputeengine.features.RouteApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
* @return an Iterator that is able to fetch additional pages when required
* @see RouteApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
* @see org.jclouds.collect.PagedIterable
*/
@Named("Routes:list")
@ -139,9 +117,9 @@ public interface RouteApi {
@Path("/global/routes")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseRoutes.class)
@Transform(ParseRoutes.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Route> list(ListOptions listOptions);
@Transform(ParseRoutes.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Route>> list(ListOptions listOptions);
/**
* Deletes the specified route resource.

View File

@ -19,6 +19,8 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import java.util.Iterator;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@ -28,9 +30,8 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
@ -84,30 +85,6 @@ public interface SnapshotApi {
@Nullable
Operation delete(@PathParam("snapshot") String snapshotName);
/**
* @see org.jclouds.googlecomputeengine.features.SnapshotApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Snapshots:list")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Path("/global/snapshots")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseSnapshots.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Snapshot> listFirstPage();
/**
* @see org.jclouds.googlecomputeengine.features.SnapshotApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Snapshots:list")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Path("/global/snapshots")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseSnapshots.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Snapshot> listAtMarker(@QueryParam("pageToken") @Nullable String marker);
/**
* 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
@ -115,9 +92,6 @@ public interface SnapshotApi {
*
* @param marker 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
*/
@Named("Snapshots:list")
@GET
@ -131,9 +105,7 @@ public interface SnapshotApi {
/**
* A paged version of SnapshotApi#listPage(String)
*
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required
* @see org.jclouds.collect.PagedIterable
* @see org.jclouds.googlecomputeengine.features.SnapshotApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
* @return an Iterator that is able to fetch additional pages when required
*/
@Named("Snapshots:list")
@GET
@ -141,9 +113,9 @@ public interface SnapshotApi {
@Path("/global/snapshots")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseSnapshots.class)
@Transform(ParseSnapshots.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Snapshot> list();
@Transform(ParseSnapshots.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Snapshot>> list();
@Named("Snapshots:list")
@GET
@ -151,8 +123,7 @@ public interface SnapshotApi {
@Path("/global/snapshots")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseSnapshots.class)
@Transform(ParseSnapshots.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Snapshot> list(ListOptions options);
@Transform(ParseSnapshots.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Snapshot>> list(ListOptions options);
}

View File

@ -20,6 +20,7 @@ import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPU
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import java.net.URI;
import java.util.Iterator;
import java.util.List;
import javax.inject.Named;
@ -33,9 +34,8 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.binders.TargetPoolChangeHealthChecksBinder;
import org.jclouds.googlecomputeengine.binders.TargetPoolChangeInstancesBinder;
@ -112,7 +112,7 @@ public interface TargetPoolApi {
Operation delete(@PathParam("targetPool") String targetPool);
/**
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required
* @return an Iterator that is able to fetch additional pages when required
* @see org.jclouds.collect.PagedIterable
*/
@Named("TargetPools:list")
@ -120,9 +120,9 @@ public interface TargetPoolApi {
@Path("/targetPools")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseTargetPools.class)
@Transform(ParseTargetPools.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<TargetPool> list();
@Transform(ParseTargetPools.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<TargetPool>> list();
/**
* @param options @see org.jclouds.googlecomputeengine.options.ListOptions
@ -140,7 +140,7 @@ public interface TargetPoolApi {
* Adds instance to the targetPool.
*
* @param targetPool the name of the target pool.
* @param instanceName the name for the instance to be added to targetPool.
* @param instances the self-links of the instances to be added to targetPool.
*
* @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.
@ -157,7 +157,7 @@ public interface TargetPoolApi {
* Removes instance URL from targetPool.
*
* @param targetPool the name of the target pool.
* @param instanceName the name for the instance to be removed from targetPool.
* @param instances the self-links of the instances to be removed from the targetPool.
*
* @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.
@ -174,7 +174,7 @@ public interface TargetPoolApi {
* Adds health check URL to targetPool.
*
* @param targetPool the name of the target pool.
* @param healthCheck the name for the healthCheck to be added to targetPool.
* @param healthChecks the self-links of the health checks to be added to targetPool.
*
* @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.
@ -192,7 +192,7 @@ public interface TargetPoolApi {
* Removes health check URL from targetPool.
*
* @param targetPool the name of the target pool.
* @param the name for the instance to be removed from targetPool.
* @param healthChecks the self-links of the health checks to be removed from the targetPool.
*
* @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.

View File

@ -18,6 +18,8 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import java.util.Iterator;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
@ -25,9 +27,8 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Zone;
@ -62,28 +63,6 @@ public interface ZoneApi {
@Fallback(NullOnNotFoundOr404.class)
Zone get(@PathParam("zone") String zoneName);
/**
* @see ZoneApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Zones:list")
@GET
@Path("/zones")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseZones.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Zone> listFirstPage();
/**
* @see ZoneApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("Zones:list")
@GET
@Path("/zones")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseZones.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Zone> listAtMarker(String marker);
/**
* Retrieves the listFirstPage of zone resources available to the specified project.
* By default the listFirstPage as a maximum size of 100, if no options are provided or ListOptions#getMaxResults()
@ -91,9 +70,6 @@ public interface ZoneApi {
*
* @param marker marks the beginning of the next list page
* @param listOptions listing options
* @return a page of the listFirstPage
* @see ListOptions
* @see ListPage
*/
@Named("Zones:list")
@GET
@ -111,23 +87,22 @@ public interface ZoneApi {
@Path("/zones")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseZones.class)
@Transform(ParseZones.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Zone> list();
@Transform(ParseZones.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Zone>> list();
/**
* A paged version of ZoneApi#listFirstPage()
*
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required
* @return an Iterator that is able to fetch additional pages when required
* @see ZoneApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
* @see PagedIterable
*/
@Named("Zones:list")
@GET
@Path("/zones")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseZones.class)
@Transform(ParseZones.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Zone> list(ListOptions listOptions);
@Transform(ParseZones.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Zone>> list(ListOptions listOptions);
}

View File

@ -19,6 +19,8 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import java.util.Iterator;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@ -28,9 +30,8 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404;
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
@ -80,31 +81,6 @@ public interface ZoneOperationApi {
@Fallback(NullOnNotFoundOr404.class)
void deleteInZone(@PathParam("zone") String zone, @PathParam("operation") String operationName);
/**
* @see ZoneOperationApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("ZoneOperations:list")
@GET
@Path("/zones/{zone}/operations")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseZoneOperations.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Operation> listFirstPageInZone(@PathParam("zone") String zone);
/**
* @see ZoneOperationApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("ZoneOperations:list")
@GET
@Path("/zones/{zone}/operations")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseZoneOperations.class)
@Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Operation> listAtMarkerInZone(@PathParam("zone") String zone,
@QueryParam("pageToken") @Nullable String marker);
/**
* 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()
@ -114,8 +90,6 @@ public interface ZoneOperationApi {
* @param marker marks the beginning of the next list page
* @param listOptions listing options
* @return a page of the list, starting at marker
* @see ListOptions
* @see org.jclouds.googlecomputeengine.domain.ListPage
*/
@Named("ZoneOperations:list")
@GET
@ -137,15 +111,14 @@ public interface ZoneOperationApi {
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseZoneOperations.class)
@Transform(ParseZoneOperations.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Operation> listInZone(@PathParam("zone") String zone);
@Transform(ParseZoneOperations.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Operation>> listInZone(@PathParam("zone") String zone);
/**
* A paged version of ZoneOperationApi#listFirstPageInZone(String)
*
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required
* @see PagedIterable
* @return an Iterator that is able to fetch additional pages when required
* @see ZoneOperationApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("ZoneOperations:list")
@ -154,8 +127,7 @@ public interface ZoneOperationApi {
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseZoneOperations.class)
@Transform(ParseZoneOperations.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Operation> listInZone(@PathParam("zone") String zone, ListOptions listOptions);
@Transform(ParseZoneOperations.ToIteratorOfListPage.class)
@Fallback(EmptyIteratorOnNotFoundOr404.class)
Iterator<ListPage<Operation>> listInZone(@PathParam("zone") String zone, ListOptions listOptions);
}

View File

@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.functions.internal;
import org.jclouds.googlecomputeengine.domain.ListPage;
import com.google.common.base.Function;
import com.google.common.collect.AbstractIterator;
final class AdvancingIterator<T> extends AbstractIterator<ListPage<T>> {
private final Function<String, ListPage<T>> tokenToNext;
private ListPage<T> current;
private boolean unread = true;
AdvancingIterator(ListPage<T> initial, Function<String, ListPage<T>> tokenToNext) {
this.current = initial;
this.tokenToNext = tokenToNext;
}
@Override protected ListPage<T> computeNext() {
if (unread) {
try {
return current;
} finally {
unread = false;
}
} else if (current.nextPageToken() != null) {
return current = tokenToNext.apply(current.nextPageToken());
} else {
return endOfData();
}
}
}

View File

@ -19,10 +19,8 @@ package org.jclouds.googlecomputeengine.functions.internal;
import static com.google.common.base.Predicates.instanceOf;
import static com.google.common.collect.Iterables.tryFind;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.collect.PagedIterable;
import org.jclouds.collect.PagedIterables;
import java.util.Iterator;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.http.HttpRequest;
@ -32,17 +30,18 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.common.annotations.Beta;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.collect.Iterators;
@Beta
public abstract class BaseToPagedIterable<T, I extends BaseToPagedIterable<T, I>> implements
Function<ListPage<T>, PagedIterable<T>>, InvocationContext<I> {
public abstract class BaseToIteratorOfListPage<T, I extends BaseToIteratorOfListPage<T, I>>
implements Function<ListPage<T>, Iterator<ListPage<T>>>, InvocationContext<I> {
private GeneratedHttpRequest request;
@Override
public PagedIterable<T> apply(ListPage<T> input) {
public Iterator<ListPage<T>> apply(ListPage<T> input) {
if (input.nextPageToken() == null) {
return PagedIterables.onlyPage(IterableWithMarkers.from(input));
return Iterators.singletonIterator(input);
}
Optional<Object> project = tryFind(request.getCaller().get().getArgs(), instanceOf(String.class));
@ -53,12 +52,11 @@ public abstract class BaseToPagedIterable<T, I extends BaseToPagedIterable<T, I>
String.format("programming error, method %s should have a string param for the " + "project",
request.getCaller().get().getInvokable());
return PagedIterables.advance(IterableWithMarkers.from(input, input.nextPageToken()),
return new AdvancingIterator<T>(input,
fetchNextPage(project.get().toString(), (ListOptions) listOptions.orNull()));
}
protected abstract Function<Object, IterableWithMarker<T>> fetchNextPage(String projectName,
ListOptions listOptions);
protected abstract Function<String, ListPage<T>> fetchNextPage(String projectName, ListOptions listOptions);
@SuppressWarnings("unchecked")
@Override

View File

@ -19,10 +19,8 @@ package org.jclouds.googlecomputeengine.functions.internal;
import static com.google.common.base.Predicates.instanceOf;
import static com.google.common.collect.Iterables.tryFind;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.collect.PagedIterable;
import org.jclouds.collect.PagedIterables;
import java.util.Iterator;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.http.HttpRequest;
@ -32,18 +30,19 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.common.annotations.Beta;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.collect.Iterators;
@Beta
public abstract class BaseWithRegionToPagedIterable<T, I extends BaseWithRegionToPagedIterable<T, I>> implements
Function<ListPage<T>, PagedIterable<T>>, InvocationContext<I> {
public abstract class BaseWithRegionToIteratorOfListPage<T, I extends BaseWithRegionToIteratorOfListPage<T, I>>
implements Function<ListPage<T>, Iterator<ListPage<T>>>, InvocationContext<I> {
private GeneratedHttpRequest request;
@Override public PagedIterable<T> apply(ListPage<T> input) {
@Override public Iterator<ListPage<T>> apply(ListPage<T> input) {
if (input.nextPageToken() == null)
return PagedIterables.onlyPage(IterableWithMarkers.from(input));
return Iterators.singletonIterator(input);
Optional <Object> project = tryFind(request.getCaller().get().getArgs(), instanceOf(String.class));
Optional<Object> project = tryFind(request.getCaller().get().getArgs(), instanceOf(String.class));
Optional<Object> region = tryFind(request.getInvocation().getArgs(), instanceOf(String.class));
@ -55,13 +54,13 @@ public abstract class BaseWithRegionToPagedIterable<T, I extends BaseWithRegionT
assert region.isPresent() : String.format("programming error, method %s should have a string param for the "
+ "region", request.getCaller().get().getInvokable());
return PagedIterables.advance(IterableWithMarkers.from(input, input.nextPageToken()),
return new AdvancingIterator<T>(input,
fetchNextPage(project.get().toString(), region.get().toString(), (ListOptions) listOptions.orNull()));
}
protected abstract Function<Object, IterableWithMarker<T>> fetchNextPage(String projectName,
String regionName,
ListOptions listOptions);
protected abstract Function<String, ListPage<T>> fetchNextPage(String projectName,
String regionName,
ListOptions listOptions);
@SuppressWarnings("unchecked")
@Override

View File

@ -19,10 +19,8 @@ package org.jclouds.googlecomputeengine.functions.internal;
import static com.google.common.base.Predicates.instanceOf;
import static com.google.common.collect.Iterables.tryFind;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.collect.PagedIterable;
import org.jclouds.collect.PagedIterables;
import java.util.Iterator;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.http.HttpRequest;
@ -32,16 +30,18 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.common.annotations.Beta;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.collect.Iterators;
@Beta
public abstract class BaseWithZoneToPagedIterable<T, I extends BaseWithZoneToPagedIterable<T, I>> implements
Function<ListPage<T>, PagedIterable<T>>, InvocationContext<I> {
public abstract class BaseWithZoneToIteratorOfListPage<T, I extends BaseWithZoneToIteratorOfListPage<T, I>>
implements Function<ListPage<T>, Iterator<ListPage<T>>>, InvocationContext<I> {
private GeneratedHttpRequest request;
@Override public PagedIterable<T> apply(ListPage<T> input) {
if (input.nextPageToken() == null)
return PagedIterables.onlyPage(IterableWithMarkers.from(input));
@Override public Iterator<ListPage<T>> apply(ListPage<T> input) {
if (input.nextPageToken() == null) {
return Iterators.singletonIterator(input);
}
Optional<Object> project = tryFind(request.getCaller().get().getArgs(), instanceOf(String.class));
@ -55,13 +55,13 @@ public abstract class BaseWithZoneToPagedIterable<T, I extends BaseWithZoneToPag
assert zone.isPresent() : String.format("programming error, method %s should have a string param for the "
+ "zone", request.getCaller().get().getInvokable());
return PagedIterables.advance(IterableWithMarkers.from(input, input.nextPageToken()),
return new AdvancingIterator<T>(input,
fetchNextPage(project.get().toString(), zone.get().toString(), (ListOptions) listOptions.orNull()));
}
protected abstract Function<Object, IterableWithMarker<T>> fetchNextPage(String projectName,
String zoneName,
ListOptions listOptions);
protected abstract Function<String, ListPage<T>> fetchNextPage(String projectName,
String zoneName,
ListOptions listOptions);
@SuppressWarnings("unchecked")
@Override

View File

@ -18,8 +18,6 @@ package org.jclouds.googlecomputeengine.functions.internal;
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.Address;
import org.jclouds.googlecomputeengine.domain.ListPage;
@ -37,22 +35,19 @@ public final class ParseAddresses extends ParseJson<ListPage<Address>> {
});
}
public static class ToPagedIterable extends BaseWithRegionToPagedIterable<Address, ToPagedIterable> {
public static class ToIteratorOfListPage extends BaseWithRegionToIteratorOfListPage<Address, ToIteratorOfListPage> {
private final GoogleComputeEngineApi api;
@Inject ToPagedIterable(GoogleComputeEngineApi api) {
@Inject ToIteratorOfListPage(GoogleComputeEngineApi api) {
this.api = api;
}
@Override protected Function<Object, IterableWithMarker<Address>> fetchNextPage(final String projectName,
@Override protected Function<String, ListPage<Address>> fetchNextPage(final String projectName,
final String regionName, final ListOptions options) {
return new Function<Object, IterableWithMarker<Address>>() {
@Override public IterableWithMarker<Address> apply(Object input) {
ListPage<Address> result = api.getAddressApi(projectName)
.listAtMarkerInRegion(regionName, input.toString(), options);
return IterableWithMarkers.from(result, result.nextPageToken());
return new Function<String, ListPage<Address>>() {
@Override public ListPage<Address> apply(String input) {
return api.getAddressApi(projectName).listAtMarkerInRegion(regionName, input, options);
}
};
}

View File

@ -18,8 +18,6 @@ package org.jclouds.googlecomputeengine.functions.internal;
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.DiskType;
import org.jclouds.googlecomputeengine.domain.ListPage;
@ -37,22 +35,19 @@ public final class ParseDiskTypes extends ParseJson<ListPage<DiskType>> {
});
}
public static class ToPagedIterable extends BaseWithZoneToPagedIterable<DiskType, ToPagedIterable> {
public static class ToIteratorOfListPage extends BaseWithZoneToIteratorOfListPage<DiskType, ToIteratorOfListPage> {
private final GoogleComputeEngineApi api;
@Inject ToPagedIterable(GoogleComputeEngineApi api) {
@Inject ToIteratorOfListPage(GoogleComputeEngineApi api) {
this.api = api;
}
@Override protected Function<Object, IterableWithMarker<DiskType>> fetchNextPage(final String projectName,
@Override protected Function<String, ListPage<DiskType>> fetchNextPage(final String projectName,
final String zoneName, final ListOptions options) {
return new Function<Object, IterableWithMarker<DiskType>>() {
@Override public IterableWithMarker<DiskType> apply(Object input) {
ListPage<DiskType> result = api.getDiskTypeApi(projectName)
.listAtMarkerInZone(zoneName, input.toString(), options);
return IterableWithMarkers.from(result, result.nextPageToken());
return new Function<String, ListPage<DiskType>>() {
@Override public ListPage<DiskType> apply(String input) {
return api.getDiskTypeApi(projectName).listAtMarkerInZone(zoneName, input, options);
}
};
}

View File

@ -18,8 +18,6 @@ package org.jclouds.googlecomputeengine.functions.internal;
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.Disk;
import org.jclouds.googlecomputeengine.domain.ListPage;
@ -37,22 +35,20 @@ public final class ParseDisks extends ParseJson<ListPage<Disk>> {
});
}
public static class ToPagedIterable extends BaseWithZoneToPagedIterable<Disk, ToPagedIterable> {
public static class ToIteratorOfListPage extends BaseWithZoneToIteratorOfListPage<Disk, ToIteratorOfListPage> {
private final GoogleComputeEngineApi api;
@Inject ToPagedIterable(GoogleComputeEngineApi api) {
@Inject ToIteratorOfListPage(GoogleComputeEngineApi api) {
this.api = api;
}
@Override protected Function<Object, IterableWithMarker<Disk>> fetchNextPage(final String projectName,
@Override protected Function<String, ListPage<Disk>> fetchNextPage(final String projectName,
final String zoneName, final ListOptions options) {
return new Function<Object, IterableWithMarker<Disk>>() {
return new Function<String, ListPage<Disk>>() {
@Override public IterableWithMarker<Disk> apply(Object input) {
ListPage<Disk> result = api.getDiskApi(projectName)
.listAtMarkerInZone(zoneName, input.toString(), options);
return IterableWithMarkers.from(result, result.nextPageToken());
@Override public ListPage<Disk> apply(String input) {
return api.getDiskApi(projectName).listAtMarkerInZone(zoneName, input, options);
}
};
}

View File

@ -18,8 +18,6 @@ package org.jclouds.googlecomputeengine.functions.internal;
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.Firewall;
import org.jclouds.googlecomputeengine.domain.ListPage;
@ -37,20 +35,19 @@ public final class ParseFirewalls extends ParseJson<ListPage<Firewall>> {
});
}
public static final class ToPagedIterable extends BaseToPagedIterable<Firewall, ToPagedIterable> {
public static final class ToIteratorOfListPage extends BaseToIteratorOfListPage<Firewall, ToIteratorOfListPage> {
private final GoogleComputeEngineApi api;
@Inject ToPagedIterable(GoogleComputeEngineApi api) {
@Inject ToIteratorOfListPage(GoogleComputeEngineApi api) {
this.api = api;
}
@Override protected Function<Object, IterableWithMarker<Firewall>> fetchNextPage(final String projectName,
@Override protected Function<String, ListPage<Firewall>> fetchNextPage(final String projectName,
final ListOptions options) {
return new Function<Object, IterableWithMarker<Firewall>>() {
@Override public IterableWithMarker<Firewall> apply(Object input) {
ListPage<Firewall> result = api.getFirewallApi(projectName).listAtMarker(input.toString(), options);
return IterableWithMarkers.from(result, result.nextPageToken());
return new Function<String, ListPage<Firewall>>() {
@Override public ListPage<Firewall> apply(String input) {
return api.getFirewallApi(projectName).listAtMarker(input, options);
}
};
}

View File

@ -18,8 +18,6 @@ package org.jclouds.googlecomputeengine.functions.internal;
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ForwardingRule;
import org.jclouds.googlecomputeengine.domain.ListPage;
@ -37,21 +35,21 @@ public final class ParseForwardingRules extends ParseJson<ListPage<ForwardingRul
});
}
public static class ToPagedIterable extends BaseWithRegionToPagedIterable<ForwardingRule, ToPagedIterable> {
public static class ToIteratorOfListPage
extends BaseWithRegionToIteratorOfListPage<ForwardingRule, ToIteratorOfListPage> {
private final GoogleComputeEngineApi api;
@Inject ToPagedIterable(GoogleComputeEngineApi api) {
@Inject ToIteratorOfListPage(GoogleComputeEngineApi api) {
this.api = api;
}
@Override protected Function<Object, IterableWithMarker<ForwardingRule>> fetchNextPage(final String projectName,
@Override protected Function<String, ListPage<ForwardingRule>> fetchNextPage(final String projectName,
final String regionName,
final ListOptions options) {
return new Function<Object, IterableWithMarker<ForwardingRule>>() {
@Override public IterableWithMarker<ForwardingRule> apply(Object input) {
ListPage<ForwardingRule> result = api.getForwardingRuleApi(projectName, regionName).list(options);
return IterableWithMarkers.from(result, result.nextPageToken());
return new Function<String, ListPage<ForwardingRule>>() {
@Override public ListPage<ForwardingRule> apply(String input) {
return api.getForwardingRuleApi(projectName, regionName).list(options);
}
};
}

View File

@ -18,8 +18,6 @@ package org.jclouds.googlecomputeengine.functions.internal;
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
@ -37,22 +35,20 @@ public final class ParseGlobalOperations extends ParseJson<ListPage<Operation>>
});
}
public static final class ToPagedIterable extends BaseToPagedIterable<Operation, ToPagedIterable> {
public static final class ToIteratorOfListPage extends BaseToIteratorOfListPage<Operation, ToIteratorOfListPage> {
private final GoogleComputeEngineApi api;
@Inject ToPagedIterable(GoogleComputeEngineApi api) {
@Inject ToIteratorOfListPage(GoogleComputeEngineApi api) {
this.api = api;
}
@Override
protected Function<Object, IterableWithMarker<Operation>> fetchNextPage(final String projectName,
protected Function<String, ListPage<Operation>> fetchNextPage(final String projectName,
final ListOptions options) {
return new Function<Object, IterableWithMarker<Operation>>() {
@Override public IterableWithMarker<Operation> apply(Object input) {
ListPage<Operation> result = api.getGlobalOperationApi(projectName)
.listAtMarker(input.toString(), options);
return IterableWithMarkers.from(result, result.nextPageToken());
return new Function<String, ListPage<Operation>>() {
@Override public ListPage<Operation> apply(String input) {
return api.getGlobalOperationApi(projectName).listAtMarker(input, options);
}
};
}

View File

@ -20,8 +20,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.HttpHealthCheck;
import org.jclouds.googlecomputeengine.domain.ListPage;
@ -39,21 +37,20 @@ public final class ParseHttpHealthChecks extends ParseJson<ListPage<HttpHealthCh
});
}
public static class ToPagedIterable extends BaseToPagedIterable<HttpHealthCheck, ToPagedIterable> {
public static class ToIteratorOfListPage extends BaseToIteratorOfListPage<HttpHealthCheck, ToIteratorOfListPage> {
private final GoogleComputeEngineApi api;
@Inject ToPagedIterable(GoogleComputeEngineApi api) {
@Inject ToIteratorOfListPage(GoogleComputeEngineApi api) {
this.api = checkNotNull(api, "api");
}
@Override protected Function<Object, IterableWithMarker<HttpHealthCheck>> fetchNextPage(final String projectName,
@Override protected Function<String, ListPage<HttpHealthCheck>> fetchNextPage(final String projectName,
final ListOptions options) {
return new Function<Object, IterableWithMarker<HttpHealthCheck>>() {
return new Function<String, ListPage<HttpHealthCheck>>() {
@Override public IterableWithMarker<HttpHealthCheck> apply(Object input) {
ListPage<HttpHealthCheck> result = api.getHttpHealthCheckApi(projectName).list(options);
return IterableWithMarkers.from(result, result.nextPageToken());
@Override public ListPage<HttpHealthCheck> apply(String input) {
return api.getHttpHealthCheckApi(projectName).list(options);
}
};
}

View File

@ -18,8 +18,6 @@ package org.jclouds.googlecomputeengine.functions.internal;
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.Image;
import org.jclouds.googlecomputeengine.domain.ListPage;
@ -37,20 +35,19 @@ public final class ParseImages extends ParseJson<ListPage<Image>> {
});
}
public static final class ToPagedIterable extends BaseToPagedIterable<Image, ToPagedIterable> {
public static final class ToIteratorOfListPage extends BaseToIteratorOfListPage<Image, ToIteratorOfListPage> {
private final GoogleComputeEngineApi api;
@Inject ToPagedIterable(GoogleComputeEngineApi api) {
@Inject ToIteratorOfListPage(GoogleComputeEngineApi api) {
this.api = api;
}
@Override protected Function<Object, IterableWithMarker<Image>> fetchNextPage(final String projectName,
@Override protected Function<String, ListPage<Image>> fetchNextPage(final String projectName,
final ListOptions options) {
return new Function<Object, IterableWithMarker<Image>>() {
@Override public IterableWithMarker<Image> apply(Object input) {
ListPage<Image> result = api.getImageApi(projectName).listAtMarker(input.toString(), options);
return IterableWithMarkers.from(result, result.nextPageToken());
return new Function<String, ListPage<Image>>() {
@Override public ListPage<Image> apply(String input) {
return api.getImageApi(projectName).listAtMarker(input, options);
}
};
}

View File

@ -18,8 +18,6 @@ package org.jclouds.googlecomputeengine.functions.internal;
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.Instance;
import org.jclouds.googlecomputeengine.domain.ListPage;
@ -37,22 +35,21 @@ public final class ParseInstances extends ParseJson<ListPage<Instance>> {
});
}
public static final class ToPagedIterable extends BaseWithZoneToPagedIterable<Instance, ToPagedIterable> {
public static final class ToIteratorOfListPage
extends BaseWithZoneToIteratorOfListPage<Instance, ToIteratorOfListPage> {
private final GoogleComputeEngineApi api;
@Inject ToPagedIterable(GoogleComputeEngineApi api) {
@Inject ToIteratorOfListPage(GoogleComputeEngineApi api) {
this.api = api;
}
@Override
protected Function<Object, IterableWithMarker<Instance>> fetchNextPage(final String project, final String zone,
protected Function<String, ListPage<Instance>> fetchNextPage(final String project, final String zone,
final ListOptions options) {
return new Function<Object, IterableWithMarker<Instance>>() {
@Override public IterableWithMarker<Instance> apply(Object input) {
ListPage<Instance> result = api.getInstanceApi(project)
.listAtMarkerInZone(zone, input.toString(), options);
return IterableWithMarkers.from(result, result.nextPageToken());
return new Function<String, ListPage<Instance>>() {
@Override public ListPage<Instance> apply(String input) {
return api.getInstanceApi(project).listAtMarkerInZone(zone, input, options);
}
};
}

View File

@ -18,8 +18,6 @@ package org.jclouds.googlecomputeengine.functions.internal;
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.MachineType;
@ -37,22 +35,21 @@ public final class ParseMachineTypes extends ParseJson<ListPage<MachineType>> {
});
}
public static class ToPagedIterable extends BaseWithZoneToPagedIterable<MachineType, ToPagedIterable> {
public static class ToIteratorOfListPage
extends BaseWithZoneToIteratorOfListPage<MachineType, ToIteratorOfListPage> {
private final GoogleComputeEngineApi api;
@Inject ToPagedIterable(GoogleComputeEngineApi api) {
@Inject ToIteratorOfListPage(GoogleComputeEngineApi api) {
this.api = api;
}
@Override protected Function<Object, IterableWithMarker<MachineType>> fetchNextPage(final String projectName,
@Override protected Function<String, ListPage<MachineType>> fetchNextPage(final String projectName,
final String zoneName, final ListOptions options) {
return new Function<Object, IterableWithMarker<MachineType>>() {
return new Function<String, ListPage<MachineType>>() {
@Override public IterableWithMarker<MachineType> apply(Object input) {
ListPage<MachineType> result = api.getMachineTypeApi(projectName)
.listAtMarkerInZone(zoneName, input.toString(), options);
return IterableWithMarkers.from(result, result.nextPageToken());
@Override public ListPage<MachineType> apply(String input) {
return api.getMachineTypeApi(projectName).listAtMarkerInZone(zoneName, input, options);
}
};
}

View File

@ -18,8 +18,6 @@ package org.jclouds.googlecomputeengine.functions.internal;
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Network;
@ -37,20 +35,19 @@ public final class ParseNetworks extends ParseJson<ListPage<Network>> {
});
}
public static final class ToPagedIterable extends BaseToPagedIterable<Network, ToPagedIterable> {
public static final class ToIteratorOfListPage extends BaseToIteratorOfListPage<Network, ToIteratorOfListPage> {
private final GoogleComputeEngineApi api;
@Inject ToPagedIterable(GoogleComputeEngineApi api) {
@Inject ToIteratorOfListPage(GoogleComputeEngineApi api) {
this.api = api;
}
@Override protected Function<Object, IterableWithMarker<Network>> fetchNextPage(final String projectName,
@Override protected Function<String, ListPage<Network>> fetchNextPage(final String projectName,
final ListOptions options) {
return new Function<Object, IterableWithMarker<Network>>() {
@Override public IterableWithMarker<Network> apply(Object input) {
ListPage<Network> result = api.getNetworkApi(projectName).listAtMarker(input.toString(), options);
return IterableWithMarkers.from(result, result.nextPageToken());
return new Function<String, ListPage<Network>>() {
@Override public ListPage<Network> apply(String input) {
return api.getNetworkApi(projectName).listAtMarker(input, options);
}
};
}

View File

@ -18,8 +18,6 @@ package org.jclouds.googlecomputeengine.functions.internal;
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
@ -37,21 +35,20 @@ public final class ParseRegionOperations extends ParseJson<ListPage<Operation>>
});
}
public static class ToPagedIterable extends BaseWithRegionToPagedIterable<Operation, ToPagedIterable> {
public static class ToIteratorOfListPage
extends BaseWithRegionToIteratorOfListPage<Operation, ToIteratorOfListPage> {
private final GoogleComputeEngineApi api;
@Inject ToPagedIterable(GoogleComputeEngineApi api) {
@Inject ToIteratorOfListPage(GoogleComputeEngineApi api) {
this.api = api;
}
@Override protected Function<Object, IterableWithMarker<Operation>> fetchNextPage(final String projectName,
@Override protected Function<String, ListPage<Operation>> fetchNextPage(final String projectName,
final String regionName, final ListOptions options) {
return new Function<Object, IterableWithMarker<Operation>>() {
@Override public IterableWithMarker<Operation> apply(Object input) {
ListPage<Operation> result = api.getRegionOperationApi(projectName)
.listAtMarkerInRegion(regionName, input.toString(), options);
return IterableWithMarkers.from(result, result.nextPageToken());
return new Function<String, ListPage<Operation>>() {
@Override public ListPage<Operation> apply(String input) {
return api.getRegionOperationApi(projectName).listAtMarkerInRegion(regionName, input, options);
}
};
}

View File

@ -18,8 +18,6 @@ package org.jclouds.googlecomputeengine.functions.internal;
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Region;
@ -37,20 +35,19 @@ public final class ParseRegions extends ParseJson<ListPage<Region>> {
});
}
public static final class ToPagedIterable extends BaseToPagedIterable<Region, ToPagedIterable> {
public static final class ToIteratorOfListPage extends BaseToIteratorOfListPage<Region, ToIteratorOfListPage> {
private final GoogleComputeEngineApi api;
@Inject ToPagedIterable(GoogleComputeEngineApi api) {
@Inject ToIteratorOfListPage(GoogleComputeEngineApi api) {
this.api = api;
}
@Override protected Function<Object, IterableWithMarker<Region>> fetchNextPage(final String projectName,
@Override protected Function<String, ListPage<Region>> fetchNextPage(final String projectName,
final ListOptions options) {
return new Function<Object, IterableWithMarker<Region>>() {
@Override public IterableWithMarker<Region> apply(Object input) {
ListPage<Region> result = api.getRegionApi(projectName).listAtMarker(input.toString(), options);
return IterableWithMarkers.from(result, result.nextPageToken());
return new Function<String, ListPage<Region>>() {
@Override public ListPage<Region> apply(String input) {
return api.getRegionApi(projectName).listAtMarker(input, options);
}
};
}

View File

@ -18,8 +18,6 @@ package org.jclouds.googlecomputeengine.functions.internal;
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Route;
@ -37,21 +35,20 @@ public final class ParseRoutes extends ParseJson<ListPage<Route>> {
});
}
public static final class ToPagedIterable extends BaseToPagedIterable<Route, ToPagedIterable> {
public static final class ToIteratorOfListPage extends BaseToIteratorOfListPage<Route, ToIteratorOfListPage> {
private final GoogleComputeEngineApi api;
@Inject ToPagedIterable(GoogleComputeEngineApi api) {
@Inject ToIteratorOfListPage(GoogleComputeEngineApi api) {
this.api = api;
}
@Override
protected Function<Object, IterableWithMarker<Route>> fetchNextPage(final String projectName,
protected Function<String, ListPage<Route>> fetchNextPage(final String projectName,
final ListOptions options) {
return new Function<Object, IterableWithMarker<Route>>() {
@Override public IterableWithMarker<Route> apply(Object input) {
ListPage<Route> result = api.getRouteApi(projectName).listAtMarker(input.toString(), options);
return IterableWithMarkers.from(result, result.nextPageToken());
return new Function<String, ListPage<Route>>() {
@Override public ListPage<Route> apply(String input) {
return api.getRouteApi(projectName).listAtMarker(input, options);
}
};
}

View File

@ -18,8 +18,6 @@ package org.jclouds.googlecomputeengine.functions.internal;
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Snapshot;
@ -37,20 +35,19 @@ public final class ParseSnapshots extends ParseJson<ListPage<Snapshot>> {
});
}
public static final class ToPagedIterable extends BaseToPagedIterable<Snapshot, ToPagedIterable> {
public static final class ToIteratorOfListPage extends BaseToIteratorOfListPage<Snapshot, ToIteratorOfListPage> {
private final GoogleComputeEngineApi api;
@Inject ToPagedIterable(GoogleComputeEngineApi api) {
@Inject ToIteratorOfListPage(GoogleComputeEngineApi api) {
this.api = api;
}
@Override protected Function<Object, IterableWithMarker<Snapshot>> fetchNextPage(final String projectName,
@Override protected Function<String, ListPage<Snapshot>> fetchNextPage(final String projectName,
final ListOptions options) {
return new Function<Object, IterableWithMarker<Snapshot>>() {
@Override public IterableWithMarker<Snapshot> apply(Object input) {
ListPage<Snapshot> result = api.getSnapshotApi(projectName).listAtMarker(input.toString(), options);
return IterableWithMarkers.from(result, result.nextPageToken());
return new Function<String, ListPage<Snapshot>>() {
@Override public ListPage<Snapshot> apply(String input) {
return api.getSnapshotApi(projectName).listAtMarker(input, options);
}
};
}

View File

@ -20,8 +20,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.TargetPool;
@ -39,23 +37,22 @@ public final class ParseTargetPools extends ParseJson<ListPage<TargetPool>> {
});
}
public static class ToPagedIterable extends BaseWithZoneToPagedIterable<TargetPool, ToPagedIterable> {
public static class ToIteratorOfListPage extends BaseWithZoneToIteratorOfListPage<TargetPool, ToIteratorOfListPage> {
private final GoogleComputeEngineApi api;
@Inject ToPagedIterable(GoogleComputeEngineApi api) {
@Inject ToIteratorOfListPage(GoogleComputeEngineApi api) {
this.api = checkNotNull(api, "api");
}
@Override protected Function<Object, IterableWithMarker<TargetPool>> fetchNextPage(final String projectName,
@Override protected Function<String, ListPage<TargetPool>> fetchNextPage(final String projectName,
final String regionName,
final ListOptions options) {
return new Function<Object, IterableWithMarker<TargetPool>>() {
return new Function<String, ListPage<TargetPool>>() {
@Override
public IterableWithMarker<TargetPool> apply(Object input) {
ListPage<TargetPool> result = api.getTargetPoolApi(projectName, regionName).list(options);
return IterableWithMarkers.from(result, result.nextPageToken());
public ListPage<TargetPool> apply(String input) {
return api.getTargetPoolApi(projectName, regionName).list(options);
}
};
}

View File

@ -18,8 +18,6 @@ package org.jclouds.googlecomputeengine.functions.internal;
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
@ -37,22 +35,20 @@ public final class ParseZoneOperations extends ParseJson<ListPage<Operation>> {
});
}
public static class ToPagedIterable extends BaseWithZoneToPagedIterable<Operation, ToPagedIterable> {
public static class ToIteratorOfListPage extends BaseWithZoneToIteratorOfListPage<Operation, ToIteratorOfListPage> {
private final GoogleComputeEngineApi api;
@Inject ToPagedIterable(GoogleComputeEngineApi api) {
@Inject ToIteratorOfListPage(GoogleComputeEngineApi api) {
this.api = api;
}
@Override protected Function<Object, IterableWithMarker<Operation>> fetchNextPage(final String projectName,
@Override protected Function<String, ListPage<Operation>> fetchNextPage(final String projectName,
final String zoneName, final ListOptions options) {
return new Function<Object, IterableWithMarker<Operation>>() {
return new Function<String, ListPage<Operation>>() {
@Override public IterableWithMarker<Operation> apply(Object input) {
ListPage<Operation> result = api.getZoneOperationApi(projectName)
.listAtMarkerInZone(zoneName, input.toString(), options);
return IterableWithMarkers.from(result, result.nextPageToken());
@Override public ListPage<Operation> apply(String input) {
return api.getZoneOperationApi(projectName).listAtMarkerInZone(zoneName, input, options);
}
};
}

View File

@ -18,8 +18,6 @@ package org.jclouds.googlecomputeengine.functions.internal;
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Zone;
@ -37,21 +35,20 @@ public final class ParseZones extends ParseJson<ListPage<Zone>> {
});
}
public static final class ToPagedIterable extends BaseToPagedIterable<Zone, ToPagedIterable> {
public static final class ToIteratorOfListPage extends BaseToIteratorOfListPage<Zone, ToIteratorOfListPage> {
private final GoogleComputeEngineApi api;
@Inject ToPagedIterable(GoogleComputeEngineApi api) {
@Inject ToIteratorOfListPage(GoogleComputeEngineApi api) {
this.api = api;
}
@Override
protected Function<Object, IterableWithMarker<Zone>> fetchNextPage(final String projectName,
protected Function<String, ListPage<Zone>> fetchNextPage(final String projectName,
final ListOptions options) {
return new Function<Object, IterableWithMarker<Zone>>() {
@Override public IterableWithMarker<Zone> apply(Object input) {
ListPage<Zone> result = api.getZoneApi(projectName).listAtMarker(input.toString(), options);
return IterableWithMarkers.from(result, result.nextPageToken());
return new Function<String, ListPage<Zone>>() {
@Override public ListPage<Zone> apply(String input) {
return api.getZoneApi(projectName).listAtMarker(input, options);
}
};
}

View File

@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.internal;
import java.util.Iterator;
import org.jclouds.googlecomputeengine.domain.ListPage;
import com.google.common.collect.AbstractIterator;
import com.google.common.collect.Iterators;
public final class ListPages {
public static <T> Iterable<T> concat(final Iterator<ListPage<T>> input) {
return new Iterable<T>() {
@Override public Iterator<T> iterator() {
return Iterators.concat(new AbstractIterator<Iterator<T>>() {
@Override protected Iterator<T> computeNext() {
return input.hasNext() ? input.next().iterator() : endOfData();
}
});
}
};
}
private ListPages() {
}
}

View File

@ -17,11 +17,13 @@
package org.jclouds.googlecomputeengine;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertSame;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable;
import java.util.Iterator;
import org.jclouds.googlecomputeengine.domain.Image;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.features.ImageApi;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.options.ListOptions;
@ -51,12 +53,9 @@ public class PageSystemExpectTest extends BaseGoogleComputeEngineApiExpectTest {
ImageApi imageApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, list, operationResponse).getImageApi("myproject");
PagedIterable<Image> images = imageApi.list();
Iterator<ListPage<Image>> images = imageApi.list();
// expect one page
assertSame(images.size(), 1);
// with three images
assertSame(images.concat().size(), 3);
assertEquals(images.next().size(), 3);
}
public void testGetMultiplePages() {
@ -100,13 +99,11 @@ public class PageSystemExpectTest extends BaseGoogleComputeEngineApiExpectTest {
TOKEN_RESPONSE, list1, list1response, list2, list2Response, list3, list3Response)
.getImageApi("myproject");
PagedIterable<Image> images = imageApi.list(new ListOptions.Builder().maxResults(3));
Iterator<ListPage<Image>> images = imageApi.list(new ListOptions.Builder().maxResults(3));
int imageCounter = 0;
for (IterableWithMarker<Image> page : images) {
for (Image image : page) {
imageCounter++;
}
while (images.hasNext()) {
imageCounter += images.next().size();
}
assertSame(imageCounter, 9);
}

View File

@ -415,8 +415,6 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin
@Test(dependsOnMethods = "testListLocationsWhenResponseIs2xx")
public void testCreateNodeWhenNetworkNorFirewallExistDoesNotExist() throws RunNodesException, IOException {
String payload = Strings2.toStringAndClose(InstanceApiExpectTest.class.getResourceAsStream("/instance_get.json"));
payload = payload.replace("test-0", "test-1");

View File

@ -67,7 +67,7 @@ public class GoogleComputeEngineServiceLiveTest extends BaseComputeServiceLiveTe
}, UserProject.class));
ImmutableSet.Builder<String> deprecatedMachineTypes = ImmutableSet.builder();
for (MachineType machine : api.getMachineTypeApi(userProject.get())
.listInZone(DEFAULT_ZONE_NAME).concat()) {
.listInZone(DEFAULT_ZONE_NAME).next()) {
if (machine.deprecated() != null) {
deprecatedMachineTypes.add(machine.id());
}

View File

@ -16,6 +16,7 @@
*/
package org.jclouds.googlecomputeengine.compute.functions;
import static com.google.common.collect.Iterators.singletonIterator;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
@ -26,10 +27,9 @@ import static org.testng.Assert.assertTrue;
import java.net.URI;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.collect.PagedIterables;
import org.jclouds.compute.domain.SecurityGroup;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Network;
import org.jclouds.googlecomputeengine.features.FirewallApi;
import org.jclouds.googlecomputeengine.options.ListOptions;
@ -39,7 +39,7 @@ import org.testng.annotations.Test;
import com.google.common.base.Predicates;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
public class NetworkToSecurityGroupTest {
@ -62,7 +62,7 @@ public class NetworkToSecurityGroupTest {
expect(api.getFirewallApi(projectSupplier.get()))
.andReturn(fwApi);
expect(fwApi.list(options)).andReturn(
PagedIterables.onlyPage(IterableWithMarkers.from(ImmutableSet.of(FirewallToIpPermissionTest.fwForTest()))));
singletonIterator(ListPage.create(ImmutableList.of(FirewallToIpPermissionTest.fwForTest()), null)));
replay(api, fwApi);

View File

@ -19,7 +19,7 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertFalse;
import static org.testng.AssertJUnit.assertNull;
import javax.ws.rs.core.MediaType;
@ -137,8 +137,7 @@ public class AddressApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, list, operationResponse).getAddressApi("myproject");
assertEquals(api.listFirstPageInRegion("us-central1").toString(),
new ParseAddressListTest().expected().toString());
assertEquals(api.listInRegion("us-central1").next().toString(), new ParseAddressListTest().expected().toString());
}
public void testListAddresssResponseIs4xx() {
@ -154,6 +153,6 @@ public class AddressApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, list, operationResponse).getAddressApi("myproject");
assertTrue(api.listInRegion("us-central1").concat().isEmpty());
assertFalse(api.listInRegion("us-central1").hasNext());
}
}

View File

@ -19,16 +19,14 @@ package org.jclouds.googlecomputeengine.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.util.List;
import java.util.Iterator;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.domain.Address;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.testng.annotations.Test;
import com.google.common.collect.Lists;
public class AddressApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
private static final String ADDRESS_NAME = "address-api-live-test-address";
@ -54,13 +52,10 @@ public class AddressApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live", dependsOnMethods = "testGetAddress")
public void testListAddress() {
PagedIterable<Address> addresss = api().listInRegion(DEFAULT_REGION_NAME, new ListOptions.Builder()
Iterator<ListPage<Address>> addresses = api().listInRegion(DEFAULT_REGION_NAME, new ListOptions.Builder()
.filter("name eq " + ADDRESS_NAME));
List<Address> addresssAsList = Lists.newArrayList(addresss.concat());
assertEquals(addresssAsList.size(), 1);
assertEquals(addresses.next().size(), 1);
}
@Test(groups = "live", dependsOnMethods = "testListAddress")

View File

@ -19,7 +19,7 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertFalse;
import static org.testng.AssertJUnit.assertNull;
import java.net.URI;
@ -228,8 +228,7 @@ public class DiskApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, list, operationResponse).getDiskApi("myproject");
assertEquals(api.listFirstPageInZone("us-central1-a").toString(),
new ParseDiskListTest().expected().toString());
assertEquals(api.listInZone("us-central1-a").next().toString(), new ParseDiskListTest().expected().toString());
}
public void testListDisksResponseIs4xx() {
@ -245,6 +244,6 @@ public class DiskApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, list, operationResponse).getDiskApi("myproject");
assertTrue(api.listInZone("us-central1-a").concat().isEmpty());
assertFalse(api.listInZone("us-central1-a").hasNext());
}
}

View File

@ -20,18 +20,16 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.net.URI;
import java.util.Iterator;
import java.util.List;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.domain.Disk;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.DiskCreationOptions;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
public class DiskApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
public static final String DISK_NAME = "disk-api-live-test-disk";
@ -45,7 +43,7 @@ public class DiskApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live")
public void testInsertDisk() {
assertZoneOperationDoneSucessfully(api().createInZone(DISK_NAME, sizeGb, DEFAULT_ZONE_NAME), TIME_WAIT);
assertZoneOperationDoneSuccessfully(api().createInZone(DISK_NAME, sizeGb, DEFAULT_ZONE_NAME), TIME_WAIT);
}
@Test(groups = "live", dependsOnMethods = "testInsertDisk")
@ -59,21 +57,21 @@ public class DiskApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live", dependsOnMethods = "testGetDisk")
public void testListDisk() {
PagedIterable<Disk> disks = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder()
Iterator<ListPage<Disk>> disks = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder()
.filter("name eq " + DISK_NAME));
List<Disk> disksAsList = Lists.newArrayList(disks.concat());
List<Disk> disksAsList = disks.next();
assertEquals(disksAsList.size(), 1);
assertDiskEquals(Iterables.getOnlyElement(disksAsList));
assertDiskEquals(disksAsList.get(0));
}
@Test(groups = "live", dependsOnMethods = "testListDisk")
public void testDeleteDisk() {
assertZoneOperationDoneSucessfully(api().deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME), TIME_WAIT);
assertZoneOperationDoneSuccessfully(api().deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME), TIME_WAIT);
}
private void assertDiskEquals(Disk result) {
@ -86,7 +84,8 @@ public class DiskApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
public void testInsertSSDDisk() {
URI diskType = getDiskTypeUrl(userProject.get(), DEFAULT_ZONE_NAME, "pd-ssd");
DiskCreationOptions diskCreationOptions = new DiskCreationOptions().type(diskType);
assertZoneOperationDoneSucessfully(api().createInZone(SSD_DISK_NAME, sizeGb, DEFAULT_ZONE_NAME, diskCreationOptions), TIME_WAIT);
assertZoneOperationDoneSuccessfully(
api().createInZone(SSD_DISK_NAME, sizeGb, DEFAULT_ZONE_NAME, diskCreationOptions), TIME_WAIT);
}
@Test(groups = "live", dependsOnMethods = "testInsertSSDDisk")
@ -100,7 +99,7 @@ public class DiskApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live", dependsOnMethods = "testGetSSDDisk")
public void testDeleteSSDDisk() {
assertZoneOperationDoneSucessfully(api().deleteInZone(DEFAULT_ZONE_NAME, SSD_DISK_NAME), TIME_WAIT);
assertZoneOperationDoneSuccessfully(api().deleteInZone(DEFAULT_ZONE_NAME, SSD_DISK_NAME), TIME_WAIT);
}
private void assertSSDDiskEquals(Disk result) {

View File

@ -18,8 +18,8 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.parse.ParseDiskTypeListTest;
@ -95,7 +95,7 @@ public class DiskTypeApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
TOKEN_RESPONSE, LIST_DISK_TYPES_REQUEST, LIST_DISK_TYPES_RESPONSE).getDiskTypeApi
("myproject");
assertEquals(diskTypeApi.listFirstPageInZone("us-central1-a").toString(),
assertEquals(diskTypeApi.listInZone("us-central1-a").next().toString(),
new ParseDiskTypeListTest().expected().toString());
}
@ -106,6 +106,6 @@ public class DiskTypeApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
DiskTypeApi diskTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, LIST_DISK_TYPES_REQUEST, operationResponse).getDiskTypeApi("myproject");
assertTrue(diskTypeApi.listInZone("us-central1-a").concat().isEmpty());
assertFalse(diskTypeApi.listInZone("us-central1-a").hasNext());
}
}

View File

@ -18,21 +18,16 @@ package org.jclouds.googlecomputeengine.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertSame;
import static org.testng.Assert.assertTrue;
import java.util.Iterator;
import java.util.List;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.domain.DiskType;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
public class DiskTypeApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
private DiskType diskType;
@ -44,18 +39,15 @@ public class DiskTypeApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live")
public void testDiskType() {
PagedIterable<DiskType> diskTypes = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder()
.maxResults(1));
Iterator<IterableWithMarker<DiskType>> pageIterator = diskTypes.iterator();
Iterator<ListPage<DiskType>> pageIterator = api().listInZone(DEFAULT_ZONE_NAME,
new ListOptions.Builder().maxResults(1));
assertTrue(pageIterator.hasNext());
IterableWithMarker<DiskType> singlePageIterator = pageIterator.next();
List<DiskType> diskTypeAsList = singlePageIterator.toList();
ListPage<DiskType> page = pageIterator.next();
assertSame(diskTypeAsList.size(), 1);
assertEquals(page.size(), 1);
this.diskType = Iterables.getOnlyElement(diskTypeAsList);
this.diskType = page.get(0);
}
@Test(groups = "live", dependsOnMethods = "testDiskType")

View File

@ -24,7 +24,7 @@ import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPU
import static org.jclouds.io.Payloads.newStringPayload;
import static org.jclouds.util.Strings2.toStringAndClose;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertFalse;
import static org.testng.AssertJUnit.assertNull;
import java.io.IOException;
@ -259,8 +259,7 @@ public class FirewallApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
FirewallApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, list, operationResponse).getFirewallApi("myproject");
assertEquals(api.listFirstPage().toString(),
new ParseFirewallListTest().expected().toString());
assertEquals(api.list().next().toString(), new ParseFirewallListTest().expected().toString());
}
public void testListFirewallsResponseIs4xx() {
@ -276,6 +275,6 @@ public class FirewallApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
FirewallApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, list, operationResponse).getFirewallApi("myproject");
assertTrue(api.list().concat().isEmpty());
assertFalse(api.list().hasNext());
}
}

View File

@ -20,17 +20,17 @@ import static com.google.common.collect.Iterables.getOnlyElement;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.util.Iterator;
import java.util.List;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.domain.Firewall;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.FirewallOptions;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
@Test(groups = "live", testName = "FirewallApiLiveTest")
public class FirewallApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@ -110,13 +110,12 @@ public class FirewallApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live", dependsOnMethods = "testGetFirewall")
public void testListFirewall() {
PagedIterable<Firewall> firewalls = api().list(new ListOptions.Builder()
Iterator<ListPage<Firewall>> firewalls = api().list(new ListOptions.Builder()
.filter("name eq " + FIREWALL_NAME));
List<Firewall> firewallsAsList = Lists.newArrayList(firewalls.concat());
List<Firewall> firewallsAsList = firewalls.next();
assertEquals(firewallsAsList.size(), 1);
}
@Test(groups = "live", dependsOnMethods = "testListFirewall")

View File

@ -19,7 +19,7 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertFalse;
import static org.testng.AssertJUnit.assertNull;
import java.net.URI;
@ -28,7 +28,6 @@ import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.googlecomputeengine.parse.ParseForwardingRuleListTest;
import org.jclouds.googlecomputeengine.parse.ParseForwardingRuleTest;
import org.jclouds.googlecomputeengine.parse.ParseRegionOperationTest;
@ -142,8 +141,7 @@ public class ForwardingRuleApiExpectTest extends BaseGoogleComputeEngineApiExpec
ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, list, operationResponse).getForwardingRuleApi("myproject", "us-central1");
ListOptions options = new ListOptions();
assertEquals(api.list(options).toString(), new ParseForwardingRuleListTest().expected().toString());
assertEquals(api.list().next().toString(), new ParseForwardingRuleListTest().expected().toString());
}
public void testListForwardingRulesResponseIs4xx() {
@ -159,7 +157,7 @@ public class ForwardingRuleApiExpectTest extends BaseGoogleComputeEngineApiExpec
ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, list, operationResponse).getForwardingRuleApi("myproject", "us-central1");
assertTrue(api.list().concat().isEmpty());
assertFalse(api.list().hasNext());
}
public void testSetTargetForwardingRuleResponseIs2xx(){

View File

@ -19,8 +19,8 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.options.ListOptions;
@ -108,7 +108,7 @@ public class GlobalOperationApiExpectTest extends BaseGoogleComputeEngineApiExpe
GlobalOperationApi globalOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, get, operationResponse).getGlobalOperationApi("myproject");
assertEquals(globalOperationApi.listFirstPage().toString(),
assertEquals(globalOperationApi.list().next().toString(),
new ParseGlobalOperationListTest().expected().toString());
}
@ -150,6 +150,6 @@ public class GlobalOperationApiExpectTest extends BaseGoogleComputeEngineApiExpe
GlobalOperationApi globalOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, get, operationResponse).getGlobalOperationApi("myproject");
assertTrue(globalOperationApi.list().concat().isEmpty());
assertFalse(globalOperationApi.list().hasNext());
}
}

View File

@ -16,74 +16,51 @@
*/
package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.features.ProjectApiLiveTest.addItemToMetadata;
import static org.jclouds.googlecomputeengine.features.ProjectApiLiveTest.deleteItemFromMetadata;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.Iterator;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.testng.SkipException;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
@Test(groups = "live", testName = "GlobalOperationApiLiveTest")
public class GlobalOperationApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
private static final String METADATA_ITEM_KEY = "operationLiveTestTestProp";
private static final String METADATA_ITEM_VALUE = "operationLiveTestTestValue";
private Operation addOperation;
private Operation deleteOperation;
private Operation operation;
private GlobalOperationApi api() {
return api.getGlobalOperationApi(userProject.get());
}
@Test(groups = "live")
public void testCreateOperations() {
//insert some operations by adding and deleting metadata items
// this will make sure there is stuff to listFirstPage
addOperation = assertGlobalOperationDoneSucessfully(addItemToMetadata(api.getProjectApi(),
userProject.get(), METADATA_ITEM_KEY, METADATA_ITEM_VALUE), 20);
deleteOperation = assertGlobalOperationDoneSucessfully(deleteItemFromMetadata(api
.getProjectApi(), userProject.get(), METADATA_ITEM_KEY), 20);
assertNotNull(addOperation);
assertNotNull(deleteOperation);
}
@Test(groups = "live", dependsOnMethods = "testCreateOperations")
public void testGetOperation() {
Operation operation = api().get(addOperation.name());
assertNotNull(operation);
assertOperationEquals(operation, this.addOperation);
}
@Test(groups = "live", dependsOnMethods = "testCreateOperations")
public void testListOperationsWithFiltersAndPagination() {
PagedIterable<Operation> operations = api().list(new ListOptions.Builder()
.filter("operationType eq setMetadata")
.maxResults(1));
Iterator<ListPage<Operation>> operations = api().list(new ListOptions.Builder()
// .filter("operationType eq insert")
.maxResults(1));
// make sure that in spite of having only one result per page we get at least two results
final AtomicInteger counter = new AtomicInteger();
operations.firstMatch(new Predicate<IterableWithMarker<Operation>>() {
@Override public boolean apply(IterableWithMarker<Operation> input) {
counter.addAndGet(Iterables.size(input));
return counter.get() == 2;
int count = 0;
for (; count < 2 && operations.hasNext(); ) {
ListPage<Operation> result = operations.next();
if (result.isEmpty()) {
operation = result.get(0);
count++;
}
});
}
if (count < 2) {
throw new SkipException("Not enough global operations");
}
assertEquals(count, 2);
}
private void assertOperationEquals(Operation result, Operation expected) {
assertEquals(result.name(), expected.name());
@Test(groups = "live", dependsOnMethods = "testListOperationsWithFiltersAndPagination")
public void testGetOperation() {
Operation result = api().get(operation.name());
assertNotNull(result);
assertEquals(result.name(), operation.name()); // Checking state besides name can lead to flaky test.
}
}

View File

@ -19,14 +19,13 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertFalse;
import static org.testng.AssertJUnit.assertNull;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.options.HttpHealthCheckCreationOptions;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.googlecomputeengine.parse.ParseGlobalOperationTest;
import org.jclouds.googlecomputeengine.parse.ParseHttpHealthCheckListTest;
import org.jclouds.googlecomputeengine.parse.ParseHttpHealthCheckTest;
@ -161,9 +160,7 @@ public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineApiExpe
HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, list, operationResponse).getHttpHealthCheckApi("myproject");
ListOptions options = new ListOptions();
assertEquals(api.list(options).toString(),
new ParseHttpHealthCheckListTest().expected().toString());
assertEquals(api.list().next().toString(), new ParseHttpHealthCheckListTest().expected().toString());
}
public void testListHttpHealthChecksResponseIs4xx() {
@ -179,7 +176,7 @@ public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineApiExpe
HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, list, operationResponse).getHttpHealthCheckApi("myproject");
assertTrue(api.list().concat().isEmpty());
assertFalse(api.list().hasNext());
}
public void testPatchHttpHealthChecksResponseIs2xx() {

View File

@ -19,7 +19,7 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertFalse;
import static org.testng.AssertJUnit.assertNull;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
@ -139,8 +139,7 @@ public class ImageApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
TOKEN_RESPONSE, LIST_PROJECT_IMAGES_REQUEST, LIST_PROJECT_IMAGES_RESPONSE).getImageApi
("myproject");
assertEquals(imageApi.listFirstPage().toString(),
new ParseImageListTest().expected().toString());
assertEquals(imageApi.list().next().toString(), new ParseImageListTest().expected().toString());
}
public void testListImagesResponseIs4xx() {
@ -150,7 +149,7 @@ public class ImageApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
ImageApi imageApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, LIST_PROJECT_IMAGES_REQUEST, operationResponse).getImageApi("myproject");
assertTrue(imageApi.list().concat().isEmpty());
assertFalse(imageApi.list().hasNext());
}
public void testCreateImageFromPdResponseIs2xx(){

View File

@ -18,23 +18,18 @@ package org.jclouds.googlecomputeengine.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertSame;
import static org.testng.Assert.assertTrue;
import java.net.URI;
import java.util.Iterator;
import java.util.List;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.domain.Disk;
import org.jclouds.googlecomputeengine.domain.Image;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
public class ImageApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
public static final String DISK_NAME = "image-api-live-test-disk";
@ -60,17 +55,13 @@ public class ImageApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live")
public void testListImage() {
PagedIterable<Image> images = api().list(new ListOptions.Builder().maxResults(1));
Iterator<ListPage<Image>> images = api().list(new ListOptions.Builder().maxResults(1));
Iterator<IterableWithMarker<Image>> pageIterator = images.iterator();
assertTrue(pageIterator.hasNext());
List<Image> imageAsList = images.next();
IterableWithMarker<Image> singlePageIterator = pageIterator.next();
List<Image> imageAsList = singlePageIterator.toList();
assertEquals(imageAsList.size(), 1);
assertSame(imageAsList.size(), 1);
this.image = Iterables.getOnlyElement(imageAsList);
this.image = imageAsList.get(0);
}
@ -87,7 +78,7 @@ public class ImageApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live")
public void testInsertDisk() {
assertZoneOperationDoneSucessfully(diskApi().createInZone(DISK_NAME, sizeGb, DEFAULT_ZONE_NAME), TIME_WAIT);
assertZoneOperationDoneSuccessfully(diskApi().createInZone(DISK_NAME, sizeGb, DEFAULT_ZONE_NAME), TIME_WAIT);
Disk disk = diskApi().getInZone(DEFAULT_ZONE_NAME, DISK_NAME);
diskURI = disk.selfLink();
}
@ -106,7 +97,7 @@ public class ImageApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live", dependsOnMethods = "testGetCreatedImage")
public void testCleanup(){
assertGlobalOperationDoneSucessfully(imageApi().delete(IMAGE_NAME), TIME_WAIT);
assertZoneOperationDoneSucessfully(diskApi().deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME), TIME_WAIT);
assertZoneOperationDoneSuccessfully(diskApi().deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME), TIME_WAIT);
}
private void assertImageEquals(Image result) {

View File

@ -22,7 +22,7 @@ import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPU
import static org.jclouds.googlecomputeengine.features.ProjectApiExpectTest.GET_PROJECT_REQUEST;
import static org.jclouds.googlecomputeengine.features.ProjectApiExpectTest.GET_PROJECT_RESPONSE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertFalse;
import static org.testng.AssertJUnit.assertNull;
import java.net.URI;
@ -216,7 +216,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE,
LIST_INSTANCES_REQUEST, LIST_INSTANCES_RESPONSE).getInstanceApi("myproject");
assertEquals(api.listFirstPageInZone("us-central1-a").toString(),
assertEquals(api.listInZone("us-central1-a").next().toString(),
new ParseInstanceListTest().expected().toString());
}
@ -233,7 +233,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, list, operationResponse).getInstanceApi("myproject");
assertTrue(api.listInZone("us-central1-a").concat().isEmpty());
assertFalse(api.listInZone("us-central1-a").hasNext());
}
public void testSetInstanceMetadataResponseIs2xx() {

View File

@ -21,14 +21,15 @@ import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.net.URI;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.Image;
import org.jclouds.googlecomputeengine.domain.Instance;
import org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.templates.InstanceTemplate;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.AttachDiskOptions;
@ -40,10 +41,10 @@ import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.inject.Module;
@Test(groups = "live", testName = "InstanceApiLiveTest")
@ -68,9 +69,9 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Override
protected GoogleComputeEngineApi create(Properties props, Iterable<Module> modules) {
GoogleComputeEngineApi api = super.create(props, modules);
URI imageUri = api.getImageApi("centos-cloud")
.list(new ListOptions.Builder().filter("name eq centos.*"))
.concat()
List<Image> list = api.getImageApi("centos-cloud")
.list(new ListOptions.Builder().filter("name eq centos.*")).next();
URI imageUri = FluentIterable.from(list)
.filter(new Predicate<Image>() {
@Override
public boolean apply(Image input) {
@ -111,15 +112,15 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
(INSTANCE_NETWORK_NAME, IPV4_RANGE), TIME_WAIT);
DiskCreationOptions diskCreationOptions = new DiskCreationOptions().sourceImage(instance.image());
assertZoneOperationDoneSucessfully(api.getDiskApi(userProject.get())
.createInZone(BOOT_DISK_NAME, DEFAULT_DISK_SIZE_GB, DEFAULT_ZONE_NAME, diskCreationOptions),
TIME_WAIT);
assertZoneOperationDoneSuccessfully(api.getDiskApi(userProject.get())
.createInZone(BOOT_DISK_NAME, DEFAULT_DISK_SIZE_GB, DEFAULT_ZONE_NAME, diskCreationOptions),
TIME_WAIT);
assertZoneOperationDoneSucessfully(diskApi().createInZone
("instance-live-test-disk", DEFAULT_DISK_SIZE_GB, DEFAULT_ZONE_NAME), TIME_WAIT);
assertZoneOperationDoneSuccessfully(
diskApi().createInZone("instance-live-test-disk", DEFAULT_DISK_SIZE_GB, DEFAULT_ZONE_NAME), TIME_WAIT);
assertZoneOperationDoneSucessfully(api().createInZone(INSTANCE_NAME, DEFAULT_ZONE_NAME, instance), TIME_WAIT);
assertZoneOperationDoneSuccessfully(api().createInZone(INSTANCE_NAME, DEFAULT_ZONE_NAME, instance), TIME_WAIT);
}
@ -134,10 +135,9 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live", dependsOnMethods = "testListInstance")
public void testSetMetadataForInstance() {
Instance originalInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME);
assertZoneOperationDoneSucessfully(api().setMetadataInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME,
ImmutableMap.of(METADATA_ITEM_KEY, METADATA_ITEM_VALUE),
originalInstance.metadata().fingerprint()),
TIME_WAIT);
assertZoneOperationDoneSuccessfully(api().setMetadataInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME,
ImmutableMap.of(METADATA_ITEM_KEY, METADATA_ITEM_VALUE), originalInstance.metadata().fingerprint()),
TIME_WAIT);
Instance modifiedInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME);
@ -150,9 +150,9 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live", dependsOnMethods = "testListInstance")
public void testSetTagsForInstance() {
Instance originalInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME);
assertZoneOperationDoneSucessfully(api().setTagsInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME, TAGS,
originalInstance.tags().fingerprint()),
TIME_WAIT);
assertZoneOperationDoneSuccessfully(
api().setTagsInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME, TAGS, originalInstance.tags().fingerprint()),
TIME_WAIT);
Instance modifiedInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME);
@ -162,15 +162,13 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live", dependsOnMethods = "testSetMetadataForInstance")
public void testAttachDiskToInstance() {
assertZoneOperationDoneSucessfully(diskApi().createInZone(ATTACH_DISK_NAME, 1, DEFAULT_ZONE_NAME), TIME_WAIT);
assertZoneOperationDoneSuccessfully(diskApi().createInZone(ATTACH_DISK_NAME, 1, DEFAULT_ZONE_NAME), TIME_WAIT);
Instance originalInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME);
assertZoneOperationDoneSucessfully(api().attachDiskInZone(DEFAULT_ZONE_NAME, 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);
assertZoneOperationDoneSuccessfully(api().attachDiskInZone(DEFAULT_ZONE_NAME, 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);
@ -188,44 +186,42 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live", dependsOnMethods = "testAttachDiskToInstance")
public void testDetachDiskFromInstance() {
Instance originalInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME);
assertZoneOperationDoneSucessfully(api().detachDiskInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME,
ATTACH_DISK_DEVICE_NAME), TIME_WAIT);
assertZoneOperationDoneSuccessfully(
api().detachDiskInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME, ATTACH_DISK_DEVICE_NAME), TIME_WAIT);
Instance modifiedInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME);
assertTrue(modifiedInstance.disks().size() < originalInstance.disks().size());
assertZoneOperationDoneSucessfully(diskApi().deleteInZone(DEFAULT_ZONE_NAME, ATTACH_DISK_NAME), TIME_WAIT);
assertZoneOperationDoneSuccessfully(diskApi().deleteInZone(DEFAULT_ZONE_NAME, ATTACH_DISK_NAME), TIME_WAIT);
}
@Test(groups = "live", dependsOnMethods = "testInsertInstance")
public void testListInstance() {
PagedIterable<Instance> instances = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder()
Iterator<ListPage<Instance>> instances = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder()
.filter("name eq " + INSTANCE_NAME));
List<Instance> instancesAsList = Lists.newArrayList(instances.concat());
List<Instance> instancesAsList = instances.next();
assertEquals(instancesAsList.size(), 1);
assertInstanceEquals(Iterables.getOnlyElement(instancesAsList), instance);
assertInstanceEquals(instancesAsList.get(0), instance);
}
@Test(groups = "live", dependsOnMethods = "testDetachDiskFromInstance")
public void testResetInstance() {
assertZoneOperationDoneSucessfully(api().resetInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME),
TIME_WAIT);
assertZoneOperationDoneSuccessfully(api().resetInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME), TIME_WAIT);
}
@Test(groups = "live", dependsOnMethods = "testResetInstance")
public void testDeleteInstance() {
assertZoneOperationDoneSucessfully(api().deleteInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME), TIME_WAIT);
assertZoneOperationDoneSucessfully(api.getDiskApi(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME),
TIME_WAIT);
assertZoneOperationDoneSucessfully(api.getDiskApi(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME, BOOT_DISK_NAME),
TIME_WAIT);
assertZoneOperationDoneSuccessfully(api().deleteInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME), TIME_WAIT);
assertZoneOperationDoneSuccessfully(api.getDiskApi(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME),
TIME_WAIT);
assertZoneOperationDoneSuccessfully(
api.getDiskApi(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME, BOOT_DISK_NAME), TIME_WAIT);
assertGlobalOperationDoneSucessfully(api.getNetworkApi(userProject.get()).delete
(INSTANCE_NETWORK_NAME), TIME_WAIT);
}

View File

@ -18,8 +18,8 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.parse.ParseMachineTypeListTest;
@ -95,7 +95,7 @@ public class MachineTypeApiExpectTest extends BaseGoogleComputeEngineApiExpectTe
TOKEN_RESPONSE, LIST_MACHINE_TYPES_REQUEST, LIST_MACHINE_TYPES_RESPONSE).getMachineTypeApi
("myproject");
assertEquals(machineTypeApi.listFirstPageInZone("us-central1-a").toString(),
assertEquals(machineTypeApi.listInZone("us-central1-a").next().toString(),
new ParseMachineTypeListTest().expected().toString());
}
@ -106,6 +106,6 @@ public class MachineTypeApiExpectTest extends BaseGoogleComputeEngineApiExpectTe
MachineTypeApi machineTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, LIST_MACHINE_TYPES_REQUEST, operationResponse).getMachineTypeApi("myproject");
assertTrue(machineTypeApi.listInZone("us-central1-a").concat().isEmpty());
assertFalse(machineTypeApi.listInZone("us-central1-a").hasNext());
}
}

View File

@ -18,21 +18,17 @@ package org.jclouds.googlecomputeengine.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertSame;
import static org.testng.Assert.assertTrue;
import java.util.Iterator;
import java.util.List;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.MachineType;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
public class MachineTypeApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
private MachineType machineType;
@ -43,19 +39,15 @@ public class MachineTypeApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live")
public void testListMachineType() {
PagedIterable<MachineType> machineTypes = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder()
.maxResults(1));
Iterator<IterableWithMarker<MachineType>> pageIterator = machineTypes.iterator();
Iterator<ListPage<MachineType>> pageIterator = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder()
.maxResults(1));
assertTrue(pageIterator.hasNext());
IterableWithMarker<MachineType> singlePageIterator = pageIterator.next();
List<MachineType> machineTypeAsList = singlePageIterator.toList();
List<MachineType> machineTypeAsList = pageIterator.next();
assertSame(machineTypeAsList.size(), 1);
assertEquals(machineTypeAsList.size(), 1);
this.machineType = Iterables.getOnlyElement(machineTypeAsList);
this.machineType = machineTypeAsList.get(0);
}

View File

@ -19,7 +19,7 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertFalse;
import static org.testng.AssertJUnit.assertNull;
import javax.ws.rs.core.MediaType;
@ -138,7 +138,7 @@ public class NetworkApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
NetworkApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, list, operationResponse).getNetworkApi("myproject");
assertEquals(api.listFirstPage().toString(),
assertEquals(api.list().next().toString(),
new ParseNetworkListTest().expected().toString());
}
@ -152,9 +152,9 @@ public class NetworkApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
NetworkApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, list, operationResponse).getNetworkApi("myproject");
NetworkApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, list,
operationResponse).getNetworkApi("myproject");
assertTrue(api.list().concat().isEmpty());
assertFalse(api.list().hasNext());
}
}

View File

@ -19,17 +19,15 @@ package org.jclouds.googlecomputeengine.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.util.Iterator;
import java.util.List;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Network;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
@Test(groups = "live", testName = "NetworkApiLiveTest")
public class NetworkApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@ -43,14 +41,11 @@ public class NetworkApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live")
public void testInsertNetwork() {
assertGlobalOperationDoneSucessfully(api().createInIPv4Range(NETWORK_NAME, IPV4_RANGE), TIME_WAIT);
}
@Test(groups = "live", dependsOnMethods = "testInsertNetwork")
public void testGetNetwork() {
Network network = api().get(NETWORK_NAME);
assertNotNull(network);
assertNetworkEquals(network);
@ -59,14 +54,14 @@ public class NetworkApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live", dependsOnMethods = "testGetNetwork")
public void testListNetwork() {
PagedIterable<Network> networks = api().list(new ListOptions.Builder()
Iterator<ListPage<Network>> networks = api().list(new ListOptions.Builder()
.filter("name eq " + NETWORK_NAME));
List<Network> networksAsList = Lists.newArrayList(networks.concat());
List<Network> networksAsList = networks.next();
assertEquals(networksAsList.size(), 1);
assertNetworkEquals(Iterables.getOnlyElement(networksAsList));
assertNetworkEquals(networksAsList.get(0));
}

View File

@ -18,8 +18,8 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.parse.ParseRegionListTest;
@ -78,8 +78,7 @@ public class RegionApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
RegionApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, LIST_REGIONS_REQ, LIST_REGIONS_RESPONSE).getRegionApi("myproject");
assertEquals(api.listFirstPage().toString(),
new ParseRegionListTest().expected().toString());
assertEquals(api.list().next().toString(), new ParseRegionListTest().expected().toString());
}
public void testListRegionWithPaginationOptionsResponseIs4xx() {
@ -89,6 +88,6 @@ public class RegionApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
RegionApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, LIST_REGIONS_REQ, operationResponse).getRegionApi("myproject");
assertTrue(api.list().concat().isEmpty());
assertFalse(api.list().hasNext());
}
}

View File

@ -18,21 +18,17 @@ package org.jclouds.googlecomputeengine.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertSame;
import static org.testng.Assert.assertTrue;
import java.util.Iterator;
import java.util.List;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Region;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
public class RegionApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
private Region region;
@ -43,19 +39,14 @@ public class RegionApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live")
public void testListRegion() {
PagedIterable<Region> regions = api().list(new ListOptions.Builder()
.maxResults(1));
Iterator<IterableWithMarker<Region>> pageIterator = regions.iterator();
Iterator<ListPage<Region>> pageIterator = api().list(new ListOptions.Builder().maxResults(1));
assertTrue(pageIterator.hasNext());
IterableWithMarker<Region> singlePageIterator = pageIterator.next();
List<Region> regionAsList = singlePageIterator.toList();
List<Region> regionAsList = pageIterator.next();
assertSame(regionAsList.size(), 1);
assertEquals(regionAsList.size(), 1);
this.region = Iterables.getOnlyElement(regionAsList);
this.region = regionAsList.get(0);
}
@Test(groups = "live", dependsOnMethods = "testListRegion")

View File

@ -19,8 +19,8 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
@ -120,8 +120,7 @@ public class RegionOperationApiExpectTest extends BaseGoogleComputeEngineApiExpe
RegionOperationApi regionOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, get, operationResponse).getRegionOperationApi("myproject");
assertEquals(regionOperationApi.listFirstPageInRegion("us-central1").toString(),
expectedList().toString());
assertEquals(regionOperationApi.listInRegion("us-central1").next().toString(), expectedList().toString());
}
public void testListOperationWithPaginationOptionsResponseIs2xx() {
@ -162,6 +161,6 @@ public class RegionOperationApiExpectTest extends BaseGoogleComputeEngineApiExpe
RegionOperationApi regionOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, get, operationResponse).getRegionOperationApi("myproject");
assertTrue(regionOperationApi.listInRegion("us-central1").concat().isEmpty());
assertFalse(regionOperationApi.listInRegion("us-central1").hasNext());
}
}

View File

@ -19,71 +19,48 @@ package org.jclouds.googlecomputeengine.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.Iterator;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.testng.SkipException;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
@Test(groups = "live", testName = "RegionOperationApiLiveTest")
public class RegionOperationApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
private static final String ADDRESS_NAME = "region-operations-api-live-test-address";
private Operation addOperation;
private Operation deleteOperation;
private Operation operation;
private RegionOperationApi api() {
return api.getRegionOperationApi(userProject.get());
}
private AddressApi addressApi() {
return api.getAddressApi(userProject.get());
}
@Test(groups = "live")
public void testCreateOperations() {
//insert some operations by adding and deleting metadata items
// this will make sure there is stuff to listFirstPage
addOperation = assertRegionOperationDoneSucessfully(addressApi().createInRegion(DEFAULT_REGION_NAME,
ADDRESS_NAME), 20);
deleteOperation = assertRegionOperationDoneSucessfully(addressApi().deleteInRegion(DEFAULT_REGION_NAME,
ADDRESS_NAME), 20);
assertNotNull(addOperation);
assertNotNull(deleteOperation);
}
@Test(groups = "live", dependsOnMethods = "testCreateOperations")
public void testGetOperation() {
Operation operation = api().getInRegion(DEFAULT_REGION_NAME, addOperation.name());
assertNotNull(operation);
assertOperationEquals(operation, this.addOperation);
}
@Test(groups = "live", dependsOnMethods = "testCreateOperations")
public void testListOperationsWithFiltersAndPagination() {
PagedIterable<Operation> operations = api().listInRegion(DEFAULT_REGION_NAME, new ListOptions.Builder()
// .filter("operationType eq insert")
.maxResults(1));
Iterator<ListPage<Operation>> operations = api().listInRegion(DEFAULT_REGION_NAME, new ListOptions.Builder()
// .filter("operationType eq insert")
.maxResults(1));
// make sure that in spite of having only one result per page we get at least two results
final AtomicInteger counter = new AtomicInteger();
operations.firstMatch(new Predicate<IterableWithMarker<Operation>>() {
@Override public boolean apply(IterableWithMarker<Operation> input) {
counter.addAndGet(Iterables.size(input));
return counter.get() == 2;
int count = 0;
for (; count < 2 && operations.hasNext(); ) {
ListPage<Operation> result = operations.next();
if (result.isEmpty()) {
operation = result.get(0);
count++;
}
});
}
if (count < 2) {
throw new SkipException("Not enough operations in " + DEFAULT_REGION_NAME);
}
assertEquals(count, 2);
}
private void assertOperationEquals(Operation result, Operation expected) {
assertEquals(result.name(), expected.name());
@Test(groups = "live", dependsOnMethods = "testListOperationsWithFiltersAndPagination")
public void testGetOperation() {
Operation result = api().getInRegion(DEFAULT_REGION_NAME, operation.name());
assertNotNull(result);
assertEquals(result.name(), operation.name()); // Checking state besides name can lead to flaky test.
}
}

View File

@ -19,7 +19,7 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertFalse;
import static org.testng.AssertJUnit.assertNull;
import java.net.URI;
@ -148,8 +148,7 @@ public class RouteApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
RouteApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, list, operationResponse).getRouteApi("myproject");
assertEquals(api.listFirstPage().toString(),
new ParseRouteListTest().expected().toString());
assertEquals(api.list().next().toString(), new ParseRouteListTest().expected().toString());
}
public void testListRoutesResponseIs4xx() {
@ -165,6 +164,6 @@ public class RouteApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
RouteApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, list, operationResponse).getRouteApi("myproject");
assertTrue(api.list().concat().isEmpty());
assertFalse(api.list().hasNext());
}
}

View File

@ -19,18 +19,16 @@ package org.jclouds.googlecomputeengine.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.util.Iterator;
import java.util.List;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Route;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.googlecomputeengine.options.RouteOptions;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
@Test(groups = "live", testName = "RouteApiLiveTest")
public class RouteApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@ -70,15 +68,14 @@ public class RouteApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live", dependsOnMethods = "testGetRoute")
public void testListRoute() {
PagedIterable<Route> routes = api().list(new ListOptions()
Iterator<ListPage<Route>> routes = api().list(new ListOptions()
.filter("name eq " + ROUTE_NAME));
List<Route> routesAsList = Lists.newArrayList(routes.concat());
List<Route> routesAsList = routes.next();
assertEquals(routesAsList.size(), 1);
assertRouteEquals(Iterables.getOnlyElement(routesAsList));
assertRouteEquals(routesAsList.get(0));
}
@Test(groups = "live", dependsOnMethods = "testListRoute")

View File

@ -18,8 +18,8 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.parse.ParseSnapshotListTest;
@ -78,8 +78,7 @@ public class SnapshotApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
SnapshotApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, LIST_SNAPSHOTS_REQ, LIST_SNAPSHOTS_RESPONSE).getSnapshotApi("myproject");
assertEquals(api.listFirstPage().toString(),
new ParseSnapshotListTest().expected().toString());
assertEquals(api.list().next().toString(), new ParseSnapshotListTest().expected().toString());
}
public void testListSnapshotWithPaginationOptionsResponseIs4xx() {
@ -89,6 +88,6 @@ public class SnapshotApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
SnapshotApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, LIST_SNAPSHOTS_REQ, operationResponse).getSnapshotApi("myproject");
assertTrue(api.list().concat().isEmpty());
assertFalse(api.list().hasNext());
}
}

View File

@ -19,18 +19,16 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.features.DiskApiLiveTest.TIME_WAIT;
import static org.testng.Assert.assertEquals;
import java.util.Iterator;
import java.util.List;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.domain.Disk;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Snapshot;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
public class SnapshotApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
private static final String DISK_NAME = "snapshot-api-live-test-disk";
@ -47,11 +45,11 @@ public class SnapshotApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live")
public void testCreateSnapshot() {
assertZoneOperationDoneSucessfully(diskApi().createInZone(DISK_NAME, 1, DEFAULT_ZONE_NAME), TIME_WAIT);
assertZoneOperationDoneSuccessfully(diskApi().createInZone(DISK_NAME, 1, DEFAULT_ZONE_NAME), TIME_WAIT);
disk = diskApi().getInZone(DEFAULT_ZONE_NAME, DISK_NAME);
assertZoneOperationDoneSucessfully(diskApi().createSnapshotInZone(DEFAULT_ZONE_NAME, DISK_NAME, SNAPSHOT_NAME),
TIME_WAIT);
assertZoneOperationDoneSuccessfully(diskApi().createSnapshotInZone(DEFAULT_ZONE_NAME, DISK_NAME, SNAPSHOT_NAME),
TIME_WAIT);
}
@Test(groups = "live", dependsOnMethods = "testCreateSnapshot")
@ -65,20 +63,20 @@ public class SnapshotApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live", dependsOnMethods = "testGetSnapshot")
public void testListSnapshot() {
PagedIterable<Snapshot> snapshots = api().list(new ListOptions.Builder()
Iterator<ListPage<Snapshot>> snapshots = api().list(new ListOptions.Builder()
.filter("name eq " + SNAPSHOT_NAME));
List<Snapshot> snapshotsAsList = Lists.newArrayList(snapshots.concat());
List<Snapshot> snapshotsAsList = snapshots.next();
assertEquals(snapshotsAsList.size(), 1);
assertSnapshotEquals(Iterables.getOnlyElement(snapshotsAsList));
assertSnapshotEquals(snapshotsAsList.get(0));
}
@Test(groups = "live", dependsOnMethods = "testListSnapshot")
public void testDeleteDisk() {
assertZoneOperationDoneSucessfully(diskApi().deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME), TIME_WAIT);
assertZoneOperationDoneSuccessfully(diskApi().deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME), TIME_WAIT);
assertGlobalOperationDoneSucessfully(api().delete(SNAPSHOT_NAME), TIME_WAIT);
}

View File

@ -19,7 +19,7 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertFalse;
import static org.testng.AssertJUnit.assertNull;
import java.net.URI;
@ -171,7 +171,7 @@ public class TargetPoolApiExpectTest extends BaseGoogleComputeEngineApiExpectTes
TargetPoolApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, list, operationResponse).getTargetPoolApi("myproject", "us-central1");
assertTrue(api.list().concat().isEmpty());
assertFalse(api.list().hasNext());
}
public void testAddInstanceResponseIs2xx() throws Exception {

View File

@ -40,6 +40,7 @@ import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Iterables;
public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@ -72,10 +73,10 @@ public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
InstanceApi instanceApi = api.getInstanceApi(userProject.get());
HttpHealthCheckApi httpHealthCheckApi = api.getHttpHealthCheckApi(userProject.get());
ListPage<Image> list = api.getImageApi("centos-cloud").list(new ListOptions.Builder().filter("name eq centos.*"))
.next();
// Get an imageUri
URI imageUri = api.getImageApi("centos-cloud")
.list(new ListOptions.Builder().filter("name eq centos.*"))
.concat()
URI imageUri = FluentIterable.from(list)
.filter(new Predicate<Image>() {
@Override
public boolean apply(Image input) {
@ -103,15 +104,13 @@ public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
// Create a disk.
DiskCreationOptions diskCreationOptions = new DiskCreationOptions().sourceImage(instanceTemplate.image());
assertZoneOperationDoneSucessfully(api.getDiskApi(userProject.get())
.createInZone(BOOT_DISK_NAME, DEFAULT_DISK_SIZE_GB, DEFAULT_ZONE_NAME, diskCreationOptions),
TIME_WAIT_LONG);
assertZoneOperationDoneSuccessfully(api.getDiskApi(userProject.get())
.createInZone(BOOT_DISK_NAME, DEFAULT_DISK_SIZE_GB, DEFAULT_ZONE_NAME, diskCreationOptions),
TIME_WAIT_LONG);
// Create an instance.
assertZoneOperationDoneSucessfully(instanceApi.createInZone(INSTANCE_NAME,
DEFAULT_ZONE_NAME,
instanceTemplate),
TIME_WAIT_LONG);
assertZoneOperationDoneSuccessfully(instanceApi.createInZone(INSTANCE_NAME, DEFAULT_ZONE_NAME, instanceTemplate),
TIME_WAIT_LONG);
Instance instance = instanceApi.getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME);
instances = new ArrayList<URI>();
instances.add(instance.selfLink());

View File

@ -18,8 +18,8 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.parse.ParseZoneListTest;
@ -81,8 +81,7 @@ public class ZoneApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
ZoneApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, LIST_ZONES_REQ, LIST_ZONES_RESPONSE).getZoneApi("myproject");
assertEquals(api.listFirstPage().toString(),
new ParseZoneListTest().expected().toString());
assertEquals(api.list().next().toString(), new ParseZoneListTest().expected().toString());
}
public void testListZoneWithPaginationOptionsResponseIs4xx() {
@ -92,6 +91,6 @@ public class ZoneApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
ZoneApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, LIST_ZONES_REQ, operationResponse).getZoneApi("myproject");
assertTrue(api.list().concat().isEmpty());
assertFalse(api.list().hasNext());
}
}

View File

@ -18,21 +18,17 @@ package org.jclouds.googlecomputeengine.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertSame;
import static org.testng.Assert.assertTrue;
import java.util.Iterator;
import java.util.List;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Zone;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
public class ZoneApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
private Zone zone;
@ -44,18 +40,14 @@ public class ZoneApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live")
public void testListZone() {
PagedIterable<Zone> zones = api().list(new ListOptions.Builder()
.maxResults(1));
Iterator<IterableWithMarker<Zone>> pageIterator = zones.iterator();
Iterator<ListPage<Zone>> pageIterator = api().list(new ListOptions.Builder().maxResults(1));
assertTrue(pageIterator.hasNext());
IterableWithMarker<Zone> singlePageIterator = pageIterator.next();
List<Zone> zoneAsList = singlePageIterator.toList();
List<Zone> zoneAsList = pageIterator.next();
assertSame(zoneAsList.size(), 1);
assertEquals(zoneAsList.size(), 1);
this.zone = Iterables.getOnlyElement(zoneAsList);
this.zone = zoneAsList.get(0);
}

View File

@ -19,8 +19,8 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
@ -118,7 +118,7 @@ public class ZoneOperationApiExpectTest extends BaseGoogleComputeEngineApiExpect
ZoneOperationApi zoneOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, get, operationResponse).getZoneOperationApi("myproject");
assertEquals(zoneOperationApi.listFirstPageInZone("us-central1-a").toString(),
assertEquals(zoneOperationApi.listInZone("us-central1-a").next().toString(),
expectedList().toString());
}
@ -158,9 +158,8 @@ public class ZoneOperationApiExpectTest extends BaseGoogleComputeEngineApiExpect
HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
ZoneOperationApi zoneOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, get, operationResponse).getZoneOperationApi("myproject");
ZoneOperationApi zoneOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, get, operationResponse).getZoneOperationApi("myproject");
assertTrue(zoneOperationApi.listInZone("us-central1-a").concat().isEmpty());
assertFalse(zoneOperationApi.listInZone("us-central1-a").hasNext());
}
}

View File

@ -16,73 +16,51 @@
*/
package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.features.DiskApiLiveTest.TIME_WAIT;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.Iterator;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.testng.SkipException;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
@Test(groups = "live", testName = "ZoneOperationApiLiveTest")
public class ZoneOperationApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
private static final String DISK_NAME = "zone-operations-api-live-test-disk";
private Operation addOperation;
private Operation deleteOperation;
private Operation operation;
private ZoneOperationApi api() {
return api.getZoneOperationApi(userProject.get());
}
private DiskApi diskApi() {
return api.getDiskApi(userProject.get());
}
@Test(groups = "live")
public void testCreateOperations() {
//insert some operations by creating and deleting a disk
// this will make sure there is stuff to listFirstPage
addOperation = assertZoneOperationDoneSucessfully(diskApi().createInZone(DISK_NAME, 1, DEFAULT_ZONE_NAME), TIME_WAIT);
deleteOperation = assertZoneOperationDoneSucessfully(diskApi().deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME), TIME_WAIT);
assertNotNull(addOperation);
assertNotNull(deleteOperation);
}
@Test(groups = "live", dependsOnMethods = "testCreateOperations")
public void testGetOperation() {
Operation operation = api().getInZone(DEFAULT_ZONE_NAME, addOperation.name());
assertNotNull(operation);
assertOperationEquals(operation, this.addOperation);
}
@Test(groups = "live", dependsOnMethods = "testCreateOperations")
public void testListOperationsWithFiltersAndPagination() {
PagedIterable<Operation> operations = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder()
Iterator<ListPage<Operation>> operations = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder()
// .filter("operationType eq insert")
.maxResults(1));
// make sure that in spite of having only one result per page we get at least two results
final AtomicInteger counter = new AtomicInteger();
operations.firstMatch(new Predicate<IterableWithMarker<Operation>>() {
@Override public boolean apply(IterableWithMarker<Operation> input) {
counter.addAndGet(Iterables.size(input));
return counter.get() == 2;
int count = 0;
for (; count < 2 && operations.hasNext(); ) {
ListPage<Operation> result = operations.next();
if (result.isEmpty()) {
operation = result.get(0);
count++;
}
});
}
if (count < 2) {
throw new SkipException("Not enough operations in " + DEFAULT_ZONE_NAME);
}
assertEquals(count, 2);
}
private void assertOperationEquals(Operation result, Operation expected) {
assertEquals(result.name(), expected.name());
@Test(groups = "live", dependsOnMethods = "testListOperationsWithFiltersAndPagination")
public void testGetOperation() {
Operation result = api().getInZone(DEFAULT_ZONE_NAME, operation.name());
assertNotNull(result);
assertEquals(result.name(), operation.name()); // Checking state besides name can lead to flaky test.
}
}

View File

@ -30,6 +30,7 @@ import org.jclouds.apis.BaseApiLiveTest;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.config.UserProject;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
@ -48,7 +49,6 @@ public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest<GoogleCo
protected static final String DEFAULT_ZONE_NAME = "us-central1-a";
protected static final String DEFAULT_REGION_NAME = "us-central1";
protected static final String NETWORK_API_URL_SUFFIX = "/global/networks/";
protected static final String DEFAULT_NETWORK_NAME = "live-test-network";
protected static final String MACHINE_TYPE_API_URL_SUFFIX = "/machineTypes/";
protected static final String DEFAULT_MACHINE_TYPE_NAME = "n1-standard-1";
protected static final String GATEWAY_API_URL_SUFFIX = "/global/gateways/";
@ -85,37 +85,30 @@ public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest<GoogleCo
return injector.getInstance(GoogleComputeEngineApi.class);
}
protected Operation assertGlobalOperationDoneSucessfully(Operation operation, long maxWaitSeconds) {
operation = waitGlobalOperationDone(operation, maxWaitSeconds);
protected void assertGlobalOperationDoneSucessfully(Operation operation, long maxWaitSeconds) {
operation = waitOperationDone(globalOperationDonePredicate, operation, maxWaitSeconds);
assertEquals(operation.status(), Operation.Status.DONE);
assertTrue(operation.errors().isEmpty());
return operation;
}
protected Operation waitGlobalOperationDone(Operation operation, long maxWaitSeconds) {
return waitOperationDone(globalOperationDonePredicate, operation, maxWaitSeconds);
protected void waitGlobalOperationDone(Operation operation, long maxWaitSeconds) {
waitOperationDone(globalOperationDonePredicate, operation, maxWaitSeconds);
}
protected Operation assertRegionOperationDoneSucessfully(Operation operation, long maxWaitSeconds) {
operation = waitRegionOperationDone(operation, maxWaitSeconds);
protected void assertRegionOperationDoneSucessfully(Operation operation, long maxWaitSeconds) {
operation = waitOperationDone(regionOperationDonePredicate, operation, maxWaitSeconds);
assertEquals(operation.status(), Operation.Status.DONE);
assertTrue(operation.errors().isEmpty());
return operation;
}
protected Operation waitRegionOperationDone(Operation operation, long maxWaitSeconds) {
return waitOperationDone(regionOperationDonePredicate, operation, maxWaitSeconds);
}
protected Operation assertZoneOperationDoneSucessfully(Operation operation, long maxWaitSeconds) {
operation = waitZoneOperationDone(operation, maxWaitSeconds);
protected void assertZoneOperationDoneSuccessfully(@Nullable Operation operation, long maxWaitSeconds) {
operation = waitOperationDone(zoneOperationDonePredicate, operation, maxWaitSeconds);
assertEquals(operation.status(), Operation.Status.DONE);
assertTrue(operation.errors().isEmpty());
return operation;
}
protected Operation waitZoneOperationDone(Operation operation, long maxWaitSeconds) {
return waitOperationDone(zoneOperationDonePredicate, operation, maxWaitSeconds);
protected void waitZoneOperationDone(@Nullable Operation operation, long maxWaitSeconds) {
waitOperationDone(zoneOperationDonePredicate, operation, maxWaitSeconds);
}
protected URI getDiskTypeUrl(String project, String zone, String diskType){
@ -130,10 +123,6 @@ public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest<GoogleCo
return URI.create(API_URL_PREFIX + project + ZONE_API_URL_SUFFIX + zone);
}
protected URI getDefaultNetworkUrl(String project) {
return getNetworkUrl(project, DEFAULT_NETWORK_NAME);
}
protected URI getNetworkUrl(String project, String network) {
return URI.create(API_URL_PREFIX + project + NETWORK_API_URL_SUFFIX + network);
}
@ -156,12 +145,14 @@ public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest<GoogleCo
}
protected URI getDiskUrl(String project, String diskName) {
return URI.create(API_URL_PREFIX + project + ZONE_API_URL_SUFFIX
+ DEFAULT_ZONE_NAME + "/disks/" + diskName);
return URI.create(API_URL_PREFIX + project + ZONE_API_URL_SUFFIX + DEFAULT_ZONE_NAME + "/disks/" + diskName);
}
protected static Operation waitOperationDone(Predicate<AtomicReference<Operation>> operationDonePredicate,
Operation operation, long maxWaitSeconds) {
private static Operation waitOperationDone(Predicate<AtomicReference<Operation>> operationDonePredicate,
@Nullable Operation operation, long maxWaitSeconds) {
if (operation == null) { // Null can mean a delete op didn't need to occur.
return null;
}
AtomicReference<Operation> operationReference = Atomics.newReference(operation);
retry(operationDonePredicate, maxWaitSeconds, 1, SECONDS).apply(operationReference);
return operationReference.get();