From be7f0dfa794475b8621bc3da0dd7721d5e707d4e Mon Sep 17 00:00:00 2001 From: Jesper Justesen <1972142+FirestarJes@users.noreply.github.com> Date: Wed, 25 Sep 2024 10:42:49 +0200 Subject: [PATCH] Add new job params --- .../RequestSettlementReportCommand.cs | 2 +- .../RequestSettlementReportHandler.cs | 2 +- .../Helpers/DatabricksJobsHelper.cs | 31 ++++++++++--------- .../Helpers/IDatabricksJobsHelper.cs | 3 +- .../RequestSettlementReportHandlerTests.cs | 4 +-- .../SettlementReportsController.cs | 6 +--- 6 files changed, 23 insertions(+), 25 deletions(-) diff --git a/source/settlement-report/SettlementReports.Application/Commands/RequestSettlementReportCommand.cs b/source/settlement-report/SettlementReports.Application/Commands/RequestSettlementReportCommand.cs index 209d9f1..53ab539 100644 --- a/source/settlement-report/SettlementReports.Application/Commands/RequestSettlementReportCommand.cs +++ b/source/settlement-report/SettlementReports.Application/Commands/RequestSettlementReportCommand.cs @@ -21,5 +21,5 @@ public sealed record RequestSettlementReportCommand( Guid UserId, Guid ActorId, bool IsFas, - string? ChargeOwnerId, + string ActorGln, MarketRole MarketRole); diff --git a/source/settlement-report/SettlementReports.Application/Handlers/RequestSettlementReportHandler.cs b/source/settlement-report/SettlementReports.Application/Handlers/RequestSettlementReportHandler.cs index 302b93c..eb89afd 100644 --- a/source/settlement-report/SettlementReports.Application/Handlers/RequestSettlementReportHandler.cs +++ b/source/settlement-report/SettlementReports.Application/Handlers/RequestSettlementReportHandler.cs @@ -35,7 +35,7 @@ public RequestSettlementReportHandler( public async Task HandleAsync(RequestSettlementReportCommand request) { var reportId = new SettlementReportRequestId(Guid.NewGuid().ToString()); - var runId = await _jobHelper.RunSettlementReportsJobAsync(request.RequestDto, request.MarketRole, reportId).ConfigureAwait(false); + var runId = await _jobHelper.RunSettlementReportsJobAsync(request.RequestDto, request.MarketRole, reportId, request.ActorGln).ConfigureAwait(false); await _settlementReportInitializeHandler .InitializeFromJobAsync( request.UserId, diff --git a/source/settlement-report/SettlementReports.Infrastructure/Helpers/DatabricksJobsHelper.cs b/source/settlement-report/SettlementReports.Infrastructure/Helpers/DatabricksJobsHelper.cs index 24628ed..51ad662 100644 --- a/source/settlement-report/SettlementReports.Infrastructure/Helpers/DatabricksJobsHelper.cs +++ b/source/settlement-report/SettlementReports.Infrastructure/Helpers/DatabricksJobsHelper.cs @@ -35,10 +35,11 @@ public DatabricksJobsHelper(IJobsApiClient jobsApiClient) public async Task RunSettlementReportsJobAsync( SettlementReportRequestDto request, MarketRole marketRole, - SettlementReportRequestId reportId) + SettlementReportRequestId reportId, + string actorGln) { var job = await GetSettlementReportsJobAsync(GetJobName(request.Filter.CalculationType)).ConfigureAwait(false); - return new JobRunId(await _jobsApiClient.Jobs.RunNow(job.JobId, CreateParameters(request, marketRole, reportId)).ConfigureAwait(false)); + return new JobRunId(await _jobsApiClient.Jobs.RunNow(job.JobId, CreateParameters(request, marketRole, reportId, actorGln)).ConfigureAwait(false)); } public async Task GetSettlementReportsJobStatusAsync(long runId) @@ -71,36 +72,36 @@ private async Task GetSettlementReportsJobAsync(string jobName) return await _jobsApiClient.Jobs.Get(settlementJob.JobId).ConfigureAwait(false); } - private RunParameters CreateParameters(SettlementReportRequestDto request, MarketRole marketRole, SettlementReportRequestId reportId) + private RunParameters CreateParameters(SettlementReportRequestDto request, MarketRole marketRole, SettlementReportRequestId reportId, string actorGln) { var gridAreas = $"{{{string.Join(", ", request.Filter.GridAreas.Select(c => $"\"{c.Key}\": \"{(c.Value is null ? string.Empty : c.Value?.Id)}\""))}}}"; - var jobParameters = new Dictionary() + var jobParameters = new List { - { "report-id", reportId.Id }, - { "calculation-type", CalculationTypeMapper.ToDeltaTableValue(request.Filter.CalculationType) }, - { "calculation-id-by-grid-area", gridAreas }, - { "period-start", request.Filter.PeriodStart.ToInstant().ToString() }, - { "period-end", request.Filter.PeriodEnd.ToInstant().ToString() }, - { "market-role", MapMarketRole(marketRole) }, + $"--report-id={reportId.Id}", + $"--calculation-type={CalculationTypeMapper.ToDeltaTableValue(request.Filter.CalculationType)}", + $"--calculation-id-by-grid-area={gridAreas}", + $"--period-start={request.Filter.PeriodStart.ToInstant()}", + $"--period-end={request.Filter.PeriodEnd.ToInstant()}", + $"--requesting-actor-market-role={MapMarketRole(request.MarketRoleOverride ?? marketRole)}", + $"--requesting-actor-id={actorGln}", }; - if (request.Filter.EnergySupplier != null) { - jobParameters.Add("energy-supplier-id", request.Filter.EnergySupplier); + jobParameters.Add($"--energy-supplier-id={request.Filter.EnergySupplier}"); } if (request.SplitReportPerGridArea) { - jobParameters.Add("split-report-by-grid-area", request.SplitReportPerGridArea.ToString()); + jobParameters.Add("--split-report-by-grid-area"); } if (request.PreventLargeTextFiles) { - jobParameters.Add("prevent-large-text-files", request.PreventLargeTextFiles.ToString()); + jobParameters.Add("--prevent-large-text-files"); } - return RunParameters.CreateJobParams(jobParameters); + return RunParameters.CreatePythonParams(jobParameters); } private static string MapMarketRole(MarketRole marketRole) diff --git a/source/settlement-report/SettlementReports.Interfaces/Helpers/IDatabricksJobsHelper.cs b/source/settlement-report/SettlementReports.Interfaces/Helpers/IDatabricksJobsHelper.cs index 7372631..b5279c9 100644 --- a/source/settlement-report/SettlementReports.Interfaces/Helpers/IDatabricksJobsHelper.cs +++ b/source/settlement-report/SettlementReports.Interfaces/Helpers/IDatabricksJobsHelper.cs @@ -21,7 +21,8 @@ public interface IDatabricksJobsHelper Task RunSettlementReportsJobAsync( SettlementReportRequestDto request, MarketRole marketRole, - SettlementReportRequestId reportId); + SettlementReportRequestId reportId, + string actorGln); Task GetSettlementReportsJobStatusAsync(long runId); } diff --git a/source/settlement-report/SettlementReports.UnitTests/Handlers/RequestSettlementReportHandlerTests.cs b/source/settlement-report/SettlementReports.UnitTests/Handlers/RequestSettlementReportHandlerTests.cs index 96038e7..3835996 100644 --- a/source/settlement-report/SettlementReports.UnitTests/Handlers/RequestSettlementReportHandlerTests.cs +++ b/source/settlement-report/SettlementReports.UnitTests/Handlers/RequestSettlementReportHandlerTests.cs @@ -51,10 +51,10 @@ public async Task Handle_ValidRequest_ReturnsJobId() var jobHelperMock = new Mock(); var jobRunId = new JobRunId(Random.Shared.NextInt64()); jobHelperMock - .Setup(x => x.RunSettlementReportsJobAsync(It.IsAny(), It.IsAny(), It.IsAny())) + .Setup(x => x.RunSettlementReportsJobAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(jobRunId); - var command = new RequestSettlementReportCommand(request, Guid.NewGuid(), Guid.NewGuid(), true, null, MarketRole.EnergySupplier); + var command = new RequestSettlementReportCommand(request, Guid.NewGuid(), Guid.NewGuid(), true, "1233", MarketRole.EnergySupplier); var handler = new RequestSettlementReportHandler(jobHelperMock.Object, initializerMock.Object); // Act diff --git a/source/settlement-report/SettlementReports.WebAPI/Controllers/SettlementReportsController.cs b/source/settlement-report/SettlementReports.WebAPI/Controllers/SettlementReportsController.cs index 5abecbd..d3b2739 100644 --- a/source/settlement-report/SettlementReports.WebAPI/Controllers/SettlementReportsController.cs +++ b/source/settlement-report/SettlementReports.WebAPI/Controllers/SettlementReportsController.cs @@ -92,16 +92,12 @@ public async Task> RequestSettlementReport([FromBody] Settlem return BadRequest(); } - var chargeOwnerId = marketRole is MarketRole.GridAccessProvider or MarketRole.SystemOperator - ? _userContext.CurrentUser.Actor.ActorNumber - : null; - var requestCommand = new RequestSettlementReportCommand( settlementReportRequest, _userContext.CurrentUser.UserId, _userContext.CurrentUser.Actor.ActorId, _userContext.CurrentUser.MultiTenancy, - chargeOwnerId, + _userContext.CurrentUser.Actor.ActorNumber, marketRole); var result = await _requestSettlementReportJobHandler.HandleAsync(requestCommand).ConfigureAwait(false);