func (s stateInactiveGracePeriod) action() action {
	return stop
}
action implements state.action()
package checkpoint
import (
	"fmt"
	"time"
	"github.com/golang/glog"
)
type apiCondition struct {
	apiAvailable bool
	apiParent bool
	localRunning bool
	localParent bool
}
func (a apiCondition) String() string {
	return fmt.Sprintf("apiAvailable=%t, apiParent=%t, localRunning=%t, localParent=%t", a.apiAvailable, a.apiParent, a.localRunning, a.localParent)
}
type action int
const (
	none = iota
	start
	stop
	remove
)
func (a action) String() string {
	switch a {
	case none:
		return "none"
	case start:
		return "start"
	case stop:
		return "stop"
	case remove:
		return "remove"
	default:
		return "[unknown action]"
	}
}
type checkpointState interface {
	transition(time.Time, apiCondition) checkpointState
	action() action
}
type stateSelfCheckpointActive struct{}
func (s stateSelfCheckpointActive) transition(now time.Time, apis apiCondition) checkpointState {
	if !apis.apiAvailable {
		return s
	}
	if apis.apiParent {
		return s
	}
	return stateActiveGracePeriod{gracePeriodEnd: now.Add(checkpointGracePeriod)}.checkGracePeriod(now, apis)
}
func (s stateSelfCheckpointActive) action() action {
	return start
}
func (s stateSelfCheckpointActive) String() string {
	return "self-checkpoint"
}
type stateNone struct{}
func (s stateNone) transition(now time.Time, apis apiCondition) checkpointState {
	if apis.localRunning || apis.localParent {
		return stateInactive{}.transition(now, apis)
	}
	return s
}
func (s stateNone) action() action {
	return none
}
func (s stateNone) String() string {
	return "none"
}
type stateInactive struct{}
func (s stateInactive) transition(now time.Time, apis apiCondition) checkpointState {
	if !apis.apiAvailable {
		if apis.localRunning {
			return s
		}
		return stateActive{}
	}
	if apis.apiParent {
		if apis.localRunning {
			return s
		}
		return stateActive{}
	}
	return stateInactiveGracePeriod{gracePeriodEnd: now.Add(checkpointGracePeriod)}.checkGracePeriod(now, apis)
}
func (s stateInactive) action() action {
	return stop
}
func (s stateInactive) String() string {
	return "inactive"
}
type stateInactiveGracePeriod struct {
	gracePeriodEnd time.Time
}
func (s stateInactiveGracePeriod) transition(now time.Time, apis apiCondition) checkpointState {
	if !apis.apiAvailable {
		if apis.localRunning {
			return s.checkGracePeriod(now, apis)
		}
		return stateActive{}
	}
	if apis.apiParent {
		if apis.localRunning {
			return stateInactive{}
		}
		return stateActive{}
	}
	return s.checkGracePeriod(now, apis)
}
func (s stateInactiveGracePeriod) checkGracePeriod(now time.Time, apis apiCondition) checkpointState {
	if now.Equal(s.gracePeriodEnd) || now.After(s.gracePeriodEnd) {
		glog.Infof("Grace period exceeded for state %s", s)
		return stateRemove{}
	}
	return s
}