Skip to content

Commit

Permalink
add unallocation method
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhongFuze committed Sep 2, 2024
1 parent 0057fa5 commit 4b1cfa6
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/config/nginx/nginx.conf.2
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ http {

server {
listen 80;
server_name ec2-18-167-19-252.ap-east-1.compute.amazonaws.com;
server_name localhost;

location / {
proxy_pass http://localhost:9001;
Expand Down
2 changes: 1 addition & 1 deletion src/config/nginx/nginx.conf.bak
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ http {

server {
listen 9001;
server_name ec2-18-167-19-252.ap-east-1.compute.amazonaws.com;
server_name localhost;

# Deny access to all resources by default
location / {
Expand Down
64 changes: 63 additions & 1 deletion src/controller/allocation_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author: Zella Zhong
Date: 2024-05-23 22:47:04
LastEditors: Zella Zhong
LastEditTime: 2024-05-26 16:57:04
LastEditTime: 2024-09-02 10:08:16
FilePath: /id_allocation/src/controller/allocation_controller.py
Description: allocation controller
'''
Expand All @@ -31,6 +31,68 @@ class AllocationController(httpsvr.BaseController):
def __init__(self, obj, param=None):
super(AllocationController, self).__init__(obj)

def unallocation(self):
'''
description:
requestbody: {
"vids": ["string"],
}
return: {
{
"unique_id_1": "old_graph_id_1",
"unique_id_2": "old_graph_id_2",
}
}
'''
post_data = self.inout.request.body
if post_data is None:
return httpsvr.Resp(msg="Invalid input body", data=None, code=-1)
if post_data == "":
return httpsvr.Resp(msg="Invalid input body", data=None, code=-1)
data = json.loads(post_data)
vids = data.get("vids", [])
if len(vids) == 0:
return httpsvr.Resp(msg="Invalid input body", data=None, code=-1)

data = {}
for vid in vids:
data[vid] = ""

rows = []
code = 0
msg = ""
try:
pg_conn = get_write_conn()
cursor = pg_conn.cursor()

in_vids = "(" + ",".join(["'" + x + "'" for x in vids]) + ")"
ssql = "SELECT unique_id, graph_id FROM id_allocation WHERE unique_id in {}".format(in_vids)
cursor.execute(ssql)
rows = [dict_factory(cursor, row) for row in cursor.fetchall()]

for row in rows:
row_unique_id = row["unique_id"]
row_graph_id = row["graph_id"]
data[row_unique_id] = row_graph_id

if len(rows) > 0:
delete_sql = "DELETE FROM id_allocation WHERE unique_id in {}".format(in_vids)
cursor.execute(delete_sql)
pg_conn.commit()
logging.warn("unallocation delete: {}".format(rows))

logging.info("unallocation vids: {}, result: {}".format(in_vids, rows))
except Exception as e:
code = -1
msg = repr(e)
logging.exception(e)
finally:
cursor.close()
pg_conn.close()

return httpsvr.Resp(msg=msg, data=data, code=code)

def allocation(self):
'''
description:
Expand Down
3 changes: 2 additions & 1 deletion src/data_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author: Zella Zhong
Date: 2024-05-23 22:34:52
LastEditors: Zella Zhong
LastEditTime: 2024-05-25 04:19:08
LastEditTime: 2024-09-02 10:13:00
FilePath: /id_allocation/src/data_server.py
Description: main entry point for allocating
'''
Expand Down Expand Up @@ -32,6 +32,7 @@
ctrl_info = [
["/", HelloController, "hello"],
["/id_allocation/allocation", AllocationController, "allocation"],
["/id_allocation/unallocation", AllocationController, "unallocation"],
]
svr = httpsvr.HttpSvr(config, ctrl_info)
svr.Start()
Expand Down
1 change: 1 addition & 0 deletions src/script/test_api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

curl -w "\nTime: %{time_total}s\n" -X POST http://localhost:9002/id_allocation/allocation -d '{"graph_id":"cba9bbf5-ee77-48f6-919c-302fcd1c2a23","updated_nanosecond":1716482473640540,"vids":["twitter,chan_izaki65652","farcaster,gytred","ethereum,0x61ae970ac67ff4164ebf2fd6f38f630df522e5ef"]}'

curl -w "\nTime: %{time_total}s\n" -X POST 'http://localhost:9002/id_allocation/unallocation' -d '{"vids": ["farcaster,zzfzz.eth"]}'

curl -w "\nTime: %{time_total}s\n" -X POST 'http://localhost:9002/id_allocation/allocation' -d '{"graph_id":"101d4307-f84f-4942-b6ce-df0bab491bae","updated_nanosecond":1716565633694549,"vids":["crossbell,suji.csb","crossbell,sujiyan.csb","ethereum,0x934b510d4c9103e6a87aef13b816fb080286d649"]}'

0 comments on commit 4b1cfa6

Please sign in to comment.