diff options
author | Igor D.C <igor.duarte.cardoso@intel.com> | 2020-07-28 03:05:05 +0000 |
---|---|---|
committer | Igor D.C <igor.duarte.cardoso@intel.com> | 2020-07-28 03:10:15 +0000 |
commit | d641c3864d4ba71e127d332c4ac2082f98bba1e5 (patch) | |
tree | 5127f2c8f6a377d0e36457530255612bf9bfba38 /src/dcm/api | |
parent | 39b7d2f8a79f23141301e7b9abf7bf3a0f2e8f21 (diff) |
DCM - fix code formatting via vscode
Visual Studio Code automatic code formatting was
performed on the 4 modified DCM files.
Issue-ID: MULTICLOUD-1143
Signed-off-by: Igor D.C <igor.duarte.cardoso@intel.com>
Change-Id: I24d2b44181b5c0737df7cb4541f9eede0950211a
Diffstat (limited to 'src/dcm/api')
-rw-r--r-- | src/dcm/api/api.go | 263 | ||||
-rw-r--r-- | src/dcm/api/logicalCloudHandler.go | 293 |
2 files changed, 277 insertions, 279 deletions
diff --git a/src/dcm/api/api.go b/src/dcm/api/api.go index 87ad77b5..de1d5c97 100644 --- a/src/dcm/api/api.go +++ b/src/dcm/api/api.go @@ -14,143 +14,142 @@ limitations under the License. package api import ( + "github.com/onap/multicloud-k8s/src/dcm/pkg/module" - "github.com/onap/multicloud-k8s/src/dcm/pkg/module" - - "github.com/gorilla/mux" + "github.com/gorilla/mux" ) // NewRouter creates a router that registers the various urls that are // supported func NewRouter( - logicalCloudClient module.LogicalCloudManager, - clusterClient module.ClusterManager, - userPermissionClient module.UserPermissionManager, - quotaClient module.QuotaManager, - keyValueClient module.KeyValueManager) *mux.Router { - - router := mux.NewRouter() - - // Set up Logical Cloud handler routes - if logicalCloudClient == nil { - logicalCloudClient = module.NewLogicalCloudClient() - } - - if clusterClient == nil { - clusterClient = module.NewClusterClient() - } - - if quotaClient == nil { - quotaClient = module.NewQuotaClient() - } - - logicalCloudHandler := logicalCloudHandler{client: logicalCloudClient, - clusterClient: clusterClient, - quotaClient: quotaClient, - } - lcRouter := router.PathPrefix("/v2/projects/{project-name}").Subrouter() - lcRouter.HandleFunc( - "/logical-clouds", - logicalCloudHandler.createHandler).Methods("POST") - lcRouter.HandleFunc( - "/logical-clouds", - logicalCloudHandler.getHandler).Methods("GET") - lcRouter.HandleFunc( - "/logical-clouds/{logical-cloud-name}", - logicalCloudHandler.getHandler).Methods("GET") - lcRouter.HandleFunc( - "/logical-clouds/{logical-cloud-name}", - logicalCloudHandler.deleteHandler).Methods("DELETE") - lcRouter.HandleFunc( - "/logical-clouds/{logical-cloud-name}", - logicalCloudHandler.updateHandler).Methods("PUT") - lcRouter.HandleFunc( - "/logical-clouds/{logical-cloud-name}/apply", - logicalCloudHandler.applyHandler).Methods("POST") - // To Do - // get kubeconfig - /*lcRouter.HandleFunc( - "/logical-clouds/{name}/kubeconfig?cluster-reference={cluster}", - logicalCloudHandler.getConfigHandler).Methods("GET") - //get status - lcRouter.HandleFunc( - "/logical-clouds/{name}/cluster-references/", - logicalCloudHandler.associateHandler).Methods("GET")*/ - - // Set up Cluster API - - clusterHandler := clusterHandler{client: clusterClient} - clusterRouter := router.PathPrefix("/v2/projects/{project-name}").Subrouter() - clusterRouter.HandleFunc( - "/logical-clouds/{logical-cloud-name}/cluster-references", - clusterHandler.createHandler).Methods("POST") - clusterRouter.HandleFunc( - "/logical-clouds/{logical-cloud-name}/cluster-references", - clusterHandler.getHandler).Methods("GET") - clusterRouter.HandleFunc( - "/logical-clouds/{logical-cloud-name}/cluster-references/{cluster-reference}", - clusterHandler.getHandler).Methods("GET") - clusterRouter.HandleFunc( - "/logical-clouds/{logical-cloud-name}/cluster-references/{cluster-reference}", - clusterHandler.updateHandler).Methods("PUT") - clusterRouter.HandleFunc( - "/logical-clouds/{logical-cloud-name}/cluster-references/{cluster-reference}", - clusterHandler.deleteHandler).Methods("DELETE") - - // Set up User Permission API - if userPermissionClient == nil { - userPermissionClient = module.NewUserPermissionClient() - } - userPermissionHandler := userPermissionHandler{client: userPermissionClient} - upRouter := router.PathPrefix("/v2/projects/{project-name}").Subrouter() - upRouter.HandleFunc( - "/logical-clouds/{logical-cloud-name}/user-permissions", - userPermissionHandler.createHandler).Methods("POST") - upRouter.HandleFunc( - "/logical-clouds/{logical-cloud-name}/user-permissions/{permission-name}", - userPermissionHandler.getHandler).Methods("GET") - upRouter.HandleFunc( - "/logical-clouds/{logical-cloud-name}/user-permissions/{permission-name}", - userPermissionHandler.updateHandler).Methods("PUT") - upRouter.HandleFunc( - "/logical-clouds/{logical-cloud-name}/user-permissions/{permission-name}", - userPermissionHandler.deleteHandler).Methods("DELETE") - - // Set up Quota API - - quotaHandler := quotaHandler{client: quotaClient} - quotaRouter := router.PathPrefix("/v2/projects/{project-name}").Subrouter() - quotaRouter.HandleFunc( - "/logical-clouds/{logical-cloud-name}/cluster-quotas", - quotaHandler.createHandler).Methods("POST") - quotaRouter.HandleFunc( - "/logical-clouds/{logical-cloud-name}/cluster-quotas/{quota-name}", - quotaHandler.getHandler).Methods("GET") - quotaRouter.HandleFunc( - "/logical-clouds/{logical-cloud-name}/cluster-quotas/{quota-name}", - quotaHandler.updateHandler).Methods("PUT") - quotaRouter.HandleFunc( - "/logical-clouds/{logical-cloud-name}/cluster-quotas/{quota-name}", - quotaHandler.deleteHandler).Methods("DELETE") - - // Set up Key Value API - if keyValueClient == nil { - keyValueClient = module.NewKeyValueClient() - } - keyValueHandler := keyValueHandler{client: keyValueClient} - kvRouter := router.PathPrefix("/v2/projects/{project-name}").Subrouter() - kvRouter.HandleFunc( - "/logical-clouds/{logical-cloud-name}/kv-pairs", - keyValueHandler.createHandler).Methods("POST") - kvRouter.HandleFunc( - "/logical-clouds/{logical-cloud-name}/kv-pairs/{kv-pair-name}", - keyValueHandler.getHandler).Methods("GET") - kvRouter.HandleFunc( - "/logical-clouds/{logical-cloud-name}/kv-pairs/{kv-pair-name}", - keyValueHandler.updateHandler).Methods("PUT") - kvRouter.HandleFunc( - "/logical-clouds/{logical-cloud-name}/kv-pairs/{kv-pair-name}", - keyValueHandler.deleteHandler).Methods("DELETE") - return router + logicalCloudClient module.LogicalCloudManager, + clusterClient module.ClusterManager, + userPermissionClient module.UserPermissionManager, + quotaClient module.QuotaManager, + keyValueClient module.KeyValueManager) *mux.Router { + + router := mux.NewRouter() + + // Set up Logical Cloud handler routes + if logicalCloudClient == nil { + logicalCloudClient = module.NewLogicalCloudClient() + } + + if clusterClient == nil { + clusterClient = module.NewClusterClient() + } + + if quotaClient == nil { + quotaClient = module.NewQuotaClient() + } + + logicalCloudHandler := logicalCloudHandler{client: logicalCloudClient, + clusterClient: clusterClient, + quotaClient: quotaClient, + } + lcRouter := router.PathPrefix("/v2/projects/{project-name}").Subrouter() + lcRouter.HandleFunc( + "/logical-clouds", + logicalCloudHandler.createHandler).Methods("POST") + lcRouter.HandleFunc( + "/logical-clouds", + logicalCloudHandler.getHandler).Methods("GET") + lcRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}", + logicalCloudHandler.getHandler).Methods("GET") + lcRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}", + logicalCloudHandler.deleteHandler).Methods("DELETE") + lcRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}", + logicalCloudHandler.updateHandler).Methods("PUT") + lcRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/apply", + logicalCloudHandler.applyHandler).Methods("POST") + // To Do + // get kubeconfig + /*lcRouter.HandleFunc( + "/logical-clouds/{name}/kubeconfig?cluster-reference={cluster}", + logicalCloudHandler.getConfigHandler).Methods("GET") + //get status + lcRouter.HandleFunc( + "/logical-clouds/{name}/cluster-references/", + logicalCloudHandler.associateHandler).Methods("GET")*/ + + // Set up Cluster API + + clusterHandler := clusterHandler{client: clusterClient} + clusterRouter := router.PathPrefix("/v2/projects/{project-name}").Subrouter() + clusterRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/cluster-references", + clusterHandler.createHandler).Methods("POST") + clusterRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/cluster-references", + clusterHandler.getHandler).Methods("GET") + clusterRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/cluster-references/{cluster-reference}", + clusterHandler.getHandler).Methods("GET") + clusterRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/cluster-references/{cluster-reference}", + clusterHandler.updateHandler).Methods("PUT") + clusterRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/cluster-references/{cluster-reference}", + clusterHandler.deleteHandler).Methods("DELETE") + + // Set up User Permission API + if userPermissionClient == nil { + userPermissionClient = module.NewUserPermissionClient() + } + userPermissionHandler := userPermissionHandler{client: userPermissionClient} + upRouter := router.PathPrefix("/v2/projects/{project-name}").Subrouter() + upRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/user-permissions", + userPermissionHandler.createHandler).Methods("POST") + upRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/user-permissions/{permission-name}", + userPermissionHandler.getHandler).Methods("GET") + upRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/user-permissions/{permission-name}", + userPermissionHandler.updateHandler).Methods("PUT") + upRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/user-permissions/{permission-name}", + userPermissionHandler.deleteHandler).Methods("DELETE") + + // Set up Quota API + + quotaHandler := quotaHandler{client: quotaClient} + quotaRouter := router.PathPrefix("/v2/projects/{project-name}").Subrouter() + quotaRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/cluster-quotas", + quotaHandler.createHandler).Methods("POST") + quotaRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/cluster-quotas/{quota-name}", + quotaHandler.getHandler).Methods("GET") + quotaRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/cluster-quotas/{quota-name}", + quotaHandler.updateHandler).Methods("PUT") + quotaRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/cluster-quotas/{quota-name}", + quotaHandler.deleteHandler).Methods("DELETE") + + // Set up Key Value API + if keyValueClient == nil { + keyValueClient = module.NewKeyValueClient() + } + keyValueHandler := keyValueHandler{client: keyValueClient} + kvRouter := router.PathPrefix("/v2/projects/{project-name}").Subrouter() + kvRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/kv-pairs", + keyValueHandler.createHandler).Methods("POST") + kvRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/kv-pairs/{kv-pair-name}", + keyValueHandler.getHandler).Methods("GET") + kvRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/kv-pairs/{kv-pair-name}", + keyValueHandler.updateHandler).Methods("PUT") + kvRouter.HandleFunc( + "/logical-clouds/{logical-cloud-name}/kv-pairs/{kv-pair-name}", + keyValueHandler.deleteHandler).Methods("DELETE") + return router } diff --git a/src/dcm/api/logicalCloudHandler.go b/src/dcm/api/logicalCloudHandler.go index d8fcf268..d9a3e5f5 100644 --- a/src/dcm/api/logicalCloudHandler.go +++ b/src/dcm/api/logicalCloudHandler.go @@ -14,182 +14,181 @@ * See the License for the specific language governing permissions * and * limitations under the License. -*/ + */ package api import ( - "encoding/json" - "net/http" - "io" - "github.com/onap/multicloud-k8s/src/dcm/pkg/module" - "github.com/gorilla/mux" -) + "encoding/json" + "io" + "net/http" + "github.com/gorilla/mux" + "github.com/onap/multicloud-k8s/src/dcm/pkg/module" +) // logicalCloudHandler is used to store backend implementations objects type logicalCloudHandler struct { - client module.LogicalCloudManager - clusterClient module.ClusterManager - quotaClient module.QuotaManager + client module.LogicalCloudManager + clusterClient module.ClusterManager + quotaClient module.QuotaManager } // CreateHandler handles creation of the logical cloud entry in the database func (h logicalCloudHandler) createHandler(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - project := vars["project-name"] - var v module.LogicalCloud - - err := json.NewDecoder(r.Body).Decode(&v) - switch { - case err == io.EOF: - http.Error(w, "Empty body", http.StatusBadRequest) - return - case err != nil: - http.Error(w, err.Error(), http.StatusUnprocessableEntity) - return - } - - // Logical Cloud Name is required. - if v.MetaData.LogicalCloudName == "" { - http.Error(w, "Missing name in POST request", http.StatusBadRequest) - return - } - - ret, err := h.client.Create(project, v) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusCreated) - err = json.NewEncoder(w).Encode(ret) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } + vars := mux.Vars(r) + project := vars["project-name"] + var v module.LogicalCloud + + err := json.NewDecoder(r.Body).Decode(&v) + switch { + case err == io.EOF: + http.Error(w, "Empty body", http.StatusBadRequest) + return + case err != nil: + http.Error(w, err.Error(), http.StatusUnprocessableEntity) + return + } + + // Logical Cloud Name is required. + if v.MetaData.LogicalCloudName == "" { + http.Error(w, "Missing name in POST request", http.StatusBadRequest) + return + } + + ret, err := h.client.Create(project, v) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } // getHandler handle GET operations on a particular name // Returns a Logical Cloud func (h logicalCloudHandler) getHandler(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - project := vars["project-name"] - name := vars["logical-cloud-name"] - var ret interface{} - var err error - - if len(name) == 0 { - ret, err = h.client.GetAll(project) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - } else { - ret, err = h.client.Get(project, name) - 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(ret) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } + vars := mux.Vars(r) + project := vars["project-name"] + name := vars["logical-cloud-name"] + var ret interface{} + var err error + + if len(name) == 0 { + ret, err = h.client.GetAll(project) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } else { + ret, err = h.client.Get(project, name) + 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(ret) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } // UpdateHandler handles Update operations on a particular logical cloud func (h logicalCloudHandler) updateHandler(w http.ResponseWriter, r *http.Request) { - var v module.LogicalCloud - vars := mux.Vars(r) - project := vars["project-name"] - name := vars["logical-cloud-name"] - - err := json.NewDecoder(r.Body).Decode(&v) - 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 v.MetaData.LogicalCloudName == "" { - http.Error(w, "Missing name in PUT request", http.StatusBadRequest) - return - } - - ret, err := h.client.Update(project, name, v) - if err != nil { - http.Error(w, err.Error(), - http.StatusInternalServerError) - return - } - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusCreated) - err = json.NewEncoder(w).Encode(ret) - if err != nil { - http.Error(w, err.Error(), - http.StatusInternalServerError) - return - } + var v module.LogicalCloud + vars := mux.Vars(r) + project := vars["project-name"] + name := vars["logical-cloud-name"] + + err := json.NewDecoder(r.Body).Decode(&v) + 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 v.MetaData.LogicalCloudName == "" { + http.Error(w, "Missing name in PUT request", http.StatusBadRequest) + return + } + + ret, err := h.client.Update(project, name, v) + if err != nil { + http.Error(w, err.Error(), + http.StatusInternalServerError) + return + } + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), + http.StatusInternalServerError) + return + } } func (h logicalCloudHandler) deleteHandler(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - project := vars["project-name"] - name := vars["logical-cloud-name"] + vars := mux.Vars(r) + project := vars["project-name"] + name := vars["logical-cloud-name"] - err := h.client.Delete(project, name) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } + err := h.client.Delete(project, name) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } - w.WriteHeader(http.StatusNoContent) + w.WriteHeader(http.StatusNoContent) } func (h logicalCloudHandler) applyHandler(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - project := vars["project-name"] - name := vars["logical-cloud-name"] - - // Get logical cloud - lc, err := h.client.Get(project, name) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - // Get Clusters - clusters, err := h.clusterClient.GetAllClusters(project, name) - - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - - //Get Quotas - quotas, err := h.quotaClient.GetAllQuotas(project, name) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - err = module.CreateEtcdContext(lc, clusters, quotas) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - return + vars := mux.Vars(r) + project := vars["project-name"] + name := vars["logical-cloud-name"] + + // Get logical cloud + lc, err := h.client.Get(project, name) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + // Get Clusters + clusters, err := h.clusterClient.GetAllClusters(project, name) + + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + //Get Quotas + quotas, err := h.quotaClient.GetAllQuotas(project, name) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + err = module.CreateEtcdContext(lc, clusters, quotas) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + return } |