From 257d6ebac119269387f31cd5d33b2b294da40712 Mon Sep 17 00:00:00 2001 From: Alex Wichmann Date: Thu, 24 Nov 2022 11:44:31 +0100 Subject: [PATCH] Remove pulsar binding --- .../AsyncApiChannelBindingDeserializer.cs | 2 - .../AsyncApiServerBindingDeserializer.cs | 2 - .../AsyncApiPulsarBindingsDeserializer.cs | 40 --------- .../Models/Bindings/BindingType.cs | 3 - .../Bindings/Pulsar/PulsarChannelBinding.cs | 90 ------------------- .../Bindings/Pulsar/PulsarServerBinding.cs | 66 -------------- .../Bindings/Pulsar/RetentionDefinition.cs | 28 ------ .../AsyncApiDocumentTests.cs | 36 +------- 8 files changed, 2 insertions(+), 265 deletions(-) delete mode 100644 src/LEGO.AsyncAPI.Readers/Bindings/AsyncApiPulsarBindingsDeserializer.cs delete mode 100644 src/LEGO.AsyncAPI/Models/Bindings/Pulsar/PulsarChannelBinding.cs delete mode 100644 src/LEGO.AsyncAPI/Models/Bindings/Pulsar/PulsarServerBinding.cs delete mode 100644 src/LEGO.AsyncAPI/Models/Bindings/Pulsar/RetentionDefinition.cs diff --git a/src/LEGO.AsyncAPI.Readers/AsyncApiChannelBindingDeserializer.cs b/src/LEGO.AsyncAPI.Readers/AsyncApiChannelBindingDeserializer.cs index 1f6964b3..3a60c3c4 100644 --- a/src/LEGO.AsyncAPI.Readers/AsyncApiChannelBindingDeserializer.cs +++ b/src/LEGO.AsyncAPI.Readers/AsyncApiChannelBindingDeserializer.cs @@ -42,8 +42,6 @@ internal static IChannelBinding LoadChannelBinding(ParseNode node) { case BindingType.Kafka: return LoadBinding("ChannelBinding", property.Value, kafkaChannelBindingFixedFields); - case BindingType.Pulsar: - return LoadBinding("ChannelBinding", property.Value, pulsarChannelBindingFixedFields); default: throw new System.Exception("ChannelBinding not found"); } diff --git a/src/LEGO.AsyncAPI.Readers/AsyncApiServerBindingDeserializer.cs b/src/LEGO.AsyncAPI.Readers/AsyncApiServerBindingDeserializer.cs index 5e5ed417..27ed6f76 100644 --- a/src/LEGO.AsyncAPI.Readers/AsyncApiServerBindingDeserializer.cs +++ b/src/LEGO.AsyncAPI.Readers/AsyncApiServerBindingDeserializer.cs @@ -42,8 +42,6 @@ internal static IServerBinding LoadServerBinding(ParseNode node) { case BindingType.Kafka: return LoadBinding("ServerBinding", property.Value, kafkaServerBindingFixedFields); - case BindingType.Pulsar: - return LoadBinding("ServerBinding", property.Value, pulsarServerBindingFixedFields); default: throw new System.Exception("ServerBinding not found"); } diff --git a/src/LEGO.AsyncAPI.Readers/Bindings/AsyncApiPulsarBindingsDeserializer.cs b/src/LEGO.AsyncAPI.Readers/Bindings/AsyncApiPulsarBindingsDeserializer.cs deleted file mode 100644 index f31c3ef0..00000000 --- a/src/LEGO.AsyncAPI.Readers/Bindings/AsyncApiPulsarBindingsDeserializer.cs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) The LEGO Group. All rights reserved. - -namespace LEGO.AsyncAPI.Readers -{ - using LEGO.AsyncAPI.Models.Bindings.Pulsar; - using LEGO.AsyncAPI.Readers.ParseNodes; - - internal static partial class AsyncApiDeserializer - { - private static FixedFieldMap pulsarServerBindingFixedFields = new() - { - { "bindingVersion", (a, n) => { a.BindingVersion = n.GetScalarValue(); } }, - { "tenant", (a, n) => { a.Tenant = n.GetScalarValue(); } }, - }; - - private static FixedFieldMap pulsarChannelBindingFixedFields = new() - { - { "bindingVersion", (a, n) => { a.BindingVersion = n.GetScalarValue(); } }, - { "namespace", (a, n) => { a.Namespace = n.GetScalarValue(); } }, - { "persistence", (a, n) => { a.Persistence = n.GetScalarValue(); } }, - { "compaction", (a, n) => { a.Compaction = n.GetLongValue(); } }, - { "retention", (a, n) => { a.Retention = LoadRetention(n); } }, - { "deduplication", (a, n) => { a.Deduplication = n.GetBooleanValue(); } }, - }; - - private static FixedFieldMap pulsarServerBindingRetentionFixedFields = new() - { - { "time", (a, n) => { a.Time = n.GetIntegerValue(); } }, - { "size", (a, n) => { a.Size = n.GetIntegerValue(); } }, - }; - - private static RetentionDefinition LoadRetention(ParseNode node) - { - var mapNode = node.CheckMapNode("retention"); - var retention = new RetentionDefinition(); - ParseMap(mapNode, retention, pulsarServerBindingRetentionFixedFields, null); - return retention; - } - } -} diff --git a/src/LEGO.AsyncAPI/Models/Bindings/BindingType.cs b/src/LEGO.AsyncAPI/Models/Bindings/BindingType.cs index a3b80e7d..7076c3dc 100644 --- a/src/LEGO.AsyncAPI/Models/Bindings/BindingType.cs +++ b/src/LEGO.AsyncAPI/Models/Bindings/BindingType.cs @@ -11,8 +11,5 @@ public enum BindingType [Display("http")] Http, - - [Display("pulsar")] - Pulsar, } } diff --git a/src/LEGO.AsyncAPI/Models/Bindings/Pulsar/PulsarChannelBinding.cs b/src/LEGO.AsyncAPI/Models/Bindings/Pulsar/PulsarChannelBinding.cs deleted file mode 100644 index c799a845..00000000 --- a/src/LEGO.AsyncAPI/Models/Bindings/Pulsar/PulsarChannelBinding.cs +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (c) The LEGO Group. All rights reserved. - -namespace LEGO.AsyncAPI.Models.Bindings.Pulsar -{ - using System; - using System.Collections.Generic; - using System.Diagnostics.Contracts; - using LEGO.AsyncAPI.Models.Interfaces; - using LEGO.AsyncAPI.Writers; - - /// - /// Binding class for Pulsar server settings. - /// - public class PulsarChannelBinding : IChannelBinding - { - /// - /// The namespace associated with the topic. - /// - public string Namespace { get; set; } - - /// - /// persistence of the topic in Pulsar persistent or non-persistent. - /// - public string Persistence { get; set; } - - /// - /// Topic compaction threshold given in bytes. - /// - public long Compaction { get; set; } - - /// - /// Topic retention policy. - /// - public RetentionDefinition Retention { get; set; } - - /// - /// When Message deduplication is enabled, it ensures that each message produced on Pulsar topics is persisted to disk only once. - /// - public bool Deduplication { get; set; } - - /// - /// The version of this binding. - public string BindingVersion { get; set; } - - public BindingType Type => BindingType.Pulsar; - - public bool UnresolvedReference { get; set; } - - public AsyncApiReference Reference { get; set; } - - public IDictionary Extensions { get; set; } = new Dictionary(); - - /// - /// Serialize to AsyncAPI V2 document without using reference. - /// - public void SerializeV2WithoutReference(IAsyncApiWriter writer) - { - if (writer is null) - { - throw new ArgumentNullException(nameof(writer)); - } - - writer.WriteStartObject(); - writer.WriteOptionalProperty(AsyncApiConstants.Namespace, this.Namespace); - writer.WriteOptionalProperty(AsyncApiConstants.Persistence, this.Persistence); - writer.WriteProperty(AsyncApiConstants.Compaction, this.Compaction); - writer.WriteOptionalObject(AsyncApiConstants.Retention, this.Retention, (w, r) => r.Serialize(w)); - writer.WriteProperty(AsyncApiConstants.Deduplication, this.Deduplication); - writer.WriteOptionalProperty(AsyncApiConstants.BindingVersion, this.BindingVersion); - - writer.WriteEndObject(); - } - - public void SerializeV2(IAsyncApiWriter writer) - { - if (writer is null) - { - throw new ArgumentNullException(nameof(writer)); - } - - if (this.Reference != null && writer.GetSettings().ReferenceInline != ReferenceInlineSetting.InlineReferences) - { - this.Reference.SerializeV2(writer); - return; - } - - this.SerializeV2WithoutReference(writer); - } - } -} diff --git a/src/LEGO.AsyncAPI/Models/Bindings/Pulsar/PulsarServerBinding.cs b/src/LEGO.AsyncAPI/Models/Bindings/Pulsar/PulsarServerBinding.cs deleted file mode 100644 index 3ccc7e17..00000000 --- a/src/LEGO.AsyncAPI/Models/Bindings/Pulsar/PulsarServerBinding.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) The LEGO Group. All rights reserved. - -namespace LEGO.AsyncAPI.Models.Bindings.Pulsar -{ - using System; - using System.Collections.Generic; - using LEGO.AsyncAPI.Models.Interfaces; - using LEGO.AsyncAPI.Writers; - - /// - /// Binding class for Pulsar server settings. - /// - public class PulsarServerBinding : IServerBinding - { - /// - /// The tenant. - /// - public string Tenant { get; set; } - - /// - /// The version of this binding. - public string BindingVersion { get; set; } - - public BindingType Type => BindingType.Pulsar; - - public bool UnresolvedReference { get; set; } - - public AsyncApiReference Reference { get; set; } - - public IDictionary Extensions { get; set; } = new Dictionary(); - - /// - /// Serialize to AsyncAPI V2 document without using reference. - /// - public void SerializeV2WithoutReference(IAsyncApiWriter writer) - { - if (writer is null) - { - throw new ArgumentNullException(nameof(writer)); - } - - writer.WriteStartObject(); - - writer.WriteOptionalProperty(AsyncApiConstants.Tenant, this.Tenant); - writer.WriteOptionalProperty(AsyncApiConstants.BindingVersion, this.BindingVersion); - - writer.WriteEndObject(); - } - - public void SerializeV2(IAsyncApiWriter writer) - { - if (writer is null) - { - throw new ArgumentNullException(nameof(writer)); - } - - if (this.Reference != null && writer.GetSettings().ReferenceInline != ReferenceInlineSetting.InlineReferences) - { - this.Reference.SerializeV2(writer); - return; - } - - this.SerializeV2WithoutReference(writer); - } - } -} diff --git a/src/LEGO.AsyncAPI/Models/Bindings/Pulsar/RetentionDefinition.cs b/src/LEGO.AsyncAPI/Models/Bindings/Pulsar/RetentionDefinition.cs deleted file mode 100644 index 39bcabbd..00000000 --- a/src/LEGO.AsyncAPI/Models/Bindings/Pulsar/RetentionDefinition.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) The LEGO Group. All rights reserved. - -namespace LEGO.AsyncAPI.Models.Bindings.Pulsar -{ - using LEGO.AsyncAPI.Models.Interfaces; - using LEGO.AsyncAPI.Writers; - - public class RetentionDefinition : IAsyncApiElement - { - /// - /// Time given in Minutes. 0 = Disable message retention (by default). - /// - public int Time { get; set; } - - /// - /// Size given in MegaBytes. 0 = Disable message retention (by default). - /// - public int Size { get; set; } - - public void Serialize(IAsyncApiWriter writer) - { - writer.WriteStartObject(); - writer.WriteProperty(AsyncApiConstants.Time, this.Time); - writer.WriteProperty(AsyncApiConstants.Size, this.Size); - writer.WriteEndObject(); - } - } -} diff --git a/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentTests.cs b/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentTests.cs index 934ac8e9..41b156d9 100644 --- a/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentTests.cs +++ b/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentTests.cs @@ -10,7 +10,6 @@ using LEGO.AsyncAPI.Models.Bindings; using LEGO.AsyncAPI.Models.Bindings.Http; using LEGO.AsyncAPI.Models.Bindings.Kafka; - using LEGO.AsyncAPI.Models.Bindings.Pulsar; using LEGO.AsyncAPI.Models.Interfaces; using LEGO.AsyncAPI.Readers; using LEGO.AsyncAPI.Writers; @@ -463,9 +462,6 @@ public void Serialize_WithBindings_Serializes() url: example.com protocol: pulsar+ssl description: test description - bindings: - pulsar: - tenant: contoso channels: testChannel: publish: @@ -480,14 +476,8 @@ public void Serialize_WithBindings_Serializes() bindings: kafka: partitions: 2 - replicas: 1 - pulsar: - persistence: persistent - compaction: 9223372036854775807 - retention: - time: 4 - size: 1 - deduplication: true"; + replicas: 1"; + var doc = new AsyncApiDocument(); doc.Info = new AsyncApiInfo() { @@ -498,15 +488,6 @@ public void Serialize_WithBindings_Serializes() Description = "test description", Protocol = "pulsar+ssl", Url = "example.com", - Bindings = new AsyncApiBindings - { - { - new PulsarServerBinding - { - Tenant = "contoso", - } - }, - } }); doc.Channels.Add("testChannel", new AsyncApiChannel @@ -520,19 +501,6 @@ public void Serialize_WithBindings_Serializes() Replicas = 1, } }, - { - new PulsarChannelBinding - { - Compaction = long.MaxValue, - Deduplication = true, - Persistence = "persistent", - Retention = new RetentionDefinition() - { - Time = 4, - Size = 1, - }, - } - }, }, Publish = new AsyncApiOperation {