-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
DataLakeLeaseClient.cs
752 lines (703 loc) · 29.3 KB
/
DataLakeLeaseClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Threading;
using System.Threading.Tasks;
using Azure.Core.Pipeline;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Specialized;
using Azure.Storage.Files.DataLake.Models;
namespace Azure.Storage.Files.DataLake
{
/// <summary>
/// The <see cref="DataLakeLeaseClient"/> allows you to manipulate Azure
/// Storage leases on paths.
/// </summary>
public class DataLakeLeaseClient
{
/// <summary>
/// Blob lease client for managing leases.
/// </summary>
private readonly BlobLeaseClient _blobLeaseClient;
/// <summary>
/// The <see cref="TimeSpan"/> representing an infinite lease duration.
/// </summary>
public static readonly TimeSpan InfiniteLeaseDuration = TimeSpan.FromSeconds(Constants.Blob.Lease.InfiniteLeaseDuration);
/// <summary>
/// Gets the URI of the object being leased.
/// </summary>
public Uri Uri => _blobLeaseClient.Uri;
/// <summary>
/// Gets the Lease ID for this lease.
/// </summary>
public virtual string LeaseId => _blobLeaseClient.LeaseId;
/// <summary>
/// The <see cref="ClientDiagnostics"/> instance used to create diagnostic scopes
/// every request.
/// </summary>
private readonly ClientDiagnostics _clientDiagnostics;
/// <summary>
/// The <see cref="ClientDiagnostics"/> instance used to create diagnostic scopes
/// every request.
/// </summary>
internal virtual ClientDiagnostics ClientDiagnostics => _clientDiagnostics;
#region ctors
/// <summary>
/// Initializes a new instance of the <see cref="DataLakeLeaseClient"/> class
/// for mocking.
/// </summary>
protected DataLakeLeaseClient()
{
_blobLeaseClient = null;
_clientDiagnostics = null;
}
/// <summary>
/// Initializes a new instance of the <see cref="DataLakeLeaseClient"/> class.
/// </summary>
/// <param name="client">
/// A <see cref="BlobClient"/> representing the blob being leased.
/// </param>
/// <param name="leaseId">
/// An optional lease ID. If no lease ID is provided, a random lease
/// ID will be created.
/// </param>
public DataLakeLeaseClient(DataLakePathClient client, string leaseId = null)
{
_blobLeaseClient = new BlobLeaseClient(client.BlobClient, leaseId);
_clientDiagnostics = client.ClientConfiguration.ClientDiagnostics;
}
/// <summary>
/// Initializes a new instance of the <see cref="DataLakeLeaseClient"/> class.
/// </summary>
/// <param name="client">
/// A <see cref="DataLakeFileSystemClient"/> representing the file system
/// being leased.
/// </param>
/// <param name="leaseId">
/// An optional lease ID. If no lease ID is provided, a random lease
/// ID will be created.
/// </param>
public DataLakeLeaseClient(DataLakeFileSystemClient client, string leaseId = null)
{
_blobLeaseClient = new BlobLeaseClient(client.ContainerClient, leaseId);
_clientDiagnostics = client.ClientConfiguration.ClientDiagnostics;
}
#endregion ctors
#region Acquire
/// <summary>
/// The <see cref="Acquire"/> operation acquires a lease on
/// the path or file system. The lease <paramref name="duration"/> must
/// be between 15 to 60 seconds, or infinite (-1).
///
/// If the file system does not have an active lease, the Data Lake service
/// creates a lease on the path or file system and returns it. If the
/// file system has an active lease, you can only request a new lease
/// using the active lease ID as <see cref="LeaseId"/>, but you can
/// specify a new <paramref name="duration"/>.
///
/// For more information, see
/// <see href="https://docs.microsoft.com/rest/api/storageservices/lease-container">
/// Lease Container</see>.
/// </summary>
/// <param name="duration">
/// Specifies the duration of the lease, in seconds, or specify
/// <see cref="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 <see cref="RenewAsync"/> or <see cref="ChangeAsync"/>.
/// </param>
/// <param name="conditions">
/// Optional <see cref="RequestConditions"/> to add
/// conditions on acquiring a lease.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// A <see cref="Response{Lease}"/> describing the lease.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
public virtual Response<DataLakeLease> Acquire(
TimeSpan duration,
RequestConditions conditions = default,
CancellationToken cancellationToken = default)
{
DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakeLeaseClient)}.{nameof(Acquire)}");
try
{
scope.Start();
Response<Blobs.Models.BlobLease> response = _blobLeaseClient.Acquire(
duration,
conditions,
cancellationToken);
return Response.FromValue(
response.Value.ToDataLakeLease(),
response.GetRawResponse());
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
finally
{
scope.Dispose();
}
}
/// <summary>
/// The <see cref="AcquireAsync"/> operation acquires a lease on
/// the path or file system. The lease <paramref name="duration"/> must
/// be between 15 to 60 seconds, or infinite (-1).
///
/// If the file system does not have an active lease, the Data Lake service
/// creates a lease on the file system or path and returns it. If the
/// file system has an active lease, you can only request a new lease
/// using the active lease ID as <see cref="LeaseId"/>, but you can
/// specify a new <paramref name="duration"/>.
///
/// For more information, see
/// <see href="https://docs.microsoft.com/rest/api/storageservices/lease-container">
/// Lease Container</see>.
/// </summary>
/// <param name="duration">
/// Specifies the duration of the lease, in seconds, or specify
/// <see cref="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 <see cref="RenewAsync"/> or <see cref="ChangeAsync"/>.
/// </param>
/// <param name="conditions">
/// Optional <see cref="RequestConditions"/> to add
/// conditions on acquiring a lease.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// A <see cref="Response{Lease}"/> describing the lease.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
public virtual async Task<Response<DataLakeLease>> AcquireAsync(
TimeSpan duration,
RequestConditions conditions = default,
CancellationToken cancellationToken = default)
{
DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakeLeaseClient)}.{nameof(Acquire)}");
try
{
scope.Start();
Response<Blobs.Models.BlobLease> response = await _blobLeaseClient.AcquireAsync(
duration,
conditions,
cancellationToken)
.ConfigureAwait(false);
return Response.FromValue(
response.Value.ToDataLakeLease(),
response.GetRawResponse());
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
finally
{
scope.Dispose();
}
}
#endregion Acquire
#region Renew
/// <summary>
/// The <see cref="Renew"/> operation renews the path or
/// file system's previously-acquired lease.
///
/// The lease can be renewed if the leaseId
/// matches that associated with the path or file system. Note that the
/// lease may be renewed even if it has expired as long as the path or
/// file system has not been leased again since the expiration of that
/// lease. When you renew a lease, the lease duration clock resets.
///
/// For more information, see
/// <see href="https://docs.microsoft.com/rest/api/storageservices/lease-container">
/// Lease Container</see>.
/// </summary>
/// <param name="conditions">
/// Optional <see cref="RequestConditions"/> to add
/// conditions on acquiring a lease.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// A <see cref="Response{Lease}"/> describing the lease.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
public virtual Response<DataLakeLease> Renew(
RequestConditions conditions = default,
CancellationToken cancellationToken = default)
{
DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakeLeaseClient)}.{nameof(Renew)}");
try
{
scope.Start();
Response<Blobs.Models.BlobLease> response = _blobLeaseClient.Renew(
conditions,
cancellationToken);
return Response.FromValue(
response.Value.ToDataLakeLease(),
response.GetRawResponse());
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
finally
{
scope.Dispose();
}
}
/// <summary>
/// The <see cref="RenewAsync"/> operation renews the path or
/// file system's previously-acquired lease.
///
/// The lease can be renewed if the leaseId
/// matches that associated with the path or file system. Note that the
/// lease may be renewed even if it has expired as long as the path or
/// file system has not been leased again since the expiration of that
/// lease. When you renew a lease, the lease duration clock resets.
///
/// For more information, see
/// <see href="https://docs.microsoft.com/rest/api/storageservices/lease-container">
/// Lease Container</see>.
/// </summary>
/// <param name="conditions">
/// Optional <see cref="RequestConditions"/> to add
/// conditions on acquiring a lease.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// A <see cref="Response{Lease}"/> describing the lease.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
public virtual async Task<Response<DataLakeLease>> RenewAsync(
RequestConditions conditions = default,
CancellationToken cancellationToken = default)
{
DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakeLeaseClient)}.{nameof(Renew)}");
try
{
scope.Start();
Response<Blobs.Models.BlobLease> response = await _blobLeaseClient.RenewAsync(
conditions,
cancellationToken)
.ConfigureAwait(false);
return Response.FromValue(
response.Value.ToDataLakeLease(),
response.GetRawResponse());
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
finally
{
scope.Dispose();
}
}
#endregion Renew
#region Release
/// <summary>
/// The <see cref="Release"/> operation releases the
/// file system or path's previously-acquired lease.
///
/// The lease may be released if the <see cref="LeaseId"/>
/// matches that associated with the file system or path. Releasing the
/// lease allows another client to immediately acquire the lease for the
/// file system or path as soon as the release is complete.
///
/// For more information, see
/// <see href="https://docs.microsoft.com/rest/api/storageservices/lease-container">
/// Lease Container</see>.
/// </summary>
/// <param name="conditions">
/// Optional <see cref="RequestConditions"/> to add
/// conditions on acquiring a lease.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// A <see cref="Response{ReleaseObjectLeaseInfo}"/> describing the
/// updated path or file system.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
public virtual Response<ReleasedObjectInfo> Release(
RequestConditions conditions = default,
CancellationToken cancellationToken = default)
{
DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakeLeaseClient)}.{nameof(Release)}");
try
{
scope.Start();
Response<Blobs.Models.ReleasedObjectInfo> response = _blobLeaseClient.Release(
conditions,
cancellationToken);
return Response.FromValue(
new ReleasedObjectInfo(response.Value.ETag, response.Value.LastModified),
response.GetRawResponse());
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
finally
{
scope.Dispose();
}
}
/// <summary>
/// The <see cref="ReleaseAsync"/> operation releases the
/// file system or path's previously-acquired lease.
///
/// The lease may be released if the <see cref="LeaseId"/>
/// matches that associated with the file system or path. Releasing the
/// lease allows another client to immediately acquire the lease for the
/// file system or path as soon as the release is complete.
///
/// For more information, see
/// <see href="https://docs.microsoft.com/rest/api/storageservices/lease-container">
/// Lease Container</see>.
/// </summary>
/// <param name="conditions">
/// Optional <see cref="RequestConditions"/> to add
/// conditions on acquiring a lease.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// A <see cref="Response{ReleasedObjectInfo}"/> describing the
/// updated path or file system.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
public virtual async Task<Response<ReleasedObjectInfo>> ReleaseAsync(
RequestConditions conditions = default,
CancellationToken cancellationToken = default)
{
DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakeLeaseClient)}.{nameof(Release)}");
try
{
scope.Start();
Response<Blobs.Models.ReleasedObjectInfo> response = await _blobLeaseClient.ReleaseAsync(
conditions,
cancellationToken)
.ConfigureAwait(false);
return Response.FromValue(
new ReleasedObjectInfo(response.Value.ETag, response.Value.LastModified),
response.GetRawResponse());
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
finally
{
scope.Dispose();
}
}
#endregion Release
#region Change
/// <summary>
/// The <see cref="Change"/> operation changes the lease
/// of an active lease. A change must include the current
/// <see cref="LeaseId"/> and a new <paramref name="proposedId"/>.
///
/// For more information, see
/// <see href="https://docs.microsoft.com/rest/api/storageservices/lease-container">
/// Lease Container</see>.
/// </summary>
/// <param name="proposedId">
/// An optional proposed lease ID, in a GUID string format. A
/// <see cref="RequestFailedException"/> will be thrown if the
/// proposed lease ID is not in the correct format.
/// </param>
/// <param name="conditions">
/// Optional <see cref="RequestConditions"/> to add
/// conditions on acquiring a lease.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// A <see cref="Response{Lease}"/> describing the lease.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
public virtual Response<DataLakeLease> Change(
string proposedId,
RequestConditions conditions = default,
CancellationToken cancellationToken = default)
{
DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakeLeaseClient)}.{nameof(Change)}");
try
{
scope.Start();
Response<Blobs.Models.BlobLease> response = _blobLeaseClient.Change(
proposedId,
conditions,
cancellationToken);
return Response.FromValue(
response.Value.ToDataLakeLease(),
response.GetRawResponse());
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
finally
{
scope.Dispose();
}
}
/// <summary>
/// The <see cref="ChangeAsync"/> operation changes the lease
/// of an active lease. A change must include the current
/// <see cref="LeaseId"/> and a new <paramref name="proposedId"/>.
///
/// For more information, see
/// <see href="https://docs.microsoft.com/rest/api/storageservices/lease-container">
/// Lease Container</see>.
/// </summary>
/// <param name="proposedId">
/// An optional proposed lease ID, in a GUID string format. A
/// <see cref="RequestFailedException"/> will be thrown if the
/// proposed lease ID is not in the correct format.
/// </param>
/// <param name="conditions">
/// Optional <see cref="RequestConditions"/> to add
/// conditions on acquiring a lease.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// A <see cref="Response{Lease}"/> describing the lease.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
public virtual async Task<Response<DataLakeLease>> ChangeAsync(
string proposedId,
RequestConditions conditions = default,
CancellationToken cancellationToken = default)
{
DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakeLeaseClient)}.{nameof(Change)}");
try
{
scope.Start();
Response<Blobs.Models.BlobLease> response = await _blobLeaseClient.ChangeAsync(
proposedId,
conditions,
cancellationToken)
.ConfigureAwait(false);
return Response.FromValue(
response.Value.ToDataLakeLease(),
response.GetRawResponse());
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
finally
{
scope.Dispose();
}
}
#endregion Change
#region Break
/// <summary>
/// The <see cref="Break"/> operation breaks the path or
/// file system's previously-acquired lease (if it exists).
///
/// Once a lease is broken, it cannot be renewed. Any authorized
/// request can break the lease; the request is not required to
/// specify a matching lease ID. When a lease is broken, the lease
/// break <paramref name="breakPeriod"/> is allowed to elapse,
/// during which time no lease operation except
/// <see cref="Break"/> and <see cref="Release"/> can be
/// performed on the path or file system. When a lease is successfully
/// broken, the response indicates the interval in seconds until a new
/// lease can be acquired.
///
/// A lease that has been broken can also be released. A client can
/// immediately acquire a path or file system lease that has been
/// released.
///
/// For more information, see
/// <see href="https://docs.microsoft.com/rest/api/storageservices/lease-container">
/// Lease Container</see>.
/// </summary>
/// <param name="breakPeriod">
/// Specifies the proposed duration the lease should continue before
/// it is broken, in seconds, between 0 and 60. This break period is
/// only used if it is shorter than the time remaining on the lease.
/// If longer, the time remaining on the lease is used. A new lease
/// will not be available before the break period has expired, but the
/// lease may be held for longer than the break period. If this value
/// is not provided, a fixed-duration lease breaks after the remaining
/// lease period elapses, and an infinite lease breaks immediately.
/// </param>
/// <param name="conditions">
/// Optional <see cref="RequestConditions"/> to add
/// conditions on acquiring a lease.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// A <see cref="Response{Lease}"/> describing the broken lease.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
public virtual Response<DataLakeLease> Break(
TimeSpan? breakPeriod = default,
RequestConditions conditions = default,
CancellationToken cancellationToken = default)
{
DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakeLeaseClient)}.{nameof(Break)}");
try
{
scope.Start();
Response<Blobs.Models.BlobLease> response = _blobLeaseClient.Break(
breakPeriod,
conditions,
cancellationToken);
return Response.FromValue(
response.Value.ToDataLakeLease(),
response.GetRawResponse());
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
finally
{
scope.Dispose();
}
}
/// <summary>
/// The <see cref="BreakAsync"/> operation breaks the path or
/// file system's previously-acquired lease (if it exists).
///
/// Once a lease is broken, it cannot be renewed. Any authorized
/// request can break the lease; the request is not required to
/// specify a matching lease ID. When a lease is broken, the lease
/// break <paramref name="breakPeriod"/> is allowed to elapse,
/// during which time no lease operation except
/// <see cref="BreakAsync"/> and <see cref="ReleaseAsync"/> can be
/// performed on the path or file system. When a lease is successfully
/// broken, the response indicates the interval in seconds until a new
/// lease can be acquired.
///
/// A lease that has been broken can also be released. A client can
/// immediately acquire a path or file system lease that has been
/// released.
///
/// For more information, see
/// <see href="https://docs.microsoft.com/rest/api/storageservices/lease-container">
/// Lease Container</see>.
/// </summary>
/// <param name="breakPeriod">
/// Specifies the proposed duration the lease should continue before
/// it is broken, in seconds, between 0 and 60. This break period is
/// only used if it is shorter than the time remaining on the lease.
/// If longer, the time remaining on the lease is used. A new lease
/// will not be available before the break period has expired, but the
/// lease may be held for longer than the break period. If this value
/// is not provided, a fixed-duration lease breaks after the remaining
/// lease period elapses, and an infinite lease breaks immediately.
/// </param>
/// <param name="conditions">
/// Optional <see cref="RequestConditions"/> to add
/// conditions on acquiring a lease.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// A <see cref="Response{Lease}"/> describing the broken lease.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
public virtual async Task<Response<DataLakeLease>> BreakAsync(
TimeSpan? breakPeriod = default,
RequestConditions conditions = default,
CancellationToken cancellationToken = default)
{
DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakeLeaseClient)}.{nameof(Break)}");
try
{
scope.Start();
Response<Blobs.Models.BlobLease> response = await _blobLeaseClient.BreakAsync(
breakPeriod,
conditions,
cancellationToken).ConfigureAwait(false);
return Response.FromValue(
response.Value.ToDataLakeLease(),
response.GetRawResponse());
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
finally
{
scope.Dispose();
}
}
#endregion Break
}
}