Skip to content
Closed
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
46 changes: 46 additions & 0 deletions pkg/ctl/bk/autorecovery/autorecovery.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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 autorecovery

import (
"github.com/streamnative/pulsarctl/pkg/cmdutils"

"github.com/spf13/cobra"
)

func Commands(flagGrouping *cmdutils.FlagGrouping) *cobra.Command {
resourceCmd := cmdutils.NewResourceCmd(
"auto-recovery",
"Operations about ledger",
"",
"")

commands := []func(*cmdutils.VerbCmd){
RecoverBookieCmd,
ListUnderReplicatedLedgerCmd,
WhoIsAuditorCmd,
TriggerAuditCmd,
SetLostBookieRecoveryDelayCmd,
GetLostBookieRecoveryDelayCmd,
DecommissionCmd,
}

cmdutils.AddVerbCmds(flagGrouping, resourceCmd, commands...)

return resourceCmd
}
70 changes: 70 additions & 0 deletions pkg/ctl/bk/autorecovery/decommission.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// 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 autorecovery

import (
"github.com/streamnative/pulsarctl/pkg/cmdutils"
"github.com/streamnative/pulsarctl/pkg/pulsar"
)

func DecommissionCmd(vc *cmdutils.VerbCmd) {
var desc pulsar.LongDescription
desc.CommandUsedFor = "This command is used for decommission a bookie."
desc.CommandPermission = "none"

var examples []pulsar.Example
c := pulsar.Example{
Desc: "Decommission a bookie",
Command: "pulsarctl bk auto-recovery (bk-ip:bk-port)",
}
examples = append(examples, c)
desc.CommandExamples = examples

var out []pulsar.Output
successOut := pulsar.Output{
Desc: "normal output",
Out: "Successfully decommission the bookie (bookie-ip:bookie-port)",
}

argError := pulsar.Output{
Desc: "the bookie address is not specified or the bookie address is specified more than one",
Out: "[✖] the bookie address is not specified or the bookie address is specified more than one",
}
out = append(out, successOut, argError)
desc.CommandOutput = out

vc.SetDescription(
"decommission",
"Decommission a bookie",
desc.ToString(),
desc.ExampleToString())

vc.SetRunFuncWithNameArg(func() error {
return doDecommission(vc)
}, "the bookie address is not specified or the bookie address is specified more than one")
}

func doDecommission(vc *cmdutils.VerbCmd) error {
admin := cmdutils.NewBookieClient()
err := admin.AutoRecovery().Decommission(vc.NameArg)
if err == nil {
vc.Command.Printf("Successfully decommission the bookie %s\n", vc.NameArg)
}

return err
}
65 changes: 65 additions & 0 deletions pkg/ctl/bk/autorecovery/get_lost_bookie_recovery_delay.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// 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 autorecovery

import (
"github.com/streamnative/pulsarctl/pkg/cmdutils"
"github.com/streamnative/pulsarctl/pkg/pulsar"
)

func GetLostBookieRecoveryDelayCmd(vc *cmdutils.VerbCmd) {
var desc pulsar.LongDescription
desc.CommandUsedFor = "This command is used for getting the lost bookie recovery delay in second of a bookie."
desc.CommandPermission = "none"

var examples []pulsar.Example
get := pulsar.Example{
Desc: "Get the lost Bookie Recovery Delay of a bookie",
Command: "pulsarctl bk auto-recovery get-delay",
}
examples = append(examples, get)
desc.CommandExamples = examples

var out []pulsar.Output
successOut := pulsar.Output{
Desc: "normal output",
Out: "lostBookieRecoveryDelay value: (delay)",
}
out = append(out, successOut)
desc.CommandOutput = out

vc.SetDescription(
"get-delay",
"Get the lost bookie recovery delay of a bookie",
desc.ToString(),
desc.ExampleToString())

vc.SetRunFunc(func() error {
return doGetLostBookieRecoveryDelay(vc)
})
}

func doGetLostBookieRecoveryDelay(vc *cmdutils.VerbCmd) error {
admin := cmdutils.NewBookieClient()
out, err := admin.AutoRecovery().GetLostBookieRecoveryDelay()
if err == nil {
vc.Command.Println(out)
}

return err
}
97 changes: 97 additions & 0 deletions pkg/ctl/bk/autorecovery/list_under_replicated_ledger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// 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 autorecovery

import (
"github.com/streamnative/pulsarctl/pkg/cmdutils"
"github.com/streamnative/pulsarctl/pkg/pulsar"

"github.com/spf13/pflag"
)

