Skip to content

Commit d86ede9

Browse files
committed
Fix minor issues with functional snapshot methods and tests
1 parent fe57d61 commit d86ede9

5 files changed

Lines changed: 96 additions & 58 deletions

File tree

gcloud-java-compute/src/main/java/com/google/gcloud/compute/Compute.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ class DiskTypeFilter extends ListFilter {
582582

583583
private static final long serialVersionUID = 4847837203592234453L;
584584

585-
DiskTypeFilter(DiskTypeField field, ComparisonOperator operator, Object value) {
585+
private DiskTypeFilter(DiskTypeField field, ComparisonOperator operator, Object value) {
586586
super(field.selector(), operator, value);
587587
}
588588

@@ -630,7 +630,7 @@ class MachineTypeFilter extends ListFilter {
630630

631631
private static final long serialVersionUID = 7346062041571853235L;
632632

633-
MachineTypeFilter(MachineTypeField field, ComparisonOperator operator, Object value) {
633+
private MachineTypeFilter(MachineTypeField field, ComparisonOperator operator, Object value) {
634634
super(field.selector(), operator, value);
635635
}
636636

@@ -678,7 +678,7 @@ class RegionFilter extends ListFilter {
678678

679679
private static final long serialVersionUID = 4464892812442567172L;
680680

681-
RegionFilter(RegionField field, ComparisonOperator operator, Object value) {
681+
private RegionFilter(RegionField field, ComparisonOperator operator, Object value) {
682682
super(field.selector(), operator, value);
683683
}
684684

@@ -712,7 +712,7 @@ class ZoneFilter extends ListFilter {
712712

713713
private static final long serialVersionUID = -3927428278548808737L;
714714

715-
ZoneFilter(ZoneField field, ComparisonOperator operator, Object value) {
715+
private ZoneFilter(ZoneField field, ComparisonOperator operator, Object value) {
716716
super(field.selector(), operator, value);
717717
}
718718

@@ -746,7 +746,7 @@ class OperationFilter extends ListFilter {
746746

747747
private static final long serialVersionUID = -3202249202748346427L;
748748

749-
OperationFilter(OperationField field, ComparisonOperator operator, Object value) {
749+
private OperationFilter(OperationField field, ComparisonOperator operator, Object value) {
750750
super(field.selector(), operator, value);
751751
}
752752

@@ -794,7 +794,7 @@ class AddressFilter extends ListFilter {
794794

795795
private static final long serialVersionUID = -227481644259653765L;
796796

797-
AddressFilter(AddressField field, ComparisonOperator operator, Object value) {
797+
private AddressFilter(AddressField field, ComparisonOperator operator, Object value) {
798798
super(field.selector(), operator, value);
799799
}
800800

@@ -828,12 +828,12 @@ class SnapshotFilter extends ListFilter {
828828

829829
private static final long serialVersionUID = 8757711630092406747L;
830830

831-
SnapshotFilter(SnapshotField field, ComparisonOperator operator, Object value) {
831+
private SnapshotFilter(SnapshotField field, ComparisonOperator operator, Object value) {
832832
super(field.selector(), operator, value);
833833
}
834834

835835
/**
836-
* Returns an equality filter for the given field and string value. For string fields,
836+
* Returns an equals filter for the given field and string value. For string fields,
837837
* {@code value} is interpreted as a regular expression using RE2 syntax. {@code value} must
838838
* match the entire field.
839839
*
@@ -855,7 +855,7 @@ public static SnapshotFilter notEquals(SnapshotField field, String value) {
855855
}
856856

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

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

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

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

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

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

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

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

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

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

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

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

14491459
/**
14501460
* Returns an option to specify the snapshot's fields to be returned by the RPC call. If this
1451-
* option is not provided, all snapshot's fields are returned. {@code SnapshotListOption.fields}
1452-
* can be used to specify only the fields of interest. {@link Snapshot#snapshotId()} is always
1453-
* returned, even if not specified.
1461+
* option is not provided, all the snapshot's fields are returned.
1462+
* {@code SnapshotListOption.fields} can be used to specify only the fields of interest.
1463+
* {@link Snapshot#snapshotId()} is always returned, even if not specified.
14541464
*/
14551465
public static SnapshotListOption fields(SnapshotField... fields) {
14561466
StringBuilder builder = new StringBuilder();

gcloud-java-compute/src/main/java/com/google/gcloud/compute/ComputeImpl.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ public com.google.api.services.compute.model.Operation call() {
934934
}
935935

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

10071007
@Override
1008-
public Operation deleteSnapshot(final SnapshotId snapshot, OperationOption... options) {
1008+
public Operation deleteSnapshot(SnapshotId snapshot, OperationOption... options) {
1009+
return deleteSnapshot(snapshot.snapshot(), options);
1010+
1011+
}
1012+
1013+
@Override
1014+
public Operation deleteSnapshot(final String snapshot, OperationOption... options) {
10091015
final Map<ComputeRpc.Option, ?> optionsMap = optionMap(options);
10101016
try {
10111017
com.google.api.services.compute.model.Operation answer =
10121018
runWithRetries(new Callable<com.google.api.services.compute.model.Operation>() {
10131019
@Override
10141020
public com.google.api.services.compute.model.Operation call() {
1015-
return computeRpc.deleteSnapshot(snapshot.snapshot(), optionsMap);
1021+
return computeRpc.deleteSnapshot(snapshot, optionsMap);
10161022
}
10171023
}, options().retryParams(), EXCEPTION_HANDLER);
10181024
return answer == null ? null : Operation.fromPb(this, answer);
@@ -1021,11 +1027,6 @@ public com.google.api.services.compute.model.Operation call() {
10211027
}
10221028
}
10231029

1024-
@Override
1025-
public Operation deleteSnapshot(final String snapshot, OperationOption... options) {
1026-
return deleteSnapshot(SnapshotId.of(snapshot));
1027-
}
1028-
10291030
private Map<ComputeRpc.Option, ?> optionMap(Option... options) {
10301031
Map<ComputeRpc.Option, Object> optionMap = Maps.newEnumMap(ComputeRpc.Option.class);
10311032
for (Option option : options) {

gcloud-java-compute/src/main/java/com/google/gcloud/compute/Snapshot.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

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

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

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

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

0 commit comments

Comments
 (0)