Skip to content

Commit

Permalink
Merge branch 'xabpe/1-Refactor-ArchivedMessages-to-clean-architecture…
Browse files Browse the repository at this point in the history
…' into xabpe/2-Refactor-BuildingBlocks-to-clean-architecture
  • Loading branch information
AndersBallingPetersen committed Nov 13, 2024
2 parents 721a8a4 + f49476d commit 1aa4f2e
Show file tree
Hide file tree
Showing 61 changed files with 787 additions and 439 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ updates:
- package-ecosystem: nuget
directory: /source
schedule:
interval: monthly
interval: weekly
9 changes: 9 additions & 0 deletions docs/ProcessManager.Client/ReleaseNotes/ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# ProcessManager.Client Release Notes

## Version 0.9.2

- Updated DTO types.

## Version 0.9.1

- Add documentation to several domain and DTO types.
- Remove nullable from places where we always expect a value.

## Version 0.9.0

- Walking skeleton for working with BRS_023_027.
Expand Down
9 changes: 7 additions & 2 deletions source/B2BApi.AppTests/Fixtures/B2BApiAppFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public B2BApiAppFixture()
LogStopwatch(stopwatch, nameof(CleanupAzuriteStorage));

DurableTaskManager = new DurableTaskManager(
"AzureWebJobsStorage",
"OrchestrationsStorageConnectionString",
AzuriteManager.FullConnectionString);
LogStopwatch(stopwatch, nameof(DurableTaskManager));

Expand Down Expand Up @@ -379,10 +379,15 @@ private FunctionAppHostSettings CreateAppHostSettings(string csprojName, ref int
"APPLICATIONINSIGHTS_CONNECTION_STRING",
IntegrationTestConfiguration.ApplicationInsightsConnectionString);

// Durable Functions Task Hub Name
// Durable Functions
// => Task Hub Name
appHostSettings.ProcessEnvironmentVariables.Add(
"OrchestrationsTaskHubName",
TaskHubName);
// => Task Hub Storage account connection string
appHostSettings.ProcessEnvironmentVariables.Add(
"OrchestrationsStorageConnectionString",
AzuriteManager.FullConnectionString);

// Make Orchestrator poll for updates every second (default is every 30 seconds) by overriding maxQueuePollingInterval
// (ref: https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-bindings?tabs=python-v2%2Cisolated-process%2C2x-durable-functions&pivots=programming-language-csharp#hostjson-settings)
Expand Down
3 changes: 3 additions & 0 deletions source/B2BApi/host.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"extensions": {
"durableTask": {
"hubName": "%OrchestrationsTaskHubName%",
"storageProvider": {
"connectionStringName": "OrchestrationsStorageConnectionString"
},
"tracing": {
"traceInputsAndOutputs": true
},
Expand Down
23 changes: 13 additions & 10 deletions source/B2BApi/local.settings.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
"B2C_TENANT_ID": "<Azure B2C tenant id>",
"BACKEND_SERVICE_APP_ID": "<Backend service application id>",
"DB_CONNECTION_STRING": "<SQL database connection string>",
"AZURE_STORAGE_ACCOUNT_CONNECTION_STRING": "<Azure storage account connection string>",
"AZURE_STORAGE_ACCOUNT_URL": "<Azure storage account url>",
"AZURE_STORAGE_ACCOUNT_CONNECTION_STRING": "<Azure storage account connection string>",
"AZURE_STORAGE_ACCOUNT_URL": "<Azure storage account url>",

"ServiceBus__ManageConnectionString": "<service bus connection string for shared service bus with manage permissions>",
"ServiceBus__ListenConnectionString": "<service bus connection string for shared service bus with listener permissions>",
"ServiceBus__SendConnectionString": "<connection string for shared service bus with sender permissions>",
"ServiceBus__SendConnectionString": "<connection string for shared service bus with sender permissions>",

"EdiInbox__QueueName": "<Name of queue where incoming messages to EDI from other subsystems are placed>",
"WholesaleInbox__QueueName": "<Name of queue where EDI place messages to wholesale>",
"IncomingMessages__QueueName": "<Name of queue where incoming messages to EDI from EDI are placed>",
"EdiInbox__QueueName": "<Name of queue where incoming messages to EDI from other subsystems are placed>",
"WholesaleInbox__QueueName": "<Name of queue where EDI place messages to wholesale>",
"IncomingMessages__QueueName": "<Name of queue where incoming messages to EDI from EDI are placed>",

"IntegrationEvents__TopicName": "<Name of topic where integration events are received>",
"IntegrationEvents__SubscriptionName": "<Name of the service bus topic subscription for aggregation result notifications>",
"IntegrationEvents__TopicName": "<Name of topic where integration events are received>",
"IntegrationEvents__SubscriptionName": "<Name of the service bus topic subscription for aggregation result notifications>",

"FeatureManagement__UsePeekMessages": "<Boolean to enable or disable feature>",

Expand All @@ -28,8 +28,11 @@
"WarehouseId": "<Databricks warehouse id>",
"EdiDatabricks__CatalogName": "<Databricks unity catalog name>",

// Durable Functions Task Hub Name
// Durable Functions
// => Task Hub Name
// See naming constraints: https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-task-hubs?tabs=csharp#task-hub-names
"OrchestrationsTaskHubName": "Edi01"
"OrchestrationsTaskHubName": "Edi01",
// => Task Hub Storage account connection string
"OrchestrationsStorageConnectionString": "UseDevelopmentStorage=true"
}
}
1 change: 1 addition & 0 deletions source/BuildingBlocks.Domain/Models/ProcessType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class ProcessType : EnumerationType
public static readonly ProcessType RequestWholesaleResults = new(nameof(RequestWholesaleResults));
public static readonly ProcessType ReceiveWholesaleResults = new(nameof(ReceiveWholesaleResults));
public static readonly ProcessType IncomingMeteredDataForMeasurementPoint = new(nameof(IncomingMeteredDataForMeasurementPoint));
public static readonly ProcessType OutgoingMeteredDataForMeasurementPoint = new(nameof(OutgoingMeteredDataForMeasurementPoint));

