core

package
v0.0.0-...-4df958d Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2023 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsUnhealthyMembersError

func IsUnhealthyMembersError(err error) bool

IsUnhealthyMembersError returns whether the cause of this error is that replica set members are unhealthy.

func NewUnhealthyMembersError

func NewUnhealthyMembersError(members []ReplicaSetMember) error

NewUnhealthyMembersError returns an error reporting the status of the given members.

Types

type BackupFile

type BackupFile interface {
	// Metadata retrieves identifying information from the backup file
	// and returns it.
	Metadata() (BackupMetadata, error)

	// DumpDirectory returns the path of the database dump to be
	// restored.
	DumpDirectory() string

	// Close indicates the backup file is not needed anymore so any
	// temp space used can be freed.
	Close() error
}

BackupFile represents a specific backup file and provides methods for getting information from it.

type BackupMetadata

type BackupMetadata struct {
	// FormatVersion tells us which version of the backup structure
	// this file uses. If one wasn't specified in the file, it's
	// version 0.
	FormatVersion int64

	// ControllerModelUUID is the model UUID of the backed up
	// controller model.
	ControllerModelUUID string

	// ControllerUUID is the UUID of the backed up controller.
	ControllerUUID string

	// JujuVersion is the Juju version of the controller from which
	// the backup was taken.
	JujuVersion version.Number

	// Series is the OS series the backup was taken on. This will
	// determine the version of mongo that's installed and will need
	// to match the restore target.
	Series string

	// BackupCreated stores when this backup was created.
	BackupCreated time.Time

	// Hostname stores the name of the machine that created the
	// backup.
	Hostname string

	// ContainsLogs will be true if this backup includes log
	// collections.
	ContainsLogs bool

	// ModelCount reports how many models are contained in the backup.
	ModelCount int

	// CloudCount reports how many clouds are contained in the backup.
	CloudCount int

	// HANodes is the number of machines in the controller that was
	// backed up.
	HANodes int
}

BackupMetadata holds interesting information about a backup file.

type ControllerInfo

type ControllerInfo struct {
	// ControllerModelUUID is the controller model UUID for this controller.
	ControllerModelUUID string

	// ControllerUUID is the controller UUID for this controller.
	ControllerUUID string

	// ControllerModelCloud is the name of the controller model cloud.
	ControllerModelCloud string

	// ControllerModelCloudCredential is the name of the controller model cloud credential.
	ControllerModelCloudCredential string

	// JujuVersion is the version of Juju running on this controller.
	JujuVersion version.Number

	// Series is the OS series the controller is deployed on. Ths
	// determines what version of mongo is installed and whether we
	// can restore a given backup.
	Series string

	// HANodes is the count of controller machines.
	HANodes int

	// Models is the count of models.
	Models int
}

ControllerInfo holds identifying information about a Juju controller.

type ControllerNode

type ControllerNode interface {
	// IP returns IP address of the machine.
	IP() string

	// Ping checks connection to the controller machine.
	Ping() error

	// StopAgent stops jujud-machine-* service on the controller node.
	StopAgent() error

	// StartAgent starts jujud-machine-* service on the controller node.
	StartAgent() error

	// UpdateAgentVersion changes the tools symlink and agent.conf for
	// this machine to match the specified version.
	UpdateAgentVersion(version.Number) error
}

ControllerNode defines behavior for a controller node machine.

type ControllerNodeFactory

type ControllerNodeFactory func(member ReplicaSetMember) ControllerNode

ControllerNodeFactory gets a controller node machine from a replicaset member.

type Database

type Database interface {
	// ReplicaSet gets the status of the replica set and all members.
	ReplicaSet() (ReplicaSet, error)

	// ControllerInfo gets information about the controller that we
	// can compare to the backup file.
	ControllerInfo() (ControllerInfo, error)

	// CopyController copies the core controller data from the backup
	// file so that the target controller looks like the source controller.
	CopyController(controller ControllerInfo) error

	// RestoreFromDump restores the database dump in the directory
	// passed in to the database and writes progress logging to the
	// specified path.
	RestoreFromDump(dumpDir string, logFile string, includeStatusHistory, copyController bool) error

	// Close terminates the database connection.
	Close()
}

