Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MetricsAdvisor] Fixed UpdateHook methods #21559

Merged
merged 11 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ public MetricsAdvisorAdministrationClient(System.Uri endpoint, Azure.Core.TokenC
public virtual System.Threading.Tasks.Task<Azure.Response> UpdateDataFeedAsync(string dataFeedId, Azure.AI.MetricsAdvisor.Models.DataFeed dataFeed, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response UpdateDetectionConfiguration(string detectionConfigurationId, Azure.AI.MetricsAdvisor.Models.AnomalyDetectionConfiguration detectionConfiguration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response> UpdateDetectionConfigurationAsync(string detectionConfigurationId, Azure.AI.MetricsAdvisor.Models.AnomalyDetectionConfiguration detectionConfiguration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response UpdateHook(string hookId, Azure.AI.MetricsAdvisor.Models.NotificationHook hook, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response> UpdateHookAsync(string hookId, Azure.AI.MetricsAdvisor.Models.NotificationHook hook, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.AI.MetricsAdvisor.Models.NotificationHook> UpdateHook(Azure.AI.MetricsAdvisor.Models.NotificationHook hook, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.MetricsAdvisor.Models.NotificationHook>> UpdateHookAsync(Azure.AI.MetricsAdvisor.Models.NotificationHook hook, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
kinelski marked this conversation as resolved.
Show resolved Hide resolved
}
}
namespace Azure.AI.MetricsAdvisor.Models
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1588,22 +1588,27 @@ public virtual Response<NotificationHook> CreateHook(NotificationHook hook, Canc
}

/// <summary>
/// Updates an existing <see cref="NotificationHook"/>.
/// Updates an existing <see cref="NotificationHook"/>. In order to update your hook, you cannot create a <see cref="NotificationHook"/>
/// directly from its constructor. You need to obtain an instance via <see cref="GetHookAsync"/> or another CRUD operation and update it
/// before calling this method.
/// </summary>
/// <param name="hookId">The ID of the existing <see cref="NotificationHook"/> to update.</param>
/// <param name="hook">The <see cref="NotificationHook"/> model containing the updates to be applied.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <returns>
/// A <see cref="Response"/> containing the result of the operation.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="hookId"/> or <paramref name="hook"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="hookId"/> is empty or not a valid GUID.</exception>
public virtual async Task<Response> UpdateHookAsync(string hookId, NotificationHook hook, CancellationToken cancellationToken = default)
/// <exception cref="ArgumentNullException"><paramref name="hook"/> or <paramref name="hook"/>.Id is null.</exception>
public virtual async Task<Response<NotificationHook>> UpdateHookAsync(NotificationHook hook, CancellationToken cancellationToken = default)
{
/*
Guid hookGuid = ClientCommon.ValidateGuid(hookId, nameof(hookId));
Argument.AssertNotNull(hook, nameof(hook));

if (hook.Id == null)
{
throw new ArgumentNullException(nameof(hook), $"{nameof(hook)}.Id not available. Call {nameof(GetHookAsync)} and update the returned model before calling this method.");
}

Guid hookGuid = new Guid(hook.Id);

using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(MetricsAdvisorAdministrationClient)}.{nameof(UpdateHook)}");
scope.Start();

Expand All @@ -1618,29 +1623,30 @@ public virtual async Task<Response> UpdateHookAsync(string hookId, NotificationH
scope.Failed(e);
throw;
}
*/

await Task.CompletedTask.ConfigureAwait(false);
return default;
}

/// <summary>
/// Updates an existing <see cref="NotificationHook"/>.
/// Updates an existing <see cref="NotificationHook"/>. In order to update your hook, you cannot create a <see cref="NotificationHook"/>
/// directly from its constructor. You need to obtain an instance via <see cref="GetHook"/> or another CRUD operation and update it
/// before calling this method.
/// </summary>
/// <param name="hookId">The ID of the existing <see cref="NotificationHook"/> to update.</param>
/// <param name="hook">The <see cref="NotificationHook"/> model containing the updates to be applied.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <returns>
/// A <see cref="Response"/> containing the result of the operation.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="hookId"/> or <paramref name="hook"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="hookId"/> is empty or not a valid GUID.</exception>
public virtual Response UpdateHook(string hookId, NotificationHook hook, CancellationToken cancellationToken = default)
/// <exception cref="ArgumentNullException"><paramref name="hook"/> or <paramref name="hook"/>.Id is null.</exception>
public virtual Response<NotificationHook> UpdateHook(NotificationHook hook, CancellationToken cancellationToken = default)
{
/*
Guid hookGuid = ClientCommon.ValidateGuid(hookId, nameof(hookId));
Argument.AssertNotNull(hook, nameof(hook));

if (hook.Id == null)
{
throw new ArgumentNullException(nameof(hook), $"{nameof(hook)}.Id not available. Call {nameof(GetHook)} and update the returned model before calling this method.");
}

Guid hookGuid = new Guid(hook.Id);

using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(MetricsAdvisorAdministrationClient)}.{nameof(UpdateHook)}");
scope.Start();

Expand All @@ -1655,9 +1661,6 @@ public virtual Response UpdateHook(string hookId, NotificationHook hook, Cancell
scope.Failed(e);
throw;
}
*/

return default;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Generic;

namespace Azure.AI.MetricsAdvisor.Models
{
internal partial class EmailHookParameterPatch
{
public IList<string> ToList { get; internal set; }
kinelski marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Generic;

namespace Azure.AI.MetricsAdvisor.Models
{
internal partial class WebhookHookParameterPatch
{
public IDictionary<string, string> Headers { get; internal set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,33 @@ internal NotificationHook(HookType hookType, string id, string name, string desc

internal static HookInfoPatch GetPatchModel(NotificationHook hook)
{
return hook switch
HookInfoPatch patch = hook switch
kinelski marked this conversation as resolved.
Show resolved Hide resolved
{
EmailNotificationHook h => new EmailHookInfoPatch() { HookName = h.Name, Description = h.Description, ExternalLink = h.ExternalLink?.AbsoluteUri, /*HookParameter = h.HookParameter,*/ Admins = h.Administrators },
WebNotificationHook h => new WebhookHookInfoPatch() { HookName = h.Name, Description = h.Description, ExternalLink = h.ExternalLink?.AbsoluteUri, /*HookParameter = h.HookParameter,*/ Admins = h.Administrators },
_ => throw new InvalidOperationException("Unknown AlertingHook type.")
EmailNotificationHook h => new EmailHookInfoPatch()
{
HookParameter = new() { ToList = h.EmailsToAlert }
},
WebNotificationHook h => new WebhookHookInfoPatch()
{
HookParameter = new()
{
Endpoint = h.Endpoint?.AbsoluteUri,
Username = h.Username,
Password = h.Password,
CertificateKey = h.CertificateKey,
CertificatePassword = h.CertificatePassword,
Headers = h.Headers
}
},
_ => throw new InvalidOperationException("Unknown hook type.")
};

patch.HookName = hook.Name;
patch.Description = hook.Description;
patch.ExternalLink = hook.ExternalLink?.AbsoluteUri;
patch.Admins = hook.Administrators;

return patch;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ public async Task CreateAndGetWebNotificationHookWithOptionalMembers()
[RecordedTest]
[TestCase(true)]
[TestCase(false)]
[Ignore("https://github.com/Azure/azure-sdk-for-net/issues/21177")]
public async Task UpdateEmailNotificationHookWithMinimumSetupAndGetInstance(bool useTokenCredential)
{
// Create a hook.
Expand All @@ -198,7 +197,7 @@ public async Task UpdateEmailNotificationHookWithMinimumSetupAndGetInstance(bool

hookToUpdate.EmailsToAlert.Add("fake3@email.com");

await adminClient.UpdateHookAsync(disposableHook.Id, hookToUpdate);
await adminClient.UpdateHookAsync(hookToUpdate);
kinelski marked this conversation as resolved.
Show resolved Hide resolved

// Get the hook and check if updates are in place.

Expand Down Expand Up @@ -239,7 +238,7 @@ public async Task UpdateEmailNotificationHookWithMinimumSetupAndNewInstance()

hookToUpdate.EmailsToAlert.Add("fake3@email.com");

await adminClient.UpdateHookAsync(disposableHook.Id, hookToUpdate);
await adminClient.UpdateHookAsync(hookToUpdate);

// Get the hook and check if updates are in place.

Expand All @@ -255,7 +254,6 @@ public async Task UpdateEmailNotificationHookWithMinimumSetupAndNewInstance()
}

[RecordedTest]
[Ignore("https://github.com/Azure/azure-sdk-for-net/issues/21177")]
public async Task UpdateEmailNotificationHookWithEveryMemberAndGetInstance()
{
// Create a hook.
Expand All @@ -281,7 +279,7 @@ public async Task UpdateEmailNotificationHookWithEveryMemberAndGetInstance()
hookToUpdate.ExternalLink = new Uri("http://fake.endpoint.com/");
hookToUpdate.EmailsToAlert.Add("fake3@email.com");

await adminClient.UpdateHookAsync(disposableHook.Id, hookToUpdate);
await adminClient.UpdateHookAsync(hookToUpdate);

// Get the hook and check if updates are in place.

Expand Down Expand Up @@ -327,7 +325,7 @@ public async Task UpdateEmailNotificationHookWithEveryMemberAndNewInstance()

hookToUpdate.EmailsToAlert.Add("fake3@email.com");

await adminClient.UpdateHookAsync(disposableHook.Id, hookToUpdate);
await adminClient.UpdateHookAsync(hookToUpdate);

// Get the hook and check if updates are in place.

Expand All @@ -343,7 +341,7 @@ public async Task UpdateEmailNotificationHookWithEveryMemberAndNewInstance()
}

[RecordedTest]
[Ignore("https://github.com/Azure/azure-sdk-for-net/issues/21177")]
[Ignore("https://github.com/Azure/azure-sdk-for-net/issues/21504")]
kinelski marked this conversation as resolved.
Show resolved Hide resolved
public async Task UpdateWebNotificationHookWithMinimumSetupAndGetInstance()
{
// Create a hook.
Expand All @@ -362,7 +360,7 @@ public async Task UpdateWebNotificationHookWithMinimumSetupAndGetInstance()

hookToUpdate.Username = "fakeUsername";

await adminClient.UpdateHookAsync(disposableHook.Id, hookToUpdate);
await adminClient.UpdateHookAsync(hookToUpdate);

// Get the hook and check if updates are in place.

Expand All @@ -384,7 +382,7 @@ public async Task UpdateWebNotificationHookWithMinimumSetupAndGetInstance()
}

[RecordedTest]
[Ignore("https://github.com/Azure/azure-sdk-for-net/issues/21177")]
[Ignore("https://github.com/Azure/azure-sdk-for-net/issues/21504")]
public async Task UpdateWebNotificationHookWithMinimumSetupAndNewInstance()
{
// Create a hook.
Expand All @@ -402,7 +400,7 @@ public async Task UpdateWebNotificationHookWithMinimumSetupAndNewInstance()

var hookToUpdate = new WebNotificationHook() { Endpoint = endpoint, Username = "fakeUsername" };

await adminClient.UpdateHookAsync(disposableHook.Id, hookToUpdate);
await adminClient.UpdateHookAsync(hookToUpdate);

// Get the hook and check if updates are in place.

Expand All @@ -424,7 +422,7 @@ public async Task UpdateWebNotificationHookWithMinimumSetupAndNewInstance()
}

[RecordedTest]
[Ignore("https://github.com/Azure/azure-sdk-for-net/issues/21177")]
[Ignore("https://github.com/Azure/azure-sdk-for-net/issues/21504")]
public async Task UpdateWebNotificationHookWithEveryMemberAndGetInstance()
{
// Create a hook.
Expand Down Expand Up @@ -460,7 +458,7 @@ public async Task UpdateWebNotificationHookWithEveryMemberAndGetInstance()
hookToUpdate.Headers.Add(header);
}

await adminClient.UpdateHookAsync(disposableHook.Id, hookToUpdate);
await adminClient.UpdateHookAsync(hookToUpdate);

// Get the hook and check if updates are in place.

Expand All @@ -482,7 +480,7 @@ public async Task UpdateWebNotificationHookWithEveryMemberAndGetInstance()
}

[RecordedTest]
[Ignore("https://github.com/Azure/azure-sdk-for-net/issues/21177")]
[Ignore("https://github.com/Azure/azure-sdk-for-net/issues/21504")]
public async Task UpdateWebNotificationHookWithEveryMemberAndNewInstance()
{
// Create a hook.
Expand Down Expand Up @@ -520,7 +518,7 @@ public async Task UpdateWebNotificationHookWithEveryMemberAndNewInstance()
hookToUpdate.Headers.Add(header);
}

await adminClient.UpdateHookAsync(disposableHook.Id, hookToUpdate);
await adminClient.UpdateHookAsync(hookToUpdate);

// Get the hook and check if updates are in place.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,37 +81,33 @@ public void CreateHookRespectsTheCancellationToken()
}

[Test]
[Ignore("https://github.com/Azure/azure-sdk-for-net/issues/21177")]
public void UpdateHookValidatesArguments()
{
MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

var hook = new EmailNotificationHook();

Assert.That(() => adminClient.UpdateHookAsync(null, hook), Throws.InstanceOf<ArgumentNullException>());
Assert.That(() => adminClient.UpdateHookAsync("", hook), Throws.InstanceOf<ArgumentException>());
Assert.That(() => adminClient.UpdateHookAsync("hookId", hook), Throws.InstanceOf<ArgumentException>().With.InnerException.TypeOf(typeof(FormatException)));
Assert.That(() => adminClient.UpdateHookAsync(FakeGuid, null), Throws.InstanceOf<ArgumentNullException>());
Assert.That(() => adminClient.UpdateHookAsync(null), Throws.InstanceOf<ArgumentNullException>());
Assert.That(() => adminClient.UpdateHook(null), Throws.InstanceOf<ArgumentNullException>());

Assert.That(() => adminClient.UpdateHook(null, hook), Throws.InstanceOf<ArgumentNullException>());
Assert.That(() => adminClient.UpdateHook("", hook), Throws.InstanceOf<ArgumentException>());
Assert.That(() => adminClient.UpdateHook("hookId", hook), Throws.InstanceOf<ArgumentException>().With.InnerException.TypeOf(typeof(FormatException)));
Assert.That(() => adminClient.UpdateHook(FakeGuid, null), Throws.InstanceOf<ArgumentNullException>());
var hookWithNullId = new EmailNotificationHook();

Assert.That(() => adminClient.UpdateHookAsync(hookWithNullId), Throws.InstanceOf<ArgumentNullException>());
Assert.That(() => adminClient.UpdateHook(hookWithNullId), Throws.InstanceOf<ArgumentNullException>());
}

[Test]
[Ignore("https://github.com/Azure/azure-sdk-for-net/issues/21177")]
public void UpdateHookRespectsTheCancellationToken()
{
MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

var hook = new EmailNotificationHook();
var hook = new EmailNotificationHook(default, FakeGuid, default, default, default, new List<string>(), new EmailHookParameter(new List<string>()));

using var cancellationSource = new CancellationTokenSource();
cancellationSource.Cancel();

Assert.That(() => adminClient.UpdateHookAsync(FakeGuid, hook, cancellationSource.Token), Throws.InstanceOf<OperationCanceledException>());
Assert.That(() => adminClient.UpdateHook(FakeGuid, hook, cancellationSource.Token), Throws.InstanceOf<OperationCanceledException>());
Assert.That(() => adminClient.UpdateHookAsync(hook, cancellationSource.Token), Throws.InstanceOf<OperationCanceledException>());
Assert.That(() => adminClient.UpdateHook(hook, cancellationSource.Token), Throws.InstanceOf<OperationCanceledException>());
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ public async Task UpdateHookAsync()
string originalDescription = hook.Description;
hook.Description = "This description was generated by a sample.";

await adminClient.UpdateHookAsync(hookId, hook);
await adminClient.UpdateHookAsync(hook);

// Undo the changes to leave the hook unaltered. Skip this step if you intend to keep
kinelski marked this conversation as resolved.
Show resolved Hide resolved
// the changes.

hook.Description = originalDescription;
await adminClient.UpdateHookAsync(hookId, hook);
await adminClient.UpdateHookAsync(hook);
}

[Test]
Expand Down
Loading