From ae54acca8555f5fabf8c433466c5113298a1cadc Mon Sep 17 00:00:00 2001 From: Josh Friedman Date: Fri, 10 Feb 2017 14:41:27 -0800 Subject: [PATCH 01/12] Share Snapshot Support --- BreakingChanges.txt | 11 +- ChangeLog.txt | 4 + .../storage/file/CloudFileClientTests.java | 51 ++- .../storage/file/CloudFileDirectoryTests.java | 71 +++- .../storage/file/CloudFileShareTests.java | 199 ++++++++++- .../azure/storage/file/CloudFileTests.java | 116 ++++++- .../azure/storage/file/FileTestHelper.java | 6 +- .../microsoft/azure/storage/Constants.java | 14 +- .../storage/StorageErrorCodeStrings.java | 5 + .../azure/storage/blob/BlobConstants.java | 5 - .../azure/storage/blob/BlobRequest.java | 2 +- .../com/microsoft/azure/storage/core/SR.java | 1 + .../core/SharedAccessSignatureHelper.java | 8 +- .../azure/storage/file/CloudFile.java | 153 ++++++--- .../azure/storage/file/CloudFileClient.java | 55 ++- .../storage/file/CloudFileDirectory.java | 77 +++-- .../azure/storage/file/CloudFileShare.java | 323 +++++++++++++++++- .../file/DeleteShareSnapshotsOption.java | 35 ++ .../azure/storage/file/FileOutputStream.java | 8 +- .../azure/storage/file/FileRequest.java | 148 +++++++- .../azure/storage/file/FileResponse.java | 11 + .../storage/file/FileShareProperties.java | 25 +- .../azure/storage/file/ShareListHandler.java | 6 + .../storage/file/ShareListingDetails.java | 8 +- 24 files changed, 1191 insertions(+), 151 deletions(-) create mode 100644 microsoft-azure-storage/src/com/microsoft/azure/storage/file/DeleteShareSnapshotsOption.java diff --git a/BreakingChanges.txt b/BreakingChanges.txt index 3101b223c40ea..7c93f08574014 100644 --- a/BreakingChanges.txt +++ b/BreakingChanges.txt @@ -1,3 +1,12 @@ +Changes in 6.0.0 + +FILE + * Exists() calls on Shares and Directories now populates metadata. This was already being done for Files. + * CloudFileShare constructor now takes a snapshotID String which can be null. + * FileRequest get methods now takes a snapshotID String which can be null. + * Changed listShares() ShareListingDetails parameter to be an enum set like what is done for listing blobs. + * In CloudFileShareProperties, setShareQuota() no longer asserts in bounds. This check has been moved to create() and uploadProperties() in CloudFileShare. + Changes in 5.0.0 BLOB @@ -5,7 +14,7 @@ BLOB * getQualifiedStorageUri() has been deprecated. Please use getSnapshotQualifiedStorageUri() instead. This new function will return the blob including the snapshot (if present) and no SAS token. * Fixed a bug where copying from a blob that included a SAS token and a snapshot did not use the SAS token. - FILE +FILE * Fixed a bug where copying from a blob that included a SAS token and a snapshot did not use the SAS token. QUEUE diff --git a/ChangeLog.txt b/ChangeLog.txt index bd2430e8943dc..ed782927c4f6c 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,7 @@ +2017.XX.XX Version 6.0.0 + * Added support for taking a snapshot of a share. + * Fixed Exists() calls on Shares and Directories to now populate metadata. This was already being done for Files. + 2017.01.18 Version 5.0.0 * Prefix support for listing files and directories. * Added support for setting public access when creating a blob container diff --git a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileClientTests.java b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileClientTests.java index f90b148a85acf..822009833421c 100644 --- a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileClientTests.java +++ b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileClientTests.java @@ -28,6 +28,8 @@ import java.net.URISyntaxException; import java.util.ArrayList; +import java.util.EnumSet; +import java.util.HashMap; import java.util.UUID; import static org.junit.Assert.*; @@ -64,8 +66,8 @@ public void testListSharesTest() throws StorageException, URISyntaxException { ResultContinuation token = null; do { - ResultSegment segment = fileClient.listSharesSegmented(prefix, ShareListingDetails.ALL, - 15, token, null, null); + ResultSegment segment = fileClient.listSharesSegmented(prefix, + EnumSet.allOf(ShareListingDetails.class), 15, token, null, null); for (final CloudFileShare share : segment.getResults()) { share.downloadAttributes(); @@ -102,7 +104,7 @@ public void testListSharesMaxResultsValidationTest() throws StorageException, UR for (int i = 0; i >= -2; i--) { try{ fileClient.listSharesSegmented( - prefix, ShareListingDetails.ALL, i, null, null, null); + prefix, EnumSet.allOf(ShareListingDetails.class), i, null, null, null); fail(); } catch (IllegalArgumentException e) { @@ -112,4 +114,47 @@ public void testListSharesMaxResultsValidationTest() throws StorageException, UR } assertNotNull(fileClient.listSharesSegmented("thereshouldntbeanyshareswiththisprefix")); } + + @Test + public void testListSharesWithSnapshot() throws StorageException, URISyntaxException { + CloudFileClient fileClient = FileTestHelper.createCloudFileClient(); + CloudFileShare share = fileClient.getShareReference(UUID.randomUUID().toString()); + share.create(); + + HashMap shareMeta = new HashMap(); + shareMeta.put("key1", "value1"); + share.setMetadata(shareMeta); + share.uploadMetadata(); + + CloudFileShare snapshot = share.createSnapshot(); + HashMap meta2 = new HashMap(); + meta2.put("key2", "value2"); + share.setMetadata(meta2); + share.uploadMetadata(); + + CloudFileClient client = FileTestHelper.createCloudFileClient(); + Iterable listResult = client.listShares(share.name, EnumSet.allOf(ShareListingDetails.class), null, null); + + int count = 0; + boolean originalFound = false; + boolean snapshotFound = false; + for (CloudFileShare listShareItem : listResult) { + if (listShareItem.getName().equals(share.getName()) && !listShareItem.isSnapshot() && !originalFound) + { + count++; + originalFound = true; + assertEquals(share.getMetadata(), listShareItem.getMetadata()); + assertEquals(share.getStorageUri(), listShareItem.getStorageUri()); + } + else if (listShareItem.getName().equals(share.getName()) && + listShareItem.isSnapshot() && !snapshotFound) { + count++; + snapshotFound = true; + assertEquals(snapshot.getMetadata(), listShareItem.getMetadata()); + assertEquals(snapshot.getStorageUri(), listShareItem.getStorageUri()); + } + } + + assertEquals(2, count); + } } \ No newline at end of file diff --git a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileDirectoryTests.java b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileDirectoryTests.java index fbf9e898e8b00..588e5f978852b 100644 --- a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileDirectoryTests.java +++ b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileDirectoryTests.java @@ -27,12 +27,14 @@ import com.microsoft.azure.storage.TestRunners.DevStoreTests; import com.microsoft.azure.storage.core.PathUtility; import com.microsoft.azure.storage.core.SR; +import com.microsoft.azure.storage.core.UriQueryBuilder; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; +import java.util.HashMap; import org.junit.After; import org.junit.Assert; @@ -460,7 +462,7 @@ public void testCloudFileDirectoryInvalidMetadata() throws StorageException, URI testMetadataFailures(directory, "key1", "\n \t", false); } - private static void testMetadataFailures(CloudFileDirectory directory, String key, String value, boolean badKey) { + private static void testMetadataFailures(CloudFileDirectory directory, String key, String value, boolean badKey) throws URISyntaxException { directory.getMetadata().put(key, value); try { directory.uploadMetadata(); @@ -478,6 +480,71 @@ private static void testMetadataFailures(CloudFileDirectory directory, String ke directory.getMetadata().remove(key); } + @Test + public void testUnsupportedDirectoryApisWithinShareSnapshot() throws StorageException, URISyntaxException { + CloudFileShare snapshot = this.share.createSnapshot(); + CloudFileDirectory rootDir = snapshot.getRootDirectoryReference(); + try { + rootDir.create(); + fail("Shouldn't get here"); + } + catch (IllegalArgumentException e) { + assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage()); + } + try { + rootDir.delete(); + fail("Shouldn't get here"); + } + catch (IllegalArgumentException e) { + assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage()); + } + try { + rootDir.uploadMetadata(); + fail("Shouldn't get here"); + } + catch (IllegalArgumentException e) { + assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage()); + } + + snapshot.delete(); + } + + @Test + public void testSupportedDirectoryApisInShareSnapshot() throws StorageException, URISyntaxException { + CloudFileDirectory dir = this.share.getRootDirectoryReference().getDirectoryReference("dir1"); + dir.deleteIfExists(); + dir.create(); + HashMap meta = new HashMap(); + meta.put("key1", "value1"); + dir.setMetadata(meta); + dir.uploadMetadata(); + CloudFileShare snapshot = this.share.createSnapshot(); + CloudFileDirectory snapshotDir = snapshot.getRootDirectoryReference().getDirectoryReference("dir1"); + + HashMap meta2 = new HashMap(); + meta2.put("key2", "value2"); + dir.setMetadata(meta2); + dir.uploadMetadata(); + snapshotDir.downloadAttributes(); + + assertTrue(snapshotDir.getMetadata().size() == 1 && snapshotDir.getMetadata().get("key1").equals("value1")); + assertNotNull(snapshotDir.getProperties().getEtag()); + + dir.downloadAttributes(); + assertTrue(dir.getMetadata().size() == 1 && dir.getMetadata().get("key2").equals("value2")); + assertNotNull(dir.getProperties().getEtag()); + assertNotEquals(dir.getProperties().getEtag(), snapshotDir.getProperties().getEtag()); + + final UriQueryBuilder uriBuilder = new UriQueryBuilder(); + uriBuilder.add("sharesnapshot", snapshot.snapshotID); + uriBuilder.add("restype", "directory"); + CloudFileDirectory snapshotDir2 = new CloudFileDirectory(uriBuilder.addToURI(dir.getUri()), this.share.getServiceClient().getCredentials()); + assertEquals(snapshot.snapshotID, snapshotDir2.getShare().snapshotID); + assertTrue(snapshotDir2.exists()); + + snapshot.delete(); + } + /* [TestMethod] [Description("CloudFileDirectory deleting a directory using conditional access")] @@ -807,6 +874,8 @@ public void eventOccurred(SendingRequestEvent eventArg) { } catch (StorageException e) { fail("Delete should succeed."); + } catch (URISyntaxException e) { + fail("Delete should succeed."); } } } diff --git a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileShareTests.java b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileShareTests.java index d7e62ed1a0b7c..81ea738d1ce53 100644 --- a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileShareTests.java +++ b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileShareTests.java @@ -25,6 +25,8 @@ import com.microsoft.azure.storage.TestRunners.DevFabricTests; import com.microsoft.azure.storage.TestRunners.DevStoreTests; import com.microsoft.azure.storage.TestRunners.SlowTests; +import com.microsoft.azure.storage.core.SR; +import com.microsoft.azure.storage.core.UriQueryBuilder; import org.junit.After; import org.junit.Assert; @@ -32,6 +34,7 @@ import org.junit.Test; import org.junit.experimental.categories.Category; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URISyntaxException; @@ -50,7 +53,6 @@ @Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class }) public class CloudFileShareTests { - protected static CloudFileClient client; protected CloudFileShare share; @Before @@ -60,7 +62,7 @@ public void fileShareTestMethodSetUp() throws StorageException, URISyntaxExcepti @After public void fileShareTestMethodTearDown() throws StorageException { - this.share.deleteIfExists(); + //this.share.deleteIfExists(); } /** @@ -316,7 +318,7 @@ public void testCloudFileShareUploadMetadata() throws StorageException, URISynta Assert.assertEquals("value2", this.share.getMetadata().get("key2")); Iterable shares = this.share.getServiceClient().listShares(this.share.getName(), - ShareListingDetails.METADATA, null, null); + EnumSet.of(ShareListingDetails.METADATA), null, null); for (CloudFileShare share3 : shares) { Assert.assertEquals(2, share3.getMetadata().size()); @@ -427,6 +429,7 @@ public void testCloudFileShareQuota() throws StorageException, URISyntaxExceptio try { shareQuota = FileConstants.MAX_SHARE_QUOTA + 1; this.share.getProperties().setShareQuota(shareQuota); + this.share.uploadProperties(); fail(); } catch (IllegalArgumentException e) { assertEquals(String.format(SR.PARAMETER_NOT_IN_RANGE, "Share Quota", 1, FileConstants.MAX_SHARE_QUOTA), @@ -491,6 +494,196 @@ public void eventOccurred(SendingRequestEvent eventArg) { assertTrue(this.share.deleteIfExists(null, null, ctx)); } + @Test + public void testCreateShareSnapshot() throws StorageException, URISyntaxException, IOException { + // create share with metadata + this.share.create(); + assertTrue(this.share.exists()); + HashMap shareMeta = new HashMap(); + shareMeta.put("key1", "value1"); + this.share.setMetadata(shareMeta); + this.share.uploadMetadata(); + + CloudFileDirectory dir1 = this.share.getRootDirectoryReference().getDirectoryReference("dir1"); + dir1.create(); + CloudFile file1 = dir1.getFileReference("file1"); + file1.create(1024); + ByteArrayInputStream srcStream = FileTestHelper.getRandomDataStream(1024); + file1.upload(srcStream, 1024); + + // create directory with metadata + HashMap dirMeta = new HashMap(); + dirMeta.put("key2", "value2"); + dir1.setMetadata(dirMeta); + dir1.uploadMetadata(); + + // verify that exists() call on snapshot populates metadata + CloudFileShare snapshot = this.share.createSnapshot(); + CloudFileClient client = FileTestHelper.createCloudFileClient(); + CloudFileShare snapshotRef = client.getShareReference(snapshot.name, snapshot.snapshotID); + assertTrue(snapshotRef.exists()); + assertTrue(snapshotRef.getMetadata().size() == 1 && snapshotRef.getMetadata().get("key1").equals("value1")); + + // verify that downloadAttributes() populates metadata + CloudFileShare snapshotRef2 = client.getShareReference(snapshot.name, snapshot.snapshotID); + snapshotRef2.downloadAttributes(); + snapshot.downloadAttributes(); + assertTrue(snapshotRef2.getMetadata().size() == 1 && snapshotRef2.getMetadata().get("key1").equals("value1")); + assertTrue(snapshot.getMetadata().size() == 1 && snapshot.getMetadata().get("key1").equals("value1")); + + // verify that exists() populates the metadata + CloudFileDirectory snapshotDir1 = snapshot.getRootDirectoryReference().getDirectoryReference("dir1"); + snapshotDir1.exists(); + assertTrue(snapshotDir1.getMetadata().size() == 1 && snapshotDir1.getMetadata().get("key2").equals("value2")); + + // verify that downloadAttributes() populates the metadata + CloudFileDirectory snapshotDir2 = snapshot.getRootDirectoryReference().getDirectoryReference("dir1"); + snapshotDir2.downloadAttributes(); + assertTrue(snapshotDir2.getMetadata().size() == 1 && snapshotDir2.getMetadata().get("key2").equals("value2")); + + // create snapshot with metadata + HashMap shareMeta2 = new HashMap(); + shareMeta2.put("abc", "def"); + CloudFileShare snapshotRef3 = this.share.createSnapshot(shareMeta2, null, null, null); + CloudFileShare snapshotRef4 = client.getShareReference(snapshotRef3.name, snapshotRef3.snapshotID); + assertTrue(snapshotRef4.exists()); + assertTrue(snapshotRef4.getMetadata().size() == 1 && snapshotRef4.getMetadata().get("abc").equals("def")); + + final UriQueryBuilder uriBuilder = new UriQueryBuilder(); + uriBuilder.add("sharesnapshot", snapshot.snapshotID); + CloudFileShare snapshotRef5 = new CloudFileShare(uriBuilder.addToURI(this.share.getUri()), + this.share.getServiceClient().getCredentials(), null); + assertEquals(snapshot.snapshotID, snapshotRef5.snapshotID); + assertTrue(snapshotRef5.exists()); + + snapshot.delete(); + } + + @Test + public void testDeleteShareSnapshotOptions() throws StorageException, URISyntaxException, IOException { + // create share with metadata + this.share.create(); + assertTrue(this.share.exists()); + + // verify that exists() call on snapshot populates metadata + CloudFileShare snapshot = this.share.createSnapshot(); + CloudFileClient client = FileTestHelper.createCloudFileClient(); + CloudFileShare snapshotRef = client.getShareReference(snapshot.name, snapshot.snapshotID); + assertTrue(snapshotRef.exists()); + + try { + share.delete(); + } + catch (final StorageException e) { + assertEquals(StorageErrorCodeStrings.SHARE_HAS_SNAPSHOTS, e.getErrorCode()); + } + + share.delete(DeleteShareSnapshotsOption.INCLUDE_SNAPSHOTS, null, null, null); + assertFalse(share.exists()); + assertFalse(snapshot.exists()); + } + + @Test + public void testListFilesAndDirectoriesWithinShareSnapshot() throws StorageException, URISyntaxException { + this.share.create(); + + CloudFileDirectory myDir = this.share.getRootDirectoryReference().getDirectoryReference("mydir"); + myDir.create(); + myDir.getFileReference("myfile").create(1024); + myDir.getDirectoryReference("yourDir").create(); + assertTrue(this.share.exists()); + + CloudFileShare snapshot = this.share.createSnapshot(); + CloudFileClient client = FileTestHelper.createCloudFileClient(); + CloudFileShare snapshotRef = client.getShareReference(snapshot.name, snapshot.snapshotID); + + Iterable listResult = snapshotRef.getRootDirectoryReference().listFilesAndDirectories(); + int count = 0; + for (ListFileItem listFileItem : listResult) { + count++; + assertEquals("mydir", ((CloudFileDirectory) listFileItem).getName()); + } + + assertEquals(1, count); + + count = 0; + listResult = snapshotRef.getRootDirectoryReference().getDirectoryReference("mydir").listFilesAndDirectories(); + for (ListFileItem listFileItem : listResult) { + if (listFileItem instanceof CloudFileDirectory) { + count++; + assertEquals("yourDir", ((CloudFileDirectory) listFileItem).getName()); + } + else { + count++; + assertEquals("myfile", ((CloudFile) listFileItem).getName()); + } + } + + assertEquals(2, count); + + snapshot.delete(); + } + + @Test + public void testUnsupportedApisShareSnapshot() throws StorageException, URISyntaxException { + CloudFileClient client = FileTestHelper.createCloudFileClient(); + this.share.create(); + this.share.downloadPermissions(); + CloudFileShare snapshot = this.share.createSnapshot(); + try { + snapshot.createSnapshot(); + fail("Shouldn't get here"); + } + catch (IllegalArgumentException e) { + assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage()); + } + try { + new CloudFileShare(snapshot.getQualifiedUri(), client.getCredentials(), "2016-10-24T16:37:17.0000000Z"); + fail("Shouldn't get here"); + } + catch (IllegalArgumentException e) { + assertEquals(SR.SNAPSHOT_QUERY_OPTION_ALREADY_DEFINED, e.getMessage()); + } + try { + snapshot.downloadPermissions(); + fail("Shouldn't get here"); + } + catch (IllegalArgumentException e) { + assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage()); + } + try { + snapshot.getStats(); + fail("Shouldn't get here"); + } + catch (IllegalArgumentException e) { + assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage()); + } + try { + snapshot.uploadMetadata(); + fail("Shouldn't get here"); + } + catch (IllegalArgumentException e) { + assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage()); + } + try { + FileSharePermissions permissions = new FileSharePermissions(); + snapshot.uploadPermissions(permissions); + fail("Shouldn't get here"); + } + catch (IllegalArgumentException e) { + assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage()); + } + try { + snapshot.uploadProperties(); + fail("Shouldn't get here"); + } + catch (IllegalArgumentException e) { + assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage()); + } + + snapshot.delete(); + } + private static void assertPermissionsEqual(FileSharePermissions expected, FileSharePermissions actual) { HashMap expectedPolicies = expected.getSharedAccessPolicies(); HashMap actualPolicies = actual.getSharedAccessPolicies(); diff --git a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileTests.java b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileTests.java index 9d165fb3a1e78..9aef81b54273b 100644 --- a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileTests.java +++ b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileTests.java @@ -1,4 +1,4 @@ -/** +/** * Copyright Microsoft Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -38,6 +38,9 @@ import com.microsoft.azure.storage.TestRunners.DevFabricTests; import com.microsoft.azure.storage.TestRunners.DevStoreTests; import com.microsoft.azure.storage.TestRunners.SlowTests; +import com.microsoft.azure.storage.core.SR; +import com.microsoft.azure.storage.core.UriQueryBuilder; +import com.microsoft.azure.storage.core.Utility; import org.junit.After; import org.junit.Before; @@ -48,6 +51,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.lang.reflect.Constructor; import java.net.HttpURLConnection; import java.net.URI; @@ -82,7 +86,7 @@ public void fileTestMethodSetUp() throws URISyntaxException, StorageException { @After public void fileTestMethodTearDown() throws StorageException { - this.share.deleteIfExists(); + //this.share.deleteIfExists(); } /** @@ -994,7 +998,7 @@ private void doUploadFromByteArrayTest(CloudFile file, int bufferSize, int buffe } } - private void doUploadDownloadFileTest(CloudFile file, int fileSize) throws IOException, StorageException { + private void doUploadDownloadFileTest(CloudFile file, int fileSize) throws IOException, StorageException, URISyntaxException { File sourceFile = File.createTempFile("sourceFile", ".tmp"); File destinationFile = new File(sourceFile.getParentFile(), "destinationFile.tmp"); @@ -1349,6 +1353,8 @@ public void eventOccurred(SendingRequestEvent eventArg) { } catch (StorageException e) { fail("Delete should succeed."); + } catch (URISyntaxException e) { + fail("Delete should succeed."); } } } @@ -1397,8 +1403,8 @@ public void testFileGetRangeContentMD5Bounds() throws StorageException, IOExcept FileRequestOptions options = new FileRequestOptions(); OperationContext opContext = new OperationContext(); try { - FileRequest.getFile(file.getUri(), options, opContext, null, 0L, 4L * Constants.MB, true); - FileRequest.getFile(file.getUri(), options, opContext, null, 0L, 4L * Constants.MB + 1, true); + FileRequest.getFile(file.getUri(), options, opContext, null, null, 0L, 4L * Constants.MB, true); + FileRequest.getFile(file.getUri(), options, opContext, null, null, 0L, 4L * Constants.MB + 1, true); fail("The request for range ContentMD5 should have thrown an Exception for exceeding the limit."); } catch (IllegalArgumentException e) @@ -1551,4 +1557,104 @@ private void doCloudFileCopy(boolean sourceIsSas, boolean destinationIsSas) destination.delete(); source.delete(); } + + @Test + public void testUnsupportedFileApisWithinShareSnapshot() throws StorageException, URISyntaxException { + CloudFileShare snapshot = this.share.createSnapshot(); + CloudFile file = snapshot.getRootDirectoryReference().getFileReference("file"); + + try { + file.create(1024); + fail("Shouldn't get here"); + } + catch (IllegalArgumentException e) { + assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage()); + } + try { + file.delete(); + fail("Shouldn't get here"); + } + catch (IllegalArgumentException e) { + assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage()); + } + try { + file.uploadMetadata(); + fail("Shouldn't get here"); + } + catch (IllegalArgumentException e) { + assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage()); + } + try { + file.abortCopy(null); + fail("Shouldn't get here"); + } + catch (IllegalArgumentException e) { + assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage()); + } + try { + file.clearRange(0, 512); + fail("Shouldn't get here"); + } + catch (IllegalArgumentException e) { + assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage()); + } + try { + file.startCopy(file); + fail("Shouldn't get here"); + } + catch (IllegalArgumentException e) { + assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage()); + } + try { + file.upload(null, 512); + fail("Shouldn't get here"); + } + catch (IllegalArgumentException e) { + assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage()); + } catch (IOException e) { + fail("Shouldn't get here"); + } + + snapshot.delete(); + } + + @Test + public void testSupportedFileApisInShareSnapshot() throws StorageException, URISyntaxException, UnsupportedEncodingException { + CloudFileDirectory dir = this.share.getRootDirectoryReference().getDirectoryReference("dir1"); + dir.deleteIfExists(); + dir.create(); + CloudFile file = dir.getFileReference("file"); + file.create(1024); + + HashMap meta = new HashMap(); + meta.put("key1", "value1"); + file.setMetadata(meta); + file.uploadMetadata(); + + CloudFileShare snapshot = this.share.createSnapshot(); + CloudFile snapshotFile = snapshot.getRootDirectoryReference() + .getDirectoryReference("dir1").getFileReference("file"); + + HashMap meta2 = new HashMap(); + meta2.put("key2", "value2"); + file.setMetadata(meta2); + file.uploadMetadata(); + snapshotFile.downloadAttributes(); + + assertTrue(snapshotFile.getMetadata().size() == 1 && snapshotFile.getMetadata().get("key1").equals("value1")); + assertNotNull(snapshotFile.getProperties().getEtag()); + + file.downloadAttributes(); + assertTrue(file.getMetadata().size() == 1 && file.getMetadata().get("key2").equals("value2")); + assertNotNull(file.getProperties().getEtag()); + assertNotEquals(file.getProperties().getEtag(), snapshotFile.getProperties().getEtag()); + + final UriQueryBuilder uriBuilder = new UriQueryBuilder(); + uriBuilder.add("sharesnapshot", snapshot.snapshotID); + CloudFile snapshotFile2 = new CloudFile(uriBuilder.addToURI(file.getUri()), this.share.getServiceClient().getCredentials()); + assertEquals(snapshot.snapshotID, snapshotFile2.getShare().snapshotID); + assertTrue(snapshotFile2.exists()); + + snapshot.delete(); + } } \ No newline at end of file diff --git a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/FileTestHelper.java b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/FileTestHelper.java index 6d4e90c35b037..4e7ca42364a4e 100644 --- a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/FileTestHelper.java +++ b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/FileTestHelper.java @@ -97,7 +97,7 @@ static StorageUri ensureTrailingSlash(StorageUri uri) throws URISyntaxException } protected static void doDownloadTest(CloudFile file, int fileSize, int bufferSize, int bufferOffset) - throws StorageException, IOException { + throws StorageException, IOException, URISyntaxException { final Random randGenerator = new Random(); final byte[] buffer = new byte[fileSize]; randGenerator.nextBytes(buffer); @@ -119,7 +119,7 @@ protected static void doDownloadTest(CloudFile file, int fileSize, int bufferSiz } protected static void doDownloadRangeToByteArrayTest(CloudFile file, int fileSize, int bufferSize, - int bufferOffset, Long fileOffset, Long length) throws IOException, StorageException { + int bufferOffset, Long fileOffset, Long length) throws IOException, StorageException, URISyntaxException { final Random randGenerator = new Random(); final byte[] buffer = new byte[fileSize]; randGenerator.nextBytes(buffer); @@ -153,7 +153,7 @@ protected static void doDownloadRangeToByteArrayTest(CloudFile file, int fileSiz } } - protected static void doDownloadRangeToByteArrayNegativeTests(CloudFile file) throws StorageException, IOException { + protected static void doDownloadRangeToByteArrayNegativeTests(CloudFile file) throws StorageException, IOException, URISyntaxException { int fileLength = 1024; int resultBufSize = 1024; final Random randGenerator = new Random(); diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/Constants.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/Constants.java index ebfdf56cc8020..cc0995cd9e109 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/Constants.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/Constants.java @@ -500,7 +500,12 @@ public static class HeaderConstants { * The blob sequence number equal condition header. */ public static final String IF_SEQUENCE_NUMBER_EQUAL = PREFIX_FOR_STORAGE_HEADER + "if-sequence-number-eq"; - + + /** + * Specifies snapshots are to be included. + */ + public static final String INCLUDE_SNAPSHOTS_VALUE = "include"; + /** * The header that specifies the lease action to perform */ @@ -636,7 +641,7 @@ public static class HeaderConstants { /** * The current storage version header value. */ - public static final String TARGET_STORAGE_VERSION = "2016-05-31"; + public static final String TARGET_STORAGE_VERSION = "2016-10-16"; /** * The header that specifies the next visible time for a queue message. @@ -808,6 +813,11 @@ public static class QueryConstants { */ public static final String SNAPSHOT = "snapshot"; + /** + * The query component for snapshot time. + */ + public static final String SHARE_SNAPSHOT = "sharesnapshot"; + /** * The query component for the SAS start partition key. */ diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageErrorCodeStrings.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageErrorCodeStrings.java index 5a1d596195c4e..cece90e8ff085 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageErrorCodeStrings.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageErrorCodeStrings.java @@ -569,6 +569,11 @@ public final class StorageErrorCodeStrings { */ public static final String SHARE_DISABLED = "ShareDisabled"; + /** + * The specified share contains snapshots. + */ + public static final String SHARE_HAS_SNAPSHOTS = "ShareHasSnapshots"; + /** * The specified share was not found. */ diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobConstants.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobConstants.java index 2e33407172e13..f2d7fd8adff81 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobConstants.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobConstants.java @@ -156,11 +156,6 @@ final class BlobConstants { */ public static final int DEFAULT_SINGLE_BLOB_PUT_THRESHOLD_IN_BYTES = 32 * Constants.MB; - /** - * Specifies snapshots are to be included. - */ - public static final String INCLUDE_SNAPSHOTS_VALUE = "include"; - /** * XML element for the latest. */ diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobRequest.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobRequest.java index 84b0ec68b8a95..7fe4e69b9c22d 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobRequest.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobRequest.java @@ -373,7 +373,7 @@ public static HttpURLConnection deleteBlob(final URI uri, final BlobRequestOptio break; case INCLUDE_SNAPSHOTS: request.setRequestProperty(Constants.HeaderConstants.DELETE_SNAPSHOT_HEADER, - BlobConstants.INCLUDE_SNAPSHOTS_VALUE); + HeaderConstants.INCLUDE_SNAPSHOTS_VALUE); break; case DELETE_SNAPSHOTS_ONLY: request.setRequestProperty(Constants.HeaderConstants.DELETE_SNAPSHOT_HEADER, diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/core/SR.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/core/SR.java index 43973d90aa717..279b500347b94 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/core/SR.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/core/SR.java @@ -103,6 +103,7 @@ public class SR { public static final String INVALID_MIME_RESPONSE = "Invalid MIME response received."; public static final String INVALID_NUMBER_OF_BYTES_IN_THE_BUFFER = "Page data must be a multiple of 512 bytes. Buffer currently contains %d bytes."; public static final String INVALID_OPERATION_FOR_A_SNAPSHOT = "Cannot perform this operation on a blob representing a snapshot."; + public static final String INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT = "Cannot perform this operation on a share representing a snapshot."; public static final String INVALID_PAGE_BLOB_LENGTH = "Page blob length must be multiple of 512."; public static final String INVALID_PAGE_START_OFFSET = "Page start offset must be multiple of 512."; public static final String INVALID_RANGE_CONTENT_MD5_HEADER = "Cannot specify x-ms-range-get-content-md5 header on ranges larger than 4 MB. Either use a BlobReadStream via openRead, or disable TransactionalMD5 via the BlobRequestOptions."; diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/core/SharedAccessSignatureHelper.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/core/SharedAccessSignatureHelper.java index af91d35a06f29..3826450a8c317 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/core/SharedAccessSignatureHelper.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/core/SharedAccessSignatureHelper.java @@ -418,7 +418,7 @@ public static StorageCredentialsSharedAccessSignature parseQuery(final StorageUr */ public static StorageCredentialsSharedAccessSignature parseQuery(final HashMap queryParams) throws StorageException { - + boolean sasParameterFound = false; List removeList = new ArrayList(); for (final Entry entry : queryParams.entrySet()) { @@ -434,9 +434,11 @@ public static StorageCredentialsSharedAccessSignature parseQuery(final HashMapCloudFile class using the specified absolute URI * and credentials. @@ -154,8 +154,9 @@ public CloudFile(final StorageUri fileAbsoluteUri) throws StorageException, URIS * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ - public CloudFile(final URI fileAbsoluteUri, final StorageCredentials credentials) throws StorageException { + public CloudFile(final URI fileAbsoluteUri, final StorageCredentials credentials) throws StorageException, URISyntaxException { this(new StorageUri(fileAbsoluteUri), credentials); } @@ -170,8 +171,9 @@ public CloudFile(final URI fileAbsoluteUri, final StorageCredentials credentials * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ - public CloudFile(final StorageUri fileAbsoluteUri, final StorageCredentials credentials) throws StorageException { + public CloudFile(final StorageUri fileAbsoluteUri, final StorageCredentials credentials) throws StorageException, URISyntaxException { this.parseQueryAndVerify(fileAbsoluteUri, credentials); } @@ -229,9 +231,10 @@ protected CloudFile(final StorageUri uri, final String fileName, final CloudFile * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest - public final void abortCopy(final String copyId) throws StorageException { + public final void abortCopy(final String copyId) throws StorageException, URISyntaxException { this.abortCopy(copyId, null /* accessCondition */, null /* options */, null /* opContext */); } @@ -253,14 +256,17 @@ public final void abortCopy(final String copyId) throws StorageException { * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest public final void abortCopy(final String copyId, final AccessCondition accessCondition, FileRequestOptions options, - OperationContext opContext) throws StorageException { + OperationContext opContext) throws StorageException, URISyntaxException { if (opContext == null) { opContext = new OperationContext(); } + this.getShare().assertNoSnapshot(); + opContext.initialize(); options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); @@ -426,9 +432,10 @@ public final String startCopy(final CloudFile sourceFile, final AccessCondition * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest - public final String startCopy(final URI source) throws StorageException { + public final String startCopy(final URI source) throws StorageException, URISyntaxException { return this.startCopy(source, null /* sourceAccessCondition */, null /* destinationAccessCondition */, null /* options */, null /* opContext */); } @@ -456,16 +463,19 @@ public final String startCopy(final URI source) throws StorageException { * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException * */ @DoesServiceRequest public final String startCopy(final URI source, final AccessCondition sourceAccessCondition, final AccessCondition destinationAccessCondition, FileRequestOptions options, OperationContext opContext) - throws StorageException { + throws StorageException, URISyntaxException { if (opContext == null) { opContext = new OperationContext(); } + this.getShare().assertNoSnapshot(); + opContext.initialize(); options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); @@ -534,9 +544,10 @@ public String preProcessResponse(CloudFile file, CloudFileClient client, Operati * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest - public void clearRange(final long offset, final long length) throws StorageException { + public void clearRange(final long offset, final long length) throws StorageException, URISyntaxException { this.clearRange(offset, length, null /* accessCondition */, null /* options */, null /* opContext */); } @@ -563,14 +574,17 @@ public void clearRange(final long offset, final long length) throws StorageExcep * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest public void clearRange(final long offset, final long length, final AccessCondition accessCondition, - FileRequestOptions options, OperationContext opContext) throws StorageException { + FileRequestOptions options, OperationContext opContext) throws StorageException, URISyntaxException { if (opContext == null) { opContext = new OperationContext(); } + this.getShare().assertNoSnapshot(); + options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); final FileRange range = new FileRange(offset, offset + length - 1); @@ -587,9 +601,10 @@ public void clearRange(final long offset, final long length, final AccessConditi * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest - public void create(final long size) throws StorageException { + public void create(final long size) throws StorageException, URISyntaxException { this.create(size, null /* accessCondition */, null /* options */, null /* opContext */); } @@ -612,15 +627,18 @@ public void create(final long size) throws StorageException { * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest public void create(final long size, final AccessCondition accessCondition, FileRequestOptions options, - OperationContext opContext) throws StorageException { + OperationContext opContext) throws StorageException, URISyntaxException { if (opContext == null) { opContext = new OperationContext(); } + this.getShare().assertNoSnapshot(); + options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); ExecutionEngine.executeWithRetry(this.fileServiceClient, this, this.createImpl(size, accessCondition, options), @@ -672,9 +690,10 @@ public Void preProcessResponse(CloudFile file, CloudFileClient client, Operation * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest - public final void delete() throws StorageException { + public final void delete() throws StorageException, URISyntaxException { this.delete(null /* accessCondition */, null /* options */, null /* opContext */); } @@ -694,14 +713,17 @@ public final void delete() throws StorageException { * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest public final void delete(final AccessCondition accessCondition, FileRequestOptions options, - OperationContext opContext) throws StorageException { + OperationContext opContext) throws StorageException, URISyntaxException { if (opContext == null) { opContext = new OperationContext(); } + this.getShare().assertNoSnapshot(); + opContext.initialize(); options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); @@ -716,10 +738,11 @@ public final void delete(final AccessCondition accessCondition, FileRequestOptio * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException * */ @DoesServiceRequest - public final boolean deleteIfExists() throws StorageException { + public final boolean deleteIfExists() throws StorageException, URISyntaxException { return this.deleteIfExists(null /* accessCondition */, null /* options */, null /* opContext */); } @@ -741,11 +764,13 @@ public final boolean deleteIfExists() throws StorageException { * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest public final boolean deleteIfExists(final AccessCondition accessCondition, FileRequestOptions options, - OperationContext opContext) throws StorageException { + OperationContext opContext) throws StorageException, URISyntaxException { options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); + this.getShare().assertNoSnapshot(); boolean exists = this.exists(true, accessCondition, options, opContext); if (exists) { @@ -1264,7 +1289,7 @@ public void setRequestLocationMode() { public HttpURLConnection buildRequest(CloudFileClient client, CloudFile file, OperationContext context) throws Exception { return FileRequest.getFileRanges(file.getTransformedAddress(context).getUri(this.getCurrentLocation()), - options, context, accessCondition); + options, context, accessCondition, file.getShare().snapshotID); } @Override @@ -1331,7 +1356,7 @@ public HttpURLConnection buildRequest(CloudFileClient client, CloudFile file, Op // : accessCondition; return FileRequest.getFile(file.getTransformedAddress(context).getUri(this.getCurrentLocation()), - options, context, accessCondition, this.getOffset(), this.getLength(), + options, context, accessCondition, file.getShare().snapshotID, this.getOffset(), this.getLength(), (options.getUseTransactionalContentMD5() && !this.getArePropertiesPopulated())); } @@ -1506,7 +1531,7 @@ public HttpURLConnection buildRequest(CloudFileClient client, CloudFile file, Op throws Exception { return FileRequest.getFileProperties( file.getTransformedAddress(context).getUri(this.getCurrentLocation()), - options, context, accessCondition); + options, context, accessCondition, file.getShare().snapshotID); } @Override @@ -1603,7 +1628,7 @@ public HttpURLConnection buildRequest(CloudFileClient client, CloudFile file, Op throws Exception { return FileRequest.getFileProperties( file.getTransformedAddress(context).getUri(this.getCurrentLocation()), - options, context, accessCondition); + options, context, accessCondition, file.getShare().snapshotID); } @Override @@ -1825,9 +1850,10 @@ public final FileInputStream openRead(final AccessCondition accessCondition, Fil * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest - public FileOutputStream openWriteExisting() throws StorageException { + public FileOutputStream openWriteExisting() throws StorageException, URISyntaxException { return this .openOutputStreamInternal(null /* length */, null /* accessCondition */, null /* options */, null /* opContext */); } @@ -1851,10 +1877,11 @@ public FileOutputStream openWriteExisting() throws StorageException { * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest public FileOutputStream openWriteExisting(AccessCondition accessCondition, FileRequestOptions options, - OperationContext opContext) throws StorageException { + OperationContext opContext) throws StorageException, URISyntaxException { return this .openOutputStreamInternal(null /* length */, null /* accessCondition */, null /* options */, null /* opContext */); } @@ -1874,9 +1901,10 @@ public FileOutputStream openWriteExisting(AccessCondition accessCondition, FileR * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest - public FileOutputStream openWriteNew(final long length) throws StorageException { + public FileOutputStream openWriteNew(final long length) throws StorageException, URISyntaxException { return this .openOutputStreamInternal(length, null /* accessCondition */, null /* options */, null /* opContext */); } @@ -1906,10 +1934,11 @@ public FileOutputStream openWriteNew(final long length) throws StorageException * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest public FileOutputStream openWriteNew(final long length, AccessCondition accessCondition, - FileRequestOptions options, OperationContext opContext) throws StorageException { + FileRequestOptions options, OperationContext opContext) throws StorageException, URISyntaxException { return openOutputStreamInternal(length, accessCondition, options, opContext); } @@ -1936,13 +1965,16 @@ public FileOutputStream openWriteNew(final long length, AccessCondition accessCo * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ private FileOutputStream openOutputStreamInternal(Long length, AccessCondition accessCondition, - FileRequestOptions options, OperationContext opContext) throws StorageException { + FileRequestOptions options, OperationContext opContext) throws StorageException, URISyntaxException { if (opContext == null) { opContext = new OperationContext(); } + this.getShare().assertNoSnapshot(); + options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient, false /* setStartTime */); if (length != null) { @@ -1977,9 +2009,10 @@ private FileOutputStream openOutputStreamInternal(Long length, AccessCondition a * @throws StorageException * If a storage service error occurred. * @throws IOException + * @throws URISyntaxException */ public void uploadFromByteArray(final byte[] buffer, final int offset, final int length) throws StorageException, - IOException { + IOException, URISyntaxException { uploadFromByteArray(buffer, offset, length, null /* accessCondition */, null /* options */, null /* opContext */); } @@ -2006,10 +2039,11 @@ public void uploadFromByteArray(final byte[] buffer, final int offset, final int * @throws StorageException * If a storage service error occurred. * @throws IOException + * @throws URISyntaxException */ public void uploadFromByteArray(final byte[] buffer, final int offset, final int length, final AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext) - throws StorageException, IOException { + throws StorageException, IOException, URISyntaxException { ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer, offset, length); this.upload(inputStream, length, accessCondition, options, opContext); inputStream.close(); @@ -2024,8 +2058,9 @@ public void uploadFromByteArray(final byte[] buffer, final int offset, final int * @throws StorageException * If a storage service error occurred. * @throws IOException + * @throws URISyntaxException */ - public void uploadFromFile(final String path) throws StorageException, IOException { + public void uploadFromFile(final String path) throws StorageException, IOException, URISyntaxException { uploadFromFile(path, null /* accessCondition */, null /* options */, null /* opContext */); } @@ -2048,9 +2083,10 @@ public void uploadFromFile(final String path) throws StorageException, IOExcepti * @throws StorageException * If a storage service error occurred. * @throws IOException + * @throws URISyntaxException */ public void uploadFromFile(final String path, final AccessCondition accessCondition, FileRequestOptions options, - OperationContext opContext) throws StorageException, IOException { + OperationContext opContext) throws StorageException, IOException, URISyntaxException { File file = new File(path); long fileLength = file.length(); InputStream inputStream = new BufferedInputStream(new java.io.FileInputStream(file)); @@ -2068,8 +2104,9 @@ public void uploadFromFile(final String path, final AccessCondition accessCondit * @throws StorageException * If a storage service error occurred. * @throws IOException + * @throws URISyntaxException */ - public void uploadText(final String content) throws StorageException, IOException { + public void uploadText(final String content) throws StorageException, IOException, URISyntaxException { this.uploadText(content, null /* charsetName */, null /* accessCondition */, null /* options */, null /* opContext */); } @@ -2096,9 +2133,10 @@ public void uploadText(final String content) throws StorageException, IOExceptio * @throws StorageException * If a storage service error occurred. * @throws IOException + * @throws URISyntaxException */ public void uploadText(final String content, final String charsetName, final AccessCondition accessCondition, - FileRequestOptions options, OperationContext opContext) throws StorageException, IOException { + FileRequestOptions options, OperationContext opContext) throws StorageException, IOException, URISyntaxException { byte[] bytes = (charsetName == null) ? content.getBytes() : content.getBytes(charsetName); this.uploadFromByteArray(bytes, 0, bytes.length, accessCondition, options, opContext); } @@ -2118,10 +2156,11 @@ public void uploadText(final String content, final String charsetName, final Acc * If an I/O exception occurred. * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest public void uploadRange(final InputStream sourceStream, final long offset, final long length) - throws StorageException, IOException { + throws StorageException, IOException, URISyntaxException { this.uploadRange(sourceStream, offset, length, null /* accessCondition */, null /* options */, null /* opContext */); } @@ -2150,15 +2189,18 @@ public void uploadRange(final InputStream sourceStream, final long offset, final * If an I/O exception occurred. * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest public void uploadRange(final InputStream sourceStream, final long offset, final long length, final AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext) - throws StorageException, IOException { + throws StorageException, IOException, URISyntaxException { if (opContext == null) { opContext = new OperationContext(); } + this.getShare().assertNoSnapshot(); + options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); final FileRange range = new FileRange(offset, offset + length - 1); @@ -2286,9 +2328,10 @@ public Void preProcessResponse(CloudFile file, CloudFileClient client, Operation * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest - public final void uploadMetadata() throws StorageException { + public final void uploadMetadata() throws StorageException, URISyntaxException { this.uploadMetadata(null /* accessCondition */, null /* options */, null /* opContext */); } @@ -2312,15 +2355,18 @@ public final void uploadMetadata() throws StorageException { * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest public final void uploadMetadata(final AccessCondition accessCondition, FileRequestOptions options, - OperationContext opContext) throws StorageException { + OperationContext opContext) throws StorageException, URISyntaxException { if (opContext == null) { opContext = new OperationContext(); } + this.getShare().assertNoSnapshot(); + opContext.initialize(); options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); @@ -2376,9 +2422,10 @@ public Void preProcessResponse(CloudFile file, CloudFileClient client, Operation * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest - public final void uploadProperties() throws StorageException { + public final void uploadProperties() throws StorageException, URISyntaxException { this.uploadProperties(null /* accessCondition */, null /* options */, null /*opContext */); } @@ -2401,14 +2448,17 @@ public final void uploadProperties() throws StorageException { * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest public final void uploadProperties(final AccessCondition accessCondition, FileRequestOptions options, - OperationContext opContext) throws StorageException { + OperationContext opContext) throws StorageException, URISyntaxException { if (opContext == null) { opContext = new OperationContext(); } + this.getShare().assertNoSnapshot(); + opContext.initialize(); options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); @@ -2460,8 +2510,9 @@ public Void preProcessResponse(CloudFile file, CloudFileClient client, Operation * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ - public void resize(long size) throws StorageException { + public void resize(long size) throws StorageException, URISyntaxException { this.resize(size, null /* accessCondition */, null /* options */, null /* operationContext */); } @@ -2483,13 +2534,16 @@ public void resize(long size) throws StorageException { * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ public void resize(long size, AccessCondition accessCondition, FileRequestOptions options, - OperationContext opContext) throws StorageException { + OperationContext opContext) throws StorageException, URISyntaxException { if (opContext == null) { opContext = new OperationContext(); } + this.getShare().assertNoSnapshot(); + opContext.initialize(); options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); @@ -2544,9 +2598,10 @@ public Void preProcessResponse(CloudFile file, CloudFileClient client, Operation * If an I/O exception occurred. * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest - public void upload(final InputStream sourceStream, final long length) throws StorageException, IOException { + public void upload(final InputStream sourceStream, final long length) throws StorageException, IOException, URISyntaxException { this.upload(sourceStream, length, null /* accessCondition */, null /* options */, null /* opContext */); } @@ -2574,14 +2629,17 @@ public void upload(final InputStream sourceStream, final long length) throws Sto * If an I/O exception occurred. * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest public void upload(final InputStream sourceStream, final long length, final AccessCondition accessCondition, - FileRequestOptions options, OperationContext opContext) throws StorageException, IOException { + FileRequestOptions options, OperationContext opContext) throws StorageException, IOException, URISyntaxException { if (opContext == null) { opContext = new OperationContext(); } + this.getShare().assertNoSnapshot(); + options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); if (length <= 0) { @@ -2670,9 +2728,10 @@ protected static String getParentNameFromURI(final StorageUri resourceAddress, f * A {@link StorageCredentials} object used to authenticate access. * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ private void parseQueryAndVerify(final StorageUri completeUri, final StorageCredentials credentials) - throws StorageException { + throws StorageException, URISyntaxException { Utility.assertNotNull("completeUri", completeUri); if (!completeUri.isAbsolute()) { @@ -2680,7 +2739,7 @@ private void parseQueryAndVerify(final StorageUri completeUri, final StorageCred } this.storageUri = PathUtility.stripURIQueryAndFragment(completeUri); - + final StorageCredentialsSharedAccessSignature parsedCredentials = SharedAccessSignatureHelper.parseQuery(completeUri); @@ -2697,6 +2756,13 @@ private void parseQueryAndVerify(final StorageUri completeUri, final StorageCred catch (final URISyntaxException e) { throw Utility.generateNewUnexpectedStorageException(e); } + + final HashMap queryParameters = PathUtility.parseQueryString(completeUri.getQuery()); + + final String[] snapshotIDs = queryParameters.get(Constants.QueryConstants.SHARE_SNAPSHOT); + if (snapshotIDs != null && snapshotIDs.length > 0) { + this.getShare().snapshotID = snapshotIDs[0]; + } } protected void updateEtagAndLastModifiedFromResponse(HttpURLConnection request) { @@ -2733,7 +2799,8 @@ public final CloudFileShare getShare() throws StorageException, URISyntaxExcepti if (this.share == null) { final StorageUri shareUri = PathUtility.getShareURI(this.getStorageUri(), this.fileServiceClient.isUsePathStyleUris()); - this.share = new CloudFileShare(shareUri, this.fileServiceClient.getCredentials()); + + this.share = new CloudFileShare(shareUri, this.fileServiceClient.getCredentials(), null); } return this.share; diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileClient.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileClient.java index f5bac5295393b..030fa41529868 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileClient.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileClient.java @@ -17,6 +17,7 @@ import java.net.HttpURLConnection; import java.net.URI; import java.net.URISyntaxException; +import java.util.EnumSet; import com.microsoft.azure.storage.DoesServiceRequest; import com.microsoft.azure.storage.OperationContext; @@ -100,7 +101,29 @@ public CloudFileClient(StorageUri storageUri, StorageCredentials credentials) { */ public CloudFileShare getShareReference(final String shareName) throws URISyntaxException, StorageException { Utility.assertNotNullOrEmpty("shareName", shareName); - return new CloudFileShare(shareName, this); + return this.getShareReference(shareName, null); + } + + /** + * Gets a {@link CloudFileShare} object with the specified name. + * + * @param shareName + * The name of the share, which must adhere to share naming rules. The share name should not + * include any path separator characters (/). + * Share names must be lowercase, between 3-63 characters long and must start with a letter or + * number. Share names may contain only letters, numbers, and the dash (-) character. + * @param snapshotID + * A String that represents the snapshot ID of the share. + * @return A reference to a {@link CloudFileShare} object. + * @throws StorageException + * @throws URISyntaxException + * + * @see Naming and Referencing Shares, + * Directories, Files, and Metadata + */ + public CloudFileShare getShareReference(final String shareName, String snapshotID) throws URISyntaxException, StorageException { + Utility.assertNotNullOrEmpty("shareName", shareName); + return new CloudFileShare(shareName, snapshotID, this); } /** @@ -111,7 +134,7 @@ public CloudFileShare getShareReference(final String shareName) throws URISyntax */ @DoesServiceRequest public Iterable listShares() { - return this.listSharesWithPrefix(null, ShareListingDetails.NONE, null /* options */, null /* opContext */); + return this.listSharesWithPrefix(null, EnumSet.noneOf(ShareListingDetails.class), null /* options */, null /* opContext */); } /** @@ -126,7 +149,7 @@ public Iterable listShares() { */ @DoesServiceRequest public Iterable listShares(final String prefix) { - return this.listSharesWithPrefix(prefix, ShareListingDetails.NONE, null /* options */, null /* opContext */); + return this.listSharesWithPrefix(prefix, EnumSet.noneOf(ShareListingDetails.class), null /* options */, null /* opContext */); } /** @@ -136,7 +159,8 @@ public Iterable listShares(final String prefix) { * @param prefix * A String that represents the share name prefix. * @param detailsIncluded - * A {@link ShareListingDetails} value that indicates whether share metadata will be returned. + * A java.util.EnumSet object that contains {@link ShareListingDetails} values that indicate + * whether share snapshots and/or metadata will be returned. * @param options * A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying * null will use the default request options from the associated service client ( @@ -150,7 +174,7 @@ public Iterable listShares(final String prefix) { * shares for this client. */ @DoesServiceRequest - public Iterable listShares(final String prefix, final ShareListingDetails detailsIncluded, + public Iterable listShares(final String prefix, final EnumSet detailsIncluded, final FileRequestOptions options, final OperationContext opContext) { return this.listSharesWithPrefix(prefix, detailsIncluded, options, opContext); } @@ -166,7 +190,7 @@ public Iterable listShares(final String prefix, final ShareListi */ @DoesServiceRequest public ResultSegment listSharesSegmented() throws StorageException { - return this.listSharesSegmented(null, ShareListingDetails.NONE, null, null /* continuationToken */, + return this.listSharesSegmented(null, EnumSet.noneOf(ShareListingDetails.class), null, null /* continuationToken */, null /* options */, null /* opContext */); } @@ -186,7 +210,7 @@ public ResultSegment listSharesSegmented() throws StorageExcepti */ @DoesServiceRequest public ResultSegment listSharesSegmented(final String prefix) throws StorageException { - return this.listSharesWithPrefixSegmented(prefix, ShareListingDetails.NONE, null, null /* continuationToken */, + return this.listSharesWithPrefixSegmented(prefix, EnumSet.noneOf(ShareListingDetails.class), null, null /* continuationToken */, null /* options */, null /* opContext */); } @@ -197,7 +221,8 @@ public ResultSegment listSharesSegmented(final String prefix) th * @param prefix * A String that represents the prefix of the share name. * @param detailsIncluded - * A {@link ShareListingDetails} value that indicates whether share metadata will be returned. + * A java.util.EnumSet object that contains {@link ShareListingDetails} values that indicate + * whether share snapshots and/or metadata will be returned. * @param maxResults * The maximum number of results to retrieve. If null or greater * than 5000, the server will return up to 5,000 items. Must be at least 1. @@ -221,7 +246,7 @@ public ResultSegment listSharesSegmented(final String prefix) th */ @DoesServiceRequest public ResultSegment listSharesSegmented(final String prefix, - final ShareListingDetails detailsIncluded, final Integer maxResults, + final EnumSet detailsIncluded, final Integer maxResults, final ResultContinuation continuationToken, final FileRequestOptions options, final OperationContext opContext) throws StorageException { return this.listSharesWithPrefixSegmented(prefix, detailsIncluded, maxResults, continuationToken, options, @@ -235,7 +260,8 @@ public ResultSegment listSharesSegmented(final String prefix, * @param prefix * A String that represents the prefix of the share name. * @param detailsIncluded - * A {@link ShareListingDetails} value that indicates whether share metadata will be returned. + * A java.util.EnumSet object that contains {@link ShareListingDetails} + * values that indicate whether snapshots and/or metadata are returned. * @param options * A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying * null will use the default request options from the associated service client ( @@ -249,7 +275,7 @@ public ResultSegment listSharesSegmented(final String prefix, * shares whose names begin with the specified prefix. */ private Iterable listSharesWithPrefix(final String prefix, - final ShareListingDetails detailsIncluded, FileRequestOptions options, OperationContext opContext) { + final EnumSet detailsIncluded, FileRequestOptions options, OperationContext opContext) { if (opContext == null) { opContext = new OperationContext(); } @@ -271,7 +297,8 @@ private Iterable listSharesWithPrefix(final String prefix, * @param prefix * A String that represents the prefix of the share name. * @param detailsIncluded - * A {@link FileListingDetails} value that indicates whether share metadata will be returned. + * A java.util.EnumSet object that contains {@link ShareListingDetails} values that indicate + * whether share snapshots and/or metadata will be returned. * @param maxResults * The maximum number of results to retrieve. If null or greater * than 5000, the server will return up to 5,000 items. Must be at least 1. @@ -294,7 +321,7 @@ private Iterable listSharesWithPrefix(final String prefix, * If a storage service error occurred. */ private ResultSegment listSharesWithPrefixSegmented(final String prefix, - final ShareListingDetails detailsIncluded, final Integer maxResults, + final EnumSet detailsIncluded, final Integer maxResults, final ResultContinuation continuationToken, FileRequestOptions options, OperationContext opContext) throws StorageException { if (opContext == null) { @@ -315,7 +342,7 @@ private ResultSegment listSharesWithPrefixSegmented(final String } private StorageRequest> listSharesWithPrefixSegmentedImpl( - final String prefix, final ShareListingDetails detailsIncluded, final Integer maxResults, + final String prefix, final EnumSet detailsIncluded, final Integer maxResults, final FileRequestOptions options, final SegmentedStorageRequest segmentedRequest) { Utility.assertContinuationType(segmentedRequest.getToken(), ResultContinuationType.SHARE); diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileDirectory.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileDirectory.java index a479446359aad..92735f7b6c9ab 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileDirectory.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileDirectory.java @@ -94,8 +94,9 @@ public final class CloudFileDirectory implements ListFileItem { * @param directoryAbsoluteUri * A {@link URI} that represents the file directory's address. * @throws StorageException + * @throws URISyntaxException */ - public CloudFileDirectory(final URI directoryAbsoluteUri) throws StorageException { + public CloudFileDirectory(final URI directoryAbsoluteUri) throws StorageException, URISyntaxException { this(new StorageUri(directoryAbsoluteUri)); } @@ -105,8 +106,9 @@ public CloudFileDirectory(final URI directoryAbsoluteUri) throws StorageExceptio * @param directoryAbsoluteUri * A {@link StorageUri} that represents the file directory's address. * @throws StorageException + * @throws URISyntaxException */ - public CloudFileDirectory(final StorageUri directoryAbsoluteUri) throws StorageException { + public CloudFileDirectory(final StorageUri directoryAbsoluteUri) throws StorageException, URISyntaxException { this(directoryAbsoluteUri, (StorageCredentials) null); } @@ -119,9 +121,10 @@ public CloudFileDirectory(final StorageUri directoryAbsoluteUri) throws StorageE * @param credentials * A {@link StorageCredentials} object used to authenticate access. * @throws StorageException + * @throws URISyntaxException */ public CloudFileDirectory(final URI directoryAbsoluteUri, final StorageCredentials credentials) - throws StorageException { + throws StorageException, URISyntaxException { this(new StorageUri(directoryAbsoluteUri), credentials); } @@ -134,9 +137,10 @@ public CloudFileDirectory(final URI directoryAbsoluteUri, final StorageCredentia * @param credentials * A {@link StorageCredentials} object used to authenticate access. * @throws StorageException + * @throws URISyntaxException */ public CloudFileDirectory(final StorageUri directoryAbsoluteUri, final StorageCredentials credentials) - throws StorageException { + throws StorageException, URISyntaxException { this.parseQueryAndVerify(directoryAbsoluteUri, credentials); } @@ -167,9 +171,10 @@ protected CloudFileDirectory(final StorageUri uri, final String directoryName, f * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest - public void create() throws StorageException { + public void create() throws StorageException, URISyntaxException { this.create(null /* options */, null /* opContext */); } @@ -187,13 +192,16 @@ public void create() throws StorageException { * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest - public void create(FileRequestOptions options, OperationContext opContext) throws StorageException { + public void create(FileRequestOptions options, OperationContext opContext) throws StorageException, URISyntaxException { if (opContext == null) { opContext = new OperationContext(); } + this.getShare().assertNoSnapshot(); + opContext.initialize(); options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); @@ -250,9 +258,10 @@ public Void preProcessResponse(CloudFileDirectory directory, CloudFileClient cli * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest - public boolean createIfNotExists() throws StorageException { + public boolean createIfNotExists() throws StorageException, URISyntaxException { return this.createIfNotExists(null /* options */, null /* opContext */); } @@ -272,11 +281,14 @@ public boolean createIfNotExists() throws StorageException { * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest - public boolean createIfNotExists(FileRequestOptions options, OperationContext opContext) throws StorageException { + public boolean createIfNotExists(FileRequestOptions options, OperationContext opContext) throws StorageException, URISyntaxException { options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); + this.getShare().assertNoSnapshot(); + boolean exists = this.exists(true /* primaryOnly */, null /* accessCondition */, options, opContext); if (exists) { return false; @@ -303,9 +315,10 @@ public boolean createIfNotExists(FileRequestOptions options, OperationContext op * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest - public void delete() throws StorageException { + public void delete() throws StorageException, URISyntaxException { this.delete(null /* accessCondition */, null /* options */, null /* opContext */); } @@ -325,14 +338,17 @@ public void delete() throws StorageException { * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest public void delete(AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext) - throws StorageException { + throws StorageException, URISyntaxException { if (opContext == null) { opContext = new OperationContext(); } + this.getShare().assertNoSnapshot(); + opContext.initialize(); options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); @@ -378,9 +394,10 @@ public Void preProcessResponse(CloudFileDirectory directory, CloudFileClient cli * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest - public boolean deleteIfExists() throws StorageException { + public boolean deleteIfExists() throws StorageException, URISyntaxException { return this.deleteIfExists(null /* accessCondition */, null /* options */, null /* opContext */); } @@ -402,10 +419,11 @@ public boolean deleteIfExists() throws StorageException { * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest public boolean deleteIfExists(AccessCondition accessCondition, FileRequestOptions options, - OperationContext opContext) throws StorageException { + OperationContext opContext) throws StorageException, URISyntaxException { options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); boolean exists = this.exists(true /* primaryOnly */, accessCondition, options, opContext); @@ -498,7 +516,7 @@ public HttpURLConnection buildRequest(CloudFileClient client, CloudFileDirectory OperationContext context) throws Exception { return FileRequest.getDirectoryProperties( directory.getTransformedAddress().getUri(this.getCurrentLocation()), options, context, - accessCondition); + accessCondition, directory.getShare().snapshotID); } @Override @@ -511,7 +529,12 @@ public void signRequest(HttpURLConnection connection, CloudFileClient client, Op public Boolean preProcessResponse(CloudFileDirectory directory, CloudFileClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() == HttpURLConnection.HTTP_OK) { - directory.updatePropertiesFromResponse(this.getConnection()); + // Set properties + final FileDirectoryAttributes attributes = + FileResponse.getFileDirectoryAttributes(this.getConnection(), client.isUsePathStyleUris()); + directory.setMetadata(attributes.getMetadata()); + directory.setProperties(attributes.getProperties()); + return Boolean.valueOf(true); } else if (this.getResult().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) { @@ -546,9 +569,10 @@ private void updatePropertiesFromResponse(HttpURLConnection request) { * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest - public void uploadMetadata() throws StorageException { + public void uploadMetadata() throws StorageException, URISyntaxException { this.uploadMetadata(null /* accessCondition */, null /* options */, null /* opContext */); } @@ -568,14 +592,17 @@ public void uploadMetadata() throws StorageException { * * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ @DoesServiceRequest public void uploadMetadata(AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext) - throws StorageException { + throws StorageException, URISyntaxException { if (opContext == null) { opContext = new OperationContext(); } + this.getShare().assertNoSnapshot(); + opContext.initialize(); options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); @@ -679,7 +706,7 @@ public HttpURLConnection buildRequest(CloudFileClient client, CloudFileDirectory OperationContext context) throws Exception { return FileRequest.getDirectoryProperties( directory.getTransformedAddress().getUri(this.getCurrentLocation()), options, context, - accessCondition); + accessCondition, directory.getShare().snapshotID); } @Override @@ -900,7 +927,7 @@ public HttpURLConnection buildRequest(CloudFileClient client, CloudFileDirectory .getNextMarker() : null); return FileRequest.listFilesAndDirectories( directory.getTransformedAddress().getUri(this.getCurrentLocation()), - options, context, listingContext); + options, context, listingContext, directory.getShare().snapshotID); } @Override @@ -1058,7 +1085,9 @@ public CloudFileDirectory getParent() throws URISyntaxException, StorageExceptio if (parentName != null) { StorageUri parentURI = PathUtility.appendPathToUri(this.getShare().getStorageUri(), parentName); + this.parent = new CloudFileDirectory(parentURI, this.getServiceClient().getCredentials()); + //this.parent = new CloudFileDirectory(parentURI, parentName, this.getShare()); } } return this.parent; @@ -1135,9 +1164,10 @@ protected void setStorageUri(final StorageUri storageUri) { * A {@link StorageCredentials} object used to authenticate access. * @throws StorageException * If a storage service error occurred. + * @throws URISyntaxException */ private void parseQueryAndVerify(final StorageUri completeUri, final StorageCredentials credentials) - throws StorageException { + throws StorageException, URISyntaxException { Utility.assertNotNull("completeUri", completeUri); if (!completeUri.isAbsolute()) { @@ -1145,7 +1175,7 @@ private void parseQueryAndVerify(final StorageUri completeUri, final StorageCred } this.storageUri = PathUtility.stripURIQueryAndFragment(completeUri); - + final StorageCredentialsSharedAccessSignature parsedCredentials = SharedAccessSignatureHelper.parseQuery(completeUri); @@ -1162,6 +1192,13 @@ private void parseQueryAndVerify(final StorageUri completeUri, final StorageCred catch (final URISyntaxException e) { throw Utility.generateNewUnexpectedStorageException(e); } + + final HashMap queryParameters = PathUtility.parseQueryString(completeUri.getQuery()); + + final String[] snapshotIDs = queryParameters.get(Constants.QueryConstants.SHARE_SNAPSHOT); + if (snapshotIDs != null && snapshotIDs.length > 0) { + this.getShare().snapshotID = snapshotIDs[0]; + } } /** diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileShare.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileShare.java index 64fa0328ac61b..4345788def410 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileShare.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileShare.java @@ -78,6 +78,11 @@ public final class CloudFileShare { */ private StorageUri storageUri; + /** + * Holds the snapshot ID. + */ + String snapshotID; + /** * Holds a reference to the associated service client. */ @@ -92,6 +97,8 @@ public final class CloudFileShare { * The share name should not include any path separator characters (/). * Share names must be lowercase, between 3-63 characters long and must start with a letter or * number. Share names may contain only letters, numbers, and the dash (-) character. + * @param snapshotID + * A String that represents the snapshot version, if applicable. * @param client * A {@link CloudFileClient} object that represents the associated service client, and that specifies the * endpoint for the File service. @@ -104,13 +111,14 @@ public final class CloudFileShare { * @see Naming and Referencing Shares, * Directories, Files, and Metadata */ - protected CloudFileShare(final String shareName, final CloudFileClient client) throws URISyntaxException, + protected CloudFileShare(final String shareName, String snapshotID, final CloudFileClient client) throws URISyntaxException, StorageException { Utility.assertNotNull("client", client); Utility.assertNotNull("shareName", shareName); this.storageUri = PathUtility.appendPathToUri(client.getStorageUri(), shareName); this.name = shareName; + this.snapshotID = snapshotID; this.fileServiceClient = client; } @@ -137,9 +145,9 @@ public CloudFileShare(final URI uri) throws StorageException { * If a storage service error occurred. */ public CloudFileShare(final StorageUri storageUri) throws StorageException { - this(storageUri, (StorageCredentials) null); + this(storageUri, (StorageCredentials) null, null); } - + /** * Creates an instance of the CloudFileShare class using the specified URI and credentials. * @@ -147,12 +155,14 @@ public CloudFileShare(final StorageUri storageUri) throws StorageException { * A java.net.URI object that represents the absolute URI of the share. * @param credentials * A {@link StorageCredentials} object used to authenticate access. + * @param snapshotID + * A String that represents the snapshot version, if applicable. * * @throws StorageException * If a storage service error occurred. */ - public CloudFileShare(final URI uri, final StorageCredentials credentials) throws StorageException { - this(new StorageUri(uri), credentials); + public CloudFileShare(final URI uri, final StorageCredentials credentials, String snapshotID) throws StorageException { + this(new StorageUri(uri), credentials, snapshotID); } /** @@ -162,12 +172,22 @@ public CloudFileShare(final URI uri, final StorageCredentials credentials) throw * A {@link StorageUri} object which represents the absolute StorageUri of the share. * @param credentials * A {@link StorageCredentials} object used to authenticate access. - * + * @param snapshotID + * A String that represents the snapshot version, if applicable. * @throws StorageException * If a storage service error occurred. */ - public CloudFileShare(final StorageUri storageUri, final StorageCredentials credentials) throws StorageException { + public CloudFileShare(final StorageUri storageUri, final StorageCredentials credentials, String snapshotID) throws StorageException { this.parseQueryAndVerify(storageUri, credentials); + + if (snapshotID != null) { + if (this.snapshotID != null) { + throw new IllegalArgumentException(SR.SNAPSHOT_QUERY_OPTION_ALREADY_DEFINED); + } + else { + this.snapshotID = snapshotID; + } + } } /** @@ -202,6 +222,11 @@ public void create(FileRequestOptions options, OperationContext opContext) throw opContext = new OperationContext(); } + assertNoSnapshot(); + if (this.properties != null && this.properties.getShareQuota() != null) { + Utility.assertInBounds("Share Quota", this.properties.getShareQuota(), 1, FileConstants.MAX_SHARE_QUOTA); + } + opContext.initialize(); options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); @@ -319,7 +344,7 @@ public boolean createIfNotExists(FileRequestOptions options, OperationContext op */ @DoesServiceRequest public void delete() throws StorageException { - this.delete(null /* accessCondition */, null /* options */, null /* opContext */); + this.delete(DeleteShareSnapshotsOption.NONE, null /* accessCondition */, null /* options */, null /* opContext */); } /** @@ -342,6 +367,36 @@ public void delete() throws StorageException { @DoesServiceRequest public void delete(AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext) throws StorageException { + this.delete(DeleteShareSnapshotsOption.NONE, accessCondition, options, opContext); + } + + /** + * Deletes the share using the specified snapshot and request options, and operation context. + *

+ * A share that has snapshots cannot be deleted unless the snapshots are also deleted. If a share has snapshots, use + * the {@link DeleteShareSnapshotsOption#INCLUDE_SNAPSHOTS} value + * in the deleteSnapshotsOption parameter to include the snapshots when deleting the base share. + * + * @param deleteSnapshotsOption + * A {@link DeleteShareSnapshotsOption} object that indicates whether to delete only snapshots, or the share + * and its snapshots. + * @param accessCondition + * An {@link AccessCondition} object that represents the access conditions for the share. + * @param options + * A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying + * null will use the default request options from the associated service client ( + * {@link CloudFileClient}). + * @param opContext + * An {@link OperationContext} object that represents the context for the current operation. This object + * is used to track requests to the storage service, and to provide additional runtime information about + * the operation. + * + * @throws StorageException + * If a storage service error occurred. + */ + @DoesServiceRequest + public void delete(DeleteShareSnapshotsOption deleteSnapshotsOption, AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext) + throws StorageException { if (opContext == null) { opContext = new OperationContext(); } @@ -349,12 +404,12 @@ public void delete(AccessCondition accessCondition, FileRequestOptions options, opContext.initialize(); options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); - ExecutionEngine.executeWithRetry(this.fileServiceClient, this, deleteImpl(accessCondition, options), + ExecutionEngine.executeWithRetry(this.fileServiceClient, this, deleteImpl(deleteSnapshotsOption, accessCondition, options), options.getRetryPolicyFactory(), opContext); } private StorageRequest deleteImpl( - final AccessCondition accessCondition, final FileRequestOptions options) { + final DeleteShareSnapshotsOption deleteSnapshotsOption, final AccessCondition accessCondition, final FileRequestOptions options) { final StorageRequest putRequest = new StorageRequest(options, this.getStorageUri()) { @@ -363,7 +418,7 @@ private StorageRequest deleteImpl( public HttpURLConnection buildRequest( CloudFileClient client, CloudFileShare share, OperationContext context) throws Exception { return FileRequest.deleteShare( - share.getTransformedAddress().getPrimaryUri(), options, context, accessCondition); + share.getTransformedAddress().getPrimaryUri(), options, context, accessCondition, share.snapshotID, deleteSnapshotsOption); } @Override @@ -396,12 +451,13 @@ public Void preProcessResponse(CloudFileShare share, CloudFileClient client, Ope */ @DoesServiceRequest public boolean deleteIfExists() throws StorageException { - return this.deleteIfExists(null /* accessCondition */, null /* options */, null /* opContext */); + return this.deleteIfExists(DeleteShareSnapshotsOption.NONE, null /* accessCondition */, null /* options */, null /* opContext */); } - + /** * Deletes the share if it exists using the specified request options and operation context. * + * * @param accessCondition * An {@link AccessCondition} object that represents the access conditions for the share. * @param options @@ -421,12 +477,45 @@ public boolean deleteIfExists() throws StorageException { @DoesServiceRequest public boolean deleteIfExists(AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext) throws StorageException { + return this.deleteIfExists(DeleteShareSnapshotsOption.NONE, accessCondition, options, opContext); + + } + + /** + * Deletes the share if it exists, using the specified snapshot and request options, and operation context. + *

+ * A share that has snapshots cannot be deleted unless the snapshots are also deleted. If a share has snapshots, use + * the {@link DeleteShareSnapshotsOption#INCLUDE_SNAPSHOTS} value + * in the deleteSnapshotsOption parameter to include the snapshots when deleting the base share. + * + * @param deleteSnapshotsOption + * A {@link DeleteShareSnapshotsOption} object that indicates whether to delete only snapshots, or the share + * and its snapshots. + * @param accessCondition + * An {@link AccessCondition} object that represents the access conditions for the share. + * @param options + * A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying + * null will use the default request options from the associated service client ( + * {@link CloudFileClient}). + * @param opContext + * An {@link OperationContext} object that represents the context for the current operation. This object + * is used to track requests to the storage service, and to provide additional runtime information about + * the operation. + * + * @return true if the share existed and was deleted; otherwise, false. + * + * @throws StorageException + * If a storage service error occurred. + */ + @DoesServiceRequest + public boolean deleteIfExists(DeleteShareSnapshotsOption deleteSnapshotsOption, AccessCondition accessCondition, FileRequestOptions options, + OperationContext opContext) throws StorageException { options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); boolean exists = this.exists(true /* primaryOnly */, accessCondition, options, opContext); if (exists) { try { - this.delete(accessCondition, options, opContext); + this.delete(deleteSnapshotsOption, accessCondition, options, opContext); return true; } catch (StorageException e) { @@ -501,7 +590,7 @@ public void setRequestLocationMode() { public HttpURLConnection buildRequest(CloudFileClient client, CloudFileShare share, OperationContext context) throws Exception { return FileRequest.getShareProperties(share.getTransformedAddress().getUri(this.getCurrentLocation()), - options, context, accessCondition); + options, context, accessCondition, share.snapshotID); } @Override @@ -569,6 +658,8 @@ public FileSharePermissions downloadPermissions(AccessCondition accessCondition, opContext = new OperationContext(); } + assertNoSnapshot(); + opContext.initialize(); options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); @@ -628,6 +719,136 @@ public FileSharePermissions postProcessResponse(HttpURLConnection connection, return getRequest; } + /** + * Creates a snapshot of the share. + * + * @return A CloudFileShare object that represents the snapshot of the share. + * + * @throws StorageException + * If a storage service error occurred. + */ + @DoesServiceRequest + public final CloudFileShare createSnapshot() throws StorageException { + return this + .createSnapshot(null /* metadata */, null /* accessCondition */, null /* options */, null /* opContext */); + } + + /** + * Creates a snapshot of the file share using the specified request options and operation context. + * + * @param accessCondition + * An {@link AccessCondition} object that represents the access conditions for the share. + * @param options + * A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying + * null will use the default request options from the associated service client ( + * {@link CloudFileClient}). + * @param opContext + * An {@link OperationContext} object that represents the context for the current operation. This object + * is used to track requests to the storage service, and to provide additional runtime information about + * the operation. + * + * @return A CloudFileShare object that represents the snapshot of the file share. + * + * @throws StorageException + * If a storage service error occurred. + */ + @DoesServiceRequest + public final CloudFileShare createSnapshot(final AccessCondition accessCondition, FileRequestOptions options, + OperationContext opContext) throws StorageException { + return this.createSnapshot(null /* metadata */, accessCondition, options, opContext); + } + + /** + * Creates a snapshot of the file share using the specified request options and operation context. + * + * @param metadata + * A collection of name-value pairs defining the metadata of the snapshot, or null. + * @param accessCondition + * An {@link AccessCondition} object that represents the access conditions for the file share. + * @param options + * A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying + * null will use the default request options from the associated service client ( + * {@link CloudFileClient}). + * @param opContext + * An {@link OperationContext} object that represents the context for the current operation. This object + * is used to track requests to the storage service, and to provide additional runtime information about + * the operation. + * + * @return A CloudFileShare object that represents the snapshot of the file share. + * + * @throws StorageException + * If a storage service error occurred. + */ + @DoesServiceRequest + public final CloudFileShare createSnapshot(final HashMap metadata, + final AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext) + throws StorageException { + assertNoSnapshot(); + + if (opContext == null) { + opContext = new OperationContext(); + } + + opContext.initialize(); + options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); + + return ExecutionEngine + .executeWithRetry(this.fileServiceClient, this, + this.createSnapshotImpl(metadata, accessCondition, options), options.getRetryPolicyFactory(), + opContext); + } + + private StorageRequest createSnapshotImpl( + final HashMap metadata, final AccessCondition accessCondition, + final FileRequestOptions options) { + final StorageRequest putRequest = + new StorageRequest( + options, this.getStorageUri()) { + + @Override + public HttpURLConnection buildRequest(CloudFileClient client, CloudFileShare share, OperationContext context) + throws Exception { + return FileRequest.snapshotShare(share.getTransformedAddress().getUri(this.getCurrentLocation()), + options, context, accessCondition); + } + + @Override + public void setHeaders(HttpURLConnection connection, CloudFileShare share, OperationContext context) { + if (metadata != null) { + FileRequest.addMetadata(connection, metadata, context); + } + } + + @Override + public void signRequest(HttpURLConnection connection, CloudFileClient client, OperationContext context) + throws Exception { + StorageRequest.signBlobQueueAndFileRequest(connection, client, 0L, context); + } + + @Override + public CloudFileShare preProcessResponse(CloudFileShare share, CloudFileClient client, OperationContext context) + throws Exception { + if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_CREATED) { + this.setNonExceptionedRetryableFailure(true); + return null; + } + + final String snapshotTime = FileResponse.getSnapshotTime(this.getConnection()); + CloudFileShare snapshot = new CloudFileShare(share.getName(), snapshotTime, client); + snapshot.setProperties(new FileShareProperties(share.properties)); + + // use the specified metadata if not null : otherwise share's metadata + snapshot.setMetadata(metadata != null ? metadata : share.metadata); + + share.updatePropertiesFromResponse(this.getConnection()); + + return snapshot; + } + }; + + return putRequest; + } + /** * Queries the service for this share's {@link ShareStats}. * @@ -664,6 +885,8 @@ public ShareStats getStats(FileRequestOptions options, OperationContext opContex opContext = new OperationContext(); } + assertNoSnapshot(); + opContext.initialize(); options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); @@ -783,7 +1006,7 @@ public void setRequestLocationMode() { public HttpURLConnection buildRequest(CloudFileClient client, CloudFileShare share, OperationContext context) throws Exception { return FileRequest.getShareProperties(share.getTransformedAddress().getUri(this.getCurrentLocation()), - options, context, accessCondition); + options, context, accessCondition, share.snapshotID); } @Override @@ -796,7 +1019,11 @@ public void signRequest(HttpURLConnection connection, CloudFileClient client, Op public Boolean preProcessResponse(CloudFileShare share, CloudFileClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() == HttpURLConnection.HTTP_OK) { - share.updatePropertiesFromResponse(this.getConnection()); + final FileShareAttributes attributes = FileResponse.getFileShareAttributes(this.getConnection(), + client.isUsePathStyleUris()); + share.metadata = attributes.getMetadata(); + share.properties = attributes.getProperties(); + return Boolean.valueOf(true); } else if (this.getResult().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) { @@ -804,6 +1031,7 @@ else if (this.getResult().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) { } else { this.setNonExceptionedRetryableFailure(true); + // return false instead of null to avoid SCA issues return false; } @@ -814,6 +1042,10 @@ else if (this.getResult().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) { } private void updatePropertiesFromResponse(HttpURLConnection request) { + if (this.getProperties() == null) { + this.properties = new FileShareProperties(); + } + // ETag this.getProperties().setEtag(request.getHeaderField(Constants.HeaderConstants.ETAG)); @@ -826,6 +1058,15 @@ private void updatePropertiesFromResponse(HttpURLConnection request) { } } + /** + * Asserts that the share is not a snapshot. + */ + protected void assertNoSnapshot() { + if (isSnapshot()) { + throw new IllegalArgumentException(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT); + } + } + /** * Returns a shared access signature for the share. Note this does not contain the leading "?". * @@ -933,6 +1174,8 @@ public void uploadMetadata() throws StorageException { @DoesServiceRequest public void uploadMetadata(AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext) throws StorageException { + assertNoSnapshot(); + if (opContext == null) { opContext = new OperationContext(); } @@ -1021,6 +1264,12 @@ public final void uploadProperties() throws StorageException { public final void uploadProperties( AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext) throws StorageException { + assertNoSnapshot(); + + if (this.properties != null && this.properties.getShareQuota() != null) { + Utility.assertInBounds("Share Quota", this.properties.getShareQuota(), 1, FileConstants.MAX_SHARE_QUOTA); + } + if (opContext == null) { opContext = new OperationContext(); } @@ -1102,6 +1351,8 @@ public void uploadPermissions(final FileSharePermissions permissions) throws Sto @DoesServiceRequest public void uploadPermissions(final FileSharePermissions permissions, final AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext) throws StorageException { + assertNoSnapshot(); + if (opContext == null) { opContext = new OperationContext(); } @@ -1201,7 +1452,14 @@ private void parseQueryAndVerify(final StorageUri completeUri, final StorageCred } this.storageUri = PathUtility.stripURIQueryAndFragment(completeUri); - + + final HashMap queryParameters = PathUtility.parseQueryString(completeUri.getQuery()); + + final String[] snapshotIDs = queryParameters.get(Constants.QueryConstants.SHARE_SNAPSHOT); + if (snapshotIDs != null && snapshotIDs.length > 0) { + this.snapshotID = snapshotIDs[0]; + } + final StorageCredentialsSharedAccessSignature parsedCredentials = SharedAccessSignatureHelper.parseQuery(completeUri); @@ -1238,6 +1496,17 @@ public URI getUri() { return this.storageUri.getPrimaryUri(); } + /** + * Indicates whether this share is a snapshot. + * + * @return true if the share is a snapshot, otherwise false. + * + * @see DeleteSnapshotsOption + */ + public final boolean isSnapshot() { + return this.snapshotID != null; + } + /** * Returns the list of URIs for all locations. * @@ -1247,6 +1516,24 @@ public StorageUri getStorageUri() { return this.storageUri; } + /** + * Returns the snapshot or shared access signature qualified URI for this share. + * + * @return A java.net.URI object that represents the snapshot or shared access signature. + * + * @throws StorageException + * If a storage service error occurred. + * @throws URISyntaxException + * If the resource URI is invalid. + */ + public final URI getQualifiedUri() throws URISyntaxException, StorageException { + if (this.isSnapshot()) { + return PathUtility.addToQuery(this.getUri(), String.format("sharesnapshot=%s", this.snapshotID)); + } + + return this.fileServiceClient.getCredentials().transformUri(this.getUri()); + } + /** * Returns the name of the share. * diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/DeleteShareSnapshotsOption.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/DeleteShareSnapshotsOption.java new file mode 100644 index 0000000000000..c44b4954431eb --- /dev/null +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/DeleteShareSnapshotsOption.java @@ -0,0 +1,35 @@ +/** + * Copyright Microsoft Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * + */ +package com.microsoft.azure.storage.file; + +/** + * Specifies options when calling the delete share operation. + */ +public enum DeleteShareSnapshotsOption { + + /** + * Specifies deleting the blob and its snapshots. + */ + INCLUDE_SNAPSHOTS, + + /** + * Specifies deleting the blob only. If the blob has snapshots, this option will result in an error from the + * service. + */ + NONE +} diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileOutputStream.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileOutputStream.java index f768db82901f5..6d28da2a5a54e 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileOutputStream.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileOutputStream.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.URISyntaxException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.concurrent.Callable; @@ -205,6 +206,8 @@ public void close() throws IOException { } catch (final StorageException e) { throw Utility.initIOException(e); + } catch (URISyntaxException e) { + throw Utility.initIOException(e); } } finally { @@ -227,9 +230,10 @@ public void close() throws IOException { * * @throws StorageException * An exception representing any error which occurred during the operation. + * @throws URISyntaxException */ @DoesServiceRequest - private void commit() throws StorageException { + private void commit() throws StorageException, URISyntaxException { if (this.options.getStoreFileContentMD5()) { this.parentFileRef.getProperties().setContentMD5(Base64.encode(this.md5Digest.digest())); } @@ -271,7 +275,7 @@ private synchronized void dispatchWrite(final int writeLength) throws IOExceptio worker = new Callable() { @Override - public Void call() { + public Void call() throws URISyntaxException { try { fileRef.uploadRange(bufferRef, opOffset, opWriteLength, FileOutputStream.this.accessCondition, FileOutputStream.this.options, FileOutputStream.this.opContext); diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileRequest.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileRequest.java index dc00aa6ccf87d..49c5f33c439c7 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileRequest.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileRequest.java @@ -18,6 +18,7 @@ import java.net.HttpURLConnection; import java.net.URI; import java.net.URISyntaxException; +import java.util.EnumSet; import java.util.Map; import com.microsoft.azure.storage.AccessCondition; @@ -38,6 +39,8 @@ final class FileRequest { private static final String RANGE_LIST_QUERY_ELEMENT_NAME = "rangelist"; + private static final String SNAPSHOTS_QUERY_ELEMENT_NAME = "snapshots"; + /** * Generates a web request to abort a copy operation. * @@ -118,6 +121,23 @@ private static void addProperties(final HttpURLConnection request, FilePropertie BaseRequest.addOptionalHeader(request, FileConstants.CONTENT_TYPE_HEADER, properties.getContentType()); } + /** + * Adds the share snapshot if present. + * Only for listing files and directories which requires a different query param. + * + * @param builder + * a query builder. + * @param snapshotVersion + * the share snapshot version to the query builder. + * @throws StorageException + */ + public static void addShareSnapshot(final UriQueryBuilder builder, final String snapshotVersion) + throws StorageException { + if (snapshotVersion != null) { + builder.add(Constants.QueryConstants.SHARE_SNAPSHOT, snapshotVersion); + } + } + /** * Creates a request to copy a file, Sign with 0 length. * @@ -268,14 +288,27 @@ public static HttpURLConnection deleteFile(final URI uri, final FileRequestOptio * @throws IllegalArgumentException */ public static HttpURLConnection deleteShare(final URI uri, final FileRequestOptions fileOptions, - final OperationContext opContext, final AccessCondition accessCondition) throws IOException, - URISyntaxException, StorageException { + final OperationContext opContext, final AccessCondition accessCondition, String snapshotVersion, DeleteShareSnapshotsOption deleteSnapshotsOption) + throws IOException, URISyntaxException, StorageException { final UriQueryBuilder shareBuilder = getShareUriQueryBuilder(); + FileRequest.addShareSnapshot(shareBuilder, snapshotVersion); HttpURLConnection request = BaseRequest.delete(uri, fileOptions, shareBuilder, opContext); if (accessCondition != null) { accessCondition.applyConditionToRequest(request); } + switch (deleteSnapshotsOption) { + case NONE: + // nop + break; + case INCLUDE_SNAPSHOTS: + request.setRequestProperty(Constants.HeaderConstants.DELETE_SNAPSHOT_HEADER, + Constants.HeaderConstants.INCLUDE_SNAPSHOTS_VALUE); + break; + default: + break; + } + return request; } @@ -329,6 +362,8 @@ public static HttpURLConnection getAcl(final URI uri, final FileRequestOptions f * the operation. * @param accessCondition * An {@link AccessCondition} object that represents the access conditions for the file. + * @param snapshotVersion + * The snapshot version, if the share is a snapshot. * @param offset * The offset at which to begin returning content. * @param count @@ -345,7 +380,7 @@ public static HttpURLConnection getAcl(final URI uri, final FileRequestOptions f * @throws IllegalArgumentException */ public static HttpURLConnection getFile(final URI uri, final FileRequestOptions fileOptions, - final OperationContext opContext, final AccessCondition accessCondition, final Long offset, + final OperationContext opContext, final AccessCondition accessCondition, final String snapshotVersion, final Long offset, final Long count, boolean requestRangeContentMD5) throws IOException, URISyntaxException, StorageException { if (offset != null && requestRangeContentMD5) { @@ -354,6 +389,7 @@ public static HttpURLConnection getFile(final URI uri, final FileRequestOptions } final UriQueryBuilder builder = new UriQueryBuilder(); + FileRequest.addShareSnapshot(builder, snapshotVersion); final HttpURLConnection request = BaseRequest.createURLConnection(uri, fileOptions, builder, opContext); request.setRequestMethod(Constants.HTTP_GET); @@ -398,6 +434,8 @@ public static HttpURLConnection getFile(final URI uri, final FileRequestOptions * @param accessCondition * An {@link AccessCondition} object that represents the access conditions for the file. * @return a HttpURLConnection to use to perform the operation. + * @param snapshotVersion + * the snapshot version to the query builder. * @throws IOException * if there is an error opening the connection * @throws URISyntaxException @@ -407,10 +445,11 @@ public static HttpURLConnection getFile(final URI uri, final FileRequestOptions * @throws IllegalArgumentException */ public static HttpURLConnection getFileProperties(final URI uri, final FileRequestOptions fileOptions, - final OperationContext opContext, final AccessCondition accessCondition) throws StorageException, + final OperationContext opContext, final AccessCondition accessCondition, final String snapshotVersion) throws StorageException, IOException, URISyntaxException { final UriQueryBuilder builder = new UriQueryBuilder(); - return getProperties(uri, fileOptions, opContext, accessCondition, builder); + + return getProperties(uri, fileOptions, opContext, accessCondition, builder, snapshotVersion); } /** @@ -428,6 +467,8 @@ public static HttpURLConnection getFileProperties(final URI uri, final FileReque * the operation. * @param accessCondition * An {@link AccessCondition} object that represents the access conditions for the file. + * @param snapshotVersion + * the snapshot version to the query builder. * @return a HttpURLConnection to use to perform the operation. * @throws IOException * if there is an error opening the connection @@ -438,10 +479,11 @@ public static HttpURLConnection getFileProperties(final URI uri, final FileReque * @throws IllegalArgumentException */ public static HttpURLConnection getFileRanges(final URI uri, final FileRequestOptions fileOptions, - final OperationContext opContext, final AccessCondition accessCondition) throws StorageException, + final OperationContext opContext, final AccessCondition accessCondition, final String snapshotVersion) throws StorageException, IOException, URISyntaxException { final UriQueryBuilder builder = new UriQueryBuilder(); + addShareSnapshot(builder, snapshotVersion); builder.add(Constants.QueryConstants.COMPONENT, RANGE_LIST_QUERY_ELEMENT_NAME); final HttpURLConnection request = BaseRequest.createURLConnection(uri, fileOptions, builder, opContext); @@ -469,14 +511,17 @@ public static HttpURLConnection getFileRanges(final URI uri, final FileRequestOp * the operation. * @param accessCondition * An {@link AccessCondition} object that represents the access conditions for the share. + * @param snapshotVersion + * the snapshot version to the query builder. * @return a HttpURLConnection configured for the operation. * @throws StorageException * */ public static HttpURLConnection getShareProperties(final URI uri, final FileRequestOptions fileOptions, - final OperationContext opContext, AccessCondition accessCondition) throws IOException, URISyntaxException, + final OperationContext opContext, AccessCondition accessCondition, final String snapshotVersion) throws IOException, URISyntaxException, StorageException { final UriQueryBuilder shareBuilder = getShareUriQueryBuilder(); - return getProperties(uri, fileOptions, opContext, accessCondition, shareBuilder); + + return getProperties(uri, fileOptions, opContext, accessCondition, shareBuilder, snapshotVersion); } /** @@ -559,12 +604,16 @@ private static UriQueryBuilder getDirectoryUriQueryBuilder() throws StorageExcep * the operation. * @param accessCondition * An {@link AccessCondition} object that represents the access conditions for the share. + * @param snapshotVersion + * the snapshot version to the query builder. * @return a HttpURLConnection configured for the operation. * @throws StorageException * */ private static HttpURLConnection getProperties(final URI uri, final FileRequestOptions fileOptions, - final OperationContext opContext, AccessCondition accessCondition, final UriQueryBuilder builder) + final OperationContext opContext, AccessCondition accessCondition, final UriQueryBuilder builder, + String snapshotVersion) throws IOException, URISyntaxException, StorageException { + addShareSnapshot(builder, snapshotVersion); HttpURLConnection request = BaseRequest.getProperties(uri, fileOptions, builder, opContext); if (accessCondition != null) { @@ -591,7 +640,8 @@ private static HttpURLConnection getProperties(final URI uri, final FileRequestO * @param listingContext * A set of parameters for the listing operation. * @param detailsIncluded - * Additional details to return with the listing. + * A java.util.EnumSet object that contains {@link ShareListingDetails} values that indicate + * whether share snapshots and/or metadata will be returned. * @return a HttpURLConnection configured for the operation. * @throws IOException * @throws URISyntaxException @@ -600,12 +650,28 @@ private static HttpURLConnection getProperties(final URI uri, final FileRequestO */ public static HttpURLConnection listShares(final URI uri, final FileRequestOptions fileOptions, final OperationContext opContext, final ListingContext listingContext, - final ShareListingDetails detailsIncluded) throws URISyntaxException, IOException, StorageException { - + final EnumSet detailsIncluded) throws URISyntaxException, IOException, StorageException { final UriQueryBuilder builder = BaseRequest.getListUriQueryBuilder(listingContext); - if (detailsIncluded == ShareListingDetails.ALL || detailsIncluded == ShareListingDetails.METADATA) { - builder.add(Constants.QueryConstants.INCLUDE, Constants.QueryConstants.METADATA); + if (detailsIncluded != null && detailsIncluded.size() > 0) { + final StringBuilder sb = new StringBuilder(); + boolean started = false; + + if (detailsIncluded.contains(ShareListingDetails.SNAPSHOTS)) { + started = true; + sb.append(SNAPSHOTS_QUERY_ELEMENT_NAME); + } + + if (detailsIncluded.contains(ShareListingDetails.METADATA)) { + if (started) + { + sb.append(","); + } + + sb.append(Constants.QueryConstants.METADATA); + } + + builder.add(Constants.QueryConstants.INCLUDE, sb.toString()); } final HttpURLConnection request = BaseRequest.createURLConnection(uri, fileOptions, builder, opContext); @@ -741,14 +807,16 @@ public static HttpURLConnection deleteDirectory(final URI uri, final FileRequest * the operation. * @param accessCondition * An {@link AccessCondition} object that represents the access conditions for the directory. + * @param snapshotVersion + * the snapshot version to the query builder. * @return a HttpURLConnection configured for the operation. * @throws StorageException * */ public static HttpURLConnection getDirectoryProperties(final URI uri, final FileRequestOptions fileOptions, - final OperationContext opContext, AccessCondition accessCondition) throws IOException, URISyntaxException, + final OperationContext opContext, AccessCondition accessCondition, String snapshotVersion) throws IOException, URISyntaxException, StorageException { final UriQueryBuilder directoryBuilder = getDirectoryUriQueryBuilder(); - return getProperties(uri, fileOptions, opContext, accessCondition, directoryBuilder); + return getProperties(uri, fileOptions, opContext, accessCondition, directoryBuilder, snapshotVersion); } /** @@ -767,6 +835,8 @@ public static HttpURLConnection getDirectoryProperties(final URI uri, final File * the operation. * @param listingContext * A set of parameters for the listing operation. + * @param snapshotVersion + * the snapshot version to the query builder. * @return a HttpURLConnection configured for the operation. * @throws IOException * @throws URISyntaxException @@ -774,10 +844,11 @@ public static HttpURLConnection getDirectoryProperties(final URI uri, final File * @throws IllegalArgumentException */ public static HttpURLConnection listFilesAndDirectories(final URI uri, final FileRequestOptions fileOptions, - final OperationContext opContext, final ListingContext listingContext) throws URISyntaxException, + final OperationContext opContext, final ListingContext listingContext, String snapshotVersion) throws URISyntaxException, IOException, StorageException { final UriQueryBuilder builder = getDirectoryUriQueryBuilder(); + addShareSnapshot(builder, snapshotVersion); builder.add(Constants.QueryConstants.COMPONENT, Constants.QueryConstants.LIST); if (listingContext != null) { @@ -1099,6 +1170,49 @@ public static HttpURLConnection setFileMetadata(final URI uri, final FileRequest return setMetadata(uri, fileOptions, opContext, accessCondition, null); } + /** + * Constructs a HttpURLConnection to create a snapshot of the share. + * + * @param uri + * A java.net.URI object that specifies the absolute URI. + * @param fileOptions + * A {@link FileRequestOptions} object that specifies execution options such as retry policy and timeout + * settings for the operation. Specify null to use the request options specified on the + * {@link CloudFileClient}. + * @param opContext + * An {@link OperationContext} object that represents the context for the current operation. This object + * is used to track requests to the storage service, and to provide additional runtime information about + * the operation. + * @param accessCondition + * An {@link AccessCondition} object that represents the access conditions for the share. + * @return a HttpURLConnection to use to perform the operation. + * @throws IOException + * if there is an error opening the connection + * @throws URISyntaxException + * if the resource URI is invalid + * @throws StorageException + * an exception representing any error which occurred during the operation. + * @throws IllegalArgumentException + */ + public static HttpURLConnection snapshotShare(final URI uri, final FileRequestOptions fileOptions, + final OperationContext opContext, final AccessCondition accessCondition) throws IOException, + URISyntaxException, StorageException { + final UriQueryBuilder builder = new UriQueryBuilder(); + builder.add(Constants.QueryConstants.RESOURCETYPE, "share"); + builder.add(Constants.QueryConstants.COMPONENT, Constants.QueryConstants.SNAPSHOT); + final HttpURLConnection request = BaseRequest.createURLConnection(uri, fileOptions, builder, opContext); + + request.setFixedLengthStreamingMode(0); + request.setDoOutput(true); + request.setRequestMethod(Constants.HTTP_PUT); + + if (accessCondition != null) { + accessCondition.applyConditionToRequest(request); + } + + return request; + } + /** * Constructs a HttpURLConnection to set the file's properties, Sign with zero length specified. * diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileResponse.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileResponse.java index 40a1c5166444b..14d7bcfcd98c6 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileResponse.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileResponse.java @@ -205,6 +205,17 @@ static Integer parseShareQuota(final HttpURLConnection request) { return (shareQuota == -1) ? null : shareQuota; } + /** + * Gets the snapshot ID from the request header. + * + * @param request + * The response from server. + * @return the snapshot ID from the request header. + */ + public static String getSnapshotTime(final HttpURLConnection request) { + return request.getHeaderField(Constants.HeaderConstants.SNAPSHOT_ID_HEADER); + } + /** * Private Default Ctor */ diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileShareProperties.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileShareProperties.java index c5e29c6e35744..e834085121ad5 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileShareProperties.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileShareProperties.java @@ -17,7 +17,6 @@ import java.util.Date; import com.microsoft.azure.storage.AccessCondition; -import com.microsoft.azure.storage.core.Utility; /** * Represents the system properties for a share. @@ -39,6 +38,27 @@ public final class FileShareProperties { */ private Integer shareQuota; + /** + * Creates an instance of the FileShareProperties class. + */ + public FileShareProperties() { + } + + /** + * Creates an instance of the FileShareProperties class by copying values from another + * FileShareProperties instance. + * + * @param other + * A {@link FileShareProperties} object which represents the file share properties to copy. + */ + public FileShareProperties(final FileShareProperties other) { + if (other != null) { + this.setEtag(other.getEtag()); + this.setLastModified(other.getLastModified()); + this.setShareQuota(other.getShareQuota()); + } + } + /** * Gets the ETag value of the share. *

@@ -102,9 +122,6 @@ protected void setLastModified(final Date lastModified) { * the size of files stored on the share. */ public void setShareQuota(Integer shareQuota) { - if (shareQuota != null) { - Utility.assertInBounds("Share Quota", shareQuota, 1, FileConstants.MAX_SHARE_QUOTA); - } this.shareQuota = shareQuota; } } \ No newline at end of file diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/ShareListHandler.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/ShareListHandler.java index c73693da14e5e..3d3b9b99fd657 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/ShareListHandler.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/ShareListHandler.java @@ -46,6 +46,7 @@ final class ShareListHandler extends DefaultHandler { private final ListResponse response = new ListResponse(); private FileShareAttributes attributes; private String shareName; + private String snapshotID; private ShareListHandler(CloudFileClient serviceClient) { this.serviceClient = serviceClient; @@ -77,6 +78,7 @@ public void startElement(String uri, String localName, String qName, Attributes if (FileConstants.SHARE_ELEMENT.equals(localName)) { this.shareName = Constants.EMPTY_STRING; + this.snapshotID = null; this.attributes = new FileShareAttributes(); } } @@ -105,6 +107,7 @@ public void endElement(String uri, String localName, String qName) throws SAXExc CloudFileShare retShare = this.serviceClient.getShareReference(this.shareName); retShare.setMetadata(this.attributes.getMetadata()); retShare.setProperties(this.attributes.getProperties()); + retShare.snapshotID = this.snapshotID; this.response.getResults().add(retShare); } @@ -134,6 +137,9 @@ else if (FileConstants.SHARE_ELEMENT.equals(parentNode)) { if (Constants.NAME_ELEMENT.equals(currentNode)) { this.shareName = value; } + else if (Constants.QueryConstants.SNAPSHOT.equals(currentNode.toLowerCase())) { + this.snapshotID = value; + } } else if (Constants.PROPERTIES.equals(parentNode)) { try { diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/ShareListingDetails.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/ShareListingDetails.java index b9b54ddb0c92e..244b11fad54c8 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/ShareListingDetails.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/ShareListingDetails.java @@ -18,10 +18,6 @@ * Specifies which details to include when listing the shares in this storage account. */ public enum ShareListingDetails { - /** - * Specifies including all available details. - */ - ALL(1), /** * Specifies including share metadata. @@ -29,9 +25,9 @@ public enum ShareListingDetails { METADATA(1), /** - * Specifies including no additional details. + * Specifies listing share snapshots. */ - NONE(0); + SNAPSHOTS(2); /** * Returns the value of this enum. From 348a92ebcb84035d41accc29fd40fc0316b765e9 Mon Sep 17 00:00:00 2001 From: Josh Friedman Date: Tue, 11 Apr 2017 15:11:32 -0700 Subject: [PATCH 02/12] exposing get snapshot to CloudFileShare --- .../com/microsoft/azure/storage/file/CloudFileShare.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileShare.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileShare.java index 4345788def410..95686dc49f4d6 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileShare.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileShare.java @@ -1496,6 +1496,15 @@ public URI getUri() { return this.storageUri.getPrimaryUri(); } + /** + * Returns the snapshotID for this share. + * + * @return The snapshotID as a string for this share. + */ + public final String getSnapshot() { + return this.snapshotID; + } + /** * Indicates whether this share is a snapshot. * From 78c93c086e822fac843d21ec0a6a9f42a40d7c02 Mon Sep 17 00:00:00 2001 From: Josh Friedman Date: Wed, 12 Apr 2017 13:12:00 -0700 Subject: [PATCH 03/12] Share snapshot fix when getting server response --- .../src/com/microsoft/azure/storage/file/CloudFileShare.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileShare.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileShare.java index 95686dc49f4d6..db8a5b8085ac7 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileShare.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileShare.java @@ -840,7 +840,7 @@ public CloudFileShare preProcessResponse(CloudFileShare share, CloudFileClient c // use the specified metadata if not null : otherwise share's metadata snapshot.setMetadata(metadata != null ? metadata : share.metadata); - share.updatePropertiesFromResponse(this.getConnection()); + snapshot.updatePropertiesFromResponse(this.getConnection()); return snapshot; } From 4b4a6a5c700c2b3d4037381adb09d81c386194d0 Mon Sep 17 00:00:00 2001 From: Josh Friedman Date: Thu, 20 Apr 2017 14:55:50 -0700 Subject: [PATCH 04/12] Hiding share snapshots --- BreakingChanges.txt | 1 - ChangeLog.txt | 1 - .../storage/file/CloudFileClientTests.java | 2 +- .../storage/file/CloudFileDirectoryTests.java | 4 +- .../storage/file/CloudFileShareTests.java | 32 ++++++++-------- .../azure/storage/file/CloudFileTests.java | 4 +- .../azure/storage/file/CloudFile.java | 2 +- .../azure/storage/file/CloudFileClient.java | 2 +- .../storage/file/CloudFileDirectory.java | 1 - .../azure/storage/file/CloudFileShare.java | 38 +++++++++---------- .../azure/storage/file/FileRequest.java | 8 ++-- .../storage/file/ShareListingDetails.java | 4 +- 12 files changed, 48 insertions(+), 51 deletions(-) diff --git a/BreakingChanges.txt b/BreakingChanges.txt index 7c93f08574014..7733d297673b8 100644 --- a/BreakingChanges.txt +++ b/BreakingChanges.txt @@ -2,7 +2,6 @@ Changes in 6.0.0 FILE * Exists() calls on Shares and Directories now populates metadata. This was already being done for Files. - * CloudFileShare constructor now takes a snapshotID String which can be null. * FileRequest get methods now takes a snapshotID String which can be null. * Changed listShares() ShareListingDetails parameter to be an enum set like what is done for listing blobs. * In CloudFileShareProperties, setShareQuota() no longer asserts in bounds. This check has been moved to create() and uploadProperties() in CloudFileShare. diff --git a/ChangeLog.txt b/ChangeLog.txt index ed782927c4f6c..a03a0d76684d7 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,5 +1,4 @@ 2017.XX.XX Version 6.0.0 - * Added support for taking a snapshot of a share. * Fixed Exists() calls on Shares and Directories to now populate metadata. This was already being done for Files. 2017.01.18 Version 5.0.0 diff --git a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileClientTests.java b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileClientTests.java index 822009833421c..dedd08ac03270 100644 --- a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileClientTests.java +++ b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileClientTests.java @@ -115,7 +115,7 @@ public void testListSharesMaxResultsValidationTest() throws StorageException, UR assertNotNull(fileClient.listSharesSegmented("thereshouldntbeanyshareswiththisprefix")); } - @Test + //@Test public void testListSharesWithSnapshot() throws StorageException, URISyntaxException { CloudFileClient fileClient = FileTestHelper.createCloudFileClient(); CloudFileShare share = fileClient.getShareReference(UUID.randomUUID().toString()); diff --git a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileDirectoryTests.java b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileDirectoryTests.java index 588e5f978852b..f9e87412c7fd9 100644 --- a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileDirectoryTests.java +++ b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileDirectoryTests.java @@ -480,7 +480,7 @@ private static void testMetadataFailures(CloudFileDirectory directory, String ke directory.getMetadata().remove(key); } - @Test + //@Test public void testUnsupportedDirectoryApisWithinShareSnapshot() throws StorageException, URISyntaxException { CloudFileShare snapshot = this.share.createSnapshot(); CloudFileDirectory rootDir = snapshot.getRootDirectoryReference(); @@ -509,7 +509,7 @@ public void testUnsupportedDirectoryApisWithinShareSnapshot() throws StorageExce snapshot.delete(); } - @Test + //@Test public void testSupportedDirectoryApisInShareSnapshot() throws StorageException, URISyntaxException { CloudFileDirectory dir = this.share.getRootDirectoryReference().getDirectoryReference("dir1"); dir.deleteIfExists(); diff --git a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileShareTests.java b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileShareTests.java index 81ea738d1ce53..af3fb13d0477a 100644 --- a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileShareTests.java +++ b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileShareTests.java @@ -62,7 +62,7 @@ public void fileShareTestMethodSetUp() throws StorageException, URISyntaxExcepti @After public void fileShareTestMethodTearDown() throws StorageException { - //this.share.deleteIfExists(); + this.share.deleteIfExists(); } /** @@ -494,7 +494,7 @@ public void eventOccurred(SendingRequestEvent eventArg) { assertTrue(this.share.deleteIfExists(null, null, ctx)); } - @Test + //@Test public void testCreateShareSnapshot() throws StorageException, URISyntaxException, IOException { // create share with metadata this.share.create(); @@ -551,15 +551,15 @@ public void testCreateShareSnapshot() throws StorageException, URISyntaxExceptio final UriQueryBuilder uriBuilder = new UriQueryBuilder(); uriBuilder.add("sharesnapshot", snapshot.snapshotID); - CloudFileShare snapshotRef5 = new CloudFileShare(uriBuilder.addToURI(this.share.getUri()), - this.share.getServiceClient().getCredentials(), null); - assertEquals(snapshot.snapshotID, snapshotRef5.snapshotID); - assertTrue(snapshotRef5.exists()); +// CloudFileShare snapshotRef5 = new CloudFileShare(uriBuilder.addToURI(this.share.getUri()), +// this.share.getServiceClient().getCredentials(), null); +// assertEquals(snapshot.snapshotID, snapshotRef5.snapshotID); +// assertTrue(snapshotRef5.exists()); snapshot.delete(); } - @Test + //@Test public void testDeleteShareSnapshotOptions() throws StorageException, URISyntaxException, IOException { // create share with metadata this.share.create(); @@ -583,7 +583,7 @@ public void testDeleteShareSnapshotOptions() throws StorageException, URISyntaxE assertFalse(snapshot.exists()); } - @Test + //@Test public void testListFilesAndDirectoriesWithinShareSnapshot() throws StorageException, URISyntaxException { this.share.create(); @@ -624,7 +624,7 @@ public void testListFilesAndDirectoriesWithinShareSnapshot() throws StorageExcep snapshot.delete(); } - @Test + //@Test public void testUnsupportedApisShareSnapshot() throws StorageException, URISyntaxException { CloudFileClient client = FileTestHelper.createCloudFileClient(); this.share.create(); @@ -637,13 +637,13 @@ public void testUnsupportedApisShareSnapshot() throws StorageException, URISynta catch (IllegalArgumentException e) { assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage()); } - try { - new CloudFileShare(snapshot.getQualifiedUri(), client.getCredentials(), "2016-10-24T16:37:17.0000000Z"); - fail("Shouldn't get here"); - } - catch (IllegalArgumentException e) { - assertEquals(SR.SNAPSHOT_QUERY_OPTION_ALREADY_DEFINED, e.getMessage()); - } +// try { +// new CloudFileShare(snapshot.getQualifiedUri(), client.getCredentials(), "2016-10-24T16:37:17.0000000Z"); +// fail("Shouldn't get here"); +// } +// catch (IllegalArgumentException e) { +// assertEquals(SR.SNAPSHOT_QUERY_OPTION_ALREADY_DEFINED, e.getMessage()); +// } try { snapshot.downloadPermissions(); fail("Shouldn't get here"); diff --git a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileTests.java b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileTests.java index 9aef81b54273b..df82c0d70e857 100644 --- a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileTests.java +++ b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileTests.java @@ -1558,7 +1558,7 @@ private void doCloudFileCopy(boolean sourceIsSas, boolean destinationIsSas) source.delete(); } - @Test + //@Test public void testUnsupportedFileApisWithinShareSnapshot() throws StorageException, URISyntaxException { CloudFileShare snapshot = this.share.createSnapshot(); CloudFile file = snapshot.getRootDirectoryReference().getFileReference("file"); @@ -1618,7 +1618,7 @@ public void testUnsupportedFileApisWithinShareSnapshot() throws StorageException snapshot.delete(); } - @Test + //@Test public void testSupportedFileApisInShareSnapshot() throws StorageException, URISyntaxException, UnsupportedEncodingException { CloudFileDirectory dir = this.share.getRootDirectoryReference().getDirectoryReference("dir1"); dir.deleteIfExists(); diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFile.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFile.java index 358e4a5d04350..f4c739e8b303b 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFile.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFile.java @@ -2800,7 +2800,7 @@ public final CloudFileShare getShare() throws StorageException, URISyntaxExcepti final StorageUri shareUri = PathUtility.getShareURI(this.getStorageUri(), this.fileServiceClient.isUsePathStyleUris()); - this.share = new CloudFileShare(shareUri, this.fileServiceClient.getCredentials(), null); + this.share = new CloudFileShare(shareUri, this.fileServiceClient.getCredentials()/*, null*/); } return this.share; diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileClient.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileClient.java index 030fa41529868..d6d3eb1a63330 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileClient.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileClient.java @@ -121,7 +121,7 @@ public CloudFileShare getShareReference(final String shareName) throws URISyntax * @see Naming and Referencing Shares, * Directories, Files, and Metadata */ - public CloudFileShare getShareReference(final String shareName, String snapshotID) throws URISyntaxException, StorageException { + protected CloudFileShare getShareReference(final String shareName, String snapshotID) throws URISyntaxException, StorageException { Utility.assertNotNullOrEmpty("shareName", shareName); return new CloudFileShare(shareName, snapshotID, this); } diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileDirectory.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileDirectory.java index 92735f7b6c9ab..bc171cf4e422a 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileDirectory.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileDirectory.java @@ -1087,7 +1087,6 @@ public CloudFileDirectory getParent() throws URISyntaxException, StorageExceptio StorageUri parentURI = PathUtility.appendPathToUri(this.getShare().getStorageUri(), parentName); this.parent = new CloudFileDirectory(parentURI, this.getServiceClient().getCredentials()); - //this.parent = new CloudFileDirectory(parentURI, parentName, this.getShare()); } } return this.parent; diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileShare.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileShare.java index db8a5b8085ac7..fa13045161e7b 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileShare.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileShare.java @@ -145,7 +145,7 @@ public CloudFileShare(final URI uri) throws StorageException { * If a storage service error occurred. */ public CloudFileShare(final StorageUri storageUri) throws StorageException { - this(storageUri, (StorageCredentials) null, null); + this(storageUri, (StorageCredentials) null); } /** @@ -161,8 +161,8 @@ public CloudFileShare(final StorageUri storageUri) throws StorageException { * @throws StorageException * If a storage service error occurred. */ - public CloudFileShare(final URI uri, final StorageCredentials credentials, String snapshotID) throws StorageException { - this(new StorageUri(uri), credentials, snapshotID); + public CloudFileShare(final URI uri, final StorageCredentials credentials/*, String snapshotID*/) throws StorageException { + this(new StorageUri(uri), credentials /*, snapshotID*/); } /** @@ -177,17 +177,17 @@ public CloudFileShare(final URI uri, final StorageCredentials credentials, Strin * @throws StorageException * If a storage service error occurred. */ - public CloudFileShare(final StorageUri storageUri, final StorageCredentials credentials, String snapshotID) throws StorageException { + public CloudFileShare(final StorageUri storageUri, final StorageCredentials credentials/*, String snapshotID*/) throws StorageException { this.parseQueryAndVerify(storageUri, credentials); - if (snapshotID != null) { - if (this.snapshotID != null) { - throw new IllegalArgumentException(SR.SNAPSHOT_QUERY_OPTION_ALREADY_DEFINED); - } - else { - this.snapshotID = snapshotID; - } - } +// if (snapshotID != null) { +// if (this.snapshotID != null) { +// throw new IllegalArgumentException(SR.SNAPSHOT_QUERY_OPTION_ALREADY_DEFINED); +// } +// else { +// this.snapshotID = snapshotID; +// } +// } } /** @@ -395,7 +395,7 @@ public void delete(AccessCondition accessCondition, FileRequestOptions options, * If a storage service error occurred. */ @DoesServiceRequest - public void delete(DeleteShareSnapshotsOption deleteSnapshotsOption, AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext) + protected void delete(DeleteShareSnapshotsOption deleteSnapshotsOption, AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext) throws StorageException { if (opContext == null) { opContext = new OperationContext(); @@ -508,7 +508,7 @@ public boolean deleteIfExists(AccessCondition accessCondition, FileRequestOption * If a storage service error occurred. */ @DoesServiceRequest - public boolean deleteIfExists(DeleteShareSnapshotsOption deleteSnapshotsOption, AccessCondition accessCondition, FileRequestOptions options, + protected boolean deleteIfExists(DeleteShareSnapshotsOption deleteSnapshotsOption, AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext) throws StorageException { options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); @@ -728,7 +728,7 @@ public FileSharePermissions postProcessResponse(HttpURLConnection connection, * If a storage service error occurred. */ @DoesServiceRequest - public final CloudFileShare createSnapshot() throws StorageException { + protected final CloudFileShare createSnapshot() throws StorageException { return this .createSnapshot(null /* metadata */, null /* accessCondition */, null /* options */, null /* opContext */); } @@ -753,7 +753,7 @@ public final CloudFileShare createSnapshot() throws StorageException { * If a storage service error occurred. */ @DoesServiceRequest - public final CloudFileShare createSnapshot(final AccessCondition accessCondition, FileRequestOptions options, + protected final CloudFileShare createSnapshot(final AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext) throws StorageException { return this.createSnapshot(null /* metadata */, accessCondition, options, opContext); } @@ -780,7 +780,7 @@ public final CloudFileShare createSnapshot(final AccessCondition accessCondition * If a storage service error occurred. */ @DoesServiceRequest - public final CloudFileShare createSnapshot(final HashMap metadata, + protected final CloudFileShare createSnapshot(final HashMap metadata, final AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext) throws StorageException { assertNoSnapshot(); @@ -1501,7 +1501,7 @@ public URI getUri() { * * @return The snapshotID as a string for this share. */ - public final String getSnapshot() { + protected final String getSnapshot() { return this.snapshotID; } @@ -1512,7 +1512,7 @@ public final String getSnapshot() { * * @see DeleteSnapshotsOption */ - public final boolean isSnapshot() { + protected final boolean isSnapshot() { return this.snapshotID != null; } diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileRequest.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileRequest.java index 49c5f33c439c7..746c5b5ce3ead 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileRequest.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileRequest.java @@ -657,10 +657,10 @@ public static HttpURLConnection listShares(final URI uri, final FileRequestOptio final StringBuilder sb = new StringBuilder(); boolean started = false; - if (detailsIncluded.contains(ShareListingDetails.SNAPSHOTS)) { - started = true; - sb.append(SNAPSHOTS_QUERY_ELEMENT_NAME); - } +// if (detailsIncluded.contains(ShareListingDetails.SNAPSHOTS)) { +// started = true; +// sb.append(SNAPSHOTS_QUERY_ELEMENT_NAME); +// } if (detailsIncluded.contains(ShareListingDetails.METADATA)) { if (started) diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/ShareListingDetails.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/ShareListingDetails.java index 244b11fad54c8..3e746585cf2da 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/ShareListingDetails.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/ShareListingDetails.java @@ -22,12 +22,12 @@ public enum ShareListingDetails { /** * Specifies including share metadata. */ - METADATA(1), + METADATA(1); /** * Specifies listing share snapshots. */ - SNAPSHOTS(2); + //SNAPSHOTS(2); /** * Returns the value of this enum. From d3f34db2ee441deb233184449c96f7f2c12958ed Mon Sep 17 00:00:00 2001 From: Josh Friedman Date: Tue, 25 Apr 2017 12:36:26 -0700 Subject: [PATCH 05/12] Cleaning up merge from public dev --- .../src/com/microsoft/azure/storage/blob/BlobConstants.java | 5 ----- .../src/com/microsoft/azure/storage/file/CloudFile.java | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobConstants.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobConstants.java index f5f324668b25b..6df87f96dde50 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobConstants.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobConstants.java @@ -151,11 +151,6 @@ final class BlobConstants { */ public static final int DEFAULT_POLLING_INTERVAL_IN_SECONDS = 30; - /** - * The default maximum size, in bytes, of a blob before it must be separated into blocks. - */ - public static final int DEFAULT_SINGLE_BLOB_PUT_THRESHOLD_IN_BYTES = 32 * Constants.MB; - /** * XML element for the latest. */ diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFile.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFile.java index 231c7ffb9f9f0..aefd1349b8a34 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFile.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFile.java @@ -1881,7 +1881,7 @@ public FileOutputStream openWriteExisting() throws StorageException, URISyntaxEx */ @DoesServiceRequest public FileOutputStream openWriteExisting(AccessCondition accessCondition, FileRequestOptions options, - OperationContext opContext) throws StorageException { + OperationContext opContext) throws StorageException, URISyntaxException { return this.openOutputStreamInternal(null /* length */, accessCondition, options, opContext); } From 0da90bcca0b069f24899f58b3da147958e1238e9 Mon Sep 17 00:00:00 2001 From: Josh Friedman Date: Thu, 27 Apr 2017 14:48:40 -0700 Subject: [PATCH 06/12] Remove check that MD5 is sent by service --- .../storage/blob/CloudBlockBlobTests.java | 45 ++++++++++--------- .../azure/storage/blob/CloudBlob.java | 6 --- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlockBlobTests.java b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlockBlobTests.java index d4181721d20b7..ba4f8cd276f90 100644 --- a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlockBlobTests.java +++ b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlockBlobTests.java @@ -60,33 +60,11 @@ import java.util.Random; import java.util.TimeZone; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import com.microsoft.azure.storage.AccessCondition; -import com.microsoft.azure.storage.Constants; -import com.microsoft.azure.storage.NameValidator; -import com.microsoft.azure.storage.OperationContext; -import com.microsoft.azure.storage.RetryNoRetry; -import com.microsoft.azure.storage.SendingRequestEvent; -import com.microsoft.azure.storage.StorageCredentialsAnonymous; -import com.microsoft.azure.storage.StorageCredentialsSharedAccessSignature; import com.microsoft.azure.storage.StorageErrorCodeStrings; -import com.microsoft.azure.storage.StorageEvent; -import com.microsoft.azure.storage.StorageException; import com.microsoft.azure.storage.TestRunners.CloudTests; import com.microsoft.azure.storage.TestRunners.DevFabricTests; import com.microsoft.azure.storage.TestRunners.DevStoreTests; import com.microsoft.azure.storage.TestRunners.SlowTests; -import com.microsoft.azure.storage.core.Utility; -import com.microsoft.azure.storage.file.CloudFile; -import com.microsoft.azure.storage.file.CloudFileShare; -import com.microsoft.azure.storage.file.FileProperties; -import com.microsoft.azure.storage.file.FileTestHelper; -import com.microsoft.azure.storage.file.SharedAccessFilePermissions; -import com.microsoft.azure.storage.file.SharedAccessFilePolicy; import static org.junit.Assert.*; @@ -1197,6 +1175,29 @@ public void testBlobUploadWithoutMD5Validation() throws URISyntaxException, Stor assertEquals("MDAwMDAwMDA=", blockBlobRef2.properties.getContentMD5()); } + @Test + @Category({ DevFabricTests.class, DevStoreTests.class }) + public void testVerifyTransactionalMD5ValidationMissingOverallMD5() throws URISyntaxException, StorageException, IOException { + final String blockBlobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob"); + final CloudBlockBlob blockBlobRef = this.container.getBlockBlobReference(blockBlobName); + + final int length = 2 * 1024 * 1024; + ByteArrayInputStream srcStream = BlobTestHelper.getRandomDataStream(length); + BlobRequestOptions options = new BlobRequestOptions(); + options.setSingleBlobPutThresholdInBytes(1024*1024); + options.setDisableContentMD5Validation(true); + options.setStoreBlobContentMD5(false); + + blockBlobRef.upload(srcStream, -1, null, options, null); + + options.setDisableContentMD5Validation(false); + options.setStoreBlobContentMD5(true); + options.setUseTransactionalContentMD5(true); + final CloudBlockBlob blockBlobRef2 = this.container.getBlockBlobReference(blockBlobName); + blockBlobRef2.downloadRange(1024, (long)1024, new ByteArrayOutputStream(), null, options, null); + assertNull(blockBlobRef2.getProperties().getContentMD5()); + } + @Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testBlockBlobUploadContentMD5() throws URISyntaxException, StorageException, IOException { diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlob.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlob.java index 4992d89cf5d59..03561ba0879ec 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlob.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlob.java @@ -1354,12 +1354,6 @@ public Integer preProcessResponse(CloudBlob blob, CloudBlobClient client, Operat final BlobAttributes retrievedAttributes = BlobResponse.getBlobAttributes(this.getConnection(), blob.getStorageUri(), blob.snapshotID); - if (!options.getDisableContentMD5Validation() && options.getUseTransactionalContentMD5() - && Utility.isNullOrEmpty(retrievedAttributes.getProperties().getContentMD5())) { - throw new StorageException(StorageErrorCodeStrings.MISSING_MD5_HEADER, SR.MISSING_MD5, - Constants.HeaderConstants.HTTP_UNUSED_306, null, null); - } - blob.properties = retrievedAttributes.getProperties(); blob.metadata = retrievedAttributes.getMetadata(); From 17c8f69a18221133d4f3d9213618ee5d8e093f91 Mon Sep 17 00:00:00 2001 From: Josh Friedman Date: Thu, 27 Apr 2017 15:32:25 -0700 Subject: [PATCH 07/12] Fixed encryption bug related to attempting to use a policy on an unencrypted blob --- .../blob/CloudBlobClientEncryptionTests.java | 37 ++++++++++++++++++- .../storage/blob/CloudBlockBlobTests.java | 19 +++++++++- .../storage/blob/BlobEncryptionPolicy.java | 17 +++++---- 3 files changed, 62 insertions(+), 11 deletions(-) diff --git a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlobClientEncryptionTests.java b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlobClientEncryptionTests.java index 1fdd8eec6c0b7..3d30f86410739 100644 --- a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlobClientEncryptionTests.java +++ b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlobClientEncryptionTests.java @@ -23,6 +23,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.net.URISyntaxException; +import java.nio.charset.Charset; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; @@ -143,7 +144,41 @@ else if (type == BlobType.APPEND_BLOB) { TestHelper.assertStreamsAreEqualAtIndex(stream, new ByteArrayInputStream(outputStream.toByteArray()), 0, 0, size, 2 * 1024); } - + + @Test + public void testDownloadUnencryptedBlobWithEncryptionPolicy() throws StorageException, IOException, URISyntaxException, NoSuchAlgorithmException + { + String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("test"); + CloudBlockBlob blob = container.getBlockBlobReference(blobName); + blob.deleteIfExists(); + + byte[] msg = "my message".getBytes(); + // Upload data without encryption + blob.uploadFromByteArray(msg, 0, msg.length); + + // Create options with encryption policy + BlobRequestOptions options = new BlobRequestOptions(); + options.setEncryptionPolicy(new BlobEncryptionPolicy(new RsaKey("myKey", 1024), null)); + options.setRequireEncryption(true); + + try { + blob.downloadText(Charset.defaultCharset().name(), null, options, null); + fail("Expect exception"); + } + catch (StorageException e) { + assertEquals(SR.ENCRYPTION_DATA_NOT_PRESENT_ERROR, e.getMessage()); + } + + byte[] buffer = new byte[msg.length]; + try { + blob.downloadRangeToByteArray(0, (long) buffer.length, buffer, 0, null, options, null); + fail("Expect exception"); + } + catch (StorageException e) { + assertEquals(SR.ENCRYPTION_DATA_NOT_PRESENT_ERROR, e.getMessage()); + } + } + @Test public void testBlobEncryptionWithFile() throws URISyntaxException, StorageException, IOException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException { diff --git a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlockBlobTests.java b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlockBlobTests.java index ba4f8cd276f90..5027d672b2cce 100644 --- a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlockBlobTests.java +++ b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlockBlobTests.java @@ -33,8 +33,6 @@ import com.microsoft.azure.storage.file.SharedAccessFilePermissions; import com.microsoft.azure.storage.file.SharedAccessFilePolicy; -import junit.framework.Assert; - import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -1748,6 +1746,23 @@ public void testBlobConditionalAccess() throws StorageException, IOException, UR newETag = blob.getProperties().getEtag(); assertFalse("ETage should be modified on write metadata", newETag.equals(currentETag)); } + + @Test + public void testBlobExceedMaxRange() throws URISyntaxException, StorageException, IOException + { + CloudBlockBlob blob = container.getBlockBlobReference("blockblob4"); + blob.deleteIfExists(); + + byte[] msg = "my message".getBytes("UTF-8"); + blob.uploadFromByteArray(msg, 0, msg.length); + + byte[] buffer = new byte[msg.length + 5]; + + blob.downloadRangeToByteArray(0, (long) buffer.length, buffer, 0, null, null, null); + String expected = new String (msg, "UTF-8"); + String actual = new String(buffer, "UTF-8").substring(0, 10); + assertEquals(expected, actual); + } @Test @Category({ DevFabricTests.class, DevStoreTests.class }) diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobEncryptionPolicy.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobEncryptionPolicy.java index ea2ec36ae470e..ac77d8f47ca24 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobEncryptionPolicy.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobEncryptionPolicy.java @@ -130,15 +130,8 @@ public void setKeyResolver(IKeyResolver keyResolver) { OutputStream decryptBlob(OutputStream userProvidedStream, Map metadata, Boolean requireEncryption, byte[] iv, boolean noPadding) throws StorageException { Utility.assertNotNull("metadata", metadata); - - // If encryption policy is set but the encryption metadata is absent, throw - // an exception. String encryptionDataString = metadata.get("encryptiondata"); - if (requireEncryption != null && requireEncryption && encryptionDataString == null) - { - throw new StorageException(StorageErrorCodeStrings.DECRYPTION_ERROR, SR.ENCRYPTION_DATA_NOT_PRESENT_ERROR, null); - } - + try { if (encryptionDataString != null) { @@ -234,6 +227,14 @@ static OutputStream wrapUserStreamWithDecryptStream(CloudBlob blob, OutputStream BlobRequestOptions options, Map metadata, long blobLength, boolean rangeRead, Long endOffset, Long userSpecifiedLength, int discardFirst, boolean bufferIV) throws StorageException { + // If encryption policy is set but the encryption metadata is absent, throw + // an exception. + String encryptionDataString = metadata.get("encryptiondata"); + if (options.requireEncryption() != null && options.requireEncryption() && encryptionDataString == null) + { + throw new StorageException(StorageErrorCodeStrings.DECRYPTION_ERROR, SR.ENCRYPTION_DATA_NOT_PRESENT_ERROR, null); + } + if (!rangeRead) { // The user provided stream should be wrapped in a TruncatingNonCloseableStream in order to From bc579786a04494430eb0e348747ef91284c4170b Mon Sep 17 00:00:00 2001 From: Josh Friedman Date: Tue, 2 May 2017 18:46:27 -0700 Subject: [PATCH 08/12] Fixed transactional MD5 check --- BreakingChanges.txt | 2 +- .../src/com/microsoft/azure/storage/blob/CloudBlob.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/BreakingChanges.txt b/BreakingChanges.txt index e5598da0115bc..bc70b92ad6282 100644 --- a/BreakingChanges.txt +++ b/BreakingChanges.txt @@ -6,7 +6,7 @@ FILE * In CloudFileShareProperties, setShareQuota() no longer asserts in bounds. This check has been moved to create() and uploadProperties() in CloudFileShare. BLOB/FILE - * Fixed a bug which allowed setting content MD5 to true when calling openWriteExisting() on a page blob or file. + * Fixed a bug which prevented setting content MD5 to true when calling openWriteExisting() on a page blob or file. Changes in 5.0.0 diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlob.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlob.java index 03561ba0879ec..9ab2374340a02 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlob.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlob.java @@ -1360,6 +1360,13 @@ public Integer preProcessResponse(CloudBlob blob, CloudBlobClient client, Operat // Need to store the Content MD5 in case we fail part way through. // We would still need to verify the entire range. String contentMD5 = this.getConnection().getHeaderField(Constants.HeaderConstants.CONTENT_MD5); + + if (!options.getDisableContentMD5Validation() && options.getUseTransactionalContentMD5() + && Utility.isNullOrEmpty(contentMD5)) { + throw new StorageException(StorageErrorCodeStrings.MISSING_MD5_HEADER, SR.MISSING_MD5, + Constants.HeaderConstants.HTTP_UNUSED_306, null, null); + } + this.setContentMD5(contentMD5); this.setLockedETag(blob.properties.getEtag()); this.setArePropertiesPopulated(true); From 69759ad72d68e86694d3188a717eb3ad9a148a3c Mon Sep 17 00:00:00 2001 From: Josh Friedman Date: Thu, 4 May 2017 09:40:18 -0700 Subject: [PATCH 09/12] Fixed transactional MD5 check for files --- ChangeLog.txt | 2 ++ .../azure/storage/file/CloudFileTests.java | 24 ++++++++++++++++++- .../azure/storage/file/CloudFile.java | 12 +++++----- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 9fe483cfd0232..0d86fef069f51 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -3,6 +3,8 @@ * Changed blob constants to support up to 256 MB on put blob for block blobs. The default value for put blob threshold has also been updated to half of the maximum, or 128 MB currently. * Fixed a bug that prevented setting content MD5 to true when creating a new file. * Fixed a bug where access conditions, options, and operation context were not being passed when calling openWriteExisting() on a page blob or a file. + * Fixed a bug where an exception was being thrown on a range get of a blob or file when the options disableContentMD5Validation is set to false and useTransactionalContentMD5 is set to true and there is no overall MD5. + * Fixed a bug where retries were happening immediately if a sock exception was thrown. 2017.01.18 Version 5.0.0 * Prefix support for listing files and directories. diff --git a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileTests.java b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileTests.java index 125e4a296253e..9bf77cfb9ea47 100644 --- a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileTests.java +++ b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileTests.java @@ -86,7 +86,7 @@ public void fileTestMethodSetUp() throws URISyntaxException, StorageException { @After public void fileTestMethodTearDown() throws StorageException { - //this.share.deleteIfExists(); + this.share.deleteIfExists(); } /** @@ -1124,6 +1124,28 @@ public void testCloudFileUploadRange() throws URISyntaxException, StorageExcepti inputStream = new ByteArrayInputStream(buffer); } + + @Test + @Category({ DevFabricTests.class, DevStoreTests.class }) + public void testVerifyTransactionalMD5ValidationMissingOverallMD5() throws URISyntaxException, StorageException, IOException { + final String fileName = FileTestHelper.generateRandomFileName(); + final CloudFile fileRef = this.share.getRootDirectoryReference().getFileReference(fileName); + + final int length = 3*1024; + ByteArrayInputStream srcStream = BlobTestHelper.getRandomDataStream(length); + FileRequestOptions options = new FileRequestOptions(); + options.setDisableContentMD5Validation(true); + options.setStoreFileContentMD5(false); + + fileRef.upload(srcStream, length, null, options, null); + + options.setDisableContentMD5Validation(false); + options.setStoreFileContentMD5(true); + options.setUseTransactionalContentMD5(true); + final CloudFile fileRef2 = this.share.getRootDirectoryReference().getFileReference(fileName); + fileRef2.downloadRange(1024, (long)1024, new ByteArrayOutputStream(), null, options, null); + assertNull(fileRef2.getProperties().getContentMD5()); + } /** * Test clearing file ranges. diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFile.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFile.java index aefd1349b8a34..749e9304cb050 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFile.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFile.java @@ -1379,12 +1379,6 @@ public Integer preProcessResponse(CloudFile file, CloudFileClient client, Operat final FileAttributes retrievedAttributes = FileResponse.getFileAttributes(this.getConnection(), file.getStorageUri()); - if (!options.getDisableContentMD5Validation() && options.getUseTransactionalContentMD5() - && Utility.isNullOrEmpty(retrievedAttributes.getProperties().getContentMD5())) { - throw new StorageException(StorageErrorCodeStrings.MISSING_MD5_HEADER, SR.MISSING_MD5, - Constants.HeaderConstants.HTTP_UNUSED_306, null, null); - } - file.properties = retrievedAttributes.getProperties(); file.metadata = retrievedAttributes.getMetadata(); @@ -1392,6 +1386,12 @@ public Integer preProcessResponse(CloudFile file, CloudFileClient client, Operat // We would still need to verify the entire range. this.setContentMD5(this.getConnection().getHeaderField(Constants.HeaderConstants.CONTENT_MD5)); + if (!options.getDisableContentMD5Validation() && options.getUseTransactionalContentMD5() + && Utility.isNullOrEmpty(this.getContentMD5())) { + throw new StorageException(StorageErrorCodeStrings.MISSING_MD5_HEADER, SR.MISSING_MD5, + Constants.HeaderConstants.HTTP_UNUSED_306, null, null); + } + this.setLockedETag(file.properties.getEtag()); this.setArePropertiesPopulated(true); } From 4811953e40122b4a20695ee2c7b41fb2d8a722d4 Mon Sep 17 00:00:00 2001 From: Josh Friedman Date: Thu, 4 May 2017 09:45:50 -0700 Subject: [PATCH 10/12] Updating version for 5.1.0 release --- ChangeLog.txt | 2 +- README.md | 2 +- microsoft-azure-storage-samples/pom.xml | 2 +- .../src/com/microsoft/azure/storage/Constants.java | 2 +- pom.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 0d86fef069f51..6f2d4d628b721 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,4 +1,4 @@ -2017.04.25 Version 5.1.0 +2017.05.04 Version 5.1.0 * Fixed Exists() calls on Shares and Directories to now populate metadata. This was already being done for Files. * Changed blob constants to support up to 256 MB on put blob for block blobs. The default value for put blob threshold has also been updated to half of the maximum, or 128 MB currently. * Fixed a bug that prevented setting content MD5 to true when creating a new file. diff --git a/README.md b/README.md index 7399caeaf94eb..f10c44745ad85 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ To get the binaries of this library as distributed by Microsoft, ready for use w com.microsoft.azure azure-storage - 5.0.0 + 5.1.0 ``` diff --git a/microsoft-azure-storage-samples/pom.xml b/microsoft-azure-storage-samples/pom.xml index dfad84d66081b..1e89f60ccb739 100644 --- a/microsoft-azure-storage-samples/pom.xml +++ b/microsoft-azure-storage-samples/pom.xml @@ -26,7 +26,7 @@ com.microsoft.azure azure-storage - 5.0.0 + 5.1.0 com.microsoft.azure diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/Constants.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/Constants.java index cc0995cd9e109..31d08df24e6a8 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/Constants.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/Constants.java @@ -661,7 +661,7 @@ public static class HeaderConstants { /** * Specifies the value to use for UserAgent header. */ - public static final String USER_AGENT_VERSION = "5.0.0"; + public static final String USER_AGENT_VERSION = "5.1.0"; /** * The default type for content-type and accept diff --git a/pom.xml b/pom.xml index cc2e300d763d4..a7f39b54ba541 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ 4.0.0 com.microsoft.azure azure-storage - 5.0.0 + 5.1.0 jar Microsoft Azure Storage Client SDK From b4539bdf6b58c1bc4bf3e60e56bce6d71ebb0174 Mon Sep 17 00:00:00 2001 From: Josh Friedman Date: Thu, 4 May 2017 11:00:53 -0700 Subject: [PATCH 11/12] Revert list shares enumset and exists() populating metadata --- BreakingChanges.txt | 2 -- .../storage/file/CloudFileClientTests.java | 6 ++-- .../storage/file/CloudFileShareTests.java | 2 +- .../azure/storage/file/CloudFileClient.java | 30 ++++++++---------- .../storage/file/CloudFileDirectory.java | 11 ++++--- .../azure/storage/file/CloudFileShare.java | 9 +++--- .../azure/storage/file/FileRequest.java | 31 ++++++++++--------- .../storage/file/ShareListingDetails.java | 10 ++++++ 8 files changed, 55 insertions(+), 46 deletions(-) diff --git a/BreakingChanges.txt b/BreakingChanges.txt index bc70b92ad6282..a8f72dff58062 100644 --- a/BreakingChanges.txt +++ b/BreakingChanges.txt @@ -1,8 +1,6 @@ Changes in 5.1.0 FILE - * Exists() calls on Shares and Directories now populates metadata. This was already being done for Files. - * Changed listShares() ShareListingDetails parameter to be an enum set like what is done for listing blobs. * In CloudFileShareProperties, setShareQuota() no longer asserts in bounds. This check has been moved to create() and uploadProperties() in CloudFileShare. BLOB/FILE diff --git a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileClientTests.java b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileClientTests.java index dedd08ac03270..f83e4d588d3a5 100644 --- a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileClientTests.java +++ b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileClientTests.java @@ -67,7 +67,7 @@ public void testListSharesTest() throws StorageException, URISyntaxException { do { ResultSegment segment = fileClient.listSharesSegmented(prefix, - EnumSet.allOf(ShareListingDetails.class), 15, token, null, null); + ShareListingDetails.ALL, 15, token, null, null); for (final CloudFileShare share : segment.getResults()) { share.downloadAttributes(); @@ -104,7 +104,7 @@ public void testListSharesMaxResultsValidationTest() throws StorageException, UR for (int i = 0; i >= -2; i--) { try{ fileClient.listSharesSegmented( - prefix, EnumSet.allOf(ShareListingDetails.class), i, null, null, null); + prefix, ShareListingDetails.ALL, i, null, null, null); fail(); } catch (IllegalArgumentException e) { @@ -133,7 +133,7 @@ public void testListSharesWithSnapshot() throws StorageException, URISyntaxExcep share.uploadMetadata(); CloudFileClient client = FileTestHelper.createCloudFileClient(); - Iterable listResult = client.listShares(share.name, EnumSet.allOf(ShareListingDetails.class), null, null); + Iterable listResult = client.listShares(share.name, ShareListingDetails.ALL, null, null); int count = 0; boolean originalFound = false; diff --git a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileShareTests.java b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileShareTests.java index af3fb13d0477a..46a84aac4c581 100644 --- a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileShareTests.java +++ b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileShareTests.java @@ -318,7 +318,7 @@ public void testCloudFileShareUploadMetadata() throws StorageException, URISynta Assert.assertEquals("value2", this.share.getMetadata().get("key2")); Iterable shares = this.share.getServiceClient().listShares(this.share.getName(), - EnumSet.of(ShareListingDetails.METADATA), null, null); + ShareListingDetails.METADATA, null, null); for (CloudFileShare share3 : shares) { Assert.assertEquals(2, share3.getMetadata().size()); diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileClient.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileClient.java index d6d3eb1a63330..409d4ff2730bf 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileClient.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileClient.java @@ -134,7 +134,7 @@ protected CloudFileShare getShareReference(final String shareName, String snapsh */ @DoesServiceRequest public Iterable listShares() { - return this.listSharesWithPrefix(null, EnumSet.noneOf(ShareListingDetails.class), null /* options */, null /* opContext */); + return this.listSharesWithPrefix(null, ShareListingDetails.NONE, null /* options */, null /* opContext */); } /** @@ -149,7 +149,7 @@ public Iterable listShares() { */ @DoesServiceRequest public Iterable listShares(final String prefix) { - return this.listSharesWithPrefix(prefix, EnumSet.noneOf(ShareListingDetails.class), null /* options */, null /* opContext */); + return this.listSharesWithPrefix(prefix, ShareListingDetails.NONE, null /* options */, null /* opContext */); } /** @@ -159,8 +159,7 @@ public Iterable listShares(final String prefix) { * @param prefix * A String that represents the share name prefix. * @param detailsIncluded - * A java.util.EnumSet object that contains {@link ShareListingDetails} values that indicate - * whether share snapshots and/or metadata will be returned. + * A {@link ShareListingDetails} value that indicates whether share metadata will be returned. * @param options * A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying * null will use the default request options from the associated service client ( @@ -174,7 +173,7 @@ public Iterable listShares(final String prefix) { * shares for this client. */ @DoesServiceRequest - public Iterable listShares(final String prefix, final EnumSet detailsIncluded, + public Iterable listShares(final String prefix, final ShareListingDetails detailsIncluded, final FileRequestOptions options, final OperationContext opContext) { return this.listSharesWithPrefix(prefix, detailsIncluded, options, opContext); } @@ -190,7 +189,7 @@ public Iterable listShares(final String prefix, final EnumSet listSharesSegmented() throws StorageException { - return this.listSharesSegmented(null, EnumSet.noneOf(ShareListingDetails.class), null, null /* continuationToken */, + return this.listSharesSegmented(null, ShareListingDetails.NONE, null, null /* continuationToken */, null /* options */, null /* opContext */); } @@ -210,7 +209,7 @@ public ResultSegment listSharesSegmented() throws StorageExcepti */ @DoesServiceRequest public ResultSegment listSharesSegmented(final String prefix) throws StorageException { - return this.listSharesWithPrefixSegmented(prefix, EnumSet.noneOf(ShareListingDetails.class), null, null /* continuationToken */, + return this.listSharesWithPrefixSegmented(prefix, ShareListingDetails.NONE, null, null /* continuationToken */, null /* options */, null /* opContext */); } @@ -221,8 +220,7 @@ public ResultSegment listSharesSegmented(final String prefix) th * @param prefix * A String that represents the prefix of the share name. * @param detailsIncluded - * A java.util.EnumSet object that contains {@link ShareListingDetails} values that indicate - * whether share snapshots and/or metadata will be returned. + * A {@link ShareListingDetails} value that indicates whether share metadata will be returned. * @param maxResults * The maximum number of results to retrieve. If null or greater * than 5000, the server will return up to 5,000 items. Must be at least 1. @@ -246,7 +244,7 @@ public ResultSegment listSharesSegmented(final String prefix) th */ @DoesServiceRequest public ResultSegment listSharesSegmented(final String prefix, - final EnumSet detailsIncluded, final Integer maxResults, + final ShareListingDetails detailsIncluded, final Integer maxResults, final ResultContinuation continuationToken, final FileRequestOptions options, final OperationContext opContext) throws StorageException { return this.listSharesWithPrefixSegmented(prefix, detailsIncluded, maxResults, continuationToken, options, @@ -260,8 +258,7 @@ public ResultSegment listSharesSegmented(final String prefix, * @param prefix * A String that represents the prefix of the share name. * @param detailsIncluded - * A java.util.EnumSet object that contains {@link ShareListingDetails} - * values that indicate whether snapshots and/or metadata are returned. + * A {@link ShareListingDetails} value that indicates whether share metadata will be returned. * @param options * A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying * null will use the default request options from the associated service client ( @@ -275,7 +272,7 @@ public ResultSegment listSharesSegmented(final String prefix, * shares whose names begin with the specified prefix. */ private Iterable listSharesWithPrefix(final String prefix, - final EnumSet detailsIncluded, FileRequestOptions options, OperationContext opContext) { + final ShareListingDetails detailsIncluded, FileRequestOptions options, OperationContext opContext) { if (opContext == null) { opContext = new OperationContext(); } @@ -297,8 +294,7 @@ private Iterable listSharesWithPrefix(final String prefix, * @param prefix * A String that represents the prefix of the share name. * @param detailsIncluded - * A java.util.EnumSet object that contains {@link ShareListingDetails} values that indicate - * whether share snapshots and/or metadata will be returned. + * A {@link ShareListingDetails} value that indicates whether share metadata will be returned. * @param maxResults * The maximum number of results to retrieve. If null or greater * than 5000, the server will return up to 5,000 items. Must be at least 1. @@ -321,7 +317,7 @@ private Iterable listSharesWithPrefix(final String prefix, * If a storage service error occurred. */ private ResultSegment listSharesWithPrefixSegmented(final String prefix, - final EnumSet detailsIncluded, final Integer maxResults, + final ShareListingDetails detailsIncluded, final Integer maxResults, final ResultContinuation continuationToken, FileRequestOptions options, OperationContext opContext) throws StorageException { if (opContext == null) { @@ -342,7 +338,7 @@ private ResultSegment listSharesWithPrefixSegmented(final String } private StorageRequest> listSharesWithPrefixSegmentedImpl( - final String prefix, final EnumSet detailsIncluded, final Integer maxResults, + final String prefix, final ShareListingDetails detailsIncluded, final Integer maxResults, final FileRequestOptions options, final SegmentedStorageRequest segmentedRequest) { Utility.assertContinuationType(segmentedRequest.getToken(), ResultContinuationType.SHARE); diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileDirectory.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileDirectory.java index bc171cf4e422a..fcb275f32bcab 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileDirectory.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileDirectory.java @@ -529,11 +529,12 @@ public void signRequest(HttpURLConnection connection, CloudFileClient client, Op public Boolean preProcessResponse(CloudFileDirectory directory, CloudFileClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() == HttpURLConnection.HTTP_OK) { - // Set properties - final FileDirectoryAttributes attributes = - FileResponse.getFileDirectoryAttributes(this.getConnection(), client.isUsePathStyleUris()); - directory.setMetadata(attributes.getMetadata()); - directory.setProperties(attributes.getProperties()); + directory.updatePropertiesFromResponse(this.getConnection()); +// // Set properties +// final FileDirectoryAttributes attributes = +// FileResponse.getFileDirectoryAttributes(this.getConnection(), client.isUsePathStyleUris()); +// directory.setMetadata(attributes.getMetadata()); +// directory.setProperties(attributes.getProperties()); return Boolean.valueOf(true); } diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileShare.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileShare.java index fa13045161e7b..d3d180261010e 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileShare.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileShare.java @@ -1019,10 +1019,11 @@ public void signRequest(HttpURLConnection connection, CloudFileClient client, Op public Boolean preProcessResponse(CloudFileShare share, CloudFileClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() == HttpURLConnection.HTTP_OK) { - final FileShareAttributes attributes = FileResponse.getFileShareAttributes(this.getConnection(), - client.isUsePathStyleUris()); - share.metadata = attributes.getMetadata(); - share.properties = attributes.getProperties(); + share.updatePropertiesFromResponse(this.getConnection()); +// final FileShareAttributes attributes = FileResponse.getFileShareAttributes(this.getConnection(), +// client.isUsePathStyleUris()); +// share.metadata = attributes.getMetadata(); +// share.properties = attributes.getProperties(); return Boolean.valueOf(true); } diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileRequest.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileRequest.java index 746c5b5ce3ead..092f4866a6d62 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileRequest.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileRequest.java @@ -640,8 +640,7 @@ private static HttpURLConnection getProperties(final URI uri, final FileRequestO * @param listingContext * A set of parameters for the listing operation. * @param detailsIncluded - * A java.util.EnumSet object that contains {@link ShareListingDetails} values that indicate - * whether share snapshots and/or metadata will be returned. + * Additional details to return with the listing. * @return a HttpURLConnection configured for the operation. * @throws IOException * @throws URISyntaxException @@ -650,28 +649,32 @@ private static HttpURLConnection getProperties(final URI uri, final FileRequestO */ public static HttpURLConnection listShares(final URI uri, final FileRequestOptions fileOptions, final OperationContext opContext, final ListingContext listingContext, - final EnumSet detailsIncluded) throws URISyntaxException, IOException, StorageException { + final ShareListingDetails detailsIncluded) throws URISyntaxException, IOException, StorageException { final UriQueryBuilder builder = BaseRequest.getListUriQueryBuilder(listingContext); - if (detailsIncluded != null && detailsIncluded.size() > 0) { - final StringBuilder sb = new StringBuilder(); - boolean started = false; +// if (detailsIncluded != null && detailsIncluded.size() > 0) { +// final StringBuilder sb = new StringBuilder(); +// boolean started = false; // if (detailsIncluded.contains(ShareListingDetails.SNAPSHOTS)) { // started = true; // sb.append(SNAPSHOTS_QUERY_ELEMENT_NAME); // } - if (detailsIncluded.contains(ShareListingDetails.METADATA)) { - if (started) - { - sb.append(","); - } +// if (detailsIncluded.contains(ShareListingDetails.METADATA)) { +// if (started) +// { +// sb.append(","); +// } +// +// sb.append(Constants.QueryConstants.METADATA); +// } - sb.append(Constants.QueryConstants.METADATA); - } +// builder.add(Constants.QueryConstants.INCLUDE, sb.toString()); +// } - builder.add(Constants.QueryConstants.INCLUDE, sb.toString()); + if (detailsIncluded == ShareListingDetails.ALL || detailsIncluded == ShareListingDetails.METADATA) { + builder.add(Constants.QueryConstants.INCLUDE, Constants.QueryConstants.METADATA); } final HttpURLConnection request = BaseRequest.createURLConnection(uri, fileOptions, builder, opContext); diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/ShareListingDetails.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/ShareListingDetails.java index 3e746585cf2da..87640da8982eb 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/ShareListingDetails.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/ShareListingDetails.java @@ -19,6 +19,16 @@ */ public enum ShareListingDetails { + /** + * Specifies including no additional details. + */ + NONE(0), + + /** + * Specifies including all available details. + */ + ALL(1), + /** * Specifies including share metadata. */ From 534ef374e11900de138d323c4664bde496088032 Mon Sep 17 00:00:00 2001 From: Josh Friedman Date: Thu, 4 May 2017 11:17:02 -0700 Subject: [PATCH 12/12] Fixed breaking changes and changelog for 5.1.0 release --- BreakingChanges.txt | 10 +--------- ChangeLog.txt | 3 ++- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/BreakingChanges.txt b/BreakingChanges.txt index a8f72dff58062..79229edf4d557 100644 --- a/BreakingChanges.txt +++ b/BreakingChanges.txt @@ -1,12 +1,4 @@ -Changes in 5.1.0 - -FILE - * In CloudFileShareProperties, setShareQuota() no longer asserts in bounds. This check has been moved to create() and uploadProperties() in CloudFileShare. - -BLOB/FILE - * Fixed a bug which prevented setting content MD5 to true when calling openWriteExisting() on a page blob or file. - -Changes in 5.0.0 +Changes in 5.0.0 BLOB * getQualifiedUri() has been deprecated. Please use getSnapshotQualifiedUri() instead. This new function will return the blob including the snapshot (if present) and no SAS token. diff --git a/ChangeLog.txt b/ChangeLog.txt index 6f2d4d628b721..6f16e6fbaf9c1 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -4,7 +4,8 @@ * Fixed a bug that prevented setting content MD5 to true when creating a new file. * Fixed a bug where access conditions, options, and operation context were not being passed when calling openWriteExisting() on a page blob or a file. * Fixed a bug where an exception was being thrown on a range get of a blob or file when the options disableContentMD5Validation is set to false and useTransactionalContentMD5 is set to true and there is no overall MD5. - * Fixed a bug where retries were happening immediately if a sock exception was thrown. + * Fixed a bug where retries were happening immediately if a socket exception was thrown. + * In CloudFileShareProperties, setShareQuota() no longer asserts in bounds. This check has been moved to create() and uploadProperties() in CloudFileShare. 2017.01.18 Version 5.0.0 * Prefix support for listing files and directories.