Merge pull request #94 from rakyll/remove-type
runtime: remove unnecessary intermediate type, Status
This commit is contained in:
commit
c29728a9b0
5 changed files with 11 additions and 20 deletions
|
@ -201,7 +201,7 @@ func (s *apiServer) State(ctx context.Context, r *types.StateRequest) (*types.St
|
||||||
Id: c.ID(),
|
Id: c.ID(),
|
||||||
BundlePath: c.Path(),
|
BundlePath: c.Path(),
|
||||||
Processes: procs,
|
Processes: procs,
|
||||||
Status: string(c.State().Status),
|
Status: string(c.State()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return state, nil
|
return state, nil
|
||||||
|
@ -213,9 +213,7 @@ func (s *apiServer) UpdateContainer(ctx context.Context, r *types.UpdateContaine
|
||||||
if r.Signal != 0 {
|
if r.Signal != 0 {
|
||||||
e.Signal = syscall.Signal(r.Signal)
|
e.Signal = syscall.Signal(r.Signal)
|
||||||
}
|
}
|
||||||
e.State = &runtime.State{
|
e.State = runtime.State(r.Status)
|
||||||
Status: runtime.Status(r.Status),
|
|
||||||
}
|
|
||||||
s.sv.SendEvent(e)
|
s.sv.SendEvent(e)
|
||||||
if err := <-e.Err; err != nil {
|
if err := <-e.Err; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -289,19 +289,16 @@ func (c *libcontainerContainer) Pause() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *libcontainerContainer) State() runtime.State {
|
func (c *libcontainerContainer) State() runtime.State {
|
||||||
s := runtime.State{}
|
|
||||||
// TODO: what to do with error
|
// TODO: what to do with error
|
||||||
state, err := c.c.Status()
|
state, err := c.c.Status()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return s
|
return runtime.State("")
|
||||||
}
|
}
|
||||||
switch state {
|
switch state {
|
||||||
case libcontainer.Paused, libcontainer.Pausing:
|
case libcontainer.Paused, libcontainer.Pausing:
|
||||||
s.Status = runtime.Paused
|
return runtime.Paused
|
||||||
default:
|
|
||||||
s.Status = runtime.Running
|
|
||||||
}
|
}
|
||||||
return s
|
return runtime.State("")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *libcontainerContainer) ID() string {
|
func (c *libcontainerContainer) ID() string {
|
||||||
|
|
|
@ -15,17 +15,13 @@ type Process interface {
|
||||||
Signal(os.Signal) error
|
Signal(os.Signal) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type Status string
|
type State string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Paused Status = "paused"
|
Paused = State("paused")
|
||||||
Running Status = "running"
|
Running = State("running")
|
||||||
)
|
)
|
||||||
|
|
||||||
type State struct {
|
|
||||||
Status Status
|
|
||||||
}
|
|
||||||
|
|
||||||
type Console interface {
|
type Console interface {
|
||||||
io.ReadWriter
|
io.ReadWriter
|
||||||
io.Closer
|
io.Closer
|
||||||
|
|
|
@ -52,7 +52,7 @@ type Event struct {
|
||||||
Status int
|
Status int
|
||||||
Signal os.Signal
|
Signal os.Signal
|
||||||
Process *specs.Process
|
Process *specs.Process
|
||||||
State *runtime.State
|
State runtime.State
|
||||||
Containers []runtime.Container
|
Containers []runtime.Container
|
||||||
Checkpoint *runtime.Checkpoint
|
Checkpoint *runtime.Checkpoint
|
||||||
Err chan error
|
Err chan error
|
||||||
|
|
|
@ -12,8 +12,8 @@ func (h *UpdateEvent) Handle(e *Event) error {
|
||||||
return ErrContainerNotFound
|
return ErrContainerNotFound
|
||||||
}
|
}
|
||||||
container := i.container
|
container := i.container
|
||||||
if e.State.Status != "" {
|
if e.State != "" {
|
||||||
switch e.State.Status {
|
switch e.State {
|
||||||
case runtime.Running:
|
case runtime.Running:
|
||||||
if err := container.Resume(); err != nil {
|
if err := container.Resume(); err != nil {
|
||||||
return ErrUnknownContainerStatus
|
return ErrUnknownContainerStatus
|
||||||
|
|
Loading…
Reference in a new issue