Skip to content

Commit

Permalink
feat: Update input for BRS-026 & BRS-028 processes (#38)
Browse files Browse the repository at this point in the history
* Update input for request processes

* Update orchestrations package

* Update ReleaseNotes.md

* Fix test

* Bump client packages

* Update service bus sender name

* Add health check for subscription

* Add health checks

* Bump versions

* Fix build

* Add config to DI

* Update ProcessManagerTopicOptions.cs

* Fix tests

* Update RequestCalculatedEnergyTimeSeriesTests.cs
  • Loading branch information
ebbeknudsen authored Dec 16, 2024
1 parent 6ea37fc commit ffe1efd
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 18 deletions.
6 changes: 5 additions & 1 deletion docs/ProcessManager.Client/ReleaseNotes/ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# ProcessManager.Client Release Notes

## Version 0.14.3

- No functional changes

## Version 0.14.2

- No functional change
- No functional changes

## Version 0.14.1

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# ProcessManager.Orchestrations.Abstractions Release Notes

## Version 0.2.4

- Update (implement) correct input for starting BRS-026 and BRS-028 orchestrations.

## Version 0.2.3

- No functional change
- No functional changes.

## Version 0.2.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<PropertyGroup>
<PackageId>Energinet.DataHub.ProcessManager.Abstractions</PackageId>
<PackageVersion>0.14.2$(VersionSuffix)</PackageVersion>
<PackageVersion>0.14.3$(VersionSuffix)</PackageVersion>
<Title>DH3 Process Manager Abstractions library</Title>
<Company>Energinet-DataHub</Company>
<Authors>Energinet-DataHub</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,22 @@ public async Task DisposeAsync()
public async Task RequestCalculatedEnergyTimeSeries_WhenStarted_OrchestrationCompletesWithSuccess()
{
// Arrange
var businessReason = "test-business-reason";
var businessReason = "BalanceFixing";
var energySupplierNumber = "23143245321";
var startRequestCommand = new StartRequestCalculatedEnergyTimeSeriesCommandV1(
new ActorIdentityDto(Guid.NewGuid()),
new RequestCalculatedEnergyTimeSeriesInputV1(businessReason),
new RequestCalculatedEnergyTimeSeriesInputV1(
RequestedForActorNumber: energySupplierNumber,
RequestedForActorRole: "EnergySupplier",
BusinessReason: businessReason,
PeriodStart: "2024-04-07 23:00:00",
PeriodEnd: "2024-04-08 23:00:00",
EnergySupplierNumber: energySupplierNumber,
BalanceResponsibleNumber: null,
GridAreas: ["804"],
MeteringPointType: null,
SettlementMethod: null,
SettlementVersion: null),
"test-message-id");

var processManagerMessageClient = ServiceProvider.GetRequiredService<IProcessManagerMessageClient>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static IServiceCollection AddProcessManagerMessageClient(this IServiceCol

return serviceBusSender;
})
.WithName(nameof(ProcessManagerServiceBusClientOptions.TopicName));
.WithName(ServiceBusSenderNames.ProcessManagerTopic);
});

services.AddScoped<IProcessManagerMessageClient, ProcessManagerMessageClient>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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 Azure.Messaging.ServiceBus;

namespace Energinet.DataHub.ProcessManager.Client.Extensions.DependencyInjection;

