Skip to content

Commit

Permalink
feat: add lastchangedlist console
Browse files Browse the repository at this point in the history
  • Loading branch information
emalfroy authored and ArneD committed Feb 14, 2024
1 parent 5568c27 commit c98b052
Show file tree
Hide file tree
Showing 19 changed files with 596 additions and 21 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,21 @@ jobs:
semver: ${{ needs.set-release-version.outputs.version }}
secrets: inherit

build-projections-last-changed-list:
name: Build projections last changed list
uses: Informatievlaanderen/build-pipeline/.github/workflows/build-image.yml@main
needs: [ set-release-version ]
if: ${{ (github.repository_owner == 'Informatievlaanderen') && (needs.set-release-version.outputs.version != 'none') }}
with:
registry: streetname-registry
build-target: Containerize_ProjectionsLastChangedList
image-file: sr-projections-last-changed-list-console-image.tar
image-name: projections-last-changed-list-console
test-project: StreetNameRegistry.Tests
build-project: StreetNameRegistry.Projections.LastChangedList.Console
semver: ${{ needs.set-release-version.outputs.version }}
secrets: inherit

build-projections-backoffice:
name: Build Projections BackOffice
uses: Informatievlaanderen/build-pipeline/.github/workflows/build-image.yml@main
Expand Down Expand Up @@ -337,6 +352,7 @@ jobs:
, build-projector
, build-projections-backoffice
, build-projections-syndication
, build-projections-last-changed-list
, build-consumer
, build-producer
, build-producer-snapshot-oslo
Expand Down Expand Up @@ -681,6 +697,7 @@ jobs:
, 'projector'
, 'projections-syndication'
, 'projections-backoffice'
; 'projections-last-changed-list-console'
, 'consumer'
, 'producer'
, 'producer-snapshot-oslo'
Expand Down Expand Up @@ -803,6 +820,7 @@ jobs:
, 'projector'
, 'projections-syndication'
, 'projections-backoffice'
, 'projections-last-changed-list-console'
, 'consumer'
, 'producer'
, 'producer-snapshot-oslo'
Expand Down Expand Up @@ -865,6 +883,7 @@ jobs:
, 'projector'
, 'projections-syndication'
, 'projections-backoffice'
, 'projections-last-changed-list-console'
, 'consumer'
, 'producer'
, 'producer-snapshot-oslo'
Expand Down
7 changes: 7 additions & 0 deletions StreetNameRegistry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StreetNameRegistry.Consumer
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StreetNameRegistry.Projections.Integration", "src\StreetNameRegistry.Projections.Integration\StreetNameRegistry.Projections.Integration.csproj", "{E69043F1-E6C9-484C-A961-C28C33013C91}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StreetNameRegistry.Projections.LastChangedList.Console", "src\StreetNameRegistry.Projections.LastChangedList.Console\StreetNameRegistry.Projections.LastChangedList.Console.csproj", "{2E20B1DF-A4E2-42BA-85F4-F335754C455B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -191,6 +193,10 @@ Global
{E69043F1-E6C9-484C-A961-C28C33013C91}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E69043F1-E6C9-484C-A961-C28C33013C91}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E69043F1-E6C9-484C-A961-C28C33013C91}.Release|Any CPU.Build.0 = Release|Any CPU
{2E20B1DF-A4E2-42BA-85F4-F335754C455B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E20B1DF-A4E2-42BA-85F4-F335754C455B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E20B1DF-A4E2-42BA-85F4-F335754C455B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E20B1DF-A4E2-42BA-85F4-F335754C455B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -222,6 +228,7 @@ Global
{06F8F677-2696-4996-B4AE-B8E3B747A696} = {65EA04DE-5928-430F-92CA-24C11B6E5A00}
{83C7D129-ACEA-4FC6-A55C-748D8D31135A} = {65EA04DE-5928-430F-92CA-24C11B6E5A00}
{E69043F1-E6C9-484C-A961-C28C33013C91} = {65EA04DE-5928-430F-92CA-24C11B6E5A00}
{2E20B1DF-A4E2-42BA-85F4-F335754C455B} = {65EA04DE-5928-430F-92CA-24C11B6E5A00}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3B44FE80-30FE-47B7-A0DE-8610218FFF63}
Expand Down
1 change: 1 addition & 0 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Target.create "Containerize_ProducerSnapshotOslo" (fun _ -> containerize "Street
Target.create "Containerize_MigratorStreetName" (fun _ -> containerize "StreetNameRegistry.Migrator.StreetName" "migrator-streetname")
Target.create "Containerize_ProjectionsSyndication" (fun _ -> containerize "StreetNameRegistry.Projections.Syndication" "projections-syndication")
Target.create "Containerize_ProjectionsBackOffice" (fun _ -> containerize "StreetNameRegistry.Projections.BackOffice" "projections-backoffice")
Target.create "Containerize_ProjectionsLastChangedList" (fun _ -> containerize "StreetNameRegistry.Projections.LastChangedList.Console" "projections-last-changed-list-console")
Target.create "Containerize_SnapshotVerifier" (fun _ -> containerize "StreetNameRegistry.Snapshot.Verifier" "snapshot-verifier")
Target.create "Containerize_ConsumerReadPostal" (fun _ -> containerize "StreetNameRegistry.Consumer.Read.Postal" "consumer-read-postal")
// --------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM mcr.microsoft.com/dotnet/runtime-deps:6.0.3

# create group & user
RUN addgroup --gid 1000 --system app && adduser --uid 1000 -system app --gid 1000

# create work dir and set permissions as WORKDIR sets permissions as root
RUN mkdir /app && chown -R app:app /app
WORKDIR /app

LABEL maintainer "Digitaal Vlaanderen <[email protected]>"
LABEL registry="streetname-registry"

COPY / /app
WORKDIR /app

RUN apt-get update && \
apt-get install curl jq -y && \
chmod +x ./init.sh

# switch to created user
USER app

ENTRYPOINT ["./init.sh"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace StreetNameRegistry.Projections.LastChangedList.Console.Infrastructure
{
using System.Threading;
using System.Threading.Tasks;
using Be.Vlaanderen.Basisregisters.ProjectionHandling.LastChangedList;
using Dapper;
using Microsoft.Data.SqlClient;

public sealed class LastChangedListStreetNameCacheValidator : ICacheValidator
{
private readonly string _connectionString;
private readonly string _projectionName;

public LastChangedListStreetNameCacheValidator(string connectionString, string projectionName)
{
_connectionString = connectionString;
_projectionName = projectionName;
}

public async Task<bool> CanCache(long position, CancellationToken ct)
{
await using var connection = new SqlConnection(_connectionString);

var sql = @"SELECT [Position]
FROM [streetname-registry].[StreetNameRegistryLegacy].[ProjectionStates]
WHERE [Name] = @Name
";

var projectionPosition = await connection.ExecuteScalarAsync<int>(sql, new { Name = _projectionName });

return projectionPosition >= position;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
namespace StreetNameRegistry.Projections.LastChangedList.Console.Infrastructure.Modules
{
using System;
using StreetNameRegistry.Infrastructure;
using Autofac;
using Autofac.Extensions.DependencyInjection;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Be.Vlaanderen.Basisregisters.DataDog.Tracing.Microsoft;
using Be.Vlaanderen.Basisregisters.DependencyInjection;
using Be.Vlaanderen.Basisregisters.EventHandling;
using Be.Vlaanderen.Basisregisters.EventHandling.Autofac;
using Be.Vlaanderen.Basisregisters.ProjectionHandling.LastChangedList;
using Be.Vlaanderen.Basisregisters.ProjectionHandling.SqlStreamStore.Autofac;
using Be.Vlaanderen.Basisregisters.Projector;
using Be.Vlaanderen.Basisregisters.Projector.ConnectedProjections;
using Be.Vlaanderen.Basisregisters.Projector.Modules;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using LastChangedListContextMigrationFactory = LastChangedList.LastChangedListContextMigrationFactory;

public class LastChangedListConsoleModule : Module
{
private readonly IConfiguration _configuration;
private readonly IServiceCollection _services;
private readonly ILoggerFactory _loggerFactory;

public LastChangedListConsoleModule(
IConfiguration configuration,
IServiceCollection services,
ILoggerFactory loggerFactory)
{
_configuration = configuration;
_services = services;
_loggerFactory = loggerFactory;
}

protected override void Load(ContainerBuilder builder)
{
_services.RegisterModule(new DataDogModule(_configuration));

RegisterProjectionSetup(builder);

builder
.RegisterType<ProblemDetailsHelper>()
.AsSelf();

builder.Populate(_services);
}

private void RegisterProjectionSetup(ContainerBuilder builder)
{
builder
.RegisterModule(
new EventHandlingModule(
typeof(DomainAssemblyMarker).Assembly,
EventsJsonSerializerSettingsProvider.CreateSerializerSettings()))
.RegisterModule<EnvelopeModule>()
.RegisterEventstreamModule(_configuration)
.RegisterModule(new ProjectorModule(_configuration));

RegisterProjections(builder);
}

private void RegisterProjections(ContainerBuilder builder)
{
var logger = _loggerFactory.CreateLogger<LastChangedListConsoleModule>();
var connectionString = _configuration.GetConnectionString("LastChangedList");

builder.RegisterModule(new LastChangedListModule(connectionString, _configuration["DataDog:ServiceName"], _services, _loggerFactory));

logger.LogInformation(
"Added {Context} to services:" +
Environment.NewLine +
"\tSchema: {Schema}" +
Environment.NewLine +
"\tTableName: {TableName}",
nameof(LastChangedListContext), LastChangedListContext.Schema, LastChangedListContext.MigrationsHistoryTable);

builder.Register(c =>
new LastChangedListStreetNameCacheValidator(
_configuration.GetConnectionString("LegacyProjections"),
"StreetNameRegistry.Projections.Legacy.StreetNameDetailV2.StreetNameDetailProjectionsV2"))
.AsSelf();

builder
.RegisterProjectionMigrator<LastChangedListContextMigrationFactory>(
_configuration,
_loggerFactory)
.RegisterProjectionMigrator<DataMigrationContextMigrationFactory>(
_configuration,
_loggerFactory)
.RegisterProjections<LastChangedProjections, LastChangedListContext>(
context => new LastChangedProjections(context.Resolve<LastChangedListStreetNameCacheValidator>()),
ConnectedProjectionSettings.Default);
}
}
}
Loading

0 comments on commit c98b052

Please sign in to comment.