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).
+
==================================================================================
*/
/*
"encoding/json"
"errors"
"fmt"
+ "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
"github.com/go-openapi/loads"
"github.com/go-openapi/runtime/middleware"
"net/url"
// Drain the channel as we are only looking for the latest value until
// xapp manager sends all xapp data with every request.
length := len(dataChannel)
- //rtmgr.Logger.Info(length)
+ //xapp.Logger.Info(length)
for i := 0; i <= length; i++ {
- rtmgr.Logger.Info("data received")
+ xapp.Logger.Info("data received")
// If no data received from the REST, it blocks.
xappData = <-dataChannel
}
err := json.Unmarshal([]byte(xappData.XApps), &xapps)
return &xapps, err
} else {
- rtmgr.Logger.Info("No data")
+ xapp.Logger.Info("No data")
}
- rtmgr.Logger.Debug("Nothing received on the Http interface")
+ xapp.Logger.Debug("Nothing received on the Http interface")
return nil, nil
}
func provideXappHandleHandlerImpl(datach chan<- *models.XappCallbackData, data *models.XappCallbackData) error {
if data != nil {
- rtmgr.Logger.Debug("Received callback data")
+ xapp.Logger.Debug("Received callback data")
}
err := validateXappCallbackData(data)
if err != nil {
- rtmgr.Logger.Warn("XApp callback data validation failed: " + err.Error())
+ xapp.Logger.Warn("XApp callback data validation failed: " + err.Error())
return err
} else {
datach <- data
func provideXappSubscriptionHandleImpl(subchan chan<- *models.XappSubscriptionData,
data *models.XappSubscriptionData) error {
- rtmgr.Logger.Debug("Invoked provideXappSubscriptionHandleImpl")
+ xapp.Logger.Debug("Invoked provideXappSubscriptionHandleImpl")
err := validateXappSubscriptionData(data)
if err != nil {
- rtmgr.Logger.Error(err.Error())
+ xapp.Logger.Error(err.Error())
return err
}
subchan <- data
//var val = string(*data.Address + ":" + strconv.Itoa(int(*data.Port)))
- rtmgr.Logger.Debug("Endpoints: %v", rtmgr.Eps)
+ xapp.Logger.Debug("Endpoints: %v", rtmgr.Eps)
return nil
}
func deleteXappSubscriptionHandleImpl(subdelchan chan<- *models.XappSubscriptionData,
data *models.XappSubscriptionData) error {
- rtmgr.Logger.Debug("Invoked deleteXappSubscriptionHandleImpl")
+ xapp.Logger.Debug("Invoked deleteXappSubscriptionHandleImpl")
err := validateXappSubscriptionData(data)
if err != nil {
- rtmgr.Logger.Error(err.Error())
+ xapp.Logger.Error(err.Error())
return err
}
if !subscriptionExists(data) {
- rtmgr.Logger.Warn("subscription not found: %d", *data.SubscriptionID)
+ xapp.Logger.Warn("subscription not found: %d", *data.SubscriptionID)
err := fmt.Errorf("subscription not found: %d", *data.SubscriptionID)
return err
}
swaggerSpec, err := loads.Embedded(restapi.SwaggerJSON, restapi.FlatSwaggerJSON)
if err != nil {
//log.Fatalln(err)
- rtmgr.Logger.Error(err.Error())
+ xapp.Logger.Error(err.Error())
os.Exit(1)
}
nbiUrl, err := url.Parse(*nbiif)
if err != nil {
- rtmgr.Logger.Error(err.Error())
+ xapp.Logger.Error(err.Error())
os.Exit(1)
}
api := operations.NewRoutingManagerAPI(swaggerSpec)
server.Port, err = strconv.Atoi(nbiUrl.Port())
if err != nil {
- rtmgr.Logger.Error("Invalid NBI RestAPI port")
+ xapp.Logger.Error("Invalid NBI RestAPI port")
os.Exit(1)
}
server.Host = "0.0.0.0"
// set handlers
api.HandleProvideXappHandleHandler = handle.ProvideXappHandleHandlerFunc(
func(params handle.ProvideXappHandleParams) middleware.Responder {
- rtmgr.Logger.Info("Data received on Http interface")
+ xapp.Logger.Info("Data received on Http interface")
err := provideXappHandleHandlerImpl(datach, params.XappCallbackData)
if err != nil {
- rtmgr.Logger.Error("Invalid XApp callback data: " + err.Error())
+ xapp.Logger.Error("Invalid XApp callback data: " + err.Error())
return handle.NewProvideXappHandleBadRequest()
} else {
return handle.NewGetHandlesOK()
if err != nil {
return handle.NewProvideXappSubscriptionHandleBadRequest()
} else {
+ //Delay the reponse as add subscription channel needs to update sdl and then sbi sends updated routes to all endpoints
+ time.Sleep(1 * time.Second)
return handle.NewGetHandlesOK()
}
})
if err != nil {
return handle.NewDeleteXappSubscriptionHandleNoContent()
} else {
+ //Delay the reponse as delete subscription channel needs to update sdl and then sbi sends updated routes to all endpoints
+ time.Sleep(1 * time.Second)
return handle.NewGetHandlesOK()
}
})
// start to serve API
- rtmgr.Logger.Info("Starting the HTTP Rest service")
+ xapp.Logger.Info("Starting the HTTP Rest service")
if err := server.Serve(); err != nil {
- rtmgr.Logger.Error(err.Error())
+ xapp.Logger.Error(err.Error())
}
}
func httpGetXApps(xmurl string) (*[]rtmgr.XApp, error) {
- rtmgr.Logger.Info("Invoked httpgetter.fetchXappList: " + xmurl)
+ xapp.Logger.Info("Invoked httprestful.httpGetXApps: " + xmurl)
r, err := myClient.Get(xmurl)
if err != nil {
return nil, err
defer r.Body.Close()
if r.StatusCode == 200 {
- rtmgr.Logger.Debug("http client raw response: %v", r)
+ xapp.Logger.Debug("http client raw response: %v", r)
var xapps []rtmgr.XApp
err = json.NewDecoder(r.Body).Decode(&xapps)
if err != nil {
- rtmgr.Logger.Warn("Json decode failed: " + err.Error())
+ xapp.Logger.Warn("Json decode failed: " + err.Error())
}
- rtmgr.Logger.Info("HTTP GET: OK")
- rtmgr.Logger.Debug("httpgetter.fetchXappList returns: %v", xapps)
+ xapp.Logger.Info("HTTP GET: OK")
+ xapp.Logger.Debug("httprestful.httpGetXApps returns: %v", xapps)
return &xapps, err
}
- rtmgr.Logger.Warn("httpgetter got an unexpected http status code: %v", r.StatusCode)
+ xapp.Logger.Warn("httprestful got an unexpected http status code: %v", r.StatusCode)
return nil, nil
}
if xappData != nil && err == nil {
pcData, confErr := rtmgr.GetPlatformComponents(configfile)
if confErr != nil {
- rtmgr.Logger.Error(confErr.Error())
+ xapp.Logger.Error(confErr.Error())
return confErr
}
- rtmgr.Logger.Info("Recieved intial xapp data and platform data, writing into SDL.")
+ xapp.Logger.Info("Recieved intial xapp data and platform data, writing into SDL.")
// Combine the xapps data and platform data before writing to the SDL
ricData := &rtmgr.RicComponents{XApps: *xappData, Pcs: *pcData}
writeErr := sdlEngine.WriteAll(fileName, ricData)
if writeErr != nil {
- rtmgr.Logger.Error(writeErr.Error())
+ xapp.Logger.Error(writeErr.Error())
}
// post subscription req to appmgr
readErr = PostSubReq(xmurl, nbiif)
} else if err == nil {
readErr = errors.New("unexpected HTTP status code")
} else {
- rtmgr.Logger.Warn("cannot get xapp data due to: " + err.Error())
+ xapp.Logger.Warn("cannot get xapp data due to: " + err.Error())
readErr = err
}
}
sdlEngine sdl.Engine, rpeEngine rpe.Engine, triggerSBI chan<- bool) error {
err := r.RetrieveStartupData(xmurl, nbiif, fileName, configfile, sdlEngine)
if err != nil {
- rtmgr.Logger.Error("Exiting as nbi failed to get the initial startup data from the xapp manager: " + err.Error())
+ xapp.Logger.Error("Exiting as nbi failed to get the initial startup data from the xapp manager: " + err.Error())
return err
}
datach := make(chan *models.XappCallbackData, 10)
subschan := make(chan *models.XappSubscriptionData, 10)
subdelchan := make(chan *models.XappSubscriptionData, 10)
- rtmgr.Logger.Info("Launching Rest Http service")
+ xapp.Logger.Info("Launching Rest Http service")
go func() {
r.LaunchRest(&nbiif, datach, subschan, subdelchan)
}()
for {
data, err := r.RecvXappCallbackData(datach)
if err != nil {
- rtmgr.Logger.Error("cannot get data from rest api dute to: " + err.Error())
+ xapp.Logger.Error("cannot get data from rest api dute to: " + err.Error())
} else if data != nil {
- sdlEngine.WriteXApps(fileName, data)
- triggerSBI <- true
+ xapp.Logger.Debug("Fetching all xApps deployed in xApp Manager through GET operation.")
+ alldata, err1 := httpGetXApps(xmurl)
+ if alldata != nil && err1 == nil {
+ sdlEngine.WriteXApps(fileName, alldata)
+ triggerSBI <- true
+ }
}
}
}()
go func() {
for {
data := <-subschan
- rtmgr.Logger.Debug("received XApp subscription data")
+ xapp.Logger.Debug("received XApp subscription data")
addSubscription(&rtmgr.Subs, data)
triggerSBI <- true
}
go func() {
for {
data := <-subdelchan
- rtmgr.Logger.Debug("received XApp subscription delete data")
+ xapp.Logger.Debug("received XApp subscription delete data")
delSubscription(&rtmgr.Subs, data)
triggerSBI <- true
}
sub := rtmgr.Subscription{SubID: *xappSubData.SubscriptionID, Fqdn: *xappSubData.Address, Port: *xappSubData.Port}
for _, elem := range *subs {
if elem == sub {
- rtmgr.Logger.Warn("rtmgr.addSubscription: Subscription already present: %v", elem)
+ xapp.Logger.Warn("rtmgr.addSubscription: Subscription already present: %v", elem)
b = true
}
}
}
func delSubscription(subs *rtmgr.SubscriptionList, xappSubData *models.XappSubscriptionData) bool {
- rtmgr.Logger.Debug("Deleteing the subscription from the subscriptions list")
+ xapp.Logger.Debug("Deleteing the subscription from the subscriptions list")
var present = false
sub := rtmgr.Subscription{SubID: *xappSubData.SubscriptionID, Fqdn: *xappSubData.Address, Port: *xappSubData.Port}
for i, elem := range *subs {
}
}
if present == false {
- rtmgr.Logger.Warn("rtmgr.delSubscription: Subscription = %v, not present in the existing subscriptions", xappSubData)
+ xapp.Logger.Warn("rtmgr.delSubscription: Subscription = %v, not present in the existing subscriptions", xappSubData)
}
return present
}