return Operation<T> for copy blob API (#1736)
This commit is contained in:
parent
5fdb9f4b5d
commit
50772fa2d2
@ -6,6 +6,10 @@
|
||||
|
||||
- Added support for customized application ID.
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
- Changed the return type of `StartCopyFromUri` and `StartCopyIncremental` API from a `Response<T>` to the particular `Operation<T>` type called `StartCopyBlobOperation` directly.
|
||||
|
||||
## 12.0.0-beta.8 (2021-02-12)
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
@ -206,9 +206,9 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
* no authentication is required to perform the copy operation.
|
||||
* @param options Optional parameters to execute this function.
|
||||
* @param context Context for cancelling long running operations.
|
||||
* @return A StartCopyBlobResult describing the state of the copy operation.
|
||||
* @return A StartCopyBlobOperation describing the state of the copy operation.
|
||||
*/
|
||||
Azure::Core::Response<Models::StartCopyBlobResult> StartCopyFromUri(
|
||||
StartCopyBlobOperation StartCopyFromUri(
|
||||
const std::string& sourceUri,
|
||||
const StartCopyBlobFromUriOptions& options = StartCopyBlobFromUriOptions(),
|
||||
const Azure::Core::Context& context = Azure::Core::Context()) const;
|
||||
|
||||
@ -68,40 +68,40 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
std::string LeaseId;
|
||||
};
|
||||
|
||||
class StartCopyBlobResult : public Azure::Core::Operation<GetBlobPropertiesResult> {
|
||||
public:
|
||||
std::string RequestId;
|
||||
Azure::Core::ETag ETag;
|
||||
Azure::Core::DateTime LastModified;
|
||||
std::string CopyId;
|
||||
Models::CopyStatus CopyStatus;
|
||||
Azure::Core::Nullable<std::string> VersionId;
|
||||
|
||||
public:
|
||||
GetBlobPropertiesResult Value() const override { return m_pollResult; }
|
||||
|
||||
~StartCopyBlobResult() override {}
|
||||
|
||||
private:
|
||||
std::string GetResumeToken() const override
|
||||
{
|
||||
// Not supported
|
||||
std::abort();
|
||||
}
|
||||
|
||||
std::unique_ptr<Azure::Core::Http::RawResponse> PollInternal(
|
||||
Azure::Core::Context& context) override;
|
||||
|
||||
Azure::Core::Response<GetBlobPropertiesResult> PollUntilDoneInternal(
|
||||
Azure::Core::Context& context,
|
||||
std::chrono::milliseconds period) override;
|
||||
|
||||
std::shared_ptr<BlobClient> m_blobClient;
|
||||
Models::GetBlobPropertiesResult m_pollResult;
|
||||
|
||||
friend class Blobs::BlobClient;
|
||||
friend class Blobs::PageBlobClient;
|
||||
};
|
||||
|
||||
} // namespace Models
|
||||
|
||||
class StartCopyBlobOperation : public Azure::Core::Operation<Models::GetBlobPropertiesResult> {
|
||||
public:
|
||||
std::string RequestId;
|
||||
Azure::Core::ETag ETag;
|
||||
Azure::Core::DateTime LastModified;
|
||||
std::string CopyId;
|
||||
Models::CopyStatus CopyStatus;
|
||||
Azure::Core::Nullable<std::string> VersionId;
|
||||
|
||||
public:
|
||||
Models::GetBlobPropertiesResult Value() const override { return m_pollResult; }
|
||||
|
||||
~StartCopyBlobOperation() override {}
|
||||
|
||||
private:
|
||||
std::string GetResumeToken() const override
|
||||
{
|
||||
// Not supported
|
||||
std::abort();
|
||||
}
|
||||
|
||||
std::unique_ptr<Azure::Core::Http::RawResponse> PollInternal(
|
||||
Azure::Core::Context& context) override;
|
||||
|
||||
Azure::Core::Response<Models::GetBlobPropertiesResult> PollUntilDoneInternal(
|
||||
Azure::Core::Context& context,
|
||||
std::chrono::milliseconds period) override;
|
||||
|
||||
std::shared_ptr<BlobClient> m_blobClient;
|
||||
Models::GetBlobPropertiesResult m_pollResult;
|
||||
|
||||
friend class Blobs::BlobClient;
|
||||
friend class Blobs::PageBlobClient;
|
||||
};
|
||||
}}} // namespace Azure::Storage::Blobs
|
||||
|
||||
@ -266,9 +266,9 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
* source blob must either be public or must be authenticated via a shared access signature.
|
||||
* @param options Optional parameters to execute this function.
|
||||
* @param context Context for cancelling long running operations.
|
||||
* @return A StartCopyBlobResult describing the state of the copy operation.
|
||||
* @return A StartCopyBlobOperation describing the state of the copy operation.
|
||||
*/
|
||||
Azure::Core::Response<Models::StartCopyBlobResult> StartCopyIncremental(
|
||||
StartCopyBlobOperation StartCopyIncremental(
|
||||
const std::string& sourceUri,
|
||||
const StartCopyPageBlobIncrementalOptions& options = StartCopyPageBlobIncrementalOptions(),
|
||||
const Azure::Core::Context& context = Azure::Core::Context()) const;
|
||||
|
||||
@ -518,7 +518,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
context, *m_pipeline, m_blobUrl, protocolLayerOptions);
|
||||
}
|
||||
|
||||
Azure::Core::Response<Models::StartCopyBlobResult> BlobClient::StartCopyFromUri(
|
||||
StartCopyBlobOperation BlobClient::StartCopyFromUri(
|
||||
const std::string& sourceUri,
|
||||
const StartCopyBlobFromUriOptions& options,
|
||||
const Azure::Core::Context& context) const
|
||||
@ -544,7 +544,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
|
||||
auto response = Details::BlobRestClient::Blob::StartCopyFromUri(
|
||||
context, *m_pipeline, m_blobUrl, protocolLayerOptions);
|
||||
Models::StartCopyBlobResult res;
|
||||
StartCopyBlobOperation res;
|
||||
res.RequestId = std::move(response->RequestId);
|
||||
res.ETag = std::move(response->ETag);
|
||||
res.LastModified = std::move(response->LastModified);
|
||||
@ -552,8 +552,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
res.CopyStatus = std::move(response->CopyStatus);
|
||||
res.VersionId = std::move(response->VersionId);
|
||||
res.m_blobClient = std::make_shared<BlobClient>(*this);
|
||||
return Azure::Core::Response<Models::StartCopyBlobResult>(
|
||||
std::move(res), response.ExtractRawResponse());
|
||||
return res;
|
||||
}
|
||||
|
||||
Azure::Core::Response<Models::AbortCopyBlobFromUriResult> BlobClient::AbortCopyFromUri(
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
|
||||
#include "azure/storage/blobs/blob_client.hpp"
|
||||
|
||||
namespace Azure { namespace Storage { namespace Blobs { namespace Models {
|
||||
namespace Azure { namespace Storage { namespace Blobs {
|
||||
|
||||
std::unique_ptr<Azure::Core::Http::RawResponse> StartCopyBlobResult::PollInternal(
|
||||
std::unique_ptr<Azure::Core::Http::RawResponse> StartCopyBlobOperation::PollInternal(
|
||||
Azure::Core::Context& context)
|
||||
{
|
||||
(void)context;
|
||||
@ -17,11 +17,11 @@ namespace Azure { namespace Storage { namespace Blobs { namespace Models {
|
||||
{
|
||||
m_status = Azure::Core::OperationStatus::Failed;
|
||||
}
|
||||
else if (response->CopyStatus.GetValue() == CopyStatus::Pending)
|
||||
else if (response->CopyStatus.GetValue() == Models::CopyStatus::Pending)
|
||||
{
|
||||
m_status = Azure::Core::OperationStatus::Running;
|
||||
}
|
||||
else if (response->CopyStatus.GetValue() == CopyStatus::Success)
|
||||
else if (response->CopyStatus.GetValue() == Models::CopyStatus::Success)
|
||||
{
|
||||
m_status = Azure::Core::OperationStatus::Succeeded;
|
||||
}
|
||||
@ -33,9 +33,8 @@ namespace Azure { namespace Storage { namespace Blobs { namespace Models {
|
||||
return response.ExtractRawResponse();
|
||||
}
|
||||
|
||||
Azure::Core::Response<GetBlobPropertiesResult> StartCopyBlobResult::PollUntilDoneInternal(
|
||||
Azure::Core::Context& context,
|
||||
std::chrono::milliseconds period)
|
||||
Azure::Core::Response<Models::GetBlobPropertiesResult> StartCopyBlobOperation::
|
||||
PollUntilDoneInternal(Azure::Core::Context& context, std::chrono::milliseconds period)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
@ -43,7 +42,8 @@ namespace Azure { namespace Storage { namespace Blobs { namespace Models {
|
||||
|
||||
if (m_status == Azure::Core::OperationStatus::Succeeded)
|
||||
{
|
||||
return Azure::Core::Response<GetBlobPropertiesResult>(m_pollResult, std::move(rawResponse));
|
||||
return Azure::Core::Response<Models::GetBlobPropertiesResult>(
|
||||
m_pollResult, std::move(rawResponse));
|
||||
}
|
||||
else if (m_status == Azure::Core::OperationStatus::Failed)
|
||||
{
|
||||
@ -58,4 +58,4 @@ namespace Azure { namespace Storage { namespace Blobs { namespace Models {
|
||||
};
|
||||
}
|
||||
|
||||
}}}} // namespace Azure::Storage::Blobs::Models
|
||||
}}} // namespace Azure::Storage::Blobs
|
||||
|
||||
@ -288,7 +288,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
context, *m_pipeline, m_blobUrl, protocolLayerOptions);
|
||||
}
|
||||
|
||||
Azure::Core::Response<Models::StartCopyBlobResult> PageBlobClient::StartCopyIncremental(
|
||||
StartCopyBlobOperation PageBlobClient::StartCopyIncremental(
|
||||
const std::string& sourceUri,
|
||||
const StartCopyPageBlobIncrementalOptions& options,
|
||||
const Azure::Core::Context& context) const
|
||||
@ -303,7 +303,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
|
||||
auto response = Details::BlobRestClient::PageBlob::StartCopyIncremental(
|
||||
context, *m_pipeline, m_blobUrl, protocolLayerOptions);
|
||||
Models::StartCopyBlobResult res;
|
||||
StartCopyBlobOperation res;
|
||||
res.RequestId = std::move(response->RequestId);
|
||||
res.ETag = std::move(response->ETag);
|
||||
res.LastModified = std::move(response->LastModified);
|
||||
@ -311,8 +311,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
res.CopyStatus = std::move(response->CopyStatus);
|
||||
res.VersionId = std::move(response->VersionId);
|
||||
res.m_blobClient = std::make_shared<BlobClient>(*this);
|
||||
return Azure::Core::Response<Models::StartCopyBlobResult>(
|
||||
std::move(res), response.ExtractRawResponse());
|
||||
return res;
|
||||
}
|
||||
|
||||
}}} // namespace Azure::Storage::Blobs
|
||||
|
||||
@ -335,14 +335,14 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
Blobs::StartCopyBlobFromUriOptions copyOptions;
|
||||
copyOptions.ShouldSealDestination = false;
|
||||
auto copyResult = blobClient2.StartCopyFromUri(blobClient.GetUrl() + GetSas(), copyOptions);
|
||||
getPropertiesResult = copyResult->PollUntilDone(std::chrono::seconds(1));
|
||||
getPropertiesResult = copyResult.PollUntilDone(std::chrono::seconds(1));
|
||||
ASSERT_TRUE(getPropertiesResult->CopyStatus.HasValue());
|
||||
EXPECT_EQ(getPropertiesResult->CopyStatus.GetValue(), Blobs::Models::CopyStatus::Success);
|
||||
EXPECT_FALSE(getPropertiesResult->IsSealed.GetValue());
|
||||
|
||||
copyOptions.ShouldSealDestination = true;
|
||||
copyResult = blobClient2.StartCopyFromUri(blobClient.GetUrl() + GetSas(), copyOptions);
|
||||
getPropertiesResult = copyResult->PollUntilDone(std::chrono::seconds(1));
|
||||
getPropertiesResult = copyResult.PollUntilDone(std::chrono::seconds(1));
|
||||
EXPECT_TRUE(getPropertiesResult->IsSealed.HasValue());
|
||||
EXPECT_TRUE(getPropertiesResult->IsSealed.GetValue());
|
||||
ASSERT_TRUE(getPropertiesResult->CopyStatus.HasValue());
|
||||
|
||||
@ -208,20 +208,17 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
{
|
||||
auto blobClient = m_blobContainerClient->GetBlobClient(RandomString());
|
||||
auto res = blobClient.StartCopyFromUri(m_blockBlobClient->GetUrl());
|
||||
EXPECT_FALSE(res->RequestId.empty());
|
||||
EXPECT_FALSE(res.GetRawResponse().GetHeaders().at(Details::HttpHeaderRequestId).empty());
|
||||
EXPECT_FALSE(res.GetRawResponse().GetHeaders().at(Details::HttpHeaderDate).empty());
|
||||
EXPECT_FALSE(res.GetRawResponse().GetHeaders().at(Details::HttpHeaderXMsVersion).empty());
|
||||
EXPECT_TRUE(res->ETag.HasValue());
|
||||
EXPECT_TRUE(IsValidTime(res->LastModified));
|
||||
EXPECT_FALSE(res->CopyId.empty());
|
||||
EXPECT_TRUE(res->VersionId.HasValue());
|
||||
EXPECT_FALSE(res->VersionId.GetValue().empty());
|
||||
EXPECT_FALSE(res.RequestId.empty());
|
||||
EXPECT_TRUE(res.ETag.HasValue());
|
||||
EXPECT_TRUE(IsValidTime(res.LastModified));
|
||||
EXPECT_FALSE(res.CopyId.empty());
|
||||
EXPECT_TRUE(res.VersionId.HasValue());
|
||||
EXPECT_FALSE(res.VersionId.GetValue().empty());
|
||||
EXPECT_TRUE(
|
||||
res->CopyStatus == Azure::Storage::Blobs::Models::CopyStatus::Pending
|
||||
|| res->CopyStatus == Azure::Storage::Blobs::Models::CopyStatus::Success);
|
||||
res.CopyStatus == Azure::Storage::Blobs::Models::CopyStatus::Pending
|
||||
|| res.CopyStatus == Azure::Storage::Blobs::Models::CopyStatus::Success);
|
||||
auto properties = *blobClient.GetProperties();
|
||||
EXPECT_EQ(properties.CopyId.GetValue(), res->CopyId);
|
||||
EXPECT_EQ(properties.CopyId.GetValue(), res.CopyId);
|
||||
EXPECT_FALSE(properties.CopySource.GetValue().empty());
|
||||
EXPECT_TRUE(
|
||||
properties.CopyStatus.GetValue() == Azure::Storage::Blobs::Models::CopyStatus::Pending
|
||||
@ -236,7 +233,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
EXPECT_FALSE(properties.IncrementalCopyDestinationSnapshot.HasValue());
|
||||
|
||||
auto downloadResult = blobClient.Download();
|
||||
EXPECT_EQ(downloadResult->Details.CopyId.GetValue(), res->CopyId);
|
||||
EXPECT_EQ(downloadResult->Details.CopyId.GetValue(), res.CopyId);
|
||||
EXPECT_FALSE(downloadResult->Details.CopySource.GetValue().empty());
|
||||
EXPECT_TRUE(
|
||||
downloadResult->Details.CopyStatus.GetValue()
|
||||
|
||||
@ -151,14 +151,14 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
Azure::Core::Http::Url sourceUri(m_pageBlobClient->WithSnapshot(snapshot).GetUrl());
|
||||
sourceUri.AppendQueryParameters(GetSas());
|
||||
auto copyInfo = pageBlobClient.StartCopyIncremental(sourceUri.GetAbsoluteUrl());
|
||||
EXPECT_FALSE(copyInfo->RequestId.empty());
|
||||
EXPECT_TRUE(copyInfo->ETag.HasValue());
|
||||
EXPECT_TRUE(IsValidTime(copyInfo->LastModified));
|
||||
EXPECT_FALSE(copyInfo->CopyId.empty());
|
||||
EXPECT_FALSE(copyInfo->CopyStatus.Get().empty());
|
||||
EXPECT_TRUE(copyInfo->VersionId.HasValue());
|
||||
EXPECT_FALSE(copyInfo->VersionId.GetValue().empty());
|
||||
auto getPropertiesResult = copyInfo->PollUntilDone(std::chrono::seconds(1));
|
||||
EXPECT_FALSE(copyInfo.RequestId.empty());
|
||||
EXPECT_TRUE(copyInfo.ETag.HasValue());
|
||||
EXPECT_TRUE(IsValidTime(copyInfo.LastModified));
|
||||
EXPECT_FALSE(copyInfo.CopyId.empty());
|
||||
EXPECT_FALSE(copyInfo.CopyStatus.Get().empty());
|
||||
EXPECT_TRUE(copyInfo.VersionId.HasValue());
|
||||
EXPECT_FALSE(copyInfo.VersionId.GetValue().empty());
|
||||
auto getPropertiesResult = copyInfo.PollUntilDone(std::chrono::seconds(1));
|
||||
ASSERT_TRUE(getPropertiesResult->CopyStatus.HasValue());
|
||||
EXPECT_EQ(getPropertiesResult->CopyStatus.GetValue(), Blobs::Models::CopyStatus::Success);
|
||||
ASSERT_TRUE(getPropertiesResult->CopyId.HasValue());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user