cloud

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2017 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package cloud wraps Google Cloud Platform APIs and provides functions to use it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileInfo

type FileInfo struct {
	// Name of the file, which means the base name.
	Name string
	// URL of the file. The scheme should be roadie://.
	URL *url.URL
	// TimeCreated is the time when the file was created.
	TimeCreated time.Time
	// Size of the file.
	Size int64
}

FileInfo defines file information structure.

type FileInfoHandler

type FileInfoHandler func(*FileInfo) error

FileInfoHandler is a handler to receive a file info.

type InstanceHandler added in v0.3.5

type InstanceHandler func(name, status string) error

InstanceHandler is a handler function to retrive instances' status.

type InstanceManager added in v0.3.5

type InstanceManager interface {
	// CreateInstance creates an instance which has a given name.
	CreateInstance(ctx context.Context, script *script.Script) error
	// DeleteInstance deletes the given named instance.
	DeleteInstance(ctx context.Context, name string) error
	// Instances returns a list of running instances
	Instances(ctx context.Context, handler InstanceHandler) error
}

InstanceManager is a service interface of an instance manager.

type LogHandler added in v0.3.5

type LogHandler func(timestamp time.Time, line string, stderr bool) error

LogHandler defines a hanler function for log entries.

type LogManager added in v0.3.5

type LogManager interface {
	// Get instance log.
	Get(ctx context.Context, instanceName string, after time.Time, handler LogHandler) error
	// Delete instance log.
	Delete(ctx context.Context, instanceName string) error
	// GetQueueLog retrievs log entries from a given queue.
	GetQueueLog(ctx context.Context, queue string, handler LogHandler) error
	// GetTaskLog retrieves log entries from a task in a queue.
	GetTaskLog(ctx context.Context, queue, task string, handler LogHandler) error
}

LogManager defines a service interface for obtaining log entries.

type MachineType

type MachineType struct {
	Name        string
	Description string
}

MachineType defines a structure of machine type infoemation.

type MetadataItem

type MetadataItem struct {
	Key   string
	Value string
}

MetadataItem has Key and Value properties.

type Provider added in v0.3.5

type Provider interface {
	// InstanceManager returns an instance manager interface.
	InstanceManager(context.Context) (InstanceManager, error)
	// QueueManager returns a queue manager interface.
	QueueManager(context.Context) (QueueManager, error)
	// StorageManager returns a storage manager interface.
	StorageManager(context.Context) (StorageManager, error)
	// LogManager returns a log manager interface.
	LogManager(context.Context) (LogManager, error)
	// ResourceManager returns a resource manager interface.
	ResourceManager(context.Context) (ResourceManager, error)
}

Provider is an interface of cloud service provider.

type QueueManager added in v0.3.5

type QueueManager interface {
	// Enqueue a new task to a given named queue.
	Enqueue(ctx context.Context, queue string, task *script.Script) error
	// Tasks retrieves tasks in a given names queue.
	Tasks(ctx context.Context, queue string, handler QueueManagerTaskHandler) error
	// Queues retrieves existing queue names.
	Queues(ctx context.Context, handler QueueStatusHandler) error
	// Stop executing tasks in a given named queue.
	Stop(ctx context.Context, queue string) error
	// Restart executing tasks in a given names queue.
	Restart(ctx context.Context, queue string) error
	// CreateWorkers creates worker instances working for a given named queue.
	CreateWorkers(ctx context.Context, queue string, n int, handler QueueManagerNameHandler) error
	// Workers retrieves worker instance names for a given queue.
	Workers(ctx context.Context, queue string, handler QueueManagerNameHandler) error
	// DeleteQueue deletes a given named queue.
	DeleteQueue(ctx context.Context, queue string) error
	// DeleteTask deletes a given named task in a given named queue.
	DeleteTask(ctx context.Context, queue, task string) error
}

QueueManager is a service interface of a queuing task manager.

type QueueManagerNameHandler added in v0.3.5

type QueueManagerNameHandler func(string) error

QueueManagerNameHandler is a type of handler function to retrieve names.

type QueueManagerTaskHandler added in v0.3.5

type QueueManagerTaskHandler func(name string, status string) error

