Skip to content

Commit

Permalink
Merge branch 'master' into fix-filter-volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxubeii committed Aug 22, 2018
2 parents fdbee86 + 9e49369 commit c706c78
Show file tree
Hide file tree
Showing 41 changed files with 2,292 additions and 160 deletions.
21 changes: 21 additions & 0 deletions apis/server/container_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,27 @@ func (s *Server) logsContainer(ctx context.Context, rw http.ResponseWriter, req
return nil
}

func (s *Server) statsContainer(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
name := mux.Vars(req)["name"]

var stream bool
if _, ok := req.Form["stream"]; !ok {
stream = true
}
stream = httputils.BoolValue(req, "stream")

if !stream {
rw.Header().Set("Content-Type", "application/json")
}

config := &mgr.ContainerStatsConfig{
Stream: stream,
OutStream: rw,
}

return s.ContainerMgr.StreamStats(ctx, name, config)
}

func (s *Server) resizeContainer(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
height, err := strconv.Atoi(req.FormValue("h"))
if err != nil {
Expand Down
28 changes: 28 additions & 0 deletions apis/server/exec_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"strconv"

"github.com/alibaba/pouch/apis/types"
"github.com/alibaba/pouch/daemon/mgr"
Expand Down Expand Up @@ -93,3 +94,30 @@ func (s *Server) getExecInfo(ctx context.Context, rw http.ResponseWriter, req *h
}
return EncodeResponse(rw, http.StatusOK, execInfo)
}

func (s *Server) resizeExec(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
height, err := strconv.Atoi(req.FormValue("h"))
if err != nil {
return httputils.NewHTTPError(err, http.StatusBadRequest)
}

width, err := strconv.Atoi(req.FormValue("w"))
if err != nil {
return httputils.NewHTTPError(err, http.StatusBadRequest)
}

opts := types.ResizeOptions{
Height: int64(height),
Width: int64(width),
}

name := mux.Vars(req)["name"]

if err := s.ContainerMgr.ResizeExec(ctx, name, opts); err != nil {
return err
}

rw.WriteHeader(http.StatusOK)
return nil

}
2 changes: 2 additions & 0 deletions apis/server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func initRoute(s *Server) http.Handler {
s.addRoute(r, http.MethodPost, "/containers/{name:.*}/exec", s.createContainerExec)
s.addRoute(r, http.MethodGet, "/exec/{name:.*}/json", s.getExecInfo)
s.addRoute(r, http.MethodPost, "/exec/{name:.*}/start", s.startContainerExec)
s.addRoute(r, http.MethodPost, "/exec/{name:.*}/resize", s.resizeExec)
s.addRoute(r, http.MethodPost, "/containers/{name:.*}/rename", s.renameContainer)
s.addRoute(r, http.MethodPost, "/containers/{name:.*}/restart", s.restartContainer)
s.addRoute(r, http.MethodPost, "/containers/{name:.*}/pause", s.pauseContainer)
Expand All @@ -55,6 +56,7 @@ func initRoute(s *Server) http.Handler {
s.addRoute(r, http.MethodPost, "/containers/{name:.*}/upgrade", s.upgradeContainer)
s.addRoute(r, http.MethodGet, "/containers/{name:.*}/top", s.topContainer)
s.addRoute(r, http.MethodGet, "/containers/{name:.*}/logs", withCancelHandler(s.logsContainer))
s.addRoute(r, http.MethodGet, "/containers/{name:.*}/stats", withCancelHandler(s.statsContainer))
s.addRoute(r, http.MethodPost, "/containers/{name:.*}/resize", s.resizeContainer)
s.addRoute(r, http.MethodPost, "/containers/{name:.*}/restart", s.restartContainer)
s.addRoute(r, http.MethodPost, "/containers/{name:.*}/wait", withCancelHandler(s.waitContainer))
Expand Down
Loading

0 comments on commit c706c78

Please sign in to comment.