Skip to content

Commit 822e644

Browse files
Storage Error Codes for Copies (#45394)
* Storage Error Codes for Copies * fixing some PR comments * adding one more condition to retry policy * adding one more condition to retry policy * adding a missing recording
1 parent 486d4e0 commit 822e644

File tree

24 files changed

+1308
-1017
lines changed

24 files changed

+1308
-1017
lines changed

sdk/storage/azure-storage-blob/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "java",
44
"TagPrefix": "java/storage/azure-storage-blob",
5-
"Tag": "java/storage/azure-storage-blob_e4ae407bc2"
5+
"Tag": "java/storage/azure-storage-blob_ec8390044d"
66
}

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/implementation/AppendBlobsImpl.java

Lines changed: 42 additions & 42 deletions
Large diffs are not rendered by default.

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/implementation/BlobsImpl.java

Lines changed: 378 additions & 378 deletions
Large diffs are not rendered by default.

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/implementation/BlockBlobsImpl.java

Lines changed: 84 additions & 84 deletions
Large diffs are not rendered by default.

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/implementation/ContainersImpl.java

Lines changed: 168 additions & 168 deletions
Large diffs are not rendered by default.

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/implementation/PageBlobsImpl.java

Lines changed: 123 additions & 123 deletions
Large diffs are not rendered by default.

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/implementation/ServicesImpl.java

