datastore

package
v0.0.0-...-194264a Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2018 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package datastore retrieves stores data for the ciao controller. This package caches most data in memory, and uses a sql database as persistent storage.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoTenant            = errors.New("Tenant not found")
	ErrNoBlockData         = errors.New("Block Device not found")
	ErrNoStorageAttachment = errors.New("No Volume Attached")
)

custom errors

Functions

This section is empty.

Types

type Config

type Config struct {
	DBBackend         persistentStore
	PersistentURI     string
	InitWorkloadsPath string
}

Config contains configuration information for the datastore.

type Datastore

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

Datastore provides context for the datastore package.

func (*Datastore) AddBlockDevice

func (ds *Datastore) AddBlockDevice(device types.Volume) error

AddBlockDevice will store information about new BlockData into the datastore.

func (*Datastore) AddExternalIPs

func (ds *Datastore) AddExternalIPs(poolID string, IPs []string) error

AddExternalIPs will add a list of individual IPs to an existing pool.

func (*Datastore) AddExternalSubnet

func (ds *Datastore) AddExternalSubnet(poolID string, subnet string) error

AddExternalSubnet will add a new subnet to an existing pool.

func (*Datastore) AddImage

func (ds *Datastore) AddImage(i types.Image) error

AddImage adds an image to the datastore and database

func (*Datastore) AddInstance

func (ds *Datastore) AddInstance(instance *types.Instance) error

AddInstance will store a new instance in the datastore. The instance will be updated both in the cache and in the database

func (*Datastore) AddNode

func (ds *Datastore) AddNode(nodeID string, nodeType payloads.Resource)

AddNode adds a node into the node cache, updating the node's tracked role bitmask if the node is already present to be the superset of all reported roles.

func (*Datastore) AddPool

func (ds *Datastore) AddPool(pool types.Pool) error

AddPool will add a brand new pool to our datastore.

func (*Datastore) AddTenant

func (ds *Datastore) AddTenant(id string, config types.TenantConfig) (*types.Tenant, error)

AddTenant stores information about a tenant into the datastore. and makes sure that this new tenant is cached.

func (*Datastore) AddWorkload

func (ds *Datastore) AddWorkload(w types.Workload) error

AddWorkload is used to add a new workload to the datastore. Both cache and persistent store are updated.

func (*Datastore) AllocateTenantIP

func (ds *Datastore) AllocateTenantIP(tenantID string) (net.IP, error)

AllocateTenantIP will allocate a single IP address for a tenant.

func (*Datastore) AllocateTenantIPPool

func (ds *Datastore) AllocateTenantIPPool(tenantID string, num int) ([]net.IP, error)

AllocateTenantIPPool will reserve a pool of IP addresses for the caller.

func (*Datastore) AttachVolumeFailure

func (ds *Datastore) AttachVolumeFailure(instanceID string, volumeID string, reason payloads.AttachVolumeFailureReason) error

AttachVolumeFailure will clean up after a failure to attach a volume. The volume state will be changed back to available, and an error message will be logged.

func (*Datastore) ClearLog

func (ds *Datastore) ClearLog() error

ClearLog will remove all the event entries from the event log

func (*Datastore) CreateStorageAttachment

func (ds *Datastore) CreateStorageAttachment(instanceID string, volume payloads.StorageResource) (types.StorageAttachment, error)

CreateStorageAttachment will associate an instance with a block device in the datastore

func (*Datastore) DeleteBlockDevice

func (ds *Datastore) DeleteBlockDevice(ID string) error

DeleteBlockDevice will delete a volume from the datastore. It also deletes it from the tenant's list of devices.

func (*Datastore) DeleteExternalIP

func (ds *Datastore) DeleteExternalIP(poolID string, addrID string) error

DeleteExternalIP will remove an individual IP address from a pool.

func (*Datastore) DeleteImage

func (ds *Datastore) DeleteImage(ID string) error

DeleteImage deleted the image from the datastore and the database

func (*Datastore) DeleteInstance

func (ds *Datastore) DeleteInstance(instanceID string) error

