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