Merge pull request #94 from rakyll/remove-type

runtime: remove unnecessary intermediate type, Status
This commit is contained in:
Michael Crosby 2016-01-28 17:40:17 -08:00
commit c29728a9b0
5 changed files with 11 additions and 20 deletions

View file

@ -201,7 +201,7 @@ func (s *apiServer) State(ctx context.Context, r *types.StateRequest) (*types.St
Id: c.ID(),
BundlePath: c.Path(),
Processes: procs,
Status: string(c.State().Status),
Status: string(c.State()),
})
}
return state, nil
@ -213,9 +213,7 @@ func (s *apiServer) UpdateContainer(ctx context.Context, r *types.UpdateContaine
if r.Signal != 0 {
e.Signal = syscall.Signal(r.Signal)
}
e.State = &runtime.State{
Status: runtime.Status(r.Status),
}
e.State = runtime.State(r.Status)
s.sv.SendEvent(e)
if err := <-e.Err; err != nil {
return nil, err

View file

@ -289,19 +289,16 @@ func (c *libcontainerContainer) Pause() error {
}
func (c *libcontainerContainer) State() runtime.State {
s := runtime.State{}
// TODO: what to do with error
state, err := c.c.Status()
if err != nil {
return s
return runtime.State("")
}
switch state {
case libcontainer.Paused, libcontainer.Pausing:
s.Status = runtime.Paused
default:
s.Status = runtime.Running
return runtime.Paused
}
return s
return runtime.State("")
}
func (c *libcontainerContainer) ID() string {

View file

@ -15,17 +15,13 @@ type Process interface {
Signal(os.Signal) error
}
type Status string
type State string
const (
Paused Status = "paused"
Running Status = "running"
Paused = State("paused")
Running = State("running")
)
type State struct {
Status Status
}
type Console interface {
io.ReadWriter
io.Closer

View file

@ -52,7 +52,7 @@ type Event struct {
Status int
Signal os.Signal
Process *specs.Process
State *runtime.State
State runtime.State
Containers []runtime.Container
Checkpoint *runtime.Checkpoint
Err chan error

View file

@ -12,8 +12,8 @@ func (h *UpdateEvent) Handle(e *Event) error {
return ErrContainerNotFound
}
container := i.container
if e.State.Status != "" {
switch e.State.Status {
if e.State != "" {
switch e.State {
case runtime.Running:
if err := container.Resume(); err != nil {
return ErrUnknownContainerStatus