Ejemplo n.º 1
0
func main() {
	cfg := flag.String("c", "cfg.json", "configuration file")
	version := flag.Bool("v", false, "show version")
	flag.Parse()

	if *version {
		fmt.Println(g.VERSION)
		os.Exit(0)
	}

	g.ParseConfig(*cfg)

	g.InitRedisConnPool()
	g.InitHbsClient()

	store.InitHistoryBigMap()

	go http.Start()
	go rpc.Start()

	go cron.SyncStrategies()
	go cron.CleanStale()

	select {}
}
Ejemplo n.º 2
0
func rpcHbsGetStrategies() {
	jg.ParseConfig(judgeConfig)
	jg.InitHbsClient()

	var resp model.StrategiesResponse
	err := jg.HbsClient.Call("Hbs.GetStrategies", model.NullRpcRequest{}, &resp)
	if err != nil {
		fmt.Println("[ERROR] Hbs.GetStrategies:", err)
		return
	}

	fmt.Println("[RESP.] Hbs.GetStrategies:", resp)
	for k, v := range resp.HostStrategies {
		fmt.Printf("Idx:%v, Hostname:%v, Strategies:%v\n", k, v.Hostname, v.Strategies)
	}
}
Ejemplo n.º 3
0
func configCommonRoutes() {
	http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("ok"))
	})

	http.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte(g.VERSION))
	})

	http.HandleFunc("/workdir", func(w http.ResponseWriter, r *http.Request) {
		RenderDataJson(w, file.SelfDir())
	})

	http.HandleFunc("/config/reload", func(w http.ResponseWriter, r *http.Request) {
		if strings.HasPrefix(r.RemoteAddr, "127.0.0.1") {
			g.ParseConfig(g.ConfigFile)
			RenderDataJson(w, g.Config())
		} else {
			w.Write([]byte("no privilege"))
		}
	})
}