Skip to content

Commit

Permalink
Merge branch 'main' into xvibe/gln-for-grid-owners
Browse files Browse the repository at this point in the history
  • Loading branch information
vbelinschi authored Sep 23, 2024
2 parents 8840254 + 415af41 commit 2d1c594
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,22 @@ private async Task<IEnumerable<RequestedSettlementReportDto>> CheckStatusOfSettl
{
var updatedReport = settlementReport;

if (settlementReport.Status == SettlementReportStatus.InProgress && settlementReport.JobId == null)
var instanceInfo = await durableTaskClient
.GetInstanceAsync(settlementReport.RequestId.Id, getInputsAndOutputs: true)
.ConfigureAwait(false);

if (instanceInfo == null)
{
// If the orchestration instance is not found, we assume it is running on the other orchestration,
// either the heavy or the light one
continue;
}

if (settlementReport.Status == SettlementReportStatus.InProgress)
{
var instanceInfo = await durableTaskClient
.GetInstanceAsync(settlementReport.RequestId.Id, getInputsAndOutputs: true)
.ConfigureAwait(false);

if (instanceInfo == null || instanceInfo.RuntimeStatus
is not OrchestrationRuntimeStatus.Running
and not OrchestrationRuntimeStatus.Pending
and not OrchestrationRuntimeStatus.Suspended)
if (instanceInfo.RuntimeStatus
is OrchestrationRuntimeStatus.Terminated
or OrchestrationRuntimeStatus.Failed)
{
await _updateFailedSettlementReportsHandler
.UpdateFailedReportAsync(settlementReport.RequestId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": "2.0",
"extensions": {
"durableTask": {
"maxConcurrentActivityFunctions": 6,
"maxConcurrentActivityFunctions": 2,
"hubName": "%OrchestrationsTaskHubName%"
}
},
Expand All @@ -12,6 +12,9 @@
"isEnabled": true,
"excludedTypes": "Request"
},
"logLevel": {
"default": "Information"
},
"enableLiveMetricsFilters": true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace Energinet.DataHub.SettlementReport.Infrastructure.Experimental;
Expand All @@ -31,10 +32,11 @@ public abstract class DatabricksContextBase : IDisposable

protected DatabricksContextBase(
DatabricksSqlWarehouseQueryExecutor databricksSqlWarehouseQueryExecutor,
IOptions<DeltaTableOptions> options)
IOptions<DeltaTableOptions> options,
ILoggerFactory loggerFactory)
{
_dbContext = new DbContextCore(OnModelCreating);
_executor = new DatabricksSqlQueryExecutor(_dbContext, databricksSqlWarehouseQueryExecutor, options);
_executor = new DatabricksSqlQueryExecutor(_dbContext, databricksSqlWarehouseQueryExecutor, options, loggerFactory);
}

public void Dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace Energinet.DataHub.SettlementReport.Infrastructure.Experimental;
Expand All @@ -28,11 +29,16 @@ public sealed class DatabricksSqlQueryBuilder
{
private readonly DbContext _context;
private readonly IOptions<DeltaTableOptions> _options;
private readonly ILogger<DatabricksSqlQueryBuilder> _logger;

public DatabricksSqlQueryBuilder(DbContext context, IOptions<DeltaTableOptions> options)
public DatabricksSqlQueryBuilder(
DbContext context,
IOptions<DeltaTableOptions> options,
ILoggerFactory loggerFactory)
{
_context = context;
_options = options;
_logger = loggerFactory.CreateLogger<DatabricksSqlQueryBuilder>();
}

public DatabricksStatement Build(DatabricksSqlQueryable query)
Expand Down Expand Up @@ -101,7 +107,10 @@ private string PrepareSqlStatement(DatabricksSqlQueryable query, Func<string, st
}

sqlParameters = sqlParams;
return TranslateTransactToAnsi(sqlStatement);
var translated = TranslateTransactToAnsi(sqlStatement);
var logString = $"Translated SQL: {translated}" + Environment.NewLine + string.Join(Environment.NewLine, sqlParams.Select(x => $"Parameter Name: {x.Key} | Value: {x.Value}"));
_logger.LogInformation(logString);
return translated;
}

private string TranslateTransactToAnsi(StringBuilder transactSqlQuery)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Energinet.DataHub.Core.Databricks.SqlStatementExecution.Formats;
using Energinet.DataHub.SettlementReport.Common.Infrastructure.Options;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace Energinet.DataHub.SettlementReport.Infrastructure.Experimental;
Expand All @@ -30,9 +31,10 @@ public sealed class DatabricksSqlQueryExecutor
public DatabricksSqlQueryExecutor(
DbContext dbContext,
DatabricksSqlWarehouseQueryExecutor databricksSqlWarehouseQueryExecutor,
IOptions<DeltaTableOptions> options)
IOptions<DeltaTableOptions> options,
ILoggerFactory loggerFactory)
{
_sqlQueryBuilder = new DatabricksSqlQueryBuilder(dbContext, options);
_sqlQueryBuilder = new DatabricksSqlQueryBuilder(dbContext, options, loggerFactory);
_sqlRowHydrator = new DatabricksSqlRowHydrator();
_databricksSqlWarehouseQueryExecutor = databricksSqlWarehouseQueryExecutor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Energinet.DataHub.SettlementReport.Common.Infrastructure.Options;
using Energinet.DataHub.SettlementReport.Infrastructure.Experimental;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace Energinet.DataHub.SettlementReport.Infrastructure.Persistence.Databricks;
Expand All @@ -26,8 +27,9 @@ public sealed class SettlementReportDatabricksContext : DatabricksContextBase, I

public SettlementReportDatabricksContext(
IOptions<DeltaTableOptions> deltaTableOptions,
DatabricksSqlWarehouseQueryExecutor sqlWarehouseQueryExecutor)
: base(sqlWarehouseQueryExecutor, deltaTableOptions)
DatabricksSqlWarehouseQueryExecutor sqlWarehouseQueryExecutor,
ILoggerFactory loggerFactory)
: base(sqlWarehouseQueryExecutor, deltaTableOptions, loggerFactory)
{
_deltaTableOptions = deltaTableOptions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
using Energinet.DataHub.SettlementReport.Interfaces.Models;
using Energinet.DataHub.SettlementReport.Interfaces.SettlementReports_v2.Models;
using Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Fixtures;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Moq;
using NodaTime;
Expand Down Expand Up @@ -58,31 +60,36 @@ public SettlementReportFileRequestHandlerIntegrationTests(
Fixture.Inject(mockedOptions);

var sqlWarehouseQueryExecutor = _databricksSqlStatementApiFixture.GetDatabricksExecutor();
var databricksContext = new SettlementReportDatabricksContext(mockedOptions.Object, sqlWarehouseQueryExecutor);
var databricksContext = new SettlementReportDatabricksContext(mockedOptions.Object, sqlWarehouseQueryExecutor, NullLoggerFactory.Instance);

var settlementReportDataRepository = new SettlementReportEnergyResultRepository(databricksContext);
var settlementReportWholesaleRepository = new SettlementReportWholesaleRepository(databricksContext);
var settlementReportChargeLinkPeriodsRepository = new SettlementReportChargeLinkPeriodsRepository(databricksContext);

var settlementReportMeteringPointMasterDataRepository = new SettlementReportMeteringPointMasterDataRepository(new SettlementReportDatabricksContext(
mockedOptions.Object,
sqlWarehouseQueryExecutor));
sqlWarehouseQueryExecutor,
NullLoggerFactory.Instance));

var settlementReportMeteringPointTimeSeriesResultRepository = new SettlementReportMeteringPointTimeSeriesResultRepository(new SettlementReportDatabricksContext(
mockedOptions.Object,
sqlWarehouseQueryExecutor));
sqlWarehouseQueryExecutor,
NullLoggerFactory.Instance));

