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/xapp-frame/pkg/xapp"
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
33 transactionXappTable map[TransactionXappKey]*TransactionXapp
37 func (t *Tracker) Init() {
38 t.transactionXappTable = make(map[TransactionXappKey]*TransactionXapp)
41 func (t *Tracker) initTransaction(transBase *Transaction) {
43 defer t.mutex.Unlock()
44 transBase.EventChan = make(chan interface{})
46 transBase.Seq = t.transSeq
50 func (t *Tracker) NewSubsTransaction(subs *Subscription) *TransactionSubs {
51 trans := &TransactionSubs{}
52 trans.Meid = subs.GetMeid()
53 t.initTransaction(&trans.Transaction)
54 xapp.Logger.Debug("CREATE %s", trans.String())
58 func (t *Tracker) NewXappTransaction(
59 endpoint *xapp.RmrEndpoint,
62 meid *xapp.RMRMeid) *TransactionXapp {
64 trans := &TransactionXapp{}
65 trans.XappKey = &TransactionXappKey{*endpoint, xid}
68 t.initTransaction(&trans.Transaction)
69 xapp.Logger.Debug("CREATE %s", trans.String())
73 func (t *Tracker) Track(trans *TransactionXapp) error {
75 if trans.GetEndpoint() == nil {
76 err := fmt.Errorf("Tracker: No valid endpoint given in %s", trans.String())
81 defer t.mutex.Unlock()
83 theKey := *trans.XappKey
85 if othtrans, ok := t.transactionXappTable[theKey]; ok {
86 err := fmt.Errorf("Tracker: %s is ongoing, not tracking %s", othtrans, trans)
91 t.transactionXappTable[theKey] = trans
92 xapp.Logger.Debug("Tracker: Append %s", trans.String())
93 //xapp.Logger.Debug("Tracker: transtable=%v", t.transactionXappTable)
97 func (t *Tracker) UnTrackTransaction(xappKey TransactionXappKey) (*TransactionXapp, error) {
99 defer t.mutex.Unlock()
100 if trans, ok2 := t.transactionXappTable[xappKey]; ok2 {
101 xapp.Logger.Debug("Tracker: Remove %s", trans.String())
102 delete(t.transactionXappTable, xappKey)
103 //xapp.Logger.Debug("Tracker: transtable=%v", t.transactionXappTable)
106 return nil, fmt.Errorf("Tracker: No record %s", xappKey)