github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/cmd/client_processor.go (about) 1 // Copyright 2020 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 cmd 15 16 import ( 17 _ "github.com/go-sql-driver/mysql" // mysql driver 18 cerror "github.com/pingcap/ticdc/pkg/errors" 19 "github.com/spf13/cobra" 20 ) 21 22 func newProcessorCommand() *cobra.Command { 23 command := &cobra.Command{ 24 Use: "processor", 25 Short: "Manage processor (processor is a sub replication task running on a specified capture)", 26 } 27 command.AddCommand( 28 newListProcessorCommand(), 29 newQueryProcessorCommand(), 30 ) 31 return command 32 } 33 34 func newListProcessorCommand() *cobra.Command { 35 command := &cobra.Command{ 36 Use: "list", 37 Short: "List all processors in TiCDC cluster", 38 RunE: func(cmd *cobra.Command, args []string) error { 39 ctx := defaultContext 40 info, err := cdcEtcdCli.GetProcessors(ctx) 41 if err != nil { 42 return err 43 } 44 return jsonPrint(cmd, info) 45 }, 46 } 47 return command 48 } 49 50 func newQueryProcessorCommand() *cobra.Command { 51 command := &cobra.Command{ 52 Use: "query", 53 Short: "Query information and status of a sub replication task (processor)", 54 RunE: func(cmd *cobra.Command, args []string) error { 55 ctx := defaultContext 56 _, status, err := cdcEtcdCli.GetTaskStatus(ctx, changefeedID, captureID) 57 if err != nil && cerror.ErrTaskStatusNotExists.Equal(err) { 58 return err 59 } 60 _, position, err := cdcEtcdCli.GetTaskPosition(ctx, changefeedID, captureID) 61 if err != nil && cerror.ErrTaskPositionNotExists.Equal(err) { 62 return err 63 } 64 meta := &processorMeta{Status: status, Position: position} 65 return jsonPrint(cmd, meta) 66 }, 67 } 68 command.PersistentFlags().StringVarP(&changefeedID, "changefeed-id", "c", "", "Replication task (changefeed) ID") 69 command.PersistentFlags().StringVarP(&captureID, "capture-id", "p", "", "Capture ID") 70 _ = command.MarkPersistentFlagRequired("changefeed-id") 71 _ = command.MarkPersistentFlagRequired("capture-id") 72 return command 73 }