fix calculation

pull/46/head
Minh Doan 6 years ago
parent db905ce80d
commit ade93843ac
  1. 9
      aws-experiment-launch/experiment/commander/main.go
  2. 27
      aws-experiment-launch/experiment/soldier/main.go

@ -122,13 +122,18 @@ func dictateNode(addr string, command string) int {
log.Printf("Failed to send command to %s", addr) log.Printf("Failed to send command to %s", addr)
return 0 return 0
} }
log.Printf("Send \"%s\" to %s", command, addr) // log.Printf("Send \"%s\" to %s", command, addr)
// read response // read response
buff := make([]byte, 1024) buff := make([]byte, 1024)
if n, err := conn.Read(buff); err == nil { if n, err := conn.Read(buff); err == nil {
log.Printf("Receive from %s: %s", addr, buff[:n]) received := string(buff[:n])
// log.Printf("Receive from %s: %s", addr, buff[:n])
if strings.Contains(received, "Failed") {
return 0
} else {
return 1 return 1
}
} else { } else {
return 0 return 0
} }

@ -144,24 +144,29 @@ func handleInitCommand(args []string, w *bufio.Writer) {
utils.DownloadFile(globalSession.localConfigFileName, configURL) utils.DownloadFile(globalSession.localConfigFileName, configURL)
log.Println("Successfully downloaded config") log.Println("Successfully downloaded config")
runInstance() if err := runInstance(); err == nil {
logAndReply(w, "Done init.")
logAndReply(w, "Successfully init-ed") } else {
logAndReply(w, "Failed.")
}
} }
func handleKillCommand(w *bufio.Writer) { func handleKillCommand(w *bufio.Writer) {
log.Println("Kill command") log.Println("Kill command")
killPort(setting.port) if err := killPort(setting.port); err == nil {
logAndReply(w, "Kill command done.") logAndReply(w, "Done kill.")
} else {
logAndReply(w, "Failed.")
}
} }
func killPort(port string) { func killPort(port string) error {
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
command := fmt.Sprintf("(Get-NetTCPConnection -LocalPort %s).OwningProcess -Force", port) command := fmt.Sprintf("(Get-NetTCPConnection -LocalPort %s).OwningProcess -Force", port)
runCmd("Stop-Process", "-Id", command) return runCmd("Stop-Process", "-Id", command)
} else { } else {
command := fmt.Sprintf("lsof -i tcp:%s | grep LISTEN | awk '{print $2}' | xargs kill -9", port) command := fmt.Sprintf("lsof -i tcp:%s | grep LISTEN | awk '{print $2}' | xargs kill -9", port)
runCmd("bash", "-c", command) return runCmd("bash", "-c", command)
} }
} }
@ -280,7 +285,7 @@ func runCmd(name string, args ...string) error {
} }
} }
func runInstance() { func runInstance() error {
config := readConfigFile(globalSession.localConfigFileName) config := readConfigFile(globalSession.localConfigFileName)
myConfig := getMyConfig(setting.ip, setting.port, &config) myConfig := getMyConfig(setting.ip, setting.port, &config)
@ -288,9 +293,9 @@ func runInstance() {
os.MkdirAll(globalSession.logFolder, os.ModePerm) os.MkdirAll(globalSession.logFolder, os.ModePerm)
if myConfig[2] == "client" { if myConfig[2] == "client" {
runClient() return runClient()
} else { } else {
runNode() return runNode()
} }
} }

Loading…
Cancel
Save