Skip to content

Commit

Permalink
Update logs (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
tschumpr authored May 2, 2024
2 parents 739817c + a66ce95 commit 2ea3dc4
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 48 deletions.
12 changes: 6 additions & 6 deletions Geodatenbezug.Test/GeodiensteApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public async Task StartExportAsync()
new () { Code = HttpStatusCode.OK, Content = "{\"info\":\"Data export successfully started. Call the URL of status_url to get the current status of the export.\"}" },
]);
httpClientFactoryMock.Setup(cf => cf.CreateClient(It.IsAny<string>())).Returns(httpTestMessageHandler.ToHttpClient()).Verifiable();
loggerMock.Setup(LogLevel.Information, "Starte den Datenexport für Perimeter LN- und Sömmerungsflächen (ZG) mit https://geodienste.ch/downloads/lwb_perimeter_ln_sf/1234567890/export.json", Times.Once());
loggerMock.Setup(LogLevel.Information, "Starte den Datenexport mit https://geodienste.ch/downloads/lwb_perimeter_ln_sf/1234567890/export.json", Times.Once());
loggerMock.Setup(LogLevel.Information, "Es läuft gerade ein anderer Export. Versuche es in 1 Minute erneut.", Times.Once());

var result = await CreateGeodiensteApiMock().StartExportAsync(topic);
Expand All @@ -124,7 +124,7 @@ public async Task StartExportAsyncTimeout()
new () { Code = HttpStatusCode.NotFound, Content = "{\"error\":\"Cannot start data export because there is another data export pending\"}" },
]);
httpClientFactoryMock.Setup(cf => cf.CreateClient(It.IsAny<string>())).Returns(httpTestMessageHandler.ToHttpClient()).Verifiable();
loggerMock.Setup(LogLevel.Information, "Starte den Datenexport für Perimeter LN- und Sömmerungsflächen (ZG) mit https://geodienste.ch/downloads/lwb_perimeter_ln_sf/1234567890/export.json", Times.Once());
loggerMock.Setup(LogLevel.Information, "Starte den Datenexport mit https://geodienste.ch/downloads/lwb_perimeter_ln_sf/1234567890/export.json", Times.Once());
loggerMock.Setup(LogLevel.Information, "Es läuft gerade ein anderer Export. Versuche es in 1 Minute erneut.", Times.Exactly(9));
loggerMock.Setup(LogLevel.Error, "Es läuft bereits ein anderer Export. Zeitlimite überschritten.", Times.Once());

Expand All @@ -140,7 +140,7 @@ public async Task StartExportAsyncFails()
new () { Code = HttpStatusCode.Unauthorized },
]);
httpClientFactoryMock.Setup(cf => cf.CreateClient(It.IsAny<string>())).Returns(httpTestMessageHandler.ToHttpClient()).Verifiable();
loggerMock.Setup(LogLevel.Information, "Starte den Datenexport für Perimeter LN- und Sömmerungsflächen (ZG) mit https://geodienste.ch/downloads/lwb_perimeter_ln_sf/1234567890/export.json", Times.Once());
loggerMock.Setup(LogLevel.Information, "Starte den Datenexport mit https://geodienste.ch/downloads/lwb_perimeter_ln_sf/1234567890/export.json", Times.Once());

var result = await CreateGeodiensteApiMock().StartExportAsync(topic);
Assert.AreEqual(HttpStatusCode.Unauthorized, result.StatusCode);
Expand Down Expand Up @@ -171,7 +171,7 @@ public async Task CheckExportStatusAsync()
new () { Code = HttpStatusCode.OK, Content = "{\"status\":\"success\", \"info\":\"Data ready to be downloaded. Provide your credentials to download the data.\", \"download_url\":\"test.com/data.zip\", \"exported_at\":\"2022-03-24T09:31:05.508\"}" },
]);
httpClientFactoryMock.Setup(cf => cf.CreateClient(It.IsAny<string>())).Returns(httpTestMessageHandler.ToHttpClient()).Verifiable();
loggerMock.Setup(LogLevel.Information, "Prüfe den Status des Datenexports für Perimeter LN- und Sömmerungsflächen (ZG) mit https://geodienste.ch/downloads/lwb_perimeter_ln_sf/1234567890/status.json", Times.Once());
loggerMock.Setup(LogLevel.Information, "Prüfe den Status des Datenexports mit https://geodienste.ch/downloads/lwb_perimeter_ln_sf/1234567890/status.json", Times.Once());
loggerMock.Setup(LogLevel.Information, "Export ist in der Warteschlange. Versuche es in 1 Minute erneut.", Times.Once());
loggerMock.Setup(LogLevel.Information, "Export ist in Bearbeitung. Versuche es in 1 Minute erneut.", Times.Once());

