X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Fcontrol.go;h=42c639b5e012ae39287b7a056b71cbd6d1529f9c;hb=d13ba63c1c237882202fc975d70ed5ad21a48fcf;hp=68688e2b6ed558bcfabec9cd0b6d61cdf1340ace;hpb=54838ed6fb79821c3711f92876993264d358f2c3;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/control.go b/pkg/control/control.go index 68688e2..42c639b 100755 --- a/pkg/control/control.go +++ b/pkg/control/control.go @@ -22,9 +22,6 @@ package control import ( "fmt" "net/http" - "os" - "strconv" - "strings" "sync" "time" @@ -35,7 +32,6 @@ import ( "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/gorilla/mux" "github.com/segmentio/ksuid" "github.com/spf13/viper" ) @@ -158,9 +154,19 @@ func NewControl() *Control { c.ReadConfigParameters("") // Register REST handler for testing support + xapp.Resource.InjectRoute("/ric/v1/symptomdata", c.SymptomDataHandler, "GET") xapp.Resource.InjectRoute("/ric/v1/test/{testId}", c.TestRestHandler, "POST") xapp.Resource.InjectRoute("/ric/v1/restsubscriptions", c.GetAllRestSubscriptions, "GET") - xapp.Resource.InjectRoute("/ric/v1/symptomdata", c.SymptomDataHandler, "GET") + + xapp.Resource.InjectRoute("/ric/v1/get_all_e2nodes", c.GetAllE2Nodes, "GET") + xapp.Resource.InjectRoute("/ric/v1/get_e2node_rest_subscriptions/{ranName}", c.GetAllE2NodeRestSubscriptions, "GET") + + xapp.Resource.InjectRoute("/ric/v1/get_all_xapps", c.GetAllXapps, "GET") + xapp.Resource.InjectRoute("/ric/v1/get_xapp_rest_restsubscriptions/{xappServiceName}", c.GetAllXappRestSubscriptions, "GET") + xapp.Resource.InjectRoute("/ric/v1/get_e2subscriptions/{restId}", c.GetE2Subscriptions, "GET") + + xapp.Resource.InjectRoute("/ric/v1/delete_all_e2node_subscriptions/{ranName}", c.DeleteAllE2nodeSubscriptions, "DELETE") + xapp.Resource.InjectRoute("/ric/v1/delete_all_xapp_subscriptions/{xappServiceName}", c.DeleteAllXappSubscriptions, "DELETE") if readSubsFromDb == "true" { // Read subscriptions from db @@ -180,10 +186,12 @@ func (c *Control) SymptomDataHandler(w http.ResponseWriter, r *http.Request) { //------------------------------------------------------------------- // //------------------------------------------------------------------- -func (c *Control) GetAllRestSubscriptions(w http.ResponseWriter, r *http.Request) { - xapp.Logger.Debug("GetAllRestSubscriptions() called") - response := c.registry.GetAllRestSubscriptions() - w.Write(response) +func (c *Control) RESTQueryHandler() (models.SubscriptionList, error) { + xapp.Logger.Debug("RESTQueryHandler() called") + + c.CntRecvMsg++ + + return c.registry.QueryHandler() } //------------------------------------------------------------------- @@ -202,7 +210,7 @@ func (c *Control) ReadE2Subscriptions() error { } else { c.registry.subIds = subIds c.registry.register = register - c.HandleUncompletedSubscriptions(register) + go c.HandleUncompletedSubscriptions(register) return nil } } @@ -357,7 +365,7 @@ func (c *Control) Run() { //------------------------------------------------------------------- // //------------------------------------------------------------------- -func (c *Control) GetOrCreateRestSubscription(p *models.SubscriptionParams, md5sum string, xAppRmrEndpoint string) (*RESTSubscription, string, error) { +func (c *Control) GetOrCreateRestSubscription(p *models.SubscriptionParams, md5sum string, xAppRmrEndpoint string, xAppServiceName string) (*RESTSubscription, string, error) { var restSubId string var restSubscription *RESTSubscription @@ -384,7 +392,7 @@ func (c *Control) GetOrCreateRestSubscription(p *models.SubscriptionParams, md5s if restSubscription == nil { restSubId = ksuid.New().String() - restSubscription = c.registry.CreateRESTSubscription(&restSubId, &xAppRmrEndpoint, p.Meid) + restSubscription = c.registry.CreateRESTSubscription(&restSubId, &xAppServiceName, &xAppRmrEndpoint, p.Meid) } } else { // Subscription contains REST subscription Id @@ -449,7 +457,7 @@ func (c *Control) RESTSubscriptionHandler(params interface{}) (*models.Subscript xapp.Logger.Error("Failed to generate md5sum from incoming request - %s", err.Error()) } - restSubscription, restSubId, err := c.GetOrCreateRestSubscription(p, md5sum, xAppRmrEndpoint) + restSubscription, restSubId, err := c.GetOrCreateRestSubscription(p, md5sum, xAppRmrEndpoint, p.ClientEndpoint.Host) if err != nil { xapp.Logger.Error("Subscription with id in REST request does not exist") return nil, common.SubscribeNotFoundCode @@ -836,50 +844,6 @@ func (c *Control) SubscriptionDeleteHandler(restSubId *string, endPoint *string, return xAppEventInstanceID, nil } -//------------------------------------------------------------------- -// -//------------------------------------------------------------------- -func (c *Control) RESTQueryHandler() (models.SubscriptionList, error) { - xapp.Logger.Debug("RESTQueryHandler() called") - - c.CntRecvMsg++ - - return c.registry.QueryHandler() -} - -func (c *Control) TestRestHandler(w http.ResponseWriter, r *http.Request) { - xapp.Logger.Debug("RESTTestRestHandler() called") - - pathParams := mux.Vars(r) - s := pathParams["testId"] - - // This can be used to delete single subscription from db - if contains := strings.Contains(s, "deletesubid="); contains == true { - var splits = strings.Split(s, "=") - if subId, err := strconv.ParseInt(splits[1], 10, 64); err == nil { - xapp.Logger.Debug("RemoveSubscriptionFromSdl() called. subId = %v", subId) - c.RemoveSubscriptionFromSdl(uint32(subId)) - return - } - } - - // This can be used to remove all subscriptions db from - if s == "emptydb" { - xapp.Logger.Debug("RemoveAllSubscriptionsFromSdl() called") - c.RemoveAllSubscriptionsFromSdl() - c.RemoveAllRESTSubscriptionsFromSdl() - return - } - - // This is meant to cause submgr's restart in testing - if s == "restart" { - xapp.Logger.Debug("os.Exit(1) called") - os.Exit(1) - } - - xapp.Logger.Debug("Unsupported rest command received %s", s) -} - //------------------------------------------------------------------- // //------------------------------------------------------------------- @@ -990,7 +954,6 @@ func (c *Control) handleXAPPSubscriptionRequest(params *xapp.RMRParams) { return } - //TODO handle subscription toward e2term inside AssignToSubscription / hide handleSubscriptionCreate in it? subs, _, err := c.registry.AssignToSubscription(trans, subReqMsg, c.ResetTestFlag, c, true) if err != nil { xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans)) @@ -1034,7 +997,6 @@ func (c *Control) wakeSubscriptionRequest(subs *Subscription, trans *Transaction } } xapp.Logger.Debug("XAPP-SubReq: failed %s", idstring(err, trans, subs)) - //c.registry.RemoveFromSubscription(subs, trans, 5*time.Second) } //------------------------------------------------------------------- @@ -1100,9 +1062,6 @@ func (c *Control) handleXAPPSubscriptionDeleteRequest(params *xapp.RMRParams) { c.UpdateCounter(cSubDelRespToXapp) c.rmrSendToXapp("", subs, trans) } - - //TODO handle subscription toward e2term insiged RemoveFromSubscription / hide handleSubscriptionDelete in it? - //c.registry.RemoveFromSubscription(subs, trans, 5*time.Second) } //------------------------------------------------------------------- @@ -1161,7 +1120,7 @@ func (c *Control) handleSubscriptionCreate(subs *Subscription, parentTrans *Tran c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans) } - //Now RemoveFromSubscription in here to avoid race conditions (mostly concerns delete) + // Now RemoveFromSubscription in here to avoid race conditions (mostly concerns delete) if valid == false { c.registry.RemoveFromSubscription(subs, parentTrans, waitRouteCleanupTime, c) } @@ -1191,9 +1150,8 @@ func (c *Control) handleSubscriptionDelete(subs *Subscription, parentTrans *Tran } else { subs.mutex.Unlock() } - //Now RemoveFromSubscription in here to avoid race conditions (mostly concerns delete) - // If parallel deletes ongoing both might pass earlier sendE2TSubscriptionDeleteRequest(...) if - // RemoveFromSubscription locates in caller side (now in handleXAPPSubscriptionDeleteRequest(...)) + + // Now RemoveFromSubscription in here to avoid race conditions (mostly concerns delete) c.registry.RemoveFromSubscription(subs, parentTrans, waitRouteCleanupTime, c) parentTrans.SendEvent(nil, 0) }