charmstore

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2014 License: LGPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

This is the internal version of the charmstore package. It exposes details to the various API packages that we do not wish to expose to the world at large.

Index

Constants

View Source
const StatsGranularity = time.Minute

StatsGranularity holds the time granularity of statistics gathering. IncCounter(Async) calls within this duration may be aggregated.

Variables

This section is empty.

Functions

func NewServer

func NewServer(db *mgo.Database, es *elasticsearch.Index, config ServerParams, versions map[string]NewAPIHandlerFunc) (http.Handler, error)

NewServer returns a handler that serves the given charm store API versions using db to store that charm store data. The key of the versions map is the version name. The handler configuration is provided to all version handlers.

func NewZipFile

func NewZipFile(f *zip.File) (mongodoc.ZipFile, error)

NewZipFile returns a new mongodoc zip file reference to the given zip file.

func ReaderAtSeeker

func ReaderAtSeeker(r io.ReadSeeker) io.ReaderAt

ReaderAtSeeker adapts r so that it can be used as a ReaderAt. Note that, unlike some implementations of ReaderAt, it is not OK to use concurrently.

func ZipFileReader

func ZipFileReader(zipr io.ReadSeeker, f mongodoc.ZipFile) (io.Reader, error)

ZipFileReader returns a reader that will read content referred to by f within zipr, which should refer to the contents of a zip file,

Types

type AddParams

type AddParams struct {
	// URL holds the id to be associated with the stored entity.
	URL *charm.Reference

	// BlobName holds the name of the entity's archive blob.
	BlobName string

	// BlobHash holds the hash of the entity's archive blob.
	BlobHash string

	// BlobHash holds the size of the entity's archive blob.
	BlobSize int64

	// Contents holds references to files inside the
	// entity's archive blob.
	Contents map[mongodoc.FileId]mongodoc.ZipFile
}

AddParams holds parameters held in common between the Store.AddCharm and Store.AddBundle methods.

type Counter

type Counter struct {
	Key    []string
	Prefix bool
	Count  int64
	Time   time.Time
}

type CounterRequest

type CounterRequest struct {
	// Key and Prefix determine the counter keys to match.
	// If Prefix is false, Key must match exactly. Otherwise, counters
	// must begin with Key and have at least one more key token.
	Key    []string
	Prefix bool

	// If List is true, matching counters are aggregated under their
	// prefixes instead of being returned as a single overall sum.
	//
	// For example, given the following counts:
	//
	//   {"a", "b"}: 1,
	//   {"a", "c"}: 3
	//   {"a", "c", "d"}: 5
	//   {"a", "c", "e"}: 7
	//
	// and assuming that Prefix is true, the following keys will
	// present the respective results if List is true:
	//
	//        {"a"} => {{"a", "b"}, 1, false},
	//                 {{"a", "c"}, 3, false},
	//                 {{"a", "c"}, 12, true}
	//   {"a", "c"} => {{"a", "c", "d"}, 3, false},
	//                 {{"a", "c", "e"}, 5, false}
	//
	// If List is false, the same key prefixes will present:
	//
	//        {"a"} => {{"a"}, 16, true}
	//   {"a", "c"} => {{"a", "c"}, 12, false}
	//
	List bool

	// By defines the period covered by each aggregated data point.
	// If unspecified, it defaults to ByAll, which aggregates all
	// matching data points in a single entry.
	By CounterRequestBy

	// Start, if provided, changes the query so that only data points
	// ocurring at the given time or afterwards are considered.
	Start time.Time

	// Stop, if provided, changes the query so that only data points
	// ocurring at the given time or before are considered.
	Stop time.Time
}

CounterRequest represents a request to aggregate counter values.

type CounterRequestBy

type CounterRequestBy int
const (
	ByAll CounterRequestBy = iota
	ByDay
	ByWeek
)

type NewAPIHandlerFunc

type NewAPIHandlerFunc func(*Store, ServerParams) http.Handler

NewAPIHandlerFunc is a function that returns a new API handler that uses the given Store.

type SearchParams

type SearchParams struct {
	// The text to use in the full text search query.
	Text string
	// If autocomplete is specified, the search will return only charms and
	// bundles with a name that has text as a prefix.
	AutoComplete bool
	// Limit the search to items with attributes that match the specified filter value.
	Filters map[string][]string
	// Limit the number of returned items to the specified count.
	Limit int
	// Include the following metadata items in the search results
	Include []string
	// Start the the returned items at a specific offset
	Skip int
}

SearchParams represents the search parameters used to search the store.

type SearchResult

type SearchResult struct {
	SearchTime time.Duration
	Total      int
	Results    []*charm.Reference
}

SearchResult represents the result of performing a search.

type ServerParams

type ServerParams struct {
	AuthUsername string
	AuthPassword string
}

ServerParams holds configuration for a new internal API server.

type Store

type Store struct {
	DB        StoreDatabase
	BlobStore *blobstore.Store
	ES        *StoreElasticSearch
	// contains filtered or unexported fields
}

Store represents the underlying charm and blob data stores.

func NewStore

func NewStore(db *mgo.Database, ses *StoreElasticSearch) (*Store, error)

