forked from harshi12/AI_On_The_Edge_Platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_client.py
56 lines (49 loc) · 1.71 KB
/
db_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import requests
import sys
import json
import os
import time
from queue_req_resp import RabbitMQ
# RBMQ = RabbitMQ()
class DATABASE_CLIENT:
def __init__(self,DB_REQUEST_QUEUE = "modules_DB"):
self.DB_REQUEST_QUEUE = DB_REQUEST_QUEUE
def db_gateways_get(module, location):
req = {}
req["module"] = module
req["opcode"] = "GATEWAYS_AT_LOC_GET"
req["location"] = location
json_req = json.dumps(req)
RBMQ.send("", DB_REQUEST_QUEUE, json_req)
# print (f"Sent Request: {json_req}")
resp = RBMQ.receive_nonblock("", "DB_"+module)
# print (f"Received Response: {resp}")
return resp
def service_id_get(module, service_name):
req = {}
req["module"] = module
req["opcode"] = "SERVICE_ID_GET"
json_req = json.dumps(req)
RBMQ.send("", DB_REQUEST_QUEUE, json_req)
# print (f"Sent Request: {json_req}")
resp = RBMQ.receive_nonblock("", "DB_"+module)
# print (f"Received Response: {resp}")
return resp
def db_sensors_get(module,service_name):
req = {}
req["module"] = module
req["opcode"] = "SENSORS_AT_GATEWAY_GET"
req["service_name"] = service_name
json_req = json.dumps(req)
RBMQ.send("", DB_REQUEST_QUEUE, json_req)
resp = RBMQ.receive_nonblock("", "DB_"+module)
return resp
def db_app_links_get(module,app_id):
req = {}
req["module"] = module
req["opcode"] = "APPLICATION_DATA_LOC_GET"
req["app_id"] = app_id
json_req = json.dumps(req)
RBMQ.send("", DB_REQUEST_QUEUE, json_req)
resp = RBMQ.receive_nonblock("", "DB_"+module)
return resp