Skip to content

Commit

Permalink
Move the source code to open source repo (#5)
Browse files Browse the repository at this point in the history
* 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
s-vitaliy authored Apr 3, 2024
1 parent a6c04cd commit 293942b
Show file tree
Hide file tree
Showing 46 changed files with 3,046 additions and 21 deletions.
6 changes: 4 additions & 2 deletions src/Arcane.Operator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
<LangVersion>10</LangVersion>
<RootNamespace>Arcane.Operator</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SnD.Sdk" Version="1.0.5"/>
<PackageReference Include="SnD.Sdk" Version="1.0.6"/>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0"/>
</ItemGroup>



</Project>
11 changes: 11 additions & 0 deletions src/ArcaneEnvironment.cs
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();
}
}
37 changes: 37 additions & 0 deletions src/Configurations/CustomResourceConfiguration.cs
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
};
}
}
21 changes: 21 additions & 0 deletions src/Configurations/StreamOperatorServiceConfiguration.cs
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 src/Configurations/StreamingJobMaintenanceServiceConfiguration.cs
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 src/Configurations/StreamingJobOperatorServiceConfiguration.cs
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; }
}
101 changes: 101 additions & 0 deletions src/Extensions/V1JobExtensions.cs
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;
}
}
45 changes: 45 additions & 0 deletions src/JobTemplates/V1Beta1/V1Beta1StreamingJobTemplate.cs
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
};
}
}
24 changes: 24 additions & 0 deletions src/JobTemplates/V1Beta1/V1StreamingJobTemplateSpec.cs
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; }
}
Loading

0 comments on commit 293942b

Please sign in to comment.