DeleteInstance removes an instance from the datastore.

func (*Datastore) DeleteNode

func (ds *Datastore) DeleteNode(nodeID string) error

DeleteNode removes a node from the node cache.

func (*Datastore) DeletePool

func (ds *Datastore) DeletePool(ID string) error

DeletePool will delete an unused pool from our datastore.

func (*Datastore) DeleteStorageAttachment

func (ds *Datastore) DeleteStorageAttachment(ID string) error

DeleteStorageAttachment will delete the attachment with the associated ID from the datastore.

func (*Datastore) DeleteSubnet

func (ds *Datastore) DeleteSubnet(poolID string, subnetID string) error

DeleteSubnet will remove an unused subnet from an existing pool.

func (*Datastore) DeleteTenant

func (ds *Datastore) DeleteTenant(ID string) error

DeleteTenant removes a tenant from the datastore. It is the responsibility of the caller to ensure all tenant artifacts are removed first.

func (*Datastore) DeleteWorkload

func (ds *Datastore) DeleteWorkload(workloadID string) error

DeleteWorkload will delete an unused workload from the datastore. workload ID out of the datastore.

func (*Datastore) Exit

func (ds *Datastore) Exit()

Exit will disconnect the backing database.

func (*Datastore) GenerateCNCIWorkload

func (ds *Datastore) GenerateCNCIWorkload(vcpus int, memMB int, diskMB int, key string)

GenerateCNCIWorkload is used to create a workload definition for the CNCI. This function should be called prior to any workload launch.

func (*Datastore) GetAllCNCIInstances

func (ds *Datastore) GetAllCNCIInstances() ([]*types.Instance, error)

GetAllCNCIInstances retrieves all CNCI instances out of the datastore.

func (*Datastore) GetAllInstances

func (ds *Datastore) GetAllInstances() ([]*types.Instance, error)

GetAllInstances retrieves all tenant instances out of the datastore.

func (*Datastore) GetAllInstancesByNode

func (ds *Datastore) GetAllInstancesByNode(nodeID string) ([]*types.Instance, error)

GetAllInstancesByNode will retrieve all the instances running on a specific compute Node.

func (*Datastore) GetAllInstancesFromTenant

func (ds *Datastore) GetAllInstancesFromTenant(tenantID string) ([]*types.Instance, error)

GetAllInstancesFromTenant will retrieve all instances belonging to a specific tenant. This will exclude any CNCI instances.

func (*Datastore) GetAllTenants

func (ds *Datastore) GetAllTenants() ([]*types.Tenant, error)

GetAllTenants returns all the tenants from the datastore.

func (*Datastore) GetBatchFrameStatistics

func (ds *Datastore) GetBatchFrameStatistics(label string) ([]types.BatchFrameStat, error)

GetBatchFrameStatistics will show individual trace data per instance for a batch of trace data. The batch is identified by the label.

func (*Datastore) GetBatchFrameSummary

func (ds *Datastore) GetBatchFrameSummary() ([]types.BatchFrameSummary, error)

GetBatchFrameSummary will retieve the count of traces we have for a specific label

func (*Datastore) GetBlockDevice

func (ds *Datastore) GetBlockDevice(ID string) (types.Volume, error)

GetBlockDevice will return information about a block device from the datastore.

func (*Datastore) GetBlockDevices

func (ds *Datastore) GetBlockDevices(tenant string) ([]types.Volume, error)

GetBlockDevices will return all the BlockDevices associated with a tenant.

func (*Datastore) GetCNCIWorkloadID

func (ds *Datastore) GetCNCIWorkloadID() (string, error)

GetCNCIWorkloadID returns the UUID of the workload template for the CNCI workload

func (*Datastore) GetEventLog

func (ds *Datastore) GetEventLog() ([]*types.LogEntry, error)

GetEventLog retrieves all the log entries stored in the datastore.

func (*Datastore) GetImage

func (ds *Datastore) GetImage(ID string) (types.Image, error)

GetImage retrieves an image by ID

func (*Datastore) GetImages

