-
Notifications
You must be signed in to change notification settings - Fork 524
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
Add custom application model for EventHubs emulator #7005
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ebb6645
Add custom application model for EventHubs emulator
sebastienros c2c3424
Update doc
sebastienros f3aded3
Merge branch 'main' into sebros/eventhubsmodel
sebastienros fd36a41
Use CreateTempSubdirectory
sebastienros 77fbc9c
Merge branch 'main' into sebros/eventhubsmodel
sebastienros 00a5fd1
Apply suggestions
sebastienros a667a7a
Increase SB timeouts
sebastienros dbe2c26
Improve config.json implementation
sebastienros 1ff9b22
Update docs
sebastienros 283b511
Increase timeout for flaky test
sebastienros 71238be
Fix configuration
sebastienros 454fb7c
Fix build
sebastienros 86ad563
Improve tests
sebastienros c8edd15
Filter events
sebastienros File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
222 changes: 163 additions & 59 deletions
222
src/Aspire.Hosting.Azure.EventHubs/AzureEventHubsExtensions.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
20 changes: 20 additions & 0 deletions
20
src/Aspire.Hosting.Azure.EventHubs/ConfigJsonAnnotation.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,20 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Text.Json.Nodes; | ||
using Aspire.Hosting.ApplicationModel; | ||
|
||
namespace Aspire.Hosting.Azure.EventHubs; | ||
|
||
/// <summary> | ||
/// Represents an annotation for updating the JSON content of a mounted document. | ||
/// </summary> | ||
internal sealed class ConfigJsonAnnotation : IResourceAnnotation | ||
{ | ||
public ConfigJsonAnnotation(Action<JsonNode> configure) | ||
{ | ||
Configure = configure; | ||
} | ||
|
||
public Action<JsonNode> Configure { get; } | ||
} |
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,101 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Text.Json; | ||
using Azure.Provisioning; | ||
|
||
namespace Aspire.Hosting.Azure.EventHubs; | ||
|
||
/// <summary> | ||
/// Represents an Event Hub. | ||
/// </summary> | ||
/// <remarks> | ||
/// Use <see cref="AzureProvisioningResourceExtensions.ConfigureInfrastructure{T}(ApplicationModel.IResourceBuilder{T}, Action{AzureResourceInfrastructure})"/> to configure specific <see cref="Azure.Provisioning"/> properties. | ||
/// </remarks> | ||
public class EventHub | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="EventHub"/> class. | ||
/// </summary> | ||
public EventHub(string name) | ||
{ | ||
Name = name; | ||
} | ||
|
||
/// <summary> | ||
/// The event hub name. | ||
/// </summary> | ||
public string Name { get; set; } | ||
|
||
/// <summary> | ||
/// Number of partitions created for the Event Hub, allowed values are from | ||
/// 1 to 32 partitions. | ||
/// </summary> | ||
public long? PartitionCount { get; set; } | ||
|
||
/// <summary> | ||
/// The consumer groups for this hub. | ||
/// </summary> | ||
public List<EventHubConsumerGroup> ConsumerGroups { get; } = []; | ||
|
||
/// <summary> | ||
/// Converts the current instance to a provisioning entity. | ||
/// </summary> | ||
/// <returns>A <see cref="global::Azure.Provisioning.EventHubs.EventHub"/> instance.</returns> | ||
internal global::Azure.Provisioning.EventHubs.EventHub ToProvisioningEntity() | ||
{ | ||
var hub = new global::Azure.Provisioning.EventHubs.EventHub(Infrastructure.NormalizeBicepIdentifier(Name)); | ||
|
||
hub.Name = Name; | ||
|
||
if (PartitionCount.HasValue) | ||
{ | ||
hub.PartitionCount = PartitionCount.Value; | ||
} | ||
|
||
return hub; | ||
} | ||
|
||
/// <summary> | ||
/// Converts the current instance to a JSON object. | ||
/// </summary> | ||
/// <param name="writer">The Utf8JsonWriter to write the JSON object to.</param> | ||
internal void WriteJsonObjectProperties(Utf8JsonWriter writer) | ||
{ | ||
var hub = this; | ||
|
||
writer.WriteString(nameof(Name), hub.Name); | ||
|
||
if (hub.PartitionCount.HasValue) | ||
{ | ||
writer.WriteNumber(nameof(PartitionCount), hub.PartitionCount.Value); | ||
} | ||
else | ||
{ | ||
// Value is required. We don't assign it by default in case | ||
// we need to detect if the value was never set or if the defaults | ||
// in Azure.Provisioning change. | ||
|
||
writer.WriteNumber(nameof(PartitionCount), 1); | ||
} | ||
|
||
#pragma warning disable CA1507 // Use nameof to express symbol names: there is no direct link between the property name and the JSON representation | ||
writer.WriteStartArray("ConsumerGroups"); | ||
|
||
// The default consumer group ('$default') is automatically created by the | ||
// emulator. We don't need to create it explicitly. | ||
|
||
if (hub.ConsumerGroups.Count >= 0) | ||
{ | ||
foreach (var consumerGroup in hub.ConsumerGroups) | ||
{ | ||
writer.WriteStartObject(); | ||
consumerGroup.WriteJsonObjectProperties(writer); | ||
writer.WriteEndObject(); | ||
} | ||
} | ||
writer.WriteEndArray(); | ||
} | ||
#pragma warning restore CA1507 // Use nameof to express symbol names | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
src/Aspire.Hosting.Azure.EventHubs/EventHubConsumerGroup.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,51 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Text.Json; | ||
using Azure.Provisioning; | ||
|
||
namespace Aspire.Hosting.Azure.EventHubs; | ||
|
||
/// <summary> | ||
/// Represents a Consumer Group. | ||
/// </summary> | ||
/// <remarks> | ||
/// Use <see cref="AzureProvisioningResourceExtensions.ConfigureInfrastructure{T}(ApplicationModel.IResourceBuilder{T}, Action{AzureResourceInfrastructure})"/> to configure specific <see cref="Azure.Provisioning"/> properties. | ||
/// </remarks> | ||
public class EventHubConsumerGroup | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="EventHubConsumerGroup"/> class. | ||
/// </summary> | ||
public EventHubConsumerGroup(string name) | ||
{ | ||
Name = name; | ||
} | ||
|
||
/// <summary> | ||
/// The event hub name. | ||
/// </summary> | ||
public string Name { get; set; } | ||
|
||
/// <summary> | ||
/// Converts the current instance to a provisioning entity. | ||
/// </summary> | ||
/// <returns>A <see cref="global::Azure.Provisioning.EventHubs.EventHub"/> instance.</returns> | ||
internal global::Azure.Provisioning.EventHubs.EventHubsConsumerGroup ToProvisioningEntity() | ||
{ | ||
var consumerGroup = new global::Azure.Provisioning.EventHubs.EventHubsConsumerGroup(Infrastructure.NormalizeBicepIdentifier(Name)); | ||
|
||
consumerGroup.Name = Name; | ||
|
||
return consumerGroup; | ||
} | ||
|
||
/// <summary> | ||
/// Converts the current instance to a JSON object. | ||
/// </summary> | ||
/// <param name="writer">The Utf8JsonWriter to write the JSON object to.</param> | ||
internal void WriteJsonObjectProperties(Utf8JsonWriter writer) | ||
sebastienros marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
writer.WriteString(nameof(Name), Name); | ||
} | ||
} |
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "a mounted document" mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Config.json file (json document) that is mounted to the container using ContainerMountType.BindMount.