From ff03456548dac309461f402738ac344046de8057 Mon Sep 17 00:00:00 2001 From: Rajamohan Raj Date: Wed, 26 Feb 2020 02:07:34 +0000 Subject: Add DeploymentIntentGroup APIs Implemented the routes for creation, deletion and getting DeploymentIntentGroup. Added routes for adding, getting and deleting intents. Issue-ID: MULTICLOUD-1002 Signed-off-by: Rajamohan Raj Change-Id: I07ba3744107bcf30aa30ed89caa21bf474c0d92a --- src/orchestrator/api/add_intents_handler.go | 136 +++++++++++++++++++++ src/orchestrator/api/api.go | 29 ++++- src/orchestrator/api/clusterhandler.go | 8 +- src/orchestrator/api/clusterhandler_test.go | 34 +++--- src/orchestrator/api/controllerhandler_test.go | 6 +- .../api/deployment_intent_groups_handler.go | 133 ++++++++++++++++++++ src/orchestrator/api/projecthandler_test.go | 6 +- 7 files changed, 324 insertions(+), 28 deletions(-) create mode 100644 src/orchestrator/api/add_intents_handler.go create mode 100644 src/orchestrator/api/deployment_intent_groups_handler.go (limited to 'src/orchestrator/api') diff --git a/src/orchestrator/api/add_intents_handler.go b/src/orchestrator/api/add_intents_handler.go new file mode 100644 index 00000000..dfe1a496 --- /dev/null +++ b/src/orchestrator/api/add_intents_handler.go @@ -0,0 +1,136 @@ +/* + * Copyright 2020 Intel Corporation, Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package api + +import ( + "encoding/json" + "io" + "net/http" + + moduleLib "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module" + + "github.com/gorilla/mux" +) + +type intentHandler struct { + client moduleLib.IntentManager +} + +func (h intentHandler) addIntentHandler(w http.ResponseWriter, r *http.Request) { + var i moduleLib.Intent + + err := json.NewDecoder(r.Body).Decode(&i) + switch { + case err == io.EOF: + http.Error(w, "Empty body", http.StatusBadRequest) + return + + case err != nil: + http.Error(w, err.Error(), http.StatusUnprocessableEntity) + return + } + + if i.MetaData.Name == "" { + http.Error(w, "Missing Intent in POST request", http.StatusBadRequest) + return + } + + vars := mux.Vars(r) + p := vars["project-name"] + ca := vars["composite-app-name"] + v := vars["composite-app-version"] + d := vars["deployment-intent-group-name"] + + intent, addError := h.client.AddIntent(i, p, ca, v, d) + if addError != nil { + http.Error(w, addError.Error(), http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + err = json.NewEncoder(w).Encode(intent) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} + +func (h intentHandler) getIntentHandler(w http.ResponseWriter, r *http.Request) { + + vars := mux.Vars(r) + + i := vars["intent-name"] + if i == "" { + http.Error(w, "Missing intentName in GET request", http.StatusBadRequest) + return + } + + p := vars["project-name"] + if p == "" { + http.Error(w, "Missing projectName in GET request", http.StatusBadRequest) + return + } + ca := vars["composite-app-name"] + if ca == "" { + http.Error(w, "Missing compositeAppName in GET request", http.StatusBadRequest) + return + } + + v := vars["composite-app-version"] + if v == "" { + http.Error(w, "Missing version of compositeApp in GET request", http.StatusBadRequest) + return + } + + di := vars["deployment-intent-group-name"] + if di == "" { + http.Error(w, "Missing name of DeploymentIntentGroup in GET request", http.StatusBadRequest) + return + } + + intent, err := h.client.GetIntent(i, p, ca, v, di) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + err = json.NewEncoder(w).Encode(intent) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} + +func (h intentHandler) deleteIntentHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + + i := vars["intent-name"] + p := vars["project-name"] + ca := vars["composite-app-name"] + v := vars["composite-app-version"] + di := vars["deployment-intent-group-name"] + + err := h.client.DeleteIntent(i, p, ca, v, di) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + w.WriteHeader(http.StatusNoContent) +} diff --git a/src/orchestrator/api/api.go b/src/orchestrator/api/api.go index f4381e6c..f3e3b177 100644 --- a/src/orchestrator/api/api.go +++ b/src/orchestrator/api/api.go @@ -28,7 +28,9 @@ func NewRouter(projectClient moduleLib.ProjectManager, ControllerClient moduleLib.ControllerManager, clusterClient moduleLib.ClusterManager, genericPlacementIntentClient moduleLib.GenericPlacementIntentManager, - appIntentClient moduleLib.AppIntentManager) *mux.Router { + appIntentClient moduleLib.AppIntentManager, + deploymentIntentGrpClient moduleLib.DeploymentIntentGroupManager, + intentClient moduleLib.IntentManager) *mux.Router { router := mux.NewRouter().PathPrefix("/v2").Subrouter() @@ -114,5 +116,30 @@ func NewRouter(projectClient moduleLib.ProjectManager, router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/generic-placement-intents/{intent-name}/app-intents/{app-intent-name}", appIntentHandler.getAppIntentHandler).Methods("GET") router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/generic-placement-intents/{intent-name}/app-intents/{app-intent-name}", appIntentHandler.deleteAppIntentHandler).Methods("DELETE") + //setting routes for deploymentIntentGroup + if deploymentIntentGrpClient == nil { + deploymentIntentGrpClient = moduleClient.DeploymentIntentGroup + } + + deploymentIntentGrpHandler := deploymentIntentGroupHandler{ + client: deploymentIntentGrpClient, + } + router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups", deploymentIntentGrpHandler.createDeploymentIntentGroupHandler).Methods("POST") + router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}", deploymentIntentGrpHandler.getDeploymentIntentGroupHandler).Methods("GET") + router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}", deploymentIntentGrpHandler.deleteDeploymentIntentGroupHandler).Methods("DELETE") + + // setting routes for AddingIntents + if intentClient == nil { + intentClient = moduleClient.Intent + } + + intentHandler := intentHandler{ + client: intentClient, + } + + router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/intents", intentHandler.addIntentHandler).Methods("POST") + router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/intents/{intent-name}", intentHandler.getIntentHandler).Methods("GET") + router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/intents/{intent-name}", intentHandler.deleteIntentHandler).Methods("DELETE") + return router } diff --git a/src/orchestrator/api/clusterhandler.go b/src/orchestrator/api/clusterhandler.go index 7e769f31..ac4191e1 100644 --- a/src/orchestrator/api/clusterhandler.go +++ b/src/orchestrator/api/clusterhandler.go @@ -255,12 +255,12 @@ func (h clusterHandler) getClusterHandler(w http.ResponseWriter, r *http.Request http.Error(w, err.Error(), http.StatusInternalServerError) return } - kc_bytes, err := base64.StdEncoding.DecodeString(retKubeconfig.Kubeconfig) + kcBytes, err := base64.StdEncoding.DecodeString(retKubeconfig.Kubeconfig) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } - _, err = pw.Write(kc_bytes) + _, err = pw.Write(kcBytes) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -276,12 +276,12 @@ func (h clusterHandler) getClusterHandler(w http.ResponseWriter, r *http.Request case "application/octet-stream": w.Header().Set("Content-Type", "application/octet-stream") w.WriteHeader(http.StatusOK) - kc_bytes, err := base64.StdEncoding.DecodeString(retKubeconfig.Kubeconfig) + kcBytes, err := base64.StdEncoding.DecodeString(retKubeconfig.Kubeconfig) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } - _, err = w.Write(kc_bytes) + _, err = w.Write(kcBytes) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return diff --git a/src/orchestrator/api/clusterhandler_test.go b/src/orchestrator/api/clusterhandler_test.go index ad7635e2..a32bf021 100644 --- a/src/orchestrator/api/clusterhandler_test.go +++ b/src/orchestrator/api/clusterhandler_test.go @@ -229,7 +229,7 @@ func TestClusterProviderCreateHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { request := httptest.NewRequest("POST", "/v2/cluster-providers", testCase.reader) - resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil)) + resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { @@ -307,7 +307,7 @@ func TestClusterProviderGetAllHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { request := httptest.NewRequest("GET", "/v2/cluster-providers", nil) - resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil)) + resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { @@ -377,7 +377,7 @@ func TestClusterProviderGetHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { request := httptest.NewRequest("GET", "/v2/cluster-providers/"+testCase.name, nil) - resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil)) + resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { @@ -426,7 +426,7 @@ func TestClusterProviderDeleteHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { request := httptest.NewRequest("DELETE", "/v2/cluster-providers/"+testCase.name, nil) - resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil)) + resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { @@ -538,7 +538,7 @@ of clusterTest request := httptest.NewRequest("POST", "/v2/cluster-providers/clusterProvider1/clusters", bytes.NewBuffer(body.Bytes())) request.Header.Set("Content-Type", multiwr.FormDataContentType()) - resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil)) + resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { @@ -625,7 +625,7 @@ func TestClusterGetAllHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { request := httptest.NewRequest("GET", "/v2/cluster-providers/clusterProvder1/clusters", nil) - resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil)) + resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { @@ -706,7 +706,7 @@ func TestClusterGetHandler(t *testing.T) { if len(testCase.accept) > 0 { request.Header.Set("Accept", testCase.accept) } - resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil)) + resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { @@ -784,7 +784,7 @@ of clusterTest if len(testCase.accept) > 0 { request.Header.Set("Accept", testCase.accept) } - resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil)) + resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { @@ -834,7 +834,7 @@ func TestClusterDeleteHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { request := httptest.NewRequest("DELETE", "/v2/cluster-providers/clusterProvider1/clusters/"+testCase.name, nil) - resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil)) + resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { @@ -880,7 +880,7 @@ func TestClusterLabelCreateHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { request := httptest.NewRequest("POST", "/v2/cluster-providers/cp1/clusters/cl1/labels", testCase.reader) - resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil)) + resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { @@ -944,7 +944,7 @@ func TestClusterLabelsGetHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { request := httptest.NewRequest("GET", "/v2/cluster-providers/cp1/clusters/cl1/labels", nil) - resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil)) + resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { @@ -1004,7 +1004,7 @@ func TestClusterLabelGetHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { request := httptest.NewRequest("GET", "/v2/cluster-providers/clusterProvider1/clusters/cl1/labels/"+testCase.name, nil) - resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil)) + resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { @@ -1053,7 +1053,7 @@ func TestClusterLabelDeleteHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { request := httptest.NewRequest("DELETE", "/v2/cluster-providers/cp1/clusters/cl1/labels/"+testCase.name, nil) - resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil)) + resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { @@ -1144,7 +1144,7 @@ func TestClusterKvPairsCreateHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { request := httptest.NewRequest("POST", "/v2/cluster-providers/cp1/clusters/cl1/kv-pairs", testCase.reader) - resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil)) + resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { @@ -1262,7 +1262,7 @@ func TestClusterKvPairsGetAllHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { request := httptest.NewRequest("GET", "/v2/cluster-providers/cp1/clusters/cl1/kv-pairs", nil) - resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil)) + resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { @@ -1352,7 +1352,7 @@ func TestClusterKvPairsGetHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { request := httptest.NewRequest("GET", "/v2/cluster-providers/clusterProvider1/clusters/cl1/kv-pairs/"+testCase.name, nil) - resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil)) + resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { @@ -1401,7 +1401,7 @@ func TestClusterKvPairsDeleteHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { request := httptest.NewRequest("DELETE", "/v2/cluster-providers/cp1/clusters/cl1/kv-pairs/"+testCase.name, nil) - resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil)) + resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.clusterClient, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { diff --git a/src/orchestrator/api/controllerhandler_test.go b/src/orchestrator/api/controllerhandler_test.go index bcc06f98..dd542de7 100644 --- a/src/orchestrator/api/controllerhandler_test.go +++ b/src/orchestrator/api/controllerhandler_test.go @@ -110,7 +110,7 @@ func TestControllerCreateHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { request := httptest.NewRequest("POST", "/v2/controllers", testCase.reader) - resp := executeRequest(request, NewRouter(nil, nil, testCase.controllerClient, nil, nil, nil)) + resp := executeRequest(request, NewRouter(nil, nil, testCase.controllerClient, nil, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { @@ -173,7 +173,7 @@ func TestControllerGetHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { request := httptest.NewRequest("GET", "/v2/controllers/"+testCase.name, nil) - resp := executeRequest(request, NewRouter(nil, nil, testCase.controllerClient, nil, nil, nil)) + resp := executeRequest(request, NewRouter(nil, nil, testCase.controllerClient, nil, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { @@ -222,7 +222,7 @@ func TestControllerDeleteHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { request := httptest.NewRequest("DELETE", "/v2/controllers/"+testCase.name, nil) - resp := executeRequest(request, NewRouter(nil, nil, testCase.controllerClient, nil, nil, nil)) + resp := executeRequest(request, NewRouter(nil, nil, testCase.controllerClient, nil, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { diff --git a/src/orchestrator/api/deployment_intent_groups_handler.go b/src/orchestrator/api/deployment_intent_groups_handler.go new file mode 100644 index 00000000..3f5b3969 --- /dev/null +++ b/src/orchestrator/api/deployment_intent_groups_handler.go @@ -0,0 +1,133 @@ +/* + * Copyright 2020 Intel Corporation, Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package api + +import ( + "encoding/json" + "io" + "net/http" + + moduleLib "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module" + + "github.com/gorilla/mux" +) + +/* Used to store backend implementation objects +Also simplifies mocking for unit testing purposes +*/ +type deploymentIntentGroupHandler struct { + client moduleLib.DeploymentIntentGroupManager +} + +// createDeploymentIntentGroupHandler handles the create operation of DeploymentIntentGroup +func (h deploymentIntentGroupHandler) createDeploymentIntentGroupHandler(w http.ResponseWriter, r *http.Request) { + + var d moduleLib.DeploymentIntentGroup + + err := json.NewDecoder(r.Body).Decode(&d) + switch { + case err == io.EOF: + http.Error(w, "Empty body", http.StatusBadRequest) + return + case err != nil: + http.Error(w, err.Error(), http.StatusUnprocessableEntity) + return + } + + if d.MetaData.Name == "" { + http.Error(w, "Missing deploymentIntentGroupName in POST request", http.StatusBadRequest) + return + } + + vars := mux.Vars(r) + projectName := vars["project-name"] + compositeAppName := vars["composite-app-name"] + version := vars["composite-app-version"] + + dIntent, createErr := h.client.CreateDeploymentIntentGroup(d, projectName, compositeAppName, version) + if createErr != nil { + http.Error(w, createErr.Error(), http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + err = json.NewEncoder(w).Encode(dIntent) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} + +func (h deploymentIntentGroupHandler) getDeploymentIntentGroupHandler(w http.ResponseWriter, r *http.Request) { + + vars := mux.Vars(r) + + p := vars["project-name"] + if p == "" { + http.Error(w, "Missing projectName in GET request", http.StatusBadRequest) + return + } + ca := vars["composite-app-name"] + if ca == "" { + http.Error(w, "Missing compositeAppName in GET request", http.StatusBadRequest) + return + } + + v := vars["composite-app-version"] + if v == "" { + http.Error(w, "Missing version of compositeApp in GET request", http.StatusBadRequest) + return + } + + di := vars["deployment-intent-group-name"] + if v == "" { + http.Error(w, "Missing name of DeploymentIntentGroup in GET request", http.StatusBadRequest) + return + } + + dIntentGrp, err := h.client.GetDeploymentIntentGroup(di, p, ca, v) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + err = json.NewEncoder(w).Encode(dIntentGrp) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + +} + +func (h deploymentIntentGroupHandler) deleteDeploymentIntentGroupHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + + p := vars["project-name"] + ca := vars["composite-app-name"] + v := vars["composite-app-version"] + di := vars["deployment-intent-group-name"] + + err := h.client.DeleteDeploymentIntentGroup(di, p, ca, v) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + w.WriteHeader(http.StatusNoContent) +} diff --git a/src/orchestrator/api/projecthandler_test.go b/src/orchestrator/api/projecthandler_test.go index 84e67521..eccccb90 100644 --- a/src/orchestrator/api/projecthandler_test.go +++ b/src/orchestrator/api/projecthandler_test.go @@ -119,7 +119,7 @@ func TestProjectCreateHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { request := httptest.NewRequest("POST", "/v2/projects", testCase.reader) - resp := executeRequest(request, NewRouter(testCase.projectClient, nil, nil, nil, nil, nil)) + resp := executeRequest(request, NewRouter(testCase.projectClient, nil, nil, nil, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { @@ -188,7 +188,7 @@ func TestProjectGetHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { request := httptest.NewRequest("GET", "/v2/projects/"+testCase.name, nil) - resp := executeRequest(request, NewRouter(testCase.projectClient, nil, nil, nil, nil, nil)) + resp := executeRequest(request, NewRouter(testCase.projectClient, nil, nil, nil, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { @@ -237,7 +237,7 @@ func TestProjectDeleteHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { request := httptest.NewRequest("DELETE", "/v2/projects/"+testCase.name, nil) - resp := executeRequest(request, NewRouter(testCase.projectClient, nil, nil, nil, nil, nil)) + resp := executeRequest(request, NewRouter(testCase.projectClient, nil, nil, nil, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { -- cgit 1.2.3-korg