Beispiel #1
0
func Run(configFile string, port string) {

	t := new(Job)
	resetJob(t)
	config := configparser.ParseFile(configFile)
	t.NumMap = config.NumMap
	t.NumReduce = config.NumReduce
	t.Master = config.Master
	t.ReduceDataPort = config.ReduceDataPort

	os.RemoveAll(config.MapDir)
	os.RemoveAll(config.ReduceDir)
	os.Mkdir(config.MapDir, 0755)
	os.Mkdir(config.ReduceDir, 0755)

	rpc.Register(t)

	listener, e := net.Listen("tcp", fmt.Sprintf(":%s", port))
	Port = port

	if e != nil {
		log.Fatal("listen error:", e)
	}
	for {
		if conn, err := listener.Accept(); err != nil {
			log.Fatal("accept error: " + err.Error())
		} else {
			go rpc.ServeConn(conn)
		}
	}
}
Beispiel #2
0
func Run(configFile string) {
	rand.Seed(time.Now().Unix())
	config = configparser.ParseFile(configFile)
	webport := config.WebPort
	http.HandleFunc("/", HandleHome)
	http.HandleFunc("/start", HandleStart)
	http.HandleFunc("/output", HandleOutput)
	http.HandleFunc("/upload", HandleUpload)
	http.Handle("/static", http.FileServer(http.Dir("./static/")))

	templates = template.Must(template.ParseFiles(config.HTMLTemplate))

	master = NewMaster(config)
	go master.FileServer()
	outfPath = filepath.Join(master.ReduceDir, "1")
	http.ListenAndServe(fmt.Sprintf(":%d", webport), nil)
}