X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fnbi%2Fnbi.go;h=ddbf34739ba0839eddcb48a4ee29af5558b62f6c;hb=4101d1060980858538c5600af8d9ad7a258db107;hp=cb19e714d14bff070e15f8d9bf1c120adebb5995;hpb=871fa393844ce1b61b8d5218d27687d9fc05803a;p=ric-plt%2Frtmgr.git diff --git a/pkg/nbi/nbi.go b/pkg/nbi/nbi.go index cb19e71..ddbf347 100644 --- a/pkg/nbi/nbi.go +++ b/pkg/nbi/nbi.go @@ -14,6 +14,11 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + + + This source code is part of the near-RT RIC (RAN Intelligent Controller) + platform project (RICP). + ================================================================================== */ /* @@ -26,56 +31,89 @@ package nbi import ( "errors" - "fmt" - "rtmgr" + "net/url" + apiclient "routing-manager/pkg/appmgr_client" + "routing-manager/pkg/appmgr_client/operations" + "routing-manager/pkg/appmgr_model" + "time" + + "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" + httptransport "github.com/go-openapi/runtime/client" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" ) var ( - SupportedNbis = []*NbiEngineConfig{ - &NbiEngineConfig{ - NbiEngine{ - Name: "httpGetter", - Version: "v1", - Protocol: "http", - }, - batchFetch(fetchXappList), - true, - }, - &NbiEngineConfig{ - NbiEngine{ - Name: "httpRESTful", - Version: "v1", - Protocol: "http", - }, - batchFetch(nil), - false, + SupportedNbis = []*EngineConfig{ + { + Name: "httpGetter", + Version: "v1", + Protocol: "http", + Instance: NewHttpGetter(), + IsAvailable: true, }, - &NbiEngineConfig{ - NbiEngine{ - Name: "gRPC", - Version: "v1", - Protocol: "http2", - }, - batchFetch(nil), - false, + { + Name: "httpRESTful", + Version: "v1", + Protocol: "http", + Instance: NewHttpRestful(), + IsAvailable: true, }, } ) -func ListNbis() { - fmt.Printf("NBI:\n") +type Nbi struct { +} + +func GetNbi(nbiName string) (Engine, error) { for _, nbi := range SupportedNbis { - if nbi.IsAvailable { - rtmgr.Logger.Info(nbi.Engine.Name + "/" + nbi.Engine.Version) + if nbi.Name == nbiName && nbi.IsAvailable { + return nbi.Instance, nil } } + return nil, errors.New("NBI:" + nbiName + " is not supported or still not a available") } -func GetNbi(nbiName string) (*NbiEngineConfig, error) { - for _, nbi := range SupportedNbis { - if nbi.Engine.Name == nbiName && nbi.IsAvailable { - return nbi, nil - } +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 } - return nil, errors.New("NBI:" + nbiName + "is not supported or still not a available") }