func ListUnderReplicatedLedgerCmd(vc *cmdutils.VerbCmd) {
var desc pulsar.LongDescription
desc.CommandUsedFor = "This command is used for listing all the underreplicated ledgers which have been marked " +
"for rereplication."
desc.CommandPermission = "none"

var examples []pulsar.Example
list := pulsar.Example{
Desc: "List all the underreplicated ledgers which have been marked for rereplication",
Command: "pulsarctl bk auto-recovery list-under-replicated-ledger",
}

li := pulsar.Example{
Desc: "List all the underreplicated ledgers of a bookie which have been marked for rereplication",
Command: "pulsarctl bk auto-recovery list-under-replicated-ledger --include (bookie-ip:bookie-port)",
}

le := pulsar.Example{
Desc: "List all the underreplicated ledgers except a bookie which have been marked for rereplication",
Command: "pulsarctl bk auto-recovery list-under-replicated-ledger --exclude (bookie-ip:bookie-port)",
}
examples = append(examples, list, li, le)
desc.CommandExamples = examples

var out []pulsar.Output
successOut := pulsar.Output{
Desc: "normal output",
Out: `{
[ledgerId1, ledgerId2...]
}`,
}
out = append(out, successOut)
desc.CommandOutput = out

vc.SetDescription(
"list-under-replicated-ledger",
"List all the underreplicated ledgers which have been marked for rereplication",
desc.ToString(),
desc.ExampleToString())

var include string
var exclude string
var show bool

vc.SetRunFunc(func() error {
return doListUnderReplicatedLedger(vc, include, exclude, show)
})

vc.FlagSetGroup.InFlagSet("List Under Replicated Ledger", func(set *pflag.FlagSet) {
set.StringVar(&include, "include", "", "show the underreplicated ledger of the bookie")
set.StringVar(&exclude, "exclude", "", "show the underreplicated ledger exclude the bookie")
set.BoolVar(&show, "show", false, "show the ledgers replica list")
})
}

func doListUnderReplicatedLedger(vc *cmdutils.VerbCmd, include, exclude string, print bool) error {
admin := cmdutils.NewBookieClient()
var l interface{}
var err error
if print {
l, err = admin.AutoRecovery().PrintListUnderReplicatedLedger(include, exclude)
} else {
l, err = admin.AutoRecovery().ListUnderReplicatedLedger(include, exclude)
}

if err == nil {
cmdutils.PrintJSON(vc.Command.OutOrStdout(), l)
}

return err
}
79 changes: 79 additions & 0 deletions pkg/ctl/bk/autorecovery/recover_bookie.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// 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 autorecovery

import (
"github.com/streamnative/pulsarctl/pkg/cmdutils"
"github.com/streamnative/pulsarctl/pkg/pulsar"

"github.com/spf13/pflag"
)

func RecoverBookieCmd(vc *cmdutils.VerbCmd) {
var desc pulsar.LongDescription
desc.CommandUsedFor = "This command is used for recovering the ledger data of a failed bookie."
desc.CommandPermission = "none"

var examples []pulsar.Example
rb := pulsar.Example{
Desc: "Recover the ledger data of a failed bookie",
Command: "pulsarctl bk auto-recovery recover-bookie (bookie-1) (bookie-2)",
}
examples = append(examples, rb)
desc.CommandExamples = examples

var out []pulsar.Output
successOut := pulsar.Output{
Desc: "normal output",
Out: "Successfully recover the bookies (bookie-1) (bookie-2)",
}
out = append(out, successOut)
desc.CommandOutput = out

vc.SetDescription(
"recover-bookie",
"Recover the ledger data of a failed bookie",
desc.ToString(),
desc.ExampleToString())

var deleteCookie bool

vc.SetRunFuncWithMultiNameArgs(func() error {
return doRecoverBookie(vc, deleteCookie)
}, func(args []string) error {
return nil
})

vc.FlagSetGroup.InFlagSet("Recover Bookie", func(set *pflag.FlagSet) {
set.BoolVar(&deleteCookie, "delelte-cookie", false, "delete cookie")
})
}

func doRecoverBookie(vc *cmdutils.VerbCmd, deleteCookie bool) error {
admin := cmdutils.NewBookieClient()
err := admin.AutoRecovery().RecoverBookie(vc.NameArgs, deleteCookie)
if err == nil {
if deleteCookie {
vc.Command.Printf("Successfully recover the bookies %v and delete the cookie\n", vc.NameArgs)
} else {
vc.Command.Printf("Successfully recover the bookie %v\n", vc.NameArgs)
}
}

return err
}
Loading