pfsmodules

package
v0.1.1-beta.3 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2017 License: Apache-2.0 Imports: 22 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// DefaultMultiPartBoundary is the default multipart form boudary.
	DefaultMultiPartBoundary = "8d7b0e5709d756e21e971ff4d9ac3b20"

	// MaxJSONRequestSize is the max body size when server receives a request.
	MaxJSONRequestSize = 2048
)
View Source
const (
	// StatusFileNotFound is a error string of that there is no file or directory.
	StatusFileNotFound = "no such file or directory"
	// StatusDirectoryNotAFile is a error string of that the destination should be a file.
	StatusDirectoryNotAFile = "should be a file not a directory"
	// StatusCopyFromLocalToLocal is a error string of that this system does't support copy local to local.
	StatusCopyFromLocalToLocal = "don't support copy local to local"
	// StatusDestShouldBeDirectory is a error string of that destination shoule be a directory.
	StatusDestShouldBeDirectory = "dest should be a directory"
	// StatusOnlySupportFiles is a error string of that the system only support upload or download files not directories.
	StatusOnlySupportFiles = "only support upload or download files not directories"
	// StatusBadFileSize is a error string of that the file size is no valid.
	StatusBadFileSize = "bad file size"
	// StatusDirectoryAlreadyExist is a error string of that the directory is already exist.
	StatusDirectoryAlreadyExist = "directory already exist"
	// StatusBadChunkSize is a error string of that the chunksize is error.
	StatusBadChunkSize = "chunksize error"
	// StatusShouldBePfsPath is a error string of that a path should be a pfs path.
	StatusShouldBePfsPath = "should be pfs path"
	// StatusNotEnoughArgs is a error string of that there is not enough arguments.
	StatusNotEnoughArgs = "not enough arguments"
	// StatusInvalidArgs is a error string of that arguments are not valid.
	StatusInvalidArgs = "invalid arguments"
	// StatusUnAuthorized is a error string of that what you request should have authorization.
	StatusUnAuthorized = "what you request is unauthorized"
	// StatusJSONErr is a error string of that the system parses json error.
	StatusJSONErr = "parse json error"
	// StatusCannotDelDirectory is a error string of that what you input can't delete a directory.
	StatusCannotDelDirectory = "can't del directory"
	// StatusAlreadyExist is a error string of that the destination is already exist.
	StatusAlreadyExist = "already exist"
	// StatusBadPath is a error string of that the form of path is not correct.
	StatusBadPath = "the path should be in format eg:/pf/datacentername/"
)
View Source
const (
	// ChunkMetaCmdName is the name of GetChunkMeta command.
	ChunkMetaCmdName = "GetChunkMeta"
)
View Source
const (
	// StatCmdName means stat command name.
	StatCmdName = "stat"
)
View Source
const (
	// TouchCmdName is the name of touch command.
	TouchCmdName = "touch"
)

Variables

Config is global config object for pfs commandline

Functions

func Close

func Close(c io.Closer)

Close closes c and log it.

func CreateSizedFile

func CreateSizedFile(path string, size int64) error

CreateSizedFile creates a file with specified size.

func IsCloudPath

func IsCloudPath(path string) bool

IsCloudPath returns whether a path is a pfspath.

func RunCp

func RunCp(cmd *CpCmd) error

RunCp runs CpCmd.

func ValidatePfsPath

func ValidatePfsPath(paths []string, userName string) error

ValidatePfsPath returns whether a path is a pfspath.

Types

type Chunk

type Chunk struct {
	Path   string
	Offset int64
	Size   int64
}

Chunk respresents a chunk info.

func ParseChunk

func ParseChunk(path string) (*Chunk, error)

ParseChunk get a Chunk struct from path. path example:

path=/pfs/datacenter1/1.txt&offset=4096&chunksize=4096

func (*Chunk) LoadChunkData

func (p *Chunk) LoadChunkData(w io.Writer) error

LoadChunkData loads a specified chunk to io.Writer.

func (*Chunk) SaveChunkData

func (p *Chunk) SaveChunkData(r io.Reader) error

