RICPLT-2979 SubReq go asn into use
[ric-plt/submgr.git] / pkg / control / tracker.go
index 0e6941d..75127a7 100644 (file)
@@ -22,96 +22,41 @@ package control
 import (
        "fmt"
        "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
-       "strconv"
        "sync"
 )
 
-//-----------------------------------------------------------------------------
-//
-//-----------------------------------------------------------------------------
-type TransactionXappKey struct {
-       RmrEndpoint
-       Xid string // xapp xid in req
-}
-
-func (key *TransactionXappKey) String() string {
-       return key.RmrEndpoint.String() + "/" + key.Xid
-}
-
-//-----------------------------------------------------------------------------
-//
-//-----------------------------------------------------------------------------
-type Transaction struct {
-       tracker           *Tracker // tracker instance
-       Subs              *Subscription
-       RmrEndpoint       RmrEndpoint
-       Xid               string          // xapp xid in req
-       OrigParams        *xapp.RMRParams // request orginal params
-       RespReceived      bool
-       ForwardRespToXapp bool
-       mutex             sync.Mutex
-}
-
-func (t *Transaction) String() string {
-       t.mutex.Lock()
-       defer t.mutex.Unlock()
-       var subId string = "?"
-       if t.Subs != nil {
-               subId = strconv.FormatUint(uint64(t.Subs.Seq), 10)
-       }
-       return subId + "/" + t.RmrEndpoint.String() + "/" + t.Xid
-}
-
-func (t *Transaction) CheckResponseReceived() bool {
-       t.mutex.Lock()
-       defer t.mutex.Unlock()
-       if t.RespReceived == false {
-               t.RespReceived = true
-               return false
-       }
-       return true
-}
-
-func (t *Transaction) RetryTransaction() {
-       t.mutex.Lock()
-       defer t.mutex.Unlock()
-       t.RespReceived = false
-}
-
-func (t *Transaction) Release() {
-       t.mutex.Lock()
-       defer t.mutex.Unlock()
-       if t.Subs != nil {
-               t.Subs.UnSetTransaction(t)
-       }
-       if t.tracker != nil {
-               xappkey := TransactionXappKey{t.RmrEndpoint, t.Xid}
-               t.tracker.UnTrackTransaction(xappkey)
-       }
-       t.Subs = nil
-       t.tracker = nil
-}
-
 //-----------------------------------------------------------------------------
 //
 //-----------------------------------------------------------------------------
 type Tracker struct {
-       transactionXappTable map[TransactionXappKey]*Transaction
        mutex                sync.Mutex
+       transactionXappTable map[TransactionXappKey]*Transaction
 }
 
 func (t *Tracker) Init() {
        t.transactionXappTable = make(map[TransactionXappKey]*Transaction)
 }
 
-func (t *Tracker) TrackTransaction(subs *Subscription, endpoint RmrEndpoint, params *xapp.RMRParams, respReceived bool, forwardRespToXapp bool) (*Transaction, error) {
+func (t *Tracker) TrackTransaction(
+       endpoint *RmrEndpoint,
+       mtype int,
+       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
+       }
 
        trans := &Transaction{
                tracker:           nil,
                Subs:              nil,
-               RmrEndpoint:       endpoint,
-               Xid:               params.Xid,
-               OrigParams:        params,
+               RmrEndpoint:       *endpoint,
+               Mtype:             mtype,
+               Xid:               xid,
+               Meid:              meid,
                RespReceived:      respReceived,
                ForwardRespToXapp: forwardRespToXapp,
        }
@@ -119,24 +64,12 @@ func (t *Tracker) TrackTransaction(subs *Subscription, endpoint RmrEndpoint, par
        t.mutex.Lock()
        defer t.mutex.Unlock()
 
-       xappkey := TransactionXappKey{endpoint, params.Xid}
+       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
        }
 
-       if subs.SetTransaction(trans) == false {
-               othTrans := subs.GetTransaction()
-               err := fmt.Errorf("Tracker: Subscription %s got already transaction ongoing: %s, transaction %s not created", subs, othTrans, trans)
-               return nil, err
-       }
-       trans.Subs = subs
-       if (trans.Subs.RmrEndpoint.Addr != trans.RmrEndpoint.Addr) || (trans.Subs.RmrEndpoint.Port != trans.RmrEndpoint.Port) {
-               err := fmt.Errorf("Tracker: Subscription endpoint %s mismatch with trans: %s", subs, trans)
-               trans.Subs.UnSetTransaction(nil)
-               return nil, err
-       }
-
        trans.tracker = t
        t.transactionXappTable[xappkey] = trans
        return trans, nil