"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"
"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 {
api.CommonSubscribeHandler = common.SubscribeHandlerFunc(
func(params common.SubscribeParams) middleware.Responder {
Logger.Error("Subscribe: Params=%+v", params.SubscriptionParams)
- if resp, err := createSubscription(params.SubscriptionParams); err == nil {
- return common.NewSubscribeCreated().WithPayload(resp)
+ 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 {
Logger.Error("Unsubscribe: SubscriptionID=%+v", p.SubscriptionID)
- if err := delSubscription(p.SubscriptionID); err == nil {
- return common.NewUnsubscribeNoContent()
+ 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)
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
-}*/