move work on execution service
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
parent
dd5f74edec
commit
c857213b4c
15 changed files with 596 additions and 1016 deletions
|
@ -1,85 +1,29 @@
|
|||
package execution
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
)
|
||||
|
||||
type ContainerController interface {
|
||||
Pause(*Container) error
|
||||
Resume(*Container) error
|
||||
Status(*Container) (Status, error)
|
||||
Process(c *Container, pid int) (*Process, error)
|
||||
Processes(*Container) ([]*Process, error)
|
||||
}
|
||||
|
||||
func NewContainer(c ContainerController) *Container {
|
||||
return &Container{
|
||||
controller: c,
|
||||
}
|
||||
}
|
||||
|
||||
type Container struct {
|
||||
ID string
|
||||
Bundle string
|
||||
Root string
|
||||
controller ContainerController
|
||||
ID string
|
||||
Bundle string
|
||||
StateDir StateDir
|
||||
|
||||
processes map[int]*Process
|
||||
processes map[string]Process
|
||||
}
|
||||
|
||||
func (c *Container) Process(pid int) (*Process, error) {
|
||||
for _, p := range c.processes {
|
||||
if p.Pid == pid {
|
||||
return p, nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("todo make real error")
|
||||
func (c *Container) AddProcess(p Process) {
|
||||
c.processes[p.ID()] = p
|
||||
}
|
||||
|
||||
func (c *Container) CreateProcess(spec *specs.Process) (*Process, error) {
|
||||
if err := os.MkdirAll(filepath.Join(c.Root, c.getNextProcessID()), 0660); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
process := &Process{
|
||||
Spec: spec,
|
||||
controller: c.controller,
|
||||
}
|
||||
c.processes = append(c.processes, process)
|
||||
return process, nil
|
||||
func (c *Container) GetProcess(id string) Process {
|
||||
return c.processes[id]
|
||||
}
|
||||
|
||||
func (c *Container) DeleteProcess(pid int) error {
|
||||
process, ok := c.processes[pid]
|
||||
if !ok {
|
||||
return fmt.Errorf("it no here")
|
||||
}
|
||||
if process.Status() != Stopped {
|
||||
return fmt.Errorf("tototoit not stopped ok?")
|
||||
}
|
||||
delete(c.processes, pid)
|
||||
return os.RemoveAll(p.Root)
|
||||
func (c *Container) RemoveProcess(id string) {
|
||||
delete(c.processes, id)
|
||||
}
|
||||
|
||||
func (c *Container) Processes() []*Process {
|
||||
var out []*Process
|
||||
func (c *Container) Processes() []Process {
|
||||
var out []Process
|
||||
for _, p := range c.processes {
|
||||
out = append(out, p)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (c *Container) Pause() error {
|
||||
return c.controller.Pause(c)
|
||||
}
|
||||
|
||||
func (c *Container) Resume() error {
|
||||
return c.controller.Resume(c)
|
||||
}
|
||||
|
||||
func (c *Container) Status() (Status, error) {
|
||||
return c.controller.Status(c)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue