Change /containers to /state with machine info
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
3ea5dd79e0
commit
c1eb9ac90b
5 changed files with 56 additions and 10 deletions
|
@ -30,7 +30,7 @@ func NewServer(supervisor *containerd.Supervisor) http.Handler {
|
|||
// internal method for replaying the journal
|
||||
r.HandleFunc("/event", s.event).Methods("POST")
|
||||
r.HandleFunc("/events", s.events).Methods("GET")
|
||||
r.HandleFunc("/containers", s.containers).Methods("GET")
|
||||
r.HandleFunc("/state", s.state).Methods("GET")
|
||||
return s
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ func (s *server) event(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
if e.Containers != nil && len(e.Containers) > 0 {
|
||||
if err := writeContainers(w, &e); err != nil {
|
||||
if err := s.writeState(w, &e); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
@ -170,22 +170,28 @@ func (s *server) signalPid(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *server) containers(w http.ResponseWriter, r *http.Request) {
|
||||
func (s *server) state(w http.ResponseWriter, r *http.Request) {
|
||||
e := containerd.NewEvent(containerd.GetContainerEventType)
|
||||
s.supervisor.SendEvent(e)
|
||||
if err := <-e.Err; err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if err := writeContainers(w, e); err != nil {
|
||||
if err := s.writeState(w, e); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func writeContainers(w http.ResponseWriter, e *containerd.Event) error {
|
||||
var state State
|
||||
state.Containers = []Container{}
|
||||
func (s *server) writeState(w http.ResponseWriter, e *containerd.Event) error {
|
||||
m := s.supervisor.Machine()
|
||||
state := State{
|
||||
Containers: []Container{},
|
||||
Machine: Machine{
|
||||
Cpus: m.Cpus,
|
||||
Memory: m.Memory,
|
||||
},
|
||||
}
|
||||
for _, c := range e.Containers {
|
||||
processes, err := c.Processes()
|
||||
if err != nil {
|
||||
|
|
|
@ -2,6 +2,7 @@ package v1
|
|||
|
||||
type State struct {
|
||||
Containers []Container `json:"containers"`
|
||||
Machine Machine `json:"machine"`
|
||||
}
|
||||
|
||||
type Status string
|
||||
|
@ -11,6 +12,11 @@ const (
|
|||
Running Status = "running"
|
||||
)
|
||||
|
||||
type Machine struct {
|
||||
Cpus int `json:"cpus"`
|
||||
Memory int64 `json:"memory"`
|
||||
}
|
||||
|
||||
type ContainerState struct {
|
||||
Status Status `json:"status,omitempty"`
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue