cluster

package
v0.0.0-...-ac77e4e Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2015 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HTTPClient = http.Client{
	Timeout: base.NetworkTimeout,
	Transport: &http.Transport{
		TLSClientConfig: &tls.Config{
			InsecureSkipVerify: true,
		},
	}}

HTTPClient is an http.Client configured for querying a cluster. We need to run with "InsecureSkipVerify" (at least on Docker) due to the fact that we cannot use a fixed hostname to reach the cluster. This in turn means that we do not have a verified server name in the certs.

Functions

This section is empty.

Types

type Cluster

type Cluster interface {
	// NumNodes returns the number of nodes in the cluster, running or not.
	NumNodes() int
	// MakeClient returns a client which is pointing at the node with the given
	// index. The given integer must be in the range [0,NumNodes()-1].
	MakeClient(util.Tester, int) (*client.DB, *stop.Stopper)
	// Assert verifies that the cluster state is as expected (i.e. no unexpected
	// restarts or node deaths occurred). Tests can call this periodically to
	// ascertain cluster health.
	Assert(util.Tester)
	// AssertAndStop performs the same test as Assert but then proceeds to
	// dismantle the cluster.
	AssertAndStop(util.Tester)
	// Kill terminates the cockroach process running on the given node number.
	// The given integer must be in the range [0,NumNodes()-1].
	Kill(int) error
	// Restart terminates the cockroach process running on the given node
	// number, unless it is already stopped, and restarts it.
	// The given integer must be in the range [0,NumNodes()-1].
	Restart(int) error
	// Get queries the given node's HTTP endpoint for the given path, unmarshaling
	// into the supplied interface (or returning an error).
	Get(int, string, interface{}) error
}

A Cluster is an abstraction away from a concrete cluster deployment (i.e. a local docker cluster, or an AWS-provisioned one). It exposes a shared set of methods for test-related manipulation.

type Container

type Container struct {
	ID   string
	Name string
	// contains filtered or unexported fields
}

Container provides the programmatic interface for a single docker container.

func (*Container) Addr

func (c *Container) Addr(name string) *net.TCPAddr

Addr returns the address to connect to the specified port.

func (*Container) GetJSON

func (c *Container) GetJSON(port, path string, v interface{}) error

GetJSON retrieves the URL specified by https://Addr(<port>)<path> and unmarshals the result as JSON.

func (*Container) Inspect

func (c *Container) Inspect() (*dockerclient.ContainerInfo, error)

Inspect retrieves detailed info about a container.

func (*Container) Kill

func (c *Container) Kill() error

Kill stops a running container, without removing it.

func (*Container) Logs

func (c *Container) Logs(w io.Writer) error

Logs outputs the containers logs to the given io.Writer.

func (*Container) Pause

func (c *Container) Pause() error

Pause pauses a running container.

func (*Container) Remove

func (c *Container) Remove() error

Remove removes the container from docker. It is an error to remove a running container.

func (*Container) Restart

func (c *Container) Restart(timeoutSeconds int) error

Restart restarts a running container. Container will be killed after 'timeout' seconds if it fails to stop.

func (*Container) Start

func (c *Container) Start(binds []string, dns, vols *Container) error

Start starts a non-running container.

TODO(pmattis): Generalize the setting of parameters here.

func (*Container) Stop

func (c *Container) Stop(timeoutSeconds int) error

Stop a running container.

func (*Container) Unpause

func (c *Container) Unpause() error

Unpause resumes a paused container.

func (*Container) Wait

func (c *Container) Wait() error

Wait waits for a running container to exit.

type Event

type Event struct {
	NodeIndex int
	Status    string
}

Event for a node containing a node index and the type of event.

type LocalCluster

type LocalCluster struct {
	Nodes []*Container

	CertsDir string

	LogDir       string
	ForceLogging bool // Forces logging to disk on a per test basis
	// contains filtered or unexported fields
}

