diff --git a/src/AssociationRegistry.Admin.Api/Infrastructure/HttpClients/PublicProjectionHostHttpClient.cs b/src/AssociationRegistry.Admin.Api/Infrastructure/HttpClients/PublicProjectionHostHttpClient.cs index 08910408f..4572b2bb8 100644 --- a/src/AssociationRegistry.Admin.Api/Infrastructure/HttpClients/PublicProjectionHostHttpClient.cs +++ b/src/AssociationRegistry.Admin.Api/Infrastructure/HttpClients/PublicProjectionHostHttpClient.cs @@ -14,6 +14,8 @@ public PublicProjectionHostHttpClient(HttpClient httpClient) _httpClient = httpClient; } + public async Task RebuildAllProjections(CancellationToken cancellationToken) + => await _httpClient.PostAsync(requestUri: "/v1/projections/all/rebuild", content: null, cancellationToken); public async Task RebuildDetailProjection(CancellationToken cancellationToken) => await _httpClient.PostAsync(requestUri: "/v1/projections/detail/rebuild", content: null, cancellationToken); @@ -27,4 +29,6 @@ public void Dispose() { _httpClient.Dispose(); } + + } diff --git a/src/AssociationRegistry.Admin.Api/ProjectieBeheer/ProjectionHostController.cs b/src/AssociationRegistry.Admin.Api/ProjectieBeheer/ProjectionHostController.cs index 344579c14..8248ce984 100644 --- a/src/AssociationRegistry.Admin.Api/ProjectieBeheer/ProjectionHostController.cs +++ b/src/AssociationRegistry.Admin.Api/ProjectieBeheer/ProjectionHostController.cs @@ -73,6 +73,14 @@ public async Task GetAdminProjectionStatus(CancellationToken canc return await OkObjectOrForwardedResponse(cancellationToken, response); } + [HttpPost("public/all/rebuild")] + public async Task RebuildPublicAllProjections(CancellationToken cancellationToken) + { + var response = await _publicHttpClient.RebuildAllProjections(cancellationToken); + + return await OkOrForwardedResponse(cancellationToken, response); + } + [HttpPost("public/detail/rebuild")] public async Task RebuildPublicProjectionDetail(CancellationToken cancellationToken) { diff --git a/src/AssociationRegistry.Admin.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs b/src/AssociationRegistry.Admin.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs index ae7e23f53..d30a8de75 100644 --- a/src/AssociationRegistry.Admin.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs +++ b/src/AssociationRegistry.Admin.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs @@ -134,5 +134,7 @@ private static async Task RebuildElasticProjections( { await elasticClient.Indices.DeleteAsync(indeces, ct: CancellationToken.None).ThrowIfInvalidAsync(); } + + await projectionDaemon.StartShard($"{ProjectionNames.VerenigingZoeken}:All", CancellationToken.None); } } diff --git a/src/AssociationRegistry.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs b/src/AssociationRegistry.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs index 0f365fe98..3c98e6d76 100644 --- a/src/AssociationRegistry.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs +++ b/src/AssociationRegistry.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs @@ -13,6 +13,35 @@ public static void AddProjectionEndpoints(this WebApplication app, RebuildConfig { var shardTimeout = TimeSpan.FromMinutes(configurationSection.TimeoutInMinutes); + app.MapPost( + pattern: "v1/projections/all/rebuild", + handler: async ( + IDocumentStore store, + IElasticClient elasticClient, + ElasticSearchOptionsSection options, + ILogger logger) => + { + StartRebuild(logger, projectionName: "Detail", rebuildFunc: async () => + { + var projectionDaemon = await store.BuildProjectionDaemonAsync(); + await projectionDaemon.RebuildProjection(shardTimeout, CancellationToken.None); + }); + + StartRebuild(logger, projectionName: "Search", rebuildFunc: async () => + { + var projectionDaemon = await store.BuildProjectionDaemonAsync(); + await projectionDaemon.StopShard($"{ProjectionNames.VerenigingZoeken}:All"); + + await elasticClient.Indices.DeleteAsync(options.Indices.Verenigingen, ct: CancellationToken.None); + await elasticClient.Indices.CreateVerenigingIndexAsync(options.Indices.Verenigingen); + + await projectionDaemon.RebuildProjection(ProjectionNames.VerenigingZoeken, shardTimeout, CancellationToken.None); + await projectionDaemon.StartShard($"{ProjectionNames.VerenigingZoeken}:All", CancellationToken.None); + }); + + return Results.Accepted(); + }); + app.MapPost( pattern: "v1/projections/detail/rebuild", handler: async (IDocumentStore store, ILogger logger) => @@ -20,7 +49,7 @@ public static void AddProjectionEndpoints(this WebApplication app, RebuildConfig StartRebuild(logger, projectionName: "Detail", rebuildFunc: async () => { var projectionDaemon = await store.BuildProjectionDaemonAsync(); - await projectionDaemon.RebuildProjection(shardTimeout,CancellationToken.None); + await projectionDaemon.RebuildProjection(shardTimeout, CancellationToken.None); }); return Results.Accepted(); @@ -42,7 +71,8 @@ public static void AddProjectionEndpoints(this WebApplication app, RebuildConfig await elasticClient.Indices.DeleteAsync(options.Indices.Verenigingen, ct: CancellationToken.None); await elasticClient.Indices.CreateVerenigingIndexAsync(options.Indices.Verenigingen); - await projectionDaemon.RebuildProjection(ProjectionNames.VerenigingZoeken,shardTimeout, CancellationToken.None); + await projectionDaemon.RebuildProjection(ProjectionNames.VerenigingZoeken, shardTimeout, CancellationToken.None); + await projectionDaemon.StartShard($"{ProjectionNames.VerenigingZoeken}:All", CancellationToken.None); }); return Results.Accepted();