Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
83 changes: 83 additions & 0 deletions pkg/ctl/topic/get_subscription_dispatch_rate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// 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 topic

import (
"github.com/apache/pulsar-client-go/pulsaradmin/pkg/utils"

"github.com/streamnative/pulsarctl/pkg/cmdutils"
)

func GetSubscriptionDispatchRateCmd(vc *cmdutils.VerbCmd) {
desc := cmdutils.LongDescription{}
desc.CommandUsedFor = "Get subscription message dispatch rate for a topic"
desc.CommandPermission = "This command requires tenant admin permissions."

var examples []cmdutils.Example
msg := cmdutils.Example{
Desc: "Get subscription message dispatch rate for a topic",
Command: "pulsarctl topics get-subscription-dispatch-rate topic",
}
examples = append(examples, msg)
desc.CommandExamples = examples

var out []cmdutils.Output
successOut := cmdutils.Output{
Desc: "normal output",
Out: "Get subscription message dispatch rate successfully for [topic]",
}
out = append(out, successOut, ArgError)
out = append(out, TopicNameErrors...)
out = append(out, TopicLevelPolicyNotEnabledError)
out = append(out, NamespaceErrors...)
desc.CommandOutput = out

vc.SetDescription(
"get-subscription-dispatch-rate",
"Get subscription message dispatch rate for a topic",
desc.ToString(),
desc.ExampleToString(),
"get-subscription-dispatch-rate",
)

vc.SetRunFuncWithNameArg(func() error {
return doGetSubscriptionDispatchRate(vc)
}, "the topic name is not specified or the topic name is specified more than one")

vc.EnableOutputFlagSet()
}

func doGetSubscriptionDispatchRate(vc *cmdutils.VerbCmd) error {
// for testing
if vc.NameError != nil {
return vc.NameError
}

topic, err := utils.GetTopicName(vc.NameArg)
if err != nil {
return err
}

admin := cmdutils.NewPulsarClient()
dispatchRateData, err := admin.Topics().GetSubscriptionDispatchRate(*topic)
if err == nil {
oc := cmdutils.NewOutputContent().WithObject(dispatchRateData)
err = vc.OutputConfig.WriteOutput(vc.Command.OutOrStdout(), oc)
}
return err
}
80 changes: 80 additions & 0 deletions pkg/ctl/topic/remove_subscription_dispatch_rate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// 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 topic

import (
"github.com/apache/pulsar-client-go/pulsaradmin/pkg/utils"

"github.com/streamnative/pulsarctl/pkg/cmdutils"
)

func RemoveSubscriptionDispatchRateCmd(vc *cmdutils.VerbCmd) {
desc := cmdutils.LongDescription{}
desc.CommandUsedFor = "Remove subscription message dispatch rate for a topic"
desc.CommandPermission = "This command requires tenant admin permissions."

var examples []cmdutils.Example
msg := cmdutils.Example{
Desc: "Remove subscription message dispatch rate for a topic",
Command: "pulsarctl topics remove-subscription-dispatch-rate topic",
}
examples = append(examples, msg)
desc.CommandExamples = examples

var out []cmdutils.Output
successOut := cmdutils.Output{
Desc: "normal output",
Out: "Remove subscription message dispatch rate successfully for [topic]",
}
out = append(out, successOut, ArgError)
out = append(out, TopicNameErrors...)
out = append(out, TopicLevelPolicyNotEnabledError)
out = append(out, NamespaceErrors...)
desc.CommandOutput = out

vc.SetDescription(
"remove-subscription-dispatch-rate",
"Remove subscription message dispatch rate for a topic",
desc.ToString(),
desc.ExampleToString(),
"remove-subscription-dispatch-rate",
)

vc.SetRunFuncWithNameArg(func() error {
return doRemoveSubscriptionDispatchRate(vc)
}, "the topic name is not specified or the topic name is specified more than one")
}