Expand All @@ -198,7 +198,7 @@ public async Task CheckExportStatusAsyncTimeout()
new () { Code = HttpStatusCode.OK, Content = "{\"status\":\"working\",\"info\":\"Try again later.\",\"download_url\":null,\"exported_at\":null}" },
]);
httpClientFactoryMock.Setup(cf => cf.CreateClient(It.IsAny<string>())).Returns(httpTestMessageHandler.ToHttpClient()).Verifiable();
loggerMock.Setup(LogLevel.Information, "Prüfe den Status des Datenexports für Perimeter LN- und Sömmerungsflächen (ZG) mit https://geodienste.ch/downloads/lwb_perimeter_ln_sf/1234567890/status.json", Times.Once());
loggerMock.Setup(LogLevel.Information, "Prüfe den Status des Datenexports mit https://geodienste.ch/downloads/lwb_perimeter_ln_sf/1234567890/status.json", Times.Once());
loggerMock.Setup(LogLevel.Information, "Export ist in der Warteschlange. Versuche es in 1 Minute erneut.", Times.Exactly(7));
loggerMock.Setup(LogLevel.Information, "Export ist in Bearbeitung. Versuche es in 1 Minute erneut.", Times.Exactly(2));
loggerMock.Setup(LogLevel.Error, "Zeitlimite überschritten. Status ist in Bearbeitung", Times.Once());
Expand All @@ -216,7 +216,7 @@ public async Task CheckExportStatusAsyncFails()
new () { Code = HttpStatusCode.Unauthorized },
]);
httpClientFactoryMock.Setup(cf => cf.CreateClient(It.IsAny<string>())).Returns(httpTestMessageHandler.ToHttpClient()).Verifiable();
loggerMock.Setup(LogLevel.Information, "Prüfe den Status des Datenexports für Perimeter LN- und Sömmerungsflächen (ZG) mit https://geodienste.ch/downloads/lwb_perimeter_ln_sf/1234567890/status.json", Times.Once());
loggerMock.Setup(LogLevel.Information, "Prüfe den Status des Datenexports mit https://geodienste.ch/downloads/lwb_perimeter_ln_sf/1234567890/status.json", Times.Once());

var result = await CreateGeodiensteApiMock().CheckExportStatusAsync(topic);
Assert.AreEqual(HttpStatusCode.Unauthorized, result.StatusCode);
Expand Down
8 changes: 4 additions & 4 deletions Geodatenbezug.Test/ProcessingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ public async Task GetTopicsToUpdate()
]);

loggerMock.Setup(LogLevel.Information, "Laden der Themen...");
loggerMock.Setup(LogLevel.Information, $"Thema Perimeter LN- und Sömmerungsflächen (SH) wurde am {datestring_delta4.ToString("G", CultureInfo.GetCultureInfo("de-CH"))} aktualisiert und wird verarbeitet");
loggerMock.Setup(LogLevel.Information, $"Thema Perimeter LN- und Sömmerungsflächen (ZG) wurde am {datestring_delta23.ToString("G", CultureInfo.GetCultureInfo("de-CH"))} aktualisiert und wird verarbeitet");
loggerMock.Setup(LogLevel.Information, $"Thema Rebbaukataster (SH) wurde seit {datestring_delta30.ToString("G", CultureInfo.GetCultureInfo("de-CH"))} nicht aktualisiert");
loggerMock.Setup(LogLevel.Information, "Thema Rebbaukataster (ZG) ist nicht verfügbar");
loggerMock.Setup(LogLevel.Information, $"Perimeter LN- und Sömmerungsflächen (SH): Thema wurde am {datestring_delta4.ToString("G", CultureInfo.GetCultureInfo("de-CH"))} aktualisiert und wird verarbeitet");
loggerMock.Setup(LogLevel.Information, $"Perimeter LN- und Sömmerungsflächen (ZG): Thema wurde am {datestring_delta23.ToString("G", CultureInfo.GetCultureInfo("de-CH"))} aktualisiert und wird verarbeitet");
loggerMock.Setup(LogLevel.Information, $"Rebbaukataster (SH): Thema wurde seit {datestring_delta30.ToString("G", CultureInfo.GetCultureInfo("de-CH"))} nicht aktualisiert");
loggerMock.Setup(LogLevel.Information, "Rebbaukataster (ZG): Thema ist nicht verfügbar");
loggerMock.Setup(LogLevel.Information, "2 Themen werden prozessiert");

