Skip to content

Commit

Permalink
Move (de-)serialization from Newtonsoft.JSON to System.Json.Text (#64)
Browse files Browse the repository at this point in the history
* Move (de-)serialization from Newtonsoft.JSON to System.Json.Text

Updated de-serialization
Fixed unit test project
Fixed broken dockerfiles for testing

* Updated Readme file after upgrade to .net 7

* Some cleanup + test fix

* Remove dangling file

---------

Co-authored-by: Timm Hoffmeister <[email protected]>
Co-authored-by: Gutemberg Ribeiro <[email protected]>
  • Loading branch information
3 people authored Feb 17, 2023
1 parent 2782004 commit ce56475
Show file tree
Hide file tree
Showing 22 changed files with 125 additions and 317 deletions.
200 changes: 0 additions & 200 deletions .editorconfig

This file was deleted.

24 changes: 15 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
# - uses: engineerd/[email protected]
# with:
# config: .github/workflows/kind.yml
# - name: Setup Kube API
# run: kubectl proxy &
- uses: actions/checkout@v3

- name: Create k8s Kind Cluster
uses: helm/[email protected]

- name: Setup CRDs
run: |
kubectl apply -f src/Orleans.Clustering.Kubernetes/Definitions
kubectl create ns orleans
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.100

- name: Build
run: dotnet build --configuration Release
# - name: Test
# run: dotnet test --configuration Release --no-build

- name: Test
run: dotnet test --configuration Release --no-build
10 changes: 0 additions & 10 deletions .github/workflows/kind.yml

This file was deleted.

2 changes: 1 addition & 1 deletion samples/HelloWorld.Grains/HelloArchiveGrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public async Task<string> SayHello(string greeting)
{
this.State.Greetings.Add(greeting);

await WriteStateAsync();
await this.WriteStateAsync();

return $"You said: '{greeting}', I say: Hello!";
}
Expand Down
2 changes: 1 addition & 1 deletion samples/KubeClient/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/runtime:7.0-alpine
WORKDIR /app
COPY ./bin/Debug/net7.0 ./
COPY . ./
ENTRYPOINT ["dotnet", "KubeClient.dll"]
2 changes: 1 addition & 1 deletion samples/KubeClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace KubeClient;
/// </summary>
public static class Program
{
private static readonly AutoResetEvent Closing = new AutoResetEvent(false);
private static readonly AutoResetEvent Closing = new(false);

public static async Task<int> Main()
{
Expand Down
2 changes: 1 addition & 1 deletion samples/KubeGatewayHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace KubeGatewayHost;

public static class Program
{
private static readonly AutoResetEvent Closing = new AutoResetEvent(false);
private static readonly AutoResetEvent Closing = new(false);

public static async Task<int> Main()
{
Expand Down
2 changes: 1 addition & 1 deletion samples/KubeSiloHost/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/runtime:7.0-alpine
WORKDIR /app
COPY ./bin/Debug/net7.0 ./
COPY . ./
ENTRYPOINT ["dotnet", "KubeSiloHost.dll"]
2 changes: 1 addition & 1 deletion samples/KubeSiloHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace KubeSiloHost;

public static class Program
{
private static readonly AutoResetEvent Closing = new AutoResetEvent(false);
private static readonly AutoResetEvent Closing = new(false);

public static async Task<int> Main()
{
Expand Down
2 changes: 1 addition & 1 deletion samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This directory contains 3 projects to show a practical example of Orleans runnin

1. Docker
2. Kubernetes
3. .Net Core 3.1 SDK
3. .Net 7 SDK

## Running it

Expand Down
8 changes: 4 additions & 4 deletions src/Orleans.Clustering.Kubernetes/API/CustomObject.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using System.Text.Json.Serialization;
using k8s.Models;
using Newtonsoft.Json;

namespace Orleans.Clustering.Kubernetes.API;

internal abstract class CustomObject
{
[JsonProperty("apiVersion")]
[JsonPropertyName("apiVersion")]
public string ApiVersion { get; set; }

[JsonProperty("kind")]
[JsonPropertyName("kind")]
public string Kind { get; set; }

[JsonProperty("metadata")]
[JsonPropertyName("metadata")]
public V1ObjectMeta Metadata { get; set; }
}
24 changes: 16 additions & 8 deletions src/Orleans.Clustering.Kubernetes/KubeGatewayListProvider.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using k8s;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json.Linq;
using Orleans.Clustering.Kubernetes.Models;
using Orleans.Configuration;
using Orleans.Messaging;
Expand All @@ -11,17 +10,16 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace Orleans.Clustering.Kubernetes;

internal class KubeGatewayListProvider : IGatewayListProvider
{
private readonly ILogger _logger;
private readonly ILoggerFactory _loggerFactory;
private readonly string _clusterId;
private readonly k8s.IKubernetes _kube;
private readonly k8s.Kubernetes _kube;
private readonly KubeGatewayOptions _kubeGatewayOptions;
private string _namespace;

Expand All @@ -33,12 +31,11 @@ public KubeGatewayListProvider(
IOptions<ClusterOptions> clusterOptions,
IOptions<GatewayOptions> gatewayOptions,
IOptions<KubeGatewayOptions> kubeGatewayOptions,
k8s.IKubernetes kubernetesClient
k8s.Kubernetes kubernetesClient
)
{
this._loggerFactory = loggerFactory;
this.MaxStaleness = gatewayOptions.Value.GatewayListRefreshPeriod;
this._logger = loggerFactory?.CreateLogger<KubeGatewayListProvider>();
this._logger = loggerFactory.CreateLogger<KubeGatewayListProvider>();
this._kube = kubernetesClient;
this._clusterId = clusterOptions.Value.ClusterId;
this._kubeGatewayOptions = kubeGatewayOptions.Value;
Expand All @@ -48,7 +45,18 @@ public async Task<IList<Uri>> GetGateways()
{
try
{
var silos = ((JObject)await this._kube.ListNamespacedCustomObjectAsync(Constants.ORLEANS_GROUP, Constants.PROVIDER_MODEL_VERSION, this._namespace, SiloEntity.PLURAL))?["items"]?.ToObject<SiloEntity[]>();
var silosContainer = (JsonElement) await this._kube.ListNamespacedCustomObjectAsync(
Constants.ORLEANS_GROUP,
Constants.PROVIDER_MODEL_VERSION,
this._namespace,
SiloEntity.PLURAL);

if (silosContainer.TryGetProperty("items", out var items) is false)
{
return Array.Empty<Uri>();
}

var silos = items.Deserialize<SiloEntity[]>();
if (silos == null || silos.Length == 0) return Array.Empty<Uri>();

var gateways = silos.Where(s => s.Status == SiloStatus.Active && s.ProxyPort != 0 && s.ClusterId == this._clusterId)
Expand Down
Loading

0 comments on commit ce56475

Please sign in to comment.