Skip to content

Commit

Permalink
feat: or-1349 add rebuild en status endpoints for projections
Browse files Browse the repository at this point in the history
  • Loading branch information
QuintenGreenstack committed Dec 7, 2023
1 parent 5849ada commit b1b5c2b
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static IServiceCollection ConfigureElasticSearch(
this IServiceCollection services,
ElasticSearchOptionsSection elasticSearchOptions)
{
services.AddSingleton(elasticSearchOptions);
var elasticClient = CreateElasticClient(elasticSearchOptions);

ElasticSearchExtensions.EnsureIndexExists(elasticClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace AssociationRegistry.Admin.ProjectionHost.Infrastructure.Program.WebApp
using Marten.Events.Projections;
using Marten.Services;
using Newtonsoft.Json;
using Projections;
using Projections.Detail;
using Projections.Historiek;
using Projections.Search;
Expand Down Expand Up @@ -90,7 +91,7 @@ static JsonNetSerializer CreateCustomMartenSerializer()
)
),
ProjectionLifecycle.Async,
projectionName: "BeheerVerenigingZoekenDocument");
projectionName: ProjectionNames.VerenigingZoeken);

opts.Serializer(CreateCustomMartenSerializer());

Expand Down
47 changes: 45 additions & 2 deletions src/AssociationRegistry.Admin.ProjectionHost/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace AssociationRegistry.Admin.ProjectionHost;

using Be.Vlaanderen.Basisregisters.Aws.DistributedMutex;
using Infrastructure.ConfigurationBindings;
using Infrastructure.Extensions;
using Infrastructure.Json;
using Infrastructure.Program;
using Infrastructure.Program.WebApplication;
Expand All @@ -12,11 +14,17 @@ namespace AssociationRegistry.Admin.ProjectionHost;
using Microsoft.AspNetCore.Mvc.NewtonsoftJson;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Options;
using Nest;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Oakton;
using OpenTelemetry.Extensions;
using Projections;
using Projections.Detail;
using Projections.Historiek;
using Projections.Search;
using Projections.Search.Zoeken;
using Serilog;
using Serilog.Debugging;
using System.Net;
Expand All @@ -31,7 +39,8 @@ public static async Task Main(string[] args)

builder.Configuration
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName.ToLowerInvariant()}.json", optional: true, reloadOnChange: false)
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName.ToLowerInvariant()}.json", optional: true,
reloadOnChange: false)
.AddJsonFile($"appsettings.{Environment.MachineName.ToLowerInvariant()}.json", optional: true, reloadOnChange: false)
.AddEnvironmentVariables()
.AddCommandLine(args);
Expand Down Expand Up @@ -76,14 +85,48 @@ public static async Task Main(string[] args)
var app = builder.Build();

app.MapPost(
pattern: "/rebuild",
pattern: "projections/detail/rebuild",
handler: async (IDocumentStore store, ILogger<Program> logger, CancellationToken cancellationToken) =>
{
var projectionDaemon = await store.BuildProjectionDaemonAsync();
await projectionDaemon.RebuildProjection<BeheerVerenigingDetailProjection>(cancellationToken);
logger.LogInformation("Rebuild complete");
});

app.MapPost(
pattern: "projections/historiek/rebuild",
handler: async (IDocumentStore store, ILogger<Program> logger, CancellationToken cancellationToken) =>
{
var projectionDaemon = await store.BuildProjectionDaemonAsync();
await projectionDaemon.RebuildProjection<BeheerVerenigingHistoriekProjection>(cancellationToken);
logger.LogInformation("Rebuild complete");
});

app.MapPost(
pattern: "projections/search/rebuild",
handler: async (
IDocumentStore store,
IElasticClient elasticClient,
ElasticSearchOptionsSection options,
ILogger<Program> logger,
CancellationToken cancellationToken) =>
{
await elasticClient.Indices.DeleteAsync(options.Indices.Verenigingen, ct: cancellationToken);
elasticClient.Indices.CreateVerenigingIndex(options.Indices.Verenigingen);
await elasticClient.Indices.DeleteAsync(options.Indices.DuplicateDetection, ct: cancellationToken);
elasticClient.Indices.CreateVerenigingIndex(options.Indices.DuplicateDetection);
var projectionDaemon = await store.BuildProjectionDaemonAsync();
await projectionDaemon.RebuildProjection(ProjectionNames.VerenigingZoeken, cancellationToken);
logger.LogInformation("Rebuild complete");
});

