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

Event Grid Explorer - Adding Support for Event Grid V2 #737

Merged
merged 27 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f87a0d9
Event Grid Explorer - Adding support for Event Grid V2 in Service Bus…
t-wangamy Aug 16, 2023
cdd396b
Merge branch 'main' of https://github.com/paolosalvatori/ServiceBusEx…
t-wangamy Aug 16, 2023
e8e6791
Event Grid Explorer
t-wangamy Aug 16, 2023
b11b0c1
Event Grid Explorer
t-wangamy Aug 16, 2023
f0ad8fe
Event Grid Explorer
t-wangamy Aug 18, 2023
afe8a98
Wording
SeanFeldman Aug 18, 2023
38d75ec
Event Grid Explorer
t-wangamy Aug 18, 2023
e5b1c2a
Merge branch 'EventGridExplorer' of https://github.com/paolosalvatori…
t-wangamy Aug 18, 2023
7a7c463
Adhare to the license in the repo
SeanFeldman Nov 3, 2023
96e96e1
Fall back to the default API version
SeanFeldman Nov 5, 2023
f174fb4
Change tenantId
ErikMogensen Nov 7, 2023
5a76072
Added api-version commit
ErikMogensen Nov 7, 2023
bbc7b45
Change tenantId when logging in
ErikMogensen Nov 7, 2023
74bc13d
Merge pull request #747 from ErikMogensen/EventGridLogin
paolosalvatori Nov 9, 2023
8207abc
Improve UI event grid explorer (#752)
ErikMogensen Nov 20, 2023
fd86d19
Using Control plane sdk instead of generated files
harrieoriowo May 6, 2024
764e8cb
Finishing up the sdks
harrieoriowo May 16, 2024
2797407
Adding Filter UI
harrieoriowo May 20, 2024
a366114
Allowing multiple filters
harrieoriowo May 21, 2024
b7c3f54
Refining the explorer with proper error handling and the filters acce…
harrieoriowo May 25, 2024
e143794
Merge branch 'main' into EventGridExplorer
harrieoriowo May 25, 2024
1d43822
Resolving comments
harrieoriowo May 29, 2024
f1ed2e4
Merge branch 'EventGridExplorer' of https://github.com/paolosalvatori…
harrieoriowo May 29, 2024
46113e7
Resolving comments
harrieoriowo May 29, 2024
274791e
Removing custom exception and moving logic into filterfactory
harrieoriowo May 30, 2024
b45d3d5
Handling build warnings
harrieoriowo Jun 6, 2024
59b24b9
Build warnings resolved
harrieoriowo Jun 10, 2024
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
54 changes: 54 additions & 0 deletions src/Common/Helpers/EventGridException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#region Copyright
//=======================================================================================
// Microsoft Azure Customer Advisory Team
//
// This sample is supplemental to the technical guidance published on my personal
// blog at http://blogs.msdn.com/b/paolos/.
//
// Author: Paolo Salvatori
//=======================================================================================
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// LICENSED UNDER THE APACHE LICENSE, VERSION 2.0 (THE "LICENSE"); YOU MAY NOT USE THESE
// FILES EXCEPT IN COMPLIANCE WITH THE LICENSE. YOU MAY OBTAIN A COPY OF THE LICENSE AT
// http://www.apache.org/licenses/LICENSE-2.0
// UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, SOFTWARE DISTRIBUTED UNDER THE
// LICENSE IS DISTRIBUTED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, EITHER EXPRESS OR IMPLIED. SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING
// PERMISSIONS AND LIMITATIONS UNDER THE LICENSE.
//=======================================================================================
#endregion

#region Using Directives

using System;

#endregion


namespace ServiceBusExplorer.Helpers
{
public class EventGridException : Exception
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question - what does this custom exception type bring that is not handled by Exception?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to make this custom exception so I can throw them without having to hit the client and have the client throw the exception.

Copy link
Collaborator

@SeanFeldman SeanFeldman May 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must have missed that use. Could you point to where it's used? Thanks.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found it here. That use is on the form. When an exception is thrown, the form logs it and swallows the exception. But with EventGrid, you're going to throw? Could you help me understand why it would need to be re-thrown?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea for the user experience is that I can check the format of the filter key, operator and value and verify them without depending on the armclient to do the verification.
Yes, the form will log the error, but it will still go ahead and still hit the client.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be missing something and would love to meet today to resolve it if possible.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be missing something and would love to meet today to resolve it if possible.

Let's continue the discussion at the method level comments, no need for a meeting 🙂

{
#region Public constructors
/// <summary>
/// Initializes a new instance of the <see cref="EventGridException"/> class.
/// </summary>
/// <param name="message">Message</param>
/// <param name="innerException">Inner exception</param>
public EventGridException(
string message,
Exception innerException = null)
: base(message, innerException)
{
FullMessage = message;
}

/// <summary>
/// Gets the full message of the exception.
/// </summary>
public string FullMessage { get; }
#endregion

}
}
13 changes: 4 additions & 9 deletions src/EventGridExplorerLibrary/EventGridLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public EventGridLibrary(string subscriptionId, string apiVersion, int maxWaitTim

public async Task<Response<EventGridNamespaceResource>> GetNamespacesAsync(string resourceGroupName, string namespaceName)
{
var eventGridNamespace = await eventGridControlPlaneClient.GetNamespaceResource(resourceGroupName, namespaceName).GetAsync();
return eventGridNamespace;
return await eventGridControlPlaneClient.GetNamespaceResource(resourceGroupName, namespaceName).GetAsync();
}


Expand Down Expand Up @@ -122,22 +121,18 @@ public async Task<ReceiveResult> ReceiveEventsAsync(string topicName, string sub
{
try
{
Response<ReceiveResult> result;

if (this.maxWaitTime < MinWaitTimeInSeconds)
{
result = await dataPlaneClients[topicName].ReceiveCloudEventsAsync(topicName, subscriptionName, maxEvents: maxEventNum, maxWaitTime: TimeSpan.FromSeconds(MinWaitTimeInSeconds));
return await dataPlaneClients[topicName].ReceiveCloudEventsAsync(topicName, subscriptionName, maxEvents: maxEventNum, maxWaitTime: TimeSpan.FromSeconds(MinWaitTimeInSeconds));
}
else if (this.maxWaitTime > MaxWaitTimeInSeconds)
{
result = await dataPlaneClients[topicName].ReceiveCloudEventsAsync(topicName, subscriptionName, maxEvents: maxEventNum, maxWaitTime: TimeSpan.FromSeconds(MaxWaitTimeInSeconds));
return await dataPlaneClients[topicName].ReceiveCloudEventsAsync(topicName, subscriptionName, maxEvents: maxEventNum, maxWaitTime: TimeSpan.FromSeconds(MaxWaitTimeInSeconds));
}
else
{
result = await dataPlaneClients[topicName].ReceiveCloudEventsAsync(topicName, subscriptionName, maxEvents: maxEventNum, maxWaitTime: TimeSpan.FromSeconds(this.maxWaitTime));
return await dataPlaneClients[topicName].ReceiveCloudEventsAsync(topicName, subscriptionName, maxEvents: maxEventNum, maxWaitTime: TimeSpan.FromSeconds(this.maxWaitTime));
}

return result;
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) Microsoft. All rights reserved.
// </copyright>

namespace Microsoft.Azure.Management.EventGridV2
namespace EventGridExplorerLibrary
{
using System;
using System.Collections.Generic;
Expand All @@ -28,28 +28,6 @@ public class EventGridControlPlaneClient : IEventGridControlPlaneClient
private readonly string tenantId;
public ArmClient armclient;

private Dictionary<string, EventGridFilter> filterOperatorMap = new Dictionary<string, EventGridFilter> {
{"Boolean equals", new BoolEqualsFilter()},
{"String is in", new StringInFilter()},
{"String is not in", new StringNotInFilter()},
{"String contains", new StringContainsFilter()},
{"String does not contain", new StringNotContainsFilter()},
{"String begins with", new StringBeginsWithFilter()},
{"String does not begin with", new StringNotBeginsWithFilter()},
{"String ends with", new StringEndsWithFilter()},
{"String does not end with", new StringNotEndsWithFilter()},
{"Number is less than", new NumberLessThanFilter()},
{"Number is greater than", new NumberGreaterThanFilter()},
{"Number is less than or equal to", new NumberLessThanOrEqualsFilter()},
{"Number is greater than or equal to", new NumberGreaterThanOrEqualsFilter()},
{"Number is in", new NumberInFilter()},
{"Number is not in", new NumberNotInFilter()},
{"Number is in range", new NumberInRangeFilter()},
{"Number is not in range", new NumberNotInRangeFilter()},
{"Is null or undefined", new IsNullOrUndefinedFilter()},
{"Is not null", new IsNotNullFilter()},
};

/// <summary>
/// Initializes a new instance of the <see cref="EventGridClient"/> class.
/// </summary>
Expand Down Expand Up @@ -131,8 +109,8 @@ public async Task<string> CreateNamespaceTopicEventSubscriptionAsync(string reso
NamespaceTopicEventSubscriptionCollection collection = namespaceTopicResource.GetNamespaceTopicEventSubscriptions();
NamespaceTopicEventSubscriptionData namespaceTopicEventSubscriptionData = new NamespaceTopicEventSubscriptionData();

FiltersConfiguration filtersConfiguration = GetFiltersConfiguration(filters, eventTypes);
if (filtersConfiguration.IncludedEventTypes.Count > 0)
FiltersConfiguration filtersConfiguration = GetFiltersConfiguration(filters, eventTypes);
if (filtersConfiguration.IncludedEventTypes.Count > 0 || filtersConfiguration.Filters.Count > 0)
{
namespaceTopicEventSubscriptionData.DeliveryConfiguration = new DeliveryConfiguration
{
Expand Down Expand Up @@ -203,13 +181,32 @@ private string CreateArmId(string subscriptionId, string resourceGroupName)
private FiltersConfiguration GetFiltersConfiguration(List<Dictionary<string, string>> filters, List<string> eventTypes)
{
FiltersConfiguration filtersConfiguration = new FiltersConfiguration();
EventGridFilterValues eventGridFilterValues = new EventGridFilterValues();
harrieoriowo marked this conversation as resolved.
Show resolved Hide resolved

foreach (Dictionary<string, string> i in filters)
{
EventGridFilter filter = filterOperatorMap[i["Operator"].ToString()];
filter.Key = i["Key"].ToString();

filtersConfiguration.Filters.Add(filter);
var operatorType = i["Operator"].ToString();
var value = i["Value"].ToString();
var key = i["Key"].ToString();
if (operatorType.Equals("Boolean equals")) { var filter = new BoolEqualsFilter(); filter.Key = key; eventGridFilterValues.GetValueForBoolEqualsFilter(filter, value); filtersConfiguration.Filters.Add(filter); };
if (operatorType.Equals("String is in")) { var filter = new StringInFilter(); filter.Key = key; eventGridFilterValues.GetValueForStringInFilter(filter, value); filtersConfiguration.Filters.Add(filter); };
if (operatorType.Equals("String is not in")) { var filter = new StringNotInFilter(); filter.Key = key; eventGridFilterValues.GetValueForStringNotInFilter(filter, value); filtersConfiguration.Filters.Add(filter); };
if (operatorType.Equals("String contains")) { var filter = new StringContainsFilter(); filter.Key = key; eventGridFilterValues.GetValueForStringContainsFilter(filter, value); filtersConfiguration.Filters.Add(filter); };
if (operatorType.Equals("String does not contain")) { var filter = new StringNotContainsFilter(); filter.Key = key; eventGridFilterValues.GetValueForStringNotContainsFilter(filter, value); filtersConfiguration.Filters.Add(filter); };
if (operatorType.Equals("String begins with")) { var filter = new StringBeginsWithFilter(); filter.Key = key; eventGridFilterValues.GetValueForStringBeginsWithFilter(filter, value); filtersConfiguration.Filters.Add(filter); };
if (operatorType.Equals("String does not begin with")) { var filter = new StringNotBeginsWithFilter(); filter.Key = key; eventGridFilterValues.GetValueForStringNotBeginsWithFilter(filter, value); filtersConfiguration.Filters.Add(filter); };
if (operatorType.Equals("String ends with")) { var filter = new StringEndsWithFilter(); filter.Key = key; eventGridFilterValues.GetValueForStringEndsWithFilter(filter, value); filtersConfiguration.Filters.Add(filter); };
if (operatorType.Equals("String does not end with")) { var filter = new StringNotEndsWithFilter(); filter.Key = key; eventGridFilterValues.GetValueForStringNotEndsWithFilter(filter, value); filtersConfiguration.Filters.Add(filter); };
if (operatorType.Equals("Number is less than")) { var filter = new NumberLessThanFilter(); filter.Key = key; eventGridFilterValues.GetValueForNumberLessThanFilter(filter, value); filtersConfiguration.Filters.Add(filter); };
if (operatorType.Equals("Number is greater than")) { var filter = new NumberGreaterThanFilter(); filter.Key = key; eventGridFilterValues.GetValueForNumberGreaterThanFilter(filter, value); filtersConfiguration.Filters.Add(filter); };
if (operatorType.Equals("Number is less than or equal to")) { var filter = new NumberLessThanOrEqualsFilter(); filter.Key = key; eventGridFilterValues.GetValueForNumberLessThanOrEqualsFilter(filter, value); filtersConfiguration.Filters.Add(filter); };
if (operatorType.Equals("Number is greater than or equal to")) { var filter = new NumberGreaterThanOrEqualsFilter(); filter.Key = key; eventGridFilterValues.GetValueForNumberGreaterThanOrEqualsFilter(filter, value); filtersConfiguration.Filters.Add(filter); };
if (operatorType.Equals("Number is in")) { var filter = new NumberInFilter(); filter.Key = key; eventGridFilterValues.GetValueForNumberInFilter(filter, value); filtersConfiguration.Filters.Add(filter); };
if (operatorType.Equals("Number is not in")) { var filter = new NumberNotInFilter(); filter.Key = key; eventGridFilterValues.GetValueForNumberNotInFilter(filter, value); filtersConfiguration.Filters.Add(filter); };
if (operatorType.Equals("Number is in range")) { var filter = new NumberInRangeFilter(); filter.Key = key; eventGridFilterValues.GetValueForNumberInRangeFilter(filter, value); filtersConfiguration.Filters.Add(filter); };
if (operatorType.Equals("Number is not in range")) { var filter = new NumberNotInRangeFilter(); filter.Key = key; eventGridFilterValues.GetValueForNumberNotInRangeFilter(filter, value); filtersConfiguration.Filters.Add(filter); };
if (operatorType.Equals("Is null or undefined")) { var filter = new IsNullOrUndefinedFilter(); filter.Key = key; filtersConfiguration.Filters.Add(filter); };
if (operatorType.Equals("Is not null")) { var filter = new IsNotNullFilter(); filter.Key = key; filtersConfiguration.Filters.Add(filter);};
}

if (eventTypes.Count > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) Microsoft. All rights reserved.
// </copyright>

namespace Microsoft.Azure.Management.EventGridV2
namespace EventGridExplorerLibrary
{
using System.Collections.Generic;
using System.Threading.Tasks;
Expand Down
162 changes: 162 additions & 0 deletions src/EventGridExplorerLibrary/Management/EventGridFilterValues.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
// <copyright file="EventGridClient.cs" company="Microsoft">
// Copyright (c) Microsoft. All rights reserved.
// </copyright>

namespace EventGridExplorerLibrary
{
using System.Collections.Generic;
using global::Azure.ResourceManager.EventGrid.Models;

/// <summary>
/// Implementation of the EventGridFilterValues class
harrieoriowo marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public class EventGridFilterValues
{

/// <summary>
/// Initializes a new instance of the <see cref="EventGridFilterValues"/> class.
/// </summary>
public EventGridFilterValues()
{
}

/// <inheritdoc/>
public void GetValueForBoolEqualsFilter(BoolEqualsFilter filter, string value)
{
filter.Value = bool.Parse(value);
}

public void GetValueForStringInFilter(StringInFilter filter, string value)
{
string[] filterValuesList = value.Split(',');
foreach (string filterValue in filterValuesList)
{
filter.Values.Add(filterValue);
}
}

public void GetValueForStringNotInFilter(StringNotInFilter filter, string value)
{
string[] filterValuesList = value.Split(',');
foreach (string filterValue in filterValuesList)
{
filter.Values.Add(filterValue);
}
}

public void GetValueForStringContainsFilter(StringContainsFilter filter, string value)
{
string[] filterValuesList = value.Split(',');
foreach (string filterValue in filterValuesList)
{
filter.Values.Add(filterValue);
}
}

public void GetValueForStringNotContainsFilter(StringNotContainsFilter filter, string value)
{
string[] filterValuesList = value.Split(',');
foreach (string filterValue in filterValuesList)
{
filter.Values.Add(filterValue);
}
}
harrieoriowo marked this conversation as resolved.
Show resolved Hide resolved
public void GetValueForStringBeginsWithFilter(StringBeginsWithFilter filter, string value)
{
string[] filterValuesList = value.Split(',');
foreach (string filterValue in filterValuesList)
{
filter.Values.Add(filterValue);
}
}
public void GetValueForStringNotBeginsWithFilter(StringNotBeginsWithFilter filter, string value)
{
string[] filterValuesList = value.Split(',');
foreach (string filterValue in filterValuesList)
{
filter.Values.Add(filterValue);
}
}
public void GetValueForStringEndsWithFilter(StringEndsWithFilter filter, string value)
{
string[] filterValuesList = value.Split(',');
foreach (string filterValue in filterValuesList)
{
filter.Values.Add(filterValue);
}
}
public void GetValueForStringNotEndsWithFilter(StringNotEndsWithFilter filter, string value)
{
string[] filterValuesList = value.Split(',');
foreach (string filterValue in filterValuesList)
{
filter.Values.Add(filterValue);
}
}
public void GetValueForNumberLessThanFilter(NumberLessThanFilter filter, string value)
{
filter.Value = double.Parse(value);
}
public void GetValueForNumberGreaterThanFilter(NumberGreaterThanFilter filter, string value)
{
filter.Value = double.Parse(value);
}
public void GetValueForNumberLessThanOrEqualsFilter(NumberLessThanOrEqualsFilter filter, string value)
{
filter.Value = double.Parse(value);
}
public void GetValueForNumberGreaterThanOrEqualsFilter(NumberGreaterThanOrEqualsFilter filter, string value)
{
filter.Value = double.Parse(value);
}
public void GetValueForNumberInFilter(NumberInFilter filter, string value)
{
string[] filterValuesList = value.Split(',');
foreach (string filterValue in filterValuesList)
{
filter.Values.Add(double.Parse(filterValue));
}
}
public void GetValueForNumberNotInFilter(NumberNotInFilter filter, string value)
{
string[] filterValuesList = value.Split(',');
foreach (string filterValue in filterValuesList)
{
filter.Values.Add(double.Parse(filterValue));
}
}

public void GetValueForNumberNotInRangeFilter(NumberNotInRangeFilter filter, string value)
{
string[] filterValuesList = value.Split(',');

foreach (string filterValue in filterValuesList)
{
List<double> doubleRangeValues = new List<double>();
var rangeValues = filterValue.Split('-');
foreach (string rangeValue in rangeValues)
{
doubleRangeValues.Add(double.Parse(rangeValue));
}
filter.Values.Add(doubleRangeValues);
}
}
public void GetValueForNumberInRangeFilter(NumberInRangeFilter filter, string value)
{
string[] filterValuesList = value.Split(',');

foreach (string filterValue in filterValuesList)
{
List<double> doubleRangeValues = new List<double>();
var rangeValues = filterValue.Split('-');
foreach (string rangeValue in rangeValues)
{
doubleRangeValues.Add(double.Parse(rangeValue));
}
filter.Values.Add(doubleRangeValues);
}

}

}
}
Loading
Loading