diff --git a/aws-experiment-launch/experiment/commander/main.go b/aws-experiment-launch/experiment/commander/main.go index aa67daeb4..ff4519fc8 100644 --- a/aws-experiment-launch/experiment/commander/main.go +++ b/aws-experiment-launch/experiment/commander/main.go @@ -59,7 +59,7 @@ func handleCommand(command string) { if setting.configs != nil { log.Printf("The loaded config has %v nodes\n", len(setting.configs)) } else { - log.Println("failed to read config file") + log.Println("Failed to read config file") } case "init": session.id = time.Now().Format("150405-20060102") @@ -72,11 +72,9 @@ func handleCommand(command string) { } log.Println("New session", session.id) - count := dictateNodes(fmt.Sprintf("init %v %v %v %v", setting.ip, setting.port, setting.configURL, session.id)) - log.Printf("Finished init with %v nodes\n", count) + dictateNodes(fmt.Sprintf("init %v %v %v %v", setting.ip, setting.port, setting.configURL, session.id)) case "ping", "kill", "log", "log2": - count := dictateNodes(command) - log.Printf("Finished %v with %v nodes\n", cmd, count) + dictateNodes(command) default: log.Println("Unknown command") } @@ -88,23 +86,24 @@ func config(ip string, port string, configURL string) { setting.configURL = configURL } -func dictateNodes(command string) int { - result_chan := make(chan int) +func dictateNodes(command string) { + resultChan := make(chan int) for _, config := range setting.configs { ip := config[0] port := "1" + config[1] // the port number of solider is "1" + node port addr := strings.Join([]string{ip, port}, ":") - go func(result_chan chan int) { - result_chan <- dictateNode(addr, command) - }(result_chan) + go func(resultChan chan int) { + resultChan <- dictateNode(addr, command) + }(resultChan) } count := len(setting.configs) res := 0 - for ; count > 0; count -= 1 { - res += <-result_chan + for ; count > 0; count-- { + res += <-resultChan } - return res + + log.Printf("Finished %s with %v nodes\n", command, count) } func dictateNode(addr string, command string) int { @@ -129,9 +128,8 @@ func dictateNode(addr string, command string) int { if n, err := conn.Read(buff); err == nil { log.Printf("Receive from %s: %s", addr, buff[:n]) return 1 - } else { - return 0 } + return 0 } func handleUploadRequest(w http.ResponseWriter, r *http.Request) { @@ -176,12 +174,12 @@ func jsonResponse(w http.ResponseWriter, code int, message string) { } func serve() { - http.Handle("/", http.FileServer(http.Dir("./"))) http.HandleFunc("/upload", handleUploadRequest) err := http.ListenAndServe(":"+setting.port, nil) if err != nil { log.Fatalf("Failed to setup server! Error: %s", err.Error()) } + log.Printf("Start to host upload endpoint at http://%s:%s/upload\n", setting.ip, setting.port) } func main() { @@ -192,7 +190,6 @@ func main() { config(*ip, *port, *configURL) - log.Println("Start to host config files at http://" + setting.ip + ":" + setting.port) go serve() scanner := bufio.NewScanner(os.Stdin) diff --git a/aws-experiment-launch/experiment/soldier/main.go b/aws-experiment-launch/experiment/soldier/main.go index e98ff4027..5c7a2505c 100644 --- a/aws-experiment-launch/experiment/soldier/main.go +++ b/aws-experiment-launch/experiment/soldier/main.go @@ -175,7 +175,7 @@ func handleLogCommand(w *bufio.Writer) { files, err := ioutil.ReadDir(globalSession.logFolder) if err != nil { - logAndReply(w, fmt.Sprintf("Failed to create log folder. Error: %s", err.Error())) + logAndReply(w, fmt.Sprintf("Failed to read log folder. Error: %s", err.Error())) return }