func (ds *Datastore) GetImages(tenantID string, admin bool) ([]types.Image, error)

GetImages obtains the images available for the optional tenantID/admin combo

func (*Datastore) GetInstance

func (ds *Datastore) GetInstance(id string) (*types.Instance, error)

GetInstance retrieves an instance out of the datastore. The CNCI could be retrieved this way.

func (*Datastore) GetInstanceLastStats

func (ds *Datastore) GetInstanceLastStats(nodeID string) types.CiaoServersStats

GetInstanceLastStats retrieves the last instances stats received for this node. It returns it in a format suitable for the compute API.

func (*Datastore) GetMappedIP

func (ds *Datastore) GetMappedIP(address string) (types.MappedIP, error)

GetMappedIP will return a MappedIP struct for the given address.

func (*Datastore) GetMappedIPs

func (ds *Datastore) GetMappedIPs(tenant *string) []types.MappedIP

GetMappedIPs will return a list of mapped external IPs by tenant.

func (*Datastore) GetNode

func (ds *Datastore) GetNode(nodeID string) (types.Node, error)

GetNode retrieves a node in the node cache.

func (*Datastore) GetNodeLastStats

func (ds *Datastore) GetNodeLastStats() types.CiaoNodes

GetNodeLastStats retrieves the last nodes' stats received. It returns it in a format suitable for the compute API.

func (*Datastore) GetNodeSummary

func (ds *Datastore) GetNodeSummary() ([]*types.NodeSummary, error)

GetNodeSummary provides a summary the state and count of instances running per node.

func (*Datastore) GetPool

func (ds *Datastore) GetPool(ID string) (types.Pool, error)

GetPool will return an external IP Pool

func (*Datastore) GetPools

func (ds *Datastore) GetPools() ([]types.Pool, error)

GetPools will return a list of external IP Pools

func (*Datastore) GetQuotas

func (ds *Datastore) GetQuotas(tenantID string) ([]types.QuotaDetails, error)

GetQuotas returns the set of quotas from the database without any caching.

func (*Datastore) GetStorageAttachments

func (ds *Datastore) GetStorageAttachments(instanceID string) []types.StorageAttachment

GetStorageAttachments returns a list of volumes associated with this instance.

func (*Datastore) GetTenant

func (ds *Datastore) GetTenant(id string) (*types.Tenant, error)

GetTenant returns details about a tenant referenced by the uuid

func (*Datastore) GetTenantCNCISummary

func (ds *Datastore) GetTenantCNCISummary(cnciID string) ([]types.TenantCNCI, error)

GetTenantCNCISummary retrieves information about a given CNCI id, or all CNCIs If the cnci string is the null string, then this function will retrieve all tenants. If cnci is not null, it will only provide information about a specific cnci.

func (*Datastore) GetTenantCNCIs

func (ds *Datastore) GetTenantCNCIs(tenantID string) ([]*types.Instance, error)

GetTenantCNCIs will retrieve all CNCI instances belonging to a tenant

func (*Datastore) GetTenantInstance

func (ds *Datastore) GetTenantInstance(tenantID string, instanceID string) (*types.Instance, error)

GetTenantInstance retrieves a tenant instance out of the datastore. the CNCI will be excluded from this search.

func (*Datastore) GetTenantUsage

func (ds *Datastore) GetTenantUsage(tenantID string, start time.Time, end time.Time) ([]types.CiaoUsage, error)

GetTenantUsage provides statistics on actual resource usage. Usage is provided between a specified time period.

func (*Datastore) GetTenantWorkloads

func (ds *Datastore) GetTenantWorkloads(tenantID string) ([]types.Workload, error)

GetTenantWorkloads retrieves a list of private workloads.

func (*Datastore) GetVolumeAttachments

func (ds *Datastore) GetVolumeAttachments(volume string) ([]types.StorageAttachment, error)

GetVolumeAttachments will return a list of attachments associated with this volume ID.

func (*Datastore) GetWorkload

func (ds *Datastore) GetWorkload(ID string) (types.Workload, error)

GetWorkload returns details about a specific workload referenced by id

