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