summaryrefslogtreecommitdiffstats
path: root/src/ncm/api
diff options
context:
space:
mode:
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