2015-12-18 00:07:04 +00:00
|
|
|
package supervisor
|
2015-11-05 23:29:53 +00:00
|
|
|
|
2015-11-10 22:24:34 +00:00
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"time"
|
2015-11-10 22:57:10 +00:00
|
|
|
|
2015-12-01 19:56:08 +00:00
|
|
|
"github.com/docker/containerd/runtime"
|
2015-11-10 22:57:10 +00:00
|
|
|
"github.com/opencontainers/specs"
|
2015-11-10 22:24:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type EventType string
|
|
|
|
|
|
|
|
const (
|
2015-12-04 00:07:53 +00:00
|
|
|
ExecExitEventType EventType = "execExit"
|
|
|
|
ExitEventType EventType = "exit"
|
|
|
|
StartContainerEventType EventType = "startContainer"
|
|
|
|
DeleteEventType EventType = "deleteContainerEvent"
|
|
|
|
GetContainerEventType EventType = "getContainer"
|
|
|
|
SignalEventType EventType = "signal"
|
|
|
|
AddProcessEventType EventType = "addProcess"
|
|
|
|
UpdateContainerEventType EventType = "updateContainer"
|
|
|
|
CreateCheckpointEventType EventType = "createCheckpoint"
|
2015-12-04 22:00:07 +00:00
|
|
|
DeleteCheckpointEventType EventType = "deleteCheckpoint"
|
2015-12-14 22:43:00 +00:00
|
|
|
StatsEventType EventType = "events"
|
2015-12-16 17:39:28 +00:00
|
|
|
UnsubscribeStatsEventType EventType = "unsubscribeStats"
|
|
|
|
StopStatsEventType EventType = "stopStats"
|
2015-12-16 00:22:53 +00:00
|
|
|
OOMEventType EventType = "oom"
|
2015-11-10 22:24:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func NewEvent(t EventType) *Event {
|
|
|
|
return &Event{
|
|
|
|
Type: t,
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
Err: make(chan error, 1),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-16 00:22:53 +00:00
|
|
|
type StartResponse struct {
|
2016-01-06 21:32:46 +00:00
|
|
|
Stdin string
|
|
|
|
Stdout string
|
|
|
|
Stderr string
|
2015-12-16 00:22:53 +00:00
|
|
|
}
|
|
|
|
|
2015-11-10 22:24:34 +00:00
|
|
|
type Event struct {
|
2015-12-16 00:22:53 +00:00
|
|
|
Type EventType
|
|
|
|
Timestamp time.Time
|
|
|
|
ID string
|
|
|
|
BundlePath string
|
|
|
|
Stdout string
|
|
|
|
Stderr string
|
|
|
|
Stdin string
|
|
|
|
Console string
|
2016-01-06 21:32:46 +00:00
|
|
|
Pid string
|
2015-12-16 00:22:53 +00:00
|
|
|
Status int
|
|
|
|
Signal os.Signal
|
2016-01-06 21:32:46 +00:00
|
|
|
Process runtime.Process
|
2016-01-27 22:19:10 +00:00
|
|
|
State runtime.State
|
2016-01-06 21:32:46 +00:00
|
|
|
ProcessSpec *specs.Process
|
2015-12-16 00:22:53 +00:00
|
|
|
Containers []runtime.Container
|
|
|
|
Checkpoint *runtime.Checkpoint
|
|
|
|
Err chan error
|
|
|
|
StartResponse chan StartResponse
|
|
|
|
Stats chan interface{}
|
2015-11-10 21:44:35 +00:00
|
|
|
}
|
2015-12-01 18:55:13 +00:00
|
|
|
|
|
|
|
type Handler interface {
|
|
|
|
Handle(*Event) error
|
|
|
|
}
|
2015-12-16 21:53:11 +00:00
|
|
|
|
|
|
|
type commonEvent struct {
|
|
|
|
data *Event
|
|
|
|
sv *Supervisor
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *commonEvent) Handle() {
|
|
|
|
h, ok := e.sv.handlers[e.data.Type]
|
|
|
|
if !ok {
|
|
|
|
e.data.Err <- ErrUnknownEvent
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err := h.Handle(e.data)
|
|
|
|
if err != errDeferedResponse {
|
|
|
|
e.data.Err <- err
|
|
|
|
close(e.data.Err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|