Skip to content

Commit

Permalink
[AppConfiguration] Snapshot API Updates (Azure#34583)
Browse files Browse the repository at this point in the history
* 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
m-redding and ShivangiReja authored Apr 4, 2023
1 parent 1678667 commit 215ca78
Show file tree
Hide file tree
Showing 16 changed files with 1,165 additions and 525 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public ConfigurationClientOptions(ServiceVersion version = LatestVersion)
Version = version switch
{
ServiceVersion.V1_0 => "1.0",
// ServiceVersion.V2022_11_01_Preview => "2022-11-01-preview",
//ServiceVersion.V2022_11_01_Preview => "2022-11-01-preview",

_ => throw new NotSupportedException()
};
Expand Down
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();
}
}
}
Loading

0 comments on commit 215ca78

Please sign in to comment.