aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/app/instance.go
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2019-05-15 15:22:31 -0700
committerKiran Kamineni <kiran.k.kamineni@intel.com>2019-05-15 15:22:34 -0700
commit881bb510d7f0b7a3f1110589e8aa3596e655e38c (patch)
tree6d983672cf6711280f0b787bf23bce5047835841 /src/k8splugin/internal/app/instance.go
parent0993b5d7f5b8d7287e2e3d72c9e082b1ee0d7192 (diff)
Add find method in instance
Add a find method to get instances based on rbname, version and profile. If only rbname is provided, all instances based on that resource bundle are returned. If only rbname and version are provided, all instances based on that combination are returned. When all three parameters are provided, a single instance that matches them is returned. Issue-ID: MULTICLOUD-613 Change-Id: If63e844c77829211b807ce6cd7c11dad247751fc Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/internal/app/instance.go')
-rw-r--r--src/k8splugin/internal/app/instance.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/k8splugin/internal/app/instance.go b/src/k8splugin/internal/app/instance.go
index 6d0910d0..41eca211 100644
--- a/src/k8splugin/internal/app/instance.go
+++ b/src/k8splugin/internal/app/instance.go
@@ -53,6 +53,7 @@ type InstanceResponse struct {
type InstanceManager interface {
Create(i InstanceRequest) (InstanceResponse, error)
Get(id string) (InstanceResponse, error)
+ Find(rbName string, ver string, profile string) ([]InstanceResponse, error)
Delete(id string) error
}
@@ -176,6 +177,48 @@ func (v *InstanceClient) Get(id string) (InstanceResponse, error) {
return InstanceResponse{}, pkgerrors.New("Error getting Instance")
}
+// 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
+func (v *InstanceClient) Find(rbName string, version string, profile string) ([]InstanceResponse, error) {
+ if rbName == "" {
+ return []InstanceResponse{}, pkgerrors.New("rbName is required and cannot be empty")
+ }
+
+ values, err := db.DBconn.ReadAll(v.storeName, v.tagInst)
+ if err != nil || len(values) == 0 {
+ return []InstanceResponse{}, pkgerrors.Wrap(err, "Find Instance")
+ }
+
+ response := []InstanceResponse{}
+ //values is a map[string][]byte
+ for _, value := range values {
+ resp := InstanceResponse{}
+ db.DBconn.Unmarshal(value, &resp)
+ if err != nil {
+ return []InstanceResponse{}, pkgerrors.Wrap(err, "Unmarshaling Instance Value")
+ }
+
+ if resp.RBName == rbName {
+
+ //Check if a version is provided and if it matches
+ if version != "" {
+ if resp.RBVersion == version {
+ //Check if a profilename matches or if it is not provided
+ if profile == "" || resp.ProfileName == profile {
+ response = append(response, resp)
+ }
+ }
+ } else {
+ //Append all versions as version is not provided
+ response = append(response, resp)
+ }
+ }
+ }
+
+ return response, nil
+}
+
// Delete the Instance from database
func (v *InstanceClient) Delete(id string) error {
inst, err := v.Get(id)