Commit 27045528 authored by Matthieu Dorier's avatar Matthieu Dorier

adapted to latest bake API

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