github.com/pingcap/chaos@v0.0.0-20190710112158-c86faf4b3719/pkg/core/client.go (about)

     1  package core
     2  
     3  import (
     4  	"context"
     5  )
     6  
     7  // UnknownResponse means we don't know wether this operation
     8  // succeeds or not.
     9  type UnknownResponse interface {
    10  	IsUnknown() bool
    11  }
    12  
    13  // Client applies the request to the database.
    14  // Client is used in contorl.
    15  // You should define your own client for your database.
    16  type Client interface {
    17  	// SetUp sets up the client.
    18  	SetUp(ctx context.Context, nodes []string, node string) error
    19  	// TearDown tears down the client.
    20  	TearDown(ctx context.Context, nodes []string, node string) error
    21  	// Invoke invokes a request to the database.
    22  	// Mostly, the return Response should implement UnknownResponse interface
    23  	Invoke(ctx context.Context, node string, r interface{}) interface{}
    24  	// NextRequest generates a request for latter Invoke.
    25  	NextRequest() interface{}
    26  	// DumpState the database state(also the model's state)
    27  	DumpState(ctx context.Context) (interface{}, error)
    28  }
    29  
    30  // ClientCreator creates a client.
    31  // The control will create one client for one node.
    32  type ClientCreator interface {
    33  	// Create creates the client.
    34  	Create(node string) Client
    35  }
    36  
    37  // NoopClientCreator creates a noop client.
    38  type NoopClientCreator struct {
    39  }
    40  
    41  // Create creates the client.
    42  func (NoopClientCreator) Create(node string) Client {
    43  	return noopClient{}
    44  }
    45  
    46  // noopClient is a noop client
    47  type noopClient struct {
    48  }
    49  
    50  // SetUp sets up the client.
    51  func (noopClient) SetUp(ctx context.Context, nodes []string, node string) error { return nil }
    52  
    53  // TearDown tears down the client.
    54  func (noopClient) TearDown(ctx context.Context, nodes []string, node string) error { return nil }
    55  
    56  // Invoke invokes a request to the database.
    57  func (noopClient) Invoke(ctx context.Context, node string, r interface{}) interface{} {
    58  	return nil
    59  }
    60  
    61  // NextRequest generates a request for latter Invoke.
    62  func (noopClient) NextRequest() interface{} {
    63  	return nil
    64  }
    65  
    66  // DumpState the database state(also the model's state)
    67  func (noopClient) DumpState(ctx context.Context) (interface{}, error) {
    68  	return nil, nil
    69  }