rio

package
v0.0.0-...-b93919e Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2022 License: Apache-2.0 Imports: 6 Imported by: 16

Documentation

Index

Constants

View Source
const (
	ErrUsage                = ErrorCategory("rio-usage-error")           // Indicates some piece of user input to a command was invalid and unrunnable.
	ErrWarehouseUnavailable = ErrorCategory("rio-warehouse-unavailable") // Warehouse 404.
	ErrWarehouseUnwritable  = ErrorCategory("rio-warehouse-unwritable")  // Indicates a warehouse failed to accept a write operation.  The Warehouse is having a bad day.  ("unauthorized" is a different error category.)
	ErrWareNotFound         = ErrorCategory("rio-ware-not-found")        // Ware 404 -- warehouse appeared online, but the requested ware isn't in it.
	ErrWareCorrupt          = ErrorCategory("rio-ware-corrupt")          // Incidates a ware retreival started, but during unpacking it was found to be malformed.
	ErrWareHashMismatch     = ErrorCategory("rio-hash-mismatch")         // Returned when fetching and unpacking a ware gets results in a different content hash than we requested.  (This is distinct from ErrWareCorrupt because a full fileset *was* able to be unpacked; it's just not the one we asked for.)
	ErrCancelled            = ErrorCategory("rio-cancelled")             // The operation timed out or was cancelled
	ErrLocalCacheProblem    = ErrorCategory("rio-local-cache-problem")   // Indicates an error while either reading or writing to rio's local fileset caches.
	ErrAssemblyInvalid      = ErrorCategory("rio-assembly-invalid")      // Indicates an error in unpack or tree-unpack where the requested set of unpacks cannot assemble cleanly (e.g. a tree where a /file is a file and another unpack tries to seat something at /file/dir; this assembly is impossible).
	ErrPackInvalid          = ErrorCategory("rio-pack-invalid")          // Indicates a pack could not be performed, perhaps because you tried to pack a file using a format that must start with dirs, or because of permission errors or other misfortunes during the pack.
	ErrInoperablePath       = ErrorCategory("rio-inoperable-path")       // Indicates pack or unpack failed while reading or writing the target local filesystem path (permissions errors, etc, are likely causes).
	ErrFilterRejection      = ErrorCategory("rio-filter-rejection")      // Indicates filters rejected some part of a fileset, e.g. `rio pack tar /dev --filter dev=reject` will return this error.
	ErrRPCBreakdown         = ErrorCategory("rio-rpc-breakdown")         // Raised when running a remote rio process and the control channel is lost, the process fails to start, or unrecognized messages are received.
)

Variables

View Source
var ErrorTable = []struct {
	ExitCode int
	RioError ErrorCategory
}{
	{ExitCode: 1, RioError: ErrUsage},
	{ExitCode: 2, RioError: ""},
	{ExitCode: 3, RioError: ErrWarehouseUnavailable},
	{ExitCode: 4, RioError: ErrWarehouseUnwritable},
	{ExitCode: 5, RioError: ErrWareNotFound},
	{ExitCode: 6, RioError: ErrWareCorrupt},
	{ExitCode: 7, RioError: ErrWareHashMismatch},
	{ExitCode: 8, RioError: ErrCancelled},
	{ExitCode: 9, RioError: ErrLocalCacheProblem},
	{ExitCode: 10, RioError: ErrAssemblyInvalid},
	{ExitCode: 11, RioError: ErrPackInvalid},
	{ExitCode: 12, RioError: ErrInoperablePath},
	{ExitCode: 13, RioError: ErrFilterRejection},
	{ExitCode: 120, RioError: ErrRPCBreakdown},
}
View Source
var Error_AtlasEntry = atlas.BuildEntry(Error{}).StructMap().Autogenerate().Complete()
View Source
var Event_AtlasEntry = atlas.BuildEntry((*Event)(nil)).KeyedUnion().
	Of(map[string]*atlas.AtlasEntry{
		"log":    Event_Log_AtlasEntry,
		"prog":   Event_Progress_AtlasEntry,
		"result": Event_Result_AtlasEntry,
	})
View Source
var Event_Log_AtlasEntry = atlas.BuildEntry(Event_Log{}).StructMap().Autogenerate().Complete()
View Source
var Event_Progress_AtlasEntry = atlas.BuildEntry(Event_Progress{}).StructMap().Autogenerate().Complete()
View Source
var Event_Result_AtlasEntry = atlas.BuildEntry(Event_Result{}).StructMap().Autogenerate().Complete()

Functions

func ExitCodeForCategory

func ExitCodeForCategory(category interface{}) int

ExitCodeForCategory translates an errcat category into a numeric exit code.

func ExitCodeForError

func ExitCodeForError(err error) int

ExitCodeForError translates an error into a numeric exit code, looking up a code based on the errcat category of the error.

Types

type Error

type Error struct {
	Category_ ErrorCategory     `json:"category"          refmt:"category"`
	Message_  string            `json:"message"           refmt:"message"`
	Details_  map[string]string `json:"details,omitempty" refmt:"details,omitempty"`
}

Error implements the errcat.Error interface, specifically using this package's ErrorCategory as the concrete category, and giving us a type to hang custom serialization on.

