X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Ftracker.go;h=869e8ca66ed590319fae39582e9897931168aa67;hb=e406a34d5547107533e65ddfbb2074e96d77b4b3;hp=9b984a38799c48b36f338efb18a99a1b1c151879;hpb=1a50344b88201d4620b74d50d658a51117173636;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/tracker.go b/pkg/control/tracker.go index 9b984a3..869e8ca 100644 --- a/pkg/control/tracker.go +++ b/pkg/control/tracker.go @@ -24,80 +24,51 @@ import ( "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 - } - t.transactionTable[key] = xact - return nil -} +func (t *Tracker) TrackTransaction(endpoint RmrEndpoint, params *RMRParams, respReceived bool, forwardRespToXapp bool) (*Transaction, error) { -/* -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, + Mtype: params.Mtype, + Xid: params.Xid, + OrigParams: params, + 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, params.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) }