示例#1
0
func NewTestCluster(nodescount int) *TestCluster {
	tc := new(TestCluster)
	firstport := 20000

	tc.nodes = make([]*process.Process, nodescount)

	nodes := make([]gostore.ConfigNode, nodescount)
	for i := 0; i < nodescount; i++ {
		nodes[i].NodeId = uint16(i)
		nodes[i].NodeIP = "127.0.0.1"
		nodes[i].TCPPort = uint16(firstport + i*10)
		nodes[i].UDPPort = uint16(firstport + i*10 + 1)
	}

	rings := make([]gostore.ConfigRing, 1)
	rings[0].Id = 0
	rings[0].ReplicationFactor = 3

	for i := 0; i < nodescount; i++ {
		datadir := fmt.Sprintf("data/%d", i)

		conf := new(gostore.Config)

		conf.CurrentNode = uint16(i)
		conf.Nodes = nodes

		conf.Rings = rings
		conf.GlobalRing = 0

		conf.Services = make([]gostore.ConfigService, 1)

		// add FS
		conf.Services[0].Id = 2
		conf.Services[0].Type = "fs"
		conf.Services[0].CustomConfig = make(map[string]interface{})
		conf.Services[0].CustomConfig["DataDir"] = datadir
		conf.Services[0].CustomConfig["ApiAddress"] = fmt.Sprintf("127.0.0.1:%d", (firstport + i*10 + 2))

		// Clear and create data dir
		os.RemoveAll(datadir)
		os.Mkdir(datadir, 0777)

		tc.nodes[i] = process.NewProcess(*conf)
	}

	return tc
}
示例#2
0
文件: main.go 项目: appaquet/gostore
func main() {
	// Flags
	var configpath *string = flag.String("config", "gostore.conf", "configuration")
	var verbosity *int = flag.Int("verbosity", 3, "degree of verbosity")
	flag.Parse()

	// Set log verbosity
	log.MaxLevel = *verbosity

	log.Info("Reading config\n")
	config := gostore.LoadConfig(*configpath)

	log.Info("Starting server...\n")

	process.NewProcess(config)

	log.Info("Server started\n")

	http.ListenAndServe(":8080", nil)

	// Wait
	c := make(chan int)
	<-c
}
示例#3
0
func StartNode(id int) {
	var nodes []gostore.ConfigNode
	if id != 0 {
		nodes = make([]gostore.ConfigNode, 2)
	} else {
		nodes = make([]gostore.ConfigNode, 1)
	}

	// make the master
	nodes[0].NodeId = uint16(0)
	nodes[0].NodeIP = "127.0.0.1"
	nodes[0].TCPPort = uint16(firstport + 0*10)
	nodes[0].UDPPort = uint16(firstport + 0*10 + 1)
	nodes[0].Rings = make([]gostore.ConfigNodeRing, 1)
	nodes[0].Rings[0].RingId = 1
	nodes[0].Rings[0].Token = "0000000000000000000000"

	// make myself
	if id != 0 {
		nodes[1].NodeId = uint16(id)
		nodes[1].NodeIP = "127.0.0.1"
		nodes[1].TCPPort = uint16(firstport + id*10)
		nodes[1].UDPPort = uint16(firstport + id*10 + 1)
	}

	rings := make([]gostore.ConfigRing, 2)
	rings[0].Id = 0
	rings[0].ReplicationFactor = 3
	rings[1].Id = 1
	rings[1].ReplicationFactor = 3

	datadir := fmt.Sprintf("data/%d", id)

	conf := new(gostore.Config)

	conf.CurrentNode = uint16(id)
	conf.Nodes = nodes

	conf.Rings = rings

	conf.Services = make([]gostore.ConfigService, 2)

	// add cluster service
	conf.Services[0].Id = 1
	conf.Services[0].Type = "cls"
	conf.Services[0].CustomConfig = make(map[string]interface{})
	conf.Services[0].CustomConfig["DataDir"] = datadir
	conf.Services[0].CustomConfig["MasterRing"] = 1.0

	// add FS
	conf.Services[1].Id = 2
	conf.Services[1].Type = "fs"
	conf.Services[1].CustomConfig = make(map[string]interface{})
	conf.Services[1].CustomConfig["DataDir"] = datadir
	conf.Services[1].CustomConfig["ApiAddress"] = fmt.Sprintf("127.0.0.1:%d", (firstport + id*10 + 2))

	// Clear and create data dir
	os.RemoveAll(datadir)
	os.Mkdir(datadir, 0777)

	tc.nodes[id] = process.NewProcess(*conf)
}