diff --git a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/Compute.java b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/Compute.java
index 148e0bb88aad..eb96df0eaba9 100644
--- a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/Compute.java
+++ b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/Compute.java
@@ -16,12 +16,17 @@
package com.google.gcloud.compute;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import com.google.common.base.Joiner;
+import com.google.common.base.MoreObjects;
import com.google.common.collect.Sets;
import com.google.gcloud.Page;
import com.google.gcloud.Service;
import com.google.gcloud.spi.ComputeRpc;
+import java.io.Serializable;
+import java.util.Objects;
import java.util.Set;
/**
@@ -45,7 +50,8 @@ enum DiskTypeField {
NAME("name"),
SELF_LINK("selfLink"),
VALID_DISK_SIZE("validDiskSize"),
- ZONE("zone");
+ ZONE("zone"),
+ DEPRECATED("deprecated");
private final String selector;
@@ -76,7 +82,7 @@ static String selector(DiskTypeField... fields) {
enum MachineTypeField {
CREATION_TIMESTAMP("creationTimestamp"),
DESCRIPTION("description"),
- GUEST_CPUS("cpus"),
+ GUEST_CPUS("guestCpus"),
ID("id"),
IMAGE_SPACE_GB("imageSpaceGb"),
MAXIMUM_PERSISTENT_DISKS("maximumPersistentDisks"),
@@ -84,9 +90,9 @@ enum MachineTypeField {
MEMORY_MB("memoryMb"),
NAME("name"),
SCRATCH_DISKS("scratchDisks"),
- DISK_GB("diskGb"),
SELF_LINK("selfLink"),
- ZONE("zone");
+ ZONE("zone"),
+ DEPRECATED("deprecated");
private final String selector;
@@ -122,7 +128,8 @@ enum RegionField {
QUOTAS("quotas"),
SELF_LINK("selfLink"),
STATUS("status"),
- ZONES("zones");
+ ZONES("zones"),
+ DEPRECATED("deprecated");
private final String selector;
@@ -158,7 +165,8 @@ enum ZoneField {
NAME("name"),
REGION("region"),
SELF_LINK("selfLink"),
- STATUS("status");
+ STATUS("status"),
+ DEPRECATED("deprecated");
private final String selector;
@@ -211,6 +219,223 @@ static String selector(LicenseField... fields) {
}
}
+ /**
+ * Base class for list filters.
+ */
+ abstract class ListFilter implements Serializable {
+
+ private static final long serialVersionUID = -238638392811165127L;
+
+ private final String field;
+ private final ComparisonOperator operator;
+ private final Object value;
+
+ enum ComparisonOperator {
+ /**
+ * Defines an equality filter.
+ */
+ EQ,
+
+ /**
+ * Defines an inequality filter.
+ */
+ NE
+ }
+
+ ListFilter(String field, ComparisonOperator operator, Object value) {
+ this.field = field;
+ this.operator = operator;
+ this.value = value;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(field, operator, value);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return obj instanceof ListFilter && toPb().equals(((ListFilter) obj).toPb());
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("field", field)
+ .add("operator", operator)
+ .add("value", value)
+ .toString();
+ }
+
+ String toPb() {
+ return field + ' ' + operator.name().toLowerCase() + ' ' + value.toString();
+ }
+ }
+
+ /**
+ * Class for filtering disk type lists.
+ */
+ class DiskTypeFilter extends ListFilter {
+
+ private static final long serialVersionUID = 4847837203592234453L;
+
+ DiskTypeFilter(DiskTypeField field, ComparisonOperator operator, Object value) {
+ super(field.selector(), operator, value);
+ }
+
+ /**
+ * Returns an equality filter for the given field and string value. For string fields,
+ * {@code value} is interpreted as a regular expression using RE2 syntax. {@code value} must
+ * match the entire field.
+ *
+ * @see RE2
+ */
+ public static DiskTypeFilter equals(DiskTypeField field, String value) {
+ return new DiskTypeFilter(checkNotNull(field), ComparisonOperator.EQ, checkNotNull(value));
+ }
+
+ /**
+ * Returns an equality filter for the given field and string value. For string fields,
+ * {@code value} is interpreted as a regular expression using RE2 syntax. {@code value} must
+ * match the entire field.
+ *
+ * @see RE2
+ */
+ public static DiskTypeFilter notEquals(DiskTypeField field, String value) {
+ return new DiskTypeFilter(checkNotNull(field), ComparisonOperator.NE, checkNotNull(value));
+ }
+
+ /**
+ * Returns an equality filter for the given field and long value.
+ */
+ public static DiskTypeFilter equals(DiskTypeField field, long value) {
+ return new DiskTypeFilter(checkNotNull(field), ComparisonOperator.EQ, value);
+ }
+
+ /**
+ * Returns an inequality filter for the given field and long value.
+ */
+ public static DiskTypeFilter notEquals(DiskTypeField field, long value) {
+ return new DiskTypeFilter(checkNotNull(field), ComparisonOperator.NE, value);
+ }
+ }
+
+ /**
+ * Class for filtering machine type lists.
+ */
+ class MachineTypeFilter extends ListFilter {
+
+ private static final long serialVersionUID = 7346062041571853235L;
+
+ MachineTypeFilter(MachineTypeField field, ComparisonOperator operator, Object value) {
+ super(field.selector(), operator, value);
+ }
+
+ /**
+ * Returns an equality filter for the given field and string value. For string fields,
+ * {@code value} is interpreted as a regular expression using RE2 syntax. {@code value} must
+ * match the entire field.
+ *
+ * @see RE2
+ */
+ public static MachineTypeFilter equals(MachineTypeField field, String value) {
+ return new MachineTypeFilter(checkNotNull(field), ComparisonOperator.EQ, checkNotNull(value));
+ }
+
+ /**
+ * Returns an equality filter for the given field and string value. For string fields,
+ * {@code value} is interpreted as a regular expression using RE2 syntax. {@code value} must
+ * match the entire field.
+ *
+ * @see RE2
+ */
+ public static MachineTypeFilter notEquals(MachineTypeField field, String value) {
+ return new MachineTypeFilter(checkNotNull(field), ComparisonOperator.NE, checkNotNull(value));
+ }
+
+ /**
+ * Returns an equality filter for the given field and long value.
+ */
+ public static MachineTypeFilter equals(MachineTypeField field, long value) {
+ return new MachineTypeFilter(checkNotNull(field), ComparisonOperator.EQ, value);
+ }
+
+ /**
+ * Returns an inequality filter for the given field and long value.
+ */
+ public static MachineTypeFilter notEquals(MachineTypeField field, long value) {
+ return new MachineTypeFilter(checkNotNull(field), ComparisonOperator.NE, value);
+ }
+ }
+
+ /**
+ * Class for filtering region lists.
+ */
+ class RegionFilter extends ListFilter {
+
+ private static final long serialVersionUID = 4464892812442567172L;
+
+ RegionFilter(RegionField field, ComparisonOperator operator, Object value) {
+ super(field.selector(), operator, value);
+ }
+
+ /**
+ * Returns an equality filter for the given field and string value. For string fields,
+ * {@code value} is interpreted as a regular expression using RE2 syntax. {@code value} must
+ * match the entire field.
+ *
+ * @see RE2
+ */
+ public static RegionFilter equals(RegionField field, String value) {
+ return new RegionFilter(checkNotNull(field), ComparisonOperator.EQ, value);
+ }
+
+ /**
+ * Returns an equality filter for the given field and string value. For string fields,
+ * {@code value} is interpreted as a regular expression using RE2 syntax. {@code value} must
+ * match the entire field.
+ *
+ * @see RE2
+ */
+ public static RegionFilter notEquals(RegionField field, String value) {
+ return new RegionFilter(checkNotNull(field), ComparisonOperator.NE, checkNotNull(value));
+ }
+ }
+
+ /**
+ * Class for filtering zone lists.
+ */
+ class ZoneFilter extends ListFilter {
+
+ private static final long serialVersionUID = -3927428278548808737L;
+
+ ZoneFilter(ZoneField field, ComparisonOperator operator, Object value) {
+ super(field.selector(), operator, value);
+ }
+
+ /**
+ * Returns an equality filter for the given field and string value. For string fields,
+ * {@code value} is interpreted as a regular expression using RE2 syntax. {@code value} must
+ * match the entire field.
+ *
+ * @see RE2
+ */
+ public static ZoneFilter equals(ZoneField field, String value) {
+ return new ZoneFilter(checkNotNull(field), ComparisonOperator.EQ, checkNotNull(value));
+ }
+
+ /**
+ * Returns an equality filter for the given field and string value. For string fields,
+ * {@code value} is interpreted as a regular expression using RE2 syntax. {@code value} must
+ * match the entire field.
+ *
+ * @see RE2
+ */
+ public static ZoneFilter notEquals(ZoneField field, String value) {
+ return new ZoneFilter(checkNotNull(field), ComparisonOperator.NE, checkNotNull(value));
+ }
+ }
+
/**
* Class for specifying disk type get options.
*/
@@ -244,6 +469,13 @@ private DiskTypeListOption(ComputeRpc.Option option, Object value) {
super(option, value);
}
+ /**
+ * Returns an option to specify a filter to the disk types being listed.
+ */
+ public static DiskTypeListOption filter(DiskTypeFilter filter) {
+ return new DiskTypeListOption(ComputeRpc.Option.FILTER, filter.toPb());
+ }
+
/**
* Returns an option to specify the maximum number of disk types to be returned.
*/
@@ -271,6 +503,39 @@ public static DiskTypeListOption fields(DiskTypeField... fields) {
}
}
+ /**
+ * Class for specifying disk type aggregated list options.
+ */
+ class DiskTypeAggregatedListOption extends Option {
+
+ private static final long serialVersionUID = 7611137483018305170L;
+
+ private DiskTypeAggregatedListOption(ComputeRpc.Option option, Object value) {
+ super(option, value);
+ }
+
+ /**
+ * Returns an option to specify a filter to the disk types being listed.
+ */
+ public static DiskTypeAggregatedListOption filter(DiskTypeFilter filter) {
+ return new DiskTypeAggregatedListOption(ComputeRpc.Option.FILTER, filter.toPb());
+ }
+
+ /**
+ * Returns an option to specify the maximum number of disk types to be returned.
+ */
+ public static DiskTypeAggregatedListOption maxResults(long maxResults) {
+ return new DiskTypeAggregatedListOption(ComputeRpc.Option.MAX_RESULTS, maxResults);
+ }
+
+ /**
+ * Returns an option to specify the page token from which to start listing disk types.
+ */
+ public static DiskTypeAggregatedListOption startPageToken(String pageToken) {
+ return new DiskTypeAggregatedListOption(ComputeRpc.Option.PAGE_TOKEN, pageToken);
+ }
+ }
+
/**
* Class for specifying machine type get options.
*/
@@ -304,6 +569,13 @@ private MachineTypeListOption(ComputeRpc.Option option, Object value) {
super(option, value);
}
+ /**
+ * Returns an option to specify a filter to the machine types being listed.
+ */
+ public static MachineTypeListOption filter(MachineTypeFilter filter) {
+ return new MachineTypeListOption(ComputeRpc.Option.FILTER, filter.toPb());
+ }
+
/**
* Returns an option to specify the maximum number of machine types to be returned.
*/
@@ -331,6 +603,39 @@ public static MachineTypeListOption fields(MachineTypeField... fields) {
}
}
+ /**
+ * Class for specifying machine type aggregated list options.
+ */
+ class MachineTypeAggregatedListOption extends Option {
+
+ private static final long serialVersionUID = 8492257475500296057L;
+
+ private MachineTypeAggregatedListOption(ComputeRpc.Option option, Object value) {
+ super(option, value);
+ }
+
+ /**
+ * Returns an option to specify a filter to the machine types being listed.
+ */
+ public static MachineTypeAggregatedListOption filter(MachineTypeFilter filter) {
+ return new MachineTypeAggregatedListOption(ComputeRpc.Option.FILTER, filter.toPb());
+ }
+
+ /**
+ * Returns an option to specify the maximum number of machine types to be returned.
+ */
+ public static MachineTypeAggregatedListOption maxResults(long maxResults) {
+ return new MachineTypeAggregatedListOption(ComputeRpc.Option.MAX_RESULTS, maxResults);
+ }
+
+ /**
+ * Returns an option to specify the page token from which to start listing machine types.
+ */
+ public static MachineTypeAggregatedListOption startPageToken(String pageToken) {
+ return new MachineTypeAggregatedListOption(ComputeRpc.Option.PAGE_TOKEN, pageToken);
+ }
+ }
+
/**
* Class for specifying region get options.
*/
@@ -364,6 +669,13 @@ private RegionListOption(ComputeRpc.Option option, Object value) {
super(option, value);
}
+ /**
+ * Returns an option to specify a filter to the regions being listed.
+ */
+ public static RegionListOption filter(RegionFilter filter) {
+ return new RegionListOption(ComputeRpc.Option.FILTER, filter.toPb());
+ }
+
/**
* Returns an option to specify the maximum number of regions to be returned.
*/
@@ -424,6 +736,13 @@ private ZoneListOption(ComputeRpc.Option option, Object value) {
super(option, value);
}
+ /**
+ * Returns an option to specify a filter to the zones being listed.
+ */
+ public static ZoneListOption filter(ZoneFilter filter) {
+ return new ZoneListOption(ComputeRpc.Option.FILTER, filter.toPb());
+ }
+
/**
* Returns an option to specify the maximum number of zones to be returned.
*/
@@ -478,100 +797,96 @@ public static LicenseOption fields(LicenseField... fields) {
*
* @throws ComputeException upon failure
*/
- DiskType getDiskType(DiskTypeId diskTypeId, DiskTypeOption... options) throws ComputeException;
+ DiskType getDiskType(DiskTypeId diskTypeId, DiskTypeOption... options);
/**
* Returns the requested disk type or {@code null} if not found.
*
* @throws ComputeException upon failure
*/
- DiskType getDiskType(String zone, String diskType, DiskTypeOption... options)
- throws ComputeException;
+ DiskType getDiskType(String zone, String diskType, DiskTypeOption... options);
/**
- * Lists the disk types in the provided zone available to the current project.
+ * Lists the disk types in the provided zone.
*
* @throws ComputeException upon failure
*/
- Page listDiskTypes(String zone, DiskTypeListOption... options) throws ComputeException;
+ Page listDiskTypes(String zone, DiskTypeListOption... options);
/**
- * Lists all disk types available to the current project.
+ * Lists all disk types.
*
* @throws ComputeException upon failure
*/
- Page listDiskTypes(DiskTypeListOption... options) throws ComputeException;
+ Page listDiskTypes(DiskTypeAggregatedListOption... options);
/**
* Returns the requested machine type or {@code null} if not found.
*
* @throws ComputeException upon failure
*/
- MachineType getMachineType(MachineTypeId machineTypeId, MachineTypeOption... options)
- throws ComputeException;
+ MachineType getMachineType(MachineTypeId machineTypeId, MachineTypeOption... options);
/**
* Returns the requested machine type or {@code null} if not found.
*
* @throws ComputeException upon failure
*/
- MachineType getMachineType(String zone, String machineType, MachineTypeOption... options)
- throws ComputeException;
+ MachineType getMachineType(String zone, String machineType, MachineTypeOption... options);
/**
- * Lists the machine types in the provided zone available to the current project.
+ * Lists the machine types in the provided zone.
*
* @throws ComputeException upon failure
*/
- Page listMachineTypes(String zone, MachineTypeListOption... options)
- throws ComputeException;
+ Page listMachineTypes(String zone, MachineTypeListOption... options);
/**
- * Lists all machine types available to the current project.
+ * Lists all machine types.
*
* @throws ComputeException upon failure
*/
- Page listMachineTypes(MachineTypeListOption... options) throws ComputeException;
+ Page listMachineTypes(MachineTypeAggregatedListOption... options);
/**
* Returns the requested region or {@code null} if not found.
*
* @throws ComputeException upon failure
*/
- Region getRegion(String region, RegionOption... options) throws ComputeException;
+ Region getRegion(String region, RegionOption... options);
/**
- * Lists the regions available to the current project.
+ * Lists the regions.
*
* @throws ComputeException upon failure
*/
- Page listRegions(RegionListOption... options) throws ComputeException;
+ Page listRegions(RegionListOption... options);
/**
* Returns the requested zone or {@code null} if not found.
*
* @throws ComputeException upon failure
*/
- Zone getZone(String zone, ZoneOption... options) throws ComputeException;
+ Zone getZone(String zone, ZoneOption... options);
/**
- * Lists the zones available to the current project.
+ * Lists the zones.
*
* @throws ComputeException upon failure
*/
- Page listZones(ZoneListOption... options) throws ComputeException;
+ Page listZones(ZoneListOption... options);
/**
* Returns the requested license or {@code null} if not found.
*
* @throws ComputeException upon failure
*/
- License getLicense(String license, LicenseOption... options) throws ComputeException;
+ License getLicense(String license, LicenseOption... options);
/**
* Returns the requested license or {@code null} if not found.
*
* @throws ComputeException upon failure
*/
- License getLicense(LicenseId license, LicenseOption... options) throws ComputeException;
+ License getLicense(LicenseId license, LicenseOption... options);
}
diff --git a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/ComputeImpl.java b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/ComputeImpl.java
index 2aa54d55e90e..2087e570a349 100644
--- a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/ComputeImpl.java
+++ b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/ComputeImpl.java
@@ -161,8 +161,7 @@ public Page nextPage() {
}
@Override
- public DiskType getDiskType(final DiskTypeId diskTypeId, DiskTypeOption... options)
- throws ComputeException {
+ public DiskType getDiskType(final DiskTypeId diskTypeId, DiskTypeOption... options) {
final Map optionsMap = optionMap(options);
try {
com.google.api.services.compute.model.DiskType answer =
@@ -179,14 +178,12 @@ public com.google.api.services.compute.model.DiskType call() {
}
@Override
- public DiskType getDiskType(String zone, String diskType, DiskTypeOption... options)
- throws ComputeException {
+ public DiskType getDiskType(String zone, String diskType, DiskTypeOption... options) {
return getDiskType(DiskTypeId.of(zone, diskType), options);
}
@Override
- public Page listDiskTypes(String zone, DiskTypeListOption... options)
- throws ComputeException {
+ public Page listDiskTypes(String zone, DiskTypeListOption... options) {
return listDiskTypes(zone, options(), optionMap(options));
}
@@ -220,7 +217,7 @@ public DiskType apply(com.google.api.services.compute.model.DiskType diskType) {
}
@Override
- public Page listDiskTypes(DiskTypeListOption... options) throws ComputeException {
+ public Page listDiskTypes(DiskTypeAggregatedListOption... options) {
return listDiskTypes(options(), optionMap(options));
}
@@ -252,15 +249,14 @@ public DiskType apply(com.google.api.services.compute.model.DiskType diskType) {
}
@Override
- public MachineType getMachineType(final MachineTypeId machineTypeId, MachineTypeOption... options)
- throws ComputeException {
+ public MachineType getMachineType(final MachineTypeId machineType, MachineTypeOption... options) {
final Map optionsMap = optionMap(options);
try {
com.google.api.services.compute.model.MachineType answer =
runWithRetries(new Callable() {
@Override
public com.google.api.services.compute.model.MachineType call() {
- return computeRpc.getMachineType(machineTypeId.zone(), machineTypeId.machineType(),
+ return computeRpc.getMachineType(machineType.zone(), machineType.machineType(),
optionsMap);
}
}, options().retryParams(), EXCEPTION_HANDLER);
@@ -271,14 +267,12 @@ public com.google.api.services.compute.model.MachineType call() {
}
@Override
- public MachineType getMachineType(String zone, String machineType, MachineTypeOption... options)
- throws ComputeException {
+ public MachineType getMachineType(String zone, String machineType, MachineTypeOption... options) {
return getMachineType(MachineTypeId.of(zone, machineType), options);
}
@Override
- public Page listMachineTypes(String zone, MachineTypeListOption... options)
- throws ComputeException {
+ public Page listMachineTypes(String zone, MachineTypeListOption... options) {
return listMachineTypes(zone, options(), optionMap(options));
}
@@ -313,8 +307,7 @@ public MachineType apply(
}
@Override
- public Page listMachineTypes(MachineTypeListOption... options)
- throws ComputeException {
+ public Page listMachineTypes(MachineTypeAggregatedListOption... options) {
return listMachineTypes(options(), optionMap(options));
}
@@ -348,7 +341,7 @@ public MachineType apply(
}
@Override
- public Region getRegion(final String region, RegionOption... options) throws ComputeException {
+ public Region getRegion(final String region, RegionOption... options) {
final Map optionsMap = optionMap(options);
try {
com.google.api.services.compute.model.Region answer =
@@ -365,7 +358,7 @@ public com.google.api.services.compute.model.Region call() {
}
@Override
- public Page listRegions(RegionListOption... options) throws ComputeException {
+ public Page listRegions(RegionListOption... options) {
return listRegions(options(), optionMap(options));
}
@@ -399,7 +392,7 @@ public Region apply(com.google.api.services.compute.model.Region region) {
}
@Override
- public Zone getZone(final String zone, ZoneOption... options) throws ComputeException {
+ public Zone getZone(final String zone, ZoneOption... options) {
final Map optionsMap = optionMap(options);
try {
com.google.api.services.compute.model.Zone answer =
@@ -416,7 +409,7 @@ public com.google.api.services.compute.model.Zone call() {
}
@Override
- public Page listZones(ZoneListOption... options) throws ComputeException {
+ public Page listZones(ZoneListOption... options) {
return listZones(options(), optionMap(options));
}
@@ -449,14 +442,12 @@ public Zone apply(com.google.api.services.compute.model.Zone zone) {
}
@Override
- public License getLicense(String license, LicenseOption... options)
- throws ComputeException {
+ public License getLicense(String license, LicenseOption... options) {
return getLicense(LicenseId.of(license), options);
}
@Override
- public License getLicense(LicenseId license, LicenseOption... options)
- throws ComputeException {
+ public License getLicense(LicenseId license, LicenseOption... options) {
final LicenseId completeId = license.setProjectId(options().projectId());
final Map optionsMap = optionMap(options);
try {
diff --git a/gcloud-java-compute/src/main/java/com/google/gcloud/spi/ComputeRpc.java b/gcloud-java-compute/src/main/java/com/google/gcloud/spi/ComputeRpc.java
index 4668756e04cb..35524e0c116d 100644
--- a/gcloud-java-compute/src/main/java/com/google/gcloud/spi/ComputeRpc.java
+++ b/gcloud-java-compute/src/main/java/com/google/gcloud/spi/ComputeRpc.java
@@ -90,81 +90,75 @@ public Y y() {
*
* @throws ComputeException upon failure
*/
- DiskType getDiskType(String zone, String diskType, Map