-
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
6f22de1
commit 768e983
Showing
6 changed files
with
119 additions
and
43 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
77 changes: 77 additions & 0 deletions
77
source/settlement-report/SettlementReports.Infrastructure/Helpers/DatabricksJobsHelper.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,77 @@ | ||
// 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.Handlers; | ||
using Energinet.DataHub.SettlementReport.Infrastructure.SqlStatements.Mappers; | ||
using Energinet.DataHub.SettlementReport.Interfaces.Models; | ||
using Energinet.DataHub.SettlementReport.Interfaces.SettlementReports_v2.Models; | ||
using Microsoft.Azure.Databricks.Client.Models; | ||
|
||
namespace Energinet.DataHub.SettlementReport.Infrastructure.Helpers; | ||
|
||
public class DatabricksJobsHelper : IDatabricksJobsHelper | ||
{ | ||
private readonly IJobsApiClient _jobsApiClient; | ||
|
||
public DatabricksJobsHelper(IJobsApiClient jobsApiClient) | ||
{ | ||
_jobsApiClient = jobsApiClient; | ||
} | ||
|
||
public async Task<long> RunSettlementReportsJobAsync(SettlementReportRequestDto request) | ||
{ | ||
var job = await GetSettlementReportsJobAsync(GetJobName(request.Filter.CalculationType)).ConfigureAwait(false); | ||
return await _jobsApiClient.Jobs.RunNow(job.JobId, CreateParameters(request)).ConfigureAwait(false); | ||
} | ||
|
||
private string GetJobName(CalculationType calculationType) | ||
{ | ||
return calculationType switch | ||
{ | ||
CalculationType.BalanceFixing => DatabricksJobNames.BalanceFixing, | ||
CalculationType.WholesaleFixing => DatabricksJobNames.Wholesale, | ||
CalculationType.FirstCorrectionSettlement => DatabricksJobNames.Wholesale, | ||
CalculationType.SecondCorrectionSettlement => DatabricksJobNames.Wholesale, | ||
CalculationType.ThirdCorrectionSettlement => DatabricksJobNames.Wholesale, | ||
CalculationType.Aggregation => DatabricksJobNames.Wholesale, | ||
_ => throw new ArgumentOutOfRangeException(nameof(calculationType), calculationType, null), | ||
}; | ||
} | ||
|
||
private async Task<Job> GetSettlementReportsJobAsync(string jobName) | ||
{ | ||
var calculatorJob = await _jobsApiClient.Jobs | ||
.ListPageable(name: jobName) | ||
.SingleAsync() | ||
.ConfigureAwait(false); | ||
|
||
return await _jobsApiClient.Jobs.Get(calculatorJob.JobId).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); | ||
} | ||
} |
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