Ejemplo n.º 1
0
Archivo: edda.go Proyecto: ruo91/spigo
// Start edda, to listen for logging data from services
func Start(name string) {
	// use a waitgroup so whoever starts edda can tell the logs have been flushed
	Wg.Add(1)
	defer Wg.Done()
	if Logchan == nil {
		return
	}
	var msg gotocol.Message
	microservices := make(map[string]bool, archaius.Conf.Dunbar)
	edges := make(map[string]bool, archaius.Conf.Dunbar)
	var ok bool
	hist := collect.NewHist(name)
	log.Println(name + ": starting")
	if archaius.Conf.GraphmlFile != "" {
		graphml.Setup(archaius.Conf.GraphmlFile)
	}
	if archaius.Conf.GraphjsonFile != "" {
		graphjson.Enabled = true
		graphjson.Setup(archaius.Conf.GraphjsonFile)
	}
	for {
		msg, ok = <-Logchan
		collect.Measure(hist, time.Since(msg.Sent))
		if !ok {
			break // channel was closed
		}
		if archaius.Conf.Msglog {
			log.Printf("%v(backlog %v): %v\n", name, len(Logchan), msg)
		}
		switch msg.Imposition {
		case gotocol.Inform:
			edge := names.FilterEdge(msg.Intention)
			if edges[edge] == false { // only log an edge once
				edges[edge] = true
				graphml.WriteEdge(edge)
				graphjson.WriteEdge(edge, msg.Sent)
			}
		case gotocol.Put:
			node := names.FilterNode(msg.Intention)
			if microservices[node] == false { // only log a node once
				microservices[node] = true
				graphml.WriteNode(node + " " + names.Package(msg.Intention))
				graphjson.WriteNode(node+" "+names.Package(msg.Intention), msg.Sent)
			}
		case gotocol.Forget: // forget the edge
			graphjson.WriteForget(msg.Intention, msg.Sent)
		case gotocol.Delete: // remove the node
			if microservices[msg.Intention] == true { // only remove nodes that exist, and only log it once
				microservices[msg.Intention] = false
				graphjson.WriteDone(msg.Intention, msg.Sent)
			}
		}
	}
	log.Println(name + ": closing")
	graphml.Close()
	graphjson.Close()
}
Ejemplo n.º 2
0
// Reload the network from a file
func Reload(arch string) string {
	root := ""
	g := graphjson.ReadArch(arch)
	archaius.Conf.Population = 0 // just to make sure
	// count how many nodes there are
	for _, element := range g.Graph {
		if element.Node != "" {
			archaius.Conf.Population++
		}
	}
	CreateChannels()
	CreateEureka()
	// eureka and edda aren't recorded in the json file to simplify the graph
	// Start all the services
	for _, element := range g.Graph {
		if element.Node != "" {
			name := element.Node
			StartNode(name, "")
			if names.Package(name) == DenominatorPkg {
				root = name
			}
		}
	}
	// Make all the connections
	for _, element := range g.Graph {
		if element.Edge != "" && element.Source != "" && element.Target != "" {
			Connect(element.Source, element.Target)
		}
	}
	// run for a while
	if root == "" {
		log.Fatal("No denominator root microservice specified")
	}
	return root
}
Ejemplo n.º 3
0
// Reload the network from a file
func Reload(arch string) string {
	root := ""
	g := graphjson.ReadArch(arch)
	archaius.Conf.Population = 0 // just to make sure
	// count how many nodes there are
	for _, element := range g.Graph {
		if element.Node != "" {
			archaius.Conf.Population++
		}
	}
	CreateChannels()
	CreateEureka()
	// eureka and edda aren't recorded in the json file to simplify the graph
	// Start all the services
	cass := make(map[string]chan gotocol.Message) // for token distribution
	for _, element := range g.Graph {
		if element.Node != "" {
			name := element.Node
			StartNode(name, "")
			if names.Package(name) == DenominatorPkg {
				root = name
			}
			if names.Package(name) == "priamCassandra" {
				cass[name] = noodles[name] // remember the nodes
			}
		}
	}
	if len(cass) > 0 { // currently doesn't handle multiple priamCassandra per arch
		priamCassandra.Distribute(cass) // returns a string if it needs logging
	}
	// Make all the connections
	for _, element := range g.Graph {
		if element.Edge != "" && element.Source != "" && element.Target != "" {
			Connect(element.Source, element.Target)
		}
	}
	// run for a while
	if root == "" {
		log.Fatal("No denominator root microservice specified")
	}
	return root
}
Ejemplo n.º 4
0
// Start a node using the named package, and connect it to any dependencies
func StartNode(name string, dependencies ...string) {
	if names.Package(name) == "eureka" {
		eurekachan[name] = make(chan gotocol.Message, archaius.Conf.Population)
		go eureka.Start(eurekachan[name], name)
		return
	} else {
		noodles[name] = make(chan gotocol.Message)
	}
	// start the service and tell it it's name
	switch names.Package(name) {
	case "pirate":
		go pirate.Start(noodles[name])
	case "elb":
		go elb.Start(noodles[name])
	case "denominator":
		go denominator.Start(noodles[name])
	case "zuul":
		go zuul.Start(noodles[name])
	case "karyon":
		go karyon.Start(noodles[name])
	case "monolith":
		go monolith.Start(noodles[name])
	case "staash":
		go staash.Start(noodles[name])
	case "priamCassandra":
		go priamCassandra.Start(noodles[name])
	case "store":
		go store.Start(noodles[name])
	default:
		log.Fatal("asgard: unknown package: " + names.Package(name))
	}
	noodles[name] <- gotocol.Message{gotocol.Hello, listener, time.Now(), gotocol.NilContext, name}
	// there is a eureka service registry in each zone, so in-zone services just get to talk to their local registry
	// elb are cross zone, so need to see all registries in a region
	// denominator are cross region so need to see all registries globally
	// priamCassandra depends explicitly on eureka for cross region clusters
	crossregion := false
	for _, d := range dependencies {
		if d == "eureka" {
			crossregion = true
		}
	}
	for n, ch := range eurekachan {
		if names.Region(name) == "*" || crossregion {
			// need to know every eureka in all zones and regions
			gotocol.Send(noodles[name], gotocol.Message{gotocol.Inform, ch, time.Now(), gotocol.NilContext, n})
		} else {
			if names.Zone(name) == "*" && names.Region(name) == names.Region(n) {
				// need every eureka in my region
				gotocol.Send(noodles[name], gotocol.Message{gotocol.Inform, ch, time.Now(), gotocol.NilContext, n})
			} else {
				if names.RegionZone(name) == names.RegionZone(n) {
					// just the eureka in this specific zone
					gotocol.Send(noodles[name], gotocol.Message{gotocol.Inform, ch, time.Now(), gotocol.NilContext, n})
				}
			}
		}
	}
	//log.Println(dependencies)
	// pass on symbolic dependencies without channels that will be looked up in Eureka later
	for _, dep := range dependencies {
		if dep != "" && dep != "eureka" { // ignore special case of eureka in dependency list
			//log.Println(name + " depends on " + dep)
			gotocol.Send(noodles[name], gotocol.Message{gotocol.NameDrop, nil, time.Now(), gotocol.NilContext, dep})
		}
	}
}