Added lease support for DataLake's Path (#521)
This commit is contained in:
parent
b87bd0816c
commit
ae6ada5cfb
@ -719,4 +719,11 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
|
||||
*/
|
||||
int Concurrency = 1;
|
||||
};
|
||||
|
||||
using AcquirePathLeaseOptions = Blobs::AcquireBlobLeaseOptions;
|
||||
using BreakPathLeaseOptions = Blobs::BreakBlobLeaseOptions;
|
||||
using RenewPathLeaseOptions = Blobs::RenewBlobLeaseOptions;
|
||||
using ReleasePathLeaseOptions = Blobs::ReleaseBlobLeaseOptions;
|
||||
using ChangePathLeaseOptions = Blobs::ChangeBlobLeaseOptions;
|
||||
|
||||
}}}} // namespace Azure::Storage::Files::DataLake
|
||||
|
||||
@ -170,6 +170,80 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
|
||||
const std::map<std::string, std::string>& metadata,
|
||||
const SetPathMetadataOptions& options = SetPathMetadataOptions()) const;
|
||||
|
||||
/**
|
||||
* @brief Acquires a lease on the path.
|
||||
* @param proposedLeaseId Proposed lease ID, in a GUID string format.
|
||||
* @param duration Specifies the duration of the lease, in seconds, or
|
||||
* Azure::Storage::c_InfiniteLeaseDuration for a lease that never expires. A non-infinite lease
|
||||
* can be between 15 and 60 seconds. A lease duration cannot be changed using renew or change.
|
||||
* @param options Optional parameters to execute this function.
|
||||
* @return A AcquirePathLeaseResult describing the lease.
|
||||
* @remark This request is sent to blob endpoint.
|
||||
*/
|
||||
Azure::Core::Response<AcquirePathLeaseResult> AcquireLease(
|
||||
const std::string& proposedLeaseId,
|
||||
int32_t duration,
|
||||
const AcquirePathLeaseOptions& options = AcquirePathLeaseOptions()) const
|
||||
{
|
||||
return m_blobClient.AcquireLease(proposedLeaseId, duration, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Renews the path's previously-acquired lease.
|
||||
* @param leaseId ID of the previously-acquired lease.
|
||||
* @param options Optional parameters to execute this function.
|
||||
* @return A RenewPathLeaseResult describing the lease.
|
||||
* @remark This request is sent to blob endpoint.
|
||||
*/
|
||||
Azure::Core::Response<RenewPathLeaseResult> RenewLease(
|
||||
const std::string& leaseId,
|
||||
const RenewPathLeaseOptions& options = RenewPathLeaseOptions()) const
|
||||
{
|
||||
return m_blobClient.RenewLease(leaseId, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Releases the path's previously-acquired lease.
|
||||
* @param leaseId ID of the previously-acquired lease.
|
||||
* @param options Optional parameters to execute this function.
|
||||
* @return A ReleasePathLeaseResult describing the updated path.
|
||||
* @remark This request is sent to blob endpoint.
|
||||
*/
|
||||
Azure::Core::Response<ReleasePathLeaseResult> ReleaseLease(
|
||||
const std::string& leaseId,
|
||||
const ReleasePathLeaseOptions& options = ReleasePathLeaseOptions()) const
|
||||
{
|
||||
return m_blobClient.ReleaseLease(leaseId, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Changes the lease of an active lease.
|
||||
* @param leaseId ID of the previously-acquired lease.
|
||||
* @param proposedLeaseId Proposed lease ID, in a GUID string format.
|
||||
* @param options Optional parameters to execute this function.
|
||||
* @return A ChangePathLeaseResult describing the lease.
|
||||
* @remark This request is sent to blob endpoint.
|
||||
*/
|
||||
Azure::Core::Response<ChangePathLeaseResult> ChangeLease(
|
||||
const std::string& leaseId,
|
||||
const std::string& proposedLeaseId,
|
||||
const ChangePathLeaseOptions& options = ChangePathLeaseOptions()) const
|
||||
{
|
||||
return m_blobClient.ChangeLease(leaseId, proposedLeaseId, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Breaks the previously-acquired lease.
|
||||
* @param options Optional parameters to execute this function.
|
||||
* @return A BreakPathLeaseResult describing the broken lease.
|
||||
* @remark This request is sent to blob endpoint.
|
||||
*/
|
||||
Azure::Core::Response<BreakPathLeaseResult> BreakLease(
|
||||
const BreakPathLeaseOptions& options = BreakPathLeaseOptions()) const
|
||||
{
|
||||
return m_blobClient.BreakLease(options);
|
||||
}
|
||||
|
||||
protected:
|
||||
UriBuilder m_dfsUri;
|
||||
Blobs::BlobClient m_blobClient;
|
||||
|
||||
@ -31,6 +31,11 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
|
||||
// PathClient models:
|
||||
|
||||
using DeletePathResult = PathDeleteResult;
|
||||
using AcquirePathLeaseResult = Blobs::AcquireBlobLeaseResult;
|
||||
using RenewPathLeaseResult = Blobs::RenewBlobLeaseResult;
|
||||
using ReleasePathLeaseResult = Blobs::ReleaseBlobLeaseResult;
|
||||
using ChangePathLeaseResult = Blobs::ChangeBlobLeaseResult;
|
||||
using BreakPathLeaseResult = Blobs::BreakBlobLeaseResult;
|
||||
|
||||
struct Acl
|
||||
{
|
||||
|
||||
@ -231,4 +231,59 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
EXPECT_NO_THROW(m_pathClient->SetAccessControl(acls, options2));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DataLakePathClientTest, LeaseRelated)
|
||||
{
|
||||
std::string leaseId1 = CreateUniqueLeaseId();
|
||||
int32_t leaseDuration = 20;
|
||||
auto aLease = *m_pathClient->AcquireLease(leaseId1, leaseDuration);
|
||||
EXPECT_FALSE(aLease.ETag.empty());
|
||||
EXPECT_FALSE(aLease.LastModified.empty());
|
||||
EXPECT_EQ(aLease.LeaseId, leaseId1);
|
||||
aLease = *m_pathClient->AcquireLease(leaseId1, leaseDuration);
|
||||
EXPECT_FALSE(aLease.ETag.empty());
|
||||
EXPECT_FALSE(aLease.LastModified.empty());
|
||||
EXPECT_EQ(aLease.LeaseId, leaseId1);
|
||||
|
||||
auto properties = *m_pathClient->GetProperties();
|
||||
EXPECT_EQ(properties.LeaseState.GetValue(), Files::DataLake::LeaseStateType::Leased);
|
||||
EXPECT_EQ(properties.LeaseStatus.GetValue(), Files::DataLake::LeaseStatusType::Locked);
|
||||
EXPECT_FALSE(properties.LeaseDuration.GetValue().empty());
|
||||
|
||||
auto rLease = *m_pathClient->RenewLease(leaseId1);
|
||||
EXPECT_FALSE(rLease.ETag.empty());
|
||||
EXPECT_FALSE(rLease.LastModified.empty());
|
||||
EXPECT_EQ(rLease.LeaseId, leaseId1);
|
||||
|
||||
std::string leaseId2 = CreateUniqueLeaseId();
|
||||
EXPECT_NE(leaseId1, leaseId2);
|
||||
auto cLease = *m_pathClient->ChangeLease(leaseId1, leaseId2);
|
||||
EXPECT_FALSE(cLease.ETag.empty());
|
||||
EXPECT_FALSE(cLease.LastModified.empty());
|
||||
EXPECT_EQ(cLease.LeaseId, leaseId2);
|
||||
|
||||
auto pathInfo = *m_pathClient->ReleaseLease(leaseId2);
|
||||
EXPECT_FALSE(pathInfo.ETag.empty());
|
||||
EXPECT_FALSE(pathInfo.LastModified.empty());
|
||||
|
||||
aLease = *m_pathClient->AcquireLease(CreateUniqueLeaseId(), c_InfiniteLeaseDuration);
|
||||
properties = *m_pathClient->GetProperties();
|
||||
EXPECT_FALSE(properties.LeaseDuration.GetValue().empty());
|
||||
auto brokenLease = *m_pathClient->BreakLease();
|
||||
EXPECT_FALSE(brokenLease.ETag.empty());
|
||||
EXPECT_FALSE(brokenLease.LastModified.empty());
|
||||
EXPECT_EQ(brokenLease.LeaseTime, 0);
|
||||
|
||||
aLease = *m_pathClient->AcquireLease(CreateUniqueLeaseId(), leaseDuration);
|
||||
Files::DataLake::BreakPathLeaseOptions breakOptions;
|
||||
breakOptions.breakPeriod = 30;
|
||||
brokenLease = *m_pathClient->BreakLease(breakOptions);
|
||||
EXPECT_FALSE(brokenLease.ETag.empty());
|
||||
EXPECT_FALSE(brokenLease.LastModified.empty());
|
||||
EXPECT_NE(brokenLease.LeaseTime, 0);
|
||||
|
||||
Files::DataLake::BreakPathLeaseOptions options;
|
||||
options.breakPeriod = 0;
|
||||
m_pathClient->BreakLease(options);
|
||||
}
|
||||
}}} // namespace Azure::Storage::Test
|
||||
|
||||
Loading…
Reference in New Issue
Block a user