Skip to content

Commit

Permalink
Continued refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
cdavernas committed Jul 12, 2023
1 parent 20c4611 commit 859fc01
Show file tree
Hide file tree
Showing 32 changed files with 619 additions and 85 deletions.
38 changes: 26 additions & 12 deletions Synapse.sln
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Synapse.Runtime.Agent", "sr
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "plugins", "plugins", "{9B52498A-89C1-4396-931A-D11A6D7E7AC9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "management", "management", "{FF13A50C-586A-4F29-A0DD-1AE21581D813}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "core", "core", "{FF13A50C-586A-4F29-A0DD-1AE21581D813}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sdk", "sdk", "{499E479F-3757-4009-AF70-251AF6CB59EE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Synapse.Plugins.Management", "src\plugins\management\Synapse.Plugins.Management.csproj", "{E1236A03-9E94-4982-8FB5-6D19D695B565}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Synapse.Plugins.Sdk", "src\plugins\sdk\Synapse.Plugins.Sdk.csproj", "{922A993B-C3AA-4222-9974-8C4A1972F357}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "infrastructure", "infrastructure", "{CC1BEDB4-58DF-422F-9BD3-A54DA39C260F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Synapse.Infrastructure", "src\infrastructure\Synapse.Infrastructure.csproj", "{051307BA-7D60-425B-AD90-CC4411AC04D7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Synapse.Plugins.Core", "src\plugins\core\Synapse.Plugins.Core.csproj", "{7D66CC70-14A9-4226-89F6-133102E4BE13}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -129,14 +133,6 @@ Global
{5E578F78-9063-4A81-9CDD-7085A53CA641}.Release|Any CPU.Build.0 = Release|Any CPU
{5E578F78-9063-4A81-9CDD-7085A53CA641}.Release|x86.ActiveCfg = Release|Any CPU
{5E578F78-9063-4A81-9CDD-7085A53CA641}.Release|x86.Build.0 = Release|Any CPU
{E1236A03-9E94-4982-8FB5-6D19D695B565}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E1236A03-9E94-4982-8FB5-6D19D695B565}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E1236A03-9E94-4982-8FB5-6D19D695B565}.Debug|x86.ActiveCfg = Debug|Any CPU
{E1236A03-9E94-4982-8FB5-6D19D695B565}.Debug|x86.Build.0 = Debug|Any CPU
{E1236A03-9E94-4982-8FB5-6D19D695B565}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E1236A03-9E94-4982-8FB5-6D19D695B565}.Release|Any CPU.Build.0 = Release|Any CPU
{E1236A03-9E94-4982-8FB5-6D19D695B565}.Release|x86.ActiveCfg = Release|Any CPU
{E1236A03-9E94-4982-8FB5-6D19D695B565}.Release|x86.Build.0 = Release|Any CPU
{922A993B-C3AA-4222-9974-8C4A1972F357}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{922A993B-C3AA-4222-9974-8C4A1972F357}.Debug|Any CPU.Build.0 = Debug|Any CPU
{922A993B-C3AA-4222-9974-8C4A1972F357}.Debug|x86.ActiveCfg = Debug|Any CPU
Expand All @@ -145,6 +141,22 @@ Global
{922A993B-C3AA-4222-9974-8C4A1972F357}.Release|Any CPU.Build.0 = Release|Any CPU
{922A993B-C3AA-4222-9974-8C4A1972F357}.Release|x86.ActiveCfg = Release|Any CPU
{922A993B-C3AA-4222-9974-8C4A1972F357}.Release|x86.Build.0 = Release|Any CPU
{051307BA-7D60-425B-AD90-CC4411AC04D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{051307BA-7D60-425B-AD90-CC4411AC04D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{051307BA-7D60-425B-AD90-CC4411AC04D7}.Debug|x86.ActiveCfg = Debug|Any CPU
{051307BA-7D60-425B-AD90-CC4411AC04D7}.Debug|x86.Build.0 = Debug|Any CPU
{051307BA-7D60-425B-AD90-CC4411AC04D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{051307BA-7D60-425B-AD90-CC4411AC04D7}.Release|Any CPU.Build.0 = Release|Any CPU
{051307BA-7D60-425B-AD90-CC4411AC04D7}.Release|x86.ActiveCfg = Release|Any CPU
{051307BA-7D60-425B-AD90-CC4411AC04D7}.Release|x86.Build.0 = Release|Any CPU
{7D66CC70-14A9-4226-89F6-133102E4BE13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7D66CC70-14A9-4226-89F6-133102E4BE13}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D66CC70-14A9-4226-89F6-133102E4BE13}.Debug|x86.ActiveCfg = Debug|Any CPU
{7D66CC70-14A9-4226-89F6-133102E4BE13}.Debug|x86.Build.0 = Debug|Any CPU
{7D66CC70-14A9-4226-89F6-133102E4BE13}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7D66CC70-14A9-4226-89F6-133102E4BE13}.Release|Any CPU.Build.0 = Release|Any CPU
{7D66CC70-14A9-4226-89F6-133102E4BE13}.Release|x86.ActiveCfg = Release|Any CPU
{7D66CC70-14A9-4226-89F6-133102E4BE13}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -173,8 +185,10 @@ Global
{9B52498A-89C1-4396-931A-D11A6D7E7AC9} = {D789B1B2-073B-4609-948F-25C70148CDFB}
{FF13A50C-586A-4F29-A0DD-1AE21581D813} = {9B52498A-89C1-4396-931A-D11A6D7E7AC9}
{499E479F-3757-4009-AF70-251AF6CB59EE} = {9B52498A-89C1-4396-931A-D11A6D7E7AC9}
{E1236A03-9E94-4982-8FB5-6D19D695B565} = {FF13A50C-586A-4F29-A0DD-1AE21581D813}
{922A993B-C3AA-4222-9974-8C4A1972F357} = {499E479F-3757-4009-AF70-251AF6CB59EE}
{CC1BEDB4-58DF-422F-9BD3-A54DA39C260F} = {D789B1B2-073B-4609-948F-25C70148CDFB}
{051307BA-7D60-425B-AD90-CC4411AC04D7} = {CC1BEDB4-58DF-422F-9BD3-A54DA39C260F}
{7D66CC70-14A9-4226-89F6-133102E4BE13} = {FF13A50C-586A-4F29-A0DD-1AE21581D813}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C1FCD70A-A848-4567-B59C-D7B076BC2F2E}
Expand Down
8 changes: 4 additions & 4 deletions src/core/EmbeddedResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ public static class Definitions
/// </summary>
public static readonly string Workflow = $"{Prefix}workflow.yaml";
/// <summary>
/// Gets the definition of workflow processes
/// Gets the definition of workflow instances
/// </summary>
public static readonly string WorkflowProcess = $"{Prefix}workflow-process.yaml";
public static readonly string WorkflowInstance = $"{Prefix}workflow-instance.yaml";
/// <summary>
/// Gets the definition of workflow runners
/// Gets the definition of workflow agents
/// </summary>
public static readonly string WorkflowRunner = $"{Prefix}workflow-runner.yaml";
public static readonly string WorkflowAgent = $"{Prefix}workflow-agent.yaml";

}

