aboutsummaryrefslogtreecommitdiffstats
path: root/src/ncm/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/ncm/api')
-rw-r--r--src/ncm/api/api.go3
-rw-r--r--src/ncm/api/networkhandler.go9
-rw-r--r--src/ncm/api/providernethandler.go8
-rw-r--r--src/ncm/api/schedulerhandler.go111
4 files changed, 130 insertions, 1 deletions
diff --git a/src/ncm/api/api.go b/src/ncm/api/api.go
index 6dd958a1..45551e6c 100644
--- a/src/ncm/api/api.go
+++ b/src/ncm/api/api.go
@@ -90,6 +90,9 @@ func NewRouter(testClient interface{}) *mux.Router {
}
router.HandleFunc("/cluster-providers/{cluster-provider}/clusters/{cluster}/apply", schedulerHandler.applySchedulerHandler).Methods("POST")
router.HandleFunc("/cluster-providers/{cluster-provider}/clusters/{cluster}/terminate", schedulerHandler.terminateSchedulerHandler).Methods("POST")
+ router.HandleFunc("/cluster-providers/{cluster-provider}/clusters/{cluster}/status", schedulerHandler.statusSchedulerHandler).Methods("GET")
+ router.HandleFunc("/cluster-providers/{cluster-provider}/clusters/{cluster}/status",
+ schedulerHandler.statusSchedulerHandler).Queries("instance", "{instance}", "type", "{type}", "output", "{output}", "app", "{app}", "cluster", "{cluster}", "resource", "{resource}")
return router
}
diff --git a/src/ncm/api/networkhandler.go b/src/ncm/api/networkhandler.go
index ed266697..6f305be1 100644
--- a/src/ncm/api/networkhandler.go
+++ b/src/ncm/api/networkhandler.go
@@ -30,6 +30,9 @@ import (
"github.com/gorilla/mux"
)
+var vnJSONFile string = "json-schemas/virtual-network.json"
+
+
// Used to store backend implementations objects
// Also simplifies mocking for unit testing purposes
type networkHandler struct {
@@ -86,6 +89,12 @@ func (h networkHandler) createNetworkHandler(w http.ResponseWriter, r *http.Requ
return
}
+ err, httpError := validation.ValidateJsonSchemaData(vnJSONFile, p)
+if err != nil {
+ http.Error(w, err.Error(), httpError)
+ return
+}
+
// Name is required.
if p.Metadata.Name == "" {
http.Error(w, "Missing name in POST request", http.StatusBadRequest)
diff --git a/src/ncm/api/providernethandler.go b/src/ncm/api/providernethandler.go
index 66a41a4d..48d5d7ea 100644
--- a/src/ncm/api/providernethandler.go
+++ b/src/ncm/api/providernethandler.go
@@ -31,6 +31,8 @@ import (
"github.com/gorilla/mux"
)
+var pnetJSONFile string = "json-schemas/provider-network.json"
+
// Used to store backend implementations objects
// Also simplifies mocking for unit testing purposes
type providernetHandler struct {
@@ -139,6 +141,12 @@ func (h providernetHandler) createProviderNetHandler(w http.ResponseWriter, r *h
return
}
+ err, httpError := validation.ValidateJsonSchemaData(pnetJSONFile, p)
+if err != nil {
+ http.Error(w, err.Error(), httpError)
+ return
+}
+
// Name is required.
if p.Metadata.Name == "" {
http.Error(w, "Missing name in POST request", http.StatusBadRequest)
diff --git a/src/ncm/api/schedulerhandler.go b/src/ncm/api/schedulerhandler.go
index d07d132d..9d8b4eff 100644
--- a/src/ncm/api/schedulerhandler.go
+++ b/src/ncm/api/schedulerhandler.go
@@ -17,9 +17,13 @@
package api
import (
+ "encoding/json"
"net/http"
+ "net/url"
+ "strings"
"github.com/onap/multicloud-k8s/src/ncm/pkg/scheduler"
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/validation"
"github.com/gorilla/mux"
)
@@ -47,7 +51,7 @@ func (h schedulerHandler) applySchedulerHandler(w http.ResponseWriter, r *http.R
w.WriteHeader(http.StatusNoContent)
}
-// terminateSchedulerHandler handles requests to apply network intents for a cluster
+// terminateSchedulerHandler handles requests to terminate network intents for a cluster
func (h schedulerHandler) terminateSchedulerHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
provider := vars["cluster-provider"]
@@ -61,3 +65,108 @@ func (h schedulerHandler) terminateSchedulerHandler(w http.ResponseWriter, r *ht
w.WriteHeader(http.StatusNoContent)
}
+
+// statusSchedulerHandler handles requests to query status of network intents for a cluster
+func (h schedulerHandler) statusSchedulerHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ provider := vars["cluster-provider"]
+ cluster := vars["cluster"]
+
+ qParams, err := url.ParseQuery(r.URL.RawQuery)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusBadRequest)
+ return
+ }
+
+ var queryInstance string
+ if i, found := qParams["instance"]; found {
+ queryInstance = i[0]
+ } else {
+ queryInstance = "" // default type
+ }
+
+ var queryType string
+ if t, found := qParams["type"]; found {
+ queryType = t[0]
+ if queryType != "cluster" && queryType != "rsync" {
+ http.Error(w, "Invalid query type", http.StatusBadRequest)
+ return
+ }
+ } else {
+ queryType = "rsync" // default type
+ }
+
+ var queryOutput string
+ if o, found := qParams["output"]; found {
+ queryOutput = o[0]
+ if queryOutput != "summary" && queryOutput != "all" && queryOutput != "detail" {
+ http.Error(w, "Invalid query output", http.StatusBadRequest)
+ return
+ }
+ } else {
+ queryOutput = "all" // default output format
+ }
+
+ var queryApps []string
+ if a, found := qParams["app"]; found {
+ queryApps = a
+ for _, app := range queryApps {
+ errs := validation.IsValidName(app)
+ if len(errs) > 0 {
+ http.Error(w, "Invalid app query", http.StatusBadRequest)
+ return
+ }
+ }
+ } else {
+ queryApps = make([]string, 0)
+ }
+
+ var queryClusters []string
+ if c, found := qParams["cluster"]; found {
+ queryClusters = c
+ for _, cl := range queryClusters {
+ parts := strings.Split(cl, "+")
+ if len(parts) != 2 {
+ http.Error(w, "Invalid cluster query", http.StatusBadRequest)
+ return
+ }
+ for _, p := range parts {
+ errs := validation.IsValidName(p)
+ if len(errs) > 0 {
+ http.Error(w, "Invalid cluster query", http.StatusBadRequest)
+ return
+ }
+ }
+ }
+ } else {
+ queryClusters = make([]string, 0)
+ }
+
+ var queryResources []string
+ if r, found := qParams["resource"]; found {
+ queryResources = r
+ for _, res := range queryResources {
+ errs := validation.IsValidName(res)
+ if len(errs) > 0 {
+ http.Error(w, "Invalid resources query", http.StatusBadRequest)
+ return
+ }
+ }
+ } else {
+ queryResources = make([]string, 0)
+ }
+
+ status, iErr := h.client.NetworkIntentsStatus(provider, cluster, queryInstance, queryType, queryOutput, queryApps, queryClusters, queryResources)
+ if iErr != nil {
+ http.Error(w, iErr.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ iErr = json.NewEncoder(w).Encode(status)
+ if iErr != nil {
+ http.Error(w, iErr.Error(), http.StatusInternalServerError)
+ return
+ }
+}