cbfsclient

package
v0.0.0-...-93ebdcc Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2015 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Go client for cbfs

Most storage operations are simple HTTP PUT, GET or DELETE operations. Convenience operations are provided for easier access.

Index

Constants

This section is empty.

Variables

View Source
var Missing = errors.New("file missing")

When a file is missing.

Functions

This section is empty.

Types

type BlobInfo

type BlobInfo struct {
	// Map of node name -> last time the object was validated
	Nodes map[string]time.Time
}

Blob info as returned from GetBlobInfos

type Client

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

A cbfs client.

func New

func New(u string) (*Client, error)

Construct a new cbfs client.

func (*Client) Blobs

func (c *Client) Blobs(totalConcurrency, destinationConcurrency int,
	cb FetchCallback, oids ...string) error

Fetch many blobs in bulk.

func (Client) Get

func (c Client) Get(path string) (io.ReadCloser, error)

Grab a file.

This ensures the request is coming directly from a node that already has the blob vs. proxying.

func (Client) GetBlobInfos

func (c Client) GetBlobInfos(oids ...string) (map[string]BlobInfo, error)

Find out what nodes contain the given blobs.

func (Client) GetConfig

func (c Client) GetConfig() (rv cbfsconfig.CBFSConfig, err error)

Get the current configuration.

func (Client) List

func (c Client) List(ustr string) (ListResult, error)

func (Client) ListDepth

func (c Client) ListDepth(ustr string, depth int) (ListResult, error)

List the contents below the given location.

func (Client) ListOrEmpty

func (c Client) ListOrEmpty(ustr string) (ListResult, error)

Same as List, but return an empty result on 404.

func (*Client) Nodes

func (c *Client) Nodes() (map[string]StorageNode, error)

Get the information about the nodes in a cluster.

func (Client) OpenFile

func (c Client) OpenFile(path string) (*FileHandle, error)

Get a reference to the file at the given path.

func (Client) Put

func (c Client) Put(srcname, dest string, r io.Reader, opts PutOptions) error

Put some content in CBFS.

The sourcename is optional and is used for content type detection (if not specified in options).

The dest filename is the name that the file will have in cbfs.

The io.Reader is the source of content.

Options are optional.

func (*Client) RandomNode

func (c *Client) RandomNode() (string, StorageNode, error)

func (Client) Rm

func (c Client) Rm(fn string) error

func (Client) SetConfigParam

func (c Client) SetConfigParam(key, val string) error

Set a configuration parameter by name.

func (Client) URLFor

func (c Client) URLFor(fn string) string

Get the full URL for the given filename.

type Dir

type Dir struct {
	Descendants int   // Number of descendants.
	Largest     int64 // Size of largest file.
	Size        int64 // Total size of all files.
	Smallest    int64 // Size of smallest file.
}

Represents a directory as returned from a List operation.

type FetchCallback

type FetchCallback func(oid string, r io.Reader) error

type FileHandle

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

File info

func (*FileHandle) Close

func (f *FileHandle) Close() error

func (*FileHandle) IsDir

func (*FileHandle) IsDir() bool

false

func (*FileHandle) Meta

func (f *FileHandle) Meta() FileMeta

The headers from the file request.

func (*FileHandle) ModTime

func (f *FileHandle) ModTime() time.Time

Last modification time of this file

func (*FileHandle) Mode

func (*FileHandle) Mode() os.FileMode

file mode (0444)

func (*FileHandle) Name

func (f *FileHandle) Name() string

func (*FileHandle) Nodes

func (f *FileHandle) Nodes() map[string]time.Time

The nodes containing the files and the last time it was scrubed.

func (*FileHandle) Read

func (f *FileHandle) Read(b []byte) (int, error)

func (*FileHandle) ReadAt

func (f *FileHandle) ReadAt(p []byte, off int64) (n int, err error)

Implement io.ReaderAt

func (*FileHandle) Seek

func (f *FileHandle) Seek(offset int64, whence int) (ret int64, err error)

func (*FileHandle) Size

func (f *FileHandle) Size() int64

Length of this file

func (*FileHandle) Sys

func (*FileHandle) Sys() interface{}

nil

func (*FileHandle) WriteTo

func (f *FileHandle) WriteTo(w io.Writer) (int64, error)

Implement io.WriterTo

type FileMeta

type FileMeta struct {
	Headers http.Header `json:"headers"` // Headers
	OID     string      `json:"oid"`     // Hash
	Length  int64       `json:"length"`  // Length
	// User-supplied JSON
	Userdata *json.RawMessage `json:"userdata,omitempty"`
	// Last modified time
	Modified time.Time `json:"modified"`
	// Recorded previous versions
	Previous []PrevMeta `json:"older"`
	// Current revision number
	Revno int `json:"revno"`
}

Current file meta.

type ListResult

type ListResult struct {
	Dirs  map[string]Dir      // Immediate directories
	Files map[string]FileMeta // Immediate files
}

Results from a list operation.

type PrevMeta

type PrevMeta struct {
	Headers  http.Header `json:"headers"`  // Headers
	OID      string      `json:"oid"`      // Hash
	Length   float64     `json:"length"`   // Length
	Modified time.Time   `json:"modified"` // Modified date
	Revno    int         `json:"revno"`    // Revision number
}

Meta information from a previous revision of a file.

type PutOptions

type PutOptions struct {
	// If true, do a fast, unsafe store
	Unsafe bool
	// Expiration time
	Expiration int
	// Hash to verify ("" for no verification)
	Hash string
	// Content type (detected if not specified)
	ContentType string
	// Optional reader transform (e.g. for encryption)
	ContentTransform func(r io.Reader) io.Reader
	// contains filtered or unexported fields
}

Options for storing data.

func (*PutOptions) SetKeepRevs

func (p *PutOptions) SetKeepRevs(to int)

Specify the number of revs to keep of this object.

type StorageNode

type StorageNode struct {
	Addr      string
	AddrRaw   string    `json:"addr_raw"`
	Started   time.Time `json:"starttime"`
	HBTime    time.Time `json:"hbtime"`
	BindAddr  string
	FrameBind string
	HBAgeStr  string `json:"hbage_str"`
	Used      int64
	Free      int64
	Size      int64
	UptimeStr string `json:"uptime_str"`
	Version   string
}

Representation of a storage node.

func (StorageNode) BlobURL

func (a StorageNode) BlobURL(h string) string

func (StorageNode) URLFor

func (a StorageNode) URLFor(h string) string

Jump to

Keyboard shortcuts

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