blob: bacb67eb859610fb575c1a361c14480dddd6b93c [file] [log] [blame]
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"flag"
"android.googlesource.com/platform/tools/gpu/framework/app"
"android.googlesource.com/platform/tools/gpu/framework/file"
"android.googlesource.com/platform/tools/gpu/framework/grpcutil"
"android.googlesource.com/platform/tools/gpu/framework/log"
"android.googlesource.com/platform/tools/gpu/gapid/robot/build"
"android.googlesource.com/platform/tools/gpu/gapid/robot/job"
"android.googlesource.com/platform/tools/gpu/gapid/robot/master"
"android.googlesource.com/platform/tools/gpu/gapid/robot/monitor"
"android.googlesource.com/platform/tools/gpu/gapid/robot/subject"
"android.googlesource.com/platform/tools/gpu/gapid/robot/web"
"android.googlesource.com/platform/tools/gpu/gapid/stash"
"google.golang.org/grpc"
)
var (
port = 8080
root = file.Path{}
)
func init() {
webStart := &app.Verb{
Name: "web",
ShortHelp: "Starts a robot web server",
Run: doWebStart,
}
webStart.Flags.IntVar(&port, "port", port, "The port to serve the website on")
webStart.Flags.Var(&root, "root", "The directory to use as the root of static content")
startVerb.Add(webStart)
}
func doWebStart(ctx log.Context, flags flag.FlagSet) error {
return grpcutil.Client(ctx, serverAddress, func(ctx log.Context, conn *grpc.ClientConn) error {
config := web.Config{
Port: port,
StaticRoot: root,
Managers: monitor.Managers{
Master: master.NewRemoteMaster(ctx, conn),
Stash: stash.NewRemoteStore(ctx, conn),
Build: build.NewRemote(ctx, conn),
Subject: subject.NewRemote(ctx, conn),
Job: job.NewRemote(ctx, conn),
},
}
w, err := web.Create(ctx, config)
m := master.NewClient(ctx, config.Master)
restart := false
go func() {
shutdown, err := m.Orbit(ctx, master.ServiceList{Worker: true})
if err != nil {
return
}
restart = shutdown.Restart
w.Close()
}()
ctx.Notice().Log("Starting web server")
err = w.Serve(ctx)
if restart {
return app.Restart
}
return err
}, grpc.WithInsecure())
}