From 93370c5efba679adcaf1c8800ebf5e7f182ac12c Mon Sep 17 00:00:00 2001 From: Anthony ESTEBE Date: Fri, 7 Jun 2019 15:36:37 +0700 Subject: [PATCH 1/2] add start instance --- sdk/instance/start.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/instance/start.go b/sdk/instance/start.go index 5416daf4b..4d2caa80d 100644 --- a/sdk/instance/start.go +++ b/sdk/instance/start.go @@ -50,7 +50,7 @@ func (i *Instance) start(inst *instance.Instance) (serviceIDs []string, err erro "mesg.service": srv.Name, "mesg.hash": inst.Hash, "mesg.sid": srv.Sid, - "mesg.core": conf.Name, + "mesg.engine": conf.Name, }, Image: d.Image, Args: d.Args, From ed6426cfab2155341971523ce7a880cade18df08 Mon Sep 17 00:00:00 2001 From: Anthony ESTEBE Date: Fri, 7 Jun 2019 15:42:53 +0700 Subject: [PATCH 2/2] add stop for the instance --- sdk/instance/stop.go | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/sdk/instance/stop.go b/sdk/instance/stop.go index 8355324a1..0c72198aa 100644 --- a/sdk/instance/stop.go +++ b/sdk/instance/stop.go @@ -1,10 +1,42 @@ package instancesdk import ( + "sync" + "github.com/mesg-foundation/core/instance" + "github.com/mesg-foundation/core/service" + "github.com/mesg-foundation/core/x/xerrors" ) // Stop stops an instance. func (i *Instance) stop(inst *instance.Instance) error { - return nil + srv, err := i.serviceDB.Get(inst.ServiceHash) + if err != nil { + return err + } + + var ( + wg sync.WaitGroup + errs xerrors.SyncErrors + sNamespace = instanceNamespace(inst.Hash) + ) + for _, d := range append([]*service.Dependency{srv.Configuration}, srv.Dependencies...) { + // Service.Configuration can be nil so, here is a check for it. + if d == nil { + continue + } + wg.Add(1) + go func(namespace []string) { + defer wg.Done() + if err := i.container.StopService(namespace); err != nil { + errs.Append(err) + } + }(dependencyNamespace(sNamespace, d.Key)) + } + wg.Wait() + if err := errs.ErrorOrNil(); err != nil { + return err + } + + return i.container.DeleteNetwork(sNamespace) }