private ProcessType(string name)
: base(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,7 @@ enum DelegatedProcess {
PROCESS_REQUEST_ENERGY_RESULTS = 1;
PROCESS_RECEIVE_ENERGY_RESULTS = 2;
PROCESS_REQUEST_WHOLESALE_RESULTS = 3;
PROCESS_RECEIVE_WHOLESALE_RESULTS = 4;
PROCESS_RECEIVE_WHOLESALE_RESULTS = 4;
PROCESS_REQUEST_METERINGPOINT_DATA = 5;
PROCESS_RECEIVE_METERINGPOINT_DATA = 6;
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static IServiceCollection AddIntegrationEventModule(
// Durable Task
services.AddDurableClientFactory(options =>
{
options.ConnectionName = "AzureWebJobsStorage";
options.ConnectionName = "OrchestrationsStorageConnectionString";
options.TaskHub = configuration["OrchestrationsTaskHubName"]!;
options.IsExternalClient = true;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ private static ProcessType MapToProcessType(DelegatedProcess delegatedProcess)
DelegatedProcess.ProcessRequestEnergyResults => ProcessType.RequestEnergyResults,
DelegatedProcess.ProcessRequestWholesaleResults => ProcessType.RequestWholesaleResults,
DelegatedProcess.ProcessReceiveWholesaleResults => ProcessType.ReceiveWholesaleResults,
// TODO: DelegatedProcess.IncomingMeteredDataForMeasurementPoint => ProcessType.IncomingMeteredDataForMeasurementPoint,
DelegatedProcess.ProcessRequestMeteringpointData => ProcessType.IncomingMeteredDataForMeasurementPoint,
DelegatedProcess.ProcessReceiveMeteringpointData => ProcessType.OutgoingMeteredDataForMeasurementPoint,
_ => throw new ArgumentOutOfRangeException(nameof(delegatedProcess), delegatedProcess, null),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Energinet.DataHub.ProcessManager.Api.Model.OrchestrationInstance;
namespace Energinet.DataHub.EDI.MasterData.Application;

public class OrchestrationStepLifecycleStateDto
/// <summary>
/// Wrapper for the module context.
/// </summary>
public interface IMasterDataContext
{
public OrchestrationStepLifecycleStates? State { get; set; }

public OrchestrationStepTerminationStates? TerminationState { get; set; }

public DateTimeOffset? CreatedAt { get; set; }

public DateTimeOffset? StartedAt { get; set; }

public DateTimeOffset? TerminatedAt { get; set; }
/// <summary>
/// Saves all changes on the wrapped context async.
/// </summary>
/// <param name="cancellationToken"></param>
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
}
17 changes: 8 additions & 9 deletions source/MasterData.Application/MasterDataClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models;
using Energinet.DataHub.EDI.BuildingBlocks.Interfaces;
using Energinet.DataHub.EDI.MasterData.Domain.ActorCertificates;
using Energinet.DataHub.EDI.MasterData.Domain.Actors;
using Energinet.DataHub.EDI.MasterData.Domain.GridAreaOwners;
Expand All @@ -30,22 +29,22 @@ public sealed class MasterDataClient : IMasterDataClient
private readonly IActorRepository _actorRepository;
private readonly IGridAreaRepository _gridAreaRepository;
private readonly IActorCertificateRepository _actorCertificateRepository;
private readonly IUnitOfWork _unitOfWork;
private readonly IMasterDataContext _masterDataContext;
private readonly ILogger<IMasterDataClient> _logger;
private readonly IProcessDelegationRepository _processDelegationRepository;

public MasterDataClient(
IActorRepository actorRepository,
IGridAreaRepository gridAreaRepository,
IActorCertificateRepository actorCertificateRepository,
IUnitOfWork unitOfWork,
IMasterDataContext masterDataContext,
ILogger<IMasterDataClient> logger,
IProcessDelegationRepository processDelegationRepository)
{
_actorRepository = actorRepository;
_gridAreaRepository = gridAreaRepository;
_actorCertificateRepository = actorCertificateRepository;
_unitOfWork = unitOfWork;
_masterDataContext = masterDataContext;
_logger = logger;
_processDelegationRepository = processDelegationRepository;
}
Expand All @@ -60,7 +59,7 @@ await _actorRepository.CreateIfNotExistAsync(
cancellationToken)
.ConfigureAwait(false);

await _unitOfWork.CommitTransactionAsync(cancellationToken).ConfigureAwait(false);
await _masterDataContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
}

public Task<ActorNumber?> GetActorNumberByExternalIdAsync(
Expand All @@ -84,7 +83,7 @@ await _gridAreaRepository.UpdateOwnershipAsync(
cancellationToken)
.ConfigureAwait(false);

await _unitOfWork.CommitTransactionAsync(cancellationToken).ConfigureAwait(false);
await _masterDataContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
}

public async Task<GridAreaOwnerDto> GetGridOwnerForGridAreaCodeAsync(string gridAreaCode, CancellationToken cancellationToken)
Expand Down Expand Up @@ -131,7 +130,7 @@ public async Task CreateOrUpdateActorCertificateAsync(
request.SequenceNumber);
}

await _unitOfWork.CommitTransactionAsync(cancellationToken).ConfigureAwait(false);
await _masterDataContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
}

public async Task<Actor?> GetActorFromThumbprintAsync(
Expand All @@ -158,7 +157,7 @@ await _actorCertificateRepository
cancellationToken)
.ConfigureAwait(false);

await _unitOfWork.CommitTransactionAsync(cancellationToken).ConfigureAwait(false);
await _masterDataContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
}

public async Task CreateProcessDelegationAsync(
Expand All @@ -178,7 +177,7 @@ public async Task CreateProcessDelegationAsync(
processDelegationDto.DelegatedTo.ActorRole),
cancellationToken);

await _unitOfWork.CommitTransactionAsync(cancellationToken).ConfigureAwait(false);
await _masterDataContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
}

