devserver

package
v0.0.0-...-b5d9cbe Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: BSD-3-Clause Imports: 27 Imported by: 0

Documentation

Overview

Package devserver provides a client for devservers. For more information about devservers, see go/devserver-doc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseGSURL

func ParseGSURL(gsURL string) (bucket, path string, err error)

ParseGSURL parses a Google Cloud Storage URL. It is parsed as:

gs://<bucket>/<path>

Note that path is not prefixed with a slash, which is suitable for use with GCS APIs.

Types

type Client

type Client interface {
	// Open opens a file on Google Cloud Storage at gsURL. gsURL must have a "gs://" scheme.
	// Callers are responsible to close the/ returned io.ReadCloser after use.
	// If the file does not exist, os.ErrNotExist is returned.
	Open(ctx context.Context, gsURL string) (io.ReadCloser, error)

	// Stage opens a file on Google Cloud Storage at gsURL. sURL must have a "gs://" scheme.
	// Returns a http or file url to the data.
	Stage(ctx context.Context, gsURL string) (*url.URL, error)

	// TearDown should be called once when the Client is destructed,
	// regardless of whether Open was called or not.
	TearDown() error
}

Client is a client interface to communicate with devservers.

func NewClient

func NewClient(ctx context.Context, devservers []string,
	tlwServer, dutName, dutServer, swarmingTaskID, buildBucketID string) (Client, error)

NewClient creates a Client from a list of devservers, DUT server or a TLW server. If dutServer is non-empty, DUTServiceClient is returned. If tlwServer is non-empty, TLWClient is returned. If devserver contains 1 or more element, RealClient is returned. If the oth are empty, PseudoClient is returned.

type DUTServiceClient

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

DUTServiceClient is an implementation of Client to communicate with DUT Service API.

func NewDUTServiceClient

func NewDUTServiceClient(ctx context.Context, dutServer string) (*DUTServiceClient, error)

NewDUTServiceClient creates a DUTServiceClient.

func (*DUTServiceClient) Open

func (c *DUTServiceClient) Open(ctx context.Context, gsURL string) (io.ReadCloser, error)

Open downloads a file on GCS from storage.googleapis.com to specified destination and return io.ReadCloser for the file.

func (*DUTServiceClient) Stage

func (c *DUTServiceClient) Stage(ctx context.Context, gsURL string) (*url.URL, error)

Stage downloads a file on GCS from storage.googleapis.com to specified destination and return file: url for the file.

func (*DUTServiceClient) TearDown

func (c *DUTServiceClient) TearDown() error

TearDown closes the gRPC connection to the DUTService service.

type FakeClient

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

FakeClient is a fake implementation of devserver.Client suitable for unit tests.

func NewFakeClient

func NewFakeClient(files map[string][]byte) *FakeClient

NewFakeClient constructs a FakeClient. files is a map from GS URL to content.

func (*FakeClient) Open

func (c *FakeClient) Open(ctx context.Context, gsURL string) (io.ReadCloser, error)

Open simulates a download from Google Cloud Storage.

func (*FakeClient) Stage

func (c *FakeClient) Stage(ctx context.Context, gsURL string) (*url.URL, error)

Stage simulates a getting a url to Google Cloud Storage.

func (*FakeClient) TearDown

func (c *FakeClient) TearDown() error

TearDown does nothing.

type PseudoClient

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

PseudoClient is an implementation of Client to simulate devservers without credentials.

func NewPseudoClient

func NewPseudoClient(opts ...PseudoClientOption) *PseudoClient

NewPseudoClient creates a PseudoClient.

func (*PseudoClient) Open

func (c *PseudoClient) Open(ctx context.Context, gsURL string) (io.ReadCloser, error)

Open downloads a file on GCS directly from storage.googleapis.com.

func (*PseudoClient) Stage

func (c *PseudoClient) Stage(ctx context.Context, gsURL string) (*url.URL, error)

Stage returns a url to GCS directly from storage.googleapis.com.

func (*PseudoClient) TearDown

func (c *PseudoClient) TearDown() error

TearDown does nothing.

type PseudoClientOption

type PseudoClientOption func(o *pseudoClientOptions)

PseudoClientOption is an option accepted by NewPseudoClient to configure PseudoClient initialization.

func WithBaseURL

func WithBaseURL(baseURL string) PseudoClientOption

WithBaseURL returns an option that specifies the base URL of Google Cloud Storage HTTP API.

func WithHTTPClient

func WithHTTPClient(cl *http.Client) PseudoClientOption

WithHTTPClient returns an option that specifies http.Client used by PseudoClient.

type RealClient

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

RealClient is an implementation of Client to communicate with real devservers.

func NewRealClient

func NewRealClient(ctx context.Context, dsURLs []string, o *RealClientOptions) *RealClient

NewRealClient creates a RealClient. This function checks if devservers at dsURLs are up, and selects a subset of devservers to use. A devserver URL is usually in the form of "http://<hostname>:<port>", without trailing slashes. If we can not verify a devserver is up within ctx's timeout, it is considered down. Be sure to set ctx's timeout carefully since this function can block until it expires if any devserver is down. If o is nil, default options are used. If o is partially nil, defaults are used for them.

func (*RealClient) Open

func (c *RealClient) Open(ctx context.Context, gsURL string) (io.ReadCloser, error)

Open downloads a file on GCS via devservers. It returns an error if no devserver is up.

func (*RealClient) Stage

func (c *RealClient) Stage(ctx context.Context, gsURL string) (*url.URL, error)

Stage stages a file on GCS via devservers. It returns an error if no devserver is up.

func (*RealClient) Status

func (c *RealClient) Status() string

Status returns a message describing the status of devservers.

func (*RealClient) TearDown

func (c *RealClient) TearDown() error

TearDown does nothing.

func (*RealClient) UpServerURLs

func (c *RealClient) UpServerURLs() []string

UpServerURLs returns URLs of operational devservers.

type RealClientOptions

type RealClientOptions struct {
	// HTTPClient is HTTP client to use. If nil, defaultHTTPClient is used.
	HTTPClient *http.Client

	// StageRetryWaits instructs retry strategy for stage.
	// Its length is the number of retries and the i-th value is the interval before i-th retry.
	// If nil, default strategy is used. If zero-length slice, no retry is attempted.
	StageRetryWaits []time.Duration

	// SwarmingTaskID specifies the task ID of the scheduled job that run Tast tests.
	SwarmingTaskID string

	// BuildBucketID specifies the build bucket ID for the schedule job that run Tast tests
	BuildBucketID string
}

RealClientOptions contains options used when connecting to devserver.

type TLWClient

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

TLWClient is an implementation of Client to communicate with Test Lab Services wiring API.

func NewTLWClient

func NewTLWClient(ctx context.Context, tlwserver, dutName string) (*TLWClient, error)

NewTLWClient creates a TLWClient.

func (*TLWClient) Open

func (c *TLWClient) Open(ctx context.Context, gsURL string) (io.ReadCloser, error)

Open downloads a file on GCS from storage.googleapis.com using the TLW API.

func (*TLWClient) Stage

func (c *TLWClient) Stage(ctx context.Context, gsURL string) (*url.URL, error)

Stage downloads a file on GCS from storage.googleapis.com using the TLW API.

func (*TLWClient) TearDown

func (c *TLWClient) TearDown() error

TearDown closes the gRPC connection to the TLW service.

Directories

Path Synopsis
Package devservertest provides a fake implementation of devservers.
Package devservertest provides a fake implementation of devservers.

Jump to

Keyboard shortcuts

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