Skip to content
This repository was archived by the owner on Oct 4, 2023. It is now read-only.

Commit c5b21bc

Browse files
committed
Gedis with ZDB backend #24
1 parent 77158f8 commit c5b21bc

File tree

8 files changed

+53
-18
lines changed

8 files changed

+53
-18
lines changed

DigitalMe/servers/gedis/GedisCmds.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(self, server=None, namespace="default", name="", path="", capnpbin=
5151
kobj = klass()
5252
if hasattr(kobj, "schema"):
5353
# means is a generated actor which exposes a model (schema)
54-
key = "%s__model_%s" % (self.namespace, kobj.schema.name)
54+
key = "%s__model_%s" % (self.namespace, kobj.schema.url)
5555
else:
5656
key = "%s__%s" % (self.namespace, cname.replace(".", "_"))
5757

DigitalMe/servers/gedis/templates/actor_model_server.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def find(self, total_items_in_page=20, page_number=1, only_fields=[], **args):
5252
import ast
5353
only_fields = ast.literal_eval(only_fields.decode())
5454
return self.model.find(hook=self.hook_get, capnp=True, total_items_in_page=total_items_in_page,
55-
page_number=page_number, only_fields=only_fields, {{kwargs}})
55+
page_number=page_number, only_fields=only_fields)
5656

5757
def new(self):
5858
return self.model.new()

packages/notary/README.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
## in kosmos run the following:
33
```python
44

5+
zdb_cl = j.clients.zdb.start_test_instance()
6+
zdb_cl = zdb_cl.namespace_new("notary_namespace", secret="1234")
7+
bcdb = j.data.bcdb.new(zdbclient=zdb_cl, name="notary_bcdb")
8+
bcdb.models_add("/sandbox/code/github/threefoldtech/digitalmeX/packages/notary/models")
59
server = j.servers.gedis.configure(host="0.0.0.0", port=8888)
6-
7-
server.actor_add('/sandbox/code/github/threefoldtech/digitalmeX/packages/notary/actors/notary_actor.py')
8-
9-
server.start()
10+
server.actor_add('/sandbox/code/github/threefoldtech/digitalmeX/packages/notary/actors/notary_actor.py')
11+
server.models_add(models=bcdb.models.values())
12+
server.start()
1013
```
1114
## using Tmux
1215
```
@@ -28,5 +31,5 @@ http://localhost:8080/get?key="test"
2831

2932
## to delete
3033
```
31-
http://localhost:8080/delete?robot_id="123",key="test",key_signature="Notary_test"
34+
http://localhost:8080/delete?robot_id="123"&key="test"&content_signature="Notary_test"
3235
```

packages/notary/actors/notary_actor.py

+31-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ class notary_actor(JSBASE):
1111
def start_page(self):
1212
return "welcome to https://github.com/threefoldtech/home/issues/135"
1313

14+
def bcdb_get(self):
15+
zdb_cl = j.clients.zdb.start_test_instance()
16+
zdb_cl = zdb_cl.namespace_new("notary_namespace", secret="1234")
17+
bcdb = j.data.bcdb.new(zdbclient=zdb_cl, name="notary_bcdb")
18+
bcdb.models_add("/sandbox/code/github/threefoldtech/digitalmeX/packages/notary/models")
19+
return bcdb
20+
1421
def register(self, robot_id, key, content, content_signature, schema_out):
1522
"""
1623
```in
@@ -24,6 +31,15 @@ def register(self, robot_id, key, content, content_signature, schema_out):
2431
```
2532
"""
2633
out = schema_out.new()
34+
bcdb = self.bcdb_get()
35+
model = bcdb.models.get("threefold.grid.notary")
36+
model_obj = model.new()
37+
model_obj.robot_id = robot_id
38+
model_obj.key = key
39+
model_obj.content = content
40+
model_obj.content_signature = content_signature
41+
model_obj.save()
42+
2743
out.message = "your register info is robot_id = {} , key = {}, content = {} ,content_signature ={}".format(
2844
robot_id, key, content, content_signature)
2945
return out
@@ -38,21 +54,29 @@ def get(self, key, schema_out):
3854
```
3955
"""
4056
out = schema_out.new()
41-
# TODO: return json object
42-
out.message = "your key is {}".format(key)
57+
bcdb = self.bcdb_get()
58+
for model in bcdb.get_all():
59+
if model.key == key:
60+
return model
61+
62+
out.message = "this key doesn't exist"
4363
return out
4464

45-
def delete(self, robot_id, key, key_signature, schema_out):
65+
def delete(self, robot_id, key, content_signature, schema_out):
4666
"""
4767
```in
4868
robot_id = "" (S)
4969
key = "" (S)
50-
key_signature = "" (S)
70+
content_signature = "" (S)
5171
```
5272
```out
5373
message = "" (S)
5474
```
55-
"""
56-
out = schema_out.new()
57-
# TODO: return true if success deleted from zdb otherwise return false
75+
"""
76+
bcdb = self.bcdb_get()
77+
for model in bcdb.get_all():
78+
if model.key == key and model.robot_id == robot_id and model.content_signature == content_signature:
79+
model.delete()
80+
model.save()
81+
return "True"
5882
return "False"

packages/notary/app.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ do
3838
local client = redis.connect(config.gedis_host, config.gedis_port)
3939
client["gedis"] = redis.command("default.notary_actor.delete")
4040
local args = {
41-
["robot_id"] = self.params.id,
41+
["robot_id"] = self.params.robot_id,
4242
["key"] = self.params.key,
43-
["key_signature"] = self.params.key_signature
43+
["content_signature"] = self.params.content_signature
4444
}
4545
local header = {
4646
["response_type"] = "json"

packages/notary/app.moon

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ class extends lapis.Application
4141
client["gedis"] = redis.command("default.notary_actor.delete")
4242

4343
args = {
44-
"robot_id": @params.id,
44+
"robot_id": @params.robot_id,
4545
"key": @params.key,
46-
"key_signature": @params.key_signature
46+
"content_signature": @params.content_signature
4747
}
4848
header = {
4949
"response_type": "json"

packages/notary/models/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# notary_model
2+
@url = threefold.grid.notary
3+
name* = ""
4+
comment = ""
5+
robot_id* = "" (S)
6+
key* = (S)
7+
content = (S)
8+
content_signature = (S)

0 commit comments

Comments
 (0)