Database represents a connection to MongoDB and abstracts the operations the core needs to apply as part of restoring a backup.

type PrecheckResult

type PrecheckResult struct {
	// BackupDate is the date the backup was finished.
	BackupDate time.Time

	// ControllerModelUUID is the controller model UUID from which
	// backup was taken.
	ControllerModelUUID string

	// ControllerUUID is the UUID of the controller from which
	// backup was taken.
	ControllerUUID string

	// BackupJujuVersion is the Juju version of the controller from which backup was taken.
	BackupJujuVersion version.Number

	// ControllerJujuVersion is the Juju version of the controller
	// we're restoring into. If it's greater than BackupJujuVersion
	// (disregarding build number) then restoring this version is also
	// a downgrade.
	ControllerJujuVersion version.Number

	// ModelCount is the count of models that this backup contains.
	ModelCount int

	// CloudCount is the count of clouds that this backup contains.
	CloudCount int
}

PrecheckResult contains the results of a pre-check run.

type ReplicaSet

type ReplicaSet struct {
	// Name of the replica set - this will be "juju" for replica sets
	// that juju has created.
	Name string

	// Members lists the nodes that make up the set.
	Members []ReplicaSetMember
}

ReplicaSet holds information about the members of a replica set and its status.

type ReplicaSetMember

type ReplicaSetMember struct {
	// ID is unique across the nodes.
	ID int

	// Name will contain the ip-address:port in the case of
	// Juju-created replica sets.
	Name string

	// Self will be true for the member we're currently connected to,
	// false for the others.
	Self bool

	// Healthy indicates whether there's some problem with the node.
	Healthy bool

	// State should be PRIMARY or SECONDARY, but if there's a problem
	// with the replica set it could be any one of the values listed
	// at https://docs.mongodb.com/manual/reference/replica-states/
	State string

	// JujuMachineID has Juju machine ID for this controller node.
	// This information is needed when trying to manage Juju agents,
	// their config or any other artifacts created by Juju.
	JujuMachineID string
}

ReplicaSetMember holds status information about a database replica set member.

func (ReplicaSetMember) String

func (m ReplicaSetMember) String() string

String is part of Stringer.

type Restorer

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

Restorer checks the database health and backup file state and restores the backup file.

func NewRestorer

func NewRestorer(db Database, backup BackupFile, convert ControllerNodeFactory) (*Restorer, error)

NewRestorer returns a new restorer for a specific database and backup.

func (*Restorer) CheckDatabaseState

func (r *Restorer) CheckDatabaseState() error

CheckDatabaseState determines whether this database is appropriate for restoring into.

func (*Restorer) CheckRestorable

func (r *Restorer) CheckRestorable(allowDowngrade, copyController bool) (*PrecheckResult, error)

CheckRestorable checks whether the backup file can be restored into the target database.

func (*Restorer) CheckSecondaryControllerNodes

func (r *Restorer) CheckSecondaryControllerNodes() map[string]error

CheckSecondaryControllerNodes determines whether secondary controller nodes can be reached.

func (*Restorer) IsHA

func (r *Restorer) IsHA() bool

IsHA returns true of there is more than one member in replica set.

func (*Restorer) Restore

func (r *Restorer) Restore(logPath string, includeStatusHistory, copyController bool) error

Restore replaces the database's contents with the data from the backup's database dump.

func (*Restorer) StartAgents

func (r *Restorer) StartAgents(startSecondaries bool) map[string]error

StartAgents starts controller agents, jujud-machine-*. If stopSecondaries is true, these agents on other controller nodes will be started as well. The agents on the primary node are always started first.

func (*Restorer) StopAgents

func (r *Restorer) StopAgents(stopSecondaries bool) map[string]error

StopAgents stops controller agents, jujud-machine-*. If stopSecondaries is true, these agents on other controller nodes will be stopped as well. The agents on the primary node are always stopped last.

Jump to

Keyboard shortcuts

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