diff options
author | Ritu Sood <ritu.sood@intel.com> | 2021-02-25 14:17:19 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2021-02-25 14:17:19 +0000 |
commit | 965da8328566d58b2b38373f76aa1ab79c0b314e (patch) | |
tree | 21d98c7a7d73b9f8db7fb0b78f779601f71b4f17 /src/k8splugin/api/instancehandler.go | |
parent | 2f09583725c8481ea3d7505ed2394c180af5ef03 (diff) | |
parent | 74dfd71d3628c52e63f66c079244638c675b2b9c (diff) |
Merge "Provide Query API for CNF Instances"
Diffstat (limited to 'src/k8splugin/api/instancehandler.go')
-rw-r--r-- | src/k8splugin/api/instancehandler.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/k8splugin/api/instancehandler.go b/src/k8splugin/api/instancehandler.go index b0437426..b56a8e12 100644 --- a/src/k8splugin/api/instancehandler.go +++ b/src/k8splugin/api/instancehandler.go @@ -1,5 +1,6 @@ /* Copyright 2018 Intel Corporation. +Copyright © 2021 Samsung Electronics 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 @@ -171,6 +172,51 @@ func (i instanceHandler) statusHandler(w http.ResponseWriter, r *http.Request) { } } +// queryHandler retrieves information about specified resources for instance +func (i instanceHandler) queryHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + id := vars["instID"] + apiVersion := r.FormValue("ApiVersion") + kind := r.FormValue("Kind") + name := r.FormValue("Name") + labels := r.FormValue("Labels") + if apiVersion == "" { + http.Error(w, "Missing apiVersion mandatory parameter", http.StatusBadRequest) + return + } + if kind == "" { + http.Error(w, "Missing kind mandatory parameter", http.StatusBadRequest) + return + } + if name == "" && labels == "" { + http.Error(w, "Name or Labels parameter must be provided", http.StatusBadRequest) + return + } + resp, err := i.client.Query(id, apiVersion, kind, name, labels) + if err != nil { + log.Error("Error getting Query results", log.Fields{ + "error": err, + "id": id, + "apiVersion": apiVersion, + "kind": kind, + "name": name, + "labels": labels, + }) + http.Error(w, err.Error(), http.StatusInternalServerError) + } + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + err = json.NewEncoder(w).Encode(resp) + if err != nil { + log.Error("Error Marshaling Response", log.Fields{ + "error": err, + "response": resp, + }) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} + // listHandler retrieves information about an instance via the ID func (i instanceHandler) listHandler(w http.ResponseWriter, r *http.Request) { |