diff --git a/aws-experiment-launch/experiment/commander/main.go b/aws-experiment-launch/experiment/commander/main.go index 88a095645..5194b2abc 100644 --- a/aws-experiment-launch/experiment/commander/main.go +++ b/aws-experiment-launch/experiment/commander/main.go @@ -5,6 +5,7 @@ import ( "flag" "log" "net" + "net/http" "os" "strings" ) @@ -20,10 +21,6 @@ var ( setting commanderSetting ) -func socketClient(addr string, handler func(net.Conn, string)) { - -} - func readConfigFile() [][]string { file, err := os.Open(setting.configFile) if err != nil { @@ -52,10 +49,16 @@ func handleCommand(command string) { { dictateNodes("init http://" + setting.ip + ":" + setting.port + "/" + setting.configFile) } - default: + case "ping": + fallthrough + case "kill": { dictateNodes(command) } + default: + { + log.Println("Unknown command") + } } } @@ -64,7 +67,7 @@ func config(ip string, port string, configFile string) { setting.port = port setting.configFile = configFile setting.configs = readConfigFile() - log.Println("Config-ed", setting.configs) + log.Println("Loaded config file", setting.configs) } func dictateNodes(command string) { @@ -96,6 +99,13 @@ func dictateNodes(command string) { } } +func hostConfigFile() { + err := http.ListenAndServe(":"+setting.port, http.FileServer(http.Dir("./"))) + if err != nil { + panic("Failed to host config file!") + } +} + func main() { ip := flag.String("ip", "127.0.0.1", "ip of commander") port := flag.String("port", "8080", "port of config file") @@ -103,6 +113,9 @@ func main() { config(*ip, *port, *configFile) + log.Println("Start to host config file at http://" + setting.ip + ":" + setting.port + "/" + setting.configFile) + go hostConfigFile() + scanner := bufio.NewScanner(os.Stdin) for true { log.Printf("Listening to Your Command:")