Orchestrator support for network intent updates 82/105982/5
authorEric Multanen <eric.w.multanen@intel.com>
Wed, 15 Apr 2020 03:47:35 +0000 (20:47 -0700)
committerEric Multanen <eric.w.multanen@intel.com>
Tue, 21 Apr 2020 17:44:46 +0000 (10:44 -0700)
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 <eric.w.multanen@intel.com>
Change-Id: Ifdc78488a1e86f43d6fe656c59675862c4818af5

src/orchestrator/pkg/appcontext/appcontext.go

index bad5fa4..17afda9 100644 (file)
@@ -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)