Exemple #1
0
 def DeleteSlave(self, filename, address):
     channel = grpc.insecure_channel(address)
     stub = data_pb2_grpc.FileSystemStub(channel=channel)
     if not self.__LockFile(stub, filename):
         raise Exception
     stub.DeleteFile(data_pb2.Filename(filename=filename))
     self.__UnlockFile(stub, filename)
Exemple #2
0
 def ListFiles(self, request, context):
     data = self.__ReadData()
     for filename in data:
         addresses = data[filename]
         channel = grpc.insecure_channel(addresses[0])
         stub = data_pb2_grpc.FileSystemStub(channel=channel)
         file_info = stub.GetFileInfo(data_pb2.Filename(filename=filename))
         yield file_info
Exemple #3
0
 def UpdateSlave(self, filename, address):
     file_path = _DIR + filename
     channel = grpc.insecure_channel(address)
     stub = data_pb2_grpc.FileSystemStub(channel=channel)
     if not self.__LockFile(stub, filename):
         raise Exception
     stub.Upload(self.__ReadFile(filename, file_path))
     self.__UnlockFile(stub, filename)
Exemple #4
0
 def DeleteFile(self, filename):
     server_address = self.GetHost(filename)
     channel = grpc.insecure_channel(server_address)
     self.server_stub = data_pb2_grpc.FileSystemStub(channel=channel)
     while not self.__LockFile(filename):
         time.sleep(2)
     response = self.server_stub.DeleteFile(
         data_pb2.Filename(filename=filename))
     self.__UnlockFile(filename)
     self.tracker_stub.DeleteFile(data_pb2.Filename(filename=filename))
     file_path = DIR + 'tmp_' + filename
     if Path(file_path).is_file():
         os.chmod(file_path, S_IWUSR | S_IREAD)
         Path(file_path).unlink()
     print(response.code, response.message)
Exemple #5
0
 def UpdateFile(self, filename):
     server_address = self.GetHost(filename)
     channel = grpc.insecure_channel(server_address)
     self.server_stub = data_pb2_grpc.FileSystemStub(channel=channel)
     file_path = DIR + 'tmp_' + filename
     while not self.__LockFile(filename):
         time.sleep(2)
     if self.__CheckCache(filename, file_path):
         print('Already in cache.')
     else:
         result = self.__Download(filename, file_path)
     os.chmod(file_path, S_IWUSR | S_IREAD)
     os.system(file_path)
     response = self.__Upload(filename, file_path)
     print(response.code, response.message)
     self.__UnlockFile(filename)
Exemple #6
0
 def OpenFile(self, filename):
     response = self.tracker_stub.GetServer(
         data_pb2.Filename(filename=filename))
     if response.code != 0:
         response = self.tracker_stub.GetHost(
             data_pb2.Filename(filename=filename))
     channel = grpc.insecure_channel(response.address)
     self.server_stub = data_pb2_grpc.FileSystemStub(channel=channel)
     file_path = DIR + 'tmp_' + filename
     if self.__CheckCache(filename, file_path):
         print('Already in cache.')
     else:
         time.sleep(2)
         while not self.__LockFile(filename):
             time.sleep(2)
         if Path(file_path).is_file():
             os.chmod(file_path, S_IWUSR | S_IREAD)
             Path(file_path).unlink()
         result = self.__Download(filename, file_path)
         self.__UnlockFile(filename)
         os.chmod(file_path, S_IREAD | S_IRGRP | S_IROTH)
     os.system(file_path)
Exemple #7
0
 def __CreateFile(self, filename, address):
     channel = grpc.insecure_channel(address)
     stub = data_pb2_grpc.FileSystemStub(channel=channel)
     response = stub.CreateFile(data_pb2.Filename(filename=filename))