X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Ftracker.go;h=df3d56e4bf4685feb98f8ee5bad7660c8ad99fd9;hb=HEAD;hp=c16a76a33fca9d995ff6b9583df4030446a098f5;hpb=422d018f94aedd9f4c001176b5ff06c786de28eb;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/tracker.go b/pkg/control/tracker.go index c16a76a..df3d56e 100644 --- a/pkg/control/tracker.go +++ b/pkg/control/tracker.go @@ -21,6 +21,7 @@ package control import ( "fmt" + "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" "sync" ) @@ -30,74 +31,78 @@ import ( //----------------------------------------------------------------------------- type Tracker struct { mutex sync.Mutex - transactionXappTable map[TransactionXappKey]*Transaction + transactionXappTable map[TransactionXappKey]*TransactionXapp transSeq uint64 } func (t *Tracker) Init() { - t.transactionXappTable = make(map[TransactionXappKey]*Transaction) + t.transactionXappTable = make(map[TransactionXappKey]*TransactionXapp) } -func (t *Tracker) NewTransactionFromSkel(transSkel *Transaction) *Transaction { +func (t *Tracker) initTransaction(transBase *Transaction) { t.mutex.Lock() defer t.mutex.Unlock() - trans := transSkel - if trans == nil { - trans = &Transaction{} - } - trans.EventChan = make(chan interface{}) - trans.tracker = t - trans.Seq = t.transSeq + transBase.EventChan = make(chan interface{}) + transBase.tracker = t + transBase.Seq = t.transSeq t.transSeq++ - xapp.Logger.Debug("Transaction: Create %s", trans.String()) +} + +func (t *Tracker) NewSubsTransaction(subs *Subscription) *TransactionSubs { + trans := &TransactionSubs{} + trans.Meid = subs.GetMeid() + t.initTransaction(&trans.Transaction) + xapp.Logger.Debug("CREATE %s", trans.String()) return trans } -func (t *Tracker) NewTransaction(meid *xapp.RMRMeid) *Transaction { - trans := &Transaction{} +func (t *Tracker) NewXappTransaction( + endpoint *xapp.RmrEndpoint, + xid string, + requestId e2ap.RequestId, + meid *xapp.RMRMeid) *TransactionXapp { + + trans := &TransactionXapp{} + trans.XappKey = &TransactionXappKey{requestId.Id, *endpoint, xid} trans.Meid = meid - trans = t.NewTransactionFromSkel(trans) + trans.RequestId = requestId + t.initTransaction(&trans.Transaction) + xapp.Logger.Debug("CREATE %s", trans.String()) return trans } -func (t *Tracker) TrackTransaction( - endpoint *RmrEndpoint, - xid string, - meid *xapp.RMRMeid) (*Transaction, error) { +func (t *Tracker) Track(trans *TransactionXapp) error { - if endpoint == nil { - err := fmt.Errorf("Tracker: No valid endpoint given") - return nil, err + if trans.GetEndpoint() == nil { + err := fmt.Errorf("Tracker: No valid endpoint given in %s", trans.String()) + return err } - trans := &Transaction{} - trans.XappKey = &TransactionXappKey{*endpoint, xid} - trans.Meid = meid - trans = t.NewTransactionFromSkel(trans) - t.mutex.Lock() defer t.mutex.Unlock() - if othtrans, ok := t.transactionXappTable[*trans.XappKey]; ok { - err := fmt.Errorf("Tracker: %s is ongoing, %s not created ", othtrans, trans) - return nil, err + theKey := *trans.XappKey + + if othtrans, ok := t.transactionXappTable[theKey]; ok { + err := fmt.Errorf("Tracker: %s is ongoing, not tracking %s", othtrans, trans) + return err } trans.tracker = t - t.transactionXappTable[*trans.XappKey] = trans - xapp.Logger.Debug("Tracker: Add %s", trans.String()) + t.transactionXappTable[theKey] = trans + xapp.Logger.Debug("Tracker: Append %s", trans.String()) //xapp.Logger.Debug("Tracker: transtable=%v", t.transactionXappTable) - return trans, nil + return nil } -func (t *Tracker) UnTrackTransaction(xappKey TransactionXappKey) (*Transaction, error) { +func (t *Tracker) UnTrackTransaction(xappKey TransactionXappKey) (*TransactionXapp, error) { t.mutex.Lock() defer t.mutex.Unlock() if trans, ok2 := t.transactionXappTable[xappKey]; ok2 { - xapp.Logger.Debug("Tracker: Delete %s", trans.String()) + xapp.Logger.Debug("Tracker: Remove %s", trans.String()) delete(t.transactionXappTable, xappKey) //xapp.Logger.Debug("Tracker: transtable=%v", t.transactionXappTable) return trans, nil } - return nil, fmt.Errorf("Tracker: No record %s", xappKey) + return nil, fmt.Errorf("Tracker: No record %v", xappKey) }