aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/app
diff options
context:
space:
mode:
Diffstat (limited to 'src/k8splugin/internal/app')
-rw-r--r--src/k8splugin/internal/app/instance.go42
-rw-r--r--src/k8splugin/internal/app/instance_test.go8
2 files changed, 46 insertions, 4 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
diff --git a/src/k8splugin/internal/app/instance_test.go b/src/k8splugin/internal/app/instance_test.go
index 24558a44..3cb62ee1 100644
--- a/src/k8splugin/internal/app/instance_test.go
+++ b/src/k8splugin/internal/app/instance_test.go
@@ -51,7 +51,7 @@ func TestInstanceCreate(t *testing.T) {
Items: map[string]map[string][]byte{
rb.ProfileKey{RBName: "test-rbdef", RBVersion: "v1",
ProfileName: "profile1"}.String(): {
- "metadata": []byte(
+ "profilemetadata": []byte(
"{\"profile-name\":\"profile1\"," +
"\"release-name\":\"testprofilereleasename\"," +
"\"namespace\":\"testnamespace\"," +
@@ -59,7 +59,7 @@ func TestInstanceCreate(t *testing.T) {
"\"rb-version\":\"v1\"," +
"\"kubernetesversion\":\"1.12.3\"}"),
// base64 encoding of vagrant/tests/vnfs/testrb/helm/profile
- "content": []byte("H4sICLmjT1wAA3Byb2ZpbGUudGFyAO1Y32/bNhD2s/6Kg/KyYZZsy" +
+ "profilecontent": []byte("H4sICLmjT1wAA3Byb2ZpbGUudGFyAO1Y32/bNhD2s/6Kg/KyYZZsy" +
"78K78lLMsxY5gRxmqIYhoKWaJsYJWokZdfo+r/vSFmunCZNBtQJ1vF7sXX36e54vDN5T" +
"knGFlTpcEtS3jgO2ohBr2c/EXc/29Gg1+h0e1F32Ol1B1Gj3Ymifr8B7SPFc4BCaSIBG" +
"lII/SXeY/r/KIIg8NZUKiayEaw7nt7mdOQBrAkvqBqBL1ArWULflRJbJz4SYpEt2FJSJ" +
@@ -84,13 +84,13 @@ func TestInstanceCreate(t *testing.T) {
"yJ66WPQwcHBwcHBwcHBwcHBwcHBwcHhm8Q/mTHqWgAoAAA="),
},
rb.DefinitionKey{RBName: "test-rbdef", RBVersion: "v1"}.String(): {
- "metadata": []byte(
+ "defmetadata": []byte(
"{\"rb-name\":\"test-rbdef\"," +
"\"rb-version\":\"v1\"," +
"\"chart-name\":\"vault-consul-dev\"," +
"\"description\":\"testresourcebundle\"}"),
// base64 encoding of vagrant/tests/vnfs/testrb/helm/vault-consul-dev
- "content": []byte("H4sICEetS1wAA3ZhdWx0LWNvbnN1bC1kZXYudGFyAO0c7XLbNjK/+R" +
+ "defcontent": []byte("H4sICEetS1wAA3ZhdWx0LWNvbnN1bC1kZXYudGFyAO0c7XLbNjK/+R" +
"QYujdJehatb+V4czPnOmnPk9bO2Gk7nbaTgUhIxpgiGAK0o3P9QPca92S3C5AU9GXZiax" +
"c7rA/LJEAFovdxX4AK1/RIlGNSKSySBoxuzp4sn1oAgx6Pf0JsPipv7c63XZ70O61W4Mn" +
"zVZ7MGg9Ib1HoGUJCqloTsiTXAh1V79N7V8oXC3K/+iC5iqY0kmytTlQwP1ud538W51Wf" +