Skip to content
Snippets Groups Projects
Commit 4ad5feca authored by Martin Blanchard's avatar Martin Blanchard
Browse files

storage/remote.py: Port to new CAS downloader helper

#79
parent e7769a3e
No related branches found
No related tags found
No related merge requests found
......@@ -23,11 +23,16 @@ Forwwards storage requests to a remote storage.
import io
import logging
<<<<<<< HEAD
import grpc
from buildgrid.utils import gen_fetch_blob, gen_write_request_blob
=======
from buildgrid.client.cas import download
>>>>>>> storage/remote.py: Port to new CAS downloader helper
from buildgrid._protos.google.bytestream import bytestream_pb2_grpc
from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2, remote_execution_pb2_grpc
from buildgrid.utils import gen_write_request_blob
from .storage_abc import StorageABC
......@@ -36,7 +41,10 @@ class RemoteStorage(StorageABC):
def __init__(self, channel, instance_name):
self.logger = logging.getLogger(__name__)
self._instance_name = instance_name
self.instance_name = instance_name
self.channel = channel
self._stub_bs = bytestream_pb2_grpc.ByteStreamStub(channel)
self._stub_cas = remote_execution_pb2_grpc.ContentAddressableStorageStub(channel)
......@@ -46,29 +54,8 @@ class RemoteStorage(StorageABC):
return False
def get_blob(self, digest):
try:
fetched_data = io.BytesIO()
length = 0
for data in gen_fetch_blob(self._stub_bs, digest, self._instance_name):
length += fetched_data.write(data)
if length:
assert digest.size_bytes == length
fetched_data.seek(0)
return fetched_data
else:
return None
except grpc.RpcError as e:
if e.code() == grpc.StatusCode.NOT_FOUND:
pass
else:
self.logger.error(e.details())
raise
return None
with download(self.channel, instance=self.instance_name) as cas:
return io.BytesIO(cas.get_blob(digest))
def begin_write(self, digest):
return io.BytesIO(digest.SerializeToString())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment