Skip to content

Commit 6e2c262

Browse files
committed
Compute Operation: remove creationTimestamp field and fix isDone() (googleapis#914)
* Remove Compute Operation's creation timestamp field * Compute's Operation.isDone() return true if operation does not exist
1 parent 382ab77 commit 6e2c262

File tree

5 files changed

+8
-46
lines changed

5 files changed

+8
-46
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ static String selector(LicenseField... fields) {
232232
*/
233233
enum OperationField {
234234
CLIENT_OPERATION_ID("clientOperationId"),
235-
CREATION_TIMESTAMP("creationTimestamp"),
236235
DESCRIPTION("description"),
237236
END_TIME("endTime"),
238237
ERROR("error"),

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

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public class Operation implements Serializable {
5252
private final ComputeOptions options;
5353
private final String id;
5454
private final OperationId operationId;
55-
private final Long creationTimestamp;
5655
private final String clientOperationId;
5756
private final String operationType;
5857
private final String targetLink;
@@ -296,7 +295,6 @@ static final class Builder {
296295

297296
private Compute compute;
298297
private String id;
299-
private Long creationTimestamp;
300298
private OperationId operationId;
301299
private String clientOperationId;
302300
private String operationType;
@@ -324,9 +322,6 @@ static final class Builder {
324322
if (operationPb.getId() != null) {
325323
id = operationPb.getId().toString();
326324
}
327-
if (operationPb.getCreationTimestamp() != null) {
328-
creationTimestamp = TIMESTAMP_FORMATTER.parseMillis(operationPb.getCreationTimestamp());
329-
}
330325
if (RegionOperationId.matchesUrl(operationPb.getSelfLink())) {
331326
operationId = RegionOperationId.fromUrl(operationPb.getSelfLink());
332327
} else if (ZoneOperationId.matchesUrl(operationPb.getSelfLink())) {
@@ -372,11 +367,6 @@ Builder id(String id) {
372367
return this;
373368
}
374369

375-
Builder creationTimestamp(Long creationTimestamp) {
376-
this.creationTimestamp = creationTimestamp;
377-
return this;
378-
}
379-
380370
Builder operationId(OperationId operationId) {
381371
this.operationId = checkNotNull(operationId);
382372
return this;
@@ -471,7 +461,6 @@ private Operation(Builder builder) {
471461
this.compute = checkNotNull(builder.compute);
472462
this.options = compute.options();
473463
this.id = builder.id;
474-
this.creationTimestamp = builder.creationTimestamp;
475464
this.operationId = checkNotNull(builder.operationId);
476465
this.clientOperationId = builder.clientOperationId;
477466
this.operationType = builder.operationType;
@@ -505,13 +494,6 @@ public String id() {
505494
return id;
506495
}
507496

508-
/**
509-
* Returns the creation timestamp in milliseconds since epoch.
510-
*/
511-
public Long creationTimestamp() {
512-
return creationTimestamp;
513-
}
514-
515497
/**
516498
* Returns the operation's identity. This method returns an {@link GlobalOperationId} for global
517499
* operations, a {@link RegionOperationId} for region operations and a {@link ZoneOperationId} for
@@ -658,23 +640,21 @@ public boolean exists() throws ComputeException {
658640

659641
/**
660642
* Checks if this operation has completed its execution, either failing or succeeding. If the
661-
* operation does not exist this method returns {@code false}. To correctly wait for operation's
662-
* completion, check that the operation exists first using {@link #exists()}:
643+
* operation does not exist this method returns {@code true}. You can wait for operation
644+
* completion with:
663645
* <pre> {@code
664-
* if (operation.exists()) {
665-
* while(!operation.isDone()) {
666-
* Thread.sleep(1000L);
667-
* }
646+
* while(!operation.isDone()) {
647+
* Thread.sleep(1000L);
668648
* }}</pre>
669649
*
670-
* @return {@code true} if this operation is in {@link Operation.Status#DONE} state, {@code false}
671-
* if the state is not {@link Operation.Status#DONE} or the operation does not exist
650+
* @return {@code true} if this operation is in {@link Operation.Status#DONE} state or if it does
651+
* not exist, {@code false} if the state is not {@link Operation.Status#DONE}
672652
* @throws ComputeException upon failure
673653
*/
674654
public boolean isDone() throws ComputeException {
675655
Operation operation =
676656
compute.get(operationId, Compute.OperationOption.fields(Compute.OperationField.STATUS));
677-
return operation != null && operation.status() == Status.DONE;
657+
return operation == null || operation.status() == Status.DONE;
678658
}
679659

680660
/**
@@ -705,7 +685,6 @@ public String toString() {
705685
return MoreObjects.toStringHelper(this)
706686
.add("id", id)
707687
.add("operationsId", operationId)
708-
.add("creationTimestamp", creationTimestamp)
709688
.add("clientOperationId", clientOperationId)
710689
.add("operationType", operationType)
711690
.add("targetLink", targetLink)
@@ -743,9 +722,6 @@ com.google.api.services.compute.model.Operation toPb() {
743722
if (id != null) {
744723
operationPb.setId(new BigInteger(id));
745724
}
746-
if (creationTimestamp != null) {
747-
operationPb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp));
748-
}
749725
operationPb.setName(operationId.operation());
750726
operationPb.setClientOperationId(clientOperationId);
751727
switch (operationId.type()) {

gcloud-java-compute/src/test/java/com/google/gcloud/compute/ComputeImplTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,6 @@ public void setUp() {
427427
Compute otherService = options.toBuilder().build().service();
428428
globalOperation = new Operation.Builder(otherService)
429429
.id(ID)
430-
.creationTimestamp(CREATION_TIMESTAMP)
431430
.operationId(GLOBAL_OPERATION_ID)
432431
.clientOperationId(CLIENT_OPERATION_ID)
433432
.operationType(OPERATION_TYPE)
@@ -448,7 +447,6 @@ public void setUp() {
448447
.build();
449448
zoneOperation = new Operation.Builder(otherService)
450449
.id(ID)
451-
.creationTimestamp(CREATION_TIMESTAMP)
452450
.operationId(ZONE_OPERATION_ID)
453451
.clientOperationId(CLIENT_OPERATION_ID)
454452
.operationType(OPERATION_TYPE)
@@ -469,7 +467,6 @@ public void setUp() {
469467
.build();
470468
regionOperation = new Operation.Builder(otherService)
471469
.id(ID)
472-
.creationTimestamp(CREATION_TIMESTAMP)
473470
.operationId(REGION_OPERATION_ID)
474471
.clientOperationId(CLIENT_OPERATION_ID)
475472
.operationType(OPERATION_TYPE)

gcloud-java-compute/src/test/java/com/google/gcloud/compute/OperationTest.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ private void initializeExpectedOperation(int optionsCalls) {
8989
replay(serviceMockReturnsOptions);
9090
globalOperation = new Operation.Builder(serviceMockReturnsOptions)
9191
.id(ID)
92-
.creationTimestamp(CREATION_TIMESTAMP)
9392
.operationId(GLOBAL_OPERATION_ID)
9493
.clientOperationId(CLIENT_OPERATION_ID)
9594
.operationType(OPERATION_TYPE)
@@ -110,7 +109,6 @@ private void initializeExpectedOperation(int optionsCalls) {
110109
.build();
111110
zoneOperation = new Operation.Builder(serviceMockReturnsOptions)
112111
.id(ID)
113-
.creationTimestamp(CREATION_TIMESTAMP)
114112
.operationId(ZONE_OPERATION_ID)
115113
.clientOperationId(CLIENT_OPERATION_ID)
116114
.operationType(OPERATION_TYPE)
@@ -131,7 +129,6 @@ private void initializeExpectedOperation(int optionsCalls) {
131129
.build();
132130
regionOperation = new Operation.Builder(serviceMockReturnsOptions)
133131
.id(ID)
134-
.creationTimestamp(CREATION_TIMESTAMP)
135132
.operationId(REGION_OPERATION_ID)
136133
.clientOperationId(CLIENT_OPERATION_ID)
137134
.operationType(OPERATION_TYPE)
@@ -157,7 +154,6 @@ private void initializeOperation() {
157154
operation = new Operation.Builder(compute)
158155
.id(ID)
159156
.operationId(GLOBAL_OPERATION_ID)
160-
.creationTimestamp(CREATION_TIMESTAMP)
161157
.clientOperationId(CLIENT_OPERATION_ID)
162158
.operationType(OPERATION_TYPE)
163159
.targetLink(TARGET_LINK)
@@ -183,7 +179,6 @@ public void tearDown() throws Exception {
183179
}
184180

185181
private void assertEqualsCommonFields(Operation operation) {
186-
assertEquals(CREATION_TIMESTAMP, operation.creationTimestamp());
187182
assertEquals(ID, operation.id());
188183
assertEquals(CLIENT_OPERATION_ID, operation.clientOperationId());
189184
assertEquals(OPERATION_TYPE, operation.operationType());
@@ -205,7 +200,6 @@ private void assertEqualsCommonFields(Operation operation) {
205200
}
206201

207202
private void assertNullCommonFields(Operation operation) {
208-
assertNull(operation.creationTimestamp());
209203
assertNull(operation.id());
210204
assertNull(operation.clientOperationId());
211205
assertNull(operation.operationType());
@@ -358,7 +352,7 @@ public void testIsDone_NotExists() throws Exception {
358352
expect(compute.get(GLOBAL_OPERATION_ID, expectedOptions)).andReturn(null);
359353
replay(compute);
360354
initializeOperation();
361-
assertFalse(operation.isDone());
355+
assertTrue(operation.isDone());
362356
verify(compute);
363357
}
364358

@@ -401,7 +395,6 @@ public void testReloadWithOptions() throws Exception {
401395
private void compareOperation(Operation expected, Operation value) {
402396
assertEquals(expected, value);
403397
assertEquals(expected.compute().options(), value.compute().options());
404-
assertEquals(expected.creationTimestamp(), value.creationTimestamp());
405398
assertEquals(expected.operationId(), value.operationId());
406399
assertEquals(expected.clientOperationId(), value.clientOperationId());
407400
assertEquals(expected.operationType(), value.operationType());

gcloud-java-compute/src/test/java/com/google/gcloud/compute/it/ITComputeTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,6 @@ public void testListGlobalOperationsWithSelectedFields() {
502502
assertNull(operation.operationType());
503503
assertNull(operation.targetLink());
504504
assertNull(operation.targetId());
505-
assertNull(operation.creationTimestamp());
506505
assertNull(operation.operationType());
507506
assertNull(operation.status());
508507
assertNull(operation.statusMessage());
@@ -564,7 +563,6 @@ public void testListRegionOperationsWithSelectedFields() {
564563
assertNull(operation.operationType());
565564
assertNull(operation.targetLink());
566565
assertNull(operation.targetId());
567-
assertNull(operation.creationTimestamp());
568566
assertNull(operation.operationType());
569567
assertNull(operation.status());
570568
assertNull(operation.statusMessage());
@@ -628,7 +626,6 @@ public void testListZoneOperationsWithSelectedFields() {
628626
assertNull(operation.operationType());
629627
assertNull(operation.targetLink());
630628
assertNull(operation.targetId());
631-
assertNull(operation.creationTimestamp());
632629
assertNull(operation.operationType());
633630
assertNull(operation.status());
634631
assertNull(operation.statusMessage());

0 commit comments

Comments
 (0)