azureStorageMock.SetupSequence(storage => storage.GetLastProcessed(It.IsAny<Topic>()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void Cleanup()
[TestMethod]
public async Task RunGdalProcessingAsync()
{
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung von Thema {topic.TopicTitle} ({topic.Canton})");
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung");

processor.InputDataPath = "testdata\\lwb_bewirtschaftungseinheit_v2_0_lv95_NE_202404191123.gpkg";
await processor.RunGdalProcessingAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void Cleanup()
[TestMethod]
public async Task RunGdalProcessingAsync()
{
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung von Thema {topic.TopicTitle} ({topic.Canton})");
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung");

processor.InputDataPath = "testdata\\lwb_biodiversitaetsfoerderflaechen_v2_0_lv95_NE_202404191123.gpkg";
await processor.RunGdalProcessingAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ public async Task PrepareDataAsync()
.Setup(api => api.DownloadExportAsync(It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync("downloadedFilePath");

loggerMock.Setup(LogLevel.Information, $"Bereite Daten für die Prozessierung von {topic.TopicTitle} ({topic.Canton}) vor");
loggerMock.Setup(LogLevel.Information, $"Exportiere {topic.TopicTitle} ({topic.Canton})");
loggerMock.Setup(LogLevel.Information, $"Exportiere {bewirtschaftungseinheitTopic.TopicTitle} ({bewirtschaftungseinheitTopic.Canton})");
loggerMock.Setup(LogLevel.Information, $"Bereite Daten für die Prozessierung vor");
loggerMock.Setup(LogLevel.Information, $"Export", Times.Exactly(2));

await processor.PrepareDataAsync();
geodiensteApiMock.Verify(api => api.StartExportAsync(topic), Times.Once);
Expand All @@ -73,7 +72,7 @@ public async Task PrepareDataAsync()
[TestMethod]
public async Task RunGdalProcessingAsync()
{
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung von Thema {topic.TopicTitle} ({topic.Canton})");
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung");
loggerMock.Setup(LogLevel.Information, $"Lade Nutzungsart-Katalog von https://models.geo.admin.ch/BLW/LWB_Nutzungsflaechen_Kataloge_V2_0.xml");

processor.InputDataPath = "testdata\\lwb_nutzungsflaechen_v2_0_lv95_NE_202404191123.gpkg";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void Cleanup()
[TestMethod]
public async Task RunGdalProcessingAsync()
{
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung von Thema {topic.TopicTitle} ({topic.Canton})");
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung");

processor.InputDataPath = "testdata\\lwb_perimeter_ln_sf_v2_0_lv95_NE_202404191123.gpkg";
await processor.RunGdalProcessingAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void Cleanup()
[TestMethod]
public async Task RunGdalProcessingAsync()
{
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung von Thema {topic.TopicTitle} ({topic.Canton})");
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung");

processor.InputDataPath = "testdata\\lwb_perimeter_terrassenreben_v2_0_lv95_NE_202404191123.gpkg";
await processor.RunGdalProcessingAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void Cleanup()
[TestMethod]
public async Task RunGdalProcessingAsync()
{
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung von Thema {topic.TopicTitle} ({topic.Canton})");
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung");

processor.InputDataPath = "testdata\\lwb_rebbaukataster_v2_0_lv95_NE_202404191123.gpkg";
await processor.RunGdalProcessingAsync();
Expand Down
20 changes: 10 additions & 10 deletions Geodatenbezug.Test/Processors/TopicProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task ExportTopic()
geodiensteApiMock
.Setup(api => api.CheckExportStatusAsync(It.IsAny<Topic>()))
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("{\"status\":\"success\", \"info\":\"Data ready to be downloaded. Provide your credentials to download the data.\", \"download_url\":\"test.com/data.zip\", \"exported_at\":\"2022-03-24T09:31:05.508\"}"), });
loggerMock.Setup(LogLevel.Information, $"Exportiere {topic.TopicTitle} ({topic.Canton})");
loggerMock.Setup(LogLevel.Information, $"Export");

var result = await Processor.ExportTopicAsync(topic);

Expand All @@ -82,7 +82,7 @@ public async Task ExportTopicOnlyOneExportIn24h()
geodiensteApiMock
.Setup(api => api.CheckExportStatusAsync(It.IsAny<Topic>()))
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("{\"status\":\"success\", \"info\":\"Data ready to be downloaded. Provide your credentials to download the data.\", \"download_url\":\"test.com/data.zip\", \"exported_at\":\"2022-03-24T09:31:05.508\"}"), });
loggerMock.Setup(LogLevel.Information, $"Exportiere {topic.TopicTitle} ({topic.Canton})");
loggerMock.Setup(LogLevel.Information, $"Export");

var result = await Processor.ExportTopicAsync(topic);

Expand All @@ -106,8 +106,8 @@ public async Task ExportTopicStartExportFails()
geodiensteApiMock
.Setup(api => api.StartExportAsync(It.IsAny<Topic>()))
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("{\"error\":\"Data export information not found. Invalid token?\"}"), });
loggerMock.Setup(LogLevel.Information, $"Exportiere {topic.TopicTitle} ({topic.Canton})");
loggerMock.Setup(LogLevel.Error, $"Fehler beim Starten des Exports für Thema {topic.TopicTitle} ({topic.Canton}): {HttpStatusCode.NotFound} - Data export information not found. Invalid token?");
loggerMock.Setup(LogLevel.Information, $"Export");
loggerMock.Setup(LogLevel.Error, $"Fehler beim Starten des Exports: {HttpStatusCode.NotFound} - Data export information not found. Invalid token?");

await Assert.ThrowsExceptionAsync<InvalidOperationException>(async () => await Processor.ExportTopicAsync(topic), "Export failed");
Assert.AreEqual(processingResult.Code, Processor.ProcessingResult.Code);
Expand All @@ -134,8 +134,8 @@ public async Task ExportTopicCheckExportStatusFailed()
geodiensteApiMock
.Setup(api => api.CheckExportStatusAsync(It.IsAny<Topic>()))
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("{\"status\":\"failed\", \"info\":\"An unexpected error occurred. Please try again by starting a new data export.\"}"), });
loggerMock.Setup(LogLevel.Information, $"Exportiere {topic.TopicTitle} ({topic.Canton})");
loggerMock.Setup(LogLevel.Error, $"Fehler bei der Statusabfrage des Datenexports für Thema {topic.TopicTitle} ({topic.Canton}): An unexpected error occurred. Please try again by starting a new data export.");
loggerMock.Setup(LogLevel.Information, $"Export");
loggerMock.Setup(LogLevel.Error, $"Fehler bei der Statusabfrage des Datenexports: An unexpected error occurred. Please try again by starting a new data export.");

await Assert.ThrowsExceptionAsync<InvalidOperationException>(async () => await Processor.ExportTopicAsync(topic), "Export failed");
Assert.AreEqual(processingResult.Code, Processor.ProcessingResult.Code);
Expand Down Expand Up @@ -163,8 +163,8 @@ public async Task ExportTopicCheckExportStatusError()
geodiensteApiMock
.Setup(api => api.CheckExportStatusAsync(It.IsAny<Topic>()))
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("{\"error\":\"Data export information not found. Invalid token?\"}"), });
loggerMock.Setup(LogLevel.Information, $"Exportiere {topic.TopicTitle} ({topic.Canton})");
loggerMock.Setup(LogLevel.Error, $"Fehler bei der Statusabfrage des Datenexports für Thema {topic.TopicTitle} ({topic.Canton}): {HttpStatusCode.NotFound} - Data export information not found. Invalid token?");
loggerMock.Setup(LogLevel.Information, $"Export");
loggerMock.Setup(LogLevel.Error, $"Fehler bei der Statusabfrage des Datenexports: {HttpStatusCode.NotFound} - Data export information not found. Invalid token?");