SaveChunkData save data from io.Reader.

func (*Chunk) ToURLParam

func (p *Chunk) ToURLParam() url.Values

ToURLParam encodes variables to url encoding parameters.

type ChunkMeta

type ChunkMeta struct {
	Offset   int64  `json:"offset"`
	Checksum string `json:"checksum"`
	Len      int64  `json:"len"`
}

ChunkMeta holds the chunk meta's info.

func GetChunkMeta

func GetChunkMeta(path string, len int64) ([]ChunkMeta, error)

GetChunkMeta gets chunk metas from path of file.

func GetDiffChunkMeta

func GetDiffChunkMeta(srcMeta []ChunkMeta, dstMeta []ChunkMeta) ([]ChunkMeta, error)

GetDiffChunkMeta gets difference between srcMeta and dstMeta.

type ChunkMetaCmd

type ChunkMetaCmd struct {
	Method    string `json:"method"`
	FilePath  string `json:"path"`
	ChunkSize int64  `json:"chunksize"`
}

ChunkMetaCmd is a command.

func NewChunkMetaCmdFromURLParam

func NewChunkMetaCmdFromURLParam(r *http.Request) (*ChunkMetaCmd, error)

NewChunkMetaCmdFromURLParam get a new ChunkMetaCmd.

func (*ChunkMetaCmd) Run

func (p *ChunkMetaCmd) Run() (interface{}, error)

Run is a functions which run ChunkMetaCmd.

func (*ChunkMetaCmd) ToJSON

func (p *ChunkMetaCmd) ToJSON() ([]byte, error)

ToJSON encodes ChunkMetaCmd to JSON string.

func (*ChunkMetaCmd) ToURLParam

func (p *ChunkMetaCmd) ToURLParam() url.Values

ToURLParam encodes ChunkMetaCmd to URL encoding string.

func (*ChunkMetaCmd) ValidateCloudArgs

func (p *ChunkMetaCmd) ValidateCloudArgs(userName string) error

ValidateCloudArgs checks the conditions when running on cloud.

func (*ChunkMetaCmd) ValidateLocalArgs

func (p *ChunkMetaCmd) ValidateLocalArgs() error

ValidateLocalArgs checks the conditions when running locally.

type Command

type Command interface {
	// ToURLParam generates url.Values of the command struct.
	ToURLParam() url.Values
	// ToJSON generates JSON string of the command struct.
	ToJSON() ([]byte, error)
	// Run runs a command.
	Run() (interface{}, error)
	// ValidateLocalArgs validates arguments when running locally.
	ValidateLocalArgs() error
	// ValidateCloudArgs validates arguments when running on cloud.
	ValidateCloudArgs(userName string) error
}

Command is a interface of all commands.

type CpCmd

type CpCmd struct {
	Method string
	V      bool
	Src    []string
	Dst    string
}

CpCmd means copy-command.

func (*CpCmd) Execute

