-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21e21a4
commit 360a217
Showing
12 changed files
with
141 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...lement-report/SettlementReports.Infrastructure/Handlers/RequestSettlementReportHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2020 Energinet DataHub A/S | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License2"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using Energinet.DataHub.Core.Databricks.Jobs.Abstractions; | ||
using Energinet.DataHub.SettlementReport.Infrastructure.Commands; | ||
using Energinet.DataHub.SettlementReport.Infrastructure.SqlStatements.Mappers; | ||
using Energinet.DataHub.SettlementReport.Interfaces.SettlementReports_v2.Models; | ||
using Microsoft.Azure.Databricks.Client.Models; | ||
|
||
namespace Energinet.DataHub.SettlementReport.Infrastructure.Handlers; | ||
|
||
public sealed class RequestSettlementReportHandler : IRequestSettlemenReportJobHandler | ||
{ | ||
private readonly IJobsApiClient _jobsApiClient; | ||
|
||
public RequestSettlementReportHandler(IJobsApiClient jobsApiClient) | ||
{ | ||
_jobsApiClient = jobsApiClient; | ||
} | ||
|
||
public async Task<long> HandleAsync(RequestSettlementReportJobCommand command) | ||
{ | ||
var parameters = CreateParameters(command.Request); | ||
return await _jobsApiClient.Jobs.RunNow(1, parameters).ConfigureAwait(false); | ||
} | ||
|
||
private RunParameters CreateParameters(SettlementReportRequestDto request) | ||
{ | ||
var gridAreas = string.Join(", ", request.Filter.GridAreas.Select(c => c.Key)); | ||
|
||
var jobParameters = new List<string> | ||
{ | ||
$"--grid-areas=[{gridAreas}]", | ||
$"--period-start-datetime={request.Filter.PeriodStart}", | ||
$"--period-end-datetime={request.Filter.PeriodEnd}", | ||
$"--calculation-type={CalculationTypeMapper.ToDeltaTableValue(request.Filter.CalculationType)}", | ||
}; | ||
|
||
return RunParameters.CreatePythonParams(jobParameters); | ||
} | ||
|
||
private async Task<Job> GetSettlementReportsJobAsync() | ||
{ | ||
var calculatorJob = await _jobsApiClient.Jobs | ||
.ListPageable(name: "CalculatorJob") | ||
.SingleAsync() | ||
.ConfigureAwait(false); | ||
|
||
return await _jobsApiClient.Jobs.Get(calculatorJob.JobId).ConfigureAwait(false); | ||
} | ||
} |
25 changes: 0 additions & 25 deletions
25
...ement-report/SettlementReports.Infrastructure/Handlers/RequestSettlementReporthHandler.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...ttlementReports.WebAPI/Extensions/DependencyInjection/SettlementReportModuleExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2020 Energinet DataHub A/S | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License2"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using Energinet.DataHub.Core.App.Common.Extensions.DependencyInjection; | ||
using Energinet.DataHub.SettlementReport.Common.Infrastructure.Extensions.Options; | ||
using Energinet.DataHub.SettlementReport.Common.Infrastructure.HealthChecks; | ||
using Energinet.DataHub.SettlementReport.Infrastructure.Handlers; | ||
using Energinet.DataHub.SettlementReport.Infrastructure.Persistence; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace SettlementReports.WebAPI.Extensions.DependencyInjection; | ||
|
||
public static class SettlementReportModuleExtensions | ||
{ | ||
public static IServiceCollection AddSettlementReportApiModule(this IServiceCollection services, IConfiguration configuration) | ||
{ | ||
ArgumentNullException.ThrowIfNull(configuration); | ||
|
||
// handlers | ||
services.AddScoped<IRequestSettlemenReportJobHandler, RequestSettlementReportHandler>(); | ||
|
||
services.AddScoped<ISettlementReportDatabaseContext, SettlementReportDatabaseContext>(); | ||
services.AddDbContext<SettlementReportDatabaseContext>( | ||
options => options.UseSqlServer( | ||
configuration | ||
.GetSection(ConnectionStringsOptions.ConnectionStrings) | ||
.Get<ConnectionStringsOptions>()!.DB_CONNECTION_STRING, | ||
o => | ||
{ | ||
o.UseNodaTime(); | ||
o.EnableRetryOnFailure(); | ||
})); | ||
|
||
// Database Health check | ||
services.TryAddHealthChecks( | ||
registrationKey: HealthCheckNames.SettlementReportDatabase, | ||
(key, builder) => | ||
{ | ||
builder.AddDbContextCheck<SettlementReportDatabaseContext>(name: key); | ||
}); | ||
|
||
AddHealthChecks(services); | ||
|
||
return services; | ||
} | ||
|
||
private static void AddHealthChecks(IServiceCollection services) | ||
{ | ||
services | ||
.AddHealthChecks(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters