From c644ab480d2a764ee242cca14f96ea28a181bcad Mon Sep 17 00:00:00 2001 From: Rajamohan Raj Date: Tue, 31 Mar 2020 01:30:03 +0000 Subject: Resolve the helm templates Resolving the helm templates for each of the apps in the compositeApp by utilizing the helm libraries and thus getting the sorted templates with all values rendered. This is a subtask of adding instantiation APIs. Issue-ID: MULTICLOUD-1041 Signed-off-by: Rajamohan Raj Change-Id: Id4fddda69b5276b2409d835723b11367400ab6ea --- src/orchestrator/api/api.go | 14 ++++- .../api/composite_profilehandler_test.go | 2 +- src/orchestrator/api/controllerhandler_test.go | 6 +- src/orchestrator/api/instantiation_handler.go | 64 ++++++++++++++++++++++ src/orchestrator/api/projecthandler_test.go | 6 +- 5 files changed, 84 insertions(+), 8 deletions(-) create mode 100644 src/orchestrator/api/instantiation_handler.go (limited to 'src/orchestrator/api') diff --git a/src/orchestrator/api/api.go b/src/orchestrator/api/api.go index 1d38f106..fbd29563 100644 --- a/src/orchestrator/api/api.go +++ b/src/orchestrator/api/api.go @@ -33,7 +33,8 @@ func NewRouter(projectClient moduleLib.ProjectManager, deploymentIntentGrpClient moduleLib.DeploymentIntentGroupManager, intentClient moduleLib.IntentManager, compositeProfileClient moduleLib.CompositeProfileManager, - appProfileClient moduleLib.AppProfileManager) *mux.Router { + appProfileClient moduleLib.AppProfileManager, + instantiationClient moduleLib.InstantiationManager) *mux.Router { router := mux.NewRouter().PathPrefix("/v2").Subrouter() @@ -163,5 +164,16 @@ func NewRouter(projectClient moduleLib.ProjectManager, 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") + // setting routes for Instantiation + if instantiationClient == nil { + instantiationClient = moduleClient.Instantiation + } + + instantiationHandler := instantiationHandler{ + client: instantiationClient, + } + + router.HandleFunc("/projects/{project-name}/composite-apps/{composite-app-name}/{composite-app-version}/deployment-intent-groups/{deployment-intent-group-name}/instantiate", instantiationHandler.instantiateHandler).Methods("POST") + return router } diff --git a/src/orchestrator/api/composite_profilehandler_test.go b/src/orchestrator/api/composite_profilehandler_test.go index 360653c7..42b9b3a1 100644 --- a/src/orchestrator/api/composite_profilehandler_test.go +++ b/src/orchestrator/api/composite_profilehandler_test.go @@ -128,7 +128,7 @@ func Test_compositeProfileHandler_createHandler(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { request := httptest.NewRequest("POST", "/v2/projects/{project-name}/composite-apps/{composite-app-name}/{version}/composite-profiles", testCase.reader) - resp := executeRequest(request, NewRouter(nil, nil, nil, nil, nil, nil, nil, nil, testCase.cProfClient, nil)) + resp := executeRequest(request, NewRouter(nil, nil, nil, nil, nil, nil, nil, nil, testCase.cProfClient, 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 1844fb32..3c543cb8 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, nil, testCase.controllerClient, nil, nil, nil, nil, nil, nil)) + resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.controllerClient, nil, nil, 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, nil, testCase.controllerClient, nil, nil, nil, nil, nil, nil)) + resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.controllerClient, nil, nil, 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, nil, testCase.controllerClient, nil, nil, nil, nil, nil, nil)) + resp := executeRequest(request, NewRouter(nil, nil, nil, testCase.controllerClient, nil, nil, nil, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { diff --git a/src/orchestrator/api/instantiation_handler.go b/src/orchestrator/api/instantiation_handler.go new file mode 100644 index 00000000..d9da2183 --- /dev/null +++ b/src/orchestrator/api/instantiation_handler.go @@ -0,0 +1,64 @@ +/* + * 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 ( + "github.com/gorilla/mux" + moduleLib "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module" + "net/http" +) + +/* Used to store backend implementation objects +Also simplifies mocking for unit testing purposes +*/ +type instantiationHandler struct { + client moduleLib.InstantiationManager +} + +// func (h instantiationHandler) approveInstantiationHandler(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"] + +// instantiateErr := h.client.ApproveInstantiation(p, ca, v, di) +// if instantiateErr != nil { +// http.Error(w, instantiateErr.Error(), http.StatusInternalServerError) +// return +// } + +// w.WriteHeader(http.StatusCreated) +// } + +func (h instantiationHandler) instantiateHandler(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"] + + iErr := h.client.Instantiate(p, ca, v, di) + if iErr != nil { + http.Error(w, iErr.Error(), http.StatusInternalServerError) + return + } + w.WriteHeader(http.StatusAccepted) + +} diff --git a/src/orchestrator/api/projecthandler_test.go b/src/orchestrator/api/projecthandler_test.go index af40f961..5e820aa2 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, nil, nil, nil, nil)) + resp := executeRequest(request, NewRouter(testCase.projectClient, nil, nil, nil, 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, nil, nil, nil, nil)) + resp := executeRequest(request, NewRouter(testCase.projectClient, nil, nil, nil, 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, nil, nil, nil, nil)) + resp := executeRequest(request, NewRouter(testCase.projectClient, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil)) //Check returned code if resp.StatusCode != testCase.expectedCode { -- cgit 1.2.3-korg