func (p *CpCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus

Execute runs CpCmd.

func (*CpCmd) Name

func (*CpCmd) Name() string

Name returns CpCmd's name.

func (*CpCmd) PartToString

func (p *CpCmd) PartToString(src, dst string) string

PartToString prints command's info.

func (*CpCmd) SetFlags

func (p *CpCmd) SetFlags(f *flag.FlagSet)

SetFlags sets CpCmd's parameter.

func (*CpCmd) Synopsis

func (*CpCmd) Synopsis() string

Synopsis returns synopsis of CpCmd.

func (*CpCmd) Usage

func (*CpCmd) Usage() string

Usage returns usage of CpCmd.

type CpCmdResult

type CpCmdResult struct {
	Src string `json:"Path"`
	Dst string `json:"Dst"`
}

CpCmdResult means the copy-command's result.

type LsCmd

type LsCmd struct {
	Method string
	R      bool
	Args   []string
}

LsCmd means LsCmd structure.

func NewLsCmd

func NewLsCmd(r bool, path string) *LsCmd

NewLsCmd return a new LsCmd according r and path variable.

func NewLsCmdFromURLParam

func NewLsCmdFromURLParam(path string) (*LsCmd, error)

NewLsCmdFromURLParam returns a new LsCmd according path variable.

func (*LsCmd) Execute

func (p *LsCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus

Execute runs a LsCmd.

func (*LsCmd) Name

func (*LsCmd) Name() string

Name returns LsCmd's name.

func (*LsCmd) Run

func (p *LsCmd) Run() (interface{}, error)

Run functions runs LsCmd and return LsResult and error if any happened.

func (*LsCmd) SetFlags

func (p *LsCmd) SetFlags(f *flag.FlagSet)

SetFlags sets LsCmd's parameters.

func (*LsCmd) Synopsis

func (*LsCmd) Synopsis() string

Synopsis returns Synopsis of LsCmd.

func (*LsCmd) ToJSON

func (p *LsCmd) ToJSON() ([]byte, error)

ToJSON does't need to be implemented.

func (*LsCmd) ToURLParam

func (p *LsCmd) ToURLParam() url.Values

ToURLParam encoding LsCmd to URL Encoding string.

func (*LsCmd) Usage

func (*LsCmd) Usage() string

Usage returns usage of LsCmd.

func (*LsCmd) ValidateCloudArgs

func (p *LsCmd) ValidateCloudArgs(userName string) error

ValidateCloudArgs checks the conditions when running on cloud.

func (*LsCmd) ValidateLocalArgs

func (p *LsCmd) ValidateLocalArgs() error

ValidateLocalArgs checks the conditions when running local.

type LsResult

type LsResult struct {
	Path    string `json:"Path"`
	ModTime int64  `json:"ModTime"`
	Size    int64  `json:"Size"`
	IsDir   bool   `json:"IsDir"`
}

LsResult represents a LsCmd's result.

func RemoteLs

func RemoteLs(cmd *LsCmd) ([]LsResult, error)

RemoteLs gets LsCmd result from cloud.

type MkdirCmd

type MkdirCmd struct {
	Method string   `json:"method"`
	Args   []string `json:"path"`
}

MkdirCmd means Mkdir command.

func NewMkdirCmd

func NewMkdirCmd(path string) *MkdirCmd

NewMkdirCmd returns a new MkdirCmd.

func (*MkdirCmd) Execute

func (p *MkdirCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus

Execute runs a MkdirCmd.

func (*MkdirCmd) Name

func (*MkdirCmd) Name() string

Name returns name of MkdirComand.

func (*MkdirCmd) Run

func (p *MkdirCmd) Run() (interface{}, error)

Run runs MkdirCmd.

func (*MkdirCmd) SetFlags

func (p *MkdirCmd) SetFlags(f *flag.FlagSet)

SetFlags sets MkdirCmd's parameters.

func (*MkdirCmd) Synopsis

func (*MkdirCmd) Synopsis() string

Synopsis returns synopsis of MkdirCmd.

func (*MkdirCmd) ToJSON

func (p *MkdirCmd) ToJSON() ([]byte, error)

ToJSON encodes MkdirCmd to JSON string.

func (*MkdirCmd) ToURLParam

func (p *MkdirCmd) ToURLParam() url.Values

ToURLParam need not to be implemented.

func (*MkdirCmd) Usage

func (*MkdirCmd) Usage() string

Usage returns usage of MkdirCmd.

func (*MkdirCmd) ValidateCloudArgs

func (p *MkdirCmd) ValidateCloudArgs(userName string) error

ValidateCloudArgs checks the conditions when running on cloud.

func (*MkdirCmd) ValidateLocalArgs

func (p *MkdirCmd) ValidateLocalArgs() error

ValidateLocalArgs checks the conditions when running on local.

type MkdirResult

type MkdirResult struct {
	Path string `json:"path"`
}

MkdirResult means Mkdir command's result.

func RemoteMkdir

func RemoteMkdir(cmd *MkdirCmd) ([]MkdirResult, error)

RemoteMkdir creat a directory on cloud.

type RmCmd

type RmCmd struct {
	Method string   `json:"method"`
	R      bool     `json:"r"`
	Args   []string `json:"path"`
}

RmCmd means Rm command.

func NewRmCmd

func NewRmCmd(r bool, path string) *RmCmd

NewRmCmd returns a new RmCmd.

func (*RmCmd) Execute

func (p *RmCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus

Execute runs a RmCmd.

func (*RmCmd) Name

func (*RmCmd) Name() string

Name returns RmCmd's name.

func (*RmCmd) Run

func (p *RmCmd) Run() (interface{}, error)

Run runs RmCmd.

func (*RmCmd) SetFlags

func (p *RmCmd) SetFlags(f *flag.FlagSet)

SetFlags sets RmCmd's parameters.

func (*RmCmd) Synopsis

func (*RmCmd) Synopsis() string

Synopsis returns synopsis of RmCmd.

func (*RmCmd) ToJSON

func (p *RmCmd) ToJSON() ([]byte, error)

ToJSON encodes RmCmd to JSON string.

func (*RmCmd) ToURLParam

func (p *RmCmd) ToURLParam() url.Values

ToURLParam needs not to be implemented.

func (*RmCmd) Usage

func (*RmCmd) Usage() string

Usage returns usage of RmCmd.

func (*RmCmd) ValidateCloudArgs

func (p *RmCmd) ValidateCloudArgs(userName string) error

ValidateCloudArgs checks the conditions when running on cloud.

func (*RmCmd) ValidateLocalArgs

func (p *RmCmd) ValidateLocalArgs() error

ValidateLocalArgs checks the conditions when running local.

type RmResult

type RmResult struct {
	Path string `json:"path"`
}

RmResult means Rm-command's result.

func RemoteRm

func RemoteRm(cmd *RmCmd) ([]RmResult, error)

RemoteRm gets RmCmd Result from cloud.

type StatCmd

type StatCmd struct {
	Method string
	Path   string
}

StatCmd means stat command.

func NewStatCmdFromURLParam

func NewStatCmdFromURLParam(path string) (*StatCmd, error)

NewStatCmdFromURLParam return a new StatCmd.

func (*StatCmd) Run

func (p *StatCmd) Run() (interface{}, error)

Run runs the StatCmd.

func (*StatCmd) ToJSON

func (p *StatCmd) ToJSON() ([]byte, error)

ToJSON here need not tobe implemented.

func (*StatCmd) ToURLParam

func (p *StatCmd) ToURLParam() url.Values

ToURLParam encodes StatCmd to URL Encoding string.

func (*StatCmd) ValidateCloudArgs

func (p *StatCmd) ValidateCloudArgs(userName string) error

ValidateCloudArgs checks the conditions when running on cloud.

func (*StatCmd) ValidateLocalArgs

func (p *StatCmd) ValidateLocalArgs() error

ValidateLocalArgs checks the condition when running local.

type TouchCmd

type TouchCmd struct {
	Method   string `json:"method"`
	FileSize int64  `json:"filesize"`
	Path     string `json:"path"`
}

TouchCmd is holds touch command's variables.

func NewTouchCmdFromURLParam

func NewTouchCmdFromURLParam(path string) (*TouchCmd, int32)

NewTouchCmdFromURLParam return a new TouchCmd with specified path.

func (*TouchCmd) Run

func (p *TouchCmd) Run() (interface{}, error)

Run is a function runs TouchCmd.

func (*TouchCmd) ToJSON

func (p *TouchCmd) ToJSON() ([]byte, error)

ToJSON encodes a TouchCmd to a JSON string.

func (*TouchCmd) ToURLParam

func (p *TouchCmd) ToURLParam() url.Values

ToURLParam encodes a TouchCmd to a URL encoding string.

func (*TouchCmd) ValidateCloudArgs

func (p *TouchCmd) ValidateCloudArgs(userName string) error

ValidateCloudArgs checks the conditions when running on cloud.

func (*TouchCmd) ValidateLocalArgs

func (p *TouchCmd) ValidateLocalArgs() error

ValidateLocalArgs check the conditions when running local.

type TouchResult

type TouchResult struct {
	Path string `json:"path"`
}

TouchResult represents touch-command's result.

Jump to

Keyboard shortcuts

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