Skip to content

Commit

Permalink
add elasticsearch hosting (#4430)
Browse files Browse the repository at this point in the history
* add elasticsearch hosting
  • Loading branch information
Alirexaa authored Jul 18, 2024
1 parent 640c450 commit 5c7f578
Show file tree
Hide file tree
Showing 44 changed files with 2,000 additions and 4 deletions.
50 changes: 48 additions & 2 deletions Aspire.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
Expand Down Expand Up @@ -492,16 +491,32 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.Azure.WebPub
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.Valkey", "src\Aspire.Hosting.Valkey\Aspire.Hosting.Valkey.csproj", "{5CB63205-24F4-4388-A41B-BAF3BEA59866}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "withdockerfile", "withdockerfile", "{A6813855-E322-41EF-B2E6-7A44949EF962}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.Elasticsearch", "src\Aspire.Hosting.Elasticsearch\Aspire.Hosting.Elasticsearch.csproj", "{9357EC71-823B-433A-9993-B7CB2FA082D1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Elastic.Clients.Elasticsearch", "src\Components\Aspire.Elastic.Clients.Elasticsearch\Aspire.Elastic.Clients.Elasticsearch.csproj", "{3F7B206E-5457-458F-AA81-9449FA3C1B5C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Elasticsearch", "Elasticsearch", "{6C71A90C-30AE-45D7-9347-D66F9B257CBE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elasticsearch.ApiService", "playground\Elasticsearch\Elasticsearch.ApiService\Elasticsearch.ApiService.csproj", "{F7F57331-5DDD-444A-A620-8639FC9362B2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elasticsearch.AppHost", "playground\Elasticsearch\Elasticsearch.AppHost\Elasticsearch.AppHost.csproj", "{569B8215-BDB1-445D-A7BA-DB255700A4AC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dockerfile", "dockerfile", "{A6813855-E322-41EF-B2E6-7A44949EF962}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "withdockerfile", "withdockerfile", "{5B5DC91B-5754-4CE5-B3C0-FA1584B916A0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WithDockerfile.AppHost", "playground\withdockerfile\WithDockerfile.AppHost\WithDockerfile.AppHost.csproj", "{E6BE41D3-872C-47D2-B5B1-78C37AFAEAF9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.Containers.Tests", "tests\Aspire.Hosting.Containers.Tests\Aspire.Hosting.Containers.Tests.csproj", "{588CD2D7-EE70-43C1-8233-330854BDF53C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Elastic.Clients.Elasticsearch.Tests", "tests\Aspire.Elastic.Clients.Elasticsearch.Tests\Aspire.Elastic.Clients.Elasticsearch.Tests.csproj", "{D5B392A4-29CD-41F9-8847-0C211C832713}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "python", "python", "{7123AB7A-A4FD-4F64-8B05-D2DD0C3E2ABC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.AppHost", "playground\python\Python.AppHost\Python.AppHost.csproj", "{173BDA6E-F175-4457-BF64-58CD184E9A81}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.Elasticsearch.Tests", "tests\Aspire.Hosting.Elasticsearch.Tests\Aspire.Hosting.Elasticsearch.Tests.csproj", "{62D8C73C-DAB3-4B9E-A508-34C886C374F9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Components", "Components", "{C424395C-1235-41A4-BF55-07880A04368C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Hosting", "Hosting", "{830A89EC-4029-4753-B25A-068BAE37DEC7}"
Expand Down Expand Up @@ -1320,6 +1335,22 @@ Global
{5CB63205-24F4-4388-A41B-BAF3BEA59866}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5CB63205-24F4-4388-A41B-BAF3BEA59866}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5CB63205-24F4-4388-A41B-BAF3BEA59866}.Release|Any CPU.Build.0 = Release|Any CPU
{9357EC71-823B-433A-9993-B7CB2FA082D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9357EC71-823B-433A-9993-B7CB2FA082D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9357EC71-823B-433A-9993-B7CB2FA082D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9357EC71-823B-433A-9993-B7CB2FA082D1}.Release|Any CPU.Build.0 = Release|Any CPU
{3F7B206E-5457-458F-AA81-9449FA3C1B5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3F7B206E-5457-458F-AA81-9449FA3C1B5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3F7B206E-5457-458F-AA81-9449FA3C1B5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3F7B206E-5457-458F-AA81-9449FA3C1B5C}.Release|Any CPU.Build.0 = Release|Any CPU
{F7F57331-5DDD-444A-A620-8639FC9362B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F7F57331-5DDD-444A-A620-8639FC9362B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7F57331-5DDD-444A-A620-8639FC9362B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7F57331-5DDD-444A-A620-8639FC9362B2}.Release|Any CPU.Build.0 = Release|Any CPU
{569B8215-BDB1-445D-A7BA-DB255700A4AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{569B8215-BDB1-445D-A7BA-DB255700A4AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{569B8215-BDB1-445D-A7BA-DB255700A4AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{569B8215-BDB1-445D-A7BA-DB255700A4AC}.Release|Any CPU.Build.0 = Release|Any CPU
{E6BE41D3-872C-47D2-B5B1-78C37AFAEAF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E6BE41D3-872C-47D2-B5B1-78C37AFAEAF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E6BE41D3-872C-47D2-B5B1-78C37AFAEAF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -1328,10 +1359,18 @@ Global
{588CD2D7-EE70-43C1-8233-330854BDF53C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{588CD2D7-EE70-43C1-8233-330854BDF53C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{588CD2D7-EE70-43C1-8233-330854BDF53C}.Release|Any CPU.Build.0 = Release|Any CPU
{D5B392A4-29CD-41F9-8847-0C211C832713}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D5B392A4-29CD-41F9-8847-0C211C832713}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D5B392A4-29CD-41F9-8847-0C211C832713}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D5B392A4-29CD-41F9-8847-0C211C832713}.Release|Any CPU.Build.0 = Release|Any CPU
{173BDA6E-F175-4457-BF64-58CD184E9A81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{173BDA6E-F175-4457-BF64-58CD184E9A81}.Debug|Any CPU.Build.0 = Debug|Any CPU
{173BDA6E-F175-4457-BF64-58CD184E9A81}.Release|Any CPU.ActiveCfg = Release|Any CPU
{173BDA6E-F175-4457-BF64-58CD184E9A81}.Release|Any CPU.Build.0 = Release|Any CPU
{62D8C73C-DAB3-4B9E-A508-34C886C374F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{62D8C73C-DAB3-4B9E-A508-34C886C374F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{62D8C73C-DAB3-4B9E-A508-34C886C374F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{62D8C73C-DAB3-4B9E-A508-34C886C374F9}.Release|Any CPU.Build.0 = Release|Any CPU
{1BC02557-B78B-48CE-9D3C-488A6B7672F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1BC02557-B78B-48CE-9D3C-488A6B7672F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1BC02557-B78B-48CE-9D3C-488A6B7672F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -1591,11 +1630,18 @@ Global
{9FAE1602-2C69-4D24-8655-A164489441E8} = {C424395C-1235-41A4-BF55-07880A04368C}
{DF00FDA3-D3EC-4E07-B4EC-0EBB57A813A4} = {77CFE74A-32EE-400C-8930-5025E8555256}
{5CB63205-24F4-4388-A41B-BAF3BEA59866} = {B80354C7-BE58-43F6-8928-9F3A74AB7F47}
{9357EC71-823B-433A-9993-B7CB2FA082D1} = {B80354C7-BE58-43F6-8928-9F3A74AB7F47}
{3F7B206E-5457-458F-AA81-9449FA3C1B5C} = {27381127-6C45-4B4C-8F18-41FF48DFE4B2}
{6C71A90C-30AE-45D7-9347-D66F9B257CBE} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
{F7F57331-5DDD-444A-A620-8639FC9362B2} = {6C71A90C-30AE-45D7-9347-D66F9B257CBE}
{569B8215-BDB1-445D-A7BA-DB255700A4AC} = {6C71A90C-30AE-45D7-9347-D66F9B257CBE}
{A6813855-E322-41EF-B2E6-7A44949EF962} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
{E6BE41D3-872C-47D2-B5B1-78C37AFAEAF9} = {A6813855-E322-41EF-B2E6-7A44949EF962}
{588CD2D7-EE70-43C1-8233-330854BDF53C} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
{D5B392A4-29CD-41F9-8847-0C211C832713} = {C424395C-1235-41A4-BF55-07880A04368C}
{7123AB7A-A4FD-4F64-8B05-D2DD0C3E2ABC} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
{173BDA6E-F175-4457-BF64-58CD184E9A81} = {7123AB7A-A4FD-4F64-8B05-D2DD0C3E2ABC}
{62D8C73C-DAB3-4B9E-A508-34C886C374F9} = {830A89EC-4029-4753-B25A-068BAE37DEC7}
{C424395C-1235-41A4-BF55-07880A04368C} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
{830A89EC-4029-4753-B25A-068BAE37DEC7} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
{1BC02557-B78B-48CE-9D3C-488A6B7672F4} = {830A89EC-4029-4753-B25A-068BAE37DEC7}
Expand Down
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<PackageVersion Include="Confluent.Kafka" Version="2.4.0" />
<PackageVersion Include="Dapper" Version="2.1.44" />
<PackageVersion Include="DnsClient" Version="1.8.0" />
<PackageVersion Include="Elastic.Clients.Elasticsearch" Version="8.14.4" />
<PackageVersion Include="Google.Protobuf" Version="3.27.1" />
<PackageVersion Include="Grpc.AspNetCore" Version="2.63.0" />
<PackageVersion Include="Grpc.Net.ClientFactory" Version="2.63.0" />
Expand Down Expand Up @@ -154,7 +155,7 @@
<PackageVersion Include="Testcontainers.Redis" Version="$(TestcontainersPackageVersion)" />
<PackageVersion Include="Testcontainers.Nats" Version="$(TestcontainersPackageVersion)" />
<PackageVersion Include="Testcontainers.Milvus" Version="$(TestcontainersPackageVersion)" />

<PackageVersion Include="Testcontainers.Elasticsearch" Version="$(TestcontainersPackageVersion)" />
<!-- playground apps dependencies -->
<PackageVersion Include="Dapr.AspNetCore" Version="1.13.1" />
<PackageVersion Include="Microsoft.Orleans.Clustering.AzureStorage" Version="8.2.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Components\Aspire.Elastic.Clients.Elasticsearch\Aspire.Elastic.Clients.Elasticsearch.csproj" />
<ProjectReference Include="..\..\Playground.ServiceDefaults\Playground.ServiceDefaults.csproj" />
</ItemGroup>
</Project>
10 changes: 10 additions & 0 deletions playground/Elasticsearch/Elasticsearch.ApiService/Models/Person.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Elasticsearch.ApiService.Models;

public class Person
{
public required string FirstName { get; set; }
public required string LastName { get; set; }
}
39 changes: 39 additions & 0 deletions playground/Elasticsearch/Elasticsearch.ApiService/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Elastic.Clients.Elasticsearch;
using Elasticsearch.ApiService.Models;

var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();

builder.AddElasticsearchClient("elasticsearch");

var app = builder.Build();

app.MapGet("/get", async (ElasticsearchClient elasticClient) =>
{
var response = await elasticClient.GetAsync<Person>("people", "1");
return response;
});

app.MapGet("/create", async (ElasticsearchClient elasticClient) =>
{
var exist = await elasticClient.Indices.ExistsAsync("people");
if (exist.Exists)
{
await elasticClient.Indices.DeleteAsync("people");
}
var person = new Person
{
FirstName = "Alireza",
LastName = "Baloochi"
};
var response = await elasticClient.IndexAsync<Person>(person, "people", "1");
return response;
});

app.Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:4855",
"sslPort": 44376
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5053",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7158;http://localhost:5053",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>

<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<!-- NOTE: This line is only required because we are using P2P references, not NuGet. It will not exist in real apps. -->
<Import Project="../../../src/Aspire.Hosting.AppHost/build/Aspire.Hosting.AppHost.props" />

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project>

<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" />

<!-- NOTE: These lines are only required because we are using P2P references, not NuGet. They will not exist in real apps. -->
<Import Project="..\..\..\src\Aspire.Hosting.AppHost\build\Aspire.Hosting.AppHost.targets" />
<Import Project="..\..\..\src\Aspire.Hosting.Sdk\SDK\Sdk.targets" />

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>76c9a20b-a2cc-4874-8d26-6fbe827d11bf</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Aspire.Dashboard\Aspire.Dashboard.csproj" />
<ProjectReference Include="..\..\..\src\Aspire.Hosting.AppHost\Aspire.Hosting.AppHost.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\..\..\src\Aspire.Hosting.Elasticsearch\Aspire.Hosting.Elasticsearch.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\Elasticsearch.ApiService\Elasticsearch.ApiService.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(SharedDir)KnownResourceNames.cs" Link="KnownResourceNames.cs" />
</ItemGroup>
</Project>
19 changes: 19 additions & 0 deletions playground/Elasticsearch/Elasticsearch.AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

var builder = DistributedApplication.CreateBuilder(args);

var elasticsearch = builder.AddElasticsearch("elasticsearch")
.WithDataVolume();

builder.AddProject<Projects.Elasticsearch_ApiService>("elasticsearch-apiservice")
.WithReference(elasticsearch);

// This project is only added in playground projects to support development/debugging
// of the dashboard. It is not required in end developer code. Comment out this code
// to test end developer dashboard launch experience. Refer to Directory.Build.props
// for the path to the dashboard binary (defaults to the Aspire.Dashboard bin output
// in the artifacts dir).
builder.AddProject<Projects.Aspire_Dashboard>(KnownResourceNames.AspireDashboard);

builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17196;http://localhost:15122",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21146",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22194"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15122",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19117",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20104"
}
},
"generate-manifest": {
"commandName": "Project",
"launchBrowser": true,
"dotnetRunMessages": true,
"commandLineArgs": "--publisher manifest --output-path aspire-manifest.json",
"applicationUrl": "http://localhost:15122",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
}
}
Loading

0 comments on commit 5c7f578

Please sign in to comment.