summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/orchestrator/pkg/appcontext/appcontext.go32
1 files changed, 32 insertions, 0 deletions
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)