Skip to content

Commit ea3f11e

Browse files
committed
chore: rename ResumableSessionFailureScenario to UploadFailureScenario
The failure scenarios outlined are not resumable specific, and will be used by single-shot and appendable uploads as well.
1 parent 7546e4f commit ea3f11e

9 files changed

+86
-93
lines changed

google-cloud-storage/src/main/java/com/google/cloud/storage/GapicBidiUnbufferedAppendableWriteableByteChannel.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,11 @@ public void onNext(BidiWriteObjectResponse value) {
417417
} else if (persistedSize < totalSentBytes) {
418418
writeCtx.getConfirmedBytes().set(persistedSize);
419419
clientDetectedError(
420-
ResumableSessionFailureScenario.SCENARIO_9.toStorageException(
420+
UploadFailureScenario.SCENARIO_9.toStorageException(
421421
ImmutableList.of(lastWrittenRequest), value, context, null));
422422
} else {
423423
clientDetectedError(
424-
ResumableSessionFailureScenario.SCENARIO_7.toStorageException(
424+
UploadFailureScenario.SCENARIO_7.toStorageException(
425425
ImmutableList.of(lastWrittenRequest), value, context, null));
426426
}
427427
} else if (finalizing && value.hasResource()) {
@@ -432,11 +432,11 @@ public void onNext(BidiWriteObjectResponse value) {
432432
ok(value);
433433
} else if (finalSize < totalSentBytes) {
434434
clientDetectedError(
435-
ResumableSessionFailureScenario.SCENARIO_4_1.toStorageException(
435+
UploadFailureScenario.SCENARIO_4_1.toStorageException(
436436
ImmutableList.of(lastWrittenRequest), value, context, null));
437437
} else {
438438
clientDetectedError(
439-
ResumableSessionFailureScenario.SCENARIO_4_2.toStorageException(
439+
UploadFailureScenario.SCENARIO_4_2.toStorageException(
440440
ImmutableList.of(lastWrittenRequest), value, context, null));
441441
}
442442
} else if (finalizing && value.hasPersistedSize()) {
@@ -449,16 +449,16 @@ public void onNext(BidiWriteObjectResponse value) {
449449
writeCtx.getConfirmedBytes().set(persistedSize);
450450
} else if (persistedSize < totalSentBytes) {
451451
clientDetectedError(
452-
ResumableSessionFailureScenario.SCENARIO_3.toStorageException(
452+
UploadFailureScenario.SCENARIO_3.toStorageException(
453453
ImmutableList.of(lastWrittenRequest), value, context, null));
454454
} else {
455455
clientDetectedError(
456-
ResumableSessionFailureScenario.SCENARIO_2.toStorageException(
456+
UploadFailureScenario.SCENARIO_2.toStorageException(
457457
ImmutableList.of(lastWrittenRequest), value, context, null));
458458
}
459459
} else {
460460
clientDetectedError(
461-
ResumableSessionFailureScenario.SCENARIO_0.toStorageException(
461+
UploadFailureScenario.SCENARIO_0.toStorageException(
462462
ImmutableList.of(lastWrittenRequest), value, context, null));
463463
}
464464
}
@@ -472,7 +472,7 @@ public void onError(Throwable t) {
472472
&& ed.getErrorInfo() != null
473473
&& ed.getErrorInfo().getReason().equals("GRPC_MISMATCHED_UPLOAD_SIZE"))) {
474474
clientDetectedError(
475-
ResumableSessionFailureScenario.SCENARIO_5.toStorageException(
475+
UploadFailureScenario.SCENARIO_5.toStorageException(
476476
ImmutableList.of(lastWrittenRequest), null, context, oore));
477477
return;
478478
}
@@ -484,7 +484,7 @@ public void onError(Throwable t) {
484484
// unusual case, and it should not cause a significant overhead given its rarity.
485485
StorageException tmp = StorageException.asStorageException((ApiException) t);
486486
previousError =
487-
ResumableSessionFailureScenario.toStorageException(
487+
UploadFailureScenario.toStorageException(
488488
tmp.getCode(),
489489
tmp.getMessage(),
490490
tmp.getReason(),

google-cloud-storage/src/main/java/com/google/cloud/storage/GapicBidiUnbufferedWritableByteChannel.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public void onNext(BidiWriteObjectResponse value) {
290290
ok(value);
291291
} else {
292292
clientDetectedError(
293-
ResumableSessionFailureScenario.SCENARIO_7.toStorageException(
293+
UploadFailureScenario.SCENARIO_7.toStorageException(
294294
nullSafeList(lastWrittenRequest), value, context, null));
295295
}
296296
} else if (finalizing && value.hasResource()) {
@@ -301,16 +301,16 @@ public void onNext(BidiWriteObjectResponse value) {
301301
ok(value);
302302
} else if (finalSize < totalSentBytes) {
303303
clientDetectedError(
304-
ResumableSessionFailureScenario.SCENARIO_4_1.toStorageException(
304+
UploadFailureScenario.SCENARIO_4_1.toStorageException(
305305
nullSafeList(lastWrittenRequest), value, context, null));
306306
} else {
307307
clientDetectedError(
308-
ResumableSessionFailureScenario.SCENARIO_4_2.toStorageException(
308+
UploadFailureScenario.SCENARIO_4_2.toStorageException(
309309
nullSafeList(lastWrittenRequest), value, context, null));
310310
}
311311
} else if (!finalizing && value.hasResource()) {
312312
clientDetectedError(
313-
ResumableSessionFailureScenario.SCENARIO_1.toStorageException(
313+
UploadFailureScenario.SCENARIO_1.toStorageException(
314314
nullSafeList(lastWrittenRequest), value, context, null));
315315
} else if (finalizing && value.hasPersistedSize()) {
316316
long totalSentBytes = writeCtx.getTotalSentBytes().get();
@@ -322,16 +322,16 @@ public void onNext(BidiWriteObjectResponse value) {
322322
writeCtx.getConfirmedBytes().set(persistedSize);
323323
} else if (persistedSize < totalSentBytes) {
324324
clientDetectedError(
325-
ResumableSessionFailureScenario.SCENARIO_3.toStorageException(
325+
UploadFailureScenario.SCENARIO_3.toStorageException(
326326
nullSafeList(lastWrittenRequest), value, context, null));
327327
} else {
328328
clientDetectedError(
329-
ResumableSessionFailureScenario.SCENARIO_2.toStorageException(
329+
UploadFailureScenario.SCENARIO_2.toStorageException(
330330
nullSafeList(lastWrittenRequest), value, context, null));
331331
}
332332
} else {
333333
clientDetectedError(
334-
ResumableSessionFailureScenario.SCENARIO_0.toStorageException(
334+
UploadFailureScenario.SCENARIO_0.toStorageException(
335335
nullSafeList(lastWrittenRequest), value, context, null));
336336
}
337337
}
@@ -345,7 +345,7 @@ public void onError(Throwable t) {
345345
&& ed.getErrorInfo() != null
346346
&& ed.getErrorInfo().getReason().equals("GRPC_MISMATCHED_UPLOAD_SIZE"))) {
347347
clientDetectedError(
348-
ResumableSessionFailureScenario.SCENARIO_5.toStorageException(
348+
UploadFailureScenario.SCENARIO_5.toStorageException(
349349
nullSafeList(lastWrittenRequest), null, context, oore));
350350
return;
351351
}
@@ -357,7 +357,7 @@ public void onError(Throwable t) {
357357
// unusual case, and it should not cause a significant overhead given its rarity.
358358
StorageException tmp = StorageException.asStorageException((ApiException) t);
359359
previousError =
360-
ResumableSessionFailureScenario.toStorageException(
360+
UploadFailureScenario.toStorageException(
361361
tmp.getCode(),
362362
tmp.getMessage(),
363363
tmp.getReason(),

google-cloud-storage/src/main/java/com/google/cloud/storage/GapicUnbufferedChunkedResumableWritableByteChannel.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,7 @@ public void onError(Throwable t) {
267267
&& ed.getErrorInfo() != null
268268
&& ed.getErrorInfo().getReason().equals("GRPC_MISMATCHED_UPLOAD_SIZE"))) {
269269
StorageException storageException =
270-
ResumableSessionFailureScenario.SCENARIO_5.toStorageException(
271-
segments, null, context, oore);
270+
UploadFailureScenario.SCENARIO_5.toStorageException(segments, null, context, oore);
272271
invocationHandle.setException(storageException);
273272
return;
274273
}
@@ -280,7 +279,7 @@ public void onError(Throwable t) {
280279
// unusual case, and it should not cause a significant overhead given its rarity.
281280
StorageException tmp = StorageException.asStorageException((ApiException) t);
282281
StorageException storageException =
283-
ResumableSessionFailureScenario.toStorageException(
282+
UploadFailureScenario.toStorageException(
284283
tmp.getCode(), tmp.getMessage(), tmp.getReason(), segments, null, context, t);
285284
invocationHandle.setException(storageException);
286285
}
@@ -305,7 +304,7 @@ public void onCompleted() {
305304
writeCtx.getTotalSentBytes().set(persistedSize);
306305
writeCtx.getConfirmedBytes().set(persistedSize);
307306
} else {
308-
throw ResumableSessionFailureScenario.SCENARIO_7.toStorageException(
307+
throw UploadFailureScenario.SCENARIO_7.toStorageException(
309308
segments, last, context, null);
310309
}
311310
} else if (finalizing && last.hasResource()) {
@@ -315,28 +314,26 @@ public void onCompleted() {
315314
writeCtx.getConfirmedBytes().set(finalSize);
316315
resultFuture.set(last);
317316
} else if (finalSize < totalSentBytes) {
318-
throw ResumableSessionFailureScenario.SCENARIO_4_1.toStorageException(
317+
throw UploadFailureScenario.SCENARIO_4_1.toStorageException(
319318
segments, last, context, null);
320319
} else {
321-
throw ResumableSessionFailureScenario.SCENARIO_4_2.toStorageException(
320+
throw UploadFailureScenario.SCENARIO_4_2.toStorageException(
322321
segments, last, context, null);
323322
}
324323
} else if (!finalizing && last.hasResource()) {
325-
throw ResumableSessionFailureScenario.SCENARIO_1.toStorageException(
326-
segments, last, context, null);
324+
throw UploadFailureScenario.SCENARIO_1.toStorageException(segments, last, context, null);
327325
} else if (finalizing && last.hasPersistedSize()) {
328326
long totalSentBytes = writeCtx.getTotalSentBytes().get();
329327
long persistedSize = last.getPersistedSize();
330328
if (persistedSize < totalSentBytes) {
331-
throw ResumableSessionFailureScenario.SCENARIO_3.toStorageException(
329+
throw UploadFailureScenario.SCENARIO_3.toStorageException(
332330
segments, last, context, null);
333331
} else {
334-
throw ResumableSessionFailureScenario.SCENARIO_2.toStorageException(
332+
throw UploadFailureScenario.SCENARIO_2.toStorageException(
335333
segments, last, context, null);
336334
}
337335
} else {
338-
throw ResumableSessionFailureScenario.SCENARIO_0.toStorageException(
339-
segments, last, context, null);
336+
throw UploadFailureScenario.SCENARIO_0.toStorageException(segments, last, context, null);
340337
}
341338
} catch (Throwable se) {
342339
open = false;

google-cloud-storage/src/main/java/com/google/cloud/storage/GapicUnbufferedDirectWritableByteChannel.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public void onError(Throwable t) {
222222
// unusual case, and it should not cause a significant overhead given its rarity.
223223
StorageException tmp = StorageException.asStorageException((ApiException) t);
224224
StorageException storageException =
225-
ResumableSessionFailureScenario.toStorageException(
225+
UploadFailureScenario.toStorageException(
226226
tmp.getCode(), tmp.getMessage(), tmp.getReason(), getRequests(), null, context, t);
227227
invocationHandle.setException(storageException);
228228
} else {
@@ -243,14 +243,14 @@ public void onCompleted() {
243243
writeCtx.getConfirmedBytes().set(finalSize);
244244
resultFuture.set(last);
245245
} else if (finalSize < totalSentBytes) {
246-
throw ResumableSessionFailureScenario.SCENARIO_4_1.toStorageException(
246+
throw UploadFailureScenario.SCENARIO_4_1.toStorageException(
247247
getRequests(), last, context, null);
248248
} else {
249-
throw ResumableSessionFailureScenario.SCENARIO_4_2.toStorageException(
249+
throw UploadFailureScenario.SCENARIO_4_2.toStorageException(
250250
getRequests(), last, context, null);
251251
}
252252
} else {
253-
throw ResumableSessionFailureScenario.SCENARIO_0.toStorageException(
253+
throw UploadFailureScenario.SCENARIO_0.toStorageException(
254254
getRequests(), last, context, null);
255255
}
256256
} catch (Throwable se) {

google-cloud-storage/src/main/java/com/google/cloud/storage/GapicUnbufferedFinalizeOnCloseResumableWritableByteChannel.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public void onError(Throwable t) {
226226
// unusual case, and it should not cause a significant overhead given its rarity.
227227
StorageException tmp = StorageException.asStorageException((ApiException) t);
228228
StorageException storageException =
229-
ResumableSessionFailureScenario.toStorageException(
229+
UploadFailureScenario.toStorageException(
230230
tmp.getCode(),
231231
tmp.getMessage(),
232232
tmp.getReason(),
@@ -247,7 +247,7 @@ public void onCompleted() {
247247
boolean finalizing = lastWrittenRequest.getFinishWrite();
248248
if (last == null) {
249249
clientDetectedError(
250-
ResumableSessionFailureScenario.toStorageException(
250+
UploadFailureScenario.toStorageException(
251251
0,
252252
"onComplete without preceding onNext, unable to determine success.",
253253
"invalid",
@@ -262,16 +262,16 @@ public void onCompleted() {
262262
ok(finalSize);
263263
} else if (finalSize < totalSentBytes) {
264264
clientDetectedError(
265-
ResumableSessionFailureScenario.SCENARIO_4_1.toStorageException(
265+
UploadFailureScenario.SCENARIO_4_1.toStorageException(
266266
nullSafeList(lastWrittenRequest), last, context, null));
267267
} else {
268268
clientDetectedError(
269-
ResumableSessionFailureScenario.SCENARIO_4_2.toStorageException(
269+
UploadFailureScenario.SCENARIO_4_2.toStorageException(
270270
nullSafeList(lastWrittenRequest), last, context, null));
271271
}
272272
} else if (!finalizing || last.hasPersistedSize()) { // unexpected incremental response
273273
clientDetectedError(
274-
ResumableSessionFailureScenario.toStorageException(
274+
UploadFailureScenario.toStorageException(
275275
0,
276276
"Unexpected incremental response for finalizing request.",
277277
"invalid",
@@ -281,7 +281,7 @@ public void onCompleted() {
281281
null));
282282
} else {
283283
clientDetectedError(
284-
ResumableSessionFailureScenario.SCENARIO_0.toStorageException(
284+
UploadFailureScenario.SCENARIO_0.toStorageException(
285285
nullSafeList(lastWrittenRequest), last, context, null));
286286
}
287287
}

google-cloud-storage/src/main/java/com/google/cloud/storage/JsonResumableSessionPutTask.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void rewindTo(long offset) {
108108

109109
int code = response.getStatusCode();
110110

111-
if (!finalizing && ResumableSessionFailureScenario.isContinue(code)) {
111+
if (!finalizing && UploadFailureScenario.isContinue(code)) {
112112
long effectiveEnd = ((HttpContentRange.HasRange<?>) contentRange).range().endOffset();
113113
@Nullable String range = response.getHeaders().getRange();
114114
ByteRangeSpec ackRange = ByteRangeSpec.parse(range);
@@ -121,11 +121,11 @@ public void rewindTo(long offset) {
121121
return ResumableOperationResult.incremental(ackRange.endOffset());
122122
} else {
123123
StorageException se =
124-
ResumableSessionFailureScenario.SCENARIO_7.toStorageException(uploadId, response);
124+
UploadFailureScenario.SCENARIO_7.toStorageException(uploadId, response);
125125
span.setStatus(Status.UNKNOWN.withDescription(se.getMessage()));
126126
throw se;
127127
}
128-
} else if (finalizing && ResumableSessionFailureScenario.isOk(code)) {
128+
} else if (finalizing && UploadFailureScenario.isOk(code)) {
129129
@Nullable StorageObject storageObject;
130130
BigInteger actualSize = BigInteger.ZERO;
131131

@@ -152,7 +152,7 @@ public void rewindTo(long offset) {
152152
} else {
153153
response.ignore();
154154
StorageException se =
155-
ResumableSessionFailureScenario.SCENARIO_0_1.toStorageException(
155+
UploadFailureScenario.SCENARIO_0_1.toStorageException(
156156
uploadId, response, null, () -> null);
157157
span.setStatus(Status.UNKNOWN.withDescription(se.getMessage()));
158158
throw se;
@@ -165,35 +165,35 @@ public void rewindTo(long offset) {
165165
return ResumableOperationResult.complete(storageObject, actualSize.longValue());
166166
} else if (compare > 0) {
167167
StorageException se =
168-
ResumableSessionFailureScenario.SCENARIO_4_1.toStorageException(
168+
UploadFailureScenario.SCENARIO_4_1.toStorageException(
169169
uploadId, response, null, toString(storageObject));
170170
span.setStatus(Status.UNKNOWN.withDescription(se.getMessage()));
171171
throw se;
172172
} else {
173173
StorageException se =
174-
ResumableSessionFailureScenario.SCENARIO_4_2.toStorageException(
174+
UploadFailureScenario.SCENARIO_4_2.toStorageException(
175175
uploadId, response, null, toString(storageObject));
176176
span.setStatus(Status.UNKNOWN.withDescription(se.getMessage()));
177177
throw se;
178178
}
179-
} else if (!finalizing && ResumableSessionFailureScenario.isOk(code)) {
179+
} else if (!finalizing && UploadFailureScenario.isOk(code)) {
180180
StorageException se =
181-
ResumableSessionFailureScenario.SCENARIO_1.toStorageException(uploadId, response);
181+
UploadFailureScenario.SCENARIO_1.toStorageException(uploadId, response);
182182
span.setStatus(Status.UNKNOWN.withDescription(se.getMessage()));
183183
throw se;
184-
} else if (finalizing && ResumableSessionFailureScenario.isContinue(code)) {
184+
} else if (finalizing && UploadFailureScenario.isContinue(code)) {
185185
// in order to finalize the content range must have a size, cast down to read it
186186
HttpContentRange.HasSize size = (HttpContentRange.HasSize) contentRange;
187187

188188
ByteRangeSpec range = ByteRangeSpec.parse(response.getHeaders().getRange());
189189
if (range.endOffsetInclusive() < size.getSize()) {
190190
StorageException se =
191-
ResumableSessionFailureScenario.SCENARIO_3.toStorageException(uploadId, response);
191+
UploadFailureScenario.SCENARIO_3.toStorageException(uploadId, response);
192192
span.setStatus(Status.UNKNOWN.withDescription(se.getMessage()));
193193
throw se;
194194
} else {
195195
StorageException se =
196-
ResumableSessionFailureScenario.SCENARIO_2.toStorageException(uploadId, response);
196+
UploadFailureScenario.SCENARIO_2.toStorageException(uploadId, response);
197197
span.setStatus(Status.UNKNOWN.withDescription(se.getMessage()));
198198
throw se;
199199
}
@@ -205,8 +205,7 @@ public void rewindTo(long offset) {
205205
// a 503 with plain text content
206206
// Attempt to detect this very loosely as to minimize impact of modified error message
207207
// This is accurate circa 2023-06
208-
if ((!ResumableSessionFailureScenario.isOk(code)
209-
&& !ResumableSessionFailureScenario.isContinue(code))
208+
if ((!UploadFailureScenario.isOk(code) && !UploadFailureScenario.isContinue(code))
210209
&& contentType != null
211210
&& contentType.startsWith("text/plain")
212211
&& contentLength != null
@@ -215,14 +214,13 @@ public void rewindTo(long offset) {
215214
if (errorMessage.contains("content-range")
216215
&& !errorMessage.contains("earlier")) { // TODO: exclude "earlier request"
217216
StorageException se =
218-
ResumableSessionFailureScenario.SCENARIO_5.toStorageException(
217+
UploadFailureScenario.SCENARIO_5.toStorageException(
219218
uploadId, response, cause, cause::getContent);
220219
span.setStatus(Status.UNKNOWN.withDescription(se.getMessage()));
221220
throw se;
222221
}
223222
}
224-
StorageException se =
225-
ResumableSessionFailureScenario.toStorageException(response, cause, uploadId);
223+
StorageException se = UploadFailureScenario.toStorageException(response, cause, uploadId);
226224
span.setStatus(Status.UNKNOWN.withDescription(se.getMessage()));
227225
throw se;
228226
}
@@ -235,7 +233,7 @@ public void rewindTo(long offset) {
235233
throw e;
236234
} catch (Exception e) {
237235
StorageException se =
238-
ResumableSessionFailureScenario.SCENARIO_0.toStorageException(uploadId, response, e);
236+
UploadFailureScenario.SCENARIO_0.toStorageException(uploadId, response, e);
239237
span.setStatus(Status.UNKNOWN.withDescription(se.getMessage()));
240238
throw se;
241239
} finally {

0 commit comments

Comments
 (0)