-
+
vCTP API
diff --git a/components/core/header_templ.go b/components/core/header_templ.go
index 224b938..6367c81 100644
--- a/components/core/header_templ.go
+++ b/components/core/header_templ.go
@@ -31,7 +31,7 @@ func Header() templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Test PagevCTP API 0 {
- err := json.Unmarshal([]byte(*event.CloudEvent.Data.ConfigSpec), &config)
- if err != nil {
- h.Logger.Error("unable to decode json", "error", err)
- http.Error(w, "Invalid JSON body", http.StatusBadRequest)
- return
+ var found = false
+ // Only interested in vCPU or ram changes currently
+ for _, change := range configChanges {
+ //fmt.Printf("Type: %s, New Value: %s\n", change["type"], change["newValue"])
+ switch change["type"] {
+ case "config.hardware.numCPU":
+ i, err := strconv.ParseInt(change["newValue"], 10, 64)
+ if err != nil {
+ h.Logger.Error("Unable to convert new value to int64", "new_value", change["newValue"])
+ } else {
+ found = true
+ params.NewVcpus = sql.NullInt64{Int64: i, Valid: i > 0}
+ }
+ case "config.hardware.memoryMB":
+ i, err := strconv.ParseInt(change["newValue"], 10, 64)
+ if err != nil {
+ h.Logger.Error("Unable to convert new value to int64", "new_value", change["newValue"])
+ } else {
+ found = true
+ params.NewRam = sql.NullInt64{Int64: i, Valid: i > 0}
+ }
}
}
- */
+
+ // Only create a database record if we found one of the config changes we were interested in
+ if found {
+ result, err := h.Database.Queries().CreateUpdate(context.Background(), params)
+ if err != nil {
+ h.Logger.Error("unable to perform database insert", "error", err)
+ w.WriteHeader(http.StatusInternalServerError)
+ fmt.Fprintf(w, "Error : %v\n", err)
+ return
+ } else {
+ h.Logger.Debug("created database record", "insert_result", result)
+ }
+ }
+
+ }
h.Logger.Debug("received update request", "body", string(reqBody))
w.WriteHeader(http.StatusOK)
@@ -66,7 +96,7 @@ func (h *Handler) processConfigChanges(configChanges string) []map[string]string
changes := regexp.MustCompile(`\n+`).Split(configChanges, -1)
// Regular expression to match config type and the new value after '->' or '<-'
- re := regexp.MustCompile(`(?P[^\s]+): \d+ -[><] (?P[^;]+);`)
+ re := regexp.MustCompile(`(?P[^\s]+): [^\s]+ -[><] (?P[^;]+);`)
// Result will hold a list of changes with type and new value
var result []map[string]string