/// <summary>
/// Constants used for naming <see cref="ServiceBusSender"/> instances
/// </summary>
public static class ServiceBusSenderNames
{
/// <summary>
/// Service Bus sender for sending messages on the process manager service bus topic
/// </summary>
public const string ProcessManagerTopic = "ProcessManagerTopic";
}
2 changes: 1 addition & 1 deletion source/ProcessManager.Client/ProcessManager.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<PropertyGroup>
<PackageId>Energinet.DataHub.ProcessManager.Client</PackageId>
<PackageVersion>0.14.2$(VersionSuffix)</PackageVersion>
<PackageVersion>0.14.3$(VersionSuffix)</PackageVersion>
<Title>DH3 Process Manager Client library</Title>
<Company>Energinet-DataHub</Company>
<Authors>Energinet-DataHub</Authors>
Expand Down
3 changes: 2 additions & 1 deletion source/ProcessManager.Client/ProcessManagerMessageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Azure.Messaging.ServiceBus;
using Energinet.DataHub.ProcessManager.Abstractions.Api.Model;
using Energinet.DataHub.ProcessManager.Abstractions.Contracts;
using Energinet.DataHub.ProcessManager.Client.Extensions.DependencyInjection;
using Energinet.DataHub.ProcessManager.Client.Extensions.Options;
using Google.Protobuf;
using Microsoft.Extensions.Azure;
Expand All @@ -26,7 +27,7 @@ public class ProcessManagerMessageClient(
IAzureClientFactory<ServiceBusSender> serviceBusFactory)
: IProcessManagerMessageClient
{
private readonly ServiceBusSender _serviceBusSender = serviceBusFactory.CreateClient(nameof(ProcessManagerServiceBusClientOptions.TopicName));
private readonly ServiceBusSender _serviceBusSender = serviceBusFactory.CreateClient(ServiceBusSenderNames.ProcessManagerTopic);

public Task StartNewOrchestrationInstanceAsync<TInputParameterDto>(
MessageCommand<TInputParameterDto> command,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<PropertyGroup>
<PackageId>Energinet.DataHub.ProcessManager.Orchestrations.Abstractions</PackageId>
<PackageVersion>0.2.3$(VersionSuffix)</PackageVersion>
<PackageVersion>0.2.4$(VersionSuffix)</PackageVersion>
<Title>DH3 Process Manager Orchestrations Abstractions library</Title>
<Company>Energinet-DataHub</Company>
<Authors>Energinet-DataHub</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,33 @@

namespace Energinet.DataHub.ProcessManager.Orchestrations.Abstractions.Processes.BRS_026.V1.Model;

/// <summary>
/// The input required to start a BRS-026 RequestCalculatedEnergyTimeSeries process.
/// </summary>
/// <param name="RequestedForActorNumber">GLN or EIC of the Actor for whom to retrieve data. Typically 13 og 16 numbers.</param>
/// <param name="RequestedForActorRole">The actor role of the Actor for whom to retrieve data. Eg: GridOperator, EnergySupplier etc.</param>
/// <param name="BusinessReason">The requested business reason. Eg: BalanceFixing, Correction etc.</param>
/// <param name="PeriodStart">The start of the requested period.</param>
/// <param name="PeriodEnd">Optional end of the requested period.</param>
/// <param name="EnergySupplierNumber">Optional GLN or EIC for the energy supplier.</param>
/// <param name="BalanceResponsibleNumber">Optional GLN or EIC for the balance responsible.</param>
/// <param name="GridAreas">Grid area codes to retreive data in. Eg: 870, 540 etc.</param>
/// <param name="MeteringPointType">Optional metering point types to retrieve data for. Eg: Consumption, Production etc.</param>
/// <param name="SettlementMethod">Optional settlement method to retrieve data for. Eg: NonProfiled, Flex etc.</param>
/// <param name="SettlementVersion">
/// Optional version of the requested correction. Eg: First-, Second- or ThirdCorrection.
/// Should only be set if BusinessReason is a Correction. Will find the latest correction if not provided.
/// </param>
public record RequestCalculatedEnergyTimeSeriesInputV1(
string BusinessReason)
: IInputParameterDto;
string RequestedForActorNumber,
string RequestedForActorRole,
string BusinessReason,
string PeriodStart,
string? PeriodEnd,
string? EnergySupplierNumber,
string? BalanceResponsibleNumber,
IReadOnlyCollection<string> GridAreas,
string? MeteringPointType,
string? SettlementMethod,
string? SettlementVersion)
: IInputParameterDto;
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,38 @@

namespace Energinet.DataHub.ProcessManager.Orchestrations.Abstractions.Processes.BRS_028.V1.Model;

public record RequestCalculatedWholesaleServicesInputV1()
: IInputParameterDto;
/// <summary>
/// The input required to start a BRS-028 RequestCalculatedWholesaleServices process.
/// </summary>
/// <param name="RequestedForActorNumber">GLN or EIC of the Actor for whom to retrieve data. Typically 13 og 16 numbers.</param>
/// <param name="RequestedForActorRole">The actor role of the Actor for whom to retrieve data. Eg: GridOperator, EnergySupplier etc.</param>
/// <param name="BusinessReason">The requested business reason. Eg: WholesaleFixing, Correction etc.</param>
/// <param name="Resolution">Should be set to Monthly if requesting monthly sums, otherwise null to request amount pr. charge (Daily/Hourly).</param>
/// <param name="PeriodStart">The start of the requested period.</param>
/// <param name="PeriodEnd">Optional end of the requested period.</param>
/// <param name="EnergySupplierNumber">Optional GLN or EIC for the energy supplier on the charge.</param>
/// <param name="ChargeOwnerNumber">Optional GLN or EIC for the party that owns the charge.</param>
/// <param name="GridAreas">Grid area codes to retreive data in. Eg: 870, 540 etc.</param>
/// <param name="SettlementVersion">
/// Optional version of the requested correction. Eg: First-, Second- or ThirdCorrection.
/// Should only be set if BusinessReason is a Correction. Will find the latest correction if not provided.
/// </param>
/// <param name="ChargeTypes">Optional charge types/codes to retrieve data for.</param>
public record RequestCalculatedWholesaleServicesInputV1(
string RequestedForActorNumber,
string RequestedForActorRole,
string BusinessReason,
string? Resolution,
string PeriodStart,
string? PeriodEnd,
string? EnergySupplierNumber,
string? ChargeOwnerNumber,
IReadOnlyCollection<string> GridAreas,
string? SettlementVersion,
IReadOnlyCollection<RequestCalculatedWholesaleServicesInputV1.ChargeTypeInputV1>? ChargeTypes)
: IInputParameterDto
{
public record ChargeTypeInputV1(
string? ChargeType,
string? ChargeCode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using Azure.Identity;
using Energinet.DataHub.Core.App.Common.Diagnostics.HealthChecks;
using Energinet.DataHub.Core.Messaging.Communication.Extensions.Options;
using Energinet.DataHub.ProcessManager.Orchestrations.Extensions.Options;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

namespace Energinet.DataHub.ProcessManager.Orchestrations.Extensions.DependencyInjection;

Expand All @@ -22,13 +26,30 @@ public static class ProcessManagerTopicExtensions
/// <summary>
/// Add required dependencies to use the Process Manager Service Bus topic.
/// </summary>
public static IServiceCollection AddProcessManagerTopic(this IServiceCollection services)
public static IServiceCollection AddProcessManagerTopic(this IServiceCollection services, DefaultAzureCredential credential)
{
services.AddOptions<ServiceBusNamespaceOptions>()
.BindConfiguration(ServiceBusNamespaceOptions.SectionName)
.ValidateDataAnnotations();

services
.AddOptions<ProcessManagerTopicOptions>()
.BindConfiguration(ProcessManagerTopicOptions.SectionName)
.ValidateDataAnnotations();

services.AddHealthChecks()
.AddAzureServiceBusTopic(
fullyQualifiedNamespaceFactory: sp => sp.GetRequiredService<IOptions<ServiceBusNamespaceOptions>>().Value.FullyQualifiedNamespace,
topicNameFactory: sp => sp.GetRequiredService<IOptions<ProcessManagerTopicOptions>>().Value.TopicName,
tokenCredentialFactory: _ => credential,
name: "Process Manager Topic")
.AddAzureServiceBusSubscription(
fullyQualifiedNamespaceFactory: sp => sp.GetRequiredService<IOptions<ServiceBusNamespaceOptions>>().Value.FullyQualifiedNamespace,
topicNameFactory: sp => sp.GetRequiredService<IOptions<ProcessManagerTopicOptions>>().Value.TopicName,
subscriptionNameFactory: sp => sp.GetRequiredService<IOptions<ProcessManagerTopicOptions>>().Value.Brs026SubscriptionName,
tokenCredentialFactory: _ => credential,
name: "BRS-026 Subscription");

return services;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ public class ProcessManagerTopicOptions
/// Name of the ProcessManager Service Bus topic
/// </summary>
[Required]
public string TopicName { get; } = string.Empty;
public string TopicName { get; set; } = string.Empty;

/// <summary>
/// Name of the subscription for BRS026 to the ProcessManager Service Bus topic
/// </summary>
[Required]
public string Brs026SubscriptionName { get; } = string.Empty;
public string Brs026SubscriptionName { get; set; } = string.Empty;

/// <summary>
/// Name of the subscription for BRS021 ForwardMeteredData to the ProcessManager Service Bus topic
/// </summary>
//[Required] // TODO: Removed required for now since tests cannot be run (yet)
public string Brs021ForwardMeteredDataSubscriptionName { get; } = string.Empty;
public string Brs021ForwardMeteredDataSubscriptionName { get; set; } = string.Empty;
}
8 changes: 7 additions & 1 deletion source/ProcessManager.Orchestrations/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using Azure.Identity;
using Energinet.DataHub.Core.App.Common.Extensions.DependencyInjection;
using Energinet.DataHub.Core.App.FunctionApp.Extensions.Builder;
using Energinet.DataHub.Core.App.FunctionApp.Extensions.DependencyInjection;
Expand All @@ -28,20 +29,25 @@
using Energinet.DataHub.ProcessManager.Orchestrations.Processes.BRS_021.ForwardMeteredData.V1;
using Energinet.DataHub.ProcessManager.Orchestrations.Processes.BRS_023_027.V1;
using Energinet.DataHub.ProcessManager.Orchestrations.Processes.BRS_026.V1;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

var host = new HostBuilder()
.ConfigureFunctionsWebApplication()
.ConfigureServices((context, services) =>
{
services.AddTransient<IConfiguration>(_ => context.Configuration);

var azureCredential = new DefaultAzureCredential();

// Common
services.AddApplicationInsightsForIsolatedWorker(TelemetryConstants.SubsystemName);
services.AddHealthChecksForIsolatedWorker();
services.AddNodaTimeForApplication();

// ProcessManager
services.AddProcessManagerTopic();
services.AddProcessManagerTopic(azureCredential);
// => Orchestration Descriptions
services.AddProcessManagerForOrchestrations(() =>
{
Expand Down

0 comments on commit ffe1efd

Please sign in to comment.