Skip to content

Commit 8808d7e

Browse files
authored
Update webapp to use make's binary location (#64)
* Update webapp to use make's binary lcoation * reworked to use cwd * remove apps build, warn users when missing apps
1 parent 42a8572 commit 8808d7e

File tree

3 files changed

+28
-38
lines changed

3 files changed

+28
-38
lines changed

webapp/lib/config.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ import (
1313
. "github.com/netsec-ethz/scion-apps/webapp/util"
1414
)
1515

16-
// SCIONROOT is the root location on the scion infrastructure.
16+
// SCIONROOT is the root location of the scion infrastructure.
1717
var SCIONROOT = "src/github.com/scionproto/scion"
1818

19+
// LABROOT is the root location of scionlab apps.
20+
var LABROOT = "src/github.com/netsec-ethz/scion-apps"
21+
1922
// GOPATH is the root of the GOPATH environment.
2023
var GOPATH = os.Getenv("GOPATH")
2124

webapp/static/js/webapp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ function manageTestData() {
308308
if (d.graph != null) {
309309
// write data on graph
310310
for (var i = 0; i < d.graph.length; i++) {
311-
if (d.graph[i].Log != null) {
311+
if (d.graph[i].Log != null && d.graph[i].Log != "") {
312312
// result returned, display it and reset progress
313313
handleEndCmdDisplay(d.graph[i].Log);
314314
}

webapp/webapp.go

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package main
44

55
import (
66
"bufio"
7-
"bytes"
7+
"errors"
88
"flag"
99
"fmt"
1010
"html/template"
@@ -255,12 +255,12 @@ func parseRequest2BwtestItem(r *http.Request, appSel string) (*model.BwTestItem,
255255

256256
func parseBwTest2Cmd(d *model.BwTestItem, appSel string, pathStr string) []string {
257257
var command []string
258-
binname := getClientLocationBin(appSel)
258+
installpath := getClientLocationBin(appSel)
259259
switch appSel {
260260
case "bwtester", "camerapp", "sensorapp":
261261
optClient := fmt.Sprintf("-c=%s,[%s]:%d", d.CIa, d.CAddr, d.CPort)
262262
optServer := fmt.Sprintf("-s=%s,[%s]:%d", d.SIa, d.SAddr, d.SPort)
263-
command = append(command, binname, optServer, optClient)
263+
command = append(command, installpath, optServer, optClient)
264264
if appSel == "bwtester" {
265265
bwCS := fmt.Sprintf("-cs=%d,%d,%d,%dbps", d.CSDuration/1000, d.CSPktSize,
266266
d.CSPackets, d.CSBandwidth)
@@ -360,6 +360,7 @@ func executeCommand(w http.ResponseWriter, r *http.Request) {
360360
// execute scion go client app with client/server commands
361361
log.Info("Executing:", "command", strings.Join(command, " "))
362362
cmd := exec.Command(command[0], command[1:]...)
363+
cmd.Dir = getClientCwd(appSel)
363364

364365
log.Info("Chosen Path:", "pathStr", pathStr)
365366

@@ -373,64 +374,50 @@ func executeCommand(w http.ResponseWriter, r *http.Request) {
373374
err = cmd.Start()
374375
if err != nil {
375376
fmt.Fprintf(os.Stderr, "Failed to start err=%v", err)
377+
if w != nil {
378+
w.Write([]byte(err.Error() + "\n"))
379+
}
376380
}
377381
go writeCmdOutput(w, reader, stdin, d, appSel, pathStr, cmd)
378382
cmd.Wait()
379383
}
380384

381385
func appsBuildCheck(app string) {
382-
binname := getClientLocationBin(app)
383-
installpath := path.Join(lib.GOPATH, "bin", binname)
384-
// check for install, and install only if needed
386+
installpath := getClientLocationBin(app)
385387
if _, err := os.Stat(installpath); os.IsNotExist(err) {
386-
filepath := getClientLocationSrc(app)
387-
cmd := exec.Command("go", "install")
388-
cmd.Dir = path.Dir(filepath)
389-
log.Info(fmt.Sprintf("Installing %s...", filepath))
390-
var stdout, stderr bytes.Buffer
391-
cmd.Stdout = &stdout
392-
cmd.Stderr = &stderr
393-
err := cmd.Run()
394388
CheckError(err)
395-
outStr, errStr := string(stdout.Bytes()), string(stderr.Bytes())
396-
if len(outStr) > 0 {
397-
log.Info(outStr)
398-
}
399-
if len(errStr) > 0 {
400-
log.Error(errStr)
401-
}
389+
CheckError(errors.New("App missing, build all apps with 'deps.sh' and 'make'."))
402390
} else {
403391
log.Info(fmt.Sprintf("Existing install, found %s...", app))
404392
}
405393
}
406394

407-
// Parses html selection and returns name of app binary.
408-
func getClientLocationBin(app string) string {
409-
var binname string
395+
// Parses html selection and returns current working directory for execution.
396+
func getClientCwd(app string) string {
397+
var cwd string
410398
switch app {
411399
case "sensorapp":
412-
binname = "sensorfetcher"
400+
cwd = path.Join(lib.GOPATH, lib.LABROOT, "sensorapp/sensorfetcher")
413401
case "camerapp":
414-
binname = "imagefetcher"
402+
cwd = path.Join(lib.GOPATH, lib.LABROOT, "camerapp/imagefetcher")
415403
case "bwtester":
416-
binname = "bwtestclient"
404+
cwd = path.Join(lib.GOPATH, lib.LABROOT, "bwtester/bwtestclient")
417405
}
418-
return binname
406+
return cwd
419407
}
420408

421-
// Parses html selection and returns location of app source.
422-
func getClientLocationSrc(app string) string {
423-
slroot := "src/github.com/netsec-ethz/scion-apps"
424-
var filepath string
409+
// Parses html selection and returns name of app binary.
410+
func getClientLocationBin(app string) string {
411+
var binname string
425412
switch app {
426413
case "sensorapp":
427-
filepath = path.Join(lib.GOPATH, slroot, "sensorapp/sensorfetcher/sensorfetcher.go")
414+
binname = path.Join(lib.GOPATH, lib.LABROOT, "sensorapp/sensorfetcher/sensorfetcher")
428415
case "camerapp":
429-
filepath = path.Join(lib.GOPATH, slroot, "camerapp/imagefetcher/imagefetcher.go")
416+
binname = path.Join(lib.GOPATH, lib.LABROOT, "camerapp/imagefetcher/imagefetcher")
430417
case "bwtester":
431-
filepath = path.Join(lib.GOPATH, slroot, "bwtester/bwtestclient/bwtestclient.go")
418+
binname = path.Join(lib.GOPATH, lib.LABROOT, "bwtester/bwtestclient/bwtestclient")
432419
}
433-
return filepath
420+
return binname
434421
}
435422

436423
// Handles piping command line output to logs, database, and http response writer.

0 commit comments

Comments
 (0)