X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Ftracker.go;h=11d2cf7784b001de15295694f38b12565c5f40c2;hb=662f68d35c10fa67382235a20e1e08c50359989a;hp=9b984a38799c48b36f338efb18a99a1b1c151879;hpb=1a50344b88201d4620b74d50d658a51117173636;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/tracker.go b/pkg/control/tracker.go index 9b984a3..11d2cf7 100644 --- a/pkg/control/tracker.go +++ b/pkg/control/tracker.go @@ -21,83 +21,64 @@ package control import ( "fmt" + "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" "sync" ) -/* -Implements a record of ongoing transactions and helper functions to CRUD the records. -*/ +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- type Tracker struct { - transactionTable map[TransactionKey]Transaction - mutex sync.Mutex + mutex sync.Mutex + transactionXappTable map[TransactionXappKey]*Transaction } func (t *Tracker) Init() { - t.transactionTable = make(map[TransactionKey]Transaction) + t.transactionXappTable = make(map[TransactionXappKey]*Transaction) } -/* -Checks if a tranascation with similar type has been ongoing. If not then creates one. -Returns error if there is similar transatcion ongoing. -*/ -func (t *Tracker) TrackTransaction(key TransactionKey, xact Transaction) error { - t.mutex.Lock() - defer t.mutex.Unlock() - if _, ok := t.transactionTable[key]; ok { - // TODO: Implement merge related check here. If the key is same but the value is different. - err := fmt.Errorf("transaction tracker: Similar transaction with sub id %d and type %s is ongoing", key.SubID, key.transType) - return err +func (t *Tracker) TrackTransaction( + endpoint *RmrEndpoint, + xid string, + meid *xapp.RMRMeid, + respReceived bool, + forwardRespToXapp bool) (*Transaction, error) { + + if endpoint == nil { + err := fmt.Errorf("Tracker: No valid endpoint given") + return nil, err } - t.transactionTable[key] = xact - return nil -} -/* -Retreives the transaction table entry for the given request. -Returns error in case the transaction cannot be found. -*/ -func (t *Tracker) UpdateTransaction(SubID uint16, transType Action, xact Transaction) error { - key := TransactionKey{SubID, transType} - t.mutex.Lock() - defer t.mutex.Unlock() - if _, ok := t.transactionTable[key]; ok { - // TODO: Implement merge related check here. If the key is same but the value is different. - err := fmt.Errorf("transaction tracker: Similar transaction with sub id %d and type %v is ongoing", key.SubID, key.transType) - return err + trans := &Transaction{ + tracker: nil, + Subs: nil, + RmrEndpoint: *endpoint, + Xid: xid, + Meid: meid, + RespReceived: respReceived, + ForwardRespToXapp: forwardRespToXapp, } - t.transactionTable[key] = xact - return nil -} -/* -Retreives the transaction table entry for the given request. -Returns error in case the transaction cannot be found. -*/ -func (t *Tracker) RetriveTransaction(subID uint16, act Action) (Transaction, error) { - key := TransactionKey{subID, act} t.mutex.Lock() defer t.mutex.Unlock() - var xact Transaction - if xact, ok := t.transactionTable[key]; ok { - return xact, nil + + xappkey := TransactionXappKey{*endpoint, xid} + if _, ok := t.transactionXappTable[xappkey]; ok { + err := fmt.Errorf("Tracker: Similar transaction with xappkey %s is ongoing, transaction %s not created ", xappkey, trans) + return nil, err } - err := fmt.Errorf("transaction record for Subscription ID %d and action %s does not exist", subID, act) - return xact, err + + trans.tracker = t + t.transactionXappTable[xappkey] = trans + return trans, nil } -/* -Deletes the transaction table entry for the given request and returns the deleted xapp's address and port for reference. -Returns error in case the transaction cannot be found. -*/ -func (t *Tracker) completeTransaction(subID uint16, act Action) (Transaction, error) { - key := TransactionKey{subID, act} - var emptyTransaction Transaction +func (t *Tracker) UnTrackTransaction(xappKey TransactionXappKey) (*Transaction, error) { t.mutex.Lock() defer t.mutex.Unlock() - if xact, ok := t.transactionTable[key]; ok { - delete(t.transactionTable, key) - return xact, nil + if trans, ok2 := t.transactionXappTable[xappKey]; ok2 { + delete(t.transactionXappTable, xappKey) + return trans, nil } - err := fmt.Errorf("transaction record for Subscription ID %d and action %s does not exist", subID, act) - return emptyTransaction, err + return nil, fmt.Errorf("Tracker: No record for xappkey %s", xappKey) }