diff options
author | Ritu Sood <ritu.sood@intel.com> | 2020-09-28 23:26:25 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-09-28 23:26:25 +0000 |
commit | 4e5efb48bba88af11047fec05c9d4b5363f4add9 (patch) | |
tree | f65275ca9fa8407c2b21e22244383a7c8b5030bb /src/dcm/pkg/module/logicalcloud.go | |
parent | 4009ff23fa17910728c7985c89e65f4ac4ce3def (diff) | |
parent | 8c0cc1278cc4d84863b076b2014b9bc9d8805218 (diff) |
Merge "Implement Terminate operation in DCM"
Diffstat (limited to 'src/dcm/pkg/module/logicalcloud.go')
-rw-r--r-- | src/dcm/pkg/module/logicalcloud.go | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/src/dcm/pkg/module/logicalcloud.go b/src/dcm/pkg/module/logicalcloud.go index 7d3c806b..9b8ff703 100644 --- a/src/dcm/pkg/module/logicalcloud.go +++ b/src/dcm/pkg/module/logicalcloud.go @@ -17,6 +17,7 @@ package module import ( + "github.com/onap/multicloud-k8s/src/orchestrator/pkg/appcontext" "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/db" "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module" @@ -72,6 +73,7 @@ type LogicalCloudManager interface { GetAll(project string) ([]LogicalCloud, error) Delete(project, name string) error Update(project, name string, c LogicalCloud) (LogicalCloud, error) + GetLogicalCloudContext(name string) (appcontext.AppContext, string, error) } // Interface facilitates unit testing by mocking functions @@ -87,9 +89,10 @@ type Utility interface { // LogicalCloudClient implements the LogicalCloudManager // It will also be used to maintain some localized state type LogicalCloudClient struct { - storeName string - tagMeta string - util Utility + storeName string + tagMeta string + tagContext string + util Utility } // Added for unit testing; implements Utility interface @@ -227,6 +230,33 @@ func (v *LogicalCloudClient) Update(project, logicalCloudName string, c LogicalC return c, nil } +// GetClusterContext returns the AppContext for corresponding provider and name +func (v *LogicalCloudClient) GetLogicalCloudContext(name string) (appcontext.AppContext, string, error) { + //Construct key and tag to select the entry + key := LogicalCloudKey{ + LogicalCloudName: name, + Project: "test-project", // FIXME(igordc): temporary, need to do some rework in the LC structs + } + + value, err := db.DBconn.Find(v.storeName, key, v.tagContext) + if err != nil { + return appcontext.AppContext{}, "", pkgerrors.Wrap(err, "Get Logical Cloud Context") + } + + //value is a byte array + if value != nil { + ctxVal := string(value[0]) + var lcc appcontext.AppContext + _, err = lcc.LoadAppContext(ctxVal) + if err != nil { + return appcontext.AppContext{}, "", pkgerrors.Wrap(err, "Reinitializing Logical Cloud AppContext") + } + return lcc, ctxVal, nil + } + + return appcontext.AppContext{}, "", pkgerrors.New("Error getting Logical Cloud AppContext") +} + func (d DBService) DBInsert(storeName string, key db.Key, query interface{}, meta string, c interface{}) error { err := db.DBconn.Insert(storeName, key, nil, meta, c) |