Skip to content

Commit

Permalink
feat(Dashboard): Added the WorkflowDiagram component (WIP)
Browse files Browse the repository at this point in the history
Signed-off-by: Charles d'Avernas <[email protected]>
  • Loading branch information
cdavernas committed Jun 19, 2024
1 parent 569337f commit d1454b5
Show file tree
Hide file tree
Showing 44 changed files with 1,507 additions and 81 deletions.
4 changes: 2 additions & 2 deletions src/api/Synapse.Api.Http/Synapse.Api.Http.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Neuroglia.Mediation.AspNetCore" Version="4.11.3" />
<PackageReference Include="Neuroglia.Security.AspNetCore" Version="4.11.3" />
<PackageReference Include="Neuroglia.Mediation.AspNetCore" Version="4.12.0" />
<PackageReference Include="Neuroglia.Security.AspNetCore" Version="4.12.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.6.2" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ public async Task HandleAsync(string name, bool y)
{
Console.Write($"Are you sure you wish to delete the namespace '{name}'? Press 'y' to confirm, or any other key to cancel: ");
var inputKey = Console.ReadKey();
Console.WriteLine();
if (inputKey.Key != ConsoleKey.Y) return;
}
await this.Api.Namespaces.DeleteAsync(name);
Console.WriteLine($"namespace/{name} deleted");
Console.Write($"namespace/{name} deleted");
}

static class CommandOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

<ItemGroup>
<PackageReference Include="IdentityModel" Version="7.0.0" />
<PackageReference Include="Neuroglia.Data.Expressions.Abstractions" Version="4.11.3" />
<PackageReference Include="Neuroglia.Data.Infrastructure.Redis" Version="4.11.3" />
<PackageReference Include="Neuroglia.Data.Infrastructure.ResourceOriented.Redis" Version="4.11.3" />
<PackageReference Include="Neuroglia.Mediation" Version="4.11.3" />
<PackageReference Include="Neuroglia.Plugins" Version="4.11.3" />
<PackageReference Include="Neuroglia.Data.Expressions.Abstractions" Version="4.12.0" />
<PackageReference Include="Neuroglia.Data.Infrastructure.Redis" Version="4.12.0" />
<PackageReference Include="Neuroglia.Data.Infrastructure.ResourceOriented.Redis" Version="4.12.0" />
<PackageReference Include="Neuroglia.Mediation" Version="4.12.0" />
<PackageReference Include="Neuroglia.Plugins" Version="4.12.0" />
<PackageReference Include="ServerlessWorkflow.Sdk.IO" Version="1.0.0-alpha1" />
</ItemGroup>

Expand Down
40 changes: 40 additions & 0 deletions src/core/Synapse.Core/Extensions/WorkflowDefinitionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright © 2024-Present The Synapse Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"),
// 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 Synapse;

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

/// <summary>
/// Gets the task, if any, that should be executed after the specified one
/// </summary>
/// <param name="workflow">The <see cref="WorkflowDefinition"/> that defines the specified <see cref="TaskDefinition"/></param>
/// <param name="afterTask">The name/definition mapping of the <see cref="TaskDefinition"/> to get the following <see cref="TaskDefinition"/> of</param>
/// <param name="parentReference">A reference to the component that defines the next <see cref="TaskDefinition"/></param>
/// <returns>A name/definition mapping of the next <see cref="TaskDefinition"/>, if any</returns>
public static KeyValuePair<string, TaskDefinition>? GetNextTask(this WorkflowDefinition workflow, KeyValuePair<string, TaskDefinition> afterTask, string parentReference)
{
ArgumentNullException.ThrowIfNull(workflow);
ArgumentException.ThrowIfNullOrWhiteSpace(parentReference);
var taskMap = workflow.GetComponent<IDictionary<string, TaskDefinition>>(parentReference) ?? throw new NullReferenceException($"Failed to find the component at '{parentReference}'");
var taskIndex = taskMap.Keys.ToList().IndexOf(afterTask.Key);
var nextIndex = taskIndex < 0 ? -1 : taskIndex + 1;
if (nextIndex < 0 || nextIndex >= taskMap.Count) return null;
return taskMap.ElementAt(nextIndex);
}

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

