Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop instance #1035

Merged
merged 3 commits into from
Jun 16, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/instance/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
34 changes: 33 additions & 1 deletion sdk/instance/stop.go
Original file line number Diff line number Diff line change
@@ -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)
}