Skip to content

Commit

Permalink
Merge branch 'main' into madu/new-incoming-rsm-012-json-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsDue authored Nov 20, 2024
2 parents 624a2dc + 0643d76 commit 79eb96b
Show file tree
Hide file tree
Showing 20 changed files with 662 additions and 30 deletions.
4 changes: 4 additions & 0 deletions docs/ProcessManager.Client/ReleaseNotes/ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ProcessManager.Client Release Notes

## Version 0.10.0

- Added 'RequestCalculatedDataClientV1'

## Version 0.9.3

- Updated 'NotifyAggregatedMeasureDataInputV1' with new required 'UserId' parameter/property.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// 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.ProcessManager.Client.Tests.Fixtures;
using Xunit.Abstractions;

namespace Energinet.DataHub.ProcessManager.Client.Tests.Integration.BRS_026_028.V1;

/// <summary>
/// Test collection that verifies the Process Manager clients can be used to start a
/// request calculated energy time series orchestration and monitor its status during its lifetime.
/// </summary>
[Collection(nameof(ProcessManagerClientCollection))]
public class RequestCalculatedEnergyTimeSeriesTests : IAsyncLifetime
{
private readonly ScenarioProcessManagerAppFixture _processManagerAppFixture;
private readonly ScenarioOrchestrationsAppFixture _orchestrationsAppFixture;

public RequestCalculatedEnergyTimeSeriesTests(
ScenarioProcessManagerAppFixture processManagerAppFixture,
ScenarioOrchestrationsAppFixture orchestrationsAppFixture,
ITestOutputHelper testOutputHelper)
{
_processManagerAppFixture = processManagerAppFixture;
_orchestrationsAppFixture = orchestrationsAppFixture;

_processManagerAppFixture.SetTestOutputHelper(testOutputHelper);
_orchestrationsAppFixture.SetTestOutputHelper(testOutputHelper);
}

public Task InitializeAsync()
{
_processManagerAppFixture.AppHostManager.ClearHostLog();
_orchestrationsAppFixture.AppHostManager.ClearHostLog();

return Task.CompletedTask;
}

public Task DisposeAsync()
{
_processManagerAppFixture.SetTestOutputHelper(null!);
_orchestrationsAppFixture.SetTestOutputHelper(null!);

return Task.CompletedTask;
}

[Fact]
public async Task RequestCalculatedEnergyTimeSeries_WhenStartedUsingClient_CanMonitorLifecycle()
{
// TODO: Implement test after implementation of shared Service Bus topic in app fixtures
// Arrange
// var requestCalculatedDataClient = new RequestCalculatedDataClientV1();
// var input = new RequestCalculatedDataInputV1<RequestCalculatedEnergyTimeSeriesInputV1>(
// Guid.NewGuid().ToString(),
// new RequestCalculatedEnergyTimeSeriesInputV1("B1337"));
//
// // Act
// await requestCalculatedDataClient.RequestCalculatedEnergyTimeSeriesAsync(input, CancellationToken.None);

// Assert
await Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ public MonitorCalculationUsingClientsScenario(
var services = new ServiceCollection();
services.AddScoped<IConfiguration>(_ => CreateInMemoryConfigurations(new Dictionary<string, string?>()
{
[$"{ProcessManagerClientOptions.SectionName}:{nameof(ProcessManagerClientOptions.GeneralApiBaseAddress)}"]
[$"{ProcessManagerHttpClientsOptions.SectionName}:{nameof(ProcessManagerHttpClientsOptions.GeneralApiBaseAddress)}"]
= ProcessManagerAppFixture.AppHostManager.HttpClient.BaseAddress!.ToString(),
[$"{ProcessManagerClientOptions.SectionName}:{nameof(ProcessManagerClientOptions.OrchestrationsApiBaseAddress)}"]
[$"{ProcessManagerHttpClientsOptions.SectionName}:{nameof(ProcessManagerHttpClientsOptions.OrchestrationsApiBaseAddress)}"]
= OrchestrationsAppFixture.AppHostManager.HttpClient.BaseAddress!.ToString(),
}));
services.AddProcessManagerClients();
services.AddProcessManagerHttpClients();
ServiceProvider = services.BuildServiceProvider();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using Azure.Messaging.ServiceBus;
using Energinet.DataHub.ProcessManager.Client.Extensions.Options;
using Energinet.DataHub.ProcessManager.Client.Processes.BRS_023_027.V1;
using Energinet.DataHub.ProcessManager.Client.Processes.BRS_026_028.V1;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Azure;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

Expand All @@ -27,25 +31,25 @@ namespace Energinet.DataHub.ProcessManager.Client.Extensions.DependencyInjection
public static class ClientExtensions
{
/// <summary>
/// Register Process Manager clients for use in applications.
/// Register Process Manager HTTP clients for use in applications.
/// If <see cref="IHttpContextAccessor"/> is registered we try to retrieve the "Authorization"
/// header value and forward it to the Process Manager API for authentication/authorization.
/// </summary>
public static IServiceCollection AddProcessManagerClients(this IServiceCollection services)
public static IServiceCollection AddProcessManagerHttpClients(this IServiceCollection services)
{
services
.AddOptions<ProcessManagerClientOptions>()
.BindConfiguration(ProcessManagerClientOptions.SectionName)
.AddOptions<ProcessManagerHttpClientsOptions>()
.BindConfiguration(ProcessManagerHttpClientsOptions.SectionName)
.ValidateDataAnnotations();

services.AddHttpClient(HttpClientNames.GeneralApi, (sp, httpClient) =>
{
var options = sp.GetRequiredService<IOptions<ProcessManagerClientOptions>>().Value;
var options = sp.GetRequiredService<IOptions<ProcessManagerHttpClientsOptions>>().Value;
ConfigureHttpClient(sp, httpClient, options.GeneralApiBaseAddress);
});
services.AddHttpClient(HttpClientNames.OrchestrationsApi, (sp, httpClient) =>
{
var options = sp.GetRequiredService<IOptions<ProcessManagerClientOptions>>().Value;
var options = sp.GetRequiredService<IOptions<ProcessManagerHttpClientsOptions>>().Value;
ConfigureHttpClient(sp, httpClient, options.OrchestrationsApiBaseAddress);
});

Expand All @@ -55,6 +59,38 @@ public static IServiceCollection AddProcessManagerClients(this IServiceCollectio
return services;
}

/// <summary>
/// Register Process Manager RequestCalculatedData client for use in applications.
/// <remarks>The application must register the <see cref="ServiceBusClient"/> and contain configuration for <see cref="ProcessManagerServiceBusClientsOptions"/></remarks>
/// </summary>
public static IServiceCollection AddProcessManagerRequestCalculatedDataClient(this IServiceCollection services)
{
services
.AddOptions<ProcessManagerServiceBusClientsOptions>()
.BindConfiguration(ProcessManagerServiceBusClientsOptions.SectionName)
.ValidateDataAnnotations();

services.AddAzureClients(
builder =>
{
builder.AddClient<ServiceBusSender, ServiceBusClientOptions>(
(_, _, provider) =>
{
var serviceBusOptions = provider.GetRequiredService<IOptions<ProcessManagerServiceBusClientsOptions>>().Value;
var serviceBusSender = provider
.GetRequiredService<ServiceBusClient>()
.CreateSender(serviceBusOptions.TopicName);

return serviceBusSender;
})
.WithName(nameof(ProcessManagerServiceBusClientsOptions.TopicName));
});

services.AddScoped<IRequestCalculatedDataClientV1, RequestCalculatedDataClientV1>();

return services;
}

/// <summary>
/// Configure http client base address; and if available then apply
/// the authorization header from the current HTTP context.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
namespace Energinet.DataHub.ProcessManager.Client.Extensions.Options;

/// <summary>
/// Options for the configuration of Process Manager clients using the Process Manager API.
/// Options for the configuration of Process Manager HTTP clients using the Process Manager API.
/// </summary>
public class ProcessManagerClientOptions
public class ProcessManagerHttpClientsOptions
{
public const string SectionName = "ProcessManagerClient";
public const string SectionName = "ProcessManagerHttpClients";

/// <summary>
/// Address to the general Api hosted in Process Manager.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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 System.ComponentModel.DataAnnotations;
using Microsoft.Extensions.Configuration;

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

/// <summary>
/// Options for configuration of Process Manager Service Bus clients using the Process Manager.
/// </summary>
public class ProcessManagerServiceBusClientsOptions
{
public const string SectionName = "ProcessManagerServiceBusClients";

/// <summary>
/// Name of the topic which the Process Manager receives service bus messages on
/// </summary>
[Required]
public string TopicName { get; set; } = string.Empty;
}
21 changes: 20 additions & 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.9.3$(VersionSuffix)</PackageVersion>
<PackageVersion>0.10.0$(VersionSuffix)</PackageVersion>
<Title>DH3 Process Manager Client library</Title>
<Company>Energinet-DataHub</Company>
<Authors>Energinet-DataHub</Authors>
Expand Down Expand Up @@ -62,16 +62,35 @@
<Compile Include="..\Shared\ProcessManager\Api\Model\ScheduleOrchestrationInstanceDto.cs" Link="Model\ScheduleOrchestrationInstanceDto.cs" />
<Compile Include="..\Shared\ProcessManager\Orchestrations\Processes\BRS_023_027\V1\Model\CalculationTypes.cs" Link="Processes\BRS_023_027\V1\Model\CalculationTypes.cs" />
<Compile Include="..\Shared\ProcessManager\Orchestrations\Processes\BRS_023_027\V1\Model\NotifyAggregatedMeasureDataInputV1.cs" Link="Processes\BRS_023_027\V1\Model\NotifyAggregatedMeasureDataInputV1.cs" />
<Compile Include="..\Shared\ProcessManager\Orchestrations\Processes\BRS_026\V1\Model\RequestCalculatedEnergyTimeSeriesInputV1.cs">
<Link>Processes\BRS_026_028\V1\Model\RequestCalculatedEnergyTimeSeriesInputV1.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.18.1" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.7.6" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="8.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Google.Protobuf" Version="3.28.2" />
<PackageReference Include="Grpc.Tools" Version="2.62.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Protobuf Include="../Shared/**/*.proto">
<GrpcServices>None</GrpcServices>
<Access>Public</Access>
<ProtoCompile>True</ProtoCompile>
<CompileOutputs>True</CompileOutputs>
<Generator>MSBuild:Compile</Generator>
</Protobuf>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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.ProcessManager.Client.Processes.BRS_026_028.V1.Model;
using Energinet.DataHub.ProcessManager.Orchestrations.Processes.BRS_026.V1.Models;

namespace Energinet.DataHub.ProcessManager.Client.Processes.BRS_026_028.V1;

/// <summary>
/// Client for the BRS-026/BRS-028 process
/// </summary>
public interface IRequestCalculatedDataClientV1
{
/// <summary>
/// Start a request for energy results
/// </summary>
public Task RequestCalculatedEnergyTimeSeriesAsync(RequestCalculatedDataInputV1<RequestCalculatedEnergyTimeSeriesInputV1> input, CancellationToken cancellationToken);

/// <summary>
/// Start a request for wholesale results
/// </summary>
public Task RequestCalculatedWholesaleServicesAsync(RequestCalculatedDataInputV1<object> input, CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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.

namespace Energinet.DataHub.ProcessManager.Client.Processes.BRS_026_028.V1.Model;

public record RequestCalculatedDataInputV1<TInput>(
string MessageId,
TInput Input)
where TInput : class;
Loading

0 comments on commit 79eb96b

Please sign in to comment.