Lines changed: 85 additions & 85 deletions
Large diffs are not rendered by default.

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/implementation/models/StorageError.java

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ public final class StorageError implements XmlSerializable<StorageError> {
2323
*/
2424
private String message;
2525

26+
/*
27+
* The CopySourceStatusCode property.
28+
*/
29+
private Integer copySourceStatusCode;
30+
31+
/*
32+
* The CopySourceErrorCode property.
33+
*/
34+
private String copySourceErrorCode;
35+
36+
/*
37+
* The CopySourceErrorMessage property.
38+
*/
39+
private String copySourceErrorMessage;
40+
2641
/**
2742
* Creates an instance of StorageError class.
2843
*/
@@ -49,6 +64,66 @@ public StorageError setMessage(String message) {
4964
return this;
5065
}
5166

67+
/**
68+
* Get the copySourceStatusCode property: The CopySourceStatusCode property.
69+
*
70+
* @return the copySourceStatusCode value.
71+
*/
72+
public Integer getCopySourceStatusCode() {
73+
return this.copySourceStatusCode;
74+
}
75+
76+
/**
77+
* Set the copySourceStatusCode property: The CopySourceStatusCode property.
78+
*
79+
* @param copySourceStatusCode the copySourceStatusCode value to set.
80+
* @return the StorageError object itself.
81+
*/
82+
public StorageError setCopySourceStatusCode(Integer copySourceStatusCode) {
83+
this.copySourceStatusCode = copySourceStatusCode;
84+
return this;
85+
}
86+
87+
/**
88+
* Get the copySourceErrorCode property: The CopySourceErrorCode property.
89+
*
90+
* @return the copySourceErrorCode value.
91+
*/
92+
public String getCopySourceErrorCode() {
93+
return this.copySourceErrorCode;
94+
}
95+
96+
/**
97+
* Set the copySourceErrorCode property: The CopySourceErrorCode property.
98+
*
99+
* @param copySourceErrorCode the copySourceErrorCode value to set.
100+
* @return the StorageError object itself.
101+
*/
102+
public StorageError setCopySourceErrorCode(String copySourceErrorCode) {
103+
this.copySourceErrorCode = copySourceErrorCode;
104+
return this;
105+
}
106+
107+
/**
108+
* Get the copySourceErrorMessage property: The CopySourceErrorMessage property.
109+
*
110+
* @return the copySourceErrorMessage value.
111+
*/
112+
public String getCopySourceErrorMessage() {
113+
return this.copySourceErrorMessage;
114+
}
115+
116+
/**
117+
* Set the copySourceErrorMessage property: The CopySourceErrorMessage property.
118+
*
119+
* @param copySourceErrorMessage the copySourceErrorMessage value to set.
120+
* @return the StorageError object itself.
121+
*/
122+
public StorageError setCopySourceErrorMessage(String copySourceErrorMessage) {
123+
this.copySourceErrorMessage = copySourceErrorMessage;
124+
return this;
125+
}
126+
52127
@Override
53128
public XmlWriter toXml(XmlWriter xmlWriter) throws XMLStreamException {
54129
return toXml(xmlWriter, null);
@@ -59,6 +134,9 @@ public XmlWriter toXml(XmlWriter xmlWriter, String rootElementName) throws XMLSt
59134
rootElementName = CoreUtils.isNullOrEmpty(rootElementName) ? "StorageError" : rootElementName;
60135
xmlWriter.writeStartElement(rootElementName);
61136
xmlWriter.writeStringElement("Message", this.message);
137+
xmlWriter.writeNumberElement("CopySourceStatusCode", this.copySourceStatusCode);
138+
xmlWriter.writeStringElement("CopySourceErrorCode", this.copySourceErrorCode);
139+
xmlWriter.writeStringElement("CopySourceErrorMessage", this.copySourceErrorMessage);
62140
return xmlWriter.writeEndElement();
63141
}
64142

@@ -93,6 +171,12 @@ public static StorageError fromXml(XmlReader xmlReader, String rootElementName)
93171

94172
if ("Message".equals(elementName.getLocalPart())) {
95173
deserializedStorageError.message = reader.getStringElement();
174+
} else if ("CopySourceStatusCode".equals(elementName.getLocalPart())) {
175+
deserializedStorageError.copySourceStatusCode = reader.getNullableElement(Integer::parseInt);
176+
} else if ("CopySourceErrorCode".equals(elementName.getLocalPart())) {
177+
deserializedStorageError.copySourceErrorCode = reader.getStringElement();
178+
} else if ("CopySourceErrorMessage".equals(elementName.getLocalPart())) {
179+
deserializedStorageError.copySourceErrorMessage = reader.getStringElement();
96180
} else {
97181
reader.skipElement();
98182
}

sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/specialized/AppendBlobApiTests.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -525,18 +525,22 @@ public void appendBlockFromURLMin() {
525525
validateBasicHeaders(response.getHeaders());
526526
}
527527

528-
/*@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
528+
@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
529529
@Test
530530
public void appendBlockFromURLSourceErrorAndStatusCodeNewTest() {
531531
AppendBlobClient destBlob = cc.getBlobClient(generateBlobName()).getAppendBlobClient();
532532
destBlob.createIfNotExists();
533-
534-
BlobStorageException e = assertThrows(BlobStorageException.class, () -> destBlob.appendBlockFromUrl(bc.getBlobUrl(), new BlobRange(0, (long) PageBlobClient.PAGE_BYTES)));
535-
536-
assertTrue(e.getStatusCode() == 409);
537-
assertTrue(e.getServiceMessage().contains("PublicAccessNotPermitted"));
538-
assertTrue(e.getServiceMessage().contains("Public access is not permitted on this storage account."));
539-
}*/
533+
534+
BlobStorageException e = assertThrows(BlobStorageException.class,
535+
() -> destBlob.appendBlockFromUrl(bc.getBlobUrl(), new BlobRange(0, (long) PageBlobClient.PAGE_BYTES)));
536+
537+
assertTrue(e.getStatusCode() == 401);
538+
assertTrue(e.getServiceMessage().contains("NoAuthenticationInformation"));
539+
assertTrue(e.getServiceMessage()
540+
.contains(
541+
"Server failed to authenticate the request. Please refer to the information in the www-authenticate header."));
542+
543+
}
540544

541545
@Test
542546
public void appendBlockFromURLRange() {

sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/specialized/AppendBlobAsyncApiTests.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -536,19 +536,24 @@ public void appendBlockFromURLMin() {
536536
}).verifyComplete();
537537
}
538538

