model

package
v0.0.0-...-ba1c585 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2017 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package model defines functions for generating random sets of model databases, devices, and users that will be simulated in a syncbase longevity test.

Index

Constants

This section is empty.

Variables

View Source
var (
	LaptopSpec = DeviceSpec{
		MaxDatabases:      10,
		ConnectivitySpecs: []ConnectivitySpec{"online", "offline"},
	}

	PhoneSpec = DeviceSpec{
		MaxDatabases:      5,
		ConnectivitySpecs: []ConnectivitySpec{"online", "offline"},
	}

	CloudSpec = DeviceSpec{
		MaxDatabases:      100,
		ConnectivitySpecs: []ConnectivitySpec{"online"},
	}
)

Some common DeviceSpecs. It would be nice if these were consts, but go won't allow that.

Functions

This section is empty.

Types

type Collection

type Collection struct {
	// Name of the collection.
	Name string
	// Blessing of the collection.
	Blessing string
	// Permissions of the collection.
	Permissions Permissions
}

Collection represents a syncbase collection. TODO(nlacasse): Put syncgroups in here? It's a bit tricky because they need to have a host device name in their name, and the spec depends on the mounttable.

func (*Collection) Id

func (c *Collection) Id() wire.Id

func (*Collection) String

func (c *Collection) String() string

type CollectionSet

type CollectionSet []Collection

func (CollectionSet) String

func (cols CollectionSet) String() string

type ConnectivitySpec

type ConnectivitySpec string

ConnectivitySpec specifies the network connectivity of the device.

const (
	Online  ConnectivitySpec = "online"
	Offline ConnectivitySpec = "offline"
)

type Database

type Database struct {
	// Name of the database.
	Name string
	// Blessing of the database.
	Blessing string
	// Collections.
	Collections CollectionSet
	// Syncgroups.
	Syncgroups SyncgroupSet
	// Permissions.
	Permissions Permissions
}

Database represents a syncbase database. Each database corresponds to a single app.

func (*Database) Id

func (db *Database) Id() wire.Id

func (*Database) String

func (db *Database) String() string

type DatabaseSet

type DatabaseSet []*Database

DatabaseSet represents a set of Databases. TODO(nlacasse): Consider using a map here if uniqueness becomes an issue.

func GenerateDatabaseSet

func GenerateDatabaseSet(n int) DatabaseSet

GenerateDatabaseSet generates a DatabaseSet with n databases. TODO(nlacasse): Generate collections and syncgroups. TODO(nlacasse): Generate clients.

func (DatabaseSet) RandomSubset

func (dbs DatabaseSet) RandomSubset(min, max int) DatabaseSet

RandomSubset returns a random subset of the DatabaseSet with at least min and at most max databases.

func (DatabaseSet) String

func (dbs DatabaseSet) String() string

type Device

type Device struct {
	// Name of the device.
	Name string
	// Databases inluded on the device.
	Databases DatabaseSet
	// The device's spec.
	Spec DeviceSpec
	// Current connectivity spec for the device.  This value must be included
	// in Spec.ConnectivitySpecs.
	CurrentConnectivity ConnectivitySpec
	// Associated clients that will operate on this syncbase instance.  Clients
	// must be registered with control.RegisterClient.
	Clients []string
}

Device represents a device.

func (Device) String

func (d Device) String() string

type DeviceSet

type DeviceSet []*Device

DeviceSet is a set of devices. TODO(nlacasse): Consider using a map here if uniqueness becomes an issue.

func GenerateDeviceSet

func GenerateDeviceSet(n int, databases DatabaseSet, specs []DeviceSpec) DeviceSet

GenerateDeviceSet generates a device set of size n. The device spec for each device is chosen randomly from specs, and each device is given a non-empty set of databases taken from databases argument, obeying the maxium for the device spec.

func (DeviceSet) Lookup

func (ds DeviceSet) Lookup(name string) *Device

Lookup returns the first Device in the DeviceSet with the given name, or nil if none exists.

func (DeviceSet) String

