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 Implements a record of ongoing transactions and helper functions to CRUD the records.
31 transaction_table map[Transaction_key]Transaction
34 func (t *Tracker) Init() {
35 t.transaction_table = make(map[Transaction_key]Transaction)
39 Checks if a tranascation with similar type has been ongoing. If not then creates one.
40 Returns error if there is similar transatcion ongoing.
42 func (t *Tracker) Track_transaction(key Transaction_key, xact Transaction) error{
43 if _, ok := t.transaction_table[key]; ok {
44 // TODO: Implement merge related check here. If the key is same but the value is different.
45 err := fmt.Errorf("Transaction tracker: Similar transaction with sub id %d and type %s is ongoing", key.SubID, key.trans_type )
48 t.transaction_table[key] = xact
53 Retreives the transaction table entry for the given request.
54 Returns error in case the transaction cannot be found.
56 func (t *Tracker) Retrive_transaction(subID uint16, act Action) (Transaction, error){
57 key := Transaction_key{subID, act}
59 if xact, ok := t.transaction_table[key]; ok {
62 err := fmt.Errorf("Tranaction record for Subscription ID %d and action %s does not exist", subID, act)
67 Deletes the transaction table entry for the given request and returns the deleted xapp's address and port for reference.
68 Returns error in case the transaction cannot be found.
70 func (t *Tracker) complete_transaction(subID uint16, act Action) (string, uint16, error){
71 key := Transaction_key{subID, act}
72 var empty_address string
74 if xact, ok := t.transaction_table[key]; ok {
75 delete(t.transaction_table, key)
76 return xact.Xapp_instance_address, xact.Xapp_port, nil
78 err := fmt.Errorf("Tranaction record for Subscription ID %d and action %s does not exist", subID, act)
79 return empty_address, empty_port, err