func doRemoveSubscriptionDispatchRate(vc *cmdutils.VerbCmd) error {
// for testing
if vc.NameError != nil {
return vc.NameError
}

topic, err := utils.GetTopicName(vc.NameArg)
if err != nil {
return err
}

admin := cmdutils.NewPulsarClient()
err = admin.Topics().RemoveSubscriptionDispatchRate(*topic)
if err == nil {
vc.Command.Printf("Remove subscription message dispatch rate successfully for [%s]\n", topic.String())
}
return err
}
6 changes: 3 additions & 3 deletions pkg/ctl/topic/set_dispatch_rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ func SetDispatchRateCmd(vc *cmdutils.VerbCmd) {
"msg-dispatch-rate",
"",
-1,
"message-dispatch-rate (default -1 will be overwrite if not passed)")
"message-dispatch-rate (defaults to -1 and overwrites the existing value when omitted)")
set.Int64VarP(
&dispatchRateData.DispatchThrottlingRateInByte,
"byte-dispatch-rate",
"",
-1,
"byte-dispatch-rate (default -1 will be overwrite if not passed)")
"byte-dispatch-rate (defaults to -1 and overwrites the existing value when omitted)")
set.Int64VarP(
&dispatchRateData.RatePeriodInSecond,
"dispatch-rate-period",
"",
1,
"dispatch-rate-period in second type (default 1 second will be overwrite if not passed)")
"dispatch-rate-period in second type (defaults to 1 second and overwrites the existing value when omitted)")
set.BoolVarP(
&dispatchRateData.RelativeToPublishRate,
"relative-to-publish-rate",
Expand Down
4 changes: 2 additions & 2 deletions pkg/ctl/topic/set_publish_rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ func SetPublishRateCmd(vc *cmdutils.VerbCmd) {
"msg-publish-rate",
"",
-1,
"message-publish-rate (default -1 will be overwrite if not passed)")
"message-publish-rate (defaults to -1 and overwrites the existing value when omitted)")
set.Int64VarP(
&publishRateData.PublishThrottlingRateInByte,
"byte-publish-rate",
"",
-1,
"byte-publish-rate (default -1 will be overwrite if not passed)")
"byte-publish-rate (defaults to -1 and overwrites the existing value when omitted)")
})
vc.EnableOutputFlagSet()
}
Expand Down
110 changes: 110 additions & 0 deletions pkg/ctl/topic/set_subscription_dispatch_rate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// 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 topic

import (
"github.com/apache/pulsar-client-go/pulsaradmin/pkg/utils"
"github.com/spf13/pflag"

"github.com/streamnative/pulsarctl/pkg/cmdutils"
)

func SetSubscriptionDispatchRateCmd(vc *cmdutils.VerbCmd) {
desc := cmdutils.LongDescription{}
desc.CommandUsedFor = "Set subscription message dispatch rate for a topic"
desc.CommandPermission = "This command requires tenant admin permissions."

var examples []cmdutils.Example
msg := cmdutils.Example{
Desc: "Set subscription message dispatch rate for a topic",
Command: "pulsarctl topics set-subscription-dispatch-rate topic " +
"--msg-dispatch-rate 4 --byte-dispatch-rate 5 --dispatch-rate-period 6 --relative-to-publish-rate",
}
examples = append(examples, msg)
desc.CommandExamples = examples

var out []cmdutils.Output
successOut := cmdutils.Output{
Desc: "normal output",
Out: "Set subscription message dispatch rate successfully for [topic]",
}
out = append(out, successOut, ArgError)
out = append(out, TopicNameErrors...)
out = append(out, TopicLevelPolicyNotEnabledError)
out = append(out, NamespaceErrors...)
desc.CommandOutput = out

vc.SetDescription(
"set-subscription-dispatch-rate",
"Set subscription message dispatch rate for a topic",
desc.ToString(),
desc.ExampleToString(),
"set-subscription-dispatch-rate",
)
dispatchRateData := &utils.DispatchRateData{}
vc.SetRunFuncWithNameArg(func() error {
return doSetSubscriptionDispatchRate(vc, dispatchRateData)
}, "the topic name is not specified or the topic name is specified more than one")

vc.FlagSetGroup.InFlagSet("SubscriptionDispatchRate", func(set *pflag.FlagSet) {
set.Int64VarP(
&dispatchRateData.DispatchThrottlingRateInMsg,
"msg-dispatch-rate",
"",
-1,
"message-dispatch-rate (defaults to -1 and overwrites the existing value when omitted)")
set.Int64VarP(
&dispatchRateData.DispatchThrottlingRateInByte,
"byte-dispatch-rate",
"",
-1,
"byte-dispatch-rate (defaults to -1 and overwrites the existing value when omitted)")
set.Int64VarP(
&dispatchRateData.RatePeriodInSecond,
"dispatch-rate-period",
"",
1,
"dispatch-rate-period in second type (defaults to 1 second and overwrites the existing value when omitted)")
set.BoolVarP(
&dispatchRateData.RelativeToPublishRate,
"relative-to-publish-rate",
"",
false,
"dispatch rate relative to publish-rate (if publish-relative flag is enabled "+
"then broker will apply throttling value to (publish-rate + dispatch rate))")
})
vc.EnableOutputFlagSet()
}

func doSetSubscriptionDispatchRate(vc *cmdutils.VerbCmd, dispatchRateData *utils.DispatchRateData) error {
// for testing
if vc.NameError != nil {
return vc.NameError
}

topic, err := utils.GetTopicName(vc.NameArg)
if err != nil {
return err
}
admin := cmdutils.NewPulsarClient()
err = admin.Topics().SetSubscriptionDispatchRate(*topic, *dispatchRateData)
if err == nil {
vc.Command.Printf("Set subscription message dispatch rate successfully for [%s]\n", topic.String())
}
return err
}
Loading
Loading