var settlementReportMonthlyAmountRepository = new SettlementReportMonthlyAmountRepository(new SettlementReportDatabricksContext(
mockedOptions.Object,
sqlWarehouseQueryExecutor));
sqlWarehouseQueryExecutor,
NullLoggerFactory.Instance));

var settlementReportChargePriceRepository = new SettlementReportChargePriceRepository(new SettlementReportDatabricksContext(
mockedOptions.Object,
sqlWarehouseQueryExecutor));
sqlWarehouseQueryExecutor,
NullLoggerFactory.Instance));

var settlementReportMonthlyAmountTotalRepository = new SettlementReportMonthlyAmountTotalRepository(new SettlementReportDatabricksContext(
mockedOptions.Object,
sqlWarehouseQueryExecutor));
sqlWarehouseQueryExecutor,
NullLoggerFactory.Instance));

Fixture.Inject<ISettlementReportFileGeneratorFactory>(new SettlementReportFileGeneratorFactory(
settlementReportDataRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
using Energinet.DataHub.SettlementReport.Interfaces.SettlementReports_v2.Models;
using Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Fixtures;
using FluentAssertions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Xunit;

namespace Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Infrastructure.SettlementReports_v2;
Expand All @@ -39,7 +42,8 @@ public SettlementReportChargeLinkPeriodsRepositoryTests(MigrationsFreeDatabricks

Fixture.Inject<ISettlementReportDatabricksContext>(new SettlementReportDatabricksContext(
_databricksSqlStatementApiFixture.DatabricksSchemaManager.DeltaTableOptions,
_databricksSqlStatementApiFixture.GetDatabricksExecutor()));
_databricksSqlStatementApiFixture.GetDatabricksExecutor(),
NullLoggerFactory.Instance));
}

[Fact(Skip = "Performance testing")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
using Energinet.DataHub.SettlementReport.Interfaces.Models;
using Energinet.DataHub.SettlementReport.Interfaces.SettlementReports_v2.Models;
using Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Fixtures;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Xunit;

namespace Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Infrastructure.SettlementReports_v2;
Expand Down Expand Up @@ -50,7 +53,8 @@ public SettlementReportChargePricesRepositoryTests(MigrationsFreeDatabricksSqlSt

Fixture.Inject<ISettlementReportDatabricksContext>(new SettlementReportDatabricksContext(
_databricksSqlStatementApiFixture.DatabricksSchemaManager.DeltaTableOptions,
_databricksSqlStatementApiFixture.GetDatabricksExecutor()));
_databricksSqlStatementApiFixture.GetDatabricksExecutor(),
NullLoggerFactory.Instance));
}

[Fact(Skip = "Performance testing")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
using Energinet.DataHub.SettlementReport.Interfaces.Models;
using Energinet.DataHub.SettlementReport.Interfaces.SettlementReports_v2.Models;
using Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Fixtures;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Xunit;

namespace Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Infrastructure.SettlementReports_v2;
Expand All @@ -38,7 +41,8 @@ public SettlementReportEnergyResultRepositoryTests(MigrationsFreeDatabricksSqlSt

Fixture.Inject<ISettlementReportDatabricksContext>(new SettlementReportDatabricksContext(
_databricksSqlStatementApiFixture.DatabricksSchemaManager.DeltaTableOptions,
_databricksSqlStatementApiFixture.GetDatabricksExecutor()));
_databricksSqlStatementApiFixture.GetDatabricksExecutor(),
NullLoggerFactory.Instance));
}