539-
/*@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
539+
@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
540540
@Test
541541
public void appendBlockFromURLSourceErrorAndStatusCodeNewTest() {
542542
AppendBlobAsyncClient destBlob = ccAsync.getBlobAsyncClient(generateBlobName()).getAppendBlobAsyncClient();
543-
544-
StepVerifier.create(destBlob.createIfNotExists().then(destBlob.appendBlockFromUrl(bc.getBlobUrl(), new BlobRange(0, (long) PageBlobClient.PAGE_BYTES))))
543+
544+
StepVerifier
545+
.create(destBlob.createIfNotExists()
546+
.then(destBlob.appendBlockFromUrl(bc.getBlobUrl(), new BlobRange(0, (long) PageBlobClient.PAGE_BYTES))))
545547
.verifyErrorSatisfies(r -> {
546548
BlobStorageException e = assertInstanceOf(BlobStorageException.class, r);
547-
assertTrue(e.getStatusCode() == 409);
548-
assertTrue(e.getServiceMessage().contains("PublicAccessNotPermitted"));
549-
assertTrue(e.getServiceMessage().contains("Public access is not permitted on this storage account."));
549+
assertTrue(e.getStatusCode() == 401);
550+
assertTrue(e.getServiceMessage().contains("NoAuthenticationInformation"));
551+
assertTrue(e.getServiceMessage()
552+
.contains(
553+
"Server failed to authenticate the request. Please refer to the information in the www-authenticate header"));
554+
550555
});
551-
}*/
556+
}
552557

553558
@Test
554559
public void appendBlockFromURLRange() {

sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/specialized/BlobBaseApiTests.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -805,17 +805,20 @@ public void queryACFail(OffsetDateTime modified, OffsetDateTime unmodified, Stri
805805
assertThrows(BlobStorageException.class, () -> bc.queryWithResponse(optionsOs, null, null));
806806
}
807807

808-
/*@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
808+
@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
809809
@Test
810810
public void copyFromURLSourceErrorAndStatusCode() {
811811
BlockBlobClient destBlob = cc.getBlobClient(generateBlobName()).getBlockBlobClient();
812-
812+
813813
BlobStorageException e = assertThrows(BlobStorageException.class, () -> destBlob.copyFromUrl(bc.getBlobUrl()));
814-
815-
assertTrue(e.getStatusCode() == 409);
816-
assertTrue(e.getServiceMessage().contains("PublicAccessNotPermitted"));
817-
assertTrue(e.getServiceMessage().contains("Public access is not permitted on this storage account."));
818-
}*/
814+
815+
assertTrue(e.getStatusCode() == 401);
816+
assertTrue(e.getServiceMessage().contains("NoAuthenticationInformation"));
817+
assertTrue(e.getServiceMessage()
818+
.contains(
819+
"Server failed to authenticate the request. Please refer to the information in the www-authenticate header."));
820+
821+
}
819822

