Documentation ¶
Overview ¶
Package gcp provides implementations of interfaces defined in cloud package.
Index ¶
- Constants
- Variables
- func CreateURL(cfg *Config, name string) string
- func GenerateCodeVerifier() (codeVerifier []byte, err error)
- func NewAuthorizationConfig(port int) *oauth2.Config
- func ReplaceURLScheme(cfg *Config, task *script.Script)
- func RequestToken(ctx context.Context, output io.Writer) (token *oauth2.Token, err error)
- type ActivityPayload
- type ActivityPayloadHandler
- type ComputeService
- func (s *ComputeService) AvailableMachineTypes(ctx context.Context) (types []cloud.MachineType, err error)
- func (s *ComputeService) AvailableRegions(ctx context.Context) (regions []cloud.Region, err error)
- func (s *ComputeService) CreateInstance(ctx context.Context, task *script.Script) (err error)
- func (s *ComputeService) DeleteInstance(ctx context.Context, name string) (err error)
- func (s *ComputeService) Instances(ctx context.Context, handler cloud.InstanceHandler) (err error)
- type Config
- type EntryHandler
- type IgnitionConfig
- type IgnitionVersion
- type LogManager
- func (s *LogManager) Delete(ctx context.Context, instanceName string) error
- func (s *LogManager) Entries(ctx context.Context, filter string, handler EntryHandler) (err error)
- func (s *LogManager) Get(ctx context.Context, instanceName string, from time.Time, ...) (err error)
- func (s *LogManager) GetQueueLog(ctx context.Context, queue string, handler cloud.LogHandler) (err error)
- func (s *LogManager) GetTaskLog(ctx context.Context, queue, task string, handler cloud.LogHandler) (err error)
- func (s *LogManager) InstanceLogEntries(ctx context.Context, instanceName string, from time.Time, ...) error
- func (s *LogManager) OperationLogEntries(ctx context.Context, from time.Time, handler ActivityPayloadHandler) error
- type Provider
- func (p *Provider) InstanceManager(ctx context.Context) (cloud.InstanceManager, error)
- func (p *Provider) LogManager(ctx context.Context) (cloud.LogManager, error)
- func (p *Provider) QueueManager(ctx context.Context) (cloud.QueueManager, error)
- func (p *Provider) ResourceManager(ctx context.Context) (cloud.ResourceManager, error)
- func (p *Provider) StorageManager(ctx context.Context) (cloud.StorageManager, error)
- type QueueService
- func (s *QueueService) CreateWorkers(ctx context.Context, queue string, n int, ...) (err error)
- func (s *QueueService) DeleteQueue(ctx context.Context, queue string) (err error)
- func (s *QueueService) DeleteTask(ctx context.Context, queue, task string) (err error)
- func (s *QueueService) Enqueue(ctx context.Context, queue string, task *script.Script) (err error)
- func (s *QueueService) Fetch(ctx context.Context, queue string) (task *Task, err error)
- func (s *QueueService) Queues(ctx context.Context, handler cloud.QueueStatusHandler) (err error)
- func (s *QueueService) Restart(ctx context.Context, queue string) (err error)
- func (s *QueueService) Stop(ctx context.Context, queue string) error
- func (s *QueueService) Tasks(ctx context.Context, queue string, handler cloud.QueueManagerTaskHandler) (err error)
- func (s *QueueService) UpdateTask(ctx context.Context, queue string, modifier func(*Task) *Task) (err error)
- func (s *QueueService) Workers(ctx context.Context, queue string, handler cloud.QueueManagerNameHandler) (err error)
- type ResourceService
- func (m *ResourceService) GetMachineType() string
- func (m *ResourceService) GetProjectID() string
- func (m *ResourceService) GetRegion() string
- func (m *ResourceService) MachineTypes(ctx context.Context) ([]cloud.MachineType, error)
- func (m *ResourceService) Regions(ctx context.Context) ([]cloud.Region, error)
- func (m *ResourceService) SetMachineType(t string)
- func (m *ResourceService) SetProjectID(id string)
- func (m *ResourceService) SetRegion(region string)
- type RoadiePayloadHandler
- type StorageService
- func (s *StorageService) Delete(ctx context.Context, loc *url.URL) (err error)
- func (s *StorageService) Download(ctx context.Context, loc *url.URL, out io.Writer) (err error)
- func (s *StorageService) GetFileInfo(ctx context.Context, loc *url.URL) (info *cloud.FileInfo, err error)
- func (s *StorageService) List(ctx context.Context, loc *url.URL, handler cloud.FileInfoHandler) (err error)
- func (s *StorageService) Upload(ctx context.Context, loc *url.URL, in io.Reader) (err error)
- type SystemdConfig
- type SystemdUnit
- type Task
Constants ¶
const ( // AuthSucceedURL is a page showing authentication success. AuthSucceedURL = "https://jkawamoto.github.io/roadie/auth/succeed/" // AuthErrorURL is a page showing authentication error. AuthErrorURL = "https://jkawamoto.github.io/roadie/auth/error/" )
const ( // StoragePrefix is a prefix used to store related data into the cloud // storage. StoragePrefix = ".roadie" // DefaultZone defines the default zone. DefaultZone = "us-central1-b" // DefaultMachineType defines the default machine type. DefaultMachineType = "n1-standard-1" // DefaultDiskSize defines the default disk size. DefaultDiskSize = 10 // DefaultBaseImage defines the default base image for sandbox containers. DefaultBaseImage = "jkawamoto/roadie-gcp" // LogTimeFormat defines time format of Google Logging. LogTimeFormat = "2006-01-02T15:04:05Z" // LogEventSubtypeInsert means this event is creating an instance. LogEventSubtypeInsert = "compute.instances.insert" // LogEventSubtypeDelete means this event is deleting an instance. LogEventSubtypeDelete = "compute.instances.delete" // StatusRunning is a status representing an instance is running. StatusRunning = "running" // StatusTerminated is a status representing an instance is terminated. StatusTerminated = "terminated" )
const ( // QueueKind defines kind of entries stored in cloud datastore. QueueKind = "roadie-queue" // QueueManagerVersion defines the version of queue manager to be used. QueueManagerVersion = "0.2.3" )
const ( // TaskStatusWaiting represents a task is waiting to be run. TaskStatusWaiting = "waiting" // TaskStatusRunning represents a task is running. TaskStatusRunning = "running" // TaskStatusPending represents a task is pending to be run. TaskStatusPending = "pending" )
const (
// DefaultIgnitionVersion defines the version of ignition configuration.
DefaultIgnitionVersion = "2.0.0"
)
const (
// SourceImage defines the ID of the source image to be used for instance.
SourceImage = "projects/coreos-cloud/global/images/coreos-stable-1298-7-0-v20170401"
)
Variables ¶
var ( // CodeVerifierChars defines a set of characters used to generate a code verifier. CodeVerifierChars []byte )
var ( // RegexpCommentLine defines a regular expression for a comment line. RegexpCommentLine = regexp.MustCompile("#.*\n") )
var ( // RoadieSchemeURLOffset defines an offset value to remove scheme name from // URLs. RoadieSchemeURLOffset = len(script.RoadieSchemePrefix) )
Functions ¶
func GenerateCodeVerifier ¶ added in v0.3.6
GenerateCodeVerifier generates a plain code verifier.
func NewAuthorizationConfig ¶ added in v0.3.6
NewAuthorizationConfig creates a new configuration for authorization.
func ReplaceURLScheme ¶
ReplaceURLScheme replaced URLs which start with "roadie://". Those URLs are modified to "gs://<bucketname>/.roadie/".
Types ¶
type ActivityPayload ¶
type ActivityPayload struct { EventTimestampUs string `structpb:"event_timestamp_us"` EventType string `structpb:"vent_type"` TraceID string `structpb:"trace_id"` Actor struct { User string } Resource struct { Zone string Type string ID string Name string } Version string EventSubtype string `structpb:"event_subtype"` Operation struct { Zone string Type string ID string Name string } }
ActivityPayload defines the payload structure of activity log.
func NewActivityPayload ¶
func NewActivityPayload(payload interface{}) (res *ActivityPayload, err error)
NewActivityPayload converts LogEntry's payload to a ActivityPayload.
type ActivityPayloadHandler ¶
type ActivityPayloadHandler func(time.Time, *ActivityPayload) error
ActivityPayloadHandler is a function type to handle ActivityPayloads.
type ComputeService ¶
ComputeService implements cloud.InstanceManager based on Google Cloud Platform.
func NewComputeService ¶
func NewComputeService(cfg *Config, logger *log.Logger) *ComputeService
NewComputeService creates a new compute service client.
func (*ComputeService) AvailableMachineTypes ¶
func (s *ComputeService) AvailableMachineTypes(ctx context.Context) (types []cloud.MachineType, err error)
AvailableMachineTypes returns a slice of machie type names.
func (*ComputeService) AvailableRegions ¶
AvailableRegions returns a slice of region information.
func (*ComputeService) CreateInstance ¶
CreateInstance creates a new instance based on the builder's configuration.
func (*ComputeService) DeleteInstance ¶
func (s *ComputeService) DeleteInstance(ctx context.Context, name string) (err error)
DeleteInstance deletes a given named instance.
func (*ComputeService) Instances ¶
func (s *ComputeService) Instances(ctx context.Context, handler cloud.InstanceHandler) (err error)
Instances is different from instances and sends names of instances which are not working for any queue into the given handler.
type Config ¶
type Config struct { // Project name. Project string `yaml:"project"` // Bucket name Bucket string `yaml:"bucket"` // Zone where instances will run. Zone string `yaml:"zone"` // Default machine type of new instances. MachineType string `yaml:"machine_type"` // Instance disk size. DiskSize int64 `yaml:"disk_size,omitempty"` // If true, instances will not shutdown automatically. NoShutdown bool `yaml:"no_shutdown,omitempty"` // Authorization token. Token *oauth2.Token `yaml:"token,omitempty"` }
Config defines information to access Google Cloud Platform.
func (*Config) UnmarshalYAML ¶
UnmarshalYAML helps to unmarshal Config objects.
type EntryHandler ¶
EntryHandler is a function type to handler Entries.
type IgnitionConfig ¶
type IgnitionConfig struct { Ignition IgnitionVersion `json:"ignition,omitempty"` Systemd SystemdConfig `json:"systemd,omitempty"` }
IgnitionConfig defines a simple structure for ignition config file which has only systemd's unit configurations.
{ "ignition": { "version": "2.0.0" }, "systemd": { "units": [{ "name": "example.service", "enable": true, "contents": "[Service]\nType=oneshot\nExecStart=/usr/bin/echo Hello World\n\n[Install]\nWantedBy=multi-user.target" }] } }
func NewIgnitionConfig ¶
func NewIgnitionConfig() *IgnitionConfig
NewIgnitionConfig creates a new ignition configuration.
func (*IgnitionConfig) Append ¶
func (c *IgnitionConfig) Append(unit SystemdUnit) *IgnitionConfig
Append a new unit and returns updated this configuration.
func (*IgnitionConfig) String ¶
func (c *IgnitionConfig) String() string
String marshals this config to a JSON string.
type IgnitionVersion ¶
type IgnitionVersion struct {
Version string `json:"version,omitempty"`
}
IgnitionVersion is configuration of ignition version.
type LogManager ¶
type LogManager struct { // Config is a reference for a configuration of GCP. Config *Config Logger *log.Logger SleepTime time.Duration }
LogManager implements cloud.LogManager interface. It requests logs to google cloud logging service.
func NewLogManager ¶
func NewLogManager(cfg *Config, logger *log.Logger) (m *LogManager)
NewLogManager creates a new log manager.
func (*LogManager) Delete ¶
func (s *LogManager) Delete(ctx context.Context, instanceName string) error
Delete doesn't do anything.
func (*LogManager) Entries ¶
func (s *LogManager) Entries(ctx context.Context, filter string, handler EntryHandler) (err error)
Entries get log entries matching with a given filter from given project logs. Found log entries will be passed a given handler one by one. If the handler returns non-nil value as an error, this function will end.
func (*LogManager) Get ¶
func (s *LogManager) Get(ctx context.Context, instanceName string, from time.Time, handler cloud.LogHandler) (err error)
Get requests log entries of the given named instance.
func (*LogManager) GetQueueLog ¶
func (s *LogManager) GetQueueLog(ctx context.Context, queue string, handler cloud.LogHandler) (err error)
GetQueueLog retrieves log entries from a queue.
func (*LogManager) GetTaskLog ¶
func (s *LogManager) GetTaskLog(ctx context.Context, queue, task string, handler cloud.LogHandler) (err error)
GetTaskLog retrieves log entries for a task in a queue.
func (*LogManager) InstanceLogEntries ¶
func (s *LogManager) InstanceLogEntries(ctx context.Context, instanceName string, from time.Time, handler RoadiePayloadHandler) error
InstanceLogEntries requests log entries of a given instance. Obtained log entries will be passed a given handler entry by entry. If the handler returns non nil value, obtaining log entries is canceled immediately.
func (*LogManager) OperationLogEntries ¶
func (s *LogManager) OperationLogEntries(ctx context.Context, from time.Time, handler ActivityPayloadHandler) error
OperationLogEntries requests log entries about google cloud platform operations. Obtained log entries will be passed a given handler entry by entry. If the handler returns non nil value, obtaining log entries is canceled immediately.
type Provider ¶
Provider defines information for the service provider for GCP.
func NewProvider ¶
func NewProvider(ctx context.Context, cfg *Config, logger *log.Logger, forceAuth bool) (p *Provider, err error)
NewProvider creates a new provider for GCP service.
func (*Provider) InstanceManager ¶
InstanceManager returns an instance manager interface.
func (*Provider) LogManager ¶
LogManager returns a log manager interface.
func (*Provider) QueueManager ¶
QueueManager returns a queue manager interface.
func (*Provider) ResourceManager ¶
ResourceManager returns a resource manager interface.
func (*Provider) StorageManager ¶
StorageManager returns a storage manager interface.
type QueueService ¶
QueueService implements cloud.QueueManager based on Google Cloud Datastore.
func NewQueueService ¶
NewQueueService creates an interface for a queue service based on Google Cloud Datastore.
func (*QueueService) CreateWorkers ¶
func (s *QueueService) CreateWorkers(ctx context.Context, queue string, n int, handler cloud.QueueManagerNameHandler) (err error)
CreateWorkers creates worker instances working for a given named queue.
func (*QueueService) DeleteQueue ¶
func (s *QueueService) DeleteQueue(ctx context.Context, queue string) (err error)
DeleteQueue deletes a given named queue. This function deletes all tasks in a given queue and deletes all workers for that queue.
func (*QueueService) DeleteTask ¶
func (s *QueueService) DeleteTask(ctx context.Context, queue, task string) (err error)
DeleteTask deletes a given named task in a given named queue.
func (*QueueService) Fetch ¶
Fetch retrieves one task from a queue and returns it; status of the returned task is updated to running. If there is no task, return nil with nil error.
func (*QueueService) Queues ¶
func (s *QueueService) Queues(ctx context.Context, handler cloud.QueueStatusHandler) (err error)
Queues retrieves existing queue names.
func (*QueueService) Restart ¶
func (s *QueueService) Restart(ctx context.Context, queue string) (err error)
Restart executing tasks in a queue which has a given name.
func (*QueueService) Stop ¶
func (s *QueueService) Stop(ctx context.Context, queue string) error
Stop executing tasks in a queue which has a given name.
func (*QueueService) Tasks ¶
func (s *QueueService) Tasks(ctx context.Context, queue string, handler cloud.QueueManagerTaskHandler) (err error)
Tasks retrieves tasks in a given names queue.
func (*QueueService) UpdateTask ¶
func (s *QueueService) UpdateTask(ctx context.Context, queue string, modifier func(*Task) *Task) (err error)
UpdateTask updates tasks in a given named queue with a given modifier.
func (*QueueService) Workers ¶
func (s *QueueService) Workers(ctx context.Context, queue string, handler cloud.QueueManagerNameHandler) (err error)
Workers retrieves worker instance names for a given queue.
type ResourceService ¶
ResourceService is a service to get and set cloud configuration.
func NewResourceService ¶
func NewResourceService(cfg *Config, logger *log.Logger) *ResourceService
NewResourceService creates a new resource service.
func (*ResourceService) GetMachineType ¶
func (m *ResourceService) GetMachineType() string
GetMachineType returns a machine type the current project uses by default.
func (*ResourceService) GetProjectID ¶
func (m *ResourceService) GetProjectID() string
GetProjectID returns an ID of the current project.
func (*ResourceService) GetRegion ¶
func (m *ResourceService) GetRegion() string
GetRegion returns a region name the current project working on.
func (*ResourceService) MachineTypes ¶
func (m *ResourceService) MachineTypes(ctx context.Context) ([]cloud.MachineType, error)
MachineTypes returns a set of available machine types.
func (*ResourceService) SetMachineType ¶
func (m *ResourceService) SetMachineType(t string)
SetMachineType sets a machine type as the default one.
func (*ResourceService) SetProjectID ¶
func (m *ResourceService) SetProjectID(id string)
SetProjectID sets an ID to the current project.
func (*ResourceService) SetRegion ¶
func (m *ResourceService) SetRegion(region string)
SetRegion sets a region to the current project.
type RoadiePayloadHandler ¶
RoadiePayloadHandler is a function type to handle RoadiePayloads.
type StorageService ¶
type StorageService struct { // Config is a reference for a configuration of GCP. Config *Config // Logger Logger *log.Logger }
StorageService implements cloud.StorageServicer interface for accessing GCP's cloud storage.
func NewStorageService ¶
func NewStorageService(ctx context.Context, cfg *Config, logger *log.Logger) (s *StorageService, err error)
NewStorageService creates a new storage accessor to a bucket specified in a given configuration.
func (*StorageService) GetFileInfo ¶
func (s *StorageService) GetFileInfo(ctx context.Context, loc *url.URL) (info *cloud.FileInfo, err error)
GetFileInfo returns a file status of an object.
func (*StorageService) List ¶
func (s *StorageService) List(ctx context.Context, loc *url.URL, handler cloud.FileInfoHandler) (err error)
List searches items, i.e. files and folders, matching a given prefix. Found items will be passed to a given handler item by item. If the handler returns a non nil value, listing up will be canceled. In that case, this function will also return the given value.
type SystemdConfig ¶
type SystemdConfig struct {
Units []SystemdUnit `json:"units,omitempty"`
}
SystemdConfig defines a set of units to be set up.
type SystemdUnit ¶
type SystemdUnit struct { Name string `json:"name,omitempty"` Enable bool `json:"enable,omitempty"` Contents string `json:"contents,omitempty"` }
SystemdUnit is configuration for a systemd unit.
func FluentdUnit ¶
func FluentdUnit(name string) (unit SystemdUnit, err error)
FluentdUnit creates a new SystemdUnit for fluentd.
func LogcastUnit ¶
func LogcastUnit(service string) (unit SystemdUnit, err error)
LogcastUnit creates a new unit for forwarding log to Fluentd.
func QueueManagerUnit ¶
func QueueManagerUnit(project, version, queueName string) (unit SystemdUnit, err error)
QueueManagerUnit creates a new unit for Roadie queue manager.
func RoadieUnit ¶
func RoadieUnit(name, image, options string) (unit SystemdUnit, err error)
RoadieUnit creates a new SystemdUnit for roadie-gcp.
type Task ¶
type Task struct { // Name of this task. Name string `yaml:"name,omitempty"` // The script body. Script *script.Script `yaml:"script,omitempty"` // Queue name. QueueName string `yaml:"queue-name"` // Status of this task Status string `yaml:"status"` }
Task defines a data structure of enqueued script file.