Skip to content

Commit

Permalink
feat: add snapshot status endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneD authored Jul 29, 2024
1 parent 6b2ddb2 commit 025f881
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/Public.Api/Infrastructure/Modules/StatusModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ protected override void Load(ContainerBuilder builder)
RegisterConsumerStatusClient(key, value.ProjectionsUrl, builder);
RegisterImporterGrbStatusClient(key, value.ImporterGrbUrl, builder);
RegisterBackOfficeStatusClient(key, value.ProjectionsUrl, builder);
RegisterSnapshotStatusClient(key, value.ProjectionsUrl, builder);
}
}

Expand Down Expand Up @@ -181,6 +182,22 @@ private void RegisterBackOfficeStatusClient(
.AsSelf();
}

private void RegisterSnapshotStatusClient(
string name,
string baseUrl,
ContainerBuilder builder)
{
if (string.IsNullOrWhiteSpace(baseUrl))
return;

var key = $"Snapshot-{name}";
RegisterKeyedRestClient(baseUrl, key, builder);

builder
.Register(context => new SnapshotStatusClient(name, context.ResolveNamed<RestClient>(key)))
.AsSelf();
}


private void RegisterKeyedRestClient(
string baseUrl,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Public.Api.Status.Clients.BackendResponse
{
public class SnapshotStatus
{
public int FailedSnapshotsCount { get; set; }
public int DifferenceInDaysOfLastVerification { get; set; }
}
}
23 changes: 23 additions & 0 deletions src/Public.Api/Status/Clients/SnapshotStatusClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Public.Api.Status.Clients
{
using BackendResponse;
using Responses;
using RestSharp;

public sealed class SnapshotStatusClient : BaseStatusClient<RegistrySnapshotStatusResponse, SnapshotStatus>
{
public SnapshotStatusClient(string registry, RestClient restClient)
: base(registry, restClient) { }

protected override RestRequest CreateStatusRequest()
=> new RestRequest("snapshots");

protected override RegistrySnapshotStatusResponse Map(SnapshotStatus response)
=> new RegistrySnapshotStatusResponse()
{
Name = "Snapshot",
FailedSnapshotsCount = response.FailedSnapshotsCount,
DifferenceInDaysOfLastVerification = response.DifferenceInDaysOfLastVerification
};
}
}
18 changes: 18 additions & 0 deletions src/Public.Api/Status/Responses/SnapshotStatusResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Public.Api.Status.Responses
{
using System.Runtime.Serialization;

public class SnapshotStatusResponse : ListResponse<RegistrySnapshotStatusResponse> { }

public class RegistrySnapshotStatusResponse
{
[DataMember(Order = 1)]
public string Name { get; set; }

[DataMember(Order = 2)]
public int FailedSnapshotsCount { get; set; }

[DataMember(Order = 3)]
public int DifferenceInDaysOfLastVerification { get; set; }
}
}
17 changes: 15 additions & 2 deletions src/Public.Api/Status/StatusController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public async Task<IActionResult> GetProjectionStatus(
{
var keyValuePairs = await clients.GetStatuses(cancellationToken);
var projectionStatuses = ProjectionStatusResponse.From(keyValuePairs);

if (state is not null)
{
foreach (var projectionStatus in projectionStatuses
Expand Down Expand Up @@ -178,7 +178,7 @@ public async Task<IActionResult> GetProducerStatus(
}

var projectionStatuses = ProjectionStatusResponse.From(keyValuePairsProducer);

if (state is not null)
{
foreach (var projectionStatus in projectionStatuses
Expand Down Expand Up @@ -251,5 +251,18 @@ public async Task<IActionResult> GetBackOfficeStatus(

return Ok(backOfficeStatusResponses);
}

[HttpGet("snapshot")]
[ProducesResponseType(typeof(SnapshotStatusResponse), StatusCodes.Status200OK)]
[HttpCacheExpiration(MaxAge = DefaultStatusCaching)]
public async Task<IActionResult> GetSnapshotStatus(
[FromServices] IEnumerable<SnapshotStatusClient> clients,
CancellationToken cancellationToken = default)
{
var keyValuePairs = await clients.GetStatuses(cancellationToken);
var snapshotStatusResponses = SnapshotStatusResponse.From(keyValuePairs);

return Ok(snapshotStatusResponses);
}
}
}

0 comments on commit 025f881

Please sign in to comment.