<ItemGroup>
<PackageReference Include="Neuroglia.Data.Infrastructure.ResourceOriented" Version="4.11.3" />
<PackageReference Include="Neuroglia.Eventing.CloudEvents" Version="4.11.3" />
<PackageReference Include="Neuroglia.Data.Infrastructure.ResourceOriented" Version="4.12.0" />
<PackageReference Include="Neuroglia.Eventing.CloudEvents" Version="4.12.0" />
<PackageReference Include="Semver" Version="2.3.0" />
<PackageReference Include="ServerlessWorkflow.Sdk" Version="1.0.0-alpha1" />
</ItemGroup>
Expand Down
12 changes: 6 additions & 6 deletions src/correlator/Synapse.Correlator/Synapse.Correlator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
<PackageReference Include="Microsoft.Extensions.Configuration.KeyPerFile" Version="8.0.6" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
<PackageReference Include="Neuroglia.Data.Expressions.JavaScript" Version="4.11.3" />
<PackageReference Include="Neuroglia.Data.Expressions.JQ" Version="4.11.3" />
<PackageReference Include="Neuroglia.Eventing.CloudEvents.AspNetCore" Version="4.11.3" />
<PackageReference Include="Neuroglia.Mediation.AspNetCore" Version="4.11.3" />
<PackageReference Include="Neuroglia.Eventing.CloudEvents.Infrastructure" Version="4.11.3" />
<PackageReference Include="Neuroglia.Security.AspNetCore" Version="4.11.3" />
<PackageReference Include="Neuroglia.Data.Expressions.JavaScript" Version="4.12.0" />
<PackageReference Include="Neuroglia.Data.Expressions.JQ" Version="4.12.0" />
<PackageReference Include="Neuroglia.Eventing.CloudEvents.AspNetCore" Version="4.12.0" />
<PackageReference Include="Neuroglia.Mediation.AspNetCore" Version="4.12.0" />
<PackageReference Include="Neuroglia.Eventing.CloudEvents.Infrastructure" Version="4.12.0" />
<PackageReference Include="Neuroglia.Security.AspNetCore" Version="4.12.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.6.2" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.6.2" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@namespace Synapse.Dashboard.Components

<WorkflowDiagram WorkflowDefinition="Workflow.Spec.Versions.GetLatest()" Orientation="WorkflowDiagramOrientation.TopToBottom" />

