Merge pull request #513 from duglin/RemoveNullState
Remove the nullState
This commit is contained in:
commit
ee0a019448
|
@ -14,8 +14,11 @@ import (
|
||||||
type Status int
|
type Status int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// The container exists but has not been run yet
|
||||||
|
Created Status = iota
|
||||||
|
|
||||||
// The container exists and is running.
|
// The container exists and is running.
|
||||||
Running Status = iota + 1
|
Running
|
||||||
|
|
||||||
// The container exists, it is in the process of being paused.
|
// The container exists, it is in the process of being paused.
|
||||||
Pausing
|
Pausing
|
||||||
|
@ -32,6 +35,8 @@ const (
|
||||||
|
|
||||||
func (s Status) String() string {
|
func (s Status) String() string {
|
||||||
switch s {
|
switch s {
|
||||||
|
case Created:
|
||||||
|
return "created"
|
||||||
case Running:
|
case Running:
|
||||||
return "running"
|
return "running"
|
||||||
case Pausing:
|
case Pausing:
|
||||||
|
@ -43,7 +48,7 @@ func (s Status) String() string {
|
||||||
case Destroyed:
|
case Destroyed:
|
||||||
return "destroyed"
|
return "destroyed"
|
||||||
default:
|
default:
|
||||||
return "undefined"
|
return "unknown"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -166,7 +166,7 @@ func TestGetContainerState(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
container.state = &nullState{c: container}
|
container.state = &createdState{c: container}
|
||||||
state, err := container.State()
|
state, err := container.State()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
|
@ -202,7 +202,7 @@ func (l *LinuxFactory) Load(id string) (Container, error) {
|
||||||
cgroupManager: l.NewCgroupsManager(state.Config.Cgroups, state.CgroupPaths),
|
cgroupManager: l.NewCgroupsManager(state.Config.Cgroups, state.CgroupPaths),
|
||||||
root: containerRoot,
|
root: containerRoot,
|
||||||
}
|
}
|
||||||
c.state = &nullState{c: c}
|
c.state = &createdState{c: c, s: Created}
|
||||||
if err := c.refreshState(); err != nil {
|
if err := c.refreshState(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ func (r *runningState) transition(s containerState) error {
|
||||||
}
|
}
|
||||||
r.c.state = s
|
r.c.state = s
|
||||||
return nil
|
return nil
|
||||||
case *pausedState, *nullState:
|
case *pausedState:
|
||||||
r.c.state = s
|
r.c.state = s
|
||||||
return nil
|
return nil
|
||||||
case *runningState:
|
case *runningState:
|
||||||
|
@ -202,22 +202,22 @@ func (r *restoredState) destroy() error {
|
||||||
return destroy(r.c)
|
return destroy(r.c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// nullState is used whenever a container is restored, loaded, or setting additional
|
// createdState is used whenever a container is restored, loaded, or setting additional
|
||||||
// processes inside and it should not be destroyed when it is exiting.
|
// processes inside and it should not be destroyed when it is exiting.
|
||||||
type nullState struct {
|
type createdState struct {
|
||||||
c *linuxContainer
|
c *linuxContainer
|
||||||
s Status
|
s Status
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *nullState) status() Status {
|
func (n *createdState) status() Status {
|
||||||
return n.s
|
return n.s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *nullState) transition(s containerState) error {
|
func (n *createdState) transition(s containerState) error {
|
||||||
n.c.state = s
|
n.c.state = s
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *nullState) destroy() error {
|
func (n *createdState) destroy() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,9 +69,9 @@ func TestRestoredStateTransition(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err := s.transition(&nullState{})
|
err := s.transition(&createdState{})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("transition to null state should fail")
|
t.Fatal("transition to created state should fail")
|
||||||
}
|
}
|
||||||
if !isStateTransitionError(err) {
|
if !isStateTransitionError(err) {
|
||||||
t.Fatal("expected stateTransitionError")
|
t.Fatal("expected stateTransitionError")
|
||||||
|
|
Loading…
Reference in New Issue