From 0a4bff8d91aaa20b295026871e96335a839e4376 Mon Sep 17 00:00:00 2001 From: lovrogalesic-toast Date: Wed, 12 Oct 2022 12:14:37 +0100 Subject: [PATCH 1/2] Add remove property functions --- .../get_max_consumers_per_subscription.go | 6 +- .../namespace/get_max_consumers_per_topic.go | 6 +- .../namespace/get_max_producers_per_topic.go | 6 +- pkg/ctl/namespace/get_message_ttl.go | 6 +- pkg/ctl/namespace/namespace.go | 4 + .../remove_max_consumers_per_subscription.go | 74 +++++++++++++++++ .../remove_max_consumers_per_topic.go | 72 +++++++++++++++++ .../remove_max_producers_per_topic.go | 72 +++++++++++++++++ pkg/ctl/namespace/remove_message_ttl.go | 81 +++++++++++++++++++ pkg/ctl/namespace/set_message_ttl.go | 2 +- pkg/pulsar/namespace.go | 45 +++++++++-- 11 files changed, 364 insertions(+), 10 deletions(-) create mode 100644 pkg/ctl/namespace/remove_max_consumers_per_subscription.go create mode 100644 pkg/ctl/namespace/remove_max_consumers_per_topic.go create mode 100644 pkg/ctl/namespace/remove_max_producers_per_topic.go create mode 100644 pkg/ctl/namespace/remove_message_ttl.go diff --git a/pkg/ctl/namespace/get_max_consumers_per_subscription.go b/pkg/ctl/namespace/get_max_consumers_per_subscription.go index 3e446820..eb08b386 100644 --- a/pkg/ctl/namespace/get_max_consumers_per_subscription.go +++ b/pkg/ctl/namespace/get_max_consumers_per_subscription.go @@ -65,7 +65,11 @@ func doGetMaxConsumerPerSubscription(vc *cmdutils.VerbCmd) error { admin := cmdutils.NewPulsarClient() max, err := admin.Namespaces().GetMaxConsumersPerSubscription(*ns) if err == nil { - vc.Command.Printf("The max consumers per subscription of the namespace %s is %d\n", ns.String(), max) + if max < 0 { + vc.Command.Printf("The max consumers per subscription of the namespace %s is not set (%d)\n", ns.String(), max) + } else { + vc.Command.Printf("The max consumers per subscription of the namespace %s is %d\n", ns.String(), max) + } } return err diff --git a/pkg/ctl/namespace/get_max_consumers_per_topic.go b/pkg/ctl/namespace/get_max_consumers_per_topic.go index 82e0616a..e0e0a8c4 100644 --- a/pkg/ctl/namespace/get_max_consumers_per_topic.go +++ b/pkg/ctl/namespace/get_max_consumers_per_topic.go @@ -65,7 +65,11 @@ func doGetMaxConsumerPerTopic(vc *cmdutils.VerbCmd) error { admin := cmdutils.NewPulsarClient() max, err := admin.Namespaces().GetMaxConsumersPerTopic(*ns) if err == nil { - vc.Command.Printf("The max consumers per topic of the namespace %s is %d\n", ns.String(), max) + if max < 0 { + vc.Command.Printf("The max consumers per topic of the namespace %s is not set (%d)\n", ns.String(), max) + } else { + vc.Command.Printf("The max consumers per topic of the namespace %s is %d\n", ns.String(), max) + } } return err diff --git a/pkg/ctl/namespace/get_max_producers_per_topic.go b/pkg/ctl/namespace/get_max_producers_per_topic.go index 7e119689..8d7b3483 100644 --- a/pkg/ctl/namespace/get_max_producers_per_topic.go +++ b/pkg/ctl/namespace/get_max_producers_per_topic.go @@ -65,7 +65,11 @@ func doGetMaxProducersPerTopic(vc *cmdutils.VerbCmd) error { admin := cmdutils.NewPulsarClient() max, err := admin.Namespaces().GetMaxProducersPerTopic(*ns) if err == nil { - vc.Command.Printf("The max producers per topic of the namespace %s is %d\n", ns.String(), max) + if max < 0 { + vc.Command.Printf("The max producers per topic of the namespace %s is not set (%d)\n", ns.String(), max) + } else { + vc.Command.Printf("The max producers per topic of the namespace %s is %d\n", ns.String(), max) + } } return err diff --git a/pkg/ctl/namespace/get_message_ttl.go b/pkg/ctl/namespace/get_message_ttl.go index 8979d9af..b7141390 100644 --- a/pkg/ctl/namespace/get_message_ttl.go +++ b/pkg/ctl/namespace/get_message_ttl.go @@ -76,7 +76,11 @@ func doGetMessageTTL(vc *cmdutils.VerbCmd) error { admin := cmdutils.NewPulsarClient() ttl, err := admin.Namespaces().GetNamespaceMessageTTL(ns) if err == nil { - vc.Command.Print(ttl) + if ttl < 0 { + vc.Command.Printf("Message TTL for namespace %s is not set (%d)\n", ns, ttl) + } else { + vc.Command.Printf("Message TTL for namespace %s is %d\n", ns, ttl) + } } return err } diff --git a/pkg/ctl/namespace/namespace.go b/pkg/ctl/namespace/namespace.go index 3183d629..d8a2e0d1 100644 --- a/pkg/ctl/namespace/namespace.go +++ b/pkg/ctl/namespace/namespace.go @@ -38,6 +38,7 @@ func Command(flagGrouping *cmdutils.FlagGrouping) *cobra.Command { cmdutils.AddVerbCmd(flagGrouping, resourceCmd, deleteNs) cmdutils.AddVerbCmd(flagGrouping, resourceCmd, setMessageTTL) cmdutils.AddVerbCmd(flagGrouping, resourceCmd, getMessageTTL) + cmdutils.AddVerbCmd(flagGrouping, resourceCmd, RemoveMessageTTL) cmdutils.AddVerbCmd(flagGrouping, resourceCmd, getRetention) cmdutils.AddVerbCmd(flagGrouping, resourceCmd, setRetention) cmdutils.AddVerbCmd(flagGrouping, resourceCmd, getBacklogQuota) @@ -57,10 +58,13 @@ func Command(flagGrouping *cmdutils.FlagGrouping) *cobra.Command { cmdutils.AddVerbCmd(flagGrouping, resourceCmd, SetCompactionThresholdCmd) cmdutils.AddVerbCmd(flagGrouping, resourceCmd, GetCompactionThresholdCmd) cmdutils.AddVerbCmd(flagGrouping, resourceCmd, SetMaxConsumersPerSubscriptionCmd) + cmdutils.AddVerbCmd(flagGrouping, resourceCmd, RemoveMaxConsumersPerSubscriptionCmd) cmdutils.AddVerbCmd(flagGrouping, resourceCmd, GetMaxConsumersPerSubscriptionCmd) cmdutils.AddVerbCmd(flagGrouping, resourceCmd, SetMaxConsumersPerTopicCmd) + cmdutils.AddVerbCmd(flagGrouping, resourceCmd, RemoveMaxConsumersPerTopicCmd) cmdutils.AddVerbCmd(flagGrouping, resourceCmd, GetMaxConsumersPerTopicCmd) cmdutils.AddVerbCmd(flagGrouping, resourceCmd, SetMaxProducersPerTopicCmd) + cmdutils.AddVerbCmd(flagGrouping, resourceCmd, RemoveMaxProducersPerTopicCmd) cmdutils.AddVerbCmd(flagGrouping, resourceCmd, GetMaxProducersPerTopicCmd) cmdutils.AddVerbCmd(flagGrouping, resourceCmd, getAntiAffinityGroup) cmdutils.AddVerbCmd(flagGrouping, resourceCmd, setAntiAffinityGroup) diff --git a/pkg/ctl/namespace/remove_max_consumers_per_subscription.go b/pkg/ctl/namespace/remove_max_consumers_per_subscription.go new file mode 100644 index 00000000..607c000e --- /dev/null +++ b/pkg/ctl/namespace/remove_max_consumers_per_subscription.go @@ -0,0 +1,74 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package namespace + +import ( + "github.com/streamnative/pulsarctl/pkg/cmdutils" + + "github.com/streamnative/pulsarctl/pkg/pulsar/utils" +) + +func RemoveMaxConsumersPerSubscriptionCmd(vc *cmdutils.VerbCmd) { + var desc cmdutils.LongDescription + desc.CommandUsedFor = "This command is used to remove the max consumers per subscription setting of a namespace." + desc.CommandPermission = "This command requires super-user permissions and broker has write policies permission." + + var examples []cmdutils.Example + set := cmdutils.Example{ + Desc: "Remove the max consumers per subscription setting for the namespace (namespace-name)", + Command: "pulsarctl namespaces remove-max-consumers-per-subscription (namespace-name)", + } + examples = append(examples, set) + desc.CommandExamples = examples + + var out []cmdutils.Output + successOut := cmdutils.Output{ + Desc: "normal output", + Out: "Successfully removed the max consumers per subscription setting for namespace (namespace-name)", + } + out = append(out, successOut, ArgError, NsNotExistError) + out = append(out, NsErrors...) + desc.CommandOutput = out + + vc.SetDescription( + "remove-max-consumers-per-subscription", + "Remove the max consumers per subscription setting for a namespace", + desc.ToString(), + desc.ExampleToString(), + ) + + vc.SetRunFuncWithNameArg(func() error { + return doRemoveMaxConsumersPerSubscription(vc) + }, "the namespace name is not specified or the namespace name is specified more than one") +} + +func doRemoveMaxConsumersPerSubscription(vc *cmdutils.VerbCmd) error { + ns, err := utils.GetNamespaceName(vc.NameArg) + if err != nil { + return err + } + + admin := cmdutils.NewPulsarClient() + err = admin.Namespaces().RemoveMaxConsumersPerSubscription(*ns) + if err == nil { + vc.Command.Printf("Successfully removed the max consumers per subscription setting for namespace %s\n", + ns.String()) + } + + return err +} diff --git a/pkg/ctl/namespace/remove_max_consumers_per_topic.go b/pkg/ctl/namespace/remove_max_consumers_per_topic.go new file mode 100644 index 00000000..dfbdaadb --- /dev/null +++ b/pkg/ctl/namespace/remove_max_consumers_per_topic.go @@ -0,0 +1,72 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package namespace + +import ( + "github.com/streamnative/pulsarctl/pkg/cmdutils" + + "github.com/streamnative/pulsarctl/pkg/pulsar/utils" +) + +func RemoveMaxConsumersPerTopicCmd(vc *cmdutils.VerbCmd) { + var desc cmdutils.LongDescription + desc.CommandUsedFor = "This command is used to remove the max consumers per topic setting for a namespace." + desc.CommandPermission = "This command requires super-user permissions and broker has write policies permission." + + var examples []cmdutils.Example + set := cmdutils.Example{ + Desc: "Remove the max consumers per topic setting for namespace (namespace-name)", + Command: "pulsarctl namespaces remove-max-consumers-per-topic (namespace-name)", + } + examples = append(examples, set) + desc.CommandExamples = examples + + var out []cmdutils.Output + successOut := cmdutils.Output{ + Desc: "normal output", + Out: "Successfully removed the max consumers per topic setting for namespace (namespace-name)", + } + out = append(out, successOut, ArgError, NsNotExistError) + out = append(out, NsErrors...) + desc.CommandOutput = out + + vc.SetDescription( + "remove-max-consumers-per-topic", + "Remove the max consumers per topic setting for a namespace", + desc.ToString(), + desc.ExampleToString()) + + vc.SetRunFuncWithNameArg(func() error { + return doRemoveMaxConsumersPerTopic(vc) + }, "the namespace name is not specified or the namespace name is specified more than one") +} + +func doRemoveMaxConsumersPerTopic(vc *cmdutils.VerbCmd) error { + ns, err := utils.GetNamespaceName(vc.NameArg) + if err != nil { + return err + } + admin := cmdutils.NewPulsarClient() + err = admin.Namespaces().RemoveMaxConsumersPerTopic(*ns) + if err == nil { + vc.Command.Printf("Successfully removed the max consumers per topic setting for namespace %s\n", + ns.String()) + } + + return err +} diff --git a/pkg/ctl/namespace/remove_max_producers_per_topic.go b/pkg/ctl/namespace/remove_max_producers_per_topic.go new file mode 100644 index 00000000..9fa9689f --- /dev/null +++ b/pkg/ctl/namespace/remove_max_producers_per_topic.go @@ -0,0 +1,72 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package namespace + +import ( + "github.com/streamnative/pulsarctl/pkg/cmdutils" + + "github.com/streamnative/pulsarctl/pkg/pulsar/utils" +) + +func RemoveMaxProducersPerTopicCmd(vc *cmdutils.VerbCmd) { + var desc cmdutils.LongDescription + desc.CommandUsedFor = "This command is used to remove the max producers per topic for a namespace." + desc.CommandPermission = "This command requires super-user permissions and broker has write policies permission." + + var examples []cmdutils.Example + set := cmdutils.Example{ + Desc: "Removes the max producers per topic setting for namespace (namespace-name)", + Command: "pulsarctl namespaces remove-max-producers-per-topic (namespace-name)", + } + examples = append(examples, set) + desc.CommandExamples = examples + + var out []cmdutils.Output + successOut := cmdutils.Output{ + Desc: "normal output", + Out: "Successfully removed the max producers per topic for namespace (namespace-name)", + } + out = append(out, successOut, ArgError, NsNotExistError) + out = append(out, NsErrors...) + desc.CommandOutput = out + + vc.SetDescription( + "remove-max-producers-per-topic", + "Remove the max producers per topic setting for a namespace", + desc.ToString(), + desc.ExampleToString()) + + vc.SetRunFuncWithNameArg(func() error { + return doRemoveMaxProducersPerTopic(vc) + }, "the namespace name is not specified or the namespace name is specified more than one") +} + +func doRemoveMaxProducersPerTopic(vc *cmdutils.VerbCmd) error { + ns, err := utils.GetNamespaceName(vc.NameArg) + if err != nil { + return err + } + + admin := cmdutils.NewPulsarClient() + err = admin.Namespaces().RemoveMaxProducersPerTopic(*ns) + if err == nil { + vc.Command.Printf("Successfully removed the max producers per topic for namespace %s\n", ns.String()) + } + + return err +} diff --git a/pkg/ctl/namespace/remove_message_ttl.go b/pkg/ctl/namespace/remove_message_ttl.go new file mode 100644 index 00000000..ca46dbf7 --- /dev/null +++ b/pkg/ctl/namespace/remove_message_ttl.go @@ -0,0 +1,81 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package namespace + +import ( + "github.com/streamnative/pulsarctl/pkg/cmdutils" +) + +func RemoveMessageTTL(vc *cmdutils.VerbCmd) { + desc := cmdutils.LongDescription{} + desc.CommandUsedFor = "Remove Message TTL setting for a namespace" + desc.CommandPermission = "This command requires tenant admin permissions." + + var examples []cmdutils.Example + deleteMsgTTL := cmdutils.Example{ + Desc: "Remove Message TTL setting for a namespace", + Command: "pulsarctl namespaces remove-message-ttl tenant/namespace", + } + examples = append(examples, deleteMsgTTL) + desc.CommandExamples = examples + + var out []cmdutils.Output + successOut := cmdutils.Output{ + Desc: "normal output", + Out: "Successfully removed message TTL for [tenant/namespace]", + } + + noNamespaceName := cmdutils.Output{ + Desc: "you must specify a tenant/namespace name, please check if the tenant/namespace name is provided", + Out: "[✖] the namespace name is not specified or the namespace name is specified more than one", + } + + tenantNotExistError := cmdutils.Output{ + Desc: "the tenant does not exist", + Out: "[✖] code: 404 reason: Tenant does not exist", + } + + nsNotExistError := cmdutils.Output{ + Desc: "the namespace does not exist", + Out: "[✖] code: 404 reason: Namespace (tenant/namespace) does not exist", + } + + out = append(out, successOut, noNamespaceName, tenantNotExistError, nsNotExistError) + desc.CommandOutput = out + + vc.SetDescription( + "remove-message-ttl", + "Removes Message TTL for a namespace", + desc.ToString(), + desc.ExampleToString(), + ) + + vc.SetRunFuncWithNameArg(func() error { + return doDeleteMessageTTL(vc) + }, "the namespace name is not specified or the namespace name is specified more than one") +} + +func doDeleteMessageTTL(vc *cmdutils.VerbCmd) error { + ns := vc.NameArg + admin := cmdutils.NewPulsarClient() + err := admin.Namespaces().RemoveNamespaceMessageTTL(ns) + if err == nil { + vc.Command.Printf("Successfully removed Message TTL setting for namespace %s\n", ns) + } + return err +} diff --git a/pkg/ctl/namespace/set_message_ttl.go b/pkg/ctl/namespace/set_message_ttl.go index b666ef05..77f163db 100644 --- a/pkg/ctl/namespace/set_message_ttl.go +++ b/pkg/ctl/namespace/set_message_ttl.go @@ -98,7 +98,7 @@ func doSetMessageTTL(vc *cmdutils.VerbCmd, data utils.NamespacesData) error { admin := cmdutils.NewPulsarClient() err := admin.Namespaces().SetNamespaceMessageTTL(ns, data.MessageTTL) if err == nil { - vc.Command.Printf("Set message TTL successfully for [%s]\n", ns) + vc.Command.Printf("Message TTL for namespace %s successfully set to %d\n", ns, data.MessageTTL) } return err } diff --git a/pkg/pulsar/namespace.go b/pkg/pulsar/namespace.go index f7b2fb10..8aabb202 100644 --- a/pkg/pulsar/namespace.go +++ b/pkg/pulsar/namespace.go @@ -61,6 +61,9 @@ type Namespaces interface { // GetNamespaceMessageTTL returns the message TTL for a namespace GetNamespaceMessageTTL(namespace string) (int, error) + // RemoveNamespaceMessageTTL removes the message TTL config for a namespace, defaulting to broker settings + RemoveNamespaceMessageTTL(namespace string) error + // GetRetention returns the retention configuration for a namespace GetRetention(namespace string) (*utils.RetentionPolicies, error) @@ -124,18 +127,27 @@ type Namespaces interface { // GetMaxConsumersPerSubscription returns the maxConsumersPerSubscription for a namespace. GetMaxConsumersPerSubscription(namespace utils.NameSpaceName) (int, error) + // RemoveMaxConsumersPerSubscription removes the maxConsumersPerSubscription config for a namespace, defaulting to broker settings. + RemoveMaxConsumersPerSubscription(namespace utils.NameSpaceName) error + // SetMaxConsumersPerTopic sets maxConsumersPerTopic for a namespace. SetMaxConsumersPerTopic(namespace utils.NameSpaceName, max int) error // GetMaxConsumersPerTopic returns the maxProducersPerTopic for a namespace. GetMaxConsumersPerTopic(namespace utils.NameSpaceName) (int, error) + // RemoveMaxConsumersPerTopic removes the maxProducersPerTopic config for a namespace, defaulting to broker settings. + RemoveMaxConsumersPerTopic(namespace utils.NameSpaceName) error + // SetMaxProducersPerTopic sets maxProducersPerTopic for a namespace. SetMaxProducersPerTopic(namespace utils.NameSpaceName, max int) error // GetMaxProducersPerTopic returns the maxProducersPerTopic for a namespace. GetMaxProducersPerTopic(namespace utils.NameSpaceName) (int, error) + // RemoveMaxProducersPerTopic removes the maxProducersPerTopic config for a namespace, defaulting to broker settings. + RemoveMaxProducersPerTopic(namespace utils.NameSpaceName) error + // GetNamespaceReplicationClusters returns the replication clusters for a namespace GetNamespaceReplicationClusters(namespace string) ([]string, error) @@ -362,7 +374,7 @@ func (n *namespaces) DeleteNamespaceBundle(namespace string, bundleRange string) } func (n *namespaces) GetNamespaceMessageTTL(namespace string) (int, error) { - var ttl int + ttl := -1 nsName, err := utils.GetNamespaceName(namespace) if err != nil { return 0, err @@ -377,11 +389,19 @@ func (n *namespaces) SetNamespaceMessageTTL(namespace string, ttlInSeconds int) if err != nil { return err } - endpoint := n.pulsar.endpoint(n.basePath, nsName.String(), "messageTTL") return n.pulsar.Client.Post(endpoint, &ttlInSeconds) } +func (n *namespaces) RemoveNamespaceMessageTTL(namespace string) error { + nsName, err := utils.GetNamespaceName(namespace) + if err != nil { + return err + } + endpoint := n.pulsar.endpoint(n.basePath, nsName.String(), "messageTTL") + return n.pulsar.Client.Delete(endpoint) +} + func (n *namespaces) SetRetention(namespace string, policy utils.RetentionPolicies) error { nsName, err := utils.GetNamespaceName(namespace) if err != nil { @@ -502,12 +522,17 @@ func (n *namespaces) SetMaxConsumersPerSubscription(namespace utils.NameSpaceNam } func (n *namespaces) GetMaxConsumersPerSubscription(namespace utils.NameSpaceName) (int, error) { - var result int + result := -1 endpoint := n.pulsar.endpoint(n.basePath, namespace.String(), "maxConsumersPerSubscription") err := n.pulsar.Client.Get(endpoint, &result) return result, err } +func (n *namespaces) RemoveMaxConsumersPerSubscription(namespace utils.NameSpaceName) error { + endpoint := n.pulsar.endpoint(n.basePath, namespace.String(), "maxConsumersPerSubscription") + return n.pulsar.Client.Delete(endpoint) +} + func (n *namespaces) SetOffloadThreshold(namespace utils.NameSpaceName, threshold int64) error { endpoint := n.pulsar.endpoint(n.basePath, namespace.String(), "offloadThreshold") return n.pulsar.Client.Put(endpoint, threshold) @@ -526,12 +551,17 @@ func (n *namespaces) SetMaxConsumersPerTopic(namespace utils.NameSpaceName, max } func (n *namespaces) GetMaxConsumersPerTopic(namespace utils.NameSpaceName) (int, error) { - var result int + result := -1 endpoint := n.pulsar.endpoint(n.basePath, namespace.String(), "maxConsumersPerTopic") err := n.pulsar.Client.Get(endpoint, &result) return result, err } +func (n *namespaces) RemoveMaxConsumersPerTopic(namespace utils.NameSpaceName) error { + endpoint := n.pulsar.endpoint(n.basePath, namespace.String(), "maxConsumersPerTopic") + return n.pulsar.Client.Delete(endpoint) +} + func (n *namespaces) SetCompactionThreshold(namespace utils.NameSpaceName, threshold int64) error { endpoint := n.pulsar.endpoint(n.basePath, namespace.String(), "compactionThreshold") return n.pulsar.Client.Put(endpoint, threshold) @@ -550,12 +580,17 @@ func (n *namespaces) SetMaxProducersPerTopic(namespace utils.NameSpaceName, max } func (n *namespaces) GetMaxProducersPerTopic(namespace utils.NameSpaceName) (int, error) { - var result int + result := -1 endpoint := n.pulsar.endpoint(n.basePath, namespace.String(), "maxProducersPerTopic") err := n.pulsar.Client.Get(endpoint, &result) return result, err } +func (n *namespaces) RemoveMaxProducersPerTopic(namespace utils.NameSpaceName) error { + endpoint := n.pulsar.endpoint(n.basePath, namespace.String(), "maxProducersPerTopic") + return n.pulsar.Client.Delete(endpoint) +} + func (n *namespaces) GetNamespaceReplicationClusters(namespace string) ([]string, error) { var data []string nsName, err := utils.GetNamespaceName(namespace) From 6d63a903487db4d7da6616adcb069b9cbeb12ece Mon Sep 17 00:00:00 2001 From: Lovro <91057218+lovrogalesic-toast@users.noreply.github.com> Date: Tue, 18 Oct 2022 19:37:56 +0100 Subject: [PATCH 2/2] Update pkg/ctl/namespace/get_message_ttl.go Co-authored-by: Zixuan Liu --- pkg/ctl/namespace/get_message_ttl.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/ctl/namespace/get_message_ttl.go b/pkg/ctl/namespace/get_message_ttl.go index b7141390..9c28dece 100644 --- a/pkg/ctl/namespace/get_message_ttl.go +++ b/pkg/ctl/namespace/get_message_ttl.go @@ -77,7 +77,7 @@ func doGetMessageTTL(vc *cmdutils.VerbCmd) error { ttl, err := admin.Namespaces().GetNamespaceMessageTTL(ns) if err == nil { if ttl < 0 { - vc.Command.Printf("Message TTL for namespace %s is not set (%d)\n", ns, ttl) + vc.Command.Printf("Message TTL for namespace %s is not set (%d)\n", ns, ttl) } else { vc.Command.Printf("Message TTL for namespace %s is %d\n", ns, ttl) }