Exemple #1
0
    def __init__(self):

        class Servicer(chunk_pb2_grpc.FileServerServicer):
            def __init__(self):
                self.tmp_file_name = '/tmp/server_tmp'

            def upload(self, request_iterator, context):
                save_chunks_to_file(request_iterator, self.tmp_file_name)
                return chunk_pb2.Reply(length=os.path.getsize(self.tmp_file_name))

            def download(self, request, context):
                if request.name:
                    return get_file_chunks(self.tmp_file_name)

        self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=1))
        chunk_pb2_grpc.add_FileServerServicer_to_server(Servicer(), self.server)
Exemple #2
0
    def __init__(self):

        #configuration
        args  = config.config()
        self.datapath = 'datasets'
        ataset = ODMLoadDatasetStage(self.datapath , args,
                                          verbose=args.verbose)
        # run the dataset layer
        dataset.run()

        #now we have photo metadata such as gps, camera,

        #need configuration of IP address of clients

        #https://stackoverflow.com/questions/45071567/how-to-send-custom-header-metadata-with-python-grpc













        


        class Servicer(chunk_pb2_grpc.FileServerServicer):
            def __init__(self):
                self.tmp_file_name = './temp/IMG_2359.JPG'


            def upload(self, request_iterator, context):
                save_chunks_to_file(request_iterator, self.tmp_file_name)
                return chunk_pb2.Reply(length=os.path.getsize(self.tmp_file_name))

            def download(self, request, context):
                if request.name:
                    return get_file_chunks(self.tmp_file_name)

        self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=1))
        chunk_pb2_grpc.add_FileServerServicer_to_server(Servicer(), self.server)
Exemple #3
0
    def __init__(self):
        class Servicer(chunk_pb2_grpc.FileServerServicer):
            def __init__(self):
                self.tmp_file_name = '/tmp/server_tmp'
                self.chunk_size = 1024**2

            def upload(self, request_iterator, context):
                save_chunks_to_file(request_iterator, self.tmp_file_name)
                size = os.path.getsize(self.tmp_file_name)
                # deletion takes time - need to delete for next iteration
                cleanup(self.tmp_file_name)
                return chunk_pb2.Reply(length=size)

            def download(self, request, context):
                if request.name:
                    return get_file_chunks(self.tmp_file_name, self.chunk_size)

        self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=10),
                                  options=[('grpc.max_send_message_length',
                                            1024**3),
                                           ('grpc.max_receive_message_length',
                                            1024**3)])
        chunk_pb2_grpc.add_FileServerServicer_to_server(
            Servicer(), self.server)
import sys
sys.path.append('./')

from StorageManager import StorageManagerServer
import grpc
import time
import chunk_pb2, chunk_pb2_grpc
from concurrent import futures

if __name__ == '__main__':
    print("Starting Storage Manager.")
    server_grpc = grpc.server(futures.ThreadPoolExecutor(max_workers=1))
    total_memory_node_bytes = 1 * 1024 * 1024 * 1024  # start with 1 GB
    CHUNK_SIZE_ = 1024
    total_page_memory_size_bytes = CHUNK_SIZE_
    chunk_pb2_grpc.add_FileServerServicer_to_server(
        StorageManagerServer(total_memory_node_bytes,
                             total_page_memory_size_bytes), server_grpc)
    port = 5555
    server_grpc.add_insecure_port(f'[::]:{port}')
    server_grpc.start()

    print("Storage Manager is READY.")

    try:
        while True:
            time.sleep(60 * 60 * 24)  # should infinity
    except KeyboardInterrupt:
        server_grpc.stop(0)