func (ds DeviceSet) String() string

type DeviceSpec

type DeviceSpec struct {
	// Maximum number of databases allowed on the device.
	MaxDatabases int
	// Types of connectivity allowed for the database.
	ConnectivitySpecs []ConnectivitySpec
}

DeviceSpec specifies the possible types of devices.

type Permissions

type Permissions map[string]UserSet

Permissions maps tags to Users who are included on that tag. TODO(nlacasse): Consider allowing blacklisted users with "NotIn" lists.

func (Permissions) FilterTags

func (perms Permissions) FilterTags(allowTags ...access.Tag) Permissions

func (Permissions) ToWire

func (perms Permissions) ToWire(rootBlessing string) access.Permissions

type Syncgroup

type Syncgroup struct {
	HostDevice  *Device
	Name        string
	Blessing    string
	Description string
	Collections []Collection
	Permissions Permissions
	IsPrivate   bool
	// Devices which will attempt to create the syncgroup.
	CreatorDevices DeviceSet
	// Devices which will attempt to join the syncgroup.
	JoinerDevices DeviceSet
}

Syncgroup represents a syncgroup.

func (*Syncgroup) Id

func (sg *Syncgroup) Id() wire.Id

func (*Syncgroup) Spec

func (sg *Syncgroup) Spec(rootBlessing string) wire.SyncgroupSpec

func (*Syncgroup) String

func (sg *Syncgroup) String() string

type SyncgroupSet

type SyncgroupSet []Syncgroup

func (SyncgroupSet) String

func (sgs SyncgroupSet) String() string

type Topology

type Topology map[*Device]DeviceSet

Topology is an adjacency matrix specifying the connection type between devices. TODO(nlacasse): For now we only specify which devices are reachable by each device.

func GenerateTopology

func GenerateTopology(devices DeviceSet, affinity float64) Topology

GenerateTopology generates a Topology on the given DeviceSet. The affinity argument specifies the probability that any two devices are connected. We ensure that the generated topology is symmetric, but we do *not* guarantee that it is connected. TODO(nlacasse): Have more fine-grained affinity taking into account the DeviceSpec of each device. E.g. Desktop is likely to be connected to the cloud, but less likely to be connected to a watch.

func (Topology) String

func (top Topology) String() string

type Universe

type Universe struct {
	// All users in the universe.
	Users UserSet
	// Description of device connectivity.
	Topology Topology
}

func GenerateUniverse

func GenerateUniverse(opts UniverseOpts) Universe

func (*Universe) Databases

func (u *Universe) Databases() DatabaseSet

Databases returns all databases contained in the universe.

func (*Universe) String

func (u *Universe) String() string

type UniverseOpts

type UniverseOpts struct {
	// Probability that any two devices are connected
	DeviceAffinity float64
	// Maximum number of databases in the universe.
	MaxDatabases int
	// Number of users in the universe.
	NumUsers int
	// Maximum number of databases for any user.
	MaxDatabasesPerUser int
	// Maximum number of devices for any user.
	MaxDevicesPerUser int
	// Minimum number of devices for any user.
	MinDevicesPerUser int
}

UniverseOpts specifies the options to use when creating a random universe.

type User

type User struct {
	// The user's name.
	Name string
	// The user's devices.  All databases in the user's devices will be
	// included in the user's Databases.
	Devices DeviceSet
}

User represents a user.

func GenerateUser

func GenerateUser(dbs DatabaseSet, opts UserOpts) *User

GenerateUser generates a random user with nonempty set of databases from the given database set and n devices. TODO(nlacasse): Should DatabaseSet be in UserOpts?

func (*User) Databases

func (user *User) Databases() DatabaseSet

Databases returns all databases contained on the user's devices.

func (*User) String

func (user *User) String() string

type UserOpts

type UserOpts struct {
	MaxDatabases int
	MaxDevices   int
	MinDevices   int
}

UserOpts specifies the options to use when creating a random user.

type UserSet

type UserSet []*User

UserSet is a set of users.

Jump to

Keyboard shortcuts

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