forked from Azure/azure-sdk-for-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
edfca94
commit 603edeb
Showing
7 changed files
with
189 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
sdk/storage/azure-storage-common/inc/azure/storage/common/internal/storage_pipeline.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
#pragma once | ||
|
||
#include "../storage_credential.hpp" | ||
|
||
#include <azure/core/internal/http/pipeline.hpp> | ||
|
||
namespace Azure { namespace Storage { namespace _internal { | ||
|
||
std::shared_ptr<Azure::Core::Http::_internal::HttpPipeline> ConstructStorageHttpPipeline( | ||
const std::string& apiVersion, | ||
const std::string& telemetryPackageName, | ||
const std::string& telemetryPackageVersion, | ||
std::shared_ptr<StorageSharedKeyCredential> sharedKeyCredential, | ||
std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>> perCallPolicies, | ||
std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>> perRetryPolicies, | ||
const Azure::Core::_internal::ClientOptions& clientOptions); | ||
|
||
}}} // namespace Azure::Storage::_internal |
24 changes: 24 additions & 0 deletions
24
sdk/storage/azure-storage-common/inc/azure/storage/common/internal/storage_retry_policy.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
#pragma once | ||
|
||
#include <azure/core/http/policies/policy.hpp> | ||
|
||
namespace Azure { namespace Storage { namespace _internal { | ||
|
||
class StorageRetryPolicy final : public Core::Http::Policies::_internal::RetryPolicy { | ||
public: | ||
explicit StorageRetryPolicy(Core::Http::Policies::RetryOptions options) | ||
: RetryPolicy(std::move(options)) | ||
{ | ||
} | ||
~StorageRetryPolicy() override {} | ||
|
||
protected: | ||
bool ShouldRetry( | ||
const std::unique_ptr<Core::Http::RawResponse>& response, | ||
const Core::Http::Policies::RetryOptions& retryOptions) const override; | ||
}; | ||
|
||
}}} // namespace Azure::Storage::_internal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
#include "azure/storage/common/internal/storage_pipeline.hpp" | ||
|
||
#include "azure/storage/common/internal/shared_key_policy.hpp" | ||
#include "azure/storage/common/internal/storage_per_retry_policy.hpp" | ||
#include "azure/storage/common/internal/storage_retry_policy.hpp" | ||
#include "azure/storage/common/internal/storage_service_version_policy.hpp" | ||
|
||
namespace Azure { namespace Storage { namespace _internal { | ||
|
||
std::shared_ptr<Azure::Core::Http::_internal::HttpPipeline> ConstructStorageHttpPipeline( | ||
const std::string& apiVersion, | ||
const std::string& telemetryPackageName, | ||
const std::string& telemetryPackageVersion, | ||
std::shared_ptr<StorageSharedKeyCredential> sharedKeyCredential, | ||
std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>> perCallPolicies, | ||
std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>> perRetryPolicies, | ||
const Azure::Core::_internal::ClientOptions& clientOptions) | ||
{ | ||
std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>> policies; | ||
|
||
// service-specific per call policies | ||
for (auto& policy : perCallPolicies) | ||
{ | ||
policies.push_back(std::move(policy)); | ||
} | ||
policies.push_back(std::make_unique<_internal::StorageServiceVersionPolicy>(apiVersion)); | ||
|
||
// Request Id | ||
policies.push_back(std::make_unique<Azure::Core::Http::Policies::_internal::RequestIdPolicy>()); | ||
|
||
// Telemetry (user-agent header) | ||
policies.push_back(std::make_unique<Azure::Core::Http::Policies::_internal::TelemetryPolicy>( | ||
telemetryPackageName, telemetryPackageVersion, clientOptions.Telemetry)); | ||
|
||
// client-options per call policies. | ||
for (auto& policy : clientOptions.PerOperationPolicies) | ||
{ | ||
policies.push_back(policy->Clone()); | ||
} | ||
|
||
// Retry policy | ||
policies.push_back(std::make_unique<StorageRetryPolicy>(clientOptions.Retry)); | ||
|
||
// service-specific per retry policies. | ||
for (auto& policy : perRetryPolicies) | ||
{ | ||
policies.push_back(std::move(policy)); | ||
} | ||
policies.push_back(std::make_unique<StoragePerRetryPolicy>()); | ||
|
||
// client options per retry policies. | ||
for (auto& policy : clientOptions.PerRetryPolicies) | ||
{ | ||
policies.push_back(policy->Clone()); | ||
} | ||
|
||
if (sharedKeyCredential) | ||
{ | ||
auto policy = std::make_unique<SharedKeyPolicy>(sharedKeyCredential); | ||
policies.push_back(policy->Clone()); | ||
} | ||
|
||
// Policies after here cannot modify the request anymore | ||
|
||
// Add a request activity policy which will generate distributed traces for the pipeline. | ||
Azure::Core::Http::_internal::HttpSanitizer httpSanitizer( | ||
clientOptions.Log.AllowedHttpQueryParameters, clientOptions.Log.AllowedHttpHeaders); | ||
policies.push_back( | ||
std::make_unique<Azure::Core::Http::Policies::_internal::RequestActivityPolicy>( | ||
httpSanitizer)); | ||
|
||
// logging - won't update request | ||
policies.push_back( | ||
std::make_unique<Azure::Core::Http::Policies::_internal::LogPolicy>(clientOptions.Log)); | ||
|
||
// transport | ||
policies.push_back(std::make_unique<Azure::Core::Http::Policies::_internal::TransportPolicy>( | ||
clientOptions.Transport)); | ||
|
||
return std::make_shared<Azure::Core::Http::_internal::HttpPipeline>(policies); | ||
} | ||
|
||
}}} // namespace Azure::Storage::_internal |
44 changes: 44 additions & 0 deletions
44
sdk/storage/azure-storage-common/src/storage_retry_policy.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
#include "azure/storage/common/internal/storage_retry_policy.hpp" | ||
|
||
#include "azure/core/internal/diagnostics/log.hpp" | ||
|
||
namespace Azure { namespace Storage { namespace _internal { | ||
|
||
bool StorageRetryPolicy::ShouldRetry( | ||
const std::unique_ptr<Core::Http::RawResponse>& response, | ||
const Core::Http::Policies::RetryOptions& retryOptions) const | ||
{ | ||
if (static_cast<std::underlying_type_t<Core::Http::HttpStatusCode>>(response->GetStatusCode()) | ||
>= 400) | ||
{ | ||
const auto& headers = response->GetHeaders(); | ||
auto ite = headers.find("x-ms-copy-source-status-code"); | ||
if (ite != headers.end()) | ||
{ | ||
const auto innerStatusCodeInt = std::stoi(ite->second); | ||
const auto innerStatusCode = static_cast<Core::Http::HttpStatusCode>(innerStatusCodeInt); | ||
|
||
const bool shouldRetry | ||
= retryOptions.StatusCodes.find(innerStatusCode) != retryOptions.StatusCodes.end(); | ||
|
||
if (Azure::Core::Diagnostics::_internal::Log::ShouldWrite( | ||
Azure::Core::Diagnostics::Logger::Level::Informational)) | ||
{ | ||
Azure::Core::Diagnostics::_internal::Log::Write( | ||
Azure::Core::Diagnostics::Logger::Level::Informational, | ||
std::string("x-ms-copy-source-status-code ") + std::to_string(innerStatusCodeInt) | ||
+ (shouldRetry ? " will be retried" : " won't be retried")); | ||
} | ||
if (shouldRetry) | ||
{ | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
}}} // namespace Azure::Storage::_internal |