-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathservice_communicator.py
76 lines (57 loc) · 2.65 KB
/
service_communicator.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import ast
import requests
class Service_Contactor:
def __init__(self, server_host='127.0.0.1', server_port='5000'):
url_builder = 'http://' + server_host + ':' + server_port + '/'
self._open_connection_url = url_builder + 'connect/1'
self._close_connection_url = url_builder + 'connect/0'
self._enable_edb_monitor_url = url_builder + 'track/'
self._disable_edb_monitor_url = url_builder + 'connect/3'
self._streaming_url = url_builder + 'streaming'
self._searching_url = url_builder + 'search'
self._search_del_url = url_builder + "searchdel"
self._db_info_url = url_builder + 'dbinfo'
def proc_response(self,response, **kwargs):
#print(">> Response1 ", response.request.url)
#print (response.content.decode())
if response.status_code != 200:
print (response.request.url)
print (response.content)
def enable_edb_monitor(self,monitoring_duration, time_interval):
_ = requests.put(self._enable_edb_monitor_url + str(monitoring_duration) + "/" + str(time_interval))
def disable_edb_monitor(self):
_ = requests.put(self._disable_edb_monitor_url)
#open connection to Server
def open_connection(self):
_ = requests.put(self._open_connection_url)
#print(resp.json())
#close connection to Server
def close_connection(self):
_ = requests.put(self._close_connection_url)
#print(resp.json())
def streaming_connect(self, enc_batch):
jenc_batch1 = {'enc_batch': str(enc_batch)}
#print(jenc_batch1)
response = requests.post(self._streaming_url, json=jenc_batch1)
return response
def search_connect(self, token):
if token is None:
return None
jtoken = {'token': str(token)}
resp = requests.post(self._searching_url, json=jtoken)
result = resp.json()
str_encrypted_IDs = result['result']
encrypted_IDs = ast.literal_eval(str_encrypted_IDs)
#raw_IDs = client.decryptIDs(encrypted_IDs)
#print(raw_IDs)
return encrypted_IDs
def search_del_connect(self,token):
jtoken = {'token': str(token)}
resp = requests.post(self._search_del_url, json=jtoken)
result = resp.json()
str_encrypted_IDs = result['result']
encrypted_IDs = ast.literal_eval(str_encrypted_IDs)
return encrypted_IDs
def getDBInfo(self):
resp = requests.get(self._db_info_url)
return resp.json()