From 836fb3c71565def583f842cb95a5d20428e23487 Mon Sep 17 00:00:00 2001 From: Quinten Van Assche Date: Wed, 24 Jan 2024 13:46:48 +0100 Subject: [PATCH 1/2] feat: or-1349 restart elastic deamon after rebuild --- .../Extensions/ProjectionEndpointsExtensions.cs | 2 ++ .../Extensions/ProjectionEndpointsExtensions.cs | 1 + 2 files changed, 3 insertions(+) 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..74d461c32 100644 --- a/src/AssociationRegistry.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs +++ b/src/AssociationRegistry.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs @@ -43,6 +43,7 @@ public static void AddProjectionEndpoints(this WebApplication app, RebuildConfig 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(); From 98c55e90a08413a801a172df26f019256bd3c11a Mon Sep 17 00:00:00 2001 From: Quinten Van Assche Date: Wed, 24 Jan 2024 13:49:06 +0100 Subject: [PATCH 2/2] feat: or-1349 add rebuild all publiek projections --- .../PublicProjectionHostHttpClient.cs | 4 +++ .../ProjectionHostController.cs | 8 +++++ .../ProjectionEndpointsExtensions.cs | 33 +++++++++++++++++-- 3 files changed, 43 insertions(+), 2 deletions(-) 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.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs b/src/AssociationRegistry.Public.ProjectionHost/Extensions/ProjectionEndpointsExtensions.cs index 74d461c32..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,7 @@ 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); });