+
+func CreateSubReq(restUrl string, restPort string) *appmgr_model.SubscriptionRequest {
+ // TODO: parameterize function
+ subData := appmgr_model.SubscriptionData{
+ TargetURL: swag.String(restUrl + ":" + restPort + "/ric/v1/handles/xapp-handle/"),
+ EventType: appmgr_model.EventTypeAll,
+ MaxRetries: swag.Int64(5),
+ RetryTimer: swag.Int64(10),
+ }
+
+ subReq := appmgr_model.SubscriptionRequest{
+ Data: &subData,
+ }
+
+ return &subReq
+}
+
+func PostSubReq(xmUrl string, nbiif string) error {
+ // setting up POST request to Xapp Manager
+ appmgrUrl, err := url.Parse(xmUrl)
+ if err != nil {
+ xapp.Logger.Error("Invalid XApp manager url/hostname: " + err.Error())
+ return err
+ }
+ nbiifUrl, err := url.Parse(nbiif)
+ if err != nil {
+ xapp.Logger.Error("Invalid NBI address/port: " + err.Error())
+ return err
+ }
+ transport := httptransport.New(appmgrUrl.Hostname()+":"+appmgrUrl.Port(), "/ric/v1", []string{"http"})
+ client := apiclient.New(transport, strfmt.Default)
+ addSubParams := operations.NewAddSubscriptionParamsWithTimeout(10 * time.Second)
+ // create sub req with rest url and port
+ subReq := CreateSubReq(nbiifUrl.Scheme+"://"+nbiifUrl.Hostname(), nbiifUrl.Port())
+ resp, postErr := client.Operations.AddSubscription(addSubParams.WithSubscriptionRequest(subReq))
+ if postErr != nil {
+ xapp.Logger.Error("POST unsuccessful:" + postErr.Error())
+ return postErr
+ } else {
+ // TODO: use the received ID
+ xapp.Logger.Info("POST received: " + string(resp.Payload.ID))
+ return nil
+ }
+}