summaryrefslogtreecommitdiffstats
path: root/src/ncm/api
diff options
context:
space:
mode:
authorEric Multanen <eric.w.multanen@intel.com>2020-04-14 17:54:45 -0700
committerEric Multanen <eric.w.multanen@intel.com>2020-04-16 16:58:05 -0700
commitb7a4e00a6cd9d4ce903448ea958d85f17c8d68ab (patch)
tree5ac53a49fd1efd559494755ca666ecf9550b1014 /src/ncm/api
parentc898a84208d20f0040778450cc401a35c3f8ee41 (diff)
Add apply API for network intents
Support POST API to 'apply' and 'terminate' network and providernetwork intents for a given cluster. Issue-ID: MULTICLOUD-1029 Signed-off-by: Eric Multanen <eric.w.multanen@intel.com> Change-Id: I8c9bae9e93aeeb68654eaab1f15de9883c22215c
Diffstat (limited to 'src/ncm/api')
-rw-r--r--src/ncm/api/api.go2
-rw-r--r--src/ncm/api/clusterhandler.go30
-rw-r--r--src/ncm/api/clusterhandler_test.go18
3 files changed, 50 insertions, 0 deletions
diff --git a/src/ncm/api/api.go b/src/ncm/api/api.go
index fcef7b43..7892113a 100644
--- a/src/ncm/api/api.go
+++ b/src/ncm/api/api.go
@@ -98,6 +98,8 @@ func NewRouter(testClient interface{}) *mux.Router {
router.HandleFunc("/cluster-providers/{provider-name}/clusters", clusterHandler.getClusterHandler).Queries("label", "{label}")
router.HandleFunc("/cluster-providers/{provider-name}/clusters/{name}", clusterHandler.getClusterHandler).Methods("GET")
router.HandleFunc("/cluster-providers/{provider-name}/clusters/{name}", clusterHandler.deleteClusterHandler).Methods("DELETE")
+ router.HandleFunc("/cluster-providers/{provider-name}/clusters/{name}/apply", clusterHandler.applyClusterHandler).Methods("POST")
+ router.HandleFunc("/cluster-providers/{provider-name}/clusters/{name}/terminate", clusterHandler.terminateClusterHandler).Methods("POST")
router.HandleFunc("/cluster-providers/{provider-name}/clusters/{cluster-name}/labels", clusterHandler.createClusterLabelHandler).Methods("POST")
router.HandleFunc("/cluster-providers/{provider-name}/clusters/{cluster-name}/labels", clusterHandler.getClusterLabelHandler).Methods("GET")
router.HandleFunc("/cluster-providers/{provider-name}/clusters/{cluster-name}/labels/{label}", clusterHandler.getClusterLabelHandler).Methods("GET")
diff --git a/src/ncm/api/clusterhandler.go b/src/ncm/api/clusterhandler.go
index 8c50f720..78453aa8 100644
--- a/src/ncm/api/clusterhandler.go
+++ b/src/ncm/api/clusterhandler.go
@@ -324,6 +324,36 @@ func (h clusterHandler) deleteClusterHandler(w http.ResponseWriter, r *http.Requ
w.WriteHeader(http.StatusNoContent)
}
+// apply network intents associated with the cluster
+func (h clusterHandler) applyClusterHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ provider := vars["provider-name"]
+ name := vars["name"]
+
+ err := h.client.ApplyNetworkIntents(provider, name)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ w.WriteHeader(http.StatusNoContent)
+}
+
+// terminate network intents associated with the cluster
+func (h clusterHandler) terminateClusterHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ provider := vars["provider-name"]
+ name := vars["name"]
+
+ err := h.client.TerminateNetworkIntents(provider, name)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ w.WriteHeader(http.StatusNoContent)
+}
+
// Create handles creation of the ClusterLabel entry in the database
func (h clusterHandler) createClusterLabelHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
diff --git a/src/ncm/api/clusterhandler_test.go b/src/ncm/api/clusterhandler_test.go
index a26c41bd..b32df527 100644
--- a/src/ncm/api/clusterhandler_test.go
+++ b/src/ncm/api/clusterhandler_test.go
@@ -28,6 +28,7 @@ import (
"testing"
moduleLib "github.com/onap/multicloud-k8s/src/ncm/pkg/module"
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/appcontext"
pkgerrors "github.com/pkg/errors"
)
@@ -41,6 +42,7 @@ type mockClusterManager struct {
ClusterProviderItems []moduleLib.ClusterProvider
ClusterItems []moduleLib.Cluster
ClusterContentItems []moduleLib.ClusterContent
+ ClusterContextItems []appcontext.AppContext
ClusterLabelItems []moduleLib.ClusterLabel
ClusterKvPairsItems []moduleLib.ClusterKvPairs
ClusterList []string
@@ -99,6 +101,14 @@ func (m *mockClusterManager) GetClusterContent(provider, name string) (moduleLib
return m.ClusterContentItems[0], nil
}
+func (m *mockClusterManager) GetClusterContext(provider, name string) (appcontext.AppContext, error) {
+ if m.Err != nil {
+ return appcontext.AppContext{}, m.Err
+ }
+
+ return m.ClusterContextItems[0], nil
+}
+
func (m *mockClusterManager) GetClusters(provider string) ([]moduleLib.Cluster, error) {
if m.Err != nil {
return []moduleLib.Cluster{}, m.Err
@@ -119,6 +129,14 @@ func (m *mockClusterManager) DeleteCluster(provider, name string) error {
return m.Err
}
+func (m *mockClusterManager) ApplyNetworkIntents(provider, name string) error {
+ return m.Err
+}
+
+func (m *mockClusterManager) TerminateNetworkIntents(provider, name string) error {
+ return m.Err
+}
+
func (m *mockClusterManager) CreateClusterLabel(provider, cluster string, inp moduleLib.ClusterLabel) (moduleLib.ClusterLabel, error) {
if m.Err != nil {
return moduleLib.ClusterLabel{}, m.Err