Skip to content

Commit

Permalink
Merge branch 'main' into madu/impl-cim-xml-rsm012-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsDue authored Nov 19, 2024
2 parents 574a981 + 4fbe22f commit 522131e
Show file tree
Hide file tree
Showing 35 changed files with 296 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ public class OrchestrationInstanceRepositoryTests : IAsyncLifetime
private readonly ProcessManagerCoreFixture _fixture;
private readonly ProcessManagerContext _dbContext;
private readonly OrchestrationInstanceRepository _sut;
private readonly UnitOfWork _unitOfWork;

public OrchestrationInstanceRepositoryTests(ProcessManagerCoreFixture fixture)
{
_fixture = fixture;
_dbContext = _fixture.DatabaseManager.CreateDbContext();
_sut = new OrchestrationInstanceRepository(_dbContext);
_unitOfWork = new UnitOfWork(_dbContext);
}

public Task InitializeAsync()
Expand Down Expand Up @@ -98,7 +96,7 @@ public async Task GivenOrchestrationDescriptionNotInDatabase_WhenAddOrchestratio

// Act
await _sut.AddAsync(newOrchestrationInstance);
var act = _unitOfWork.CommitAsync;
var act = () => _sut.UnitOfWork.CommitAsync();

// Assert
await act.Should()
Expand All @@ -118,7 +116,7 @@ public async Task GivenOrchestrationDescriptionInDatabase_WhenAddOrchestrationIn

// Act
await _sut.AddAsync(newOrchestrationInstance);
await _unitOfWork.CommitAsync();
await _sut.UnitOfWork.CommitAsync();

// Assert
var actual = await _sut.GetAsync(newOrchestrationInstance.Id);
Expand Down Expand Up @@ -146,7 +144,7 @@ public async Task GivenScheduledOrchestrationInstancesInDatabase_WhenGetSchedule
runAt: SystemClock.Instance.GetCurrentInstant().PlusDays(5));
await _sut.AddAsync(scheduledIntoTheFarFuture);

await _unitOfWork.CommitAsync();
await _sut.UnitOfWork.CommitAsync();