Expand Down
29 changes: 29 additions & 0 deletions src/core/Extensions/WorkflowInstanceExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Synapse;

/// <summary>
/// Defines extensions for <see cref="WorkflowInstance"/>s
/// </summary>
public static class WorkflowInstanceExtensions
{

/// <summary>
/// Determines whether or not the <see cref="WorkflowInstance"/> is managed by the specified <see cref="WorkflowAgent"/>
/// </summary>
/// <param name="instance">The extended <see cref="WorkflowInstance"/></param>
/// <param name="agentQualifiedName">The qualified name of the <see cref="WorkflowAgent"/> to check</param>
/// <returns>A boolean indicating whether or not the <see cref="WorkflowInstance"/> is managed by the specified <see cref="WorkflowAgent"/></returns>
public static bool IsManagedBy(this WorkflowInstance instance, string agentQualifiedName)
{
if (string.IsNullOrWhiteSpace(agentQualifiedName)) throw new ArgumentNullException(nameof(agentQualifiedName));
return instance.Metadata.Labels != null && instance.Metadata.Labels.TryGetValue(WorkflowInstance.Labels.Agent, out var agentRef) && agentRef == agentQualifiedName;
}

/// <summary>
/// Determines whether or not the <see cref="WorkflowInstance"/> is managed by the specified <see cref="WorkflowAgent"/>
/// </summary>
/// <param name="instance">The extended <see cref="WorkflowInstance"/></param>
/// <param name="agent">The <see cref="WorkflowAgent"/> to check</param>
/// <returns>A boolean indicating whether or not the <see cref="WorkflowInstance"/> is managed by the specified <see cref="WorkflowAgent"/></returns>
public static bool IsManagedBy(this WorkflowInstance instance, WorkflowAgent agent) => instance.IsManagedBy(agent.GetQualifiedName());

}
File renamed without changes.
2 changes: 1 addition & 1 deletion src/core/ProcessPhase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ public enum ProcessPhase
/// </summary>
[EnumMember(Value = "exited")]
Exited
}
}
2 changes: 1 addition & 1 deletion src/core/Resources/WorkflowAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public record WorkflowAgent
/// <summary>
/// Gets the <see cref="WorkflowAgent"/>'s resource type.
/// </summary>
public static ResourceDefinition ResourceDefinition { get; set; } = Hylo.Serializer.Yaml.Deserialize<ResourceDefinition>(EmbeddedResources.ReadToEnd(EmbeddedResources.Assets.Definitions.WorkflowRunner))!;
public static ResourceDefinition ResourceDefinition { get; set; } = Hylo.Serializer.Yaml.Deserialize<ResourceDefinition>(EmbeddedResources.ReadToEnd(EmbeddedResources.Assets.Definitions.WorkflowAgent))!;

