Skip to content

Commit

Permalink
Fix minor issues with functional snapshot methods and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard committed Mar 24, 2016
1 parent fe57d61 commit d86ede9
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ class DiskTypeFilter extends ListFilter {

private static final long serialVersionUID = 4847837203592234453L;

DiskTypeFilter(DiskTypeField field, ComparisonOperator operator, Object value) {
private DiskTypeFilter(DiskTypeField field, ComparisonOperator operator, Object value) {
super(field.selector(), operator, value);
}

Expand Down Expand Up @@ -630,7 +630,7 @@ class MachineTypeFilter extends ListFilter {

private static final long serialVersionUID = 7346062041571853235L;

MachineTypeFilter(MachineTypeField field, ComparisonOperator operator, Object value) {
private MachineTypeFilter(MachineTypeField field, ComparisonOperator operator, Object value) {
super(field.selector(), operator, value);
}

Expand Down Expand Up @@ -678,7 +678,7 @@ class RegionFilter extends ListFilter {

private static final long serialVersionUID = 4464892812442567172L;

RegionFilter(RegionField field, ComparisonOperator operator, Object value) {
private RegionFilter(RegionField field, ComparisonOperator operator, Object value) {
super(field.selector(), operator, value);
}

Expand Down Expand Up @@ -712,7 +712,7 @@ class ZoneFilter extends ListFilter {

private static final long serialVersionUID = -3927428278548808737L;

ZoneFilter(ZoneField field, ComparisonOperator operator, Object value) {
private ZoneFilter(ZoneField field, ComparisonOperator operator, Object value) {
super(field.selector(), operator, value);
}

Expand Down Expand Up @@ -746,7 +746,7 @@ class OperationFilter extends ListFilter {

private static final long serialVersionUID = -3202249202748346427L;

OperationFilter(OperationField field, ComparisonOperator operator, Object value) {
private OperationFilter(OperationField field, ComparisonOperator operator, Object value) {
super(field.selector(), operator, value);
}

Expand Down Expand Up @@ -794,7 +794,7 @@ class AddressFilter extends ListFilter {

private static final long serialVersionUID = -227481644259653765L;

AddressFilter(AddressField field, ComparisonOperator operator, Object value) {
private AddressFilter(AddressField field, ComparisonOperator operator, Object value) {
super(field.selector(), operator, value);
}

Expand Down Expand Up @@ -828,12 +828,12 @@ class SnapshotFilter extends ListFilter {

private static final long serialVersionUID = 8757711630092406747L;

SnapshotFilter(SnapshotField field, ComparisonOperator operator, Object value) {
private SnapshotFilter(SnapshotField field, ComparisonOperator operator, Object value) {
super(field.selector(), operator, value);
}

/**
* Returns an equality filter for the given field and string value. For string fields,
* Returns an equals 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.
*
Expand All @@ -855,7 +855,7 @@ public static SnapshotFilter notEquals(SnapshotField field, String value) {
}

/**
* Returns an equality filter for the given field and long value.
* Returns an equals filter for the given field and long value.
*/
public static SnapshotFilter equals(SnapshotField field, long value) {
return new SnapshotFilter(checkNotNull(field), ComparisonOperator.EQ, value);
Expand Down Expand Up @@ -911,6 +911,7 @@ public static DiskTypeListOption filter(DiskTypeFilter filter) {

/**
* Returns an option to specify the maximum number of disk types returned per page.
* {@code pageSize} must be between 0 and 500 (inclusive). If not specified 500 is used.
*/
public static DiskTypeListOption pageSize(long pageSize) {
return new DiskTypeListOption(ComputeRpc.Option.MAX_RESULTS, pageSize);
Expand Down Expand Up @@ -956,6 +957,7 @@ public static DiskTypeAggregatedListOption filter(DiskTypeFilter filter) {

/**
* Returns an option to specify the maximum number of disk types returned per page.
* {@code pageSize} must be between 0 and 500 (inclusive). If not specified 500 is used.
*/
public static DiskTypeAggregatedListOption pageSize(long pageSize) {
return new DiskTypeAggregatedListOption(ComputeRpc.Option.MAX_RESULTS, pageSize);
Expand Down Expand Up @@ -1011,6 +1013,7 @@ public static MachineTypeListOption filter(MachineTypeFilter filter) {

/**
* Returns an option to specify the maximum number of machine types returned per page.
* {@code pageSize} must be between 0 and 500 (inclusive). If not specified 500 is used.
*/
public static MachineTypeListOption pageSize(long pageSize) {
return new MachineTypeListOption(ComputeRpc.Option.MAX_RESULTS, pageSize);
Expand Down Expand Up @@ -1056,6 +1059,7 @@ public static MachineTypeAggregatedListOption filter(MachineTypeFilter filter) {

/**
* Returns an option to specify the maximum number of machine types returned per page.
* {@code pageSize} must be between 0 and 500 (inclusive). If not specified 500 is used.
*/
public static MachineTypeAggregatedListOption pageSize(long pageSize) {
return new MachineTypeAggregatedListOption(ComputeRpc.Option.MAX_RESULTS, pageSize);
Expand Down Expand Up @@ -1111,6 +1115,7 @@ public static RegionListOption filter(RegionFilter filter) {

/**
* Returns an option to specify the maximum number of regions returned per page.
* {@code pageSize} must be between 0 and 500 (inclusive). If not specified 500 is used.
*/
public static RegionListOption pageSize(long pageSize) {
return new RegionListOption(ComputeRpc.Option.MAX_RESULTS, pageSize);
Expand Down Expand Up @@ -1178,6 +1183,7 @@ public static ZoneListOption filter(ZoneFilter filter) {

/**
* Returns an option to specify the maximum number of zones returned per page.
* {@code pageSize} must be between 0 and 500 (inclusive). If not specified 500 is used.
*/
public static ZoneListOption pageSize(long pageSize) {
return new ZoneListOption(ComputeRpc.Option.MAX_RESULTS, pageSize);
Expand Down Expand Up @@ -1267,6 +1273,7 @@ public static OperationListOption filter(OperationFilter filter) {

/**
* Returns an option to specify the maximum number of operations returned per page.
* {@code pageSize} must be between 0 and 500 (inclusive). If not specified 500 is used.
*/
public static OperationListOption pageSize(long pageSize) {
return new OperationListOption(ComputeRpc.Option.MAX_RESULTS, pageSize);
Expand Down Expand Up @@ -1334,6 +1341,7 @@ public static AddressListOption filter(AddressFilter filter) {

/**
* Returns an option to specify the maximum number of addresses returned per page.
* {@code pageSize} must be between 0 and 500 (inclusive). If not specified 500 is used.
*/
public static AddressListOption pageSize(long pageSize) {
return new AddressListOption(ComputeRpc.Option.MAX_RESULTS, pageSize);
Expand Down Expand Up @@ -1379,6 +1387,7 @@ public static AddressAggregatedListOption filter(AddressFilter filter) {

/**
* Returns an option to specify the maximum number of addresses returned per page.
* {@code pageSize} must be between 0 and 500 (inclusive). If not specified 500 is used.
*/
public static AddressAggregatedListOption pageSize(long pageSize) {
return new AddressAggregatedListOption(ComputeRpc.Option.MAX_RESULTS, pageSize);
Expand All @@ -1405,8 +1414,8 @@ private SnapshotOption(ComputeRpc.Option option, Object value) {

/**
* Returns an option to specify the snapshot's fields to be returned by the RPC call. If this
* option is not provided, all snapshot's fields are returned. {@code SnapshotOption.fields} can
* be used to specify only the fields of interest. {@link Snapshot#snapshotId()} is always
* option is not provided, all the snapshot's fields are returned. {@code SnapshotOption.fields}
* can be used to specify only the fields of interest. {@link Snapshot#snapshotId()} is always
* returned, even if not specified.
*/
public static SnapshotOption fields(SnapshotField... fields) {
Expand Down Expand Up @@ -1434,6 +1443,7 @@ public static SnapshotListOption filter(SnapshotFilter filter) {

/**
* Returns an option to specify the maximum number of snapshots returned per page.
* {@code pageSize} must be between 0 and 500 (inclusive). If not specified 500 is used.
*/
public static SnapshotListOption pageSize(long pageSize) {
return new SnapshotListOption(ComputeRpc.Option.MAX_RESULTS, pageSize);
Expand All @@ -1448,9 +1458,9 @@ public static SnapshotListOption pageToken(String pageToken) {

/**
* Returns an option to specify the snapshot's fields to be returned by the RPC call. If this
* option is not provided, all snapshot's fields are returned. {@code SnapshotListOption.fields}
* can be used to specify only the fields of interest. {@link Snapshot#snapshotId()} is always
* returned, even if not specified.
* option is not provided, all the snapshot's fields are returned.
* {@code SnapshotListOption.fields} can be used to specify only the fields of interest.
* {@link Snapshot#snapshotId()} is always returned, even if not specified.
*/
public static SnapshotListOption fields(SnapshotField... fields) {
StringBuilder builder = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ public com.google.api.services.compute.model.Operation call() {
}

@Override
public Operation create(SnapshotInfo snapshot, final OperationOption... options) {
public Operation create(SnapshotInfo snapshot, OperationOption... options) {
final SnapshotInfo completeSnapshot = snapshot.setProjectId(options().projectId());
final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options);
try {
Expand Down Expand Up @@ -1005,14 +1005,20 @@ public Snapshot apply(com.google.api.services.compute.model.Snapshot snapshot) {
}

@Override
public Operation deleteSnapshot(final SnapshotId snapshot, OperationOption... options) {
public Operation deleteSnapshot(SnapshotId snapshot, OperationOption... options) {
return deleteSnapshot(snapshot.snapshot(), options);

}

@Override
public Operation deleteSnapshot(final String snapshot, OperationOption... options) {
final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options);
try {
com.google.api.services.compute.model.Operation answer =
runWithRetries(new Callable<com.google.api.services.compute.model.Operation>() {
@Override
public com.google.api.services.compute.model.Operation call() {
return computeRpc.deleteSnapshot(snapshot.snapshot(), optionsMap);
return computeRpc.deleteSnapshot(snapshot, optionsMap);
}
}, options().retryParams(), EXCEPTION_HANDLER);
return answer == null ? null : Operation.fromPb(this, answer);
Expand All @@ -1021,11 +1027,6 @@ public com.google.api.services.compute.model.Operation call() {
}
}

@Override
public Operation deleteSnapshot(final String snapshot, OperationOption... options) {
return deleteSnapshot(SnapshotId.of(snapshot));
}

private Map<ComputeRpc.Option, ?> optionMap(Option... options) {
Map<ComputeRpc.Option, Object> optionMap = Maps.newEnumMap(ComputeRpc.Option.class);
for (Option option : options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.gcloud.compute.Compute.OperationOption;
import com.google.gcloud.compute.Compute.SnapshotOption;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.List;
Expand All @@ -28,7 +31,7 @@
* disk and create new persistent disks from that snapshot. This can be useful for backing up data,
* recreating a persistent disk that might have been lost, or copying a persistent disk. Snapshots
* can be applied across persistent disk types. {@code Snapshot} adds a layer of service-related
* functionality over {@link SnapshotInfo}. Obejcts of this class are immutable, to get a
* functionality over {@link SnapshotInfo}. Objects of this class are immutable; to get a
* {@code Snapshot} object with the most recent information use {@link #reload}.
*
* @see <a href="https://cloud.google.com/compute/docs/disks/persistent-disks#snapshots">Use
Expand Down Expand Up @@ -146,7 +149,7 @@ public Snapshot build() {
* @throws ComputeException upon failure
*/
public boolean exists() {
return reload(Compute.SnapshotOption.fields()) != null;
return reload(SnapshotOption.fields()) != null;
}

/**
Expand All @@ -157,7 +160,7 @@ public boolean exists() {
* @return a {@code Snapshot} object with latest information or {@code null} if not found
* @throws ComputeException upon failure
*/
public Snapshot reload(Compute.SnapshotOption... options) {
public Snapshot reload(SnapshotOption... options) {
return compute.getSnapshot(snapshotId().snapshot(), options);
}

Expand All @@ -168,7 +171,7 @@ public Snapshot reload(Compute.SnapshotOption... options) {
* snapshot was not found
* @throws ComputeException upon failure
*/
public Operation delete(Compute.OperationOption... options) {
public Operation delete(OperationOption... options) {
return compute.deleteSnapshot(snapshotId(), options);
}

Expand Down
Loading

0 comments on commit d86ede9

Please sign in to comment.