@code{

[Parameter] public Workflow Workflow { get; set; } = null!;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright © 2024-Present The Synapse Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"),
// 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 ServerlessWorkflow.Sdk.Models.Tasks;

namespace Synapse.Dashboard.Components;

/// <summary>
/// Represents a call task node view model
/// </summary>
public class CallTaskNodeViewModel
: LabeledWorkflowNodeViewModel
{

/// <summary>
/// Initializes a new <see cref="CallTaskNodeViewModel"/>
/// </summary>
public CallTaskNodeViewModel(KeyValuePair<string, CallTaskDefinition> task)
: base(task.Key, "call-task-node", null, Neuroglia.Blazor.Dagre.Constants.NodeHeight * 1.5, Neuroglia.Blazor.Dagre.Constants.NodeHeight * 1.5)
{

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright © 2024-Present The Synapse Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"),
// 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 ServerlessWorkflow.Sdk.Models.Tasks;

namespace Synapse.Dashboard.Components;

/// <summary>
/// Represents a composite task node view model
/// </summary>
public class CompositeTaskNodeViewModel
: LabeledWorkflowNodeViewModel
{

/// <summary>
/// Initializes a new <see cref="CompositeTaskNodeViewModel"/>
/// </summary>
public CompositeTaskNodeViewModel(KeyValuePair<string, CompositeTaskDefinition> task)
: base(task.Key, "composite-task-node", null, Neuroglia.Blazor.Dagre.Constants.NodeHeight * 1.5, Neuroglia.Blazor.Dagre.Constants.NodeHeight * 1.5)
{

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright © 2024-Present The Synapse Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"),
// 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 Neuroglia.Blazor.Dagre;
using ServerlessWorkflow.Sdk.Models.Tasks;

namespace Synapse.Dashboard.Components;

/// <summary>
/// Represents an emit task node view model
/// </summary>
public class EmitTaskNodeViewModel
: LabeledWorkflowNodeViewModel
{

/// <summary>
/// Initializes a new <see cref="EmitTaskNodeViewModel"/>
/// </summary>
public EmitTaskNodeViewModel(KeyValuePair<string, EmitTaskDefinition> task)
: base(task.Key, "emit-task-node", null, Constants.NodeHeight * 1.5, Constants.NodeHeight * 1.5)
{

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright © 2024-Present The Synapse Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"),
// 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 Neuroglia.Blazor.Dagre;

namespace Synapse.Dashboard.Components;

/// <summary>
/// Represents the object that holds the data required to render the view of a workflow's end node
/// </summary>
public class EndNodeViewModel()
: WorkflowNodeViewModel(string.Empty, "end-node", NodeShape.Circle, WorkflowGraphBuilder.StartEndNodeRadius, WorkflowGraphBuilder.StartEndNodeRadius)
{



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright © 2024-Present The Synapse Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"),
// 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 ServerlessWorkflow.Sdk.Models.Tasks;

namespace Synapse.Dashboard.Components;

/// <summary>
/// Represents a extension task node view model
/// </summary>
public class ExtensionTaskNodeViewModel
: LabeledWorkflowNodeViewModel
{

/// <summary>
/// Initializes a new <see cref="ExtensionTaskNodeViewModel"/>
/// </summary>
public ExtensionTaskNodeViewModel(KeyValuePair<string, ExtensionTaskDefinition> task)
: base(task.Key, "composite-task-node", null, Neuroglia.Blazor.Dagre.Constants.NodeHeight * 1.5, Neuroglia.Blazor.Dagre.Constants.NodeHeight * 1.5)
{

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright © 2024-Present The Synapse Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"),
// 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 Neuroglia.Blazor.Dagre;
using ServerlessWorkflow.Sdk.Models.Tasks;

namespace Synapse.Dashboard.Components;

/// <summary>
/// Represents a for task node view model
/// </summary>
public class ForTaskNodeViewModel
: LabeledWorkflowNodeViewModel
{

/// <summary>
/// Initializes a new <see cref="ForTaskNodeViewModel"/>
/// </summary>
public ForTaskNodeViewModel(KeyValuePair<string, ForTaskDefinition> task)
: base(task.Key, "for-task-node", null, Constants.NodeHeight * 1.5, Constants.NodeHeight * 1.5)
{

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright © 2024-Present The Synapse Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"),
// 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 Synapse.Resources;

namespace Synapse.Dashboard.Components;

/// <summary>
/// Defines the fundamentals of a workflow node
/// </summary>
public interface IWorkflowNodeViewModel
{

/// <summary>
/// Gets/Sets the number of active <see cref="WorkflowInstance"/>s for which the task described by the node is operative
/// </summary>
int OperativeInstancesCount { get; set; }

/// <summary>
/// Gets/Sets the number of active faulted <see cref="WorkflowInstance"/>s for which the task described by the node is faulted
/// </summary>
int FaultedInstancesCount { get; set; }

/// <summary>
/// Resets the operative and faulted instances counts
/// </summary>
void ResetInstancesCount();

}
Loading

0 comments on commit d1454b5

Please sign in to comment.