libhoclient

package module
v0.0.0-...-ab11291 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0, MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HTTPHeaderBuildAPICreds              = "X-Cutf-Host-Orchestrator-BuildAPI-Creds"
	HTTPHeaderBuildAPICredsUserProjectID = "X-Cutf-Host-Orchestrator-BuildAPI-Creds-User-Project-ID"
	// If used, the Cloud Orchestrator proxy would set/override the "X-Cutf-Host-Orchestrator-BuildAPI-Creds"
	// http header.
	HTTPHeaderCOInjectBuildAPICreds = "X-Cutf-Cloud-Orchestrator-Inject-BuildAPI-Creds"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessTokenBuildAPICreds

type AccessTokenBuildAPICreds struct {
	AccessToken   string
	UserProjectID string
}

func (*AccessTokenBuildAPICreds) ApplyToHTTPRequest

func (c *AccessTokenBuildAPICreds) ApplyToHTTPRequest(rb *HTTPRequestBuilder)

type ApiCallError

type ApiCallError struct {
	Code     int    `json:"code,omitempty"`
	ErrorMsg string `json:"error,omitempty"`
	Details  string `json:"details,omitempty"`
}

func (*ApiCallError) Error

func (e *ApiCallError) Error() string

type BuildAPICreds

type BuildAPICreds interface {
	ApplyToHTTPRequest(rb *HTTPRequestBuilder)
}

type ConnectWebRTCOpts

type ConnectWebRTCOpts struct {
	LocalICEConfig *wclient.ICEConfig
}

type ExpBackOffOptions

type ExpBackOffOptions struct {
	InitialDuration     time.Duration
	RandomizationFactor float64
	Multiplier          float64
	MaxElapsedTime      time.Duration
}

type FilesUploader

type FilesUploader struct {
	HTTPHelper HTTPHelper
	UploadDir  string
	DumpOut    io.Writer
	UploadOptions
}

func (*FilesUploader) Upload

func (u *FilesUploader) Upload(files []string) error

type HTTPHelper

type HTTPHelper struct {
	Client            *http.Client
	RootEndpoint      string
	Dumpster          io.Writer
	AccessToken       string
	HTTPBasicUsername string
}

func (*HTTPHelper) NewDeleteRequest

func (h *HTTPHelper) NewDeleteRequest(path string) *HTTPRequestBuilder

func (*HTTPHelper) NewGetRequest

func (h *HTTPHelper) NewGetRequest(path string) *HTTPRequestBuilder

func (*HTTPHelper) NewPostRequest

func (h *HTTPHelper) NewPostRequest(path string, jsonBody any) *HTTPRequestBuilder

func (*HTTPHelper) NewUploadFileRequest

func (h *HTTPHelper) NewUploadFileRequest(ctx context.Context, path string, body io.Reader, contentType string) *HTTPRequestBuilder

type HTTPRequestBuilder

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

func (*HTTPRequestBuilder) AddHeader

func (rb *HTTPRequestBuilder) AddHeader(key, value string)

func (*HTTPRequestBuilder) Do

func (rb *HTTPRequestBuilder) Do() (*http.Response, error)

func (*HTTPRequestBuilder) JSONResDo

func (rb *HTTPRequestBuilder) JSONResDo(ret any) error

Expects a response with JSON body to be decoded into `ret`.

func (*HTTPRequestBuilder) JSONResDoWithRetries

func (rb *HTTPRequestBuilder) JSONResDoWithRetries(ret any, retryOpts RetryOptions) error

Expects a response with JSON body to be decoded into `ret`.

func (*HTTPRequestBuilder) SetBasicAuth

func (rb *HTTPRequestBuilder) SetBasicAuth()

func (*HTTPRequestBuilder) SetHeader

func (rb *HTTPRequestBuilder) SetHeader(key, value string)

type HostOrchestratorService