LocalCluster manages a local cockroach cluster running on docker. The cluster is composed of a "dns" container which automatically registers dns entries for the cockroach nodes, a "volumes" container which manages the persistent volumes used for certs and node data and N cockroach nodes.

func CreateLocal

func CreateLocal(numNodes int, stopper chan struct{}) *LocalCluster

CreateLocal creates a new local cockroach cluster. The stopper is used to gracefully shutdown the channel (e.g. when a signal arrives). The cluster must be started before being used.

func (*LocalCluster) Assert

func (l *LocalCluster) Assert(t util.Tester)

Assert drains the Events channel and compares the actual events with those expected to have been generated by the operations performed on the nodes in the cluster (restart, kill, ...). In the event of a mismatch, the passed Tester receives a fatal error. Currently, the only events generated (and asserted against) are "die" and "restart", to maximize compatibility across different versions of Docker.

func (*LocalCluster) AssertAndStop

func (l *LocalCluster) AssertAndStop(t util.Tester)

AssertAndStop calls Assert and then stops the cluster. It is safe to stop the cluster multiple times.

func (*LocalCluster) Get

func (l *LocalCluster) Get(i int, path string, dest interface{}) error

Get gets the given path from the i-th node and unmarshals into the given interface.

func (*LocalCluster) Kill

func (l *LocalCluster) Kill(i int) error

Kill kills the i-th node.

func (*LocalCluster) MakeClient

func (l *LocalCluster) MakeClient(t util.Tester, node int) (*client.DB, *stop.Stopper)

MakeClient creates a DB client for node 'i' using the cluster certs dir.

func (*LocalCluster) NumNodes

func (l *LocalCluster) NumNodes() int

NumNodes returns the number of nodes in the cluster.

func (*LocalCluster) Restart

func (l *LocalCluster) Restart(i int) error

Restart restarts the given node. If the node isn't running, this starts it.

func (*LocalCluster) Start

func (l *LocalCluster) Start()

Start starts the cluster.

type RemoteCluster

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

RemoteCluster manages a remote cluster specified by a number of hosts.

func CreateRemote

func CreateRemote(peers []string) *RemoteCluster

CreateRemote connects to a remote cockroach cluster (which is required to have been set up separately).

func (*RemoteCluster) Assert

func (r *RemoteCluster) Assert(t util.Tester)

Assert verifies that the cluster state is as expected (i.e. no unexpected restarts or node deaths occurred). Tests can call this periodically to ascertain cluster health.

func (*RemoteCluster) AssertAndStop

func (r *RemoteCluster) AssertAndStop(t util.Tester)

AssertAndStop performs the same test as Assert but then proceeds to dismantle the cluster.

func (*RemoteCluster) Exec

func (r *RemoteCluster) Exec(i int, cmd string) (string, string, error)

Exec executes the given command on the i-th node, returning (in that order) stdout, stderr and an error.

func (*RemoteCluster) Get

func (r *RemoteCluster) Get(i int, path string, v interface{}) error

Get queries the given node's HTTP endpoint for the given path, unmarshaling into the supplied interface (or returning an error).

func (*RemoteCluster) Kill

func (r *RemoteCluster) Kill(i int) error

Kill terminates the cockroach process running on the given node number. The given integer must be in the range [0,NumNodes()-1].

func (*RemoteCluster) MakeClient

func (r *RemoteCluster) MakeClient(t util.Tester, i int) (*client.DB, *stop.Stopper)

MakeClient returns a client which is pointing at the node with the given index. The given integer must be in the range [0,NumNodes()-1].

func (*RemoteCluster) NumNodes

func (r *RemoteCluster) NumNodes() int

NumNodes returns the number of nodes in the cluster, running or not.

func (*RemoteCluster) Restart

func (r *RemoteCluster) Restart(i int) error

Restart terminates the cockroach process running on the given node number, unless it is already stopped, and restarts it. The given integer must be in the range [0,NumNodes()-1].

Jump to

Keyboard shortcuts

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