From 0343be6ad23f418bb6041561def7905a99084a58 Mon Sep 17 00:00:00 2001 From: Brendan Melville Date: Tue, 17 Nov 2015 13:41:52 -0800 Subject: [PATCH] Adding Expand endpoint as "/expand". This endpoint takes a template and returns a manifest containing only the expanded config and layout. --- dm/dm.go | 8 +------- manager/deployments.go | 18 ++++++++++++++++++ manager/manager/types.go | 6 +++--- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/dm/dm.go b/dm/dm.go index f1c417a19..138b2590b 100644 --- a/dm/dm.go +++ b/dm/dm.go @@ -120,14 +120,8 @@ func main() { case "describe": fmt.Printf("the describe feature is not yet implemented") case "expand": - backend := expander.NewExpander(*binary) template := loadTemplate(args) - output, err := backend.ExpandTemplate(template) - if err != nil { - log.Fatalf("cannot expand %s: %s\n", template.Name, err) - } - - fmt.Println(output) + callService("expand", "POST", "expand configuration", marshalTemplate(template)) case "deploy": template := loadTemplate(args) action := fmt.Sprintf("deploy configuration named %s", template.Name) diff --git a/manager/deployments.go b/manager/deployments.go index e08476010..54519005b 100644 --- a/manager/deployments.go +++ b/manager/deployments.go @@ -41,6 +41,7 @@ var deployments = []Route{ {"PutDeployment", "/deployments/{deployment}", "PUT", putDeploymentHandlerFunc, "JSON"}, {"ListManifests", "/deployments/{deployment}/manifests", "GET", listManifestsHandlerFunc, ""}, {"GetManifest", "/deployments/{deployment}/manifests/{manifest}", "GET", getManifestHandlerFunc, ""}, + {"Expand", "/expand", "POST", expandHandlerFunc, ""}, {"ListTypes", "/types", "GET", listTypesHandlerFunc, ""}, {"ListTypeInstances", "/types/{type}/instances", "GET", listTypeInstancesHandlerFunc, ""}, } @@ -290,6 +291,23 @@ func getManifestHandlerFunc(w http.ResponseWriter, r *http.Request) { util.LogHandlerExitWithJSON(handler, w, m, http.StatusOK) } +func expandHandlerFunc(w http.ResponseWriter, r *http.Request) { + handler := "manager: expand config" + util.LogHandlerEntry(handler, r) + defer r.Body.Close() + t := getTemplate(w, r, handler) + if t != nil { + c, err := backend.Expand(t) + if err != nil { + util.LogAndReturnError(handler, http.StatusBadRequest, err, w) + return + } + + util.LogHandlerExitWithJSON(handler, w, c, http.StatusCreated) + return + } +} + // Putting Type handlers here for now because deployments.go // currently owns its own Manager backend and doesn't like to share. func listTypesHandlerFunc(w http.ResponseWriter, r *http.Request) { diff --git a/manager/manager/types.go b/manager/manager/types.go index e8e3fd478..90ca61988 100644 --- a/manager/manager/types.go +++ b/manager/manager/types.go @@ -112,9 +112,9 @@ type Layout struct { // expanded configuration, and the layout structure of the manifest. // type Manifest struct { - Deployment string `json:"deployment"` - Name string `json:"name"` - InputConfig *Template `json:"inputConfig"` + Deployment string `json:"deployment,omitempty"` + Name string `json:"name,omitempty"` + InputConfig *Template `json:"inputConfig,omitempty"` ExpandedConfig *Configuration `json:"expandedConfig,omitempty"` Layout *Layout `json:"layout,omitempty"` }