github.com/pingcap/chaos@v0.0.0-20190710112158-c86faf4b3719/pkg/nemesis/nemesis.go (about) 1 package nemesis 2 3 import ( 4 "context" 5 6 "github.com/pingcap/chaos/pkg/core" 7 "github.com/pingcap/chaos/pkg/util/net" 8 ) 9 10 type kill struct{} 11 12 func (kill) Invoke(ctx context.Context, node string, args ...string) error { 13 db := core.GetDB(args[0]) 14 return db.Kill(ctx, node) 15 } 16 17 func (kill) Recover(ctx context.Context, node string, args ...string) error { 18 db := core.GetDB(args[0]) 19 return db.Start(ctx, node) 20 } 21 22 func (kill) Name() string { 23 return "kill" 24 } 25 26 type drop struct { 27 t net.IPTables 28 } 29 30 func (n drop) Invoke(ctx context.Context, node string, args ...string) error { 31 for _, dropNode := range args { 32 if node == dropNode { 33 // Don't drop itself 34 continue 35 } 36 37 if err := n.t.Drop(ctx, node, dropNode); err != nil { 38 return err 39 } 40 } 41 return nil 42 } 43 44 func (n drop) Recover(ctx context.Context, node string, args ...string) error { 45 return n.t.Heal(ctx, node) 46 } 47 48 func (drop) Name() string { 49 return "drop" 50 } 51 52 func init() { 53 core.RegisterNemesis(kill{}) 54 core.RegisterNemesis(drop{}) 55 }