func ToError

func ToError(err error) *Error

ToError converts any arbitrary error into the concrete rio.Error type. If it's an errcat.Error and already has a rio.ErrorCategory, this is lossless; if it's some other kind of error, we'll panic.

func (Error) Category

func (e Error) Category() interface{}

func (Error) Details

func (e Error) Details() map[string]string

func (Error) Error

func (e Error) Error() string

func (Error) Message

func (e Error) Message() string

type ErrorCategory

type ErrorCategory string

type Event

type Event interface {
	// contains filtered or unexported methods
}

A "union" type of all the kinds of event that may be generated in the course of any of the functions.

type Event_Log

type Event_Log struct {
	Time   time.Time   `refmt:"t"`
	Level  LogLevel    `refmt:"lvl"`
	Msg    string      `refmt:"msg"`
	Detail [][2]string `refmt:"detail,omitempty"`
}

Logs from rio code.

type Event_Progress

type Event_Progress struct {
	Phase, Desc          string
	TotalProg, TotalWork int
}

Notifications about progress updates.

Imagine it being used to draw the following:

Frobnozing (145/290kb): [=====>    ]  50%

The 'totalProg' and 'totalWork' ints are expected to be a percentage; when they equal, a "done" state should be up next. A value of 'totalProg' greater than 'totalWork' is nonsensical.

The 'phase' and 'desc' args are freetext; Typically, 'phase' will remain the same for many calls in a row, while 'desc' is used to communicate a more specific contextual info than the 'total*' ints and like the ints may likely change on each call.

type Event_Result

type Event_Result struct {
	WareID api.WareID `refmt:",omitempty"`
	Error  *Error     `refmt:",omitempty"`
}

Final results. (Also converted into returns.)

type LogLevel

type LogLevel int8
const (
	LogError LogLevel = 4 // Error log lines, if used, mean the program is on its way to exiting non-zero.  If used more than once, all but the first are other serious failures to clean up gracefully.
	LogWarn  LogLevel = 3 // Warning logs are for systems which have failed, but in acceptable ways; for example, a warehouse that's not online (but a fallback is, so overall we proceeded happily).
	LogInfo  LogLevel = 2 // Info logs are statements about control flow; for example, which warehouses have been tried in what order.
	LogDebug LogLevel = 1 // Debug logs are off by default.  They may get down to the resolution of called per-file in a transmat, for example.
)

func (LogLevel) String

func (ll LogLevel) String() string

type MirrorFunc

type MirrorFunc func(
	ctx context.Context,
	wareID api.WareID,
	saveTo api.WarehouseLocation,
	fetchFrom []api.WarehouseLocation,
	monitor Monitor,
) (api.WareID, error)

type Monitor

type Monitor struct {
	Chan chan<- Event
}

Monitor hold a channel which is used for event reporting. Logs will be sent to the channel if one is provided.

The same channel and monitor may be used for multiple runs. The channel is not closed when the job is done; any goroutine with blocking service to a channel used for a single job should return after recieving an Event_Result, as it will be the final event.

func (Monitor) Send

func (m Monitor) Send(evt Event)

type PackFunc

type PackFunc func(
	ctx context.Context,
	packType api.PackType,
	path string,
	filters api.FilesetPackFilter,
	saveTo api.WarehouseLocation,
	monitor Monitor,
) (api.WareID, error)

type PlacementMode

type PlacementMode string
const (
	// "none" mode instructs unpack not to place the files at all -- but it
	// still updates the fileset cache.  So, you can use this to warm up the
	// cache.  The target path argument to unpack will be ignored.
	Placement_None PlacementMode = "none"
	// "copy" mode -- the default -- instructs unpack to use the cache of
	// already unpacked filesets (unpacking there in case of cache miss), and
	// then place the files in their final location by a plain file copy.
	Placement_Copy PlacementMode = "copy"
	// "mount" mode instructs unpack to use the fileset cache (same as "copy"),
	// then place the files in their final location by using some sort of mount.
	// Whether "mount" means "bind", "aufs", "overlayfs", etc is left to
	// interpretation, but regardless it A) should be faster than "copy" and
	// B) since it's a mount, may be slightly harder to rmdir :)
	Placement_Mount PlacementMode = "mount"
	// "direct" mode instructs unpack to skip the cache and work directly in
	// the target path.  (It will still fall back to copy mode if the requested
	// ware is already in the fileset cache, "direct" is the one mode that
	// will not *populate* the fileset cache if empty.)
	Placement_Direct PlacementMode = "direct"
)

type ScanFunc

type ScanFunc func(
	ctx context.Context,
	packType api.PackType,
	filters api.FilesetUnpackFilter,
	placementMode PlacementMode,
	addr api.WarehouseLocation,
	monitor Monitor,
) (api.WareID, error)

type UnpackFunc

type UnpackFunc func(
	ctx context.Context,
	wareID api.WareID,
	path string,
	filters api.FilesetUnpackFilter,
	placementMode PlacementMode,
	fetchFrom []api.WarehouseLocation,
	monitor Monitor,
) (api.WareID, error)

Directories

Path Synopsis
client

Jump to

Keyboard shortcuts

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