engine: Rename world API and add a context
We want to be able to pass ctx through for various reasons.
This commit is contained in:
@@ -230,11 +230,11 @@ func (obj *DeployArgs) Run(ctx context.Context, data *cliUtil.Data) (bool, error
|
||||
Logf("world: etcd: "+format, v...)
|
||||
},
|
||||
}
|
||||
if err := world.Init(worldInit); err != nil {
|
||||
return false, errwrap.Wrapf(err, "world Init failed")
|
||||
if err := world.Connect(ctx, worldInit); err != nil {
|
||||
return false, errwrap.Wrapf(err, "world Connect failed")
|
||||
}
|
||||
defer func() {
|
||||
err := errwrap.Wrapf(world.Close(), "world Close failed")
|
||||
err := errwrap.Wrapf(world.Cleanup(), "world Cleanup failed")
|
||||
if err != nil {
|
||||
// TODO: cause the final exit code to be non-zero?
|
||||
Logf("close error: %+v", err)
|
||||
|
||||
@@ -54,11 +54,11 @@ type WorldInit struct {
|
||||
// GAPI to store state and exchange information throughout the cluster. It is
|
||||
// the interface each machine uses to communicate with the rest of the world.
|
||||
type World interface { // TODO: is there a better name for this interface?
|
||||
// Init sets things up and is called once before any other methods.
|
||||
Init(*WorldInit) error
|
||||
// Connect sets things up and is called once before any other methods.
|
||||
Connect(context.Context, *WorldInit) error
|
||||
|
||||
// Close does some cleanup and is the last method that is ever called.
|
||||
Close() error
|
||||
// Cleanup does some cleanup and is the last method that is ever called.
|
||||
Cleanup() error
|
||||
|
||||
FsWorld
|
||||
|
||||
|
||||
@@ -143,8 +143,8 @@ func (obj *World) hostKeyCallback() (ssh.HostKeyCallback, error) {
|
||||
return knownhosts.New(p)
|
||||
}
|
||||
|
||||
// Init runs first.
|
||||
func (obj *World) Init(init *engine.WorldInit) error {
|
||||
// Connect runs first.
|
||||
func (obj *World) Connect(ctx context.Context, init *engine.WorldInit) error {
|
||||
obj.init = init
|
||||
obj.cleanups = []func() error{}
|
||||
|
||||
@@ -310,11 +310,11 @@ func (obj *World) Init(init *engine.WorldInit) error {
|
||||
StandaloneFs: obj.StandaloneFs,
|
||||
GetURI: obj.GetURI,
|
||||
}
|
||||
if err := obj.World.Init(init); err != nil {
|
||||
if err := obj.World.Connect(ctx, init); err != nil {
|
||||
return errwrap.Append(obj.cleanup(), err)
|
||||
}
|
||||
obj.cleanups = append(obj.cleanups, func() error {
|
||||
e := obj.World.Close()
|
||||
e := obj.World.Cleanup()
|
||||
if obj.init.Debug && e != nil {
|
||||
obj.init.Logf("world close error: %+v", e)
|
||||
}
|
||||
@@ -337,7 +337,7 @@ func (obj *World) cleanup() error {
|
||||
return errs
|
||||
}
|
||||
|
||||
// Close runs last.
|
||||
func (obj *World) Close() error {
|
||||
// CLeanup runs last.
|
||||
func (obj *World) Cleanup() error {
|
||||
return obj.cleanup()
|
||||
}
|
||||
|
||||
@@ -78,8 +78,8 @@ type World struct {
|
||||
cleanups []func() error
|
||||
}
|
||||
|
||||
// Init runs first.
|
||||
func (obj *World) Init(init *engine.WorldInit) error {
|
||||
// Connect runs first.
|
||||
func (obj *World) Connect(ctx context.Context, init *engine.WorldInit) error {
|
||||
obj.init = init
|
||||
|
||||
obj.client = obj.Client // legacy default
|
||||
@@ -135,8 +135,8 @@ func (obj *World) cleanup() error {
|
||||
return errs
|
||||
}
|
||||
|
||||
// Close runs last.
|
||||
func (obj *World) Close() error {
|
||||
// Cleanup runs last.
|
||||
func (obj *World) Cleanup() error {
|
||||
return obj.cleanup()
|
||||
}
|
||||
|
||||
|
||||
@@ -905,12 +905,12 @@ func TestAstFunc2(t *testing.T) {
|
||||
logf("world: etcd: "+format, v...)
|
||||
},
|
||||
}
|
||||
if err := world.Init(worldInit); err != nil {
|
||||
t.Errorf("world Init failed: %+v", err)
|
||||
if err := world.Connect(context.TODO(), worldInit); err != nil {
|
||||
t.Errorf("world Connect failed: %+v", err)
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
err := errwrap.Wrapf(world.Close(), "world Close failed")
|
||||
err := errwrap.Wrapf(world.Cleanup(), "world Cleanup failed")
|
||||
if err != nil {
|
||||
t.Errorf("close error: %+v", err)
|
||||
}
|
||||
@@ -1805,12 +1805,12 @@ func TestAstFunc3(t *testing.T) {
|
||||
logf("world: etcd: "+format, v...)
|
||||
},
|
||||
}
|
||||
if err := world.Init(worldInit); err != nil {
|
||||
t.Errorf("world Init failed: %+v", err)
|
||||
if err := world.Connect(context.TODO(), worldInit); err != nil {
|
||||
t.Errorf("world Connect failed: %+v", err)
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
err := errwrap.Wrapf(world.Close(), "world Close failed")
|
||||
err := errwrap.Wrapf(world.Cleanup(), "world Cleanup failed")
|
||||
if err != nil {
|
||||
t.Errorf("close error: %+v", err)
|
||||
}
|
||||
|
||||
@@ -640,11 +640,11 @@ func (obj *Main) Run() error {
|
||||
obj.Logf("world: etcd: "+format, v...)
|
||||
},
|
||||
}
|
||||
if err := world.Init(worldInit); err != nil {
|
||||
return errwrap.Wrapf(err, "world Init failed")
|
||||
if err := world.Connect(exitCtx, worldInit); err != nil {
|
||||
return errwrap.Wrapf(err, "world Connect failed")
|
||||
}
|
||||
defer func() {
|
||||
err := errwrap.Wrapf(world.Close(), "world Close failed")
|
||||
err := errwrap.Wrapf(world.Cleanup(), "world Cleanup failed")
|
||||
if err != nil {
|
||||
// TODO: cause the final exit code to be non-zero?
|
||||
Logf("close error: %+v", err)
|
||||
|
||||
Reference in New Issue
Block a user