Skip to content

Commit

Permalink
Separate cloud and host orchestrator clients
Browse files Browse the repository at this point in the history
  • Loading branch information
jemoreira committed Oct 23, 2023
1 parent 76f6320 commit 9d15900
Show file tree
Hide file tree
Showing 8 changed files with 528 additions and 450 deletions.
2 changes: 1 addition & 1 deletion pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ func runPullCommand(c *cobra.Command, args []string, flags *CVDRemoteFlags, opts
if err != nil {
return err
}
if err := service.DownloadRuntimeArtifacts(host, f); err != nil {
if err := service.HostService(host).DownloadRuntimeArtifacts(f); err != nil {
return err
}
if err := f.Close(); err != nil {
Expand Down
40 changes: 23 additions & 17 deletions pkg/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,47 +103,53 @@ func (fakeService) DeleteHosts(name []string) error {
return nil
}

func (fakeService) GetInfraConfig(host string) (*apiv1.InfraConfig, error) {
const serviceURL = "http://waldo.com"

func (fakeService) RootURI() string {
return serviceURL + "/v1"
}

func (fakeService) HostService(host string) client.HostOrchestratorService {
if host == "" {
panic("empty host")
}
return &fakeHostService{}
}

type fakeHostService struct{}

func (fakeHostService) GetInfraConfig() (*apiv1.InfraConfig, error) {
return nil, nil
}

func (fakeService) ConnectWebRTC(host, device string, observer wclient.Observer, logger io.Writer, opts client.ConnectWebRTCOpts) (*wclient.Connection, error) {
func (fakeHostService) ConnectWebRTC(device string, observer wclient.Observer, logger io.Writer, opts client.ConnectWebRTCOpts) (*wclient.Connection, error) {
return nil, nil
}

func (fakeService) FetchArtifacts(host string, req *hoapi.FetchArtifactsRequest) (*hoapi.FetchArtifactsResponse, error) {
func (fakeHostService) FetchArtifacts(req *hoapi.FetchArtifactsRequest) (*hoapi.FetchArtifactsResponse, error) {
return &hoapi.FetchArtifactsResponse{AndroidCIBundle: &hoapi.AndroidCIBundle{}}, nil
}

func (fakeService) CreateCVD(host string, req *hoapi.CreateCVDRequest) (*hoapi.CreateCVDResponse, error) {
if host == "" {
panic("empty host")
}
func (fakeHostService) CreateCVD(req *hoapi.CreateCVDRequest) (*hoapi.CreateCVDResponse, error) {
return &hoapi.CreateCVDResponse{CVDs: []*hoapi.CVD{{Name: "cvd-1"}}}, nil
}

func (fakeService) ListCVDs(host string) ([]*hoapi.CVD, error) {
func (fakeHostService) ListCVDs() ([]*hoapi.CVD, error) {
return []*hoapi.CVD{{Name: "cvd-1"}}, nil
}

func (fakeService) CreateUpload(host string) (string, error) {
func (fakeHostService) CreateUploadDir() (string, error) {
return "", nil
}

func (fakeService) UploadFiles(host, uploadDir string, filenames []string) error {
func (fakeHostService) UploadFiles(uploadDir string, filenames []string) error {
return nil
}

func (fakeService) DownloadRuntimeArtifacts(host string, dst io.Writer) error {
func (fakeHostService) DownloadRuntimeArtifacts(dst io.Writer) error {
return nil
}

const serviceURL = "http://waldo.com"

func (fakeService) RootURI() string {
return serviceURL + "/v1"
}

func TestCommandSucceeds(t *testing.T) {
tests := []struct {
Name string
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func NewConnController(
opts := client.ConnectWebRTCOpts{
LocalICEConfig: localICEConfig,
}
conn, err := service.ConnectWebRTC(cvd.Host, cvd.WebRTCDeviceID, tc, logger.Writer(), opts)
conn, err := service.HostService(cvd.Host).ConnectWebRTC(cvd.WebRTCDeviceID, tc, logger.Writer(), opts)
if err != nil {
return nil, fmt.Errorf("Failed to connect to %q: %w", cvd.WebRTCDeviceID, err)
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/cli/cvd.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ func (c *cvdCreator) createCVDFromLocalBuild() ([]*hoapi.CVD, error) {
return nil, fmt.Errorf("Invalid cvd host package: %w", err)
}
names = append(names, filepath.Join(vars.HostOut, CVDHostPackageName))
uploadDir, err := c.service.CreateUpload(c.opts.Host)
uploadDir, err := c.service.HostService(c.opts.Host).CreateUploadDir()
if err != nil {
return nil, err
}
if err := c.service.UploadFiles(c.opts.Host, uploadDir, names); err != nil {
if err := c.service.HostService(c.opts.Host).UploadFiles(uploadDir, names); err != nil {
return nil, err
}
req := hoapi.CreateCVDRequest{
Expand All @@ -148,7 +148,7 @@ func (c *cvdCreator) createCVDFromLocalBuild() ([]*hoapi.CVD, error) {
},
AdditionalInstancesNum: c.opts.AdditionalInstancesNum(),
}
res, err := c.service.CreateCVD(c.opts.Host, &req)
res, err := c.service.HostService(c.opts.Host).CreateCVD(&req)
if err != nil {
return nil, err
}
Expand All @@ -173,7 +173,7 @@ func (c *cvdCreator) createWithCanonicalConfig() ([]*hoapi.CVD, error) {
EnvConfig: c.opts.EnvConfig,
}
c.statePrinter.Print(stateMsgFetchAndStart)
res, err := c.service.CreateCVD(c.opts.Host, createReq)
res, err := c.service.HostService(c.opts.Host).CreateCVD(createReq)
c.statePrinter.PrintDone(stateMsgFetchAndStart, err)
if err != nil {
return nil, err
Expand All @@ -197,7 +197,7 @@ func (c *cvdCreator) createWithOpts() ([]*hoapi.CVD, error) {
AndroidCIBundle: &hoapi.AndroidCIBundle{Build: mainBuild, Type: hoapi.MainBundleType},
}
c.statePrinter.Print(stateMsgFetchMainBundle)
fetchMainBuildRes, err := c.service.FetchArtifacts(c.opts.Host, fetchReq)
fetchMainBuildRes, err := c.service.HostService(c.opts.Host).FetchArtifacts(fetchReq)
c.statePrinter.PrintDone(stateMsgFetchMainBundle, err)
if err != nil {
return nil, err
Expand All @@ -216,7 +216,7 @@ func (c *cvdCreator) createWithOpts() ([]*hoapi.CVD, error) {
AdditionalInstancesNum: c.opts.AdditionalInstancesNum(),
}
c.statePrinter.Print(stateMsgStartCVD)
res, err := c.service.CreateCVD(c.opts.Host, createReq)
res, err := c.service.HostService(c.opts.Host).CreateCVD(createReq)
c.statePrinter.PrintDone(stateMsgStartCVD, err)
if err != nil {
return nil, err
Expand Down Expand Up @@ -291,7 +291,7 @@ func flattenCVDs(hosts []*RemoteHost) []*RemoteCVD {

// Calling listCVDConnectionsByHost is inefficient, this internal function avoids that for listAllCVDs.
func listHostCVDsInner(service client.Service, host string, statuses map[RemoteCVDLocator]ConnStatus) ([]*RemoteCVD, error) {
cvds, err := service.ListCVDs(host)
cvds, err := service.HostService(host).ListCVDs()
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 9d15900

Please sign in to comment.