mongo

package
v0.0.0-...-f19ae85 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2015 License: AGPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// SharedSecretFile is the name of the Mongo shared secret file
	// located within the Juju data directory.
	SharedSecretFile = "shared-secret"

	// ReplicaSetName is the name of the replica set that juju uses for its
	// state servers.
	ReplicaSetName = "juju"
)
View Source
const AdminUser = "admin"

AdminUser is the name of the user that is initially created in mongo.

View Source
const SocketTimeout = 21 * time.Second

SocketTimeout should be long enough that even a slow mongo server will respond in that length of time. Since mongo servers ping themselves every 10 seconds, we use a value of just over 2 ping periods to allow for delayed pings due to issues such as CPU starvation etc.

Variables

View Source
var (

	// JujuMongodPath holds the default path to the juju-specific mongod.
	JujuMongodPath = "/usr/lib/juju/bin/mongod"
)

Functions

func CollectionFromName

func CollectionFromName(db *mgo.Database, coll string) (*mgo.Collection, func())

CollectionFromName returns a named collection on the specified database, initialised with a new session. Also returned is a close function which must be called when the collection is no longer required.

func DialInfo

func DialInfo(info Info, opts DialOpts) (*mgo.DialInfo, error)

DialInfo returns information on how to dial the state's mongo server with the given info and dial options.

func DialWithInfo

func DialWithInfo(info Info, opts DialOpts) (*mgo.Session, error)

DialWithInfo establishes a new session to the cluster identified by info, with the specified options.

func EnsureAdminUser

func EnsureAdminUser(p EnsureAdminUserParams) (added bool, err error)

EnsureAdminUser ensures that the specified user and password are added to the admin database.

This function will stop the Mongo service if it needs to add the admin user, as it must restart Mongo in --noauth mode.

func EnsureServer

func EnsureServer(args EnsureServerParams) error

EnsureServer ensures that the MongoDB server is installed, configured, and ready to run.

This method will remove old versions of the mongo init service as necessary before installing the new version.

The namespace is a unique identifier to prevent multiple instances of mongo on this machine from colliding. This should be empty unless using the local provider.

func GenerateSharedSecret

func GenerateSharedSecret() (string, error)

GenerateSharedSecret generates a pseudo-random shared secret (keyfile) for use with Mongo replica sets.

func IsMaster

func IsMaster(session *mgo.Session, obj WithAddresses) (bool, error)

IsMaster returns a boolean that represents whether the given machine's peer address is the primary mongo host for the replicaset

func Path

func Path() (string, error)

Path returns the executable path to be used to run mongod on this machine. If the juju-bundled version of mongo exists, it will return that path, otherwise it will return the command to run mongod from the path.

func RemoveService

func RemoveService(namespace string) error

RemoveService removes the mongoDB init service from this machine.

func SelectPeerAddress

func SelectPeerAddress(addrs []network.Address) string

SelectPeerAddress returns the address to use as the mongo replica set peer address by selecting it from the given addresses.

func SelectPeerHostPort

func SelectPeerHostPort(hostPorts []network.HostPort) string

SelectPeerHostPort returns the HostPort to use as the mongo replica set peer by selecting it from the given hostPorts.

func ServiceName

func ServiceName(namespace string) string

ServiceName returns the name of the init service config for mongo using the given namespace.

func SetAdminMongoPassword

func SetAdminMongoPassword(session *mgo.Session, user, password string) error

SetAdminMongoPassword sets the administrative password to access a mongo database. If the password is non-empty, all subsequent attempts to access the database must be authorized; otherwise no authorization is required.

Types

type DialOpts

type DialOpts struct {
	// Timeout is the amount of time to wait contacting
	// a state server.
	Timeout time.Duration

	// SocketTimeout is the amount of time to wait for a
	// non-responding socket to the database before it is
	// forcefully closed. If this is zero, Timeout will be
	// used.
	SocketTimeout time.Duration

	// Direct informs whether to establish connections only with the
	// specified seed servers, or to obtain information for the whole
	// cluster and establish connections with further servers too.
	Direct bool

	// PostDial, if non-nil, is called by DialWithInfo with the
	// mgo.Session after a successful dial but before DialWithInfo
	// returns to its caller.
	PostDial func(*mgo.Session) error
}

DialOpts holds configuration parameters that control the Dialing behavior when connecting to a state server.

func DefaultDialOpts

func DefaultDialOpts() DialOpts

DefaultDialOpts returns a DialOpts representing the default parameters for contacting a state server.

type EnsureAdminUserParams

type EnsureAdminUserParams struct {
	// DialInfo specifies how to connect to the mongo server.
	DialInfo *mgo.DialInfo
	// Namespace is the agent namespace, used to derive the Mongo service name.
	Namespace string
	// DataDir is the Juju data directory, used to start a --noauth server.
	DataDir string
	// Port is the listening port of the Mongo server.
	Port int
	// User holds the user to log in to the mongo server as.
	User string
	// Password holds the password for the user to log in as.
	Password string
}

type EnsureServerParams

type EnsureServerParams struct {
	// APIPort is the port to connect to the api server.
	APIPort int

	// StatePort is the port to connect to the mongo server.
	StatePort int

	// Cert is the certificate.
	Cert string

	// PrivateKey is the certificate's private key.
	PrivateKey string

	// CAPrivateKey is the CA certificate's private key.
	CAPrivateKey string

	// SharedSecret is a secret shared between mongo servers.
	SharedSecret string

	// SystemIdentity is the identity of the system.
	SystemIdentity string

	// DataDir is the machine agent data directory.
	DataDir string

	// Namespace is the machine agent's namespace, which is used to
	// generate a unique service name for Mongo.
	Namespace string

	// OplogSize is the size of the Mongo oplog.
	// If this is zero, then EnsureServer will
	// calculate a default size according to the
	// algorithm defined in Mongo.
	OplogSize int

	// SetNumaControlPolicy preference - whether the user
	// wants to set the numa control policy when starting mongo.
	SetNumaControlPolicy bool
}

EnsureServerParams is a parameter struct for EnsureServer.

type Info

type Info struct {
	// Addrs gives the addresses of the MongoDB servers for the state.
	// Each address should be in the form address:port.
	Addrs []string

	// CACert holds the CA certificate that will be used
	// to validate the state server's certificate, in PEM format.
	CACert string
}

Info encapsulates information about cluster of mongo servers and can be used to make a connection to that cluster.

type MongoInfo

type MongoInfo struct {
	// mongo.Info contains the addresses and cert of the mongo cluster.
	Info
	// Tag holds the name of the entity that is connecting.
	// It should be nil when connecting as an administrator.
	Tag names.Tag

	// Password holds the password for the connecting entity.
	Password string
}

MongoInfo encapsulates information about cluster of servers holding juju state and can be used to make a connection to that cluster.

type WithAddresses

type WithAddresses interface {
	Addresses() []network.Address
}

WithAddresses represents an entity that has a set of addresses. e.g. a state Machine object

Jump to

Keyboard shortcuts

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