From 755085f25d8096661bf09852bb2b620fede5a911 Mon Sep 17 00:00:00 2001 From: JinmingHu Date: Fri, 21 Aug 2020 09:29:26 +0800 Subject: [PATCH] GetBlobServiceStatistics (#496) --- sdk/storage/inc/blobs/blob_service_client.hpp | 43 ++++++++++--------- sdk/storage/src/blobs/blob_service_client.cpp | 8 ++++ .../test/blobs/blob_service_client_test.cpp | 24 +++++++++++ 3 files changed, 55 insertions(+), 20 deletions(-) diff --git a/sdk/storage/inc/blobs/blob_service_client.hpp b/sdk/storage/inc/blobs/blob_service_client.hpp index 4598d221e..88ddec281 100644 --- a/sdk/storage/inc/blobs/blob_service_client.hpp +++ b/sdk/storage/inc/blobs/blob_service_client.hpp @@ -37,12 +37,10 @@ namespace Azure { namespace Storage { namespace Blobs { /** * @brief Initialize a new instance of BlobServiceClient. * - * @param serviceUri A uri - * referencing the blob that includes the name of the account. - * @param credential The shared key credential used to sign - * requests. - * @param options Optional client options that define the transport pipeline - * policies for authentication, retries, etc., that are applied to every request. + * @param serviceUri A uri referencing the blob that includes the name of the account. + * @param credential The shared key credential used to sign requests. + * @param options Optional client options that define the transport pipeline policies for + * authentication, retries, etc., that are applied to every request. */ explicit BlobServiceClient( const std::string& serviceUri, @@ -52,8 +50,7 @@ namespace Azure { namespace Storage { namespace Blobs { /** * @brief Initialize a new instance of BlobServiceClient. * - * @param serviceUri A uri - * referencing the blob that includes the name of the account. + * @param serviceUri A uri referencing the blob that includes the name of the account. * @param credential The token credential used to sign requests. * @param options Optional client options that define the transport pipeline policies for * authentication, retries, etc., that are applied to every request. @@ -66,11 +63,10 @@ namespace Azure { namespace Storage { namespace Blobs { /** * @brief Initialize a new instance of BlobServiceClient. * - * @param serviceUri A uri - * referencing the blob that includes the name of the account, and possibly also a SAS token. - * @param options Optional client - * options that define the transport pipeline policies for authentication, retries, etc., that - * are applied to every request. + * @param serviceUri A uri referencing the blob that includes the name of the account, and + * possibly also a SAS token. + * @param options Optional client options that define the transport pipeline policies for + * authentication, retries, etc., that are applied to every request. */ explicit BlobServiceClient( const std::string& serviceUri, @@ -80,7 +76,6 @@ namespace Azure { namespace Storage { namespace Blobs { * @brief Creates a new BlobContainerClient object with the same uri as this BlobServiceClient. * The new BlobContainerClient uses the same request policy pipeline as this BlobServiceClient. * - * * @return A new BlobContainerClient instance. */ BlobContainerClient GetBlobContainerClient(const std::string& containerName) const; @@ -88,8 +83,7 @@ namespace Azure { namespace Storage { namespace Blobs { /** * @brief Gets the blob service's primary uri endpoint. * - * @return the blob - * service's primary uri endpoint. + * @return the blob service's primary uri endpoint. */ std::string GetUri() const { return m_serviceUrl.ToString(); } @@ -115,8 +109,7 @@ namespace Azure { namespace Storage { namespace Blobs { * specified in UTC. * @param expiresOn Expiration of the key's validity, in ISO date format. The time should be * specified in UTC. - * @param options Optional parameters to execute - * this function. + * @param options Optional parameters to execute this function. * @return A deserialized GetUserDelegationKeyResult instance. */ Azure::Core::Response GetUserDelegationKey( @@ -132,8 +125,7 @@ namespace Azure { namespace Storage { namespace Blobs { * * @param * properties The blob service properties. - * @param options Optional parameters to execute - * this function. + * @param options Optional parameters to execute this function. * @return A SetServicePropertiesResult on successfully setting the properties. */ Azure::Core::Response SetProperties( @@ -159,6 +151,17 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Response GetAccountInfo( const GetAccountInfoOptions& options = GetAccountInfoOptions()) const; + /** + * @brief Retrieves statistics related to replication for the Blob service. It is only + * available on the secondary location endpoint when read-access geo-redundant replication is + * enabled for the storage account. + * + * @param options Optional parameters to execute this function. + * @return A BlobServiceStatistics describing the service replication statistics. + */ + Azure::Core::Response GetStatistics( + const GetBlobServiceStatisticsOptions& options = GetBlobServiceStatisticsOptions()) const; + protected: UriBuilder m_serviceUrl; std::shared_ptr m_pipeline; diff --git a/sdk/storage/src/blobs/blob_service_client.cpp b/sdk/storage/src/blobs/blob_service_client.cpp index 8aaef8846..86e13e445 100644 --- a/sdk/storage/src/blobs/blob_service_client.cpp +++ b/sdk/storage/src/blobs/blob_service_client.cpp @@ -170,4 +170,12 @@ namespace Azure { namespace Storage { namespace Blobs { options.Context, *m_pipeline, m_serviceUrl.ToString(), protocolLayerOptions); } + Azure::Core::Response BlobServiceClient::GetStatistics( + const GetBlobServiceStatisticsOptions& options) const + { + BlobRestClient::Service::GetServiceStatisticsOptions protocolLayerOptions; + return BlobRestClient::Service::GetStatistics( + options.Context, *m_pipeline, m_serviceUrl.ToString(), protocolLayerOptions); + } + }}} // namespace Azure::Storage::Blobs diff --git a/sdk/storage/test/blobs/blob_service_client_test.cpp b/sdk/storage/test/blobs/blob_service_client_test.cpp index 36159a287..897423cdf 100644 --- a/sdk/storage/test/blobs/blob_service_client_test.cpp +++ b/sdk/storage/test/blobs/blob_service_client_test.cpp @@ -319,4 +319,28 @@ namespace Azure { namespace Storage { namespace Test { EXPECT_NE(accountInfo.AccountKind, Blobs::AccountKind::Unknown); } + TEST_F(BlobServiceClientTest, Statistics) + { + EXPECT_THROW(m_blobServiceClient.GetStatistics(), StorageError); + + auto GetSecondaryUri = [](const std::string& uri) { + UriBuilder secondaryUri(uri); + std::string primaryHost = secondaryUri.GetHost(); + auto dotPos = primaryHost.find("."); + std::string accountName = primaryHost.substr(0, dotPos); + std::string secondaryHost = accountName + "-secondary" + primaryHost.substr(dotPos); + secondaryUri.SetHost(secondaryHost); + return secondaryUri.ToString(); + }; + + auto keyCredential + = Details::ParseConnectionString(StandardStorageConnectionString()).KeyCredential; + auto secondaryServiceClient + = Blobs::BlobServiceClient(GetSecondaryUri(m_blobServiceClient.GetUri()), keyCredential); + auto serviceStatistics = *secondaryServiceClient.GetStatistics(); + EXPECT_NE(serviceStatistics.GeoReplication.Status, Blobs::BlobGeoReplicationStatus::Unknown); + EXPECT_TRUE(serviceStatistics.GeoReplication.LastSyncTime.HasValue()); + EXPECT_FALSE(serviceStatistics.GeoReplication.LastSyncTime.GetValue().empty()); + } + }}} // namespace Azure::Storage::Test