From f74ad24c6034294c1915f5778adb259dd65c9208 Mon Sep 17 00:00:00 2001 From: Kiran Kamineni Date: Thu, 28 Mar 2019 12:53:13 -0700 Subject: Refactor instance code Issue-ID: MULTICLOUD-350 Change-Id: I2574d94e4ebada1e138913b2a03549dd90906d7b Signed-off-by: Kiran Kamineni --- src/k8splugin/api/api.go | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src/k8splugin/api/api.go') diff --git a/src/k8splugin/api/api.go b/src/k8splugin/api/api.go index 2862a999..54147d2e 100644 --- a/src/k8splugin/api/api.go +++ b/src/k8splugin/api/api.go @@ -14,21 +14,30 @@ limitations under the License. package api import ( + "k8splugin/internal/app" "k8splugin/internal/rb" "github.com/gorilla/mux" ) -// NewRouter creates a router instance that serves the VNFInstance web methods -func NewRouter(kubeconfig string, defClient rb.DefinitionManager, - profileClient rb.ProfileManager) *mux.Router { +// NewRouter creates a router that registers the various urls that are supported +func NewRouter(defClient rb.DefinitionManager, + profileClient rb.ProfileManager, + instClient app.InstanceManager) *mux.Router { + router := mux.NewRouter() - vnfInstanceHandler := router.PathPrefix("/v1/vnf_instances").Subrouter() - vnfInstanceHandler.HandleFunc("/", CreateHandler).Methods("POST").Name("VNFCreation") - vnfInstanceHandler.HandleFunc("/{cloudRegionID}/{namespace}", ListHandler).Methods("GET") - vnfInstanceHandler.HandleFunc("/{cloudRegionID}/{namespace}/{externalVNFID}", DeleteHandler).Methods("DELETE") - vnfInstanceHandler.HandleFunc("/{cloudRegionID}/{namespace}/{externalVNFID}", GetHandler).Methods("GET") + // Setup Instance handler routes + if instClient == nil { + instClient = app.NewInstanceClient() + } + instHandler := instanceHandler{client: instClient} + instRouter := router.PathPrefix("/v1").Subrouter() + instRouter.HandleFunc("/instance", instHandler.createHandler).Methods("POST") + instRouter.HandleFunc("/instance/{instID}", instHandler.getHandler).Methods("GET") + instRouter.HandleFunc("/instance/{instID}", instHandler.deleteHandler).Methods("DELETE") + // (TODO): Fix update method + // instRouter.HandleFunc("/{vnfInstanceId}", UpdateHandler).Methods("PUT") //Setup resource bundle definition routes if defClient == nil { @@ -52,8 +61,5 @@ func NewRouter(kubeconfig string, defClient rb.DefinitionManager, resRouter.HandleFunc("/definition/{rbname}/{rbversion}/profile/{prname}", profileHandler.getHandler).Methods("GET") resRouter.HandleFunc("/definition/{rbname}/{rbversion}/profile/{prname}", profileHandler.deleteHandler).Methods("DELETE") - // (TODO): Fix update method - // vnfInstanceHandler.HandleFunc("/{vnfInstanceId}", UpdateHandler).Methods("PUT") - return router } -- cgit 1.2.3-korg