Commit 27045528 authored by Matthieu Dorier's avatar Matthieu Dorier

adapted to latest bake API

parent ce0508d2
...@@ -40,7 +40,7 @@ class BakeClient(): ...@@ -40,7 +40,7 @@ class BakeClient():
addr (MargoAddress): Address of the MargoInstance to shut down. addr (MargoAddress): Address of the MargoInstance to shut down.
""" """
_pybakeclient.shutdown_service(self._client, addr._hg_addr) _pybakeclient.shutdown_service(self._client, addr._hg_addr)
def finalize(self): def finalize(self):
""" """
Finalizes the underlying bake_client_t structure. Finalizes the underlying bake_client_t structure.
...@@ -60,7 +60,7 @@ class BakeProviderHandle(): ...@@ -60,7 +60,7 @@ class BakeProviderHandle():
by calling clt.create_provider_handle. by calling clt.create_provider_handle.
""" """
self._ph = ph self._ph = ph
def __del__(self): def __del__(self):
""" """
Explicit destructor to call provider_handle_release on the underlying Explicit destructor to call provider_handle_release on the underlying
...@@ -126,6 +126,8 @@ class BakeProviderHandle(): ...@@ -126,6 +126,8 @@ class BakeProviderHandle():
offset (int): offset at which to write. offset (int): offset at which to write.
data (str): data to write. data (str): data to write.
""" """
if(isinstance(data,str)):
data = data.encode()
_pybakeclient.write(self._ph, rid._rid, offset, data) _pybakeclient.write(self._ph, rid._rid, offset, data)
def write_numpy(self, rid, offset, array): def write_numpy(self, rid, offset, array):
...@@ -183,6 +185,8 @@ class BakeProviderHandle(): ...@@ -183,6 +185,8 @@ class BakeProviderHandle():
Returns: Returns:
The created BakeRegionID. The created BakeRegionID.
""" """
if(isinstance(data,str)):
data = data.encode()
rid = _pybakeclient.create_write_persist(self._ph, bti._tid, data) rid = _pybakeclient.create_write_persist(self._ph, bti._tid, data)
return BakeRegionID(rid) return BakeRegionID(rid)
......
...@@ -18,7 +18,7 @@ class BakeProvider(pymargo.Provider): ...@@ -18,7 +18,7 @@ class BakeProvider(pymargo.Provider):
Constructor. Initializes a provider with an Engine and provider_id. Constructor. Initializes a provider with an Engine and provider_id.
""" """
super(BakeProvider, self).__init__(engine, provider_id) super(BakeProvider, self).__init__(engine, provider_id)
self._provider = _pybakeserver.register(mid._mid, provider_id) self._provider = _pybakeserver.register(engine._mid, provider_id)
def add_storage_target(self, path): def add_storage_target(self, path):
""" """
......
...@@ -16,8 +16,9 @@ namespace py11 = pybind11; ...@@ -16,8 +16,9 @@ namespace py11 = pybind11;
static py11::bytes pybake_target_id_to_string(bake_target_id_t tid) { static py11::bytes pybake_target_id_to_string(bake_target_id_t tid) {
char id[37]; char id[37];
uuid_unparse(tid.id, id); int ret = bake_target_id_to_string(tid, id, 37);
return py11::bytes(std::string(id)); if(ret != BAKE_SUCCESS) return py11::bytes();
else return py11::bytes(std::string(id));
} }
static py11::object pybake_target_id_from_string(const py11::bytes& btidstr) { static py11::object pybake_target_id_from_string(const py11::bytes& btidstr) {
...@@ -25,23 +26,29 @@ static py11::object pybake_target_id_from_string(const py11::bytes& btidstr) { ...@@ -25,23 +26,29 @@ static py11::object pybake_target_id_from_string(const py11::bytes& btidstr) {
memset(tid.id, 0, sizeof(uuid_t)); memset(tid.id, 0, sizeof(uuid_t));
std::string tidstr = (std::string)btidstr; std::string tidstr = (std::string)btidstr;
if(tidstr.size() != 36) return py11::none(); if(tidstr.size() != 36) return py11::none();
int ret = uuid_parse((char*)tidstr.c_str(), tid.id); int ret = bake_target_id_from_string(tidstr.c_str(), &tid);
if(ret == 0) return py11::cast(tid); if(ret == BAKE_SUCCESS) return py11::cast(tid);
else return py11::none(); else return py11::none();
} }
static py11::bytes pybake_region_id_to_string(const bake_region_id_t& region_id) { static py11::bytes pybake_region_id_to_string(const bake_region_id_t& region_id) {
std::string result((const char*)(&region_id), sizeof(region_id)); char id[128];
return py11::bytes(result); memset(id, 0, 128);
int ret = bake_region_id_to_string(region_id, id, 128);
if(ret == BAKE_SUCCESS) {
std::string result(id);
return py11::bytes(result);
} else {
return py11::bytes();
}
} }
static py11::object pybake_region_id_from_string(const py11::bytes& bregion_str) { static py11::object pybake_region_id_from_string(const py11::bytes& bregion_str) {
bake_region_id_t result; bake_region_id_t result;
std::string region_str = (std::string)bregion_str; std::string region_str = (std::string)bregion_str;
memset(&result, 0, sizeof(result)); memset(&result, 0, sizeof(result));
if(region_str.size() != sizeof(bake_region_id_t)) int ret = bake_region_id_from_string(region_str.c_str(), &result);
return py11::none(); if(ret != BAKE_SUCCESS) return py11::none();
memcpy(&result, region_str.data(), sizeof(bake_region_id_t));
return py11::cast(result); return py11::cast(result);
} }
......
...@@ -66,7 +66,7 @@ class BakeRegionID(): ...@@ -66,7 +66,7 @@ class BakeRegionID():
if(self._rid is None): if(self._rid is None):
return str(None) return str(None)
a = _pybaketarget.region_id_to_string(self._rid) a = _pybaketarget.region_id_to_string(self._rid)
return base64.b64encode(a).decode() return a.decode()
@staticmethod @staticmethod
def from_str(byte_string): def from_str(byte_string):
...@@ -76,7 +76,7 @@ class BakeRegionID(): ...@@ -76,7 +76,7 @@ class BakeRegionID():
""" """
if(isinstance(byte_string,str)): if(isinstance(byte_string,str)):
byte_string = byte_string.encode() byte_string = byte_string.encode()
rid = _pybaketarget.region_id_from_string(base64.b64decode(byte_string)) rid = _pybaketarget.region_id_from_string(byte_string)
if(rid is None): if(rid is None):
return None return None
else: else:
......
...@@ -24,24 +24,24 @@ except ImportError: ...@@ -24,24 +24,24 @@ except ImportError:
# Find out the dependencies using pkgconfig # Find out the dependencies using pkgconfig
# For client... # For client...
pk = pkgconfig.parse('bake-client') bake_client = pkgconfig.parse('bake-client')
client_libraries = pk['libraries'] client_libraries = bake_client['libraries']
client_library_dirs = pk['library_dirs'] client_library_dirs = bake_client['library_dirs']
client_include_dirs = pk['include_dirs'] client_include_dirs = bake_client['include_dirs']
client_include_dirs.append(".") client_include_dirs.append(".")
client_include_dirs.append(get_pybind11_include()) client_include_dirs.append(get_pybind11_include())
# For server... # For server...
pk = pkgconfig.parse('bake-server') bake_server = pkgconfig.parse('bake-server')
server_libraries = pk['libraries'] server_libraries = bake_server['libraries']
server_library_dirs = pk['library_dirs'] server_library_dirs = bake_server['library_dirs']
server_include_dirs = pk['include_dirs'] server_include_dirs = bake_server['include_dirs']
server_include_dirs.append(".") server_include_dirs.append(".")
server_include_dirs.append(get_pybind11_include()) server_include_dirs.append(get_pybind11_include())
# For target... # For target...
pk = pkgconfig.parse('uuid') uuid = pkgconfig.parse('uuid')
target_libraries = pk['libraries'] target_libraries = uuid['libraries'] + bake_client['libraries']
target_library_dirs = pk['library_dirs'] target_library_dirs = uuid['library_dirs'] + bake_client['library_dirs']
target_include_dirs = pk['include_dirs'] target_include_dirs = uuid['include_dirs'] + bake_client['include_dirs']
target_include_dirs.append('.') target_include_dirs.append('.')
target_include_dirs.append(get_pybind11_include()) target_include_dirs.append(get_pybind11_include())
pk = pkgconfig.parse('bake-server') pk = pkgconfig.parse('bake-server')
......
...@@ -2,55 +2,61 @@ ...@@ -2,55 +2,61 @@
# See COPYRIGHT in top-level directory. # See COPYRIGHT in top-level directory.
import sys import sys
sys.path.append('.') sys.path.append('.')
sys.path.append('build/lib.linux-x86_64-2.7') sys.path.append('build/lib.linux-x86_64-3.6')
from pymargo import MargoInstance from pymargo import MargoInstance
from pybake.target import BakeRegionID from pybake.target import BakeRegionID
from pybake.client import * from pybake.client import *
mid = MargoInstance('tcp') mid = MargoInstance('tcp')
server_addr = sys.argv[1] def test():
mplex_id = int(sys.argv[2])
server_addr = sys.argv[1]
client = BakeClient(mid) mplex_id = int(sys.argv[2])
addr = mid.lookup(server_addr)
ph = client.create_provider_handle(addr, mplex_id) client = BakeClient(mid)
addr = mid.lookup(server_addr)
# Testing get_eager_limit ph = client.create_provider_handle(addr, mplex_id)
lim = ph.get_eager_limit()
print "Eager limit is: "+str(lim) # Testing get_eager_limit
lim = ph.get_eager_limit()
# probe the provider handle (for all targets) print("Eager limit is: "+str(lim))
targets = ph.probe()
print "Probe found the following targets:" # probe the provider handle (for all targets)
for t in targets: targets = ph.probe()
print "===== "+str(t) print("Probe found the following targets:")
for t in targets:
target = targets[0] print("===== "+str(t))
# create a 32-bytes region in the first target
region = ph.create(target, 32) target = targets[0]
print "Created region "+str(region) # create a 32-bytes region in the first target
region = ph.create(target, 32)
regionstr = str(region) print("Created region "+str(region))
region = BakeRegionID.from_str(regionstr)
regionstr = str(region)
# write into the region region = BakeRegionID.from_str(regionstr)
ph.write(region, 0, 'A'*16) print("reconverting region to string: "+str(region))
ph.write(region, 16, 'B'*16) # write into the region
ph.write(region, 0, 'A'*16)
# get size of region ph.write(region, 16, 'B'*16)
s = ph.get_size(region)
print "Region size is "+str(s) # get size of region
try:
# persist region s = ph.get_size(region)
ph.persist(region) print("Region size is "+str(s))
except:
# read region print("Getting region size is not supported")
result = ph.read(region, 8, 16) # persist region
print "Reading region at offset 8, size 16 gives: "+str(result) ph.persist(region, size=32)
del ph # read region
client.shutdown_service(addr) result = ph.read(region, 8, 16)
del addr print("Reading region at offset 8, size 16 gives: "+str(result))
client.finalize()
del ph
client.shutdown_service(addr)
del addr
client.finalize()
test()
mid.finalize() mid.finalize()
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# See COPYRIGHT in top-level directory. # See COPYRIGHT in top-level directory.
import sys import sys
sys.path.append('.') sys.path.append('.')
sys.path.append('build/lib.linux-x86_64-2.7') sys.path.append('build/lib.linux-x86_64-3.6')
from pymargo import MargoInstance from pymargo import MargoInstance
import pybake import pybake
import pybake.server import pybake.server
...@@ -11,22 +11,22 @@ from pybake.server import BakeProvider ...@@ -11,22 +11,22 @@ from pybake.server import BakeProvider
mid = MargoInstance('tcp') mid = MargoInstance('tcp')
mid.enable_remote_shutdown() mid.enable_remote_shutdown()
mplex_id = 42 mplex_id = 42
print "Server running at address "+str(mid.addr())+" with mplex_id="+str(mplex_id) print("Server running at address "+str(mid.addr())+" with mplex_id="+str(mplex_id))
provider = BakeProvider(mid, mplex_id) provider = BakeProvider(mid, mplex_id)
target = provider.add_storage_target("/dev/shm/baketarget") #target = provider.add_storage_target("/dev/shm/baketarget")
print "target id is "+str(target) #print("target id is "+str(target))
print "number of targets: "+str(provider.count_storage_targets()) #print("number of targets: "+str(provider.count_storage_targets()))
pybake.server.make_pool("/dev/shm/baketarget2", 2*8388608, 0664) #pybake.server.make_pool("/dev/shm/baketarget2", 2*8388608, 0o664)
target = provider.add_storage_target("/dev/shm/baketarget2") target = provider.add_storage_target("/dev/shm/baketarget2")
print "target id is "+str(target) print("target id is "+str(target))
print "number of targets: "+str(provider.count_storage_targets()) print("number of targets: "+str(provider.count_storage_targets()))
print "storage targets: " print("storage targets: ")
targets = provider.list_storage_targets() targets = provider.list_storage_targets()
for t in targets: for t in targets:
print str(t) print(str(t))
#provider.remove_all_storage_targets() #provider.remove_all_storage_targets()
#print "number of targets: "+str(provider.count_storage_targets()) #print "number of targets: "+str(provider.count_storage_targets())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment