|
|
@ -59,7 +59,7 @@ func handleCommand(command string) { |
|
|
|
if setting.configs != nil { |
|
|
|
if setting.configs != nil { |
|
|
|
log.Printf("The loaded config has %v nodes\n", len(setting.configs)) |
|
|
|
log.Printf("The loaded config has %v nodes\n", len(setting.configs)) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
log.Println("failed to read config file") |
|
|
|
log.Println("Failed to read config file") |
|
|
|
} |
|
|
|
} |
|
|
|
case "init": |
|
|
|
case "init": |
|
|
|
session.id = time.Now().Format("150405-20060102") |
|
|
|
session.id = time.Now().Format("150405-20060102") |
|
|
@ -72,11 +72,9 @@ func handleCommand(command string) { |
|
|
|
} |
|
|
|
} |
|
|
|
log.Println("New session", session.id) |
|
|
|
log.Println("New session", session.id) |
|
|
|
|
|
|
|
|
|
|
|
count := dictateNodes(fmt.Sprintf("init %v %v %v %v", setting.ip, setting.port, setting.configURL, session.id)) |
|
|
|
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) |
|
|
|
|
|
|
|
case "ping", "kill", "log", "log2": |
|
|
|
case "ping", "kill", "log", "log2": |
|
|
|
count := dictateNodes(command) |
|
|
|
dictateNodes(command) |
|
|
|
log.Printf("Finished %v with %v nodes\n", cmd, count) |
|
|
|
|
|
|
|
default: |
|
|
|
default: |
|
|
|
log.Println("Unknown command") |
|
|
|
log.Println("Unknown command") |
|
|
|
} |
|
|
|
} |
|
|
@ -88,23 +86,24 @@ func config(ip string, port string, configURL string) { |
|
|
|
setting.configURL = configURL |
|
|
|
setting.configURL = configURL |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func dictateNodes(command string) int { |
|
|
|
func dictateNodes(command string) { |
|
|
|
result_chan := make(chan int) |
|
|
|
resultChan := make(chan int) |
|
|
|
for _, config := range setting.configs { |
|
|
|
for _, config := range setting.configs { |
|
|
|
ip := config[0] |
|
|
|
ip := config[0] |
|
|
|
port := "1" + config[1] // the port number of solider is "1" + node port
|
|
|
|
port := "1" + config[1] // the port number of solider is "1" + node port
|
|
|
|
addr := strings.Join([]string{ip, port}, ":") |
|
|
|
addr := strings.Join([]string{ip, port}, ":") |
|
|
|
|
|
|
|
|
|
|
|
go func(result_chan chan int) { |
|
|
|
go func(resultChan chan int) { |
|
|
|
result_chan <- dictateNode(addr, command) |
|
|
|
resultChan <- dictateNode(addr, command) |
|
|
|
}(result_chan) |
|
|
|
}(resultChan) |
|
|
|
} |
|
|
|
} |
|
|
|
count := len(setting.configs) |
|
|
|
count := len(setting.configs) |
|
|
|
res := 0 |
|
|
|
res := 0 |
|
|
|
for ; count > 0; count -= 1 { |
|
|
|
for ; count > 0; count-- { |
|
|
|
res += <-result_chan |
|
|
|
res += <-resultChan |
|
|
|
} |
|
|
|
} |
|
|
|
return res |
|
|
|
|
|
|
|
|
|
|
|
log.Printf("Finished %s with %v nodes\n", command, res) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func dictateNode(addr string, command string) int { |
|
|
|
func dictateNode(addr string, command string) int { |
|
|
@ -134,9 +133,8 @@ func dictateNode(addr string, command string) int { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return 1 |
|
|
|
return 1 |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
return 0 |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return 0 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func handleUploadRequest(w http.ResponseWriter, r *http.Request) { |
|
|
|
func handleUploadRequest(w http.ResponseWriter, r *http.Request) { |
|
|
@ -181,12 +179,12 @@ func jsonResponse(w http.ResponseWriter, code int, message string) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func serve() { |
|
|
|
func serve() { |
|
|
|
http.Handle("/", http.FileServer(http.Dir("./"))) |
|
|
|
|
|
|
|
http.HandleFunc("/upload", handleUploadRequest) |
|
|
|
http.HandleFunc("/upload", handleUploadRequest) |
|
|
|
err := http.ListenAndServe(":"+setting.port, nil) |
|
|
|
err := http.ListenAndServe(":"+setting.port, nil) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Fatalf("Failed to setup server! Error: %s", err.Error()) |
|
|
|
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() { |
|
|
|
func main() { |
|
|
@ -197,7 +195,6 @@ func main() { |
|
|
|
|
|
|
|
|
|
|
|
config(*ip, *port, *configURL) |
|
|
|
config(*ip, *port, *configURL) |
|
|
|
|
|
|
|
|
|
|
|
log.Println("Start to host config files at http://" + setting.ip + ":" + setting.port) |
|
|
|
|
|
|
|
go serve() |
|
|
|
go serve() |
|
|
|
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(os.Stdin) |
|
|
|
scanner := bufio.NewScanner(os.Stdin) |
|
|
|