X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fxapp%2Fsubscription.go;h=bf140c4ce9aef551bada531e22d2a1d705baa612;hb=refs%2Fchanges%2F89%2F5689%2F4;hp=cf8dc04a57c723c47d0e21a600617f62b4d3aaca;hpb=5953f7e372df54c71f526e9519e8eb0ee7ee6f72;p=ric-plt%2Fxapp-frame.git diff --git a/pkg/xapp/subscription.go b/pkg/xapp/subscription.go index cf8dc04..bf140c4 100755 --- a/pkg/xapp/subscription.go +++ b/pkg/xapp/subscription.go @@ -29,9 +29,11 @@ import ( "github.com/go-openapi/strfmt" "github.com/spf13/viper" "io/ioutil" + "net" "net/http" - "strings" + "os" "time" + //"errors" apiclient "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/clientapi" apicommon "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/clientapi/common" @@ -46,6 +48,7 @@ import ( "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/policy" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/query" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/report" + //"gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/xapp" ) type SubscriptionHandler func(models.SubscriptionType, interface{}) (*models.SubscriptionResponse, error) @@ -66,7 +69,11 @@ type Subscriber struct { func NewSubscriber(host string, timo int) *Subscriber { if host == "" { - host = "service-ricplt-submgr-http:8088" + pltnamespace := os.Getenv("PLT_NAMESPACE") + if pltnamespace == "" { + pltnamespace = "ricplt" + } + host = fmt.Sprintf("service-%s-submgr-http.%s:8088", pltnamespace, pltnamespace) } if timo == 0 { @@ -144,6 +151,16 @@ func (r *Subscriber) Listen(createSubscription SubscriptionHandler, getSubscript return common.NewUnsubscribeInternalServerError() }) + // XApp: Get Config + /*api.XappGetXappConfigListHandler = xapp.GetXappConfigListHandlerFunc( + func(p xapp.GetXappConfigListParams) middleware.Responder { + Logger.Info("Hitting xapp config") + if resp,err := r.getXappConfig(); err == nil { + return xapp.NewGetXappConfigListOK().WithPayload(resp) + } + return xapp.NewGetXappConfigListInternalServerError() + })*/ + server := restapi.NewServer(api) defer server.Shutdown() server.Host = r.localAddr @@ -164,8 +181,9 @@ func (r *Subscriber) Notify(resp *models.SubscriptionResponse, clientEndpoint st return err } - port := strings.Split(viper.GetString("local.host"), ":")[1] - clientUrl := fmt.Sprintf("http://%s:%s%s", clientEndpoint, port, r.clientUrl) + ep, _, _ := net.SplitHostPort(clientEndpoint) + _, port, _ := net.SplitHostPort(fmt.Sprintf(":%d", GetPortData("http").Port)) + clientUrl := fmt.Sprintf("http://%s:%s%s", ep, port, r.clientUrl) retries := viper.GetInt("subscription.retryCount") if retries == 0 { @@ -256,3 +274,32 @@ func (r *Subscriber) QuerySubscriptions() (models.SubscriptionList, error) { func (r *Subscriber) CreateTransport() *apiclient.RICSubscription { return apiclient.New(httptransport.New(r.remoteHost, r.remoteUrl, r.remoteProt), strfmt.Default) } + +/*func (r *Subscriber) getXappConfig() (appconfig models.XappConfigList, err error) { + + Logger.Error("Inside getXappConfig") + + var metadata models.ConfigMetadata + var xappconfig models.XAppConfig + name := viper.GetString("name") + configtype := "json" + metadata.XappName = &name + metadata.ConfigType = &configtype + + configFile, err := os.Open("/opt/ric/config/config-file.json") + if err != nil { + Logger.Error("Cannot open config file: %v", err) + return nil,errors.New("Could Not parse the config file") + } + + body, err := ioutil.ReadAll(configFile) + + defer configFile.Close() + + xappconfig.Metadata = &metadata + xappconfig.Config = body + + appconfig = append(appconfig,&xappconfig) + + return appconfig,nil +}*/