Adding Expand endpoint as "/expand".

This endpoint takes a template and returns a manifest containing only
the expanded config and layout.
pull/91/head
Brendan Melville 9 years ago
parent bd59a69ea1
commit 0343be6ad2

@ -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)

@ -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) {

@ -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"`
}

Loading…
Cancel
Save