Skip to content

Commit d4d5420

Browse files
committed
feat(Correlator): Continue implementation of the correlation handler service (WIP)
Signed-off-by: Charles d'Avernas <charles.davernas@neuroglia.io>
1 parent 8dbb1ac commit d4d5420

File tree

12 files changed

+401
-85
lines changed

12 files changed

+401
-85
lines changed

src/api/Synapse.Api.Client.Core/Services/ISynapseApiClient.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ namespace Synapse.Api.Client.Services;
1919
public interface ISynapseApiClient
2020
{
2121

22+
/// <summary>
23+
/// Gets the Synapse API used to manage <see cref="Correlator"/>s
24+
/// </summary>
25+
INamespacedResourceApiClient<Correlator> Correlators { get; }
26+
2227
/// <summary>
2328
/// Gets the Synapse API used to manage <see cref="Namespace"/>s
2429
/// </summary>

src/api/Synapse.Api.Client.Http/Services/SynapseHttpApiClient.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,14 @@ public SynapseHttpApiClient(IServiceProvider serviceProvider, ILoggerFactory log
6464
protected HttpClient HttpClient { get; }
6565

6666
/// <inheritdoc/>
67-
public INamespacedResourceApiClient<Operator> Operators { get; private set; } = null!;
67+
public INamespacedResourceApiClient<Correlator> Correlators { get; private set; } = null!;
6868

6969
/// <inheritdoc/>
7070
public IClusterResourceApiClient<Namespace> Namespaces { get; private set; } = null!;
7171

72+
/// <inheritdoc/>
73+
public INamespacedResourceApiClient<Operator> Operators { get; private set; } = null!;
74+
7275
/// <inheritdoc/>
7376
public IDocumentApiClient WorkflowData { get; }
7477

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright © 2024-Present Neuroglia SRL. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
using Synapse.Resources;
15+
16+
namespace Synapse.Api.Http.Controllers;
17+
18+
/// <summary>
19+
/// Represents the <see cref="NamespacedResourceController{TResource}"/> used to manage <see cref="Correlation"/>s
20+
/// </summary>
21+
/// <param name="mediator">The service used to mediate calls</param>
22+
[Route("api/v1/correlations")]
23+
public class CorrelationsController(IMediator mediator)
24+
: NamespacedResourceController<Correlation>(mediator)
25+
{
26+
27+
28+
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright © 2024-Present Neuroglia SRL. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
using Synapse.Resources;
15+
16+
namespace Synapse.Api.Http.Controllers;
17+
18+
/// <summary>
19+
/// Represents the <see cref="NamespacedResourceController{TResource}"/> used to manage <see cref="Correlator"/>s
20+
/// </summary>
21+
/// <param name="mediator">The service used to mediate calls</param>
22+
[Route("api/v1/correlators")]
23+
public class CorrelatorsController(IMediator mediator)
24+
: NamespacedResourceController<Correlator>(mediator)
25+
{
26+
27+
28+
29+
}

src/core/Synapse.Core/Extensions/ExceptionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ public static Error ToError(this Exception ex, Uri? instance = null)
5050
};
5151
}
5252

53-
}
53+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright © 2024-Present Neuroglia SRL. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
using Neuroglia.Eventing.CloudEvents;
15+
16+
namespace Synapse.Resources;
17+
18+
/// <summary>
19+
/// Represents an object used to describe the context of a correlation
20+
/// </summary>
21+
[DataContract]
22+
public record CorrelationContext
23+
{
24+
25+
/// <summary>
26+
/// Gets/sets the context's unique identifier
27+
/// </summary>
28+
[DataMember(Name = "id", Order = 1), JsonPropertyName("id"), JsonPropertyOrder(1), YamlMember(Alias = "id", Order = 1)]
29+
public required virtual string Id { get; set; }
30+
31+
/// <summary>
32+
/// Gets a key/value mapping of the context's correlation keys
33+
/// </summary>
34+
[DataMember(Name = "keys", Order = 2), JsonPropertyName("keys"), JsonPropertyOrder(2), YamlMember(Alias = "keys", Order = 2)]
35+
public virtual EquatableDictionary<string, string> Keys { get; set; } = [];
36+
37+
/// <summary>
38+
/// Gets a key/value mapping of all correlated events, with the key being the index of the matched correlation filter
39+
/// </summary>
40+
[DataMember(Name = "events", Order = 3), JsonPropertyName("events"), JsonPropertyOrder(3), YamlMember(Alias = "events", Order = 3)]
41+
public virtual EquatableDictionary<int, CloudEvent> Events { get; set; } = [];
42+
43+
}

src/core/Synapse.Core/Resources/CorrelationStatus.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ namespace Synapse.Resources;
2020
public record CorrelationStatus
2121
{
2222

23-
23+
/// <summary>
24+
/// Gets/sets a list containing the contexts that have been created for the described correlation
25+
/// </summary>
26+
[DataMember(Name = "contexts", Order = 1), JsonPropertyName("contexts"), JsonPropertyOrder(1), YamlMember(Alias = "contexts", Order = 1)]
27+
public virtual EquatableList<CorrelationContext> Contexts { get; set; } = [];
2428

2529
}

src/core/Synapse.Core/SynapseDefaults.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,29 +139,41 @@ public static class Definitions
139139
{
140140

141141
/// <summary>
142-
/// Gets the definition of Workflow resources
142+
/// Gets the definition of Correlation resources
143143
/// </summary>
144-
public static ResourceDefinition Workflow { get; } = new WorkflowResourceDefinition();
144+
public static ResourceDefinition Correlation { get; } = new CorrelationResourceDefinition();
145145

146146
/// <summary>
147-
/// Gets the definition of WorkflowInstance resources
147+
/// Gets the definition of Correlator resources
148148
/// </summary>
149-
public static ResourceDefinition WorkflowInstance { get; } = new WorkflowInstanceResourceDefinition();
149+
public static ResourceDefinition Correlator { get; } = new CorrelatorResourceDefinition();
150150

151151
/// <summary>
152152
/// Gets the definition of Operator resources
153153
/// </summary>
154154
public static ResourceDefinition Operator { get; } = new OperatorResourceDefinition();
155155

156+
/// <summary>
157+
/// Gets the definition of Workflow resources
158+
/// </summary>
159+
public static ResourceDefinition Workflow { get; } = new WorkflowResourceDefinition();
160+
161+
/// <summary>
162+
/// Gets the definition of WorkflowInstance resources
163+
/// </summary>
164+
public static ResourceDefinition WorkflowInstance { get; } = new WorkflowInstanceResourceDefinition();
165+
156166
/// <summary>
157167
/// Gets a new <see cref="IEnumerable{T}"/> containing Synapse default resource definitions
158168
/// </summary>
159169
/// <returns></returns>
160170
public static IEnumerable<ResourceDefinition> AsEnumerable()
161171
{
172+
yield return Correlation;
173+
yield return Correlator;
174+
yield return Operator;
162175
yield return Workflow;
163176
yield return WorkflowInstance;
164-
yield return Operator;
165177
}
166178

167179
}

0 commit comments

Comments
 (0)