From 3d9611399c63215ab7746ca8a56a6eb94126648c Mon Sep 17 00:00:00 2001 From: Kamil Sobol Date: Tue, 21 Sep 2021 09:48:29 -0700 Subject: [PATCH 1/3] transform composite blob exception to datalake model. --- .../util/DataLakeImplUtils.java | 26 ++++++++-- .../util/DataLakeImplUtilsTest.groovy | 47 +++++++++++++++++++ 2 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/implementation/util/DataLakeImplUtilsTest.groovy diff --git a/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/implementation/util/DataLakeImplUtils.java b/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/implementation/util/DataLakeImplUtils.java index 1f7274f7c7a64..c3a786d85e117 100644 --- a/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/implementation/util/DataLakeImplUtils.java +++ b/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/implementation/util/DataLakeImplUtils.java @@ -6,8 +6,11 @@ import com.azure.core.util.logging.ClientLogger; import com.azure.storage.blob.models.BlobStorageException; import com.azure.storage.file.datalake.models.DataLakeStorageException; +import reactor.core.Exceptions; +import java.util.List; import java.util.function.Supplier; +import java.util.stream.Collectors; public class DataLakeImplUtils { public static String endpointToDesiredEndpoint(String endpoint, String desiredEndpoint, String currentEndpoint) { @@ -22,15 +25,28 @@ public static String endpointToDesiredEndpoint(String endpoint, String desiredEn } public static Throwable transformBlobStorageException(Throwable ex) { - if (!(ex instanceof BlobStorageException)) { - return ex; + if (ex instanceof BlobStorageException) { + return transformSingleBlobStorageException((BlobStorageException) ex); + } else if(Exceptions.isMultiple(ex)) { + List suppressed = Exceptions.unwrapMultiple(ex); + suppressed = suppressed.stream().map(e -> { + if (e instanceof BlobStorageException) { + return transformSingleBlobStorageException((BlobStorageException) e); + } else { + return e; + } + }).collect(Collectors.toList()); + return Exceptions.multiple(suppressed); } else { - BlobStorageException exception = (BlobStorageException) ex; - return new DataLakeStorageException(exception.getServiceMessage(), exception.getResponse(), - exception.getValue()); + return ex; } } + private static DataLakeStorageException transformSingleBlobStorageException(BlobStorageException ex) { + return new DataLakeStorageException(ex.getServiceMessage(), ex.getResponse(), + ex.getValue()); + } + public static T returnOrConvertException(Supplier supplier, ClientLogger logger) { try { return supplier.get(); diff --git a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/implementation/util/DataLakeImplUtilsTest.groovy b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/implementation/util/DataLakeImplUtilsTest.groovy new file mode 100644 index 0000000000000..250f8edb1b9c3 --- /dev/null +++ b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/implementation/util/DataLakeImplUtilsTest.groovy @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.storage.file.datalake.implementation.util + +import com.azure.core.test.http.MockHttpResponse +import com.azure.storage.blob.models.BlobStorageException +import com.azure.storage.file.datalake.models.DataLakeStorageException +import reactor.core.Exceptions +import spock.lang.Specification + +class DataLakeImplUtilsTest extends Specification { + def "can map blobs exception"() { + given: + def response = new MockHttpResponse(null, 412, null) + def blobException = new BlobStorageException("fail", response, null) + + when: + def dataLakeException = DataLakeImplUtils.transformBlobStorageException(blobException) + + then: + dataLakeException instanceof DataLakeStorageException + ((DataLakeStorageException) dataLakeException).statusCode == response.statusCode + ((DataLakeStorageException) dataLakeException).message == "fail" + } + + def "can map composite blobs exception"() { + given: + def response = new MockHttpResponse(null, 412, null) + def blobException1 = new BlobStorageException("fail1", response, null) + def blobException2 = new BlobStorageException("fail2", response, null) + def composite = Exceptions.multiple(blobException1, blobException2) + + when: + def dataLakeComposite = DataLakeImplUtils.transformBlobStorageException(composite) + def dataLakeException1 = Exceptions.unwrapMultiple(dataLakeComposite)[0] + def dataLakeException2 = Exceptions.unwrapMultiple(dataLakeComposite)[1] + + then: + dataLakeException1 instanceof DataLakeStorageException + ((DataLakeStorageException) dataLakeException1).statusCode == response.statusCode + ((DataLakeStorageException) dataLakeException1).message == "fail1" + dataLakeException2 instanceof DataLakeStorageException + ((DataLakeStorageException) dataLakeException2).statusCode == response.statusCode + ((DataLakeStorageException) dataLakeException2).message == "fail2" + } +} From 268cb0202f3309b698049f3235d3c6a7a86a6969 Mon Sep 17 00:00:00 2001 From: Kamil Sobol Date: Tue, 21 Sep 2021 09:49:28 -0700 Subject: [PATCH 2/3] cl. --- sdk/storage/azure-storage-file-datalake/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/storage/azure-storage-file-datalake/CHANGELOG.md b/sdk/storage/azure-storage-file-datalake/CHANGELOG.md index 1587bced46555..45b89330edfa8 100644 --- a/sdk/storage/azure-storage-file-datalake/CHANGELOG.md +++ b/sdk/storage/azure-storage-file-datalake/CHANGELOG.md @@ -7,6 +7,7 @@ ### Breaking Changes ### Bugs Fixed +- Fixed bug where composite BlobServiceException wasn't translated into DataLakeServiceException. ### Other Changes From a4e86aa8ea89a72dd777eca8f29b7b628173c0da Mon Sep 17 00:00:00 2001 From: Kamil Sobol Date: Tue, 21 Sep 2021 10:08:57 -0700 Subject: [PATCH 3/3] ... --- .../file/datalake/implementation/util/DataLakeImplUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/implementation/util/DataLakeImplUtils.java b/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/implementation/util/DataLakeImplUtils.java index c3a786d85e117..ffe7a52e0e17f 100644 --- a/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/implementation/util/DataLakeImplUtils.java +++ b/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/implementation/util/DataLakeImplUtils.java @@ -27,7 +27,7 @@ public static String endpointToDesiredEndpoint(String endpoint, String desiredEn public static Throwable transformBlobStorageException(Throwable ex) { if (ex instanceof BlobStorageException) { return transformSingleBlobStorageException((BlobStorageException) ex); - } else if(Exceptions.isMultiple(ex)) { + } else if (Exceptions.isMultiple(ex)) { List suppressed = Exceptions.unwrapMultiple(ex); suppressed = suppressed.stream().map(e -> { if (e instanceof BlobStorageException) {