Skip to content

Commit

Permalink
Reorganize
Browse files Browse the repository at this point in the history
  • Loading branch information
dstenroejl committed Nov 15, 2024
1 parent e6dd774 commit 5b64192
Show file tree
Hide file tree
Showing 32 changed files with 145 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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;

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

public interface ICancelScheduledOrchestrationInstanceCommand
{
/// <summary>
/// Cancel a scheduled orchestration instance.
/// </summary>
Task CancelScheduledOrchestrationInstanceAsync(OrchestrationInstanceId id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
using Energinet.DataHub.ProcessManagement.Core.Domain.OrchestrationDescription;
using Energinet.DataHub.ProcessManagement.Core.Domain.OrchestrationInstance;

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

/// <summary>
/// Abstracts the execution of orchestration instances from technology specific implementations.
/// </summary>
public interface IOrchestrationInstanceExecutor
internal interface IOrchestrationInstanceExecutor
{
/// <summary>
/// Start a new orchestration instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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;

public interface IOrchestrationInstanceQueries
{
/// <summary>
/// Get existing orchestration instance.
/// </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 @@ -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 IOrchestrationInstanceRepository
internal interface IOrchestrationInstanceRepository
{
/// <summary>
/// Use <see cref="IUnitOfWork.CommitAsync"/> to save changes.
Expand Down
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,7 +12,7 @@
// 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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using Energinet.DataHub.ProcessManagement.Core.Application.Scheduling;
using Energinet.DataHub.ProcessManagement.Core.Domain.OrchestrationDescription;
using Energinet.DataHub.ProcessManagement.Core.Domain.OrchestrationInstance;
using NodaTime;

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

/// <summary>
/// An manager that allows us to provide a framework for managing orchestration instances
Expand All @@ -27,8 +28,9 @@ internal class OrchestrationInstanceManager(
IOrchestrationInstanceExecutor executor,
IOrchestrationRegisterQueries orchestrationRegister,
IOrchestrationInstanceRepository repository) :
IOrchestrationInstanceManager,
IOrchestrationInstanceScheduleManager
IStartOrchestrationInstanceCommands,
IStartScheduledOrchestrationInstanceCommand,
ICancelScheduledOrchestrationInstanceCommand
{
private readonly IClock _clock = clock;
private readonly IOrchestrationInstanceExecutor _executor = executor;
Expand Down
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.Registration;

/// <summary>
/// Read/write access to the orchestration register.
/// </summary>
public interface IOrchestrationRegister
internal interface IOrchestrationRegister
{
Task<IReadOnlyCollection<OrchestrationDescription>> GetAllByHostNameAsync(string hostName);

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

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

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

public static class OrchestrationRegisterExtensions
internal static class OrchestrationRegisterExtensions
{
/// <summary>
/// Synchronize the orchestration register with the Durable Functions orchestrations for an application host.
Expand Down Expand Up @@ -58,9 +58,7 @@ public static async Task SynchronizeAsync(
&& x.Version == hostDescription.Version);

if (registerDescription == null || registerDescription.IsEnabled == false)
{
await register.RegisterAsync(hostDescription, hostName).ConfigureAwait(false);
}
}
}
}
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.Scheduling;

public interface IQueryScheduledOrchestrationInstancesByInstant
public interface IScheduledOrchestrationInstancesByInstantQuery
{
/// <summary>
/// Find scheduled orchestration instances that should be started when comparing to given <paramref name="scheduledToRunBefore"/>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

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

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

public interface IOrchestrationInstanceScheduleManager
public interface IStartScheduledOrchestrationInstanceCommand
{
/// <summary>
/// Start a scheduled orchestration instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// 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.Application.Orchestration;
using Energinet.DataHub.ProcessManagement.Core.Domain.OrchestrationDescription;
using Energinet.DataHub.ProcessManagement.Core.Domain.OrchestrationInstance;
using Microsoft.EntityFrameworkCore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +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.Application.Orchestration;
using Energinet.DataHub.ProcessManagement.Core.Application.Registration;
using Energinet.DataHub.ProcessManagement.Core.Application.Scheduling;
using Energinet.DataHub.ProcessManagement.Core.Domain.OrchestrationDescription;
using Energinet.DataHub.ProcessManagement.Core.Infrastructure.Database;
using Energinet.DataHub.ProcessManagement.Core.Infrastructure.Extensions.Options;
using Energinet.DataHub.ProcessManagement.Core.Infrastructure.Orchestration;
using Energinet.DataHub.ProcessManagement.Core.Infrastructure.Registration;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Azure.WebJobs.Extensions.DurableTask.ContextImplementations;
using Microsoft.Azure.WebJobs.Extensions.DurableTask.Options;
Expand Down Expand Up @@ -66,14 +69,18 @@ public static IServiceCollection AddProcessManagerCore(this IServiceCollection s
});

// ProcessManager components using interfaces to restrict access to functionality
// => Scheduler
services.TryAddScoped<IQueryScheduledOrchestrationInstancesByInstant, OrchestrationInstanceRepository>();
services.TryAddScoped<IOrchestrationInstanceScheduleManager, OrchestrationInstanceManager>();
// => Manager
// => Scheduling
services.TryAddScoped<IScheduledOrchestrationInstancesByInstantQuery, OrchestrationInstanceRepository>();
services.TryAddScoped<IStartScheduledOrchestrationInstanceCommand, OrchestrationInstanceManager>();
// => Cancellation (manager)
services.TryAddScoped<ICancelScheduledOrchestrationInstanceCommand, OrchestrationInstanceManager>();
// => Start instance (manager)
services.TryAddScoped<IOrchestrationInstanceExecutor, DurableOrchestrationInstanceExecutor>();
services.TryAddScoped<IOrchestrationRegisterQueries, OrchestrationRegister>();
services.TryAddScoped<IOrchestrationInstanceRepository, OrchestrationInstanceRepository>();
services.TryAddScoped<IOrchestrationInstanceManager, OrchestrationInstanceManager>();
services.TryAddScoped<IStartOrchestrationInstanceCommands, OrchestrationInstanceManager>();
// => Public queries
services.TryAddScoped<IOrchestrationInstanceQueries, OrchestrationInstanceRepository>();

return services;
}
Expand Down Expand Up @@ -123,13 +130,13 @@ public static IServiceCollection AddProcessManagerForOrchestrations(
// => Orchestration Descriptions registration during startup
services.TryAddTransient<IReadOnlyCollection<OrchestrationDescription>>(sp => enabledDescriptionsFactory());
services.TryAddTransient<IOrchestrationRegister, OrchestrationRegister>();
// => Orchestration instances progress
services.TryAddScoped<IOrchestrationInstanceProgressRepository, OrchestrationInstanceRepository>();
// => Manager
// => Start instance (manager)
services.TryAddScoped<IOrchestrationInstanceExecutor, DurableOrchestrationInstanceExecutor>();
services.TryAddScoped<IOrchestrationRegisterQueries, OrchestrationRegister>();
services.TryAddScoped<IOrchestrationInstanceRepository, OrchestrationInstanceRepository>();
services.TryAddScoped<IOrchestrationInstanceManager, OrchestrationInstanceManager>();
services.TryAddScoped<IStartOrchestrationInstanceCommands, OrchestrationInstanceManager>();
// => Public progress repository
services.TryAddScoped<IOrchestrationInstanceProgressRepository, OrchestrationInstanceRepository>();

return services;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// 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.Application.Registration;
using Energinet.DataHub.ProcessManagement.Core.Domain.OrchestrationDescription;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand All @@ -29,7 +29,7 @@ public static class HostExtensions
/// <summary>
/// Register and deregister orchestrations during application startup.
/// </summary>
public static async Task SynchronizeWithOrchestrationRegisterAsync(this IHost host)
public static async Task SynchronizeWithOrchestrationRegisterAsync(this IHost host, string hostName)
{
var loggerFactory = host.Services.GetRequiredService<ILoggerFactory>();
var logger = loggerFactory.CreateLogger(nameof(SynchronizeWithOrchestrationRegisterAsync));
Expand All @@ -40,7 +40,7 @@ public static async Task SynchronizeWithOrchestrationRegisterAsync(this IHost ho
var register = host.Services.GetRequiredService<IOrchestrationRegister>();
await register
.SynchronizeAsync(
hostName: "ProcessManager.Orchestrations",
hostName: hostName,
enabledDescriptions)
.ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// 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.Application.Orchestration;
using Energinet.DataHub.ProcessManagement.Core.Domain.OrchestrationDescription;
using Energinet.DataHub.ProcessManagement.Core.Domain.OrchestrationInstance;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
// 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.Application.Orchestration;
using Energinet.DataHub.ProcessManagement.Core.Application.Scheduling;
using Energinet.DataHub.ProcessManagement.Core.Domain.OrchestrationInstance;
using Energinet.DataHub.ProcessManagement.Core.Infrastructure.Database;
using Microsoft.EntityFrameworkCore;
Expand All @@ -27,7 +28,8 @@ internal class OrchestrationInstanceRepository(
ProcessManagerContext context) :
IOrchestrationInstanceRepository,
IOrchestrationInstanceProgressRepository,
IQueryScheduledOrchestrationInstancesByInstant
IOrchestrationInstanceQueries,
IScheduledOrchestrationInstancesByInstantQuery
{
private readonly ProcessManagerContext _context = context;

Expand All @@ -50,7 +52,7 @@ public async Task AddAsync(OrchestrationInstance orchestrationInstance)
await _context.OrchestrationInstances.AddAsync(orchestrationInstance).ConfigureAwait(false);
}

/// <inheritdoc cref="IQueryScheduledOrchestrationInstancesByInstant.FindAsync(Instant)"/>
/// <inheritdoc cref="IScheduledOrchestrationInstancesByInstantQuery.FindAsync(Instant)"/>
public async Task<IReadOnlyCollection<OrchestrationInstance>> FindAsync(Instant scheduledToRunBefore)
{
var query = _context.OrchestrationInstances
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
// 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.Application.Orchestration;
using Energinet.DataHub.ProcessManagement.Core.Application.Registration;
using Energinet.DataHub.ProcessManagement.Core.Domain.OrchestrationDescription;
using Energinet.DataHub.ProcessManagement.Core.Infrastructure.Database;
using Microsoft.EntityFrameworkCore;

namespace Energinet.DataHub.ProcessManagement.Core.Infrastructure.Orchestration;
namespace Energinet.DataHub.ProcessManagement.Core.Infrastructure.Registration;

/// <summary>
/// Keep a register of known Durable Functions orchestrations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// 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.Application.Orchestration;
using Energinet.DataHub.ProcessManagement.Core.Domain.OrchestrationInstance;
using Microsoft.Azure.Functions.Worker;
using NodaTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// 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.Application.Orchestration;
using Energinet.DataHub.ProcessManagement.Core.Domain.OrchestrationInstance;
using Microsoft.Azure.Functions.Worker;
using NodaTime;
Expand Down
Loading

0 comments on commit 5b64192

Please sign in to comment.