type HostOrchestratorService interface {
	// Lists currently running devices.
	ListCVDs() ([]*hoapi.CVD, error)

	// Creates a directory in the host where user artifacts can be uploaded to.
	CreateUploadDir() (string, error)

	// Uploads file into the given directory.
	UploadFile(uploadDir string, filename string) error
	UploadFileWithOptions(uploadDir string, filename string, options UploadOptions) error

	// Extracts a compressed file.
	ExtractFile(uploadDir string, filename string) (*hoapi.Operation, error)

	// Create a new device with artifacts from the build server or previously uploaded by the user.
	// If not empty, the provided credentials will be used to download necessary artifacts from the build api.
	CreateCVD(req *hoapi.CreateCVDRequest, creds BuildAPICreds) (*hoapi.CreateCVDResponse, error)
	CreateCVDOp(req *hoapi.CreateCVDRequest, creds BuildAPICreds) (*hoapi.Operation, error)

	// Deletes an existing cvd instance.
	DeleteCVD(id string) error

	// Calls cvd fetch in the remote host, the downloaded artifacts can be used to create a CVD later.
	// If not empty, the provided credentials will be used by the host orchestrator to access the build api.
	FetchArtifacts(req *hoapi.FetchArtifactsRequest, creds BuildAPICreds) (*hoapi.FetchArtifactsResponse, error)

	// Creates a webRTC connection to a device running in this host.
	ConnectWebRTC(device string, observer wclient.Observer, logger io.Writer, opts ConnectWebRTCOpts) (*wclient.Connection, error)

	// Connect to ADB WebSocket endpoint.
	ConnectADBWebSocket(device string) (*websocket.Conn, error)

	// Wait for an operation, `result` will be populated with the relevant operation's result object.
	WaitForOperation(name string, result any) error

	// Create cvd bugreport.
	CreateBugreport(group string, dst io.Writer) error

	// Powerwash the device.
	Powerwash(groupName, instanceName string) error

	// Stop the device.
	Stop(groupName, instanceName string) error

	// Start the device.
	Start(groupName, instanceName string, req *hoapi.StartCVDRequest) error

	// Create device snapshot.
	CreateSnapshot(groupName, instanceName string) (*hoapi.CreateSnapshotResponse, error)
}

A client to the host orchestrator service running in a remote host.

func NewHostOrchestratorService

func NewHostOrchestratorService(url string) HostOrchestratorService

type HostOrchestratorServiceImpl

type HostOrchestratorServiceImpl struct {
	HTTPHelper HTTPHelper
	ProxyURL   string
}

func (*HostOrchestratorServiceImpl) ConnectADBWebSocket

func (c *HostOrchestratorServiceImpl) ConnectADBWebSocket(device string) (*websocket.Conn, error)

func (*HostOrchestratorServiceImpl) ConnectWebRTC

func (c *HostOrchestratorServiceImpl) ConnectWebRTC(device string, observer wclient.Observer, logger io.Writer, opts ConnectWebRTCOpts) (*wclient.Connection, error)

func (*HostOrchestratorServiceImpl) CreateBugreport

func (c *HostOrchestratorServiceImpl) CreateBugreport(group string, dst io.Writer) error

func (*HostOrchestratorServiceImpl) CreateCVD

func (*HostOrchestratorServiceImpl) CreateCVDOp

func (*HostOrchestratorServiceImpl) CreateSnapshot

func (c *HostOrchestratorServiceImpl) CreateSnapshot(groupName, instanceName string) (*hoapi.CreateSnapshotResponse, error)

func (*HostOrchestratorServiceImpl) CreateUploadDir

func (c *HostOrchestratorServiceImpl) CreateUploadDir() (string, error)

func (*HostOrchestratorServiceImpl) DeleteCVD

func (c *HostOrchestratorServiceImpl) DeleteCVD(id string) error

func (*HostOrchestratorServiceImpl) ExtractFile

func (c *HostOrchestratorServiceImpl) ExtractFile(uploadDir string, filename string) (*hoapi.Operation, error)

func (*HostOrchestratorServiceImpl) FetchArtifacts

func (*HostOrchestratorServiceImpl) ListCVDs

func (c *HostOrchestratorServiceImpl) ListCVDs() ([]*hoapi.CVD, error)

func (*HostOrchestratorServiceImpl) Powerwash

func (c *HostOrchestratorServiceImpl) Powerwash(groupName, instanceName string) error

func (*HostOrchestratorServiceImpl) Start

func (c *HostOrchestratorServiceImpl) Start(groupName, instanceName string, req *hoapi.StartCVDRequest) error

func (*HostOrchestratorServiceImpl) Stop

func (c *HostOrchestratorServiceImpl) Stop(groupName, instanceName string) error

func (*HostOrchestratorServiceImpl) UploadFile

func (c *HostOrchestratorServiceImpl) UploadFile(uploadDir string, filename string) error

func (*HostOrchestratorServiceImpl) UploadFileWithOptions

func (c *HostOrchestratorServiceImpl) UploadFileWithOptions(uploadDir string, filename string, uploadOpts UploadOptions) error

func (*HostOrchestratorServiceImpl) WaitForOperation

func (c *HostOrchestratorServiceImpl) WaitForOperation(name string, res any) error

type RetryOptions

type RetryOptions struct {
	StatusCodes []int
	RetryDelay  time.Duration
	// Keep retrying until the MaxWait threshold is reached out
	MaxWait time.Duration
}

type UploadOptions

type UploadOptions struct {
	BackOffOpts    ExpBackOffOptions
	ChunkSizeBytes int64
	NumWorkers     int
}

func DefaultUploadOptions

func DefaultUploadOptions() UploadOptions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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