820823
static class MockProgressConsumer implements Consumer<BlobQueryProgress> {
821824

sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/specialized/BlobBaseAsyncApiTests.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
5353
import static org.junit.jupiter.api.Assertions.assertEquals;
5454
import static org.junit.jupiter.api.Assertions.assertFalse;
55+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
5556
import static org.junit.jupiter.api.Assertions.assertTrue;
5657

5758
public class BlobBaseAsyncApiTests extends BlobTestBase {
@@ -557,19 +558,21 @@ public void queryACFail(OffsetDateTime modified, OffsetDateTime unmodified, Stri
557558
StepVerifier.create(response).verifyError(BlobStorageException.class);
558559
}
559560

560-
/*@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
561+
@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
561562
@Test
562563
public void copyFromURLSourceErrorAndStatusCode() {
563564
BlockBlobAsyncClient destBlob = ccAsync.getBlobAsyncClient(generateBlobName()).getBlockBlobAsyncClient();
564-
565-
StepVerifier.create(destBlob.copyFromUrl(bc.getBlobUrl()))
566-
.verifyErrorSatisfies(r -> {
567-
BlobStorageException e = assertInstanceOf(BlobStorageException.class, r);
568-
assertTrue(e.getStatusCode() == 409);
569-
assertTrue(e.getServiceMessage().contains("PublicAccessNotPermitted"));
570-
assertTrue(e.getServiceMessage().contains("Public access is not permitted on this storage account."));
571-
});
572-
}*/
565+
566+
StepVerifier.create(destBlob.copyFromUrl(bc.getBlobUrl())).verifyErrorSatisfies(r -> {
567+
BlobStorageException e = assertInstanceOf(BlobStorageException.class, r);
568+
assertTrue(e.getStatusCode() == 401);
569+
assertTrue(e.getServiceMessage().contains("NoAuthenticationInformation"));
570+
assertTrue(e.getServiceMessage()
571+
.contains(
572+
"Server failed to authenticate the request. Please refer to the information in the www-authenticate header."));
573+
574+
});
575+
}
573576

574577
static class MockProgressConsumer implements Consumer<BlobQueryProgress> {
575578

sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/specialized/BlockBlobApiTests.java

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -373,19 +373,23 @@ public void stageBlockFromUrl() {
373373
assertEquals(ByteBuffer.wrap(outputStream.toByteArray()), DATA.getDefaultData());
374374
}
375375

376-
/*@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
376+
@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
377377
@Test
378378
public void stageBlockFromUrlSourceErrorAndStatusCode() {
379379
BlockBlobClient destBlob = cc.getBlobClient(generateBlobName()).getBlockBlobClient();
380-
380+
381381
String blockID = getBlockID();
382-
383-
BlobStorageException e = assertThrows(BlobStorageException.class, () -> destBlob.stageBlockFromUrl(blockID, blockBlobClient.getBlobUrl(), new BlobRange(0, (long) PageBlobClient.PAGE_BYTES)));
384-
385-
assertTrue(e.getStatusCode() == 409);
386-
assertTrue(e.getServiceMessage().contains("PublicAccessNotPermitted"));
387-
assertTrue(e.getServiceMessage().contains("Public access is not permitted on this storage account."));
388-
}*/
382+
383+
BlobStorageException e = assertThrows(BlobStorageException.class, () -> destBlob.stageBlockFromUrl(blockID,
384+
blockBlobClient.getBlobUrl(), new BlobRange(0, (long) PageBlobClient.PAGE_BYTES)));
385+
386+
assertTrue(e.getStatusCode() == 401);
387+
assertTrue(e.getServiceMessage().contains("NoAuthenticationInformation"));
388+
assertTrue(e.getServiceMessage()
389+
.contains(
390+
"Server failed to authenticate the request. Please refer to the information in the www-authenticate header."));
391+
392+
}
389393

390394
@Test
391395
public void stageBlockFromUrlMin() {
@@ -1449,17 +1453,20 @@ public void uploadFromUrlMin() {
14491453
TestUtils.assertArraysEqual(DATA.getDefaultBytes(), os.toByteArray());
14501454
}
14511455

1452-
/*@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
1456+
@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
14531457
@Test
14541458
public void uploadFromUrlSourceErrorAndStatusCode() {
14551459
BlockBlobClient destBlob = cc.getBlobClient(generateBlobName()).getBlockBlobClient();
1456-
1457-
BlobStorageException e = assertThrows(BlobStorageException.class, () -> destBlob.uploadFromUrl(blockBlobClient.getBlobUrl()));
1458-
1459-
assertTrue(e.getStatusCode() == 409);
1460-
assertTrue(e.getServiceMessage().contains("PublicAccessNotPermitted"));
1461-
assertTrue(e.getServiceMessage().contains("Public access is not permitted on this storage account."));
1462-
}*/
1460+
1461+
BlobStorageException e
1462+
= assertThrows(BlobStorageException.class, () -> destBlob.uploadFromUrl(blockBlobClient.getBlobUrl()));
1463+
1464+
assertTrue(e.getStatusCode() == 401);
1465+
assertTrue(e.getServiceMessage().contains("NoAuthenticationInformation"));
1466+
assertTrue(e.getServiceMessage()
1467+
.contains(
1468+
"Server failed to authenticate the request. Please refer to the information in the www-authenticate header."));
1469+
}
14631470

14641471
@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2020-04-08")
14651472
@Test

sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/specialized/BlockBlobAsyncApiTests.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -435,21 +435,24 @@ public void stageBlockFromUrl() {
435435
.verifyComplete();
436436
}
437437

438-
/*@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
438+
@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
439439
@Test
440440
public void stageBlockFromUrlSourceErrorAndStatusCode() {
441441
BlockBlobAsyncClient destBlob = ccAsync.getBlobAsyncClient(generateBlobName()).getBlockBlobAsyncClient();
442-
442+
443443
String blockID = getBlockID();
444-
445-
StepVerifier.create(destBlob.stageBlockFromUrl(blockID, blockBlobAsyncClient.getBlobUrl(), new BlobRange(0, (long) PageBlobClient.PAGE_BYTES)))
446-
.verifyErrorSatisfies(r -> {
444+
445+
StepVerifier.create(destBlob.stageBlockFromUrl(blockID, blockBlobAsyncClient.getBlobUrl(),
446+
new BlobRange(0, (long) PageBlobClient.PAGE_BYTES))).verifyErrorSatisfies(r -> {
447447
BlobStorageException e = assertInstanceOf(BlobStorageException.class, r);
448-
assertTrue(e.getStatusCode() == 409);
449-
assertTrue(e.getServiceMessage().contains("PublicAccessNotPermitted"));
450-
assertTrue(e.getServiceMessage().contains("Public access is not permitted on this storage account."));
448+
assertTrue(e.getStatusCode() == 401);
449+
assertTrue(e.getServiceMessage().contains("NoAuthenticationInformation"));
450+
assertTrue(e.getServiceMessage()
451+
.contains(
452+
"Server failed to authenticate the request. Please refer to the information in the www-authenticate header."));
453+
451454
});
452-
}*/
455+
}
453456