app.MapGet(
"projections/status",
async (IDocumentStore store, ILogger<Program> logger, CancellationToken cancellationToken) =>
{
return await store.Advanced.AllProjectionProgress(token: cancellationToken);
});

app.SetUpSwagger();
ConfigureHealtChecks(app);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace AssociationRegistry.Admin.ProjectionHost.Projections;

public class ProjectionNames
{
public const string VerenigingZoeken = "BeheerVerenigingZoekenDocument";
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace AssociationRegistry.Public.ProjectionHost.Infrastructure.Program.WebAp
using Marten.Events.Projections;
using Marten.Services;
using Newtonsoft.Json;
using Projections;
using Projections.Detail;
using Projections.Search;
using Schema.Detail;
Expand Down Expand Up @@ -84,7 +85,7 @@ static JsonNetSerializer CreateCustomMartenSerializer()
)
),
ProjectionLifecycle.Async,
projectionName: "PubliekVerenigingZoekenDocument");
projectionName: ProjectionNames.VerenigingZoeken);

opts.Serializer(CreateCustomMartenSerializer());

Expand Down
29 changes: 28 additions & 1 deletion src/AssociationRegistry.Public.ProjectionHost/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace AssociationRegistry.Public.ProjectionHost;

using Be.Vlaanderen.Basisregisters.Aws.DistributedMutex;
using Infrastructure.ConfigurationBindings;
using Infrastructure.Extensions;
using Infrastructure.Json;
using Infrastructure.Program;
using Infrastructure.Program.WebApplication;
Expand All @@ -12,10 +14,12 @@ namespace AssociationRegistry.Public.ProjectionHost;
using Microsoft.AspNetCore.Mvc.NewtonsoftJson;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Nest;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Oakton;
using OpenTelemetry.Extensions;
using Projections;
using Projections.Detail;
using Projections.Search;
using Serilog;
Expand Down Expand Up @@ -79,14 +83,37 @@ public static async Task Main(string[] args)
var app = builder.Build();

app.MapPost(
pattern: "/rebuild",
pattern: "projections/detail/rebuild",
handler: async (IDocumentStore store, ILogger<Program> logger, CancellationToken cancellationToken) =>
{
var projectionDaemon = await store.BuildProjectionDaemonAsync();
await projectionDaemon.RebuildProjection<PubliekVerenigingDetailProjection>(cancellationToken);
logger.LogInformation("Rebuild complete");
});

app.MapPost(
pattern: "projections/search/rebuild",
handler: async (
IDocumentStore store,
IElasticClient elasticClient,
ElasticSearchOptionsSection options,
ILogger<Program> logger,
CancellationToken cancellationToken) =>
{
await elasticClient.Indices.DeleteAsync(options.Indices.Verenigingen, ct: cancellationToken);
elasticClient.Indices.CreateVerenigingIndex(options.Indices.Verenigingen);

Check warning on line 104 in src/AssociationRegistry.Public.ProjectionHost/Program.cs

View workflow job for this annotation

GitHub Actions / analyze-code

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

Check warning on line 104 in src/AssociationRegistry.Public.ProjectionHost/Program.cs

View workflow job for this annotation

GitHub Actions / Run Tests (test/AssociationRegistry.Test.Admin.Api)

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
var projectionDaemon = await store.BuildProjectionDaemonAsync();
await projectionDaemon.RebuildProjection(ProjectionNames.VerenigingZoeken, cancellationToken);
logger.LogInformation("Rebuild complete");
});

app.MapGet(
"projections/status",
async (IDocumentStore store, ILogger<Program> logger, CancellationToken cancellationToken) =>
{
return await store.Advanced.AllProjectionProgress(token: cancellationToken);
});

app.SetUpSwagger();
await app.EnsureElasticSearchIsInitialized();
ConfigureHealtChecks(app);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace AssociationRegistry.Public.ProjectionHost.Projections;

public class ProjectionNames
{
public const string VerenigingZoeken = "PubliekVerenigingZoekenDocument";
}

0 comments on commit b1b5c2b

Please sign in to comment.