Skip to content

Commit

Permalink
container architecture added
Browse files Browse the repository at this point in the history
architecture file format extended to include container level
information. All output json graph files regenerated.
  • Loading branch information
adrianco committed Jul 13, 2015
1 parent 48265cc commit 06aa6c2
Show file tree
Hide file tree
Showing 62 changed files with 421,433 additions and 423,430 deletions.
40 changes: 26 additions & 14 deletions architecture/architecture.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (
"log"
)

type archV0r0 struct {
Arch string `json:"arch"`
Version string `json:"version"`
Description string `json:"description,omitempty"`
Args string `json:"args,omitempty"`
Date string `json:"date,omitempty"`
Victim string `json:"victim,omitempty"`
Services []serviceV0r0 `json:"services"`
type archV0r1 struct {
Arch string `json:"arch"`
Version string `json:"version"`
Description string `json:"description,omitempty"`
Args string `json:"args,omitempty"`
Date string `json:"date,omitempty"`
Victim string `json:"victim,omitempty"`
Services []containerV0r0 `json:"services"`
}

type serviceV0r0 struct {
Expand All @@ -28,8 +28,20 @@ type serviceV0r0 struct {
Dependencies []string `json:"dependencies"`
}

type containerV0r0 struct {
Name string `json:"name"`
Machine string `json:"machine,omitempty"`
Instance string `json:"instance,omitempty"`
Container string `json:"container,omitempty"`
Process string `json:"process,omitempty"`
Gopackage string `json:"package"`
Regions int `json:"regions,omitempty"`
Count int `json:"count"`
Dependencies []string `json:"dependencies"`
}

// Start architecture
func Start(a *archV0r0) {
func Start(a *archV0r1) {
var r string
if archaius.Conf.Population < 1 {
log.Fatal("architecture: can't create less than 1 microservice")
Expand All @@ -41,20 +53,20 @@ func Start(a *archV0r0) {

for _, s := range a.Services {
log.Printf("Starting: %v\n", s)
r = asgard.Create(s.Name, s.Package, s.Regions*archaius.Conf.Regions, s.Count*archaius.Conf.Population/100, s.Dependencies...)
r = asgard.Create(s.Name, s.Gopackage, s.Regions*archaius.Conf.Regions, s.Count*archaius.Conf.Population/100, s.Dependencies...)
}
asgard.Run(r, a.Victim) // run the last service in the list, and point chaos monkey at the victim
}

// ReadArch parses archjson
func ReadArch(arch string) *archV0r0 {
func ReadArch(arch string) *archV0r1 {
fn := "json_arch/" + arch + "_arch.json"
log.Println("Loading architecture from " + fn)
data, err := ioutil.ReadFile(fn)
if err != nil {
log.Fatal(err)
}
a := new(archV0r0)
a := new(archV0r1)
e := json.Unmarshal(data, a)
if e == nil {
names := make(map[string]bool, 10)
Expand All @@ -72,10 +84,10 @@ func ReadArch(arch string) *archV0r0 {
} else {
names[s.Name] = true
}
if packs[s.Package] != true {
if packs[s.Gopackage] != true {
log.Println(packs)
log.Println(s)
log.Fatal("Unknown package name in architecture: " + s.Package)
log.Fatal("Unknown package name in architecture: " + s.Gopackage)
}
}
// check all the dependencies
Expand Down
17 changes: 9 additions & 8 deletions architecture/architecture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func try(t string) {
a := new(archV0r0)
a := new(archV0r1)
err := json.Unmarshal([]byte(t), a)
if err != nil {
fmt.Println(err)
Expand All @@ -25,18 +25,19 @@ func try(t string) {

// reader parses graphjson
func TestGraph(t *testing.T) {
testJSONarchV0r0 := `
testJSONarchV0r1 := `
{
"arch":"netflixoss",
"version":"arch-0.0",
"args":"[spigo -j -d=0 -a netflixoss]",
"version":"arch-0.1",
"args":"[spigo -j -d=0 -a testContainer]",
"victim":"homepage-node",
"date":"2015-04-26T23:52:45.959905585+12:00",
"services":[
{ "name":"mysql", "package":"store", "regions":1, "count":2, "dependencies":[] },
{ "name":"homepage-node", "package":"karyon", "regions":1, "count":9, "dependencies":["mysql"] },
{ "name":"signup-node", "package":"karyon", "regions":1, "count":3, "dependencies":["mysql"] },
{ "name":"www-proxy", "package":"zuul", "regions":1, "count":3, "dependencies":["signup-node", "homepage-node"] },
{ "name":"homepage", "machine":"ecs:4", "container":"adrianco/homepage-node", "package":"karyon", "regions":1, "count":9, "dependencies":["mysql"] },
{ "name":"signup", "package":"karyon", "machine":"ecs:1", "container":"adrianco/signup-node", "process":"signup-node", "regions":1, "count":3, "dependencies":["mysql"] },
{ "name":"signup-waf", "package":"karyon", "machine":"ecs:1", "container":"adrianco/signup-node", "process":"waf", "regions":1, "count":3, "dependencies":["signup-node"] },
{ "name":"www-proxy", "package":"zuul", "regions":1, "count":3, "dependencies":["signup-waf", "homepage"] },
{ "name":"www-elb", "package":"elb", "regions":1, "count":0, "dependencies":["www-proxy"] },
{ "name":"www", "package":"denominator", "regions":0, "count":0, "dependencies":["www-elb"] }
]
Expand All @@ -53,7 +54,7 @@ func TestGraph(t *testing.T) {
//archaius.Conf.Collect = false
//archaius.Conf.StopStep = 0
archaius.Conf.EurekaPoll = "1s"
try(testJSONarchV0r0)
try(testJSONarchV0r1)
//ReadArch("testDuplicate") // these three are designed to fail, uncomment one at a time to check
//ReadArch("testMissingDep")
//ReadArch("testBadPackage")
Expand Down
24 changes: 12 additions & 12 deletions architecture/json_arch/test_arch.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"arch":"test",
"version":"arch-0.0",
"args":"[spigo -j -d=0 -a netflixoss]",
"description":"test structure",
"victim":"homepage-node",
"date":"2015-04-26T23:52:45.959905585+12:00",
"arch":"testContainer",
"version":"arch-0.1",
"args":"[spigo -j -d=0 -a testContainer]",
"victim":"homepage",
"date":"2015-04-26T23:52:45.959905585+12:00",
"services":[
{ "name":"mysql", "package":"store", "regions":1, "count":2, "dependencies":[] },
{ "name":"homepage-node", "package":"karyon", "regions":1, "count":9, "dependencies":["mysql"] },
{ "name":"signup-node", "package":"karyon", "regions":1, "count":3, "dependencies":["mysql"] },
{ "name":"www-proxy", "package":"zuul", "regions":1, "count":3, "dependencies":["signup-node", "homepage-node"] },
{ "name":"www-elb", "package":"elb", "regions":1, "count":0, "dependencies":["www-proxy"] },
{ "name":"www", "package":"denominator", "regions":0, "count":0, "dependencies":["www-elb"] }
{ "name":"mysql", "package":"store", "regions":1, "count":2, "dependencies":["mysql"] },
{ "name":"homepage", "machine":"ecs:4", "container":"adrianco/homepage-node", "package":"karyon", "regions":1, "count":9, "dependencies":["mysql"] },
{ "name":"signup", "package":"karyon", "machine":"ecs:1", "container":"adrianco/signup-node", "process":"signup-node", "regions":1, "count":3, "dependencies":["mysql"] },
{ "name":"signup-waf", "package":"karyon", "machine":"ecs:1", "container":"adrianco/signup-node", "process":"waf", "regions":1, "count":3, "dependencies":["signup"] },
{ "name":"www-proxy", "package":"zuul", "regions":1, "count":3, "dependencies":["signup-waf", "homepage"] },
{ "name":"www-elb", "package":"elb", "regions":1, "count":0, "dependencies":["www-proxy"] },
{ "name":"www", "package":"denominator", "regions":0, "count":0, "dependencies":["www-elb"] }
]
}
16 changes: 12 additions & 4 deletions edda/edda.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,19 @@ func Start(name string) {
graphjson.WriteNode(node+" "+names.Package(msg.Intention), msg.Sent)
}
case gotocol.Forget: // forget the edge
graphjson.WriteForget(msg.Intention, msg.Sent)
// problem here in that edges may be reported multiple times from several sources
// however after filtering all matching edges are reported as forgotten when the first is
// need to maintain the full model and a filtered model with counts
edge := names.FilterEdge(msg.Intention)
if edges[edge] == true { // only remove an edge once
edges[edge] = false
graphjson.WriteForget(edge, 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)
node := names.FilterNode(msg.Intention)
if microservices[node] == true { // only remove nodes that exist, and only log it once
microservices[node] = false
graphjson.WriteDone(node, msg.Sent)
}
}
}
Expand Down
Loading

0 comments on commit 06aa6c2

Please sign in to comment.