454457
@Test
455458
public void stageBlockFromUrlMin() {
@@ -2394,19 +2397,20 @@ public void uploadFromUrlMin() {
23942397
.verifyComplete();
23952398
}
23962399

2397-
/*@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
2400+
@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2024-08-04")
23982401
@Test
23992402
public void uploadFromUrlSourceErrorAndStatusCode() {
24002403
BlockBlobAsyncClient destBlob = ccAsync.getBlobAsyncClient(generateBlobName()).getBlockBlobAsyncClient();
2401-
2402-
StepVerifier.create(destBlob.uploadFromUrl(blockBlobAsyncClient.getBlobUrl()))
2403-
.verifyErrorSatisfies(r -> {
2404-
BlobStorageException e = assertInstanceOf(BlobStorageException.class, r);
2405-
assertTrue(e.getStatusCode() == 409);
2406-
assertTrue(e.getServiceMessage().contains("PublicAccessNotPermitted"));
2407-
assertTrue(e.getServiceMessage().contains("Public access is not permitted on this storage account."));
2408-
});
2409-
}*/
2404+
2405+
StepVerifier.create(destBlob.uploadFromUrl(blockBlobAsyncClient.getBlobUrl())).verifyErrorSatisfies(r -> {
2406+
BlobStorageException e = assertInstanceOf(BlobStorageException.class, r);
2407+
assertTrue(e.getStatusCode() == 401);
2408+
assertTrue(e.getServiceMessage().contains("NoAuthenticationInformation"));
2409+
assertTrue(e.getServiceMessage()
2410+
.contains(
2411+
"Server failed to authenticate the request. Please refer to the information in the www-authenticate header."));
2412+
});
2413+
}
24102414

24112415
@RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2020-04-08")
24122416
@Test

0 commit comments

Comments
 (0)