public async Task<ProcessDelegationDto?> GetProcessDelegatedByAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models;
using Energinet.DataHub.EDI.MasterData.Domain.GridAreaOwners;
using NodaTime;

namespace Energinet.DataHub.EDI.MasterData.Domain.GridAreaOwners;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

using Energinet.DataHub.EDI.BuildingBlocks.Infrastructure.DataAccess;
using Energinet.DataHub.EDI.MasterData.Application;
using Energinet.DataHub.EDI.MasterData.Domain.Actors;
using Energinet.DataHub.EDI.MasterData.Domain.GridAreaOwners;
using Energinet.DataHub.EDI.MasterData.Infrastructure.ActorCertificates;
Expand All @@ -23,7 +24,7 @@

namespace Energinet.DataHub.EDI.MasterData.Infrastructure.DataAccess;

public class MasterDataContext : DbContext, IEdiDbContext
public class MasterDataContext : DbContext, IEdiDbContext, IMasterDataContext
{
#nullable disable
public MasterDataContext(DbContextOptions<MasterDataContext> options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

using Energinet.DataHub.EDI.BuildingBlocks.Interfaces;
using Energinet.DataHub.EDI.DataAccess.Extensions.DependencyInjection;
using Energinet.DataHub.EDI.DataAccess.UnitOfWork;
using Energinet.DataHub.EDI.MasterData.Application;
using Energinet.DataHub.EDI.MasterData.Domain.ActorCertificates;
using Energinet.DataHub.EDI.MasterData.Domain.Actors;
Expand All @@ -28,7 +27,6 @@
using Energinet.DataHub.EDI.MasterData.Interfaces;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace Energinet.DataHub.EDI.MasterData.Infrastructure.Extensions.DependencyInjection;

Expand All @@ -39,8 +37,10 @@ public static IServiceCollection AddMasterDataModule(this IServiceCollection ser
services.AddScopedSqlDbContext<MasterDataContext>(configuration);

// Data access
services
.TryAddScoped<IUnitOfWork, UnitOfWork>();
services.AddScoped<IMasterDataContext, MasterDataContext>(sp =>
{
return sp.GetRequiredService<MasterDataContext>();
});

// Grid area
services
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static IServiceCollection AddProcessModule(this IServiceCollection servic
services.AddTransient<IRequestProcessOrchestrationStarter, RequestProcessOrchestrationStarter>();
services.AddDurableClientFactory(options =>
{
options.ConnectionName = "AzureWebJobsStorage";
options.ConnectionName = "OrchestrationsStorageConnectionString";
options.TaskHub = configuration["OrchestrationsTaskHubName"]!;
options.IsExternalClient = true;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ await ProcessManagerAppFixture.AppHostManager
var orchestrationInstance = await queryResponse.Content
.ReadFromJsonAsync<OrchestrationInstanceDto>();

return orchestrationInstance!.Lifecycle!.State == OrchestrationInstanceLifecycleStates.Terminated;
return orchestrationInstance!.Lifecycle.State == OrchestrationInstanceLifecycleStates.Terminated;
},
timeLimit: TimeSpan.FromSeconds(40),
delay: TimeSpan.FromSeconds(2));
Expand Down
8 changes: 4 additions & 4 deletions 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.0$(VersionSuffix)</PackageVersion>
<PackageVersion>0.9.2$(VersionSuffix)</PackageVersion>
<Title>DH3 Process Manager Client library</Title>
<Company>Energinet-DataHub</Company>
<Authors>Energinet-DataHub</Authors>
Expand Down Expand Up @@ -56,9 +56,9 @@
<Compile Include="..\Shared\ProcessManager\Api\Model\OrchestrationInstance\OrchestrationInstanceDto.cs" Link="Model\OrchestrationInstance\OrchestrationInstanceDto.cs" />
<Compile Include="..\Shared\ProcessManager\Api\Model\OrchestrationInstance\OrchestrationInstanceLifecycleStates.cs" Link="Model\OrchestrationInstance\OrchestrationInstanceLifecycleStates.cs" />
<Compile Include="..\Shared\ProcessManager\Api\Model\OrchestrationInstance\OrchestrationInstanceLifecycleStatesDto.cs" Link="Model\OrchestrationInstance\OrchestrationInstanceLifecycleStatesDto.cs" />
<Compile Include="..\Shared\ProcessManager\Api\Model\OrchestrationInstance\OrchestrationStepDto.cs" Link="Model\OrchestrationInstance\OrchestrationStepDto.cs" />
<Compile Include="..\Shared\ProcessManager\Api\Model\OrchestrationInstance\OrchestrationStepLifecycleStateDto.cs" Link="Model\OrchestrationInstance\OrchestrationStepLifecycleStateDto.cs" />
<Compile Include="..\Shared\ProcessManager\Api\Model\OrchestrationInstance\OrchestrationStepLifecycleStates.cs" Link="Model\OrchestrationInstance\OrchestrationStepLifecycleStates.cs" />
<Compile Include="..\Shared\ProcessManager\Api\Model\OrchestrationInstance\StepInstanceDto.cs" Link="Model\OrchestrationInstance\StepInstanceDto.cs" />
<Compile Include="..\Shared\ProcessManager\Api\Model\OrchestrationInstance\StepInstanceLifecycleStateDto.cs" Link="Model\OrchestrationInstance\StepInstanceLifecycleStateDto.cs" />
<Compile Include="..\Shared\ProcessManager\Api\Model\OrchestrationInstance\StepInstanceLifecycleStates.cs" Link="Model\OrchestrationInstance\StepInstanceLifecycleStates.cs" />
<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" />
Expand Down
Loading

0 comments on commit 1aa4f2e

Please sign in to comment.