QueueManagerTaskHandler is a type of handler function to retrieve tasks.

type QueueStatus added in v0.3.11

type QueueStatus struct {
	// The number of waiting tasks.
	Waiting int
	// The number of pending tasks.
	Pending int
	// The number of running tasks.
	Running int
	// The number of worker instances.
	Worker int
}

QueueStatus holds the numbers of waiting, pending, and running tasks in a queue. It also has the number of workers working for the queue, too.

type QueueStatusHandler added in v0.3.5

type QueueStatusHandler func(name string, status QueueStatus) error

QueueStatusHandler is a type of handler function to retrieve queues' stauts.

type Region added in v0.3.5

type Region struct {
	Name   string
	Status string
}

Region defines a structure of region information.

type ResourceManager added in v0.3.5

type ResourceManager interface {
	// GetProjectID returns an ID of the current project.
	GetProjectID() string
	// SetProjectID sets an ID to the current project.
	SetProjectID(string)
	// GetMachineType returns a machine type the current project uses by default.
	GetMachineType() string
	// SetMachineType sets a machine type as the default one.
	SetMachineType(string)
	// MachineTypes returns a set of available machine types.
	MachineTypes(context.Context) ([]MachineType, error)
	// GetRegion returns a region name the current project working on.
	GetRegion() string
	// SetRegion sets a region to the current project.
	SetRegion(string)
	// Regions returns a set of available regions.
	Regions(context.Context) ([]Region, error)
}

ResourceManager defines an interface for configuration to use a cloud service.

type Storage

type Storage struct {

	// TODO: Delete or update this.
	// Writer logs to be printed.
	Log io.Writer
	// contains filtered or unexported fields
}

Storage provides APIs to access a cloud storage.

func NewStorage

func NewStorage(servicer StorageManager, log io.Writer) (s *Storage)

NewStorage creates a cloud storage accessor with a given context.

func (*Storage) DeleteFiles

func (s *Storage) DeleteFiles(ctx context.Context, prefix *url.URL, queries []string) (err error)

DeleteFiles deletes files matching a given URL prefix and queries.

func (*Storage) DownloadFiles

func (s *Storage) DownloadFiles(ctx context.Context, prefix *url.URL, dir string, queries []string) (err error)

DownloadFiles downloads files matching a given prefix and queries. Downloaded files will be put in a given directory.

func (*Storage) ListupFiles

func (s *Storage) ListupFiles(ctx context.Context, loc *url.URL, handler FileInfoHandler) (err error)

ListupFiles lists up files which location is matching to a given URL. Information of found files will be passed to a handler. If the handler returns non nil value, the listing up will be canceled. In this case, this function also returns the given error value.

func (*Storage) PrintFileBody

func (s *Storage) PrintFileBody(ctx context.Context, prefix *url.URL, query string, output io.Writer, header bool) error

PrintFileBody prints file bodies which has a prefix and satisfies query. If header is ture, additional messages well be printed.

func (*Storage) UploadFile

func (s *Storage) UploadFile(ctx context.Context, loc *url.URL, input string) (err error)

UploadFile uploads a file where a given URL points.

type StorageManager added in v0.3.5

type StorageManager interface {

	// Upload a given stream to a given URL.
	Upload(ctx context.Context, loc *url.URL, in io.Reader) error

	// Download a file pointed by a given URL and write it to a given stream.
	Download(ctx context.Context, loc *url.URL, out io.Writer) error

	// GetFileInfo retrieves information of a file pointed by a given URL.
	GetFileInfo(ctx context.Context, loc *url.URL) (*FileInfo, error)

	// List up files of which URLs start with a given URL.
	// It takes a handler; information of found files are sent to it.
	List(ctx context.Context, loc *url.URL, handler FileInfoHandler) error

	// Delete a file pointed by a given URL.
	Delete(ctx context.Context, loc *url.URL) error
}

StorageManager defines methods which a storage service provider must provides. Each method takes a URL to point a file stored in this storage. The URL should be - roadie://category/path where category is one of - script.SourcePrefix - script.DataPrefix - script.ResultPrefix

Jump to

Keyboard shortcuts

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