commander host config file.

pull/37/head
Richard Liu 6 years ago
parent 06cc1cad7e
commit 06574d2f34
  1. 25
      aws-experiment-launch/experiment/commander/main.go

@ -5,6 +5,7 @@ import (
"flag" "flag"
"log" "log"
"net" "net"
"net/http"
"os" "os"
"strings" "strings"
) )
@ -20,10 +21,6 @@ var (
setting commanderSetting setting commanderSetting
) )
func socketClient(addr string, handler func(net.Conn, string)) {
}
func readConfigFile() [][]string { func readConfigFile() [][]string {
file, err := os.Open(setting.configFile) file, err := os.Open(setting.configFile)
if err != nil { if err != nil {
@ -52,10 +49,16 @@ func handleCommand(command string) {
{ {
dictateNodes("init http://" + setting.ip + ":" + setting.port + "/" + setting.configFile) dictateNodes("init http://" + setting.ip + ":" + setting.port + "/" + setting.configFile)
} }
default: case "ping":
fallthrough
case "kill":
{ {
dictateNodes(command) dictateNodes(command)
} }
default:
{
log.Println("Unknown command")
}
} }
} }
@ -64,7 +67,7 @@ func config(ip string, port string, configFile string) {
setting.port = port setting.port = port
setting.configFile = configFile setting.configFile = configFile
setting.configs = readConfigFile() setting.configs = readConfigFile()
log.Println("Config-ed", setting.configs) log.Println("Loaded config file", setting.configs)
} }
func dictateNodes(command string) { 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() { func main() {
ip := flag.String("ip", "127.0.0.1", "ip of commander") ip := flag.String("ip", "127.0.0.1", "ip of commander")
port := flag.String("port", "8080", "port of config file") port := flag.String("port", "8080", "port of config file")
@ -103,6 +113,9 @@ func main() {
config(*ip, *port, *configFile) 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) scanner := bufio.NewScanner(os.Stdin)
for true { for true {
log.Printf("Listening to Your Command:") log.Printf("Listening to Your Command:")

Loading…
Cancel
Save