From d3d840595522e492b007b01030b276c7bcbb5675 Mon Sep 17 00:00:00 2001 From: Josh Friedman Date: Tue, 10 Oct 2017 12:30:48 -0700 Subject: [PATCH 1/4] 2.0.0 Release --- BreakingChanges.txt | 9 + ChangeLog.txt | 6 + README.md | 4 +- .../AndroidManifest.xml | 2 +- .../AndroidManifest.xml | 2 +- .../azure/storage/EventFiringTests.java | 23 +- .../azure/storage/StorageAccountTests.java | 421 +++++++++++++++++- .../storage/file/CloudFileClientTests.java | 56 ++- .../storage/file/CloudFileDirectoryTests.java | 73 ++- .../storage/file/CloudFileShareTests.java | 189 +++++++- .../azure/storage/file/CloudFileTests.java | 129 +++++- .../azure/storage/file/FileTestHelper.java | 6 +- microsoft-azure-storage/AndroidManifest.xml | 2 +- microsoft-azure-storage/pom.xml | 2 +- .../azure/storage/CloudStorageAccount.java | 374 +++++++++++++--- .../microsoft/azure/storage/Constants.java | 12 +- .../storage/ServicePropertiesHandler.java | 2 +- .../azure/storage/StorageCredentials.java | 2 +- .../storage/StorageErrorCodeStrings.java | 5 + .../com/microsoft/azure/storage/core/SR.java | 1 + .../microsoft/azure/storage/core/Utility.java | 11 +- .../azure/storage/file/CloudFile.java | 146 ++++-- .../azure/storage/file/CloudFileClient.java | 55 ++- .../storage/file/CloudFileDirectory.java | 73 ++- .../azure/storage/file/CloudFileShare.java | 295 +++++++++++- .../file/DeleteShareSnapshotsOption.java | 35 ++ .../azure/storage/file/FileOutputStream.java | 12 +- .../azure/storage/file/FileRequest.java | 145 +++++- .../azure/storage/file/FileResponse.java | 11 + .../storage/file/FileShareProperties.java | 21 + .../azure/storage/file/ShareListHandler.java | 6 + .../storage/file/ShareListingDetails.java | 9 +- 32 files changed, 1919 insertions(+), 220 deletions(-) create mode 100644 BreakingChanges.txt create mode 100644 microsoft-azure-storage/src/com/microsoft/azure/storage/file/DeleteShareSnapshotsOption.java diff --git a/BreakingChanges.txt b/BreakingChanges.txt new file mode 100644 index 0000000..01fb783 --- /dev/null +++ b/BreakingChanges.txt @@ -0,0 +1,9 @@ +Breaking Changes in 2.0.0 + +FILE +* Many File service APIs can now throw a URISyntaxException. +* Changed listShares() ShareListingDetails parameter to be an enum set like what is done for listing blobs. + +OTHER + * DefaultEndpointsProtocol will now be explicitly included in generated connection strings. + * Connection string parsing has been substantially re-written and expanded. Please refer to current documentation about connection string formats. \ No newline at end of file diff --git a/ChangeLog.txt b/ChangeLog.txt index 2798859..f01b649 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,9 @@ +2017.XX.XX Version 2.0.0 + * Added support for taking a snapshot of a share. + * IOExceptions wrapping StorageExceptions will now contain the StorageException message in the outer exception. + * Connection string support expanded to allow AccountName to be specified with SharedAccessSignature and DefaultEndpointsProtocol. In this case, SharedAccessSignature is used for credentials, while having both DefaultEndpointsProtocol and AccountName allows the library to infer a set of default endpoints. Additionally, we have added support for BlobSecondaryEndpoint, QueueSecondaryEndpoint, TableSecondaryEndpoint, and FileSecondaryEndpoint. Specifying a secondary endpoint requires the specification of the corresponding primary. + * The use of DefaultEndpointsProtocol in a connection string is now optional in the case where endpoints would be automatically generated; if missing, a value of https will be inferred. When the parsed account settings in such a case are used to generate a connection string, the value of DefaultEndpointsProtocol will be explicitly included. + 2017.08.30 Version 1.2.0 * Fixed a bug when using a SAS token where the token was being omitted from calls to delete a directory in the file service. * For Standard Storage Accounts only, added the ability to set the tier of individual block blobs. The tier can currently only be set through uploadTier(). diff --git a/README.md b/README.md index 8a0cf4b..e9e2207 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ First, add mavenCentral to your repositories by adding the following to your gra Then, add a dependency by adding the following to your gradle build file: dependencies { - compile 'com.microsoft.azure.android:azure-storage-android:1.2.0@aar' + compile 'com.microsoft.azure.android:azure-storage-android:2.0.0@aar' } ### Option 4: aar via Maven @@ -57,7 +57,7 @@ To get the binaries of this library as distributed by Microsoft, ready for use w com.microsoft.azure.android azure-storage-android - 1.2.0 + 2.0.0 aar ``` diff --git a/microsoft-azure-storage-samples/AndroidManifest.xml b/microsoft-azure-storage-samples/AndroidManifest.xml index 7d9e580..da9e503 100644 --- a/microsoft-azure-storage-samples/AndroidManifest.xml +++ b/microsoft-azure-storage-samples/AndroidManifest.xml @@ -2,7 +2,7 @@ + android:versionName="2.0.0" > + android:versionName="2.0.0" > () { + StorageEvent globalResponseReceivedListener = new StorageEvent() { - @Override - public void eventOccurred(ErrorReceivingResponseEvent eventArg) { - fail("This event should not trigger"); - } - }); + @Override + public void eventOccurred(ErrorReceivingResponseEvent eventArg) { + fail("This event should not trigger"); + } + }; + + try { + OperationContext.getGlobalErrorReceivingResponseEventHandler().addListener(globalResponseReceivedListener); assertEquals(0, callList.size()); assertEquals(0, globalCallList.size()); @@ -157,8 +155,7 @@ public void eventOccurred(ErrorReceivingResponseEvent eventArg) { assertEquals(2, globalCallList.size()); } finally { - // reset event handler to prevent future tests from failing - OperationContext.setGlobalErrorReceivingResponseEventHandler(new StorageEventMultiCaster>()); + OperationContext.getGlobalErrorReceivingResponseEventHandler().removeListener(globalResponseReceivedListener); } } diff --git a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/StorageAccountTests.java b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/StorageAccountTests.java index cf7de35..7257fcf 100644 --- a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/StorageAccountTests.java +++ b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/StorageAccountTests.java @@ -281,21 +281,406 @@ public void testCloudStorageAccountDefaultStorageAccountWithHttps() throws URISy @Test public void testCloudStorageAccountConnectionStringRoundtrip() throws InvalidKeyException, URISyntaxException { - String accountString1 = String.format("DefaultEndpointsProtocol=http;AccountName=%s;AccountKey=%s", - ACCOUNT_NAME, ACCOUNT_KEY); - - String accountString2 = String.format( - "DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s;QueueEndpoint=%s", ACCOUNT_NAME, - ACCOUNT_KEY, "https://alternate.queue.endpoint/"); + Object[] accountKeyParams = new String[] + { + ACCOUNT_NAME, + ACCOUNT_KEY, + "fake.endpoint.suffix", + "https://primary.endpoint/", + "https://secondary.endpoint/" + }; + + Object[] accountSasParams = new String[] + { + ACCOUNT_NAME, + "sasTest", + "fake.endpoint.suffix", + "https://primary.endpoint/", + "https://secondary.endpoint/" + }; + + // account key + + String accountString1 = + String.format( + "DefaultEndpointsProtocol=http;AccountName=%1$s;AccountKey=%2$s;EndpointSuffix=%3$s;", + accountKeyParams); + + String accountString2 = + String.format( + "DefaultEndpointsProtocol=https;AccountName=%1$s;AccountKey=%2$s;", + accountKeyParams); + + String accountString3 = + String.format( + "DefaultEndpointsProtocol=https;AccountName=%1$s;AccountKey=%2$s;QueueEndpoint=%4$s", + accountKeyParams); + + String accountString4 = + String.format( + "DefaultEndpointsProtocol=https;AccountName=%1$s;AccountKey=%2$s;EndpointSuffix=%3$s;QueueEndpoint=%4$s", + accountKeyParams); connectionStringRoundtripHelper(accountString1); connectionStringRoundtripHelper(accountString2); + connectionStringRoundtripHelper(accountString3); + connectionStringRoundtripHelper(accountString4); + + String accountString5 = + String.format( + "AccountName=%1$s;AccountKey=%2$s;EndpointSuffix=%3$s;", + accountKeyParams); + + String accountString6 = + String.format( + "AccountName=%1$s;AccountKey=%2$s;", + accountKeyParams); + + String accountString7 = + String.format( + "AccountName=%1$s;AccountKey=%2$s;QueueEndpoint=%4$s", + accountKeyParams); + + String accountString8 = + String.format( + "AccountName=%1$s;AccountKey=%2$s;EndpointSuffix=%3$s;QueueEndpoint=%4$s", + accountKeyParams); + + connectionStringRoundtripHelper(accountString5); + connectionStringRoundtripHelper(accountString6); + connectionStringRoundtripHelper(accountString7); + connectionStringRoundtripHelper(accountString8); + + // shared access + + String accountString9 = + String.format( + "DefaultEndpointsProtocol=http;AccountName=%1$s;SharedAccessSignature=%2$s;EndpointSuffix=%3$s;", + accountSasParams); + + String accountString10 = + String.format( + "DefaultEndpointsProtocol=https;AccountName=%1$s;SharedAccessSignature=%2$s;", + accountSasParams); + + String accountString11 = + String.format( + "DefaultEndpointsProtocol=https;AccountName=%1$s;SharedAccessSignature=%2$s;QueueEndpoint=%4$s", + accountSasParams); + + String accountString12 = + String.format( + "DefaultEndpointsProtocol=https;AccountName=%1$s;SharedAccessSignature=%2$s;EndpointSuffix=%3$s;QueueEndpoint=%4$s", + accountSasParams); + + connectionStringRoundtripHelper(accountString9); + connectionStringRoundtripHelper(accountString10); + connectionStringRoundtripHelper(accountString11); + connectionStringRoundtripHelper(accountString12); + + String accountString13 = + String.format( + "AccountName=%1$s;SharedAccessSignature=%2$s;EndpointSuffix=%3$s;", + accountSasParams); + + String accountString14 = + String.format( + "AccountName=%1$s;SharedAccessSignature=%2$s;", + accountSasParams); + + String accountString15 = + String.format( + "AccountName=%1$s;SharedAccessSignature=%2$s;QueueEndpoint=%4$s", + accountSasParams); + + String accountString16 = + String.format( + "AccountName=%1$s;SharedAccessSignature=%2$s;EndpointSuffix=%3$s;QueueEndpoint=%4$s", + accountSasParams); + + connectionStringRoundtripHelper(accountString13); + connectionStringRoundtripHelper(accountString14); + connectionStringRoundtripHelper(accountString15); + connectionStringRoundtripHelper(accountString16); + + // shared access no account name + + String accountString17 = + String.format( + "SharedAccessSignature=%2$s;QueueEndpoint=%4$s", + accountSasParams); + + connectionStringRoundtripHelper(accountString17); + } + + @Test + public void CloudStorageAccountConnectionStringExpectedExceptions() + { + String[][] endpointCombinations = new String[][] + { + new String[] { "BlobEndpoint=%4$s", "BlobSecondaryEndpoint=%5$s", "BlobEndpoint=%4$s;BlobSecondaryEndpoint=%5$s" }, + new String[] { "QueueEndpoint=%4$s", "QueueSecondaryEndpoint=%5$s", "QueueEndpoint=%4$s;QueueSecondaryEndpoint=%5$s" }, + new String[] { "TableEndpoint=%4$s", "TableSecondaryEndpoint=%5$s", "TableEndpoint=%4$s;TableSecondaryEndpoint=%5$s" }, + new String[] { "FileEndpoint=%4$s", "FileSecondaryEndpoint=%5$s", "FileEndpoint=%4$s;FileSecondaryEndpoint=%5$s" } + }; + + Object[] accountKeyParams = new String[] + { + ACCOUNT_NAME, + ACCOUNT_KEY, + "fake.endpoint.suffix", + "https://primary.endpoint/", + "https://secondary.endpoint/" + }; + + Object[] accountSasParams = new String[] + { + ACCOUNT_NAME, + "sasTest", + "fake.endpoint.suffix", + "https://primary.endpoint/", + "https://secondary.endpoint/" + }; + + for (String[] endpointCombination: endpointCombinations) + { + // account key + + String accountStringKeyPrimary = + String.format( + "DefaultEndpointsProtocol=https;AccountName=%1$s;AccountKey=%2$s;EndpointSuffix=%3$s;" + endpointCombination[0], + accountKeyParams + ); + + String accountStringKeySecondary = + String.format( + "DefaultEndpointsProtocol=https;AccountName=%1$s;AccountKey=%2$s;EndpointSuffix=%3$s;" + endpointCombination[1], + accountKeyParams + ); + + String accountStringKeyPrimarySecondary = + String.format( + "DefaultEndpointsProtocol=https;AccountName=%1$s;AccountKey=%2$s;EndpointSuffix=%3$s;" + endpointCombination[2], + accountKeyParams + ); + + try { + CloudStorageAccount.parse(accountStringKeyPrimary); // no exception expected + } catch (Exception e) { + fail("Unexpected exception"); + } + + try { + CloudStorageAccount.parse(accountStringKeySecondary); + fail("Expected exception not thrown"); + } catch (IllegalArgumentException e) { + // pass + } catch (InvalidKeyException e) { + fail("Unexpected exception"); + } catch (URISyntaxException e) { + fail("Unexpected exception"); + } + + try { + CloudStorageAccount.parse(accountStringKeyPrimarySecondary); // no exception expected + } catch (Exception e) { + fail("Unexpected exception"); + } + + // account key, no default protocol + + String accountStringKeyNoDefaultProtocolPrimary = + String.format( + "AccountName=%1$s;AccountKey=%2$s;EndpointSuffix=%3$s;" + endpointCombination[0], + accountKeyParams + ); + + String accountStringKeyNoDefaultProtocolSecondary = + String.format( + "AccountName=%1$s;AccountKey=%2$s;EndpointSuffix=%3$s;" + endpointCombination[1], + accountKeyParams + ); + + String accountStringKeyNoDefaultProtocolPrimarySecondary = + String.format( + "AccountName=%1$s;AccountKey=%2$s;EndpointSuffix=%3$s;" + endpointCombination[2], + accountKeyParams + ); + + try { + CloudStorageAccount.parse(accountStringKeyNoDefaultProtocolPrimary); // no exception expected + } catch (Exception e) { + fail("Unexpected exception"); + } + + try { + CloudStorageAccount.parse(accountStringKeyNoDefaultProtocolSecondary); + fail("Expected exception not thrown"); + } catch (IllegalArgumentException e) { + // pass + } catch (InvalidKeyException e) { + fail("Unexpected exception"); + } catch (URISyntaxException e) { + fail("Unexpected exception"); + } + + try { + CloudStorageAccount.parse(accountStringKeyNoDefaultProtocolPrimarySecondary); // no exception expected + } catch (Exception e) { + fail("Unexpected exception"); + } + + // SAS + + String accountStringSasPrimary = + String.format( + "DefaultEndpointsProtocol=https;AccountName=%1$s;SharedAccessSignature=%2$s;EndpointSuffix=%3$s;" + endpointCombination[0], + accountSasParams + ); + + String accountStringSasSecondary = + String.format( + "DefaultEndpointsProtocol=https;AccountName=%1$s;SharedAccessSignature=%2$s;EndpointSuffix=%3$s;" + endpointCombination[1], + accountSasParams + ); + + String accountStringSasPrimarySecondary = + String.format( + "DefaultEndpointsProtocol=https;AccountName=%1$s;SharedAccessSignature=%2$s;EndpointSuffix=%3$s;" + endpointCombination[2], + accountSasParams + ); + + try { + CloudStorageAccount.parse(accountStringSasPrimary); // no exception expected + } catch (Exception e) { + fail("Unexpected exception"); + } + + try { + CloudStorageAccount.parse(accountStringSasSecondary); + fail("Expected exception not thrown"); + } catch (IllegalArgumentException e) { + // pass + } catch (InvalidKeyException e) { + fail("Unexpected exception"); + } catch (URISyntaxException e) { + fail("Unexpected exception"); + } + + try { + CloudStorageAccount.parse(accountStringSasPrimarySecondary); // no exception expected + } catch (Exception e) { + fail("Unexpected exception"); + } + + // SAS, no default protocol + + String accountStringSasNoDefaultProtocolPrimary = + String.format( + "AccountName=%1$s;SharedAccessSignature=%2$s;EndpointSuffix=%3$s;" + endpointCombination[0], + accountSasParams + ); + + String accountStringSasNoDefaultProtocolSecondary = + String.format( + "AccountName=%1$s;SharedAccessSignature=%2$s;EndpointSuffix=%3$s;" + endpointCombination[1], + accountSasParams + ); + + String accountStringSasNoDefaultProtocolPrimarySecondary = + String.format( + "AccountName=%1$s;SharedAccessSignature=%2$s;EndpointSuffix=%3$s;" + endpointCombination[2], + accountSasParams + ); + + try { + CloudStorageAccount.parse(accountStringSasNoDefaultProtocolPrimary); // no exception expected + } catch (Exception e) { + fail("Unexpected exception"); + } + + try { + CloudStorageAccount.parse(accountStringSasNoDefaultProtocolSecondary); + fail("Expected exception not thrown"); + } catch (IllegalArgumentException e) { + // pass + } catch (InvalidKeyException e) { + fail("Unexpected exception"); + } catch (URISyntaxException e) { + fail("Unexpected exception"); + } + + try { + CloudStorageAccount.parse(accountStringSasNoDefaultProtocolPrimarySecondary); // no exception expected + } catch (Exception e) { + fail("Unexpected exception"); + } + + // SAS without AccountName + + String accountStringSasNoNameNoEndpoint = + String.format( + "SharedAccessSignature=%2$s", + accountSasParams + ); + + String accountStringSasNoNamePrimary = + String.format( + "SharedAccessSignature=%2$s;" + endpointCombination[0], + accountSasParams + ); + + String accountStringSasNoNameSecondary = + String.format( + "SharedAccessSignature=%2$s;" + endpointCombination[1], + accountSasParams + ); + + String accountStringSasNoNamePrimarySecondary = + String.format( + "SharedAccessSignature=%2$s;" + endpointCombination[2], + accountSasParams + ); + + try { + CloudStorageAccount.parse(accountStringSasNoNameNoEndpoint); + fail("Expected exception not thrown"); + } catch (IllegalArgumentException e) { + // pass + } catch (InvalidKeyException e) { + fail("Unexpected exception"); + } catch (URISyntaxException e) { + fail("Unexpected exception"); + } + + try { + CloudStorageAccount.parse(accountStringSasNoNamePrimary); // no exception expected + } catch (Exception e) { + fail("Unexpected exception"); + } + + try { + CloudStorageAccount.parse(accountStringSasNoNameSecondary); + fail("Expected exception not thrown"); + } catch (IllegalArgumentException e) { + // pass + } catch (InvalidKeyException e) { + fail("Unexpected exception"); + } catch (URISyntaxException e) { + fail("Unexpected exception"); + } + + try { + CloudStorageAccount.parse(accountStringSasNoNamePrimarySecondary); // no exception expected + } catch (Exception e) { + fail("Unexpected exception"); + } + } } - + private void connectionStringRoundtripHelper(String accountString) throws InvalidKeyException, URISyntaxException { CloudStorageAccount originalAccount = CloudStorageAccount.parse(accountString); String copiedAccountString = originalAccount.toString(true); - // assertEquals(accountString, copiedAccountString); CloudStorageAccount copiedAccount = CloudStorageAccount.parse(copiedAccountString); // make sure it round trips @@ -393,7 +778,7 @@ public void testCloudStorageAccountDevStoreFalsePlusAccountFails() fail(); } catch (IllegalArgumentException ex) { - assertEquals(SR.INVALID_CONNECTION_STRING_DEV_STORE_NOT_TRUE, ex.getMessage()); + assertEquals(SR.INVALID_CONNECTION_STRING, ex.getMessage()); } } @@ -406,7 +791,7 @@ public void testCloudStorageAccountDevStoreFalsePlusEndpointFails() fail(); } catch (IllegalArgumentException ex) { - assertEquals(SR.INVALID_CONNECTION_STRING_DEV_STORE_NOT_TRUE, ex.getMessage()); + assertEquals(SR.INVALID_CONNECTION_STRING, ex.getMessage()); } } @@ -419,7 +804,7 @@ public void testCloudStorageAccountDevStoreFalsePlusEndpointSuffixFails() fail(); } catch (IllegalArgumentException ex) { - assertEquals(SR.INVALID_CONNECTION_STRING_DEV_STORE_NOT_TRUE, ex.getMessage()); + assertEquals(SR.INVALID_CONNECTION_STRING, ex.getMessage()); } } @@ -503,8 +888,8 @@ public void testCloudStorageAccountDefaultCloudRoundtrip() @Test public void testCloudStorageAccountExplicitCloudRoundtrip() throws InvalidKeyException, URISyntaxException { - String accountString = "EndpointSuffix=a.b.c;BlobEndpoint=https://blobs/;AccountName=test;" - + "AccountKey=abc="; + String accountString = "EndpointSuffix=a.b.c;BlobEndpoint=https://blobs/;DefaultEndpointsProtocol=https;" + + "AccountName=test;AccountKey=abc="; assertEquals(accountString, CloudStorageAccount.parse(accountString).toString(true)); } @@ -540,7 +925,7 @@ public void testCloudStorageAccountEmptyValues() throws InvalidKeyException, URI String accountString = ";EndpointSuffix=a.b.c;;BlobEndpoint=http://blobs/;;" + "AccountName=test;;AccountKey=abc=;;;"; String validAccountString = "EndpointSuffix=a.b.c;BlobEndpoint=http://blobs/;" - + "AccountName=test;AccountKey=abc="; + + "DefaultEndpointsProtocol=http;AccountName=test;AccountKey=abc="; assertEquals(validAccountString, CloudStorageAccount.parse(accountString).toString(true)); } @@ -584,28 +969,28 @@ public void testCloudStorageAccountEndpointSuffix() @Test public void testCloudStorageAccountJustBlobToString() throws InvalidKeyException, URISyntaxException { - String accountString = "BlobEndpoint=http://blobs/;AccountName=test;AccountKey=abc="; + String accountString = "BlobEndpoint=http://blobs/;DefaultEndpointsProtocol=http;AccountName=test;AccountKey=abc="; assertEquals(accountString, CloudStorageAccount.parse(accountString).toString(true)); } @Test public void testCloudStorageAccountJustQueueToString() throws InvalidKeyException, URISyntaxException { - String accountString = "QueueEndpoint=http://queue/;AccountName=test;AccountKey=abc="; + String accountString = "QueueEndpoint=http://queue/;DefaultEndpointsProtocol=https;AccountName=test;AccountKey=abc="; assertEquals(accountString, CloudStorageAccount.parse(accountString).toString(true)); } @Test public void testCloudStorageAccountJustTableToString() throws InvalidKeyException, URISyntaxException { - String accountString = "TableEndpoint=http://table/;AccountName=test;AccountKey=abc="; + String accountString = "TableEndpoint=http://table/;DefaultEndpointsProtocol=https;AccountName=test;AccountKey=abc="; assertEquals(accountString, CloudStorageAccount.parse(accountString).toString(true)); } @Test public void testCloudStorageAccountJustFileToString() throws InvalidKeyException, URISyntaxException { - String accountString = "FileEndpoint=http://file/;AccountName=test;AccountKey=abc="; + String accountString = "FileEndpoint=http://file/;DefaultEndpointsProtocol=https;AccountName=test;AccountKey=abc="; assertEquals(accountString, CloudStorageAccount.parse(accountString).toString(true)); } 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 77db677..114533a 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 @@ -27,6 +27,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.*; @@ -62,9 +64,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(); @@ -101,7 +102,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) { @@ -111,4 +112,51 @@ 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()); + try { + 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); + } + finally + { + share.deleteIfExists(DeleteShareSnapshotsOption.INCLUDE_SNAPSHOTS, null, null, null); + } + } } \ 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 da5373b..0a42f00 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 @@ -26,6 +26,7 @@ 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 junit.framework.Assert; @@ -39,6 +40,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; +import java.util.HashMap; import static org.junit.Assert.*; @@ -58,7 +60,7 @@ public void cloudFileDirectorySetUp() throws URISyntaxException, StorageExceptio @After public void cloudFileDirectoryTearDown() throws StorageException { - this.share.deleteIfExists(); + this.share.deleteIfExists(DeleteShareSnapshotsOption.INCLUDE_SNAPSHOTS, null, null, null); } /** @@ -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")] @@ -798,7 +865,7 @@ public void eventOccurred(SendingRequestEvent eventArg) { directory.delete(); assertFalse(directory.exists()); } - catch (StorageException e) { + catch (Exception 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 49df9d4..0b828aa 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,12 +25,14 @@ 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.Before; 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; @@ -59,7 +61,7 @@ public void fileShareTestMethodSetUp() throws StorageException, URISyntaxExcepti @After public void fileShareTestMethodTearDown() throws StorageException { - this.share.deleteIfExists(); + this.share.deleteIfExists(DeleteShareSnapshotsOption.INCLUDE_SNAPSHOTS, null, null, null); } /** @@ -314,7 +316,7 @@ public void testCloudFileShareUploadMetadata() throws StorageException, URISynta 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) { assertEquals(2, share3.getMetadata().size()); @@ -489,6 +491,189 @@ 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()); + 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 { + 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 e30bcdb..0fb35a0 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 @@ -36,6 +36,8 @@ import com.microsoft.azure.storage.blob.SharedAccessBlobPermissions; import com.microsoft.azure.storage.blob.SharedAccessBlobPolicy; import com.microsoft.azure.storage.core.Base64; +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; @@ -47,6 +49,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; @@ -81,7 +84,7 @@ public void fileTestMethodSetUp() throws URISyntaxException, StorageException { @After public void fileTestMethodTearDown() throws StorageException { - this.share.deleteIfExists(); + this.share.deleteIfExists(DeleteShareSnapshotsOption.INCLUDE_SNAPSHOTS, null, null, null); } /** @@ -1021,7 +1024,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"); @@ -1396,7 +1399,7 @@ public void eventOccurred(SendingRequestEvent eventArg) { file.delete(); assertFalse(file.exists()); } - catch (StorageException e) { + catch (Exception e) { fail("Delete should succeed."); } } @@ -1436,6 +1439,26 @@ public void testFileNamePlusEncoding() throws StorageException, URISyntaxExcepti assertEquals(prop1.getContentMD5(), prop2.getContentMD5()); assertEquals(prop1.getContentType(), prop2.getContentType()); } + + @Test + @Category({ DevFabricTests.class, DevStoreTests.class }) + public void testFileGetRangeContentMD5Bounds() throws StorageException, IOException, URISyntaxException { + { + CloudFile file = FileTestHelper.uploadNewFile(this.share, 5 * Constants.MB, null); + + FileRequestOptions options = new FileRequestOptions(); + OperationContext opContext = new OperationContext(); + try { + 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) + { + assertEquals(e.getMessage(), String.format("The value of the parameter 'count' should be between 1 and %1d.", Constants.MAX_BLOCK_SIZE)); + } + } + } private CloudFile doCloudBlobCopy(CloudBlob source, int length) throws Exception { Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); @@ -1580,4 +1603,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 df469d7..44feb8f 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 @@ -96,7 +96,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); @@ -118,7 +118,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); @@ -152,7 +152,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/AndroidManifest.xml b/microsoft-azure-storage/AndroidManifest.xml index 8b9f543..9a4e4b0 100644 --- a/microsoft-azure-storage/AndroidManifest.xml +++ b/microsoft-azure-storage/AndroidManifest.xml @@ -11,7 +11,7 @@ diff --git a/microsoft-azure-storage/pom.xml b/microsoft-azure-storage/pom.xml index 9f225d6..1fbe65a 100644 --- a/microsoft-azure-storage/pom.xml +++ b/microsoft-azure-storage/pom.xml @@ -10,7 +10,7 @@ 4.0.0 com.microsoft.azure.android azure-storage-android - 1.2.0 + 2.0.0 aar Microsoft Azure Storage Android Client SDK diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/CloudStorageAccount.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/CloudStorageAccount.java index 1d62a34..a03fd55 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/CloudStorageAccount.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/CloudStorageAccount.java @@ -18,6 +18,7 @@ import java.net.URISyntaxException; import java.security.InvalidKeyException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -75,6 +76,11 @@ public final class CloudStorageAccount { */ protected static final String BLOB_ENDPOINT_NAME = "BlobEndpoint"; + /** + * Represents the setting name for a custom blob storage secondary endpoint. + */ + protected static final String BLOB_SECONDARY_ENDPOINT_NAME = "BlobSecondaryEndpoint"; + /** * The setting name for using the default storage endpoints with the specified protocol. */ @@ -111,6 +117,11 @@ public final class CloudStorageAccount { */ private static final String FILE_ENDPOINT_NAME = "FileEndpoint"; + /** + * Represents the setting name for a custom file secondary endpoint. + */ + private static final String FILE_SECONDARY_ENDPOINT_NAME = "FileSecondaryEndpoint"; + /** * The format string for the primary endpoint. */ @@ -126,6 +137,11 @@ public final class CloudStorageAccount { */ protected static final String QUEUE_ENDPOINT_NAME = "QueueEndpoint"; + /** + * Represents the setting name for a custom queue secondary endpoint. + */ + protected static final String QUEUE_SECONDARY_ENDPOINT_NAME = "QueueSecondaryEndpoint"; + /** * Represents the setting name for a shared access key. */ @@ -136,6 +152,11 @@ public final class CloudStorageAccount { */ protected static final String TABLE_ENDPOINT_NAME = "TableEndpoint"; + /** + * Represents the setting name for a custom table storage secondary endpoint. + */ + protected static final String TABLE_SECONDARY_ENDPOINT_NAME = "TableSecondaryEndpoint"; + /** * The setting name for using the development storage. */ @@ -272,29 +293,31 @@ public static CloudStorageAccount parse(final String connectionString) throws UR * the connection settings. * @param service * A String that represents the service's base DNS name. - * @param serviceEndpoint + * @param serviceEndpointName * The service endpoint name to check in settings. + * @param serviceSecondaryEndpointName + * The service secondary endpoint name to check in settings. + * @param matchesAutomaticEndpointsSpec + * Whether the settings match the automatic endpoints specification. * @return The {@link StorageUri}. * @throws URISyntaxException */ private static StorageUri getStorageUri( - final Map settings, final String service, final String serviceEndpoint) + final Map settings, final String service, final String serviceEndpointName, final String serviceSecondaryEndpointName, final Boolean matchesAutomaticEndpointsSpec) throws URISyntaxException { - // Explicit Endpoint Case - if (settings.containsKey(serviceEndpoint)) { - return new StorageUri(new URI(settings.get(serviceEndpoint))); - } - // Automatic Endpoint Case - else if (settings.containsKey(DEFAULT_ENDPOINTS_PROTOCOL_NAME) && - settings.containsKey(CloudStorageAccount.ACCOUNT_NAME_NAME) && - settings.containsKey(CloudStorageAccount.ACCOUNT_KEY_NAME)) { + String serviceEndpoint = settingOrDefault(settings, serviceEndpointName); + String serviceSecondaryEndpoint = settingOrDefault(settings, serviceSecondaryEndpointName); + + if (serviceSecondaryEndpoint != null && serviceEndpoint != null) { + return new StorageUri(new URI(serviceEndpoint), new URI(serviceSecondaryEndpoint)); + } else if (serviceEndpoint != null) { + return new StorageUri(new URI(serviceEndpoint)); + } else if (matchesAutomaticEndpointsSpec) { final String scheme = settings.get(CloudStorageAccount.DEFAULT_ENDPOINTS_PROTOCOL_NAME); final String accountName = settings.get(CloudStorageAccount.ACCOUNT_NAME_NAME); final String endpointSuffix = settings.get(CloudStorageAccount.ENDPOINT_SUFFIX_NAME); return getDefaultStorageUri(scheme, accountName, getDNS(service, endpointSuffix)); - } - // Otherwise - else { + } else { return null; } } @@ -356,23 +379,199 @@ private static String getDNS(String service, String base) { */ private static CloudStorageAccount tryConfigureDevStore(final Map settings) throws URISyntaxException { - if (settings.containsKey(USE_DEVELOPMENT_STORAGE_NAME)) { + if (matchesSpecification( + settings, + allRequired(USE_DEVELOPMENT_STORAGE_NAME), + optional(DEVELOPMENT_STORAGE_PROXY_URI_NAME))) { if (!Boolean.parseBoolean(settings.get(USE_DEVELOPMENT_STORAGE_NAME))) { throw new IllegalArgumentException(SR.INVALID_CONNECTION_STRING_DEV_STORE_NOT_TRUE); } URI devStoreProxyUri = null; + if (settings.containsKey(DEVELOPMENT_STORAGE_PROXY_URI_NAME)) { devStoreProxyUri = new URI(settings.get(DEVELOPMENT_STORAGE_PROXY_URI_NAME)); } return getDevelopmentStorageAccount(devStoreProxyUri); - } - else { + } else { return null; } } + private interface ConnectionStringFilter { + Map apply(Map settings); + } + + private static ConnectionStringFilter allRequired(final String... settingNames) { + return new ConnectionStringFilter() { + @Override + public Map apply(Map settings) { + final Map result = new HashMap(settings); + + for (final String settingName : settingNames) { + if (result.containsKey(settingName)) { + result.remove(settingName); + } else { + return null; + } + } + + return result; + } + }; + } + + private static ConnectionStringFilter optional(final String... settingNames) { + return new ConnectionStringFilter() { + @Override + public Map apply(Map settings) { + final Map result = new HashMap(settings); + + for (final String settingName : settingNames) { + if (result.containsKey(settingName)) { + result.remove(settingName); + } + } + + return result; + } + }; + } + + private static ConnectionStringFilter atLeastOne(final String... settingNames) { + return new ConnectionStringFilter() { + @Override + public Map apply(Map settings) { + final Map result = new HashMap(settings); + Boolean foundOne = false; + + for (final String settingName : settingNames) { + if (result.containsKey(settingName)) { + result.remove(settingName); + foundOne = true; + } + } + + return foundOne ? result : null; + } + }; + } + + private static ConnectionStringFilter none(final String... settingNames) { + return new ConnectionStringFilter() { + @Override + public Map apply(Map settings) { + final Map result = new HashMap(settings); + Boolean foundOne = false; + + for (final String settingName : settingNames) { + if (result.containsKey(settingName)) { + result.remove(settingName); + foundOne = true; + } + } + + return foundOne ? null : result; + } + }; + } + + private static ConnectionStringFilter matchesAll(final ConnectionStringFilter... filters) { + return new ConnectionStringFilter() { + @Override + public Map apply(Map settings) { + Map result = new HashMap(settings); + + for (final ConnectionStringFilter filter : filters) { + if (result == null) { + break; + } + + result = filter.apply(result); + } + + return result; + } + }; + } + + private static ConnectionStringFilter matchesOne(final ConnectionStringFilter... filters) { + return new ConnectionStringFilter() { + @Override + public Map apply(Map settings) { + Map matchResult = null; + + for (final ConnectionStringFilter filter : filters) { + Map result = filter.apply(new HashMap(settings)); + + if (result != null) { + if (matchResult == null) { + matchResult = result; + } else { + return null; + } + } + } + + return matchResult; + } + }; + } + + private static ConnectionStringFilter matchesExactly(final ConnectionStringFilter filter) { + return new ConnectionStringFilter() { + @Override + public Map apply(Map settings) { + Map result = new HashMap(settings); + + result = filter.apply(result); + + if (result == null || !result.isEmpty()) { + return null; + } else { + return result; + } + } + }; + } + + private static ConnectionStringFilter validCredentials = + matchesOne( + matchesAll(allRequired(ACCOUNT_NAME_NAME, ACCOUNT_KEY_NAME), none(SHARED_ACCESS_SIGNATURE_NAME)), + matchesAll(allRequired(SHARED_ACCESS_SIGNATURE_NAME), optional(ACCOUNT_NAME_NAME), none(ACCOUNT_KEY_NAME)), + none(ACCOUNT_NAME_NAME, ACCOUNT_KEY_NAME, SHARED_ACCESS_SIGNATURE_NAME) + ); + + + private static Boolean matchesSpecification( + Map settings, + ConnectionStringFilter... constraints) { + for (ConnectionStringFilter constraint: constraints) { + Map remainingSettings = constraint.apply(settings); + + if (remainingSettings == null) { + return false; + } else { + settings = remainingSettings; + } + } + + if (settings.isEmpty()) { + return true; + } + + return false; + } + + private static Boolean isValidEndpointPair(String primary, String secondary) { + return (primary != null) || (/* primary is null, and... */ secondary == null); + } + + private static String settingOrDefault(Map settings, String key) { + return settings.containsKey(key) ? settings.get(key) : null; + } + /** * Evaluates connection settings and configures a CloudStorageAccount accordingly. * @@ -387,50 +586,97 @@ private static CloudStorageAccount tryConfigureDevStore(final Map settings) throws URISyntaxException, InvalidKeyException { - if (settings.containsKey(USE_DEVELOPMENT_STORAGE_NAME)) { - if (!Boolean.parseBoolean(settings.get(USE_DEVELOPMENT_STORAGE_NAME))) { - throw new IllegalArgumentException(SR.INVALID_CONNECTION_STRING_DEV_STORE_NOT_TRUE); - } - else { - return null; - } - } - String defaultEndpointSetting = settings.get(DEFAULT_ENDPOINTS_PROTOCOL_NAME); - if (defaultEndpointSetting != null) { - defaultEndpointSetting = defaultEndpointSetting.toLowerCase(); - if(!defaultEndpointSetting.equals(Constants.HTTP) - && !defaultEndpointSetting.equals(Constants.HTTPS)) { - return null; + ConnectionStringFilter endpointsOptional = + optional( + BLOB_ENDPOINT_NAME, BLOB_SECONDARY_ENDPOINT_NAME, + QUEUE_ENDPOINT_NAME, QUEUE_SECONDARY_ENDPOINT_NAME, + TABLE_ENDPOINT_NAME, TABLE_SECONDARY_ENDPOINT_NAME, + FILE_ENDPOINT_NAME, FILE_SECONDARY_ENDPOINT_NAME + ); + + ConnectionStringFilter primaryEndpointRequired = + atLeastOne( + BLOB_ENDPOINT_NAME, + QUEUE_ENDPOINT_NAME, + TABLE_ENDPOINT_NAME, + FILE_ENDPOINT_NAME + ); + + ConnectionStringFilter secondaryEndpointsOptional = + optional( + BLOB_SECONDARY_ENDPOINT_NAME, + QUEUE_SECONDARY_ENDPOINT_NAME, + TABLE_SECONDARY_ENDPOINT_NAME, + FILE_SECONDARY_ENDPOINT_NAME + ); + + ConnectionStringFilter automaticEndpointsMatchSpec = + matchesExactly(matchesAll( + matchesOne( + matchesAll(allRequired(ACCOUNT_KEY_NAME)), // Key + Name, Endpoints optional + allRequired(SHARED_ACCESS_SIGNATURE_NAME) // SAS + Name, Endpoints optional + ), + allRequired(ACCOUNT_NAME_NAME), // Name required to automatically create URIs + endpointsOptional, + optional(DEFAULT_ENDPOINTS_PROTOCOL_NAME, ENDPOINT_SUFFIX_NAME) + )); + + ConnectionStringFilter explicitEndpointsMatchSpec = + matchesExactly(matchesAll( // Any Credentials, Endpoints must be explicitly declared + validCredentials, + primaryEndpointRequired, + secondaryEndpointsOptional + )); + + Boolean matchesAutomaticEndpointsSpec = matchesSpecification(settings, automaticEndpointsMatchSpec); + Boolean matchesExplicitEndpointsSpec = matchesSpecification(settings, explicitEndpointsMatchSpec); + + if (matchesAutomaticEndpointsSpec || matchesExplicitEndpointsSpec) { + if (matchesAutomaticEndpointsSpec && !settings.containsKey(DEFAULT_ENDPOINTS_PROTOCOL_NAME)) { + settings.put(DEFAULT_ENDPOINTS_PROTOCOL_NAME, "https"); } - } - final StorageCredentials credentials = StorageCredentials.tryParseCredentials(settings); - final CloudStorageAccount account = new CloudStorageAccount(credentials, - getStorageUri(settings, SR.BLOB, BLOB_ENDPOINT_NAME), - getStorageUri(settings, SR.QUEUE, QUEUE_ENDPOINT_NAME), - getStorageUri(settings, SR.TABLE, TABLE_ENDPOINT_NAME), - getStorageUri(settings, SR.FILE, FILE_ENDPOINT_NAME)); - - // Invalid Account String - if ((account.getBlobEndpoint() == null) && (account.getFileEndpoint() == null) && - (account.getQueueEndpoint() == null) && (account.getTableEndpoint() == null)) { - return null; + String blobEndpoint = settingOrDefault(settings, BLOB_ENDPOINT_NAME); + String queueEndpoint = settingOrDefault(settings, QUEUE_ENDPOINT_NAME); + String tableEndpoint = settingOrDefault(settings, TABLE_ENDPOINT_NAME); + String fileEndpoint = settingOrDefault(settings, FILE_ENDPOINT_NAME); + String blobSecondaryEndpoint = settingOrDefault(settings, BLOB_SECONDARY_ENDPOINT_NAME); + String queueSecondaryEndpoint = settingOrDefault(settings, QUEUE_SECONDARY_ENDPOINT_NAME); + String tableSecondaryEndpoint = settingOrDefault(settings, TABLE_SECONDARY_ENDPOINT_NAME); + String fileSecondaryEndpoint = settingOrDefault(settings, FILE_SECONDARY_ENDPOINT_NAME); + + // if secondary is specified, primary must also be specified + + if ( + isValidEndpointPair(blobEndpoint, blobSecondaryEndpoint) + && isValidEndpointPair(queueEndpoint, queueSecondaryEndpoint) + && isValidEndpointPair(tableEndpoint, tableSecondaryEndpoint) + && isValidEndpointPair(fileEndpoint, fileSecondaryEndpoint) + ) { + CloudStorageAccount accountInformation = + new CloudStorageAccount( + StorageCredentials.tryParseCredentials(settings), + getStorageUri(settings, SR.BLOB, BLOB_ENDPOINT_NAME, BLOB_SECONDARY_ENDPOINT_NAME, matchesAutomaticEndpointsSpec), + getStorageUri(settings, SR.QUEUE, QUEUE_ENDPOINT_NAME, QUEUE_SECONDARY_ENDPOINT_NAME, matchesAutomaticEndpointsSpec), + getStorageUri(settings, SR.TABLE, TABLE_ENDPOINT_NAME, TABLE_SECONDARY_ENDPOINT_NAME, matchesAutomaticEndpointsSpec), + getStorageUri(settings, SR.FILE, FILE_ENDPOINT_NAME, FILE_SECONDARY_ENDPOINT_NAME, matchesAutomaticEndpointsSpec) + ); + + accountInformation.isBlobEndpointDefault = blobEndpoint == null; + accountInformation.isFileEndpointDefault = fileEndpoint == null; + accountInformation.isQueueEndpointDefault = queueEndpoint == null; + accountInformation.isTableEndpointDefault = tableEndpoint == null; + + accountInformation.endpointSuffix = settingOrDefault(settings, ENDPOINT_SUFFIX_NAME); + + accountInformation.accountName = settingOrDefault(settings, ACCOUNT_NAME_NAME); + + return accountInformation; + } } - // Endpoint is only default if it is neither null nor explicitly specified - account.isBlobEndpointDefault = !((account.getBlobEndpoint() == null) || - settings.containsKey(CloudStorageAccount.BLOB_ENDPOINT_NAME)); - account.isFileEndpointDefault = !((account.getFileEndpoint() == null) || - settings.containsKey(CloudStorageAccount.FILE_ENDPOINT_NAME)); - account.isQueueEndpointDefault = !((account.getQueueEndpoint() == null) || - settings.containsKey(CloudStorageAccount.QUEUE_ENDPOINT_NAME)); - account.isTableEndpointDefault = !((account.getTableEndpoint() == null) || - settings.containsKey(CloudStorageAccount.TABLE_ENDPOINT_NAME)); - - account.endpointSuffix = settings.get(CloudStorageAccount.ENDPOINT_SUFFIX_NAME); - - return account; + return null; } @@ -463,7 +709,12 @@ private static CloudStorageAccount tryConfigureServiceAccount(final Map values = new ArrayList(); + if (this.isDevStoreAccount) { values.add(String.format("%s=true", USE_DEVELOPMENT_STORAGE_NAME)); if (!this.getBlobEndpoint().toString().equals("http://127.0.0.1:10000/devstoreaccount1")) { @@ -1091,6 +1339,10 @@ public String toString(final boolean exportSecrets) { if (this.getCredentials() != null) { values.add(this.getCredentials().toString(exportSecrets)); } + + if (this.accountName != null && (this.getCredentials() != null ? this.getCredentials().getAccountName() == null : true)) { + values.add(String.format(attributeFormat, ACCOUNT_NAME_NAME, this.accountName)); + } } final StringBuilder returnString = new StringBuilder(); 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 db0d8c0..c1c5b87 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/Constants.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/Constants.java @@ -439,6 +439,11 @@ 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 @@ -595,7 +600,7 @@ public static class HeaderConstants { /** * Specifies the value to use for UserAgent header. */ - public static final String USER_AGENT_VERSION = "1.2.0"; + public static final String USER_AGENT_VERSION = "2.0.0"; /** * The default type for content-type and accept @@ -747,6 +752,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/ServicePropertiesHandler.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/ServicePropertiesHandler.java index 44ce349..ec370d5 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/ServicePropertiesHandler.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/ServicePropertiesHandler.java @@ -58,7 +58,7 @@ public static ServiceProperties readServicePropertiesFromStream(final InputStrea IOException, ParserConfigurationException { SAXParser saxParser = Utility.getSAXParser(); ServicePropertiesHandler handler = new ServicePropertiesHandler(); - handler.props.setCors(null); + handler.props.setLogging(null); handler.props.setHourMetrics(null); handler.props.setMinuteMetrics(null); handler.props.setCors(null); diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageCredentials.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageCredentials.java index 3b65558..bb6b8d9 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageCredentials.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageCredentials.java @@ -68,7 +68,7 @@ protected static StorageCredentials tryParseCredentials(final Mapjava.io.IOException object that represents the created IO exception. */ public static IOException initIOException(final Exception ex) { - final IOException retEx = new IOException(); - retEx.initCause(ex); + String message = null; + if (ex != null && ex.getMessage() != null) { + message = ex.getMessage() + " Please see the cause for further information."; + } + else { + message = "Please see the cause for further information."; + } + + final IOException retEx = new IOException(message, ex); return retEx; } 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 48b5ec8..f621716 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 @@ -155,8 +155,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); } @@ -171,8 +172,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); } @@ -230,9 +232,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 */); } @@ -254,14 +257,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); @@ -427,9 +433,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 */); } @@ -457,16 +464,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); @@ -535,9 +545,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 */); } @@ -564,14 +575,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); @@ -588,9 +602,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 */); } @@ -613,15 +628,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), @@ -674,9 +692,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 */); } @@ -696,14 +715,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); @@ -718,10 +740,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 */); } @@ -743,11 +766,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) { @@ -1266,7 +1291,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 @@ -1333,7 +1358,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())); } @@ -1508,7 +1533,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 @@ -1605,7 +1630,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 @@ -1827,9 +1852,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 */); } @@ -1853,10 +1879,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 */, accessCondition, options, opContext); } @@ -1875,9 +1902,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 */); } @@ -1907,10 +1935,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); } @@ -1937,13 +1966,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) { @@ -1978,9 +2010,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 */); } @@ -2007,10 +2040,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(); @@ -2025,8 +2059,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 */); } @@ -2049,9 +2084,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)); @@ -2069,8 +2105,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 */); } @@ -2097,9 +2134,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); } @@ -2119,10 +2157,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 */); } @@ -2151,15 +2190,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); @@ -2288,9 +2330,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 */); } @@ -2314,15 +2357,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); @@ -2379,9 +2425,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 */); } @@ -2404,14 +2451,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); @@ -2464,8 +2514,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 */); } @@ -2487,13 +2538,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); @@ -2549,9 +2603,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 */); } @@ -2579,14 +2634,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) { @@ -2675,9 +2733,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()) { @@ -2702,6 +2761,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) { 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 f5bac52..078c008 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 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 ( @@ -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 3337a71..d2ebac8 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 @@ -95,8 +95,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)); } @@ -106,8 +107,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); } @@ -120,9 +122,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); } @@ -135,9 +138,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); } @@ -168,9 +172,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 */); } @@ -188,13 +193,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); @@ -252,9 +260,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 */); } @@ -274,11 +283,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; @@ -305,9 +317,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 */); } @@ -327,14 +340,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); @@ -380,9 +396,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 */); } @@ -404,10 +421,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); @@ -500,7 +518,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 @@ -514,6 +532,13 @@ public Boolean preProcessResponse(CloudFileDirectory directory, CloudFileClient 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) { @@ -548,9 +573,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 */); } @@ -570,14 +596,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); @@ -682,7 +711,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 @@ -903,7 +932,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 @@ -1138,9 +1167,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()) { @@ -1165,6 +1195,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 318b949..3600287 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 @@ -76,6 +76,11 @@ public final class CloudFileShare { */ private StorageUri storageUri; + /** + * Holds the snapshot ID. + */ + String snapshotID; + /** * Holds a reference to the associated service client. */ @@ -102,13 +107,14 @@ public final class CloudFileShare { * @see Naming and Referencing Shares, * Directories, Files, and Metadata */ - protected CloudFileShare(final String shareName, final CloudFileClient client) throws URISyntaxException, + public 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; } @@ -145,6 +151,8 @@ 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. @@ -200,6 +208,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); @@ -340,6 +353,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(); } @@ -347,12 +390,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()) { @@ -361,7 +404,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 @@ -419,6 +462,39 @@ 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); @@ -499,7 +575,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 @@ -567,6 +643,8 @@ public FileSharePermissions downloadPermissions(AccessCondition accessCondition, opContext = new OperationContext(); } + assertNoSnapshot(); + opContext.initialize(); options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); @@ -626,6 +704,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); + + snapshot.updatePropertiesFromResponse(this.getConnection()); + + return snapshot; + } + }; + + return putRequest; + } + /** * Queries the service for this share's {@link ShareStats}. * @@ -662,6 +870,8 @@ public ShareStats getStats(FileRequestOptions options, OperationContext opContex opContext = new OperationContext(); } + assertNoSnapshot(); + opContext.initialize(); options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient); @@ -781,7 +991,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 @@ -795,6 +1005,11 @@ public Boolean preProcessResponse(CloudFileShare share, CloudFileClient client, 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) { @@ -824,6 +1039,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 "?". * @@ -931,6 +1155,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(); } @@ -1019,6 +1245,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(); } @@ -1100,6 +1332,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(); } @@ -1200,7 +1434,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); @@ -1237,6 +1478,26 @@ 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. + * + * @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. * @@ -1246,6 +1507,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. * @@ -1293,7 +1572,7 @@ public void setMetadata(final HashMap metadata) { * A {@link FileShareProperties} object that represents the properties being assigned to the * share. */ - protected void setProperties(final FileShareProperties properties) { + public void setProperties(final FileShareProperties properties) { this.properties = properties; } 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 0000000..d6bce51 --- /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 f768db8..ee8816f 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())); } @@ -287,7 +291,13 @@ public Void call() { FileOutputStream.this.streamFaulted = true; FileOutputStream.this.lastError = Utility.initIOException(e); } + } catch (URISyntaxException e) { + synchronized (FileOutputStream.this.lastErrorLock) { + FileOutputStream.this.streamFaulted = true; + FileOutputStream.this.lastError = Utility.initIOException(e); + } } + return 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 c119ce8..8edfd9a 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,10 @@ 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); } /** @@ -438,10 +476,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 +508,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 +601,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 +637,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 +647,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 +804,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 +832,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 +841,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 +1167,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 a7ce697..fe9a009 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 @@ -209,6 +209,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 c5e29c6..b658733 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 @@ -39,6 +39,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. *

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 c73693d..3d3b9b9 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 b9b54dd..14bb2c0 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,11 @@ * Specifies which details to include when listing the shares in this storage account. */ public enum ShareListingDetails { + /** - * Specifies including all available details. + * Specifies including no additional details. */ - ALL(1), + NONE(0), /** * Specifies including share metadata. @@ -29,9 +30,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 f2fc333c1a94ca67df395164410331b56888a74b Mon Sep 17 00:00:00 2001 From: Josh Friedman Date: Tue, 10 Oct 2017 15:21:43 -0700 Subject: [PATCH 2/4] Passing delete snapshots option to DeleteIfExists --- .../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 3600287..da4f67b 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 @@ -500,7 +500,7 @@ public boolean deleteIfExists(DeleteShareSnapshotsOption deleteSnapshotsOption, 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) { From 981072a37f6871ac43d70476b6671097a52d0895 Mon Sep 17 00:00:00 2001 From: Josh Friedman Date: Wed, 11 Oct 2017 10:55:01 -0700 Subject: [PATCH 3/4] Fix proxy test --- .../src/com/microsoft/azure/storage/GenericTests.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/GenericTests.java b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/GenericTests.java index 3d9aab5..907b6b3 100644 --- a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/GenericTests.java +++ b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/GenericTests.java @@ -42,6 +42,7 @@ import java.net.HttpURLConnection; import java.net.InetSocketAddress; import java.net.Proxy; +import java.net.SocketException; import java.net.SocketTimeoutException; import java.net.URISyntaxException; import java.text.ParseException; @@ -141,7 +142,8 @@ public void testProxy() throws URISyntaxException, StorageException { fail("Bad proxy should throw an exception."); } catch (StorageException e) { if (e.getCause().getClass() != ConnectException.class && - e.getCause().getClass() != SocketTimeoutException.class) { + e.getCause().getClass() != SocketTimeoutException.class && + e.getCause().getClass() != SocketException.class) { Assert.fail("Unepected exception for bad proxy"); } } @@ -167,7 +169,8 @@ public void testDefaultProxy() throws URISyntaxException, StorageException { fail("Bad proxy should throw an exception."); } catch (StorageException e) { if (e.getCause().getClass() != ConnectException.class && - e.getCause().getClass() != SocketTimeoutException.class) { + e.getCause().getClass() != SocketTimeoutException.class && + e.getCause().getClass() != SocketException.class) { Assert.fail("Unepected exception for bad proxy"); } } From 9a2e2155f32b1b0772e9371eb67d953e83e454c8 Mon Sep 17 00:00:00 2001 From: Josh Friedman Date: Wed, 11 Oct 2017 15:43:40 -0700 Subject: [PATCH 4/4] Setting changelog date --- ChangeLog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index f01b649..e946a2e 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,4 +1,4 @@ -2017.XX.XX Version 2.0.0 +2017.10.11 Version 2.0.0 * Added support for taking a snapshot of a share. * IOExceptions wrapping StorageExceptions will now contain the StorageException message in the outer exception. * Connection string support expanded to allow AccountName to be specified with SharedAccessSignature and DefaultEndpointsProtocol. In this case, SharedAccessSignature is used for credentials, while having both DefaultEndpointsProtocol and AccountName allows the library to infer a set of default endpoints. Additionally, we have added support for BlobSecondaryEndpoint, QueueSecondaryEndpoint, TableSecondaryEndpoint, and FileSecondaryEndpoint. Specifying a secondary endpoint requires the specification of the corresponding primary.