-
Notifications
You must be signed in to change notification settings - Fork 949
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: reorder function sequence to make it more reasonable
Signed-off-by: Allen Sun <[email protected]>
- Loading branch information
1 parent
1313931
commit 8ff99bf
Showing
10 changed files
with
706 additions
and
666 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package server | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/alibaba/pouch/apis/types" | ||
"github.com/alibaba/pouch/daemon/mgr" | ||
"github.com/alibaba/pouch/pkg/httputils" | ||
|
||
"github.com/go-openapi/strfmt" | ||
"github.com/gorilla/mux" | ||
) | ||
|
||
func (s *Server) createContainerExec(ctx context.Context, rw http.ResponseWriter, req *http.Request) error { | ||
config := &types.ExecCreateConfig{} | ||
// decode request body | ||
if err := json.NewDecoder(req.Body).Decode(config); err != nil { | ||
return httputils.NewHTTPError(err, http.StatusBadRequest) | ||
} | ||
// validate request body | ||
if err := config.Validate(strfmt.NewFormats()); err != nil { | ||
return httputils.NewHTTPError(err, http.StatusBadRequest) | ||
} | ||
|
||
name := mux.Vars(req)["name"] | ||
|
||
id, err := s.ContainerMgr.CreateExec(ctx, name, config) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
execCreateResp := &types.ExecCreateResp{ | ||
ID: id, | ||
} | ||
|
||
return EncodeResponse(rw, http.StatusCreated, execCreateResp) | ||
} | ||
|
||
func (s *Server) startContainerExec(ctx context.Context, rw http.ResponseWriter, req *http.Request) error { | ||
config := &types.ExecStartConfig{} | ||
// decode request body | ||
if err := json.NewDecoder(req.Body).Decode(config); err != nil { | ||
return httputils.NewHTTPError(err, http.StatusBadRequest) | ||
} | ||
// validate request body | ||
if err := config.Validate(strfmt.NewFormats()); err != nil { | ||
return httputils.NewHTTPError(err, http.StatusBadRequest) | ||
} | ||
|
||
name := mux.Vars(req)["name"] | ||
_, upgrade := req.Header["Upgrade"] | ||
|
||
var attach *mgr.AttachConfig | ||
|
||
if !config.Detach { | ||
hijacker, ok := rw.(http.Hijacker) | ||
if !ok { | ||
return fmt.Errorf("not a hijack connection, container: %s", name) | ||
} | ||
|
||
attach = &mgr.AttachConfig{ | ||
Hijack: hijacker, | ||
Stdin: config.Tty, | ||
Stdout: true, | ||
Stderr: true, | ||
Upgrade: upgrade, | ||
} | ||
} | ||
|
||
return s.ContainerMgr.StartExec(ctx, name, config, attach) | ||
} | ||
|
||
func (s *Server) getExecInfo(ctx context.Context, rw http.ResponseWriter, req *http.Request) error { | ||
name := mux.Vars(req)["name"] | ||
execInfo, err := s.ContainerMgr.InspectExec(ctx, name) | ||
if err != nil { | ||
return err | ||
} | ||
return EncodeResponse(rw, http.StatusOK, execInfo) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.