await Assert.ThrowsExceptionAsync<InvalidOperationException>(async () => await Processor.ExportTopicAsync(topic), "Export failed");
Assert.AreEqual(processingResult.Code, Processor.ProcessingResult.Code);
Expand All @@ -189,8 +189,8 @@ public async Task PrepareDataFails()

processorMock.Setup(p => p.PrepareDataAsync())
.Throws(new InvalidOperationException("Something happened", new InvalidOperationException("Inner exception details")));
loggerMock.Setup(LogLevel.Information, $"Verarbeite Thema {topic.TopicTitle} ({topic.Canton})");
loggerMock.Setup(LogLevel.Error, $"Fehler beim Verarbeiten des Themas {topic.TopicTitle} ({topic.Canton}): Something happened");
loggerMock.Setup(LogLevel.Information, $"Verarbeite Thema");
loggerMock.Setup(LogLevel.Error, $"Fehler beim Verarbeiten des Themas: Something happened");

await Processor.ProcessAsync();
Assert.AreEqual(processingResult.Code, Processor.ProcessingResult.Code);
Expand Down
4 changes: 2 additions & 2 deletions Geodatenbezug/AzureStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected string ConnectionString
/// <inheritdoc />
public async Task<DateTime?> GetLastProcessed(Topic topic)
{
logger.LogInformation($"Frage letzte Prozessierung des Themas {topic.TopicTitle} ({topic.Canton}) ab");
logger.LogInformation($"{topic.TopicTitle} ({topic.Canton}): Frage letzte Prozessierung des Themas ab");
var containerClient = new BlobServiceClient(ConnectionString).GetBlobContainerClient(StorageContainerName);
var creationDates = new List<DateTime>();

Expand All @@ -66,7 +66,7 @@ protected string ConnectionString
/// <inheritdoc />
public async Task<string> UploadFileAsync(string storageFilePath, string localFilePath)
{
logger.LogInformation($"Lade Datei {localFilePath} in den Azure Storage hoch...");
logger.LogInformation($"Lade Datei {localFilePath} in den Azure Storage hoch");

var containerClient = new BlobServiceClient(ConnectionString).GetBlobContainerClient(StorageContainerName);
var blobClient = containerClient.GetBlobClient(storageFilePath);
Expand Down
4 changes: 2 additions & 2 deletions Geodatenbezug/GeodiensteApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task<HttpResponseMessage> StartExportAsync(Topic topic)
{
var token = GetToken(topic.BaseTopic, topic.Canton);
var url = $"{GeodiensteBaseUrl}/downloads/{topic.BaseTopic}/{token}/export.json";
logger.LogInformation($"Starte den Datenexport für {topic.TopicTitle} ({topic.Canton}) mit {url}");
logger.LogInformation($"{topic.TopicTitle} ({topic.Canton}): Starte den Datenexport mit {url}");
using var httpClient = httpClientFactory.CreateClient(nameof(GeodiensteApi));

var retryPolicy = Policy
Expand Down Expand Up @@ -90,7 +90,7 @@ public async Task<HttpResponseMessage> CheckExportStatusAsync(Topic topic)
{
var token = GetToken(topic.BaseTopic, topic.Canton);
var url = $"{GeodiensteBaseUrl}/downloads/{topic.BaseTopic}/{token}/status.json";
logger.LogInformation($"Prüfe den Status des Datenexports für {topic.TopicTitle} ({topic.Canton}) mit {url}");
logger.LogInformation($"{topic.TopicTitle} ({topic.Canton}): Prüfe den Status des Datenexports mit {url}");
using var httpClient = httpClientFactory.CreateClient(nameof(GeodiensteApi));

var retryPolicy = Policy
Expand Down
Loading

0 comments on commit 2ea3dc4

Please sign in to comment.