-
Notifications
You must be signed in to change notification settings - Fork 133
Feature/solr integration #802
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
Merged
aaronpowell
merged 16 commits into
CommunityToolkit:main
from
Chicoo:feature/solr-integration
Sep 4, 2025
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1047d84
Added Solr Hosting to community toolkit
Chicoo 2374f07
Added Solr Hosting to community toolkit
Chicoo 6ed7f4c
feat: Complete Solr hosting integration with core name support and he…
Chicoo 0006590
refactor: Simplify Solr health check implementation
Chicoo 8599f30
Merge branch 'CommunityToolkit:main' into feature/solr-integration
Chicoo f37111e
Update src/CommunityToolkit.Aspire.Hosting.Solr/SolrBuilderExtensions.cs
Chicoo d2f0646
Fixed code error
Chicoo 9c01783
Update src/CommunityToolkit.Aspire.Hosting.Solr/CommunityToolkit.Aspi…
Chicoo fbdc885
Update src/CommunityToolkit.Aspire.Hosting.Solr/CommunityToolkit.Aspi…
Chicoo bbb00eb
Update src/CommunityToolkit.Aspire.Hosting.Solr/CommunityToolkit.Aspi…
Chicoo a71546d
Update src/CommunityToolkit.Aspire.Hosting.Solr/SolrBuilderExtensions.cs
Chicoo 0fbff98
Updated after code review comments.
016c387
Merge branch 'main' into feature/solr-integration
Chicoo e328d57
Merge branch 'main' into feature/solr-integration
aaronpowell ef81ad2
Removed empty file as healthcheck has moved to SolrBuilderExtensions
d42e4ba
Merge branch 'main' into feature/solr-integration
aaronpowell 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 hidden or 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 hidden or 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
19 changes: 19 additions & 0 deletions
19
examples/solr/CommunityToolkit.Aspire.Hosting.Solr.AppHost.csproj
This file contains hidden or 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,19 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <Sdk Name="Aspire.AppHost.Sdk" Version="$(AspireAppHostSdkVersion)"/> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <IsAspireHost>true</IsAspireHost> | ||
| <UserSecretsId>bfe6b134-1a06-4449-a146-ba3cdb0d02a6</UserSecretsId> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Aspire.Hosting.AppHost" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="../../src/CommunityToolkit.Aspire.Hosting.Solr/CommunityToolkit.Aspire.Hosting.Solr.csproj" IsAspireProjectResource="false" /> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or 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,14 @@ | ||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| // Add Solr resource with default core name "solr" | ||
| var solr = builder.AddSolr("solr"); | ||
|
|
||
| // Add Solr resource with custom port and core name | ||
| var solrWithCustomPort = builder.AddSolr("solr-custom", port: 8984, coreName: "mycore"); | ||
|
|
||
| // Reference the Solr resources in a project (example) | ||
| // var exampleProject = builder.AddProject<Projects.ExampleProject>() | ||
| // .WithReference(solr) | ||
| // .WithReference(solrWithCustomPort); | ||
|
|
||
| builder.Build().Run(); |
9 changes: 9 additions & 0 deletions
9
src/CommunityToolkit.Aspire.Hosting.Solr/CommunityToolkit.Aspire.Hosting.Solr.csproj
This file contains hidden or 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,9 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <Description>A .NET Aspire hosting integration for Apache Solr.</Description> | ||
| <PackageTags>solr search hosting</PackageTags> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Aspire.Hosting" /> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or 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,42 @@ | ||
| # CommunityToolkit.Aspire.Hosting.Solr | ||
|
|
||
| This package provides a .NET Aspire hosting integration for [Apache Solr](https://solr.apache.org/), enabling you to add and configure a Solr container as part of your distributed application. | ||
|
|
||
| ## Getting Started | ||
|
|
||
| ### Install the package | ||
|
|
||
| In your AppHost project, install the package using the following command: | ||
|
|
||
| ```dotnetcli | ||
| dotnet add package CommunityToolkit.Aspire.Hosting.Solr | ||
| ``` | ||
|
|
||
| ## Usage Example | ||
|
|
||
| ```csharp | ||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| // Add Solr resource with default settings (port 8983, core "solr") | ||
| var solr = builder.AddSolr("solr"); | ||
|
|
||
| // Add Solr with custom port | ||
| var solrWithCustomPort = builder.AddSolr("solr-custom", port: 8984); | ||
|
|
||
| // Add Solr with custom core name | ||
| var solrWithCustomCore = builder.AddSolr("solr-core", coreName: "mycore"); | ||
|
|
||
| // Add Solr with both custom port and core name | ||
| var solrCustom = builder.AddSolr("solr-full", port: 8985, coreName: "documents"); | ||
|
|
||
| // Reference the Solr resource in a project | ||
| var exampleProject = builder.AddProject<Projects.ExampleProject>() | ||
| .WithReference(solr); | ||
|
|
||
| // Initialize and run the application | ||
| builder.Build().Run(); | ||
| ``` | ||
|
|
||
| ## Feedback & contributing | ||
|
|
||
| https://github.com/dotnet/aspire |
49 changes: 49 additions & 0 deletions
49
src/CommunityToolkit.Aspire.Hosting.Solr/SolrBuilderExtensions.cs
This file contains hidden or 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,49 @@ | ||
| using Aspire.Hosting.ApplicationModel; | ||
| using CommunityToolkit.Aspire.Hosting.Solr; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| namespace Aspire.Hosting; | ||
|
|
||
| /// <summary> | ||
| /// Extension methods for adding and configuring a Solr resource. | ||
| /// </summary> | ||
| public static class SolrBuilderExtensions | ||
| { | ||
| /// <summary> | ||
| /// Adds an Apache Solr container resource to the distributed application. | ||
| /// </summary> | ||
| /// <param name="builder">The <see cref="IDistributedApplicationBuilder"/>.</param> | ||
| /// <param name="name">The name of the resource. This name will be used as the connection string name when referenced in a dependency.</param> | ||
| /// <param name="port">The host port for Solr.</param> | ||
| /// <param name="coreName">The name of the core to create.</param> | ||
| /// <returns>A reference to the <see cref="IResourceBuilder{SolrResource}"/>.</returns> | ||
| public static IResourceBuilder<SolrResource> AddSolr(this IDistributedApplicationBuilder builder, [ResourceName] string name, int? port = null, string? coreName = null) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(builder); | ||
| ArgumentException.ThrowIfNullOrEmpty(name); | ||
|
|
||
| coreName ??= "solr"; | ||
|
|
||
| var resource = new SolrResource(name, coreName); | ||
|
|
||
| var solrBuilder = builder.AddResource(resource) | ||
| .WithImage(SolrContainerImageTags.Image, SolrContainerImageTags.Tag) | ||
| .WithImageRegistry(SolrContainerImageTags.Registry) | ||
| .WithHttpEndpoint(targetPort: 8983, port: port, name: SolrResource.PrimaryEndpointName) | ||
| .WithArgs("solr-precreate", coreName); | ||
|
|
||
| string healthCheckKey = $"{name}_check"; | ||
| var endpoint = solrBuilder.Resource.GetEndpoint(SolrResource.PrimaryEndpointName); | ||
|
|
||
| builder.Services.AddHealthChecks() | ||
| .AddUrlGroup(options => | ||
| { | ||
| var uri = new Uri(endpoint.Url); | ||
| options.AddUri(new Uri(uri, $"solr/{coreName}/admin/ping"), setup => setup.ExpectHttpCode(200)); | ||
| }, healthCheckKey); | ||
|
|
||
| solrBuilder.WithHealthCheck(healthCheckKey); | ||
|
|
||
| return solrBuilder; | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/CommunityToolkit.Aspire.Hosting.Solr/SolrContainerImageTags.cs
This file contains hidden or 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,11 @@ | ||
| namespace CommunityToolkit.Aspire.Hosting.Solr; | ||
|
|
||
| internal static class SolrContainerImageTags | ||
| { | ||
| /// <summary>docker.io</summary> | ||
| public const string Registry = "docker.io"; | ||
| /// <summary>solr</summary> | ||
| public const string Image = "solr"; | ||
| /// <summary>9.7</summary> | ||
| public const string Tag = "9.7"; | ||
| } |
This file contains hidden or 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,32 @@ | ||
| using Aspire.Hosting.ApplicationModel; | ||
|
|
||
| namespace Aspire.Hosting.ApplicationModel; | ||
|
|
||
| /// <summary> | ||
| /// Represents an Apache Solr container resource. | ||
| /// </summary> | ||
| /// <param name="name">The name of the resource.</param> | ||
| /// <param name="coreName">The name of the Solr core.</param> | ||
| public class SolrResource(string name, string coreName) : ContainerResource(name), IResourceWithConnectionString | ||
| { | ||
| internal const string PrimaryEndpointName = "http"; | ||
|
|
||
| private EndpointReference? _primaryEndpoint; | ||
|
|
||
| /// <summary> | ||
| /// The Solr core name. | ||
| /// </summary> | ||
| public string CoreName { get; set; } = coreName; | ||
|
|
||
| /// <summary> | ||
| /// Gets the primary endpoint for the Solr server. | ||
| /// </summary> | ||
| public EndpointReference PrimaryEndpoint => _primaryEndpoint ??= new(this, PrimaryEndpointName); | ||
|
|
||
| /// <summary> | ||
| /// Gets the connection string expression for the Solr server. | ||
| /// </summary> | ||
| public ReferenceExpression ConnectionStringExpression => ReferenceExpression.Create( | ||
| $"http://{PrimaryEndpoint.Property(EndpointProperty.Host)}:{PrimaryEndpoint.Property(EndpointProperty.Port)}/solr/{CoreName}"); | ||
|
|
||
| } | ||
25 changes: 25 additions & 0 deletions
25
src/CommunityToolkit.Aspire.Hosting.Solr/api/CommunityToolkit.Aspire.Hosting.Solr.cs
This file contains hidden or 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,25 @@ | ||
| //------------------------------------------------------------------------------ | ||
| // <auto-generated> | ||
| // This code was generated by a tool. | ||
| // | ||
| // Changes to this file may cause incorrect behavior and will be lost if | ||
| // the code is regenerated. | ||
| // </auto-generated> | ||
| //------------------------------------------------------------------------------ | ||
| namespace Aspire.Hosting | ||
| { | ||
| public static partial class SolrBuilderExtensions | ||
| { | ||
| public static ApplicationModel.IResourceBuilder<ApplicationModel.SolrResource> AddSolr(this IDistributedApplicationBuilder builder, string name, int? port = null, string? coreName = null) { throw null; } | ||
| } | ||
| } | ||
| namespace Aspire.Hosting.ApplicationModel | ||
| { | ||
| public partial class SolrResource : ContainerResource, IResourceWithConnectionString, IResource, IManifestExpressionProvider, IValueProvider, IValueWithReferences | ||
| { | ||
| public SolrResource(string name, string coreName) : base(default!, default) { } | ||
| public string CoreName { get { throw null; } set { } } | ||
| public ReferenceExpression ConnectionStringExpression { get { throw null; } } | ||
| public EndpointReference PrimaryEndpoint { get { throw null; } } | ||
| } | ||
| } |
62 changes: 62 additions & 0 deletions
62
tests/CommunityToolkit.Aspire.Hosting.Solr.Tests/AppHostTests.cs
This file contains hidden or 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,62 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Net; | ||
| using Aspire.Components.Common.Tests; | ||
| using CommunityToolkit.Aspire.Testing; | ||
|
|
||
| namespace CommunityToolkit.Aspire.Hosting.Solr.Tests; | ||
|
|
||
| [RequiresDocker] | ||
| public class AppHostTests(AspireIntegrationTestFixture<Projects.CommunityToolkit_Aspire_Hosting_Solr_AppHost> fixture) : IClassFixture<AspireIntegrationTestFixture<Projects.CommunityToolkit_Aspire_Hosting_Solr_AppHost>> | ||
| { | ||
| [Fact] | ||
| public async Task SolrResourceStartsAndRespondsOk() | ||
| { | ||
| var resourceName = "solr"; | ||
| await fixture.ResourceNotificationService.WaitForResourceHealthyAsync(resourceName).WaitAsync(TimeSpan.FromMinutes(5)); | ||
| var httpClient = fixture.CreateHttpClient(resourceName); | ||
|
|
||
| var response = await httpClient.GetAsync("/solr/"); | ||
|
|
||
| Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task SolrResourceWithCustomPortStartsAndRespondsOk() | ||
| { | ||
| var resourceName = "solr-custom"; | ||
| await fixture.ResourceNotificationService.WaitForResourceHealthyAsync(resourceName).WaitAsync(TimeSpan.FromMinutes(5)); | ||
| var httpClient = fixture.CreateHttpClient(resourceName); | ||
|
|
||
| var response = await httpClient.GetAsync("/solr/"); | ||
|
|
||
| Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task SolrCoreIsHealthy() | ||
| { | ||
| var resourceName = "solr"; | ||
| await fixture.ResourceNotificationService.WaitForResourceHealthyAsync(resourceName).WaitAsync(TimeSpan.FromMinutes(5)); | ||
| var httpClient = fixture.CreateHttpClient(resourceName); | ||
|
|
||
| // Test that the specific core admin ping endpoint works | ||
| var response = await httpClient.GetAsync("/solr/solr/admin/ping"); | ||
|
|
||
| Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task SolrCustomCoreIsHealthy() | ||
| { | ||
| var resourceName = "solr-custom"; | ||
| await fixture.ResourceNotificationService.WaitForResourceHealthyAsync(resourceName).WaitAsync(TimeSpan.FromMinutes(5)); | ||
| var httpClient = fixture.CreateHttpClient(resourceName); | ||
|
|
||
| // Test that the custom core admin ping endpoint works | ||
| var response = await httpClient.GetAsync("/solr/mycore/admin/ping"); | ||
|
|
||
| Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
...munityToolkit.Aspire.Hosting.Solr.Tests/CommunityToolkit.Aspire.Hosting.Solr.Tests.csproj
This file contains hidden or 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,9 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\examples\solr\CommunityToolkit.Aspire.Hosting.Solr.AppHost.csproj" /> | ||
| <ProjectReference Include="..\..\src\CommunityToolkit.Aspire.Hosting.Solr\CommunityToolkit.Aspire.Hosting.Solr.csproj" /> | ||
| <ProjectReference Include="..\CommunityToolkit.Aspire.Testing\CommunityToolkit.Aspire.Testing.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
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.
Uh oh!
There was an error while loading. Please reload this page.