From: Eric Multanen Date: Wed, 15 Apr 2020 03:47:35 +0000 (-0700) Subject: Orchestrator support for network intent updates X-Git-Tag: 0.6.0~13^2 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=223e6b9e99951d9ee364861c8d35109531dada09;p=multicloud%2Fk8s.git Orchestrator support for network intent updates Adds support code in orchestrator for handling updates to app context resources when ncm handles network intents. Add a get cluster names call to the app context Issue-ID: MULTICLOUD-1029 Signed-off-by: Eric Multanen Change-Id: Ifdc78488a1e86f43d6fe656c59675862c4818af5 --- diff --git a/src/orchestrator/pkg/appcontext/appcontext.go b/src/orchestrator/pkg/appcontext/appcontext.go index bad5fa47..17afda9e 100644 --- a/src/orchestrator/pkg/appcontext/appcontext.go +++ b/src/orchestrator/pkg/appcontext/appcontext.go @@ -18,6 +18,8 @@ package appcontext import ( "fmt" + "strings" + "github.com/onap/multicloud-k8s/src/orchestrator/pkg/rtcontext" pkgerrors "github.com/pkg/errors" ) @@ -160,6 +162,36 @@ func (ac *AppContext) GetClusterHandle(appname string, clustername string) (inte return nil, pkgerrors.Errorf("No handle was found for the given cluster") } +//Returns a list of all clusters for a given app +func (ac *AppContext) GetClusterNames(appname string) ([]string, error) { + if appname == "" { + return nil, pkgerrors.Errorf("Not a valid run time context app name") + } + + rh, err := ac.rtc.RtcGet() + if err != nil { + return nil, err + } + + prefix := fmt.Sprintf("%v", rh) + "app/" + appname + "/cluster/" + hs, err := ac.rtc.RtcGetHandles(prefix) + if err != nil { + return nil, pkgerrors.Errorf("Error getting handles for %v", prefix) + } + var cs []string + for _, h := range hs { + hstr := fmt.Sprintf("%v", h) + ks := strings.Split(hstr, prefix) + for _, k := range ks { + ck := strings.Split(k, "/") + if len(ck) == 2 && ck[1] == "" { + cs = append(cs, ck[0]) + } + } + } + return cs, nil +} + //Add resource under app and cluster func (ac *AppContext) AddResource(handle interface{}, resname string, value interface{}) (interface{}, error) { h, err := ac.rtc.RtcAddResource(handle, resname, value)