aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/api
diff options
context:
space:
mode:
authorKonrad Bańka <k.banka@samsung.com>2021-02-24 18:28:56 +0100
committerKonrad Bańka <k.banka@samsung.com>2021-02-24 21:43:07 +0100
commit74dfd71d3628c52e63f66c079244638c675b2b9c (patch)
tree1162640670a7bf6b3f8f3ab29b58da8bd064cff1 /src/k8splugin/api
parent69f17bdaf539b3ad89f0c3770ea624b512b80fbd (diff)
Provide Query API for CNF Instances
Query API doesn't directly use Status API code, in order to allow for querying derived resources that might not be typically returned by Status API like replicasets for deployment. Issue-ID: MULTICLOUD-1305 Signed-off-by: Konrad Bańka <k.banka@samsung.com> Change-Id: If15adce23845880f3e6771cc8eab78a78ab13517
Diffstat (limited to 'src/k8splugin/api')
-rw-r--r--src/k8splugin/api/api.go6
-rw-r--r--src/k8splugin/api/instancehandler.go46
2 files changed, 52 insertions, 0 deletions
diff --git a/src/k8splugin/api/api.go b/src/k8splugin/api/api.go
index c836fc65..e55d833b 100644
--- a/src/k8splugin/api/api.go
+++ b/src/k8splugin/api/api.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
@@ -47,6 +48,11 @@ func NewRouter(defClient rb.DefinitionManager,
instRouter.HandleFunc("/instance/{instID}", instHandler.getHandler).Methods("GET")
instRouter.HandleFunc("/instance/{instID}/status", instHandler.statusHandler).Methods("GET")
+ instRouter.HandleFunc("/instance/{instID}/query", instHandler.queryHandler).
+ Queries("ApiVersion", "{ApiVersion}",
+ "Kind", "{Kind}",
+ "Name", "{Name}",
+ "Labels", "{Labels}").Methods("GET")
instRouter.HandleFunc("/instance/{instID}", instHandler.deleteHandler).Methods("DELETE")
// (TODO): Fix update method
// instRouter.HandleFunc("/{vnfInstanceId}", UpdateHandler).Methods("PUT")
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) {