github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/tests/_dmctl_tools/check_master_online.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 main
    15  
    16  import (
    17  	"context"
    18  	"os"
    19  	"time"
    20  
    21  	toolutils "github.com/pingcap/tidb-tools/pkg/utils"
    22  	"github.com/pingcap/tiflow/dm/pb"
    23  	"github.com/pingcap/tiflow/dm/tests/utils"
    24  	"google.golang.org/grpc"
    25  )
    26  
    27  // use show-ddl-locks request to test DM-master is online
    28  func main() {
    29  	addr := os.Args[1]
    30  
    31  	secureOpt := grpc.WithInsecure()
    32  	if len(os.Args) == 5 {
    33  		sslCA := os.Args[2]
    34  		sslCert := os.Args[3]
    35  		sslKey := os.Args[4]
    36  		tls, err := toolutils.NewTLS(sslCA, sslCert, sslKey, "", nil)
    37  		if err != nil {
    38  			utils.ExitWithError(err)
    39  		}
    40  		secureOpt = tls.ToGRPCDialOption()
    41  	}
    42  
    43  	conn, err := grpc.Dial(addr, secureOpt, grpc.WithBackoffMaxDelay(2*time.Second))
    44  	if err != nil {
    45  		utils.ExitWithError(err)
    46  	}
    47  	cli := pb.NewMasterClient(conn)
    48  	req := &pb.ShowDDLLocksRequest{}
    49  	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
    50  	_, err = cli.ShowDDLLocks(ctx, req)
    51  	cancel()
    52  	if err != nil {
    53  		utils.ExitWithError(err)
    54  	}
    55  }