From 8c0cc1278cc4d84863b076b2014b9bc9d8805218 Mon Sep 17 00:00:00 2001 From: "Igor D.C" Date: Fri, 25 Sep 2020 22:31:11 +0000 Subject: Implement Terminate operation in DCM Also makes minor changes to non-terminate code as a side-effect of supporting the new Terminate operation (such as including tagContext in the LogicalCloudClient implementation of LogicalCloudManager interface). These changes are/will also be leveraged by other operations. Issue-ID: MULTICLOUD-1143 Change-Id: Idbd2ec9f6cf0e5584a0f51cf4c16144db56d9fa0 Signed-off-by: Igor D.C --- src/dcm/pkg/module/logicalcloud.go | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'src/dcm/pkg/module/logicalcloud.go') 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) -- cgit 1.2.3-korg