// Act
var actual = await _sut.FindAsync(
Expand Down Expand Up @@ -177,7 +175,7 @@ public async Task GivenOrchestrationInstancesInDatabase_WhenSearchByName_ThenExp
var basedOn02 = CreateOrchestrationInstance(existingOrchestrationDescription02);
await _sut.AddAsync(basedOn02);

await _unitOfWork.CommitAsync();
await _sut.UnitOfWork.CommitAsync();

// Act
var actual = await _sut.SearchAsync(existingOrchestrationDescription01.Name);
Expand All @@ -204,7 +202,7 @@ public async Task GivenOrchestrationInstancesInDatabase_WhenSearchByNameAndVersi
var basedOnV2 = CreateOrchestrationInstance(existingOrchestrationDescriptionV2);
await _sut.AddAsync(basedOnV2);

await _unitOfWork.CommitAsync();
await _sut.UnitOfWork.CommitAsync();

// Act
var actual = await _sut.SearchAsync(existingOrchestrationDescriptionV1.Name, existingOrchestrationDescriptionV1.Version);
Expand Down Expand Up @@ -241,7 +239,7 @@ public async Task GivenOrchestrationInstancesInDatabase_WhenSearchByNameAndLifec
isRunningV2.Lifecycle.TransitionToRunning(SystemClock.Instance);
await _sut.AddAsync(isRunningV2);

await _unitOfWork.CommitAsync();
await _sut.UnitOfWork.CommitAsync();

// Act
var actual = await _sut.SearchAsync(existingOrchestrationDescriptionV1.Name, lifecycleState: OrchestrationInstanceLifecycleStates.Running);
Expand Down Expand Up @@ -280,7 +278,7 @@ public async Task GivenOrchestrationInstancesInDatabase_WhenSearchByNameAndTermi
isTerminatedAsFailedV2.Lifecycle.TransitionToTerminated(SystemClock.Instance, OrchestrationInstanceTerminationStates.Failed);
await _sut.AddAsync(isTerminatedAsFailedV2);

await _unitOfWork.CommitAsync();
await _sut.UnitOfWork.CommitAsync();

// Act
var actual = await _sut.SearchAsync(
Expand Down Expand Up @@ -319,7 +317,7 @@ public async Task GivenOrchestrationInstancesInDatabase_WhenSearchByNameAndStart
isRunning02.Lifecycle.TransitionToRunning(SystemClock.Instance);
await _sut.AddAsync(isRunning02);

await _unitOfWork.CommitAsync();
await _sut.UnitOfWork.CommitAsync();

// Act
var actual = await _sut.SearchAsync(
Expand Down Expand Up @@ -364,7 +362,7 @@ public async Task GivenOrchestrationInstancesInDatabase_WhenSearchByNameAndTermi
isTerminated02.Lifecycle.TransitionToTerminated(SystemClock.Instance, OrchestrationInstanceTerminationStates.Succeeded);
await _sut.AddAsync(isTerminated02);

await _unitOfWork.CommitAsync();
await _sut.UnitOfWork.CommitAsync();

// Act
var actual = await _sut.SearchAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using Energinet.DataHub.ProcessManagement.Core.Application;
using Energinet.DataHub.ProcessManagement.Core.Domain.OrchestrationInstance;

namespace Energinet.DataHub.ProcessManagement.Core.Infrastructure.Database;
namespace Energinet.DataHub.ProcessManagement.Core.Application.Orchestration;

public class UnitOfWork : IUnitOfWork
public interface ICancelScheduledOrchestrationInstanceCommand
{
private readonly ProcessManagerContext _context;

public UnitOfWork(ProcessManagerContext context)
{
_context = context;
}

public async Task CommitAsync()
{
await _context.SaveChangesAsync().ConfigureAwait(false);
}
/// <summary>
/// Cancel a scheduled orchestration instance.
/// </summary>
Task CancelScheduledOrchestrationInstanceAsync(OrchestrationInstanceId id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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.ProcessManagement.Core.Domain.OrchestrationDescription;
using Energinet.DataHub.ProcessManagement.Core.Domain.OrchestrationInstance;

namespace Energinet.DataHub.ProcessManagement.Core.Application.Orchestration;

/// <summary>
/// Abstracts the execution of orchestration instances from technology specific implementations.
/// </summary>
internal interface IOrchestrationInstanceExecutor
{
/// <summary>
/// Start a new orchestration instance.
/// </summary>
Task StartNewOrchestrationInstanceAsync(OrchestrationDescription orchestrationDescription, OrchestrationInstance orchestrationInstance);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@

using Energinet.DataHub.ProcessManagement.Core.Domain.OrchestrationInstance;

namespace Energinet.DataHub.ProcessManagement.Core.Application;
namespace Energinet.DataHub.ProcessManagement.Core.Application.Orchestration;

/// <summary>
/// Use this from Durable Functions activities to get the orchestration instance and then
/// update its progress, before commiting changes back by using <see cref="IUnitOfWork.CommitAsync"/>.
/// update its progress, before commiting changes back by using <see cref="UnitOfWork"/>.
/// </summary>
public interface IOrchestrationInstanceProgressRepository
{
/// <summary>
/// Use <see cref="IUnitOfWork.CommitAsync"/> to save changes.
/// </summary>
public IUnitOfWork UnitOfWork { get; }

/// <summary>
/// Get existing orchestration instance.
/// To commit changes use <see cref="IUnitOfWork.CommitAsync"/>.
/// To commit changes use <see cref="UnitOfWork"/>.
/// </summary>
Task<OrchestrationInstance> GetAsync(OrchestrationInstanceId id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
using Energinet.DataHub.ProcessManagement.Core.Domain.OrchestrationInstance;
using NodaTime;

namespace Energinet.DataHub.ProcessManagement.Core.Application;
namespace Energinet.DataHub.ProcessManagement.Core.Application.Orchestration;

public interface IOrchestrationInstanceRepository : IOrchestrationInstanceProgressRepository
public interface IOrchestrationInstanceQueries
{
/// <summary>
/// Add the orchestration instance.
/// To commit changes use <see cref="IUnitOfWork.CommitAsync"/>.
/// Get existing orchestration instance.
/// </summary>
Task AddAsync(OrchestrationInstance orchestrationInstance);
Task<OrchestrationInstance> GetAsync(OrchestrationInstanceId id);

/// <summary>
/// Get all orchestration instances filtered by their related orchestration definition name and version,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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.ProcessManagement.Core.Domain.OrchestrationInstance;
using NodaTime;

namespace Energinet.DataHub.ProcessManagement.Core.Application.Orchestration;

internal interface IOrchestrationInstanceRepository
{
/// <summary>
/// Use <see cref="IUnitOfWork.CommitAsync"/> to save changes.
/// </summary>
public IUnitOfWork UnitOfWork { get; }

/// <summary>
/// Add the orchestration instance.
/// To commit changes use <see cref="UnitOfWork"/>.
/// </summary>
Task AddAsync(OrchestrationInstance orchestrationInstance);

/// <summary>
/// Get existing orchestration instance.
/// To commit changes use <see cref="UnitOfWork"/>.
/// </summary>
Task<OrchestrationInstance> GetAsync(OrchestrationInstanceId id);

/// <summary>
/// Get all orchestration instances filtered by their related orchestration definition name and version,
/// and their lifecycle / termination states.
/// </summary>
Task<IReadOnlyCollection<OrchestrationInstance>> SearchAsync(
string name,
int? version,
OrchestrationInstanceLifecycleStates? lifecycleState,
OrchestrationInstanceTerminationStates? terminationState,
Instant? startedAtOrLater,
Instant? terminatedAtOrEarlier);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

using Energinet.DataHub.ProcessManagement.Core.Domain.OrchestrationDescription;

namespace Energinet.DataHub.ProcessManagement.Core.Application;
namespace Energinet.DataHub.ProcessManagement.Core.Application.Orchestration;

/// <summary>
/// Readonly access to the orchestration register.
/// </summary>
public interface IOrchestrationRegisterQueries
internal interface IOrchestrationRegisterQueries
{
Task<OrchestrationDescription> GetAsync(OrchestrationDescriptionId id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
using Energinet.DataHub.ProcessManagement.Core.Domain.OrchestrationInstance;
using NodaTime;

namespace Energinet.DataHub.ProcessManagement.Core.Application;
namespace Energinet.DataHub.ProcessManagement.Core.Application.Orchestration;

public interface IOrchestrationInstanceManager
public interface IStartOrchestrationInstanceCommands
{
/// <summary>
/// Start a new instance of an orchestration.
Expand All @@ -39,9 +39,4 @@ Task<OrchestrationInstanceId> ScheduleNewOrchestrationInstanceAsync<TParameter>(
Instant runAt,
IReadOnlyCollection<int> skipStepsBySequence)
where TParameter : class;

/// <summary>
/// Cancel a scheduled orchestration instance.
/// </summary>
Task CancelScheduledOrchestrationInstanceAsync(OrchestrationInstanceId id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Energinet.DataHub.ProcessManagement.Core.Application;
namespace Energinet.DataHub.ProcessManagement.Core.Application.Orchestration;

public interface IUnitOfWork
{
Task CommitAsync();
Task CommitAsync(CancellationToken cancellationToken = default);
}
Loading

0 comments on commit 522131e

Please sign in to comment.