Plumb deployment request through client

pull/462/head
jackgr 9 years ago
parent 212dece6aa
commit 2bb5680917

@ -202,9 +202,9 @@ func createDeploymentHandlerFunc(w http.ResponseWriter, r *http.Request, c *rout
handler := "manager: create deployment" handler := "manager: create deployment"
util.LogHandlerEntry(handler, r) util.LogHandlerEntry(handler, r)
defer r.Body.Close() defer r.Body.Close()
t := getTemplate(w, r, handler) depReq := getDeploymentRequest(w, r, handler)
if t != nil { if depReq != nil {
d, err := c.Manager.CreateDeployment(t) d, err := c.Manager.CreateDeployment(depReq)
if err != nil { if err != nil {
httputil.BadRequest(w, r, err) httputil.BadRequest(w, r, err)
return nil return nil
@ -212,6 +212,7 @@ func createDeploymentHandlerFunc(w http.ResponseWriter, r *http.Request, c *rout
util.LogHandlerExitWithJSON(handler, w, d, http.StatusCreated) util.LogHandlerExitWithJSON(handler, w, d, http.StatusCreated)
} }
return nil return nil
} }
@ -242,9 +243,9 @@ func putDeploymentHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.
return err return err
} }
t := getTemplate(w, r, handler) depReq := getDeploymentRequest(w, r, handler)
if t != nil { if depReq != nil {
d, err := c.Manager.PutDeployment(name, t) d, err := c.Manager.PutDeployment(name, depReq)
if err != nil { if err != nil {
httputil.BadRequest(w, r, err) httputil.BadRequest(w, r, err)
return nil return nil
@ -252,6 +253,7 @@ func putDeploymentHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.
util.LogHandlerExitWithJSON(handler, w, d, http.StatusCreated) util.LogHandlerExitWithJSON(handler, w, d, http.StatusCreated)
} }
return nil return nil
} }
@ -289,14 +291,15 @@ func getPathVariable(w http.ResponseWriter, r *http.Request, variable, handler s
return unescaped, nil return unescaped, nil
} }
func getTemplate(w http.ResponseWriter, r *http.Request, handler string) *common.Template { func getDeploymentRequest(w http.ResponseWriter, r *http.Request, handler string) *common.DeploymentRequest {
util.LogHandlerEntry(handler, r) util.LogHandlerEntry(handler, r)
t := &common.Template{} depReq := &common.DeploymentRequest{}
if err := httputil.Decode(w, r, t); err != nil { if err := httputil.Decode(w, r, depReq); err != nil {
httputil.BadRequest(w, r, err) httputil.BadRequest(w, r, err)
return nil return nil
} }
return t
return depReq
} }
func listManifestsHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error { func listManifestsHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
@ -348,9 +351,9 @@ func expandHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context
handler := "manager: expand config" handler := "manager: expand config"
util.LogHandlerEntry(handler, r) util.LogHandlerEntry(handler, r)
defer r.Body.Close() defer r.Body.Close()
t := getTemplate(w, r, handler) depReq := getDeploymentRequest(w, r, handler)
if t != nil { if depReq != nil {
c, err := c.Manager.Expand(t) c, err := c.Manager.Expand(depReq)
if err != nil { if err != nil {
httputil.BadRequest(w, r, err) httputil.BadRequest(w, r, err)
return nil return nil
@ -358,6 +361,7 @@ func expandHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context
util.LogHandlerExitWithJSON(handler, w, c, http.StatusCreated) util.LogHandlerExitWithJSON(handler, w, c, http.StatusCreated)
} }
return nil return nil
} }

@ -60,12 +60,12 @@ func TestHealthz(t *testing.T) {
func TestCreateDeployments(t *testing.T) { func TestCreateDeployments(t *testing.T) {
c := stubContext() c := stubContext()
tpl := &common.Template{Name: "foo"} depReq := &common.DeploymentRequest{Name: "foo"}
s := httpHarness(c, "POST /deployments", createDeploymentHandlerFunc) s := httpHarness(c, "POST /deployments", createDeploymentHandlerFunc)
defer s.Close() defer s.Close()
var b bytes.Buffer var b bytes.Buffer
if err := json.NewEncoder(&b).Encode(tpl); err != nil { if err := json.NewEncoder(&b).Encode(depReq); err != nil {
t.Fatal(err) t.Fatal(err)
} }

@ -110,8 +110,9 @@ func (c *Client) DescribeDeployment(name string) (*common.Deployment, error) {
// PostDeployment posts a deployment object to the manager service. // PostDeployment posts a deployment object to the manager service.
func (c *Client) PostDeployment(res *common.Resource) error { func (c *Client) PostDeployment(res *common.Resource) error {
// This is a stop-gap until we get this API cleaned up. // This is a stop-gap until we get this API cleaned up.
t := common.CreateDeploymentRequest{ t := common.DeploymentRequest{
ChartInvocation: res, Configuration: common.Configuration{Resources: []*common.Resource{res}},
Name: res.Name,
} }
data, err := json.Marshal(t) data, err := json.Marshal(t)

Loading…
Cancel
Save