2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
24 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
25 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
34 transactionXappTable map[TransactionXappKey]*TransactionXapp
38 func (t *Tracker) Init() {
39 t.transactionXappTable = make(map[TransactionXappKey]*TransactionXapp)
42 func (t *Tracker) initTransaction(transBase *Transaction) {
44 defer t.mutex.Unlock()
45 transBase.EventChan = make(chan interface{})
47 transBase.Seq = t.transSeq
51 func (t *Tracker) NewSubsTransaction(subs *Subscription) *TransactionSubs {
52 trans := &TransactionSubs{}
53 trans.Meid = subs.GetMeid()
54 t.initTransaction(&trans.Transaction)
55 xapp.Logger.Debug("CREATE %s", trans.String())
59 func (t *Tracker) NewXappTransaction(
60 endpoint *xapp.RmrEndpoint,
62 requestId e2ap.RequestId,
63 meid *xapp.RMRMeid) *TransactionXapp {
65 trans := &TransactionXapp{}
66 trans.XappKey = &TransactionXappKey{requestId.Id, *endpoint, xid}
68 trans.RequestId = requestId
69 t.initTransaction(&trans.Transaction)
70 xapp.Logger.Debug("CREATE %s", trans.String())
74 func (t *Tracker) Track(trans *TransactionXapp) error {
76 if trans.GetEndpoint() == nil {
77 err := fmt.Errorf("Tracker: No valid endpoint given in %s", trans.String())
82 defer t.mutex.Unlock()
84 theKey := *trans.XappKey
86 if othtrans, ok := t.transactionXappTable[theKey]; ok {
87 err := fmt.Errorf("Tracker: %s is ongoing, not tracking %s", othtrans, trans)
92 t.transactionXappTable[theKey] = trans
93 xapp.Logger.Debug("Tracker: Append %s", trans.String())
94 //xapp.Logger.Debug("Tracker: transtable=%v", t.transactionXappTable)
98 func (t *Tracker) UnTrackTransaction(xappKey TransactionXappKey) (*TransactionXapp, error) {
100 defer t.mutex.Unlock()
101 if trans, ok2 := t.transactionXappTable[xappKey]; ok2 {
102 xapp.Logger.Debug("Tracker: Remove %s", trans.String())
103 delete(t.transactionXappTable, xappKey)
104 //xapp.Logger.Debug("Tracker: transtable=%v", t.transactionXappTable)
107 return nil, fmt.Errorf("Tracker: No record %v", xappKey)