github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/ctl/master/pause_relay.go (about) 1 // Copyright 2019 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package master 15 16 import ( 17 "errors" 18 "fmt" 19 "os" 20 21 "github.com/pingcap/tiflow/dm/ctl/common" 22 "github.com/pingcap/tiflow/dm/pb" 23 "github.com/spf13/cobra" 24 ) 25 26 // NewPauseRelayCmd creates a PauseRelay command. 27 func NewPauseRelayCmd() *cobra.Command { 28 cmd := &cobra.Command{ 29 Use: "pause-relay <-s source ...>", 30 Short: "Pauses DM-worker's relay unit", 31 RunE: pauseRelayFunc, 32 } 33 return cmd 34 } 35 36 // pauseRelayFunc does pause relay request. 37 func pauseRelayFunc(cmd *cobra.Command, _ []string) (err error) { 38 if len(cmd.Flags().Args()) > 0 { 39 cmd.SetOut(os.Stdout) 40 common.PrintCmdUsage(cmd) 41 err = errors.New("please check output to see error") 42 return 43 } 44 45 sources, err := common.GetSourceArgs(cmd) 46 if err != nil { 47 return 48 } 49 if len(sources) == 0 { 50 fmt.Println("must specify at least one source (`-s` / `--source`)") 51 err = errors.New("please check output to see error") 52 return 53 } 54 55 resp, err := common.OperateRelay(pb.RelayOp_PauseRelay, sources) 56 if err != nil { 57 return 58 } 59 60 common.PrettyPrintResponse(resp) 61 return 62 }