-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the source code to open source repo (#5)
* Move the source code to open source repo ## Scope - The source code has been moved to the open source repo - Added docstrings to public classes/methods/etc. - Updated project structure **NOTES** 1. The source code was moved as is w/o refactoring, but project layout was updated. * Fix unit tests
- Loading branch information
Showing
46 changed files
with
3,046 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Arcane.Operator; | ||
|
||
public static class ArcaneEnvironment | ||
{ | ||
public static string DefaultVarPrefix => $"{nameof(Arcane).ToUpper()}__"; | ||
|
||
public static string GetEnvironmentVariableName(this string name) | ||
{ | ||
return $"{DefaultVarPrefix}{name}".ToUpperInvariant(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using Snd.Sdk.Kubernetes; | ||
|
||
namespace Arcane.Operator.Configurations; | ||
|
||
[ExcludeFromCodeCoverage(Justification = "Model")] | ||
public class CustomResourceConfiguration | ||
{ | ||
/// <summary> | ||
/// Api group of the StreamDefinition CRD | ||
/// </summary> | ||
public string ApiGroup { get; init; } | ||
|
||
/// <summary> | ||
/// Version of the CRD | ||
/// </summary> | ||
public string Version { get; init; } | ||
|
||
/// <summary> | ||
/// Plural of the CRD | ||
/// </summary> | ||
public string Plural { get; init; } | ||
|
||
/// <summary> | ||
/// Convert configuration to NamespacedCrd object for consuming in the Proteus library | ||
/// </summary> | ||
/// <returns><see cref="NamespacedCrd"/> object</returns> | ||
public NamespacedCrd ToNamespacedCrd() | ||
{ | ||
return new NamespacedCrd | ||
{ | ||
Group = this.ApiGroup, | ||
Plural = this.Plural, | ||
Version = this.Version | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using Arcane.Operator.Services.Operator; | ||
|
||
namespace Arcane.Operator.Configurations; | ||
|
||
/// <summary> | ||
/// Configuration for the <see cref="StreamOperatorService{TStreamType}"/> | ||
/// </summary> | ||
[ExcludeFromCodeCoverage(Justification = "Model")] | ||
public class StreamOperatorServiceConfiguration | ||
{ | ||
/// <summary> | ||
/// Max buffer capacity for StreamDefinitions events stream | ||
/// </summary> | ||
public int MaxBufferCapacity { get; init; } | ||
|
||
/// <summary> | ||
/// Parallelism for StreamDefinitions events stream | ||
/// </summary> | ||
public int Parallelism { get; init; } | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Configurations/StreamingJobMaintenanceServiceConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using Arcane.Operator.Services.Maintenance; | ||
|
||
namespace Arcane.Operator.Configurations; | ||
|
||
/// <summary> | ||
/// Configuration for the <see cref="StreamingJobMaintenanceService"/> | ||
/// </summary> | ||
[ExcludeFromCodeCoverage(Justification = "Model")] | ||
public class StreamingJobMaintenanceServiceConfiguration | ||
{ | ||
/// <summary> | ||
/// Max buffer capacity for job events stream | ||
/// </summary> | ||
public int MaxBufferCapacity { get; init; } | ||
|
||
|
||
/// <summary> | ||
/// Parallelism for job events stream | ||
/// </summary> | ||
public int Parallelism { get; init; } | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Configurations/StreamingJobOperatorServiceConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using Arcane.Operator.Services.Streams; | ||
using k8s.Models; | ||
|
||
namespace Arcane.Operator.Configurations; | ||
|
||
/// <summary> | ||
/// Configuration for the <see cref="StreamingJobOperatorService"/> | ||
/// </summary> | ||
[ExcludeFromCodeCoverage(Justification = "Model")] | ||
public class StreamingJobOperatorServiceConfiguration | ||
{ | ||
/// <summary> | ||
/// Template for the job to be created. | ||
/// </summary> | ||
public V1Job JobTemplate { get; set; } | ||
|
||
/// <summary> | ||
/// Namespace where the job will be created | ||
/// </summary> | ||
public string Namespace { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using System.Collections.Generic; | ||
using Arcane.Models.StreamingJobLifecycle; | ||
using k8s.Models; | ||
using Snd.Sdk.Kubernetes; | ||
|
||
namespace Arcane.Operator.Extensions; | ||
|
||
public static class V1JobExtensions | ||
{ | ||
public const string STREAM_KIND_LABEL = "arcane/stream-kind"; | ||
public const string STREAM_ID_LABEL = "arcane/stream-id"; | ||
public const string FULL_LOAD_LABEL = "arcane/full-load"; | ||
|
||
public static V1Job WithStreamingJobLabels(this V1Job job, string streamId, | ||
bool fullLoadOnStart, string streamKind) | ||
{ | ||
return job.WithLabels(new Dictionary<string, string> | ||
{ | ||
{ STREAM_ID_LABEL, streamId }, | ||
{ STREAM_KIND_LABEL, streamKind }, | ||
{ FULL_LOAD_LABEL, fullLoadOnStart.ToString().ToLowerInvariant() } | ||
}); | ||
} | ||
|
||
public static V1Job WithStreamingJobAnnotations(this V1Job job, string configurationChecksum) | ||
{ | ||
return job.WithAnnotations(new Dictionary<string, string> | ||
{ | ||
{ Annotations.CONFIGURATION_CHECKSUM_ANNOTATION_KEY, configurationChecksum } | ||
}); | ||
} | ||
|
||
public static string GetStreamId(this V1Job job) | ||
{ | ||
return job.Name(); | ||
} | ||
|
||
public static string GetStreamKind(this V1Job job) | ||
{ | ||
if (job.Labels() != null && job.Labels().TryGetValue(STREAM_KIND_LABEL, out var value)) | ||
{ | ||
return value; | ||
} | ||
|
||
return string.Empty; | ||
} | ||
|
||
public static string GetConfigurationChecksum(this V1Job job) | ||
{ | ||
if (job.Annotations() != null && job.Annotations().TryGetValue( | ||
Annotations.CONFIGURATION_CHECKSUM_ANNOTATION_KEY, | ||
out var value)) | ||
{ | ||
return value; | ||
} | ||
|
||
return string.Empty; | ||
} | ||
|
||
public static bool IsStopRequested(this V1Job job) | ||
{ | ||
return job.Annotations() != null | ||
&& job.Annotations().TryGetValue(Annotations.STATE_ANNOTATION_KEY, out var value) | ||
&& value == Annotations.TERMINATE_REQUESTED_STATE_ANNOTATION_VALUE; | ||
} | ||
|
||
public static bool IsRestartRequested(this V1Job job) | ||
{ | ||
return job.Annotations() != null | ||
&& job.Annotations().TryGetValue(Annotations.STATE_ANNOTATION_KEY, out var value) | ||
&& value == Annotations.RESTARTING_STATE_ANNOTATION_VALUE; | ||
} | ||
|
||
public static bool IsReloadRequested(this V1Job job) | ||
{ | ||
return job.Annotations() != null | ||
&& job.Annotations().TryGetValue(Annotations.STATE_ANNOTATION_KEY, out var value) | ||
&& value == Annotations.RELOADING_STATE_ANNOTATION_VALUE; | ||
} | ||
|
||
public static bool IsReloading(this V1Job job) | ||
{ | ||
return job.Labels() != null | ||
&& job.Labels().TryGetValue(FULL_LOAD_LABEL, out var value) | ||
&& value == "true"; | ||
} | ||
|
||
public static bool IsSchemaMismatch(this V1Job job) | ||
{ | ||
return job.Annotations() != null | ||
&& job.Annotations().TryGetValue(Annotations.STATE_ANNOTATION_KEY, out var value) | ||
&& value == Annotations.SCHEMA_MISMATCH_STATE_ANNOTATION_VALUE; | ||
} | ||
|
||
public static bool IsStopping(this V1Job job) | ||
{ | ||
return job.Annotations() != null | ||
&& job.Annotations().TryGetValue(Annotations.STATE_ANNOTATION_KEY, out var value) | ||
&& value == Annotations.TERMINATING_STATE_ANNOTATION_VALUE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Text.Json.Serialization; | ||
using k8s; | ||
using k8s.Models; | ||
|
||
namespace Arcane.Operator.JobTemplates.V1Beta1; | ||
|
||
[ExcludeFromCodeCoverage(Justification = "Model")] | ||
public class V1Beta1StreamingJobTemplate : IKubernetesObject<V1ObjectMeta> | ||
{ | ||
/// <summary> | ||
/// Streaming job configuration | ||
/// </summary> | ||
[JsonPropertyName("spec")] | ||
public V1Beta1StreamingJobTemplateSpec Spec { get; set; } | ||
|
||
/// <summary> | ||
/// Api version | ||
/// </summary> | ||
[JsonPropertyName("apiVersion")] | ||
public string ApiVersion { get; set; } | ||
|
||
/// <summary> | ||
/// Object kind (should always be "StreamingJobTemplate") | ||
/// </summary> | ||
[JsonPropertyName("kind")] | ||
public string Kind { get; set; } | ||
|
||
/// <summary> | ||
/// Object metadata see <see cref="V1ObjectMeta"/> | ||
/// </summary> | ||
[JsonPropertyName("metadata")] | ||
public V1ObjectMeta Metadata { get; set; } | ||
|
||
public V1Job GetJob() | ||
{ | ||
return new V1Job | ||
{ | ||
ApiVersion = "batch/v1", | ||
Kind = "Job", | ||
Metadata = this.Spec.Metadata ?? new V1ObjectMeta(), | ||
Spec = this.Spec.Template.Spec | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Text.Json.Serialization; | ||
using k8s.Models; | ||
|
||
namespace Arcane.Operator.JobTemplates.V1Beta1; | ||
|
||
/// <summary> | ||
/// Configuration for streaming job template. | ||
/// </summary> | ||
[ExcludeFromCodeCoverage(Justification = "Model")] | ||
public class V1Beta1StreamingJobTemplateSpec | ||
{ | ||
/// <summary> | ||
/// Job template reference | ||
/// </summary> | ||
[JsonPropertyName("template")] | ||
public V1Job Template { get; init; } | ||
|
||
/// <summary> | ||
/// Job template reference | ||
/// </summary> | ||
[JsonPropertyName("metadata")] | ||
public V1ObjectMeta Metadata { get; init; } | ||
} |
Oops, something went wrong.