func (*Datastore) GetWorkloads

func (ds *Datastore) GetWorkloads(tenantID string) ([]types.Workload, error)

GetWorkloads retrieves the list of workloads for a particular tenant. if there are any public workloads, they will be included in the returned list.

func (*Datastore) HandleStats

func (ds *Datastore) HandleStats(stat payloads.Stat) error

HandleStats makes sure that the data from the stat payload is stored.

func (*Datastore) HandleTraceReport

func (ds *Datastore) HandleTraceReport(trace payloads.Trace) error

HandleTraceReport stores the provided trace data in the datastore.

func (*Datastore) Init

func (ds *Datastore) Init(config Config) error

Init initializes the private data for the Datastore object. The sql tables are populated with initial data from csv files if this is the first time the database has been created. The datastore caches are also filled.

func (*Datastore) InstanceRestarting

func (ds *Datastore) InstanceRestarting(instanceID string) error

InstanceRestarting resets a restarting instance's state to pending.

func (*Datastore) InstanceStopped

func (ds *Datastore) InstanceStopped(instanceID string) error

InstanceStopped removes the link between an instance and its node

func (*Datastore) JSONPatchTenant

func (ds *Datastore) JSONPatchTenant(ID string, patch []byte) error

JSONPatchTenant will update a tenant with changes from a json merge patch.

func (*Datastore) LogError

func (ds *Datastore) LogError(tenant string, msg string) error

LogError will add a message to the persistent event log as an error

func (*Datastore) LogEvent

func (ds *Datastore) LogEvent(tenant string, msg string) error

LogEvent will add a message to the persistent event log.

func (*Datastore) MapExternalIP

func (ds *Datastore) MapExternalIP(poolID string, instanceID string) (types.MappedIP, error)

MapExternalIP will allocate an external IP to an instance from a given pool.

func (*Datastore) ReleaseTenantIP

func (ds *Datastore) ReleaseTenantIP(tenantID string, ip string) error

ReleaseTenantIP will return an IP address previously allocated to the pool. Once a tenant IP address is released, it can be reassigned to another instance.

func (*Datastore) ResolveImage

func (ds *Datastore) ResolveImage(tenantID string, name string) (string, error)

ResolveImage retrieves an image by name or ID

func (*Datastore) ResolveInstance

func (ds *Datastore) ResolveInstance(tenantID string, name string) (string, error)

ResolveInstance maps an instance name to an uuid, returning "" if not found TODO: Replace this O(n) algorithm with another name to id map.

func (*Datastore) StartFailure

func (ds *Datastore) StartFailure(instanceID string, reason payloads.StartFailureReason, migration bool, nodeID string) error

StartFailure will clean up after a failure to start an instance. If an instance was a CNCI, this function will remove the CNCI instance for this tenant. If the instance was a normal tenant instance, the IP address will be released and the instance will be deleted from the datastore.

Only instances whose status is pending are removed when a StartFailure event is received. StartFailure errors may also be generated when restarting an exited instance and we want to make sure that a failure to restart such an instance does not result in it being deleted.

func (*Datastore) UnMapExternalIP

func (ds *Datastore) UnMapExternalIP(address string) error

UnMapExternalIP will stop associating a given address with an instance.

func (*Datastore) UpdateBlockDevice

func (ds *Datastore) UpdateBlockDevice(data types.Volume) error

UpdateBlockDevice will replace existing information about a block device in the datastore.

func (*Datastore) UpdateImage

func (ds *Datastore) UpdateImage(i types.Image) error

UpdateImage updates the image metadate in the datastore and database

func (*Datastore) UpdateInstance

func (ds *Datastore) UpdateInstance(instance *types.Instance) error

UpdateInstance will update certain fields of an instance

func (*Datastore) UpdateQuotas

func (ds *Datastore) UpdateQuotas(tenantID string, qds []types.QuotaDetails) error

UpdateQuotas updates the quotas for a tenant in the database.

type MemoryDB

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

MemoryDB is a memory backed persistentStore implementation for unit testing

Jump to

Keyboard shortcuts

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