[Fact(Skip = "Performance testing")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
using Energinet.DataHub.SettlementReport.Interfaces.SettlementReports_v2.Models;
using Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Fixtures;
using FluentAssertions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Xunit;

namespace Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Infrastructure.SettlementReports_v2;
Expand All @@ -39,7 +42,8 @@ public SettlementReportMeteringPointMasterDataRepositoryTests(MigrationsFreeData

Fixture.Inject<ISettlementReportDatabricksContext>(new SettlementReportDatabricksContext(
_databricksSqlStatementApiFixture.DatabricksSchemaManager.DeltaTableOptions,
_databricksSqlStatementApiFixture.GetDatabricksExecutor()));
_databricksSqlStatementApiFixture.GetDatabricksExecutor(),
NullLoggerFactory.Instance));
}

[Fact(Skip = "Performance testing")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
using Energinet.DataHub.SettlementReport.Interfaces.Models;
using Energinet.DataHub.SettlementReport.Interfaces.SettlementReports_v2.Models;
using Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Fixtures;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Xunit;

namespace Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Infrastructure.SettlementReports_v2;
Expand All @@ -39,7 +42,8 @@ public SettlementReportMeteringPointTimeSeriesResultRepositoryTests(MigrationsFr

Fixture.Inject<ISettlementReportDatabricksContext>(new SettlementReportDatabricksContext(
_databricksSqlStatementApiFixture.DatabricksSchemaManager.DeltaTableOptions,
_databricksSqlStatementApiFixture.GetDatabricksExecutor()));
_databricksSqlStatementApiFixture.GetDatabricksExecutor(),
NullLoggerFactory.Instance));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
using Energinet.DataHub.SettlementReport.Interfaces.Models;
using Energinet.DataHub.SettlementReport.Interfaces.SettlementReports_v2.Models;
using Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Fixtures;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Xunit;

namespace Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Infrastructure.SettlementReports_v2;
Expand All @@ -38,7 +41,8 @@ public SettlementReportMonthlyAmountRepositoryTests(MigrationsFreeDatabricksSqlS

Fixture.Inject<ISettlementReportDatabricksContext>(new SettlementReportDatabricksContext(
_databricksSqlStatementApiFixture.DatabricksSchemaManager.DeltaTableOptions,
_databricksSqlStatementApiFixture.GetDatabricksExecutor()));
_databricksSqlStatementApiFixture.GetDatabricksExecutor(),
NullLoggerFactory.Instance));
}

[Fact(Skip = "Performance testing")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
using Energinet.DataHub.SettlementReport.Interfaces.Models;
using Energinet.DataHub.SettlementReport.Interfaces.SettlementReports_v2.Models;
using Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Fixtures;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Xunit;

namespace Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Infrastructure.SettlementReports_v2;
Expand All @@ -38,7 +41,8 @@ public SettlementReportMonthlyAmountTotalRepositoryTests(MigrationsFreeDatabrick

Fixture.Inject<ISettlementReportDatabricksContext>(new SettlementReportDatabricksContext(
_databricksSqlStatementApiFixture.DatabricksSchemaManager.DeltaTableOptions,
_databricksSqlStatementApiFixture.GetDatabricksExecutor()));
_databricksSqlStatementApiFixture.GetDatabricksExecutor(),
NullLoggerFactory.Instance));
}

[Fact(Skip = "Performance testing")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
using Energinet.DataHub.SettlementReport.Interfaces.Models;
using Energinet.DataHub.SettlementReport.Interfaces.SettlementReports_v2.Models;
using Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Fixtures;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Xunit;

namespace Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Infrastructure.SettlementReports_v2;
Expand All @@ -38,7 +41,8 @@ public SettlementReportWholesaleRepositoryTests(MigrationsFreeDatabricksSqlState

Fixture.Inject<ISettlementReportDatabricksContext>(new SettlementReportDatabricksContext(
_databricksSqlStatementApiFixture.DatabricksSchemaManager.DeltaTableOptions,
_databricksSqlStatementApiFixture.GetDatabricksExecutor()));
_databricksSqlStatementApiFixture.GetDatabricksExecutor(),
NullLoggerFactory.Instance));
}

[Fact(Skip = "Performance testing")]
Expand Down

0 comments on commit 2d1c594

Please sign in to comment.