Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remove property functions #856

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/ctl/namespace/get_max_consumers_per_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion pkg/ctl/namespace/get_max_consumers_per_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion pkg/ctl/namespace/get_max_producers_per_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion pkg/ctl/namespace/get_message_ttl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
lovrogalesic-toast marked this conversation as resolved.
Show resolved Hide resolved
} else {
vc.Command.Printf("Message TTL for namespace %s is %d\n", ns, ttl)
}
}
return err
}
4 changes: 4 additions & 0 deletions pkg/ctl/namespace/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
74 changes: 74 additions & 0 deletions pkg/ctl/namespace/remove_max_consumers_per_subscription.go
Original file line number Diff line number Diff line change
@@ -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
}
72 changes: 72 additions & 0 deletions pkg/ctl/namespace/remove_max_consumers_per_topic.go
Original file line number Diff line number Diff line change
@@ -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
}
72 changes: 72 additions & 0 deletions pkg/ctl/namespace/remove_max_producers_per_topic.go
Original file line number Diff line number Diff line change
@@ -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
}
81 changes: 81 additions & 0 deletions pkg/ctl/namespace/remove_message_ttl.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion pkg/ctl/namespace/set_message_ttl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading