X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fxapp%2Fsubscription.go;h=01e351f1a89fdb8f67a8ccabff201fb24b6629d9;hb=40bc000e6cafe3a7eea32e4361268574050c12c4;hp=a7e7a3ca5a1f863ad00f492447c2c25cf1eeb385;hpb=9ea6c7860300c299b9fe68caaf8aff61b3ec71d2;p=ric-plt%2Fxapp-frame.git diff --git a/pkg/xapp/subscription.go b/pkg/xapp/subscription.go index a7e7a3c..01e351f 100755 --- a/pkg/xapp/subscription.go +++ b/pkg/xapp/subscription.go @@ -23,15 +23,16 @@ import ( "bytes" "encoding/json" "fmt" + "io/ioutil" + "net/http" + "os" + "time" + "github.com/go-openapi/loads" httptransport "github.com/go-openapi/runtime/client" "github.com/go-openapi/runtime/middleware" "github.com/go-openapi/strfmt" "github.com/spf13/viper" - "io/ioutil" - "net/http" - "os" - "time" 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" @@ -43,9 +44,9 @@ import ( "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/common" ) -type SubscriptionHandler func(interface{}) (*models.SubscriptionResponse, error) +type SubscriptionHandler func(interface{}) (*models.SubscriptionResponse, int) type SubscriptionQueryHandler func() (models.SubscriptionList, error) -type SubscriptionDeleteHandler func(string) error +type SubscriptionDeleteHandler func(string) int type SubscriptionResponseCallback func(*apimodel.SubscriptionResponse) type Subscriber struct { @@ -119,19 +120,31 @@ func (r *Subscriber) Listen(createSubscription SubscriptionHandler, getSubscript // Subscription: Subscribe api.CommonSubscribeHandler = common.SubscribeHandlerFunc( func(params common.SubscribeParams) middleware.Responder { - if resp, err := createSubscription(params.SubscriptionParams); err == nil { - return common.NewSubscribeCreated().WithPayload(resp) + Logger.Error("Subscribe: Params=%+v", params.SubscriptionParams) + resp, retCode := createSubscription(params.SubscriptionParams) + if retCode != common.SubscribeCreatedCode { + if retCode == common.SubscribeBadRequestCode { + return common.NewSubscribeBadRequest() + } else { + return common.NewSubscribeInternalServerError() + } } - return common.NewSubscribeInternalServerError() + return common.NewSubscribeCreated().WithPayload(resp) }) // Subscription: Unsubscribe api.CommonUnsubscribeHandler = common.UnsubscribeHandlerFunc( func(p common.UnsubscribeParams) middleware.Responder { - if err := delSubscription(p.SubscriptionID); err == nil { - return common.NewUnsubscribeNoContent() + Logger.Error("Unsubscribe: SubscriptionID=%+v", p.SubscriptionID) + retCode := delSubscription(p.SubscriptionID) + if retCode != common.UnsubscribeNoContentCode { + if retCode == common.UnsubscribeBadRequestCode { + return common.NewUnsubscribeBadRequest() + } else { + return common.NewUnsubscribeInternalServerError() + } } - return common.NewUnsubscribeInternalServerError() + return common.NewUnsubscribeNoContent() }) server := restapi.NewServer(api) @@ -234,32 +247,3 @@ 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 -}*/