core

package
v0.0.0-...-c86faf4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2019 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InvokeOperation = "call"
	ReturnOperation = "return"
)

Operation action

Variables

This section is empty.

Functions

func RegisterDB

func RegisterDB(db DB)

RegisterDB registers db. Not thread-safe

func RegisterNemesis

func RegisterNemesis(n Nemesis)

RegisterNemesis registers nemesis. Not thread-safe.

Types

type Checker

type Checker interface {
	// Check a series of operations with the given model.
	// Return false or error if operations do not satisfy the model.
	Check(m Model, ops []Operation) (bool, error)

	// Name returns the unique name for the checker.
	Name() string
}

Checker checks a history of operations.

type Client

type Client interface {
	// SetUp sets up the client.
	SetUp(ctx context.Context, nodes []string, node string) error
	// TearDown tears down the client.
	TearDown(ctx context.Context, nodes []string, node string) error
	// Invoke invokes a request to the database.
	// Mostly, the return Response should implement UnknownResponse interface
	Invoke(ctx context.Context, node string, r interface{}) interface{}
	// NextRequest generates a request for latter Invoke.
	NextRequest() interface{}
	// DumpState the database state(also the model's state)
	DumpState(ctx context.Context) (interface{}, error)
}

Client applies the request to the database. Client is used in contorl. You should define your own client for your database.

type ClientCreator

type ClientCreator interface {
	// Create creates the client.
	Create(node string) Client
}

ClientCreator creates a client. The control will create one client for one node.

type DB

type DB interface {
	// SetUp initializes the database.
	SetUp(ctx context.Context, nodes []string, node string) error
	// TearDown tears down the database.
	TearDown(ctx context.Context, nodes []string, node string) error
	// Start starts the database
	Start(ctx context.Context, node string) error
	// Stop stops the database
	Stop(ctx context.Context, node string) error
	// Kill kills the database
	Kill(ctx context.Context, node string) error
	// IsRunning checks whether the database is running or not
	IsRunning(ctx context.Context, node string) bool
	// Name returns the unique name for the database
	Name() string
}

DB allows Chaos to set up and tear down database.

func GetDB

func GetDB(name string) DB

GetDB gets the registered db.

type Model

type Model interface {
	// Prepare the initial state of the data object.
	Prepare(state interface{})

	// Initial state of the data object.
	Init() interface{}

	// Step function for the data object. Returns whether or not the system
	// could take this step with the given inputs and outputs and also
	// returns the new state. This should not mutate the existing state.
	//
	// state must support encoding to and decoding from json.
	Step(state interface{}, input interface{}, output interface{}) (bool, interface{})

	// Equality on states.
	Equal(state1, state2 interface{}) bool

	// Name returns the unique name for the model.
	Name() string
}

Model specifies the behavior of a data object.

type Nemesis

type Nemesis interface {

	// Invoke executes the nemesis
	Invoke(ctx context.Context, node string, args ...string) error
	// Recover recovers the nemesis
	Recover(ctx context.Context, node string, args ...string) error
	// Name returns the unique name for the nemesis
	Name() string
}

Nemesis injects failure and disturbs the database.

func GetNemesis

func GetNemesis(name string) Nemesis

GetNemesis gets the registered nemesis.

type NemesisGenerator

type NemesisGenerator interface {
	// Generate generates the nemesis operation for all nodes.
	// Every node will be assigned a nemesis operation.
	Generate(nodes []string) []*NemesisOperation
	Name() string
}

NemesisGenerator is used in control, it will generate a nemesis operation and then the control can use it to disturb the cluster.

type NemesisOperation

type NemesisOperation struct {
	// Nemesis name
	Name string
	// Nemesis invoke args
	InvokeArgs []string
	// Nemesis recover args
	RecoverArgs []string
	// Nemesis execute time
	RunTime time.Duration
}

NemesisOperation is nemesis operation used in control.

type NoopChecker

type NoopChecker struct{}

NoopChecker is a noop checker.

func (NoopChecker) Check

func (NoopChecker) Check(m Model, ops []Operation) (bool, error)

Check impls Checker.

func (NoopChecker) Name

func (NoopChecker) Name() string

Name impls Checker.

type NoopClientCreator

type NoopClientCreator struct {
}

NoopClientCreator creates a noop client.

func (NoopClientCreator) Create

func (NoopClientCreator) Create(node string) Client

Create creates the client.

type NoopDB

type NoopDB struct {
}

NoopDB is a DB but does nothing

func (NoopDB) IsRunning

func (NoopDB) IsRunning(ctx context.Context, node string) bool

IsRunning checks whether the database is running or not

func (NoopDB) Kill

func (NoopDB) Kill(ctx context.Context, node string) error

Kill kills the database

func (NoopDB) Name

func (NoopDB) Name() string

Name returns the unique name for the database

func (NoopDB) SetUp

func (NoopDB) SetUp(ctx context.Context, nodes []string, node string) error

SetUp initializes the database.

func (NoopDB) Start

func (NoopDB) Start(ctx context.Context, node string) error

Start starts the database

func (NoopDB) Stop

func (NoopDB) Stop(ctx context.Context, node string) error

Stop stops the database

func (NoopDB) TearDown

func (NoopDB) TearDown(ctx context.Context, nodes []string, node string) error

TearDown tears down the datase.

type NoopModel

type NoopModel struct {
	// contains filtered or unexported fields
}

NoopModel is noop model.

func (*NoopModel) Equal

func (*NoopModel) Equal(state1, state2 interface{}) bool

Equal returns equality on states.

func (*NoopModel) Init

func (n *NoopModel) Init() interface{}

Init initials state of the data object.

func (*NoopModel) Name

func (*NoopModel) Name() string

Name returns the unique name for the model.

func (*NoopModel) Prepare

func (n *NoopModel) Prepare(state interface{})

Prepare the initial state of the data object.

func (*NoopModel) Step

func (*NoopModel) Step(state interface{}, input interface{}, output interface{}) (bool, interface{})

Step function for the data object.

type NoopNemesis

type NoopNemesis struct {
}

NoopNemesis is a nemesis but does nothing

func (NoopNemesis) Invoke

func (NoopNemesis) Invoke(ctx context.Context, node string, args ...string) error

Invoke executes the nemesis

func (NoopNemesis) Name

func (NoopNemesis) Name() string

Name returns the unique name for the nemesis

func (NoopNemesis) Recover

func (NoopNemesis) Recover(ctx context.Context, node string, args ...string) error

Recover recovers the nemesis

type NoopNemesisGenerator

type NoopNemesisGenerator struct {
}

NoopNemesisGenerator generates

func (NoopNemesisGenerator) Generate

func (NoopNemesisGenerator) Generate(nodes []string) []*NemesisOperation

Generate generates the nemesis operation for the nodes.

func (NoopNemesisGenerator) Name

Name returns the name

type Operation

type Operation struct {
	Action string      `json:"action"`
	Proc   int64       `json:"proc"`
	Data   interface{} `json:"data"`
}

Operation of a data object.

type UnknownResponse

type UnknownResponse interface {
	IsUnknown() bool
}

UnknownResponse means we don't know wether this operation succeeds or not.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL