Skip to content

Commit

Permalink
Use upstream cvd binary.
Browse files Browse the repository at this point in the history
  • Loading branch information
ser-io committed Mar 4, 2024
1 parent 58bec06 commit 05752cd
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 365 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ orchestrator_https_port=2443
# Android Build URL. Defaults to "https://androidbuildinternal.googleapis.com"
# orchestrator_android_build_url=
#
# CVD binary Android Build Id. Defaults to ""
# orchestrator_cvdbin_android_build_id=
#
# CVD binary Android Build Target. Defaults to ""
# orchestrator_cvdbin_android_build_target=
#
# Directory used to store the CVD artifacts.
# Defaults to "/tmp/<uid>/cvd_artifacts"
orchestrator_cvd_artifacts_dir=/var/lib/cuttlefish-common
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@ start_orchestrator() {
if [[ -n "${orchestrator_android_build_url}" ]]; then
args+=("--android_build_url=${orchestrator_android_build_url}")
fi
if [[ -n "${orchestrator_cvdbin_android_build_id}" ]]; then
args+=("--cvd_build_id=${orchestrator_cvdbin_android_build_id}")
fi
if [[ -n "${orchestrator_cvdbin_android_build_target}" ]]; then
args+=("--cvd_build_target=${orchestrator_cvdbin_android_build_target}")
fi
if [[ -n "${orchestrator_cvd_artifacts_dir}" ]]; then
args+=("--cvd_artifacts_dir=${orchestrator_cvd_artifacts_dir}")
fi
Expand Down
1 change: 1 addition & 0 deletions frontend/debian/cuttlefish-orchestration.links
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/usr/lib/cuttlefish-common/bin/cvd /usr/bin/fetch_cvd
24 changes: 0 additions & 24 deletions frontend/src/host_orchestrator/constants_arm64.go

This file was deleted.

24 changes: 0 additions & 24 deletions frontend/src/host_orchestrator/constants_x86_64.go

This file was deleted.

13 changes: 1 addition & 12 deletions frontend/src/host_orchestrator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ func main() {
cvdUser := flag.String("cvd_user", "", "User to execute cvd as.")
operatorPort := flag.Int("operator_http_port", 1080, "Port where the operator is listening.")
abURL := flag.String("android_build_url", defaultAndroidBuildURL, "URL to an Android Build API.")
cvdBinAndroidBuildID := flag.String("cvd_build_id", defaultCVDBinAndroidBuildID, "Build ID to fetch the cvd binary from.")
cvdBinAndroidBuildTarget := flag.String("cvd_build_target", defaultCVDBinAndroidBuildTarget, "Build target to fetch the cvd binary from.")
imRootDir := flag.String("cvd_artifacts_dir", defaultCVDArtifactsDir(), "Directory where cvd will download android build artifacts to.")
address := flag.String("listen_addr", DefaultListenAddress, "IP address to listen for requests.")

Expand All @@ -123,7 +121,6 @@ func main() {

imPaths := orchestrator.IMPaths{
RootDir: *imRootDir,
CVDToolsDir: *imRootDir,
ArtifactsRootDir: filepath.Join(*imRootDir, "artifacts"),
}
om := orchestrator.NewMapOM()
Expand All @@ -132,19 +129,11 @@ func main() {
NameFactory: func() string { return uuid.New().String() },
}
uam := orchestrator.NewUserArtifactsManagerImpl(uamOpts)
cvdToolsVersion := orchestrator.AndroidBuild{
ID: *cvdBinAndroidBuildID,
Target: *cvdBinAndroidBuildTarget,
}
debugStaticVars := debug.StaticVariables{
InitialCVDBinAndroidBuildID: cvdToolsVersion.ID,
InitialCVDBinAndroidBuildTarget: cvdToolsVersion.Target,
}
debugStaticVars := debug.StaticVariables{}
debugVarsManager := debug.NewVariablesManager(debugStaticVars)
imController := orchestrator.Controller{
Config: orchestrator.Config{
Paths: imPaths,
CVDToolsVersion: cvdToolsVersion,
AndroidBuildServiceURL: *abURL,
CVDUser: *cvdUser,
},
Expand Down
31 changes: 6 additions & 25 deletions frontend/src/host_orchestrator/orchestrator/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const HeaderBuildAPICreds = "X-Cutf-Host-Orchestrator-BuildAPI-Creds"

type Config struct {
Paths IMPaths
CVDToolsVersion AndroidBuild
AndroidBuildServiceURL string
CVDUser string
}
Expand Down Expand Up @@ -134,20 +133,15 @@ func (h *fetchArtifactsHandler) Handle(r *http.Request) (interface{}, error) {
if err != nil {
return nil, operator.NewBadRequestError("Malformed JSON in request", err)
}
cvdDwnl := NewAndroidCICVDDownloader(
artifacts.NewAndroidCIBuildAPI(http.DefaultClient, h.Config.AndroidBuildServiceURL))
creds := r.Header.Get(HeaderBuildAPICreds)
buildAPIOpts := artifacts.AndroidCIBuildAPIOpts{Credentials: creds}
buildAPI := artifacts.NewAndroidCIBuildAPIWithOpts(
http.DefaultClient, h.Config.AndroidBuildServiceURL, buildAPIOpts)
artifactsFetcher := newBuildAPIArtifactsFetcher(buildAPI)
cvdBundleFetcher := newFetchCVDCommandArtifactsFetcher(
exec.CommandContext, h.Config.Paths.FetchCVDBin(), creds)
cvdBundleFetcher := newFetchCVDCommandArtifactsFetcher(exec.CommandContext, creds)
opts := FetchArtifactsActionOpts{
Request: &req,
Paths: h.Config.Paths,
CVDToolsVersion: h.Config.CVDToolsVersion,
CVDDownloader: cvdDwnl,
OperationManager: h.OM,
BuildAPI: buildAPI,
CVDBundleFetcher: cvdBundleFetcher,
Expand Down Expand Up @@ -176,15 +170,12 @@ func (h *createCVDHandler) Handle(r *http.Request) (interface{}, error) {
if err != nil {
return nil, operator.NewBadRequestError("Malformed JSON in request", err)
}
cvdDwnl := NewAndroidCICVDDownloader(
artifacts.NewAndroidCIBuildAPI(http.DefaultClient, h.Config.AndroidBuildServiceURL))
creds := r.Header.Get(HeaderBuildAPICreds)
buildAPIOpts := artifacts.AndroidCIBuildAPIOpts{Credentials: creds}
buildAPI := artifacts.NewAndroidCIBuildAPIWithOpts(
http.DefaultClient, h.Config.AndroidBuildServiceURL, buildAPIOpts)
artifactsFetcher := newBuildAPIArtifactsFetcher(buildAPI)
cvdBundleFetcher := newFetchCVDCommandArtifactsFetcher(
exec.CommandContext, h.Config.Paths.FetchCVDBin(), creds)
cvdBundleFetcher := newFetchCVDCommandArtifactsFetcher(exec.CommandContext, creds)
cvdStartTimeout := 3 * time.Minute
if req.EnvConfig != nil {
// Use a lengthier timeout when using canonical configs as this operation downloads artifacts as well.
Expand All @@ -196,8 +187,6 @@ func (h *createCVDHandler) Handle(r *http.Request) (interface{}, error) {
Paths: h.Config.Paths,
OperationManager: h.OM,
ExecContext: exec.CommandContext,
CVDToolsVersion: h.Config.CVDToolsVersion,
CVDDownloader: cvdDwnl,
BuildAPI: buildAPI,
ArtifactsFetcher: artifactsFetcher,
CVDBundleFetcher: cvdBundleFetcher,
Expand All @@ -215,14 +204,10 @@ type listCVDsHandler struct {
}

func (h *listCVDsHandler) Handle(r *http.Request) (interface{}, error) {
buildAPI := artifacts.NewAndroidCIBuildAPI(http.DefaultClient, h.Config.AndroidBuildServiceURL)
cvdDwnl := NewAndroidCICVDDownloader(buildAPI)
opts := ListCVDsActionOpts{
Paths: h.Config.Paths,
ExecContext: exec.CommandContext,
CVDToolsVersion: h.Config.CVDToolsVersion,
CVDDownloader: cvdDwnl,
CVDUser: h.Config.CVDUser,
Paths: h.Config.Paths,
ExecContext: exec.CommandContext,
CVDUser: h.Config.CVDUser,
}
return NewListCVDsAction(opts).Run()
}
Expand All @@ -243,15 +228,11 @@ func (h *stopCVDHandler) Handle(r *http.Request) (interface{}, error) {
vars := mux.Vars(r)
group := vars["group"]
name := vars["name"]
buildAPI := artifacts.NewAndroidCIBuildAPI(http.DefaultClient, h.Config.AndroidBuildServiceURL)
cvdDwnl := NewAndroidCICVDDownloader(buildAPI)
opts := StopCVDActionOpts{
Selector: CVDSelector{Group: group, Name: name},
Paths: h.Config.Paths,
OperationManager: h.OM,
ExecContext: exec.CommandContext,
CVDToolsVersion: h.Config.CVDToolsVersion,
CVDDownloader: cvdDwnl,
CVDUser: h.Config.CVDUser,
}
return NewStopCVDAction(opts).Run()
Expand All @@ -266,7 +247,7 @@ func (h *getCVDLogsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
name := vars["name"]
pathPrefix := "/cvds/" + name + "/logs"
ctx := newCVDExecContext(exec.CommandContext, h.Config.CVDUser)
logsDir, err := CVDLogsDir(ctx, h.Config.Paths.CVDBin(), name)
logsDir, err := CVDLogsDir(ctx, name)
if err != nil {
log.Printf("request %q failed with error: %v", r.Method+" "+r.URL.Path, err)
appErr, ok := err.(*operator.AppError)
Expand Down
16 changes: 3 additions & 13 deletions frontend/src/host_orchestrator/orchestrator/createcvdaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ type CreateCVDActionOpts struct {
Paths IMPaths
OperationManager OperationManager
ExecContext ExecContext
CVDDownloader CVDDownloader
CVDToolsVersion AndroidBuild
BuildAPI artifacts.BuildAPI
ArtifactsFetcher artifacts.Fetcher
CVDBundleFetcher artifacts.CVDBundleFetcher
Expand All @@ -58,8 +56,6 @@ type CreateCVDAction struct {
paths IMPaths
om OperationManager
execContext cvd.CVDExecContext
cvdToolsVersion AndroidBuild
cvdDownloader CVDDownloader
buildAPI artifacts.BuildAPI
artifactsFetcher artifacts.Fetcher
cvdBundleFetcher artifacts.CVDBundleFetcher
Expand All @@ -80,8 +76,6 @@ func NewCreateCVDAction(opts CreateCVDActionOpts) *CreateCVDAction {
hostValidator: opts.HostValidator,
paths: opts.Paths,
om: opts.OperationManager,
cvdToolsVersion: opts.CVDToolsVersion,
cvdDownloader: opts.CVDDownloader,
buildAPI: opts.BuildAPI,
artifactsFetcher: opts.ArtifactsFetcher,
cvdBundleFetcher: opts.CVDBundleFetcher,
Expand All @@ -97,7 +91,6 @@ func NewCreateCVDAction(opts CreateCVDActionOpts) *CreateCVDAction {
execContext: cvdExecContext,
startCVDHandler: &startCVDHandler{
ExecContext: cvdExecContext,
CVDBin: opts.Paths.CVDBin(),
Timeout: opts.CVDStartTimeout,
},
}
Expand All @@ -113,9 +106,6 @@ func (a *CreateCVDAction) Run() (apiv1.Operation, error) {
if err := createDir(a.paths.ArtifactsRootDir); err != nil {
return apiv1.Operation{}, err
}
if err := a.cvdDownloader.Download(a.cvdToolsVersion, a.paths.CVDBin(), a.paths.FetchCVDBin()); err != nil {
return apiv1.Operation{}, err
}
op := a.om.New()
go a.launchCVD(op)
return op, nil
Expand Down Expand Up @@ -167,11 +157,11 @@ func (a *CreateCVDAction) launchWithCanonicalConfig(op apiv1.Operation) (*apiv1.
opts := cvd.CommandOpts{
Timeout: a.cvdStartTimeout,
}
cmd := cvd.NewCommand(a.execContext, a.paths.CVDBin(), args, opts)
cmd := cvd.NewCommand(a.execContext, cvdBin, args, opts)
if err := cmd.Run(); err != nil {
return nil, operator.NewInternalError(ErrMsgLaunchCVDFailed, err)
}
group, err := cvdFleetFirstGroup(a.execContext, a.paths.CVDBin())
group, err := cvdFleetFirstGroup(a.execContext)
if err != nil {
return nil, err
}
Expand All @@ -196,7 +186,7 @@ func (a *CreateCVDAction) launchCVDResult(op apiv1.Operation) *OperationResult {
if err != nil {
return &OperationResult{Error: operator.NewInternalError(ErrMsgLaunchCVDFailed, err)}
}
group, err := cvdFleetFirstGroup(a.execContext, a.paths.CVDBin())
group, err := cvdFleetFirstGroup(a.execContext)
if err != nil {
return &OperationResult{Error: operator.NewInternalError(ErrMsgLaunchCVDFailed, err)}
}
Expand Down
Loading

0 comments on commit 05752cd

Please sign in to comment.