server

package
v11.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2017 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Overview

Package server contains core functionality for our cache servers; storing & retrieving files etc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildGrpcServer

func BuildGrpcServer(port int, cache *Cache, cluster *cluster.Cluster, keyFile, certFile, caCertFile, readonlyKeys, writableKeys string) (*grpc.Server, net.Listener)

BuildGrpcServer creates a new, unstarted grpc.Server and returns it. It also returns a net.Listener to start it on.

func BuildRouter

func BuildRouter(cache *Cache) *mux.Router

BuildRouter creates a router, sets the base FileServer directory and the Handler Functions for each endpoint, and then returns the router.

func ServeGrpcForever

func ServeGrpcForever(server *grpc.Server, lis net.Listener)

ServeGrpcForever serves gRPC until killed using the given server. It's very simple and provided as a convenience so callers don't have to import grpc themselves.

Types

type Cache

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

A Cache is the underlying implementation of our HTTP and RPC caches that handles storing & retrieving artifacts.

func NewCache

func NewCache(path string, cleanFrequency, maxArtifactAge time.Duration, lowWaterMark, highWaterMark uint64) *Cache

NewCache initialises the cache and fires off a background cleaner goroutine which runs every cleanFrequency seconds. The high and low water marks control a (soft) max size and a (harder) minimum size.

func (*Cache) DeleteAllArtifacts

func (cache *Cache) DeleteAllArtifacts() error

DeleteAllArtifacts will remove all files in the cache directory. The function will return the first error found in the process, or nil if the process is successful.

func (*Cache) DeleteArtifact

func (cache *Cache) DeleteArtifact(artPath string) error

DeleteArtifact takes in the artifact path as a parameter and removes the artifact from disk. The function will return the first error found in the process, or nil if the process is successful.

func (*Cache) NumFiles

func (cache *Cache) NumFiles() int

NumFiles returns the number of files currently monitored by the cache.

func (*Cache) RetrieveArtifact

func (cache *Cache) RetrieveArtifact(artPath string) (map[string][]byte, error)

RetrieveArtifact takes in the artifact path as a parameter and checks in the base server file directory to see if the file exists in the given path. If found, the function will return whatever's been stored there, which might be a directory and therefore contain multiple files to be returned.

func (*Cache) StoreArtifact

func (cache *Cache) StoreArtifact(artPath string, key []byte) error

StoreArtifact takes in the artifact content and path as parameters and creates a file with the given content in the given path. The function will return the first error found in the process, or nil if the process is successful.

func (*Cache) StoreMetadata

func (cache *Cache) StoreMetadata(artPath, hostname, address, peer string) error

StoreMetadata stores some metadata about the given artifact in a simple format. This mostly just identifies where it came from.

func (*Cache) TotalSize

func (cache *Cache) TotalSize() int64

TotalSize returns the current total size monitored by the cache, in bytes.

type RPCCacheServer

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

A RPCCacheServer implements our RPC cache, including communication in a cluster.

func (*RPCCacheServer) Delete

Delete implements the Delete RPC to delete an artifact from the cache.

func (*RPCCacheServer) ListNodes

func (r *RPCCacheServer) ListNodes(ctx context.Context, req *pb.ListRequest) (*pb.ListResponse, error)

ListNodes implements the RPC for clustered servers.

func (*RPCCacheServer) Retrieve

Retrieve implements the Retrieve RPC to retrieve artifacts from the cache.

func (*RPCCacheServer) Store

Store implements the Store RPC to store an artifact in the cache.

type RPCServer

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

RPCServer implements the gRPC server for communication between cache nodes.

func (*RPCServer) Join

func (r *RPCServer) Join(ctx context.Context, req *pb.JoinRequest) (*pb.JoinResponse, error)

Join implements the Join RPC for a new server joining the cluster.

func (*RPCServer) Replicate

func (r *RPCServer) Replicate(ctx context.Context, req *pb.ReplicateRequest) (*pb.ReplicateResponse, error)

Replicate implements the Replicate RPC for replicating an artifact from another node.

Jump to

Keyboard shortcuts

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