blob: b9877165006ec1d2c5aa1423d1b37378beccfe78 [file] [log] [blame]
Niranjana3d457a02020-08-12 13:33:22 +05301import flask
2import json
3from flask import request
4import requests
5import threading
6import time
7
8app = flask.Flask(__name__)
9app.config["DEBUG"] = True
10
Niranjana3d457a02020-08-12 13:33:22 +053011def get_neighbour_cell_list_for_cell_id():
12 with open('cell_list.json') as cell_list:
13 data = json.load(cell_list)
14 if not data:
15 return {"Error": "Unable to read file"}, 503
16 return data, None
17
18def get_pci_for_cell_id():
19 with open('pci_value.json') as pci_value:
20 data = json.load(pci_value)
21 if not data:
22 return {"Error": "Unable to read file"}, 503
23 return data, None
24
25def get_cell_data_for_cell_id():
26 with open('cell_data.json') as cell_data:
27 data = json.load(cell_data)
28 if not data:
29 return {"Error": "Unable to read file"}, 503
30 return data, None
31
32def get_oof_sync_response():
33 with open('oof_syn_response.json') as syncRes:
34 data = json.load(syncRes)
35 if not data:
36 return {"Error": "Unale to read file"}, 503
37 return data, None
38
39def get_oof_async_response(callback_url, transaction_id):
40 time.sleep(10)
41 with open('oof_async_response.json') as asyncRes:
42 data = json.load(asyncRes)
43 data['transactionId'] = transaction_id
44 if not data:
45 return {"Error": "Unable to read file"}, 503
46 res = requests.post(callback_url, json=data)
47 print('response from server:',res.text)
48 return res
49
50@app.route("/api/sdnc-config-db/v3/getNbrList/<cell_id>/<ts>", methods=["GET"])
51def get_neighbour_list(cell_id, ts):
52 data, status = get_neighbour_cell_list_for_cell_id()
53 if not status:
54 return data
55 return data, 503
56
57@app.route("/api/sdnc-config-db/v3/getPCI/<cell_id>/<ts>", methods=["GET"])
58def get_pci(cell_id, ts):
59 data, status = get_pci_for_cell_id()
60 if not status:
61 return data
62 return data, 503
63@app.route("/api/sdnc-config-db/v3/getPnfId/<cell_id>/<ts>", methods=["GET"])
64def get_pnf_id(cell_id, ts):
65 data, status = get_pci_for_cell_id()
66 data['value'] = 'ncserver5'
67 if not status:
68 return data
69 return data, 503
70
71@app.route("/api/sdnc-config-db/v3/getCell/<cell_id>", methods=["GET"])
72def get_cell_data(cell_id):
73 data, status = get_cell_data_for_cell_id()
74 if not status:
75 return data
76 return data, 503
77
78@app.route("/api/oof/v1/pci",methods=["POST"])
79def oof_optimizatio_result():
80 content = request.get_json()
81 callback_url = content['requestInfo']['callbackUrl']
82 transaction_id = content['requestInfo']['transactionId']
83 try:
84 task = threading.Thread(target=get_oof_async_response, args=(callback_url,transaction_id,))
85 task.daemon = True
86 task.start()
87 except:
88 print("Error: Unable to start thread")
89
90 data, status = get_oof_sync_response()
91
92 if not status:
93 return data, 202
94 return data, 503
95
96
97app.run(host='0.0.0.0')
Malarvizhiea92dc32022-03-23 14:52:42 +000098app.run(debug=True)