/// <summary>
/// Initializes a new <see cref="WorkflowAgent"/>
Expand Down
7 changes: 6 additions & 1 deletion src/core/Resources/WorkflowAgentProcessRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ public WorkflowAgentProcessRule(string name, IEnumerable<string> supportedLangua
{
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name));
if (supportedLanguages == null || !supportedLanguages.Any()) throw new ArgumentNullException(nameof(supportedLanguages));
supportedLanguages.All(l => (l.Length < 7 || l.Length > 126 || !l.IsAlphanumeric('-', '.') || l.Split('.').Length != 2) ? throw new ArgumentException($"The specified value '{l}' is not a valid versioned DSL reference", nameof(supportedLanguages)) : true);
supportedLanguages.ToList().ForEach(dslReference =>
{
if (dslReference.Length < 7 || dslReference.Length > 126 || !dslReference.IsAlphanumeric('-', '.', ':') || dslReference.Split(':').Length != 2)
throw new ArgumentException($"The specified value '{dslReference}' is not a valid versioned DSL reference", nameof(supportedLanguages));
});

this.Name = name;
this.SupportedLanguages = new(supportedLanguages);
this.Selectors = selectors == null ? null : new(selectors);
Expand Down
4 changes: 2 additions & 2 deletions src/core/Resources/WorkflowAgentSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public record WorkflowAgentSpec
/// Initializes a new <see cref="WorkflowAgentSpec"/>
/// </summary>
/// <param name="processRules">A set of rules that define which workflow instances to run and how</param>
public WorkflowAgentSpec(List<WorkflowAgentProcessRule> processRules)
public WorkflowAgentSpec(params WorkflowAgentProcessRule[] processRules)
{
if(processRules == null || processRules.Count < 1) throw new ArgumentNullException(nameof(processRules));
if(processRules == null || !processRules.Any()) throw new ArgumentNullException(nameof(processRules));
this.ProcessRules = new(processRules);
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/Resources/WorkflowInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public record WorkflowInstance
/// <summary>
/// Gets the <see cref="WorkflowInstance"/>'s resource type.
/// </summary>
public static ResourceDefinition ResourceDefinition { get; set; } = Hylo.Serializer.Yaml.Deserialize<ResourceDefinition>(EmbeddedResources.ReadToEnd(EmbeddedResources.Assets.Definitions.WorkflowProcess))!;
public static ResourceDefinition ResourceDefinition { get; set; } = Hylo.Serializer.Yaml.Deserialize<ResourceDefinition>(EmbeddedResources.ReadToEnd(EmbeddedResources.Assets.Definitions.WorkflowInstance))!;

/// <summary>
/// Initializes a new <see cref="WorkflowInstance"/>
Expand Down
55 changes: 55 additions & 0 deletions src/core/Resources/WorkflowInstanceRuntime.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
namespace Synapse.Resources;

/// <summary>
/// Represents an object used to describe a period of time during which a workflow instance has been running
/// </summary>
public record WorkflowInstanceRuntime
{

/// <summary>
/// Initializes a new <see cref="WorkflowInstanceRuntime"/>
/// </summary>
public WorkflowInstanceRuntime() { }

/// <summary>
/// Initializes a new <see cref="WorkflowInstanceRuntime"/>
/// </summary>
/// <param name="agentQualifiedName">The qualified name of the agent managing the execution of the workflow instance</param>
/// <param name="processId">A value used to globally and uniquely identify the process that is running the workflow instance</param>
public WorkflowInstanceRuntime(string agentQualifiedName, string processId)
{
if (string.IsNullOrWhiteSpace(agentQualifiedName)) throw new ArgumentNullException(nameof(agentQualifiedName));
if (string.IsNullOrWhiteSpace(processId)) throw new ArgumentNullException(nameof(processId));
this.Agent = agentQualifiedName;
this.ProcessId = processId;
this.StartedAt = DateTimeOffset.Now;
}

/// <summary>
/// Gets/sets the qualified name of the agent managing the execution of the workflow instance
/// </summary>
[Required]
[DataMember(Order = 1, Name = "agent", IsRequired = true), JsonPropertyOrder(1), JsonPropertyName("agent"), YamlMember(Order = 1, Alias = "agent")]
public virtual string Agent { get; set; } = null!;

/// <summary>
/// Gets/sets a value used to globally and uniquely identify the process that is running the workflow instance
/// </summary>
[Required]
[DataMember(Order = 2, Name = "processId", IsRequired = true), JsonPropertyOrder(2), JsonPropertyName("processId"), YamlMember(Order = 2, Alias = "processId")]
public virtual string ProcessId { get; set; } = null!;

/// <summary>
/// Gets the date and time at which the session has started
/// </summary>
[Required]
[DataMember(Order = 3, Name = "startedAt", IsRequired = true), JsonPropertyOrder(3), JsonPropertyName("startedAt"), YamlMember(Order = 3, Alias = "startedAt")]
public virtual DateTimeOffset StartedAt { get; set; }

/// <summary>
/// Gets the date and time at which the session has ended
/// </summary>
[DataMember(Order = 4, Name = "endedAt"), JsonPropertyOrder(4), JsonPropertyName("endedAt"), YamlMember(Order = 4, Alias = "endedAt")]
public virtual DateTimeOffset? EndedAt { get; set; }

}
36 changes: 29 additions & 7 deletions src/core/Resources/WorkflowInstanceStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,57 @@
public record WorkflowInstanceStatus
{

/// <summary>
/// Initializes a new <see cref="WorkflowInstanceStatus"/>
/// </summary>
public WorkflowInstanceStatus() { }

/// <summary>
/// Initializes a new <see cref="WorkflowInstanceStatus"/>
/// </summary>
/// <param name="agent">A reference to the agent that is currently executing the described workflow instance, if any</param>
public WorkflowInstanceStatus(string agent)
{
if (string.IsNullOrWhiteSpace(agent)) throw new ArgumentNullException(nameof(agent));
this.Phase = WorkflowInstancePhase.Pending;
this.Agent = agent;
}

/// <summary>
/// Gets/sets the workflow instance's phase. Values supported by default are 'pending', 'running', 'suspended', 'faulted', 'cancelled', 'executed'
/// </summary>
[Required, MinLength(3), MaxLength(22)]
[DataMember(Order = 1, Name = "phase", IsRequired = true), JsonPropertyOrder(1), JsonPropertyName("phase"), YamlMember(Order = 1, Alias = "phase")]
public virtual string Phase { get; set; } = null!;
public virtual WorkflowInstancePhase Phase { get; set; }

/// <summary>
/// Gets/sets a reference to the agent that is currently executing the described workflow instance, if any
/// </summary>
[DataMember(Order = 2, Name = "agent"), JsonPropertyOrder(2), JsonPropertyName("agent"), YamlMember(Order = 2, Alias = "agent")]
public virtual string? Agent { get; set; }

/// <summary>
/// Gets/sets a reference to the runner that is currently executing the described workflow instance, if any
/// Gets/sets a list containing the workflow instance's runtimes, if any
/// </summary>
[DataMember(Order = 2, Name = "runner"), JsonPropertyOrder(2), JsonPropertyName("runner"), YamlMember(Order = 2, Alias = "runner")]
public virtual string? Runner { get; set; }
[DataMember(Order = 3, Name = "runtimes"), JsonPropertyOrder(3), JsonPropertyName("runtimes"), YamlMember(Order = 3, Alias = "runtimes")]
public virtual EquatableList<WorkflowInstanceRuntime>? Runtimes { get; set; }

/// <summary>
/// Gets/sets a list containing the activities processed during the described workflow instance's execution
/// </summary>
[DataMember(Order = 3, Name = "activities", IsRequired = true), JsonPropertyOrder(5), JsonPropertyName("activities"), YamlMember(Order = 5, Alias = "activities")]
[DataMember(Order = 4, Name = "activities", IsRequired = true), JsonPropertyOrder(4), JsonPropertyName("activities"), YamlMember(Order = 4, Alias = "activities")]
public virtual EquatableList<WorkflowActivity>? Activities { get; set; }

/// <summary>
/// Gets/sets an object used to describe the error that has faulted the execution of the instance, if any
/// </summary>
[DataMember(Order = 4, Name = "error"), JsonPropertyOrder(3), JsonPropertyName("error"), YamlMember(Order = 3, Alias = "error")]
[DataMember(Order = 5, Name = "error"), JsonPropertyOrder(5), JsonPropertyName("error"), YamlMember(Order = 5, Alias = "error")]
public virtual ProblemDetails? Error { get; set; }

/// <summary>
/// Gets/sets a reference to the instance's output data, if any. If set, must be a valid url following the format '{storageProvider}://{storageSpecificReference}' (ex: minio://workflows/pets/order/po-2023Q200069.output.json)
/// </summary>
[DataMember(Order = 5, Name = "outputData", IsRequired = true), JsonPropertyOrder(4), JsonPropertyName("outputData"), YamlMember(Order = 4, Alias = "outputData")]
[DataMember(Order = 6, Name = "outputData", IsRequired = true), JsonPropertyOrder(6), JsonPropertyName("outputData"), YamlMember(Order = 6, Alias = "outputData")]
public virtual Uri? OutputData { get; set; }


Expand Down
4 changes: 2 additions & 2 deletions src/core/Synapse.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Hylo.Core" Version="0.4.0" />
<PackageReference Include="Hylo.Core" Version="0.5.0" />
<PackageReference Include="JsonCons.Utilities" Version="1.0.0" />
<PackageReference Include="JsonPatch.Net" Version="2.0.6" />
<PackageReference Include="JsonSchema.Net" Version="4.1.0" />
<PackageReference Include="JsonSchema.Net" Version="4.1.1" />
<PackageReference Include="Semver" Version="2.3.0" />
<PackageReference Include="System.Reactive.Linq" Version="5.0.0" />
<PackageReference Include="YamlDotNet" Version="13.1.0" />
Expand Down
44 changes: 44 additions & 0 deletions src/core/WorkflowInstancePhase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Hylo.Serialization.Json;
using Hylo.Serialization;
using System.ComponentModel;

namespace Synapse;

/// <summary>
/// Enuemrates the possible phases a workflow instance can go through
/// </summary>
[TypeConverter(typeof(StringEnumTypeConverter))]
[JsonConverter(typeof(JsonStringEnumConverterFactory))]
public enum WorkflowInstancePhase
{
/// <summary>
/// Indicates that the workflow instance is pending execution
/// </summary>
[EnumMember(Value = "pending")]
Pending,
/// <summary>
/// Indicates that the workflow instance is being executed
/// </summary>
[EnumMember(Value = "running")]
Running,
/// <summary>
/// Indicates that the execution of the workflow instance has been suspended
/// </summary>
[EnumMember(Value = "suspended")]
Suspended,
/// <summary>
/// Indicates that the execution of the workflow instance faulted
/// </summary>
[EnumMember(Value = "faulted")]
Faulted,
/// <summary>
/// Indicates that the execution of the workflow instance has been cancelled
/// </summary>
[EnumMember(Value = "cancelled")]
Cancelled,
/// <summary>
/// Indicates that the execution of the workflow instance completed successfully
/// </summary>
[EnumMember(Value = "completed")]
Completed
}
Loading

0 comments on commit 859fc01

Please sign in to comment.