NewStore returns a Store that uses the given database.

func (*Store) AddBundle

func (s *Store) AddBundle(b charm.Bundle, p AddParams) error

AddBundle adds a bundle to the entities collection with the given parameters.

func (*Store) AddBundleWithArchive

func (s *Store) AddBundleWithArchive(url *charm.Reference, b charm.Bundle) error

AddBundleWithArchive is like AddBundle but also adds the charm archive to the blob store. This method is provided principally so that tests can easily create content in the store.

func (*Store) AddCharm

func (s *Store) AddCharm(c charm.Charm, p AddParams) (err error)

AddCharm adds a charm entities collection with the given parameters.

func (*Store) AddCharmWithArchive

func (s *Store) AddCharmWithArchive(url *charm.Reference, ch charm.Charm) error

AddCharmWithArchive is like AddCharm but also adds the charm archive to the blob store. This method is provided principally so that tests can easily create content in the store.

func (*Store) BlobNameAndHash

func (s *Store) BlobNameAndHash(id *charm.Reference) (name, hash string, err error)

BlobNameAndHash returns the name that is used to store the blob for the entity with the given id and its hash. It returns a params.ErrNotFound error if the entity does not exist.

func (*Store) Counters

func (s *Store) Counters(req *CounterRequest) ([]Counter, error)

Counters aggregates and returns counter values according to the provided request.

func (*Store) ExpandURL

func (s *Store) ExpandURL(url *charm.Reference) ([]*charm.Reference, error)

ExpandURL returns all the URLs that the given URL may refer to.

func (*Store) ExportToElasticSearch

func (store *Store) ExportToElasticSearch() error

ExportToElasticSearch reads all of the mongodoc Entities and writes them to elasticsearch

func (*Store) FindEntities

func (s *Store) FindEntities(url *charm.Reference, fields ...string) ([]*mongodoc.Entity, error)

FindEntities finds all entities in the store matching the given URL. If any fields are specified, only those fields will be populated in the returned entities.

func (*Store) FindEntity

func (s *Store) FindEntity(url *charm.Reference, fields ...string) (*mongodoc.Entity, error)

FindEntity finds the entity in the store with the given URL, which must be fully qualified. If any fields are specified, only those fields will be populated in the returned entities.

func (*Store) IncCounter

func (s *Store) IncCounter(key []string) error

IncCounter increases by one the counter associated with the composed key.

func (*Store) IncCounterAsync

func (s *Store) IncCounterAsync(key []string)

IncCounterAsync increases by one the counter associated with the composed key. The action is done in the background using a separate goroutine.

func (*Store) IncCounterAtTime

func (s *Store) IncCounterAtTime(key []string, t time.Time) error

IncCounterAtTime increases by one the counter associated with the composed key, associating it with the given time, which should be time.Now. This method is exposed for testing purposes only - production code should always call IncCounter or IncCounterAsync.

func (*Store) OpenBlob

func (s *Store) OpenBlob(id *charm.Reference) (r blobstore.ReadSeekCloser, size int64, hash string, err error)

OpenBlob opens a blob given its entity id; it returns the blob's data source, its size and its hash. It returns a params.ErrNotFound error if the entity does not exist.

func (*Store) OpenCachedBlobFile

func (s *Store) OpenCachedBlobFile(
	entity *mongodoc.Entity,
	fileId mongodoc.FileId,
	isFile func(f *zip.File) bool,
) (_ io.ReadCloser, err error)

OpenCachedBlobFile opens a file from the given entity's archive blob. The file is identified by the provided fileId. If the file has not previously been opened on this entity, the isFile function will be used to determine which file in the zip file to use. The result will be cached for the next time.

When retrieving the entity, at least the BlobName and Contents fields must be populated.

func (*Store) Search

func (store *Store) Search(sp SearchParams) (SearchResult, error)

Search searches the store for the given SearchParams. It returns a slice a SearchResult containing the results of the search.

type StoreDatabase

type StoreDatabase struct {
	*mgo.Database
}

StoreDatabase wraps an mgo.DB ands adds a few convenience methods.

func (StoreDatabase) Close

func (s StoreDatabase) Close()

Close closes the store database's underlying session.

func (StoreDatabase) Collections

func (s StoreDatabase) Collections() []*mgo.Collection

Collections returns a slice of all the collections used by the charm store.

func (StoreDatabase) Copy

func (s StoreDatabase) Copy() StoreDatabase

Copy copies the StoreDatabase and its underlying mgo session.

func (StoreDatabase) Entities

func (s StoreDatabase) Entities() *mgo.Collection

Entities returns the mongo collection where entities are stored.

func (StoreDatabase) StatCounters

func (s StoreDatabase) StatCounters() *mgo.Collection

func (StoreDatabase) StatTokens

func (s StoreDatabase) StatTokens() *mgo.Collection

type StoreElasticSearch

type StoreElasticSearch struct {
	*elasticsearch.Index
}

StoreElasticSearch provides strongly typed methods for accessing the elasticsearch database. These methods will not return errors if elasticsearch is not configured, allowing them to be safely called even if it is not enabled in this service.

Jump to

Keyboard shortcuts

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