forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AppConfiguration] Snapshot API Updates (Azure#34583)
* API updates * addded tests * additional API changes * fix * regeneration * sample * set public-clients: false * updates * internalizing instead of suppressing * suppression -> transforms * simplifying changes based on feedback * cleaning up to make dif cleaner * working on LRO implementation * completed LRO implementation * reverting some things * re-gen * sample * initial LRO * removing snippet tags * changing title * propagating operation type * feedback * removing some things before release * Add SnapshotName field in SettingSelector * Update public API * adding TODOs for the LRO implementation - need to wait until feature is out of dogfoo in order to move forward * regenerating using new swagger * initial update * adding get snapshot * lro updates * quick fix * minor changes * simplification changes * adding tests * test tweaks plus added samples * switching back service version * adding some additional documentation * docs/api regeneration * changing ID to snapshot name --------- Co-authored-by: Shivangi Reja <[email protected]>
- Loading branch information
1 parent
1678667
commit 215ca78
Showing
16 changed files
with
1,165 additions
and
525 deletions.
There are no files selected for viewing
96 changes: 37 additions & 59 deletions
96
...nfiguration/Azure.Data.AppConfiguration/api/Azure.Data.AppConfiguration.netstandard2.0.cs
Large diffs are not rendered by default.
Oops, something went wrong.
305 changes: 226 additions & 79 deletions
305
sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient.cs
Large diffs are not rendered by default.
Oops, something went wrong.
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
108 changes: 108 additions & 0 deletions
108
sdk/appconfiguration/Azure.Data.AppConfiguration/src/CreateSnapshotOperation.cs
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,108 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Globalization; | ||
using System.Text.Json; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Azure.Core; | ||
using Azure.Core.Pipeline; | ||
|
||
namespace Azure.Data.AppConfiguration | ||
{ | ||
/// <summary> | ||
/// A long-running operation for <see cref="ConfigurationClient.CreateSnapshot(WaitUntil, string, ConfigurationSettingsSnapshot, CancellationToken)"/> | ||
/// or <see cref="ConfigurationClient.CreateSnapshotAsync(WaitUntil, string, ConfigurationSettingsSnapshot, CancellationToken)"/>. | ||
/// </summary> | ||
public class CreateSnapshotOperation : Operation<ConfigurationSettingsSnapshot> | ||
{ | ||
private readonly ClientDiagnostics _diagnostics; | ||
private Operation<BinaryData> _operation; | ||
private readonly string _id; | ||
private static readonly TimeSpan s_defaultPollingInterval = TimeSpan.FromSeconds(5); | ||
|
||
/// <summary> | ||
/// Gets the <see cref="ConfigurationSettingsSnapshot"/>. This snapshot will have a status of | ||
/// <see cref="SnapshotStatus.Provisioning"/> until the operation has completed. | ||
/// </summary> | ||
public override ConfigurationSettingsSnapshot Value => ConfigurationSettingsSnapshot.FromResponse(_operation.GetRawResponse()); | ||
|
||
/// <inheritdoc/> | ||
public override bool HasValue => _operation.HasValue; | ||
|
||
/// <inheritdoc/> | ||
public override string Id => _id; | ||
|
||
/// <inheritdoc/> | ||
public override bool HasCompleted => _operation.HasCompleted; | ||
|
||
internal CreateSnapshotOperation(string snapshotName) | ||
{ | ||
_id = snapshotName; | ||
} | ||
|
||
internal CreateSnapshotOperation(string snapshotName, ClientDiagnostics diagnostics, Operation<BinaryData> operation) | ||
: this(snapshotName) | ||
{ | ||
_diagnostics = diagnostics; | ||
_operation = operation; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of <see cref="CreateSnapshotOperation"/> for mocking. | ||
/// </summary> | ||
protected CreateSnapshotOperation() { } | ||
|
||
/// <inheritdoc/> | ||
public override Response GetRawResponse() | ||
{ | ||
return _operation.GetRawResponse(); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override Response UpdateStatus(CancellationToken cancellationToken = default) => UpdateStatusAsync(false, cancellationToken).EnsureCompleted(); | ||
|
||
/// <inheritdoc/> | ||
public override async ValueTask<Response> UpdateStatusAsync(CancellationToken cancellationToken = default) => await UpdateStatusAsync(true, cancellationToken).ConfigureAwait(false); | ||
|
||
/// <inheritdoc /> | ||
public override ValueTask<Response<ConfigurationSettingsSnapshot>> WaitForCompletionAsync(CancellationToken cancellationToken = default) => | ||
this.DefaultWaitForCompletionAsync(s_defaultPollingInterval, cancellationToken); | ||
|
||
/// <inheritdoc /> | ||
public override ValueTask<Response<ConfigurationSettingsSnapshot>> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken) => | ||
this.DefaultWaitForCompletionAsync(pollingInterval, cancellationToken); | ||
|
||
private async ValueTask<Response> UpdateStatusAsync(bool async, CancellationToken cancellationToken) | ||
{ | ||
if (!_operation.HasCompleted) | ||
{ | ||
using DiagnosticScope? scope = _diagnostics?.CreateScope($"{nameof(CreateSnapshotOperation)}.{nameof(UpdateStatus)}"); | ||
scope?.Start(); | ||
|
||
try | ||
{ | ||
Response update; | ||
if (async) | ||
{ | ||
update = await _operation.UpdateStatusAsync(cancellationToken).ConfigureAwait(false); | ||
} | ||
else | ||
{ | ||
update = _operation.UpdateStatus(cancellationToken); | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
scope?.Failed(e); | ||
throw; | ||
} | ||
} | ||
|
||
return GetRawResponse(); | ||
} | ||
} | ||
} |
Oops, something went wrong.