summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/app
diff options
context:
space:
mode:
authorBin Yang <bin.yang@windriver.com>2019-07-23 07:30:16 +0000
committerGerrit Code Review <gerrit@onap.org>2019-07-23 07:30:16 +0000
commitf83526881ac7758638b1e7e0e1bcf2ab8cd13133 (patch)
tree83e38d253bf746e39b38d026fd9ba0717f626cad /src/k8splugin/internal/app
parent40014c64df3250db72b41e05da3dd40746d3d6d3 (diff)
parente04fd6fa1f0abe6b18787b192e01164db1db06db (diff)
Merge "Add a list api for instances"
Diffstat (limited to 'src/k8splugin/internal/app')
-rw-r--r--src/k8splugin/internal/app/instance.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/k8splugin/internal/app/instance.go b/src/k8splugin/internal/app/instance.go
index 5272d60f..d28fe799 100644
--- a/src/k8splugin/internal/app/instance.go
+++ b/src/k8splugin/internal/app/instance.go
@@ -19,6 +19,7 @@ package app
import (
"encoding/base64"
"encoding/json"
+ "log"
"math/rand"
"github.com/onap/multicloud-k8s/src/k8splugin/internal/db"
@@ -46,10 +47,20 @@ type InstanceResponse struct {
Resources []helm.KubernetesResource `json:"resources"`
}
+// InstanceMiniResponse contains the response from instantiation
+// It does NOT include the created resources.
+// Use the regular GET to get the created resources for a particular instance
+type InstanceMiniResponse struct {
+ ID string `json:"id"`
+ Request InstanceRequest `json:"request"`
+ Namespace string `json:"namespace"`
+}
+
// InstanceManager is an interface exposes the instantiation functionality
type InstanceManager interface {
Create(i InstanceRequest) (InstanceResponse, error)
Get(id string) (InstanceResponse, error)
+ List() ([]InstanceMiniResponse, error)
Find(rbName string, ver string, profile string, labelKeys map[string]string) ([]InstanceResponse, error)
Delete(id string) error
}
@@ -171,6 +182,37 @@ func (v *InstanceClient) Get(id string) (InstanceResponse, error) {
return InstanceResponse{}, pkgerrors.New("Error getting Instance")
}
+// List returns the instance for corresponding ID
+// Empty string returns all
+func (v *InstanceClient) List() ([]InstanceMiniResponse, error) {
+
+ dbres, err := db.DBconn.ReadAll(v.storeName, v.tagInst)
+ if err != nil || len(dbres) == 0 {
+ return []InstanceMiniResponse{}, pkgerrors.Wrap(err, "Listing Instances")
+ }
+
+ var results []InstanceMiniResponse
+ for key, value := range dbres {
+ //value is a byte array
+ if value != nil {
+ resp := InstanceResponse{}
+ err = db.DBconn.Unmarshal(value, &resp)
+ if err != nil {
+ log.Printf("[Instance] Error: %s Unmarshaling Instance: %s", err.Error(), key)
+ }
+
+ miniresp := InstanceMiniResponse{
+ ID: resp.ID,
+ Request: resp.Request,
+ Namespace: resp.Namespace,
+ }
+ results = append(results, miniresp)
+ }
+ }
+
+ return results, nil
+}
+
// Find returns the instances that match the given criteria
// If version is empty, it will return all instances for a given rbName
// If profile is empty, it will return all instances for a given rbName+version