Skip to content

Commit

Permalink
fix(Solution): Transformed the CustomFunction into a cluster resource
Browse files Browse the repository at this point in the history
Signed-off-by: Charles d'Avernas <[email protected]>
  • Loading branch information
cdavernas committed Oct 22, 2024
1 parent 5cf98c0 commit f02958c
Show file tree
Hide file tree
Showing 34 changed files with 60 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha4</VersionSuffix>
<VersionSuffix>alpha4.1</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public interface ISynapseApiClient
/// <summary>
/// Gets the Synapse API used to manage <see cref="CustomFunction"/>s
/// </summary>
INamespacedResourceApiClient<CustomFunction> CustomFunctions { get; }
IClusterResourceApiClient<CustomFunction> CustomFunctions { get; }

/// <summary>
/// Gets the Synapse API used to manage <see cref="Document"/>s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha4</VersionSuffix>
<VersionSuffix>alpha4.1</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public SynapseHttpApiClient(IServiceProvider serviceProvider, ILoggerFactory log
public INamespacedResourceApiClient<Correlator> Correlators { get; private set; } = null!;

/// <inheritdoc/>
public INamespacedResourceApiClient<CustomFunction> CustomFunctions { get; private set; } = null!;
public IClusterResourceApiClient<CustomFunction> CustomFunctions { get; private set; } = null!;

/// <inheritdoc/>
public IDocumentApiClient Documents { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha4</VersionSuffix>
<VersionSuffix>alpha4.1</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
namespace Synapse.Api.Http.Controllers;

/// <summary>
/// Represents the <see cref="NamespacedResourceController{TResource}"/> used to manage <see cref="CustomFunction"/>s
/// Represents the <see cref="ClusterResourceController{TResource}"/> used to manage <see cref="CustomFunction"/>s
/// </summary>
/// <param name="mediator">The service used to mediate calls</param>
/// <param name="jsonSerializer">The service used to serialize/deserialize objects to/from JSON</param>
[Route("api/v1/custom-functions")]
public class CustomFunctionsController(IMediator mediator, IJsonSerializer jsonSerializer)
: NamespacedResourceController<CustomFunction>(mediator, jsonSerializer)
: ClusterResourceController<CustomFunction>(mediator, jsonSerializer)
{


Expand Down
2 changes: 1 addition & 1 deletion src/api/Synapse.Api.Http/Synapse.Api.Http.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>Library</OutputType>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha4</VersionSuffix>
<VersionSuffix>alpha4.1</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
2 changes: 1 addition & 1 deletion src/api/Synapse.Api.Server/Synapse.Api.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha4</VersionSuffix>
<VersionSuffix>alpha4.1</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
2 changes: 1 addition & 1 deletion src/cli/Synapse.Cli/Synapse.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha4</VersionSuffix>
<VersionSuffix>alpha4.1</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha4</VersionSuffix>
<VersionSuffix>alpha4.1</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha4</VersionSuffix>
<VersionSuffix>alpha4.1</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha4</VersionSuffix>
<VersionSuffix>alpha4.1</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
2 changes: 1 addition & 1 deletion src/core/Synapse.Core/Resources/CustomFunction.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: CustomResourceDefinition
metadata:
name: custom-functions.synapse.io
spec:
scope: Namespaced
scope: Cluster
group: synapse.io
names:
plural: custom-functions
Expand Down
2 changes: 1 addition & 1 deletion src/core/Synapse.Core/Synapse.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha4</VersionSuffix>
<VersionSuffix>alpha4.1</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha4</VersionSuffix>
<VersionSuffix>alpha4.1</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ namespace Synapse.Dashboard.Components.ResourceManagement;
/// <param name="resourceEventHub">The <see cref="IResourceEventWatchHub"/> websocket service client</param>
public class NamespacedResourceManagementComponentStore<TState, TResource>(ILogger<NamespacedResourceManagementComponentStore<TState, TResource>> logger, ISynapseApiClient apiClient, ResourceWatchEventHubClient resourceEventHub)
: ResourceManagementComponentStoreBase<TState, TResource>(logger, apiClient, resourceEventHub)
where TResource : Resource, new()
where TState : NamespacedResourceManagementComponentState<TResource>, new()
where TResource : Resource, new()
{

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using moment.net.Models;
using System.Globalization;

namespace Synapse.Dashboard.Extensions;
namespace Synapse.Dashboard;

/// <summary>
/// Provides extension methods for <see cref="DateTime"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@
<ConfirmDialog @ref="Dialog" />

@code {

/// <inheritdoc/>
protected override void OnInitialized()
{
base.OnInitialized();
BreadcrumbManager.Use(Breadcrumbs.Correlators);
}

}
14 changes: 0 additions & 14 deletions src/dashboard/Synapse.Dashboard/Pages/Functions/Create/State.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,12 @@ namespace Synapse.Dashboard.Pages.Functions.Create;
[Feature]
public record CreateFunctionViewState
{
/// <summary>
/// Gets a <see cref="EquatableList{T}"/> that contains all <see cref="Neuroglia.Data.Infrastructure.ResourceOriented.Namespace"/>s
/// </summary>
public EquatableList<Namespace>? Namespaces { get; set; }

/// <summary>
/// Gets/sets the <see cref="CustomFunction"/>'s namespace
/// </summary>
public string? Namespace { get; set; }

/// <summary>
/// Gets/sets the <see cref="CustomFunction"/>'s name
/// </summary>
public string? Name { get; set; }

/// <summary>
/// Gets/sets the <see cref="CustomFunction"/>'s namespace, when the user is creating one
/// </summary>
public string? ChosenNamespace { get; set; }

/// <summary>
/// Gets/sets the <see cref="CustomFunction"/>'s name, when the user is creating one
/// </summary>
Expand Down
83 changes: 12 additions & 71 deletions src/dashboard/Synapse.Dashboard/Pages/Functions/Create/Store.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,13 @@ MonacoInterop monacoInterop
/// </summary>
public StandaloneCodeEditor? TextEditor { get; set; }

/// <summary>
/// Gets an <see cref="IObservable{T}"/> used to observe <see cref="Namespace"/>s
/// </summary>
public IObservable<EquatableList<Namespace>?> Namespaces => this.Select(s => s.Namespaces).DistinctUntilChanged();

#region Selectors
/// <summary>
/// Gets an <see cref="IObservable{T}"/> used to observe <see cref="CreateFunctionViewState.Namespace"/> changes
/// </summary>
public IObservable<string?> Namespace => this.Select(state => state.Namespace).DistinctUntilChanged();

/// <summary>
/// Gets an <see cref="IObservable{T}"/> used to observe <see cref="CreateFunctionViewState.Name"/> changes
/// </summary>
public IObservable<string?> Name => this.Select(state => state.Name).DistinctUntilChanged();

/// <summary>
/// Gets an <see cref="IObservable{T}"/> used to observe <see cref="CreateFunctionViewState.ChosenNamespace"/> changes
/// </summary>
public IObservable<string?> ChosenNamespace => this.Select(state => state.ChosenNamespace).DistinctUntilChanged();

/// <summary>
/// Gets an <see cref="IObservable{T}"/> used to observe <see cref="CreateFunctionViewState.ChosenName"/> changes
/// </summary>
Expand Down Expand Up @@ -203,18 +189,6 @@ MonacoInterop monacoInterop
#endregion

#region Setters
/// <summary>
/// Sets the state's <see cref="CreateFunctionViewState.Namespace"/>
/// </summary>
/// <param name="ns">The new <see cref="CreateFunctionViewState.Namespace"/> value</param>
public void SetNamespace(string? ns)
{
this.Reduce(state => state with
{
Namespace = ns,
Loading = true
});
}

/// <summary>
/// Sets the state's <see cref="CreateFunctionViewState.Name"/>
Expand All @@ -228,17 +202,6 @@ public void SetName(string? name)
Loading = true
});
}
/// <summary>
/// Sets the state's <see cref="CreateFunctionViewState.ChosenNamespace"/>
/// </summary>
/// <param name="ns">The new <see cref="CreateFunctionViewState.ChosenNamespace"/> value</param>
public void SetChosenNamespace(string? ns)
{
this.Reduce(state => state with
{
ChosenNamespace = ns
});
}

/// <summary>
/// Sets the state's <see cref="CreateFunctionViewState.ChosenName"/>
Expand Down Expand Up @@ -273,14 +236,12 @@ public void SetProblemDetails(ProblemDetails? problem)
/// <summary>
/// Gets the <see cref="CustomFunction"/> for the specified namespace and name
/// </summary>
/// <param name="namespace">The namespace the <see cref="CustomFunction"/> to create a new version of belongs to</param>
/// <param name="name">The name of the <see cref="CustomFunction"/> to create a new version of</param>
/// <returns>A new awaitable <see cref="Task"/></returns>
public async Task GetCustomFunctionAsync(string @namespace, string name)
public async Task GetCustomFunctionAsync(string name)
{
ArgumentException.ThrowIfNullOrWhiteSpace(@namespace);
ArgumentException.ThrowIfNullOrWhiteSpace(name);
var resources = await this.ApiClient.CustomFunctions.GetAsync(name, @namespace) ?? throw new NullReferenceException($"Failed to find the specified function '{name}.{@namespace}'");
var resources = await this.ApiClient.CustomFunctions.GetAsync(name) ?? throw new NullReferenceException($"Failed to find the specified function '{name}'");
var version = resources.Spec.Versions.GetLatestVersion();
var function = resources.Spec.Versions.GetLatest();
var nextVersion = SemVersion.Parse(version, SemVersionStyles.Strict);
Expand Down Expand Up @@ -429,15 +390,14 @@ public async Task SaveCustomFunctionAsync()
var function = this.MonacoEditorHelper.PreferredLanguage == PreferredLanguage.JSON ?
this.JsonSerializer.Deserialize<TaskDefinition>(functionText)! :
this.YamlSerializer.Deserialize<TaskDefinition>(functionText)!;
var @namespace = this.Get(state => state.Namespace) ?? this.Get(state => state.ChosenNamespace);
var name = this.Get(state => state.Name) ?? this.Get(state => state.ChosenName);
var version = this.Get(state => state.Version).ToString();
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(@namespace))
if (string.IsNullOrEmpty(name))
{
this.Reduce(state => state with
{
ProblemTitle = "Invalid function",
ProblemDetail = "The name or namespace cannot be empty."
ProblemDetail = "The name cannot be empty."
});
return;
}
Expand All @@ -448,7 +408,7 @@ public async Task SaveCustomFunctionAsync()
CustomFunction? resource = null;
try
{
resource = await this.ApiClient.CustomFunctions.GetAsync(name, @namespace);
resource = await this.ApiClient.CustomFunctions.GetAsync(name);
}
catch
{
Expand All @@ -460,7 +420,6 @@ public async Task SaveCustomFunctionAsync()
{
Metadata = new()
{
Namespace = @namespace,
Name = name
},
Spec = new()
Expand All @@ -478,10 +437,10 @@ public async Task SaveCustomFunctionAsync()
if (patch != null)
{
var resourcePatch = new Patch(PatchType.JsonPatch, jsonPatch);
await this.ApiClient.ManageNamespaced<CustomFunction>().PatchAsync(name, @namespace, resourcePatch, null, this.CancellationTokenSource.Token);
await this.ApiClient.ManageCluster<CustomFunction>().PatchAsync(name, resourcePatch, null, this.CancellationTokenSource.Token);
}
}
this.NavigationManager.NavigateTo($"/functions/{@namespace}/{name}");
this.NavigationManager.NavigateTo($"/functions/{name}");
}
catch (ProblemDetailsException ex)
{
Expand Down Expand Up @@ -531,9 +490,8 @@ public async Task SaveCustomFunctionAsync()
/// <inheritdoc/>
public override async Task InitializeAsync()
{
await this.ListNamespacesAsync().ConfigureAwait(false);
this.Function.SubscribeAsync(async definition => {
string document = "";
string document = string.Empty;
if (definition != null)
{
document = this.MonacoEditorHelper.PreferredLanguage == PreferredLanguage.JSON ?
Expand All @@ -546,14 +504,10 @@ public override async Task InitializeAsync()
});
await this.OnTextBasedEditorInitAsync();
}, cancellationToken: this.CancellationTokenSource.Token);
Observable.CombineLatest(
this.Namespace.Where(ns => !string.IsNullOrWhiteSpace(ns)),
this.Name.Where(name => !string.IsNullOrWhiteSpace(name)),
(ns, name) => (ns!, name!)
).SubscribeAsync(async ((string ns, string name) function) =>
{
await this.GetCustomFunctionAsync(function.ns, function.name);
}, cancellationToken: this.CancellationTokenSource.Token);
this.Name.Where(name => !string.IsNullOrWhiteSpace(name))
.SubscribeAsync(async name =>
await this.GetCustomFunctionAsync(name!),
cancellationToken: this.CancellationTokenSource.Token);
await this.SetValidationSchema();
await base.InitializeAsync();
}
Expand Down Expand Up @@ -587,19 +541,6 @@ protected async Task SetValidationSchema(string? version = null)
this._processingVersion = false;
}

/// <summary>
/// Lists all available <see cref="Namespace"/>s
/// </summary>
/// <returns>A new awaitable <see cref="Task"/></returns>
public virtual async Task ListNamespacesAsync()
{
var namespaceList = new EquatableList<Namespace>(await (await this.ApiClient.Namespaces.ListAsync().ConfigureAwait(false)).OrderBy(ns => ns.GetQualifiedName()).ToListAsync().ConfigureAwait(false));
this.Reduce(s => s with
{
Namespaces = namespaceList
});
}

/// <summary>
/// Disposes of the store
/// </summary>
Expand Down
Loading

0 comments on commit f02958c

Please sign in to comment.