// Create a tier and specify any dependencies, return the full name of the last node created func Create(servicename, packagename string, regions, count int, dependencies ...string) string { var name string arch := archaius.Conf.Arch rnames := archaius.Conf.RegionNames znames := archaius.Conf.ZoneNames if regions == 0 { // for dns that isn't in a region or zone //log.Printf("Create cross region: " + servicename) name = names.Make(arch, "*", "*", servicename, packagename, 0) StartNode(name, dependencies...) } for r := 0; r < regions; r++ { if count == 0 { // for AWS services that are cross zone like elb and S3 //log.Printf("Create cross zone: " + servicename) name = names.Make(arch, rnames[r], "*", servicename, packagename, 0) StartNode(name, dependencies...) } else { //log.Printf("Create service: " + servicename) for i := r * count; i < (r+1)*count; i++ { name = names.Make(arch, rnames[r], znames[i%3], servicename, packagename, i) //log.Println(dependencies) StartNode(name, dependencies...) } } } return name }
// Create a tier and specify any dependencies, return the full name of the last node created func Create(servicename, packagename string, regions, count int, dependencies ...string) string { var name string arch := archaius.Conf.Arch rnames := archaius.Conf.RegionNames znames := archaius.Conf.ZoneNames if regions == 0 { // for dns that isn't in a region or zone //log.Printf("Create cross region: " + servicename) name = names.Make(arch, "*", "*", servicename, packagename, 0) StartNode(name, dependencies...) } for r := 0; r < regions; r++ { if count == 0 { // for AWS services that are cross zone like elb and S3 //log.Printf("Create cross zone: " + servicename) name = names.Make(arch, rnames[r], "*", servicename, packagename, 0) StartNode(name, dependencies...) } else { //log.Printf("Create service: " + servicename) cass := make(map[string]mapchan) // for token distribution for i := r * count; i < (r+1)*count; i++ { name = names.Make(arch, rnames[r], znames[i%3], servicename, packagename, i) //log.Println(dependencies) StartNode(name, dependencies...) if packagename == "priamCassandra" { rz := names.RegionZone(name) if cass[rz] == nil { cass[rz] = make(mapchan) } cass[rz][name] = noodles[name] // remember the nodes } } if packagename == "priamCassandra" { // split by zone for _, v := range cass { priamCassandra.Distribute(v) // returns a string if it needs logging } } } } return name }
// Start fsm and create new pirates func Start() { listener = make(chan gotocol.Message) // listener for fsm if archaius.Conf.Population < 2 { log.Fatal("fsm: can't create less than 2 pirates") } // create map of channels and a name index to select randoml nodes from noodles = make(map[string]chan gotocol.Message, archaius.Conf.Population) pnames = make([]string, archaius.Conf.Population) // indexable name list log.Println("fsm: population", archaius.Conf.Population, "pirates") for i := 1; i <= archaius.Conf.Population; i++ { name := names.Make(archaius.Conf.Arch, "atlantic", "bermuda", "blackbeard", "pirate", i) noodles[name] = make(chan gotocol.Message) go pirate.Start(noodles[name]) } i := 0 msgcount := 1 start := time.Now() for name, noodle := range noodles { pnames[i] = name i++ // tell the pirate it's name and how to talk back to it's fsm // this must be the first message the pirate sees noodle <- gotocol.Message{gotocol.Hello, listener, time.Now(), gotocol.NilContext(), name} if edda.Logchan != nil { // tell the pirate to report itself and new edges to the logger noodle <- gotocol.Message{gotocol.Inform, edda.Logchan, time.Now(), gotocol.NilContext(), ""} msgcount = 2 } } log.Println("fsm: Talk amongst yourselves for", archaius.Conf.RunDuration) rand.Seed(int64(len(noodles))) for _, name := range pnames { // for each pirate tell them about two other random pirates noodle := noodles[name] // lookup the channel // pick a first random pirate to tell this one about talkto := pnames[rand.Intn(len(pnames))] noodle <- gotocol.Message{gotocol.NameDrop, noodles[talkto], time.Now(), gotocol.NewRequest(), talkto} // pick a second random pirate to tell this one about talkto = pnames[rand.Intn(len(pnames))] noodle <- gotocol.Message{gotocol.NameDrop, noodles[talkto], time.Now(), gotocol.NewRequest(), talkto} // anonymously send this pirate a random amount of GoldCoin up to 100 gold := fmt.Sprintf("%d", rand.Intn(100)) noodle <- gotocol.Message{gotocol.GoldCoin, nil, time.Now(), gotocol.NewRequest(), gold} // tell this pirate to start chatting with friends every 0.1 to 10 secs delay := fmt.Sprintf("%dms", 100+rand.Intn(9900)) noodle <- gotocol.Message{gotocol.Chat, nil, time.Now(), gotocol.NewRequest(), delay} } msgcount += 4 d := time.Since(start) log.Println("fsm: Delivered", msgcount*len(pnames), "messages in", d) shutdown() }
func TestConf(t *testing.T) { Conf.Arch = "testarch" Conf.GraphmlFile = "graphml" Conf.GraphjsonFile = "graphjson" Conf.RunDuration = 10 * time.Second Conf.Dunbar = 100 Conf.Population = 100 Conf.Msglog = true Conf.Regions = 2 Conf.Collect = true Conf.StopStep = 2 Conf.EurekaPoll = "1s" for _, r := range Conf.RegionNames { for i, z := range Conf.ZoneNames { // make two different names to make sure the IP is unique and make sure it is stored n1 := names.Make(Conf.Arch, r, z, "lookup", "dhcp", i) fmt.Println(n1, Lookup(n1)) n2 := names.Make(Conf.Arch, r, z, "lookup", "dhcp", 100+i) fmt.Println(n2, Lookup(n2)) fmt.Println(n2, Lookup(n2)) // check stored lookup returns the same thing } } }