aboutsummaryrefslogtreecommitdiffstats
path: root/src/ncm/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/ncm/api')
-rw-r--r--src/ncm/api/api.go1
-rw-r--r--src/ncm/api/netcontrolintenthandler.go32
2 files changed, 33 insertions, 0 deletions
diff --git a/src/ncm/api/api.go b/src/ncm/api/api.go
index 7892113a..2b105716 100644
--- a/src/ncm/api/api.go
+++ b/src/ncm/api/api.go
@@ -135,6 +135,7 @@ func NewRouter(testClient interface{}) *mux.Router {
router.HandleFunc("/projects/{project}/composite-apps/{composite-app-name}/{version}/network-controller-intent/{name}", netcontrolintentHandler.putHandler).Methods("PUT")
router.HandleFunc("/projects/{project}/composite-apps/{composite-app-name}/{version}/network-controller-intent/{name}", netcontrolintentHandler.getHandler).Methods("GET")
router.HandleFunc("/projects/{project}/composite-apps/{composite-app-name}/{version}/network-controller-intent/{name}", netcontrolintentHandler.deleteHandler).Methods("DELETE")
+ router.HandleFunc("/projects/{project}/composite-apps/{composite-app-name}/{version}/network-controller-intent/{name}/apply", netcontrolintentHandler.applyHandler).Methods("POST")
workloadintentHandler := workloadintentHandler{
client: setClient(moduleClient.WorkloadIntent, testClient).(moduleLib.WorkloadIntentManager),
diff --git a/src/ncm/api/netcontrolintenthandler.go b/src/ncm/api/netcontrolintenthandler.go
index c59a389b..48ef1de2 100644
--- a/src/ncm/api/netcontrolintenthandler.go
+++ b/src/ncm/api/netcontrolintenthandler.go
@@ -196,3 +196,35 @@ func (h netcontrolintentHandler) deleteHandler(w http.ResponseWriter, r *http.Re
w.WriteHeader(http.StatusNoContent)
}
+
+// Apply handles POST operations to Apply a particular NetControlIntent to the App Context
+func (h netcontrolintentHandler) applyHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ name := vars["name"]
+ project := vars["project"]
+ compositeApp := vars["composite-app-name"]
+ compositeAppVersion := vars["version"]
+
+ var aci struct {
+ AppContextId string `json:"appContextId"`
+ }
+
+ err := json.NewDecoder(r.Body).Decode(&aci)
+
+ switch {
+ case err == io.EOF:
+ http.Error(w, "Empty body", http.StatusBadRequest)
+ return
+ case err != nil:
+ http.Error(w, err.Error(), http.StatusUnprocessableEntity)
+ return
+ }
+
+ err = h.client.ApplyNetControlIntent(name, project, compositeApp, compositeAppVersion, aci.AppContextId)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ w.WriteHeader(http.StatusNoContent)
+}