Beispiel #1
0
def upfile(stub, sourcepath, destination):
    contentarray ,sizes= chunk.split(sourcepath)
    response = stub.getChunkInfoAndAllocatedDataServer(MasterForClient_pb2.getChunkInfoAndAllocatedDataServerRequest(
    size = sizes,
    path = destination
    ))
    chunknum = 0
    address = []
    allchunk = []
    for feature in response:
        chunks = chunk.chunk()
        chunks.ChunkSize = feature.ChunkSize
        chunks.setCID(feature.ChunkId)
        chunks.setFileInfo(feature.inFID,feature.offset)
        chunks.setDID(feature.StoreDID)
        ip = feature.ip
        port = feature.port
        chunks.setContent(contentarray[chunknum])
        chunknum += 1
        address.append(str(ip)+':'+str(port))
        allchunk.append(chunks)

    """ with multiprocessing.Pool(4) as p:
        results = p.map(SendChunkToDataserver, zip(address,allchunk)) """
    results = []
    for i in range(len(allchunk)):
        results.append(SendChunkToDataserver((address[i],allchunk[i])))
    print('upload ok')
    print(results)
Beispiel #2
0
 def getFiletree(self, request, context):
     itemlist = []
     for item in filetree.FileTree.seriesToPath():
         respond = MasterForClient_pb2.Str(name=item[0], isFolder=item[1])
         itemlist.append(respond)
     for answer in itemlist:
         yield answer
Beispiel #3
0
def getTree(stub):
    response = stub.getFiletree(MasterForClient_pb2.EmptyArg())
    newtree = []
    print()
    for feature in response:
        newtree.append((feature.name, feature.isFolder))

    filetree.FileTree.deseriesFromPath(newtree)
Beispiel #4
0
    def requestDownloadFromMaster(self, request, context):
        requestFile = request.path
        temp = FileManager.sys.FindByFilenama(requestFile)
        if not temp:
            yield MasterForClient_pb2.targetInfo(status=0, )

        chunkList = temp.getChunkList()
        responseList = []
        for chk in chunkList:
            ip, port = FileManager.sys.SeekSocket(chk.getDataserverID())
            rsps = MasterForClient_pb2.targetInfo(ip=ip,
                                                  port=port,
                                                  ChunkSize=chk.ChunkSize,
                                                  ChunkId=chk.ChunkId,
                                                  status=1)
            responseList.append(rsps)
        for response in responseList:
            yield response
Beispiel #5
0
def mkdir(stub, cur_node, user_input):
    dir_name = user_input.split()[1]
    destination = cur_node.path + '/' + dir_name
    if filetree.FileTree.seek(destination) is None:
        result = stub.createFolder(MasterForClient_pb2.createFolderRequest(destination=destination))
        if result.feedBack:
            print(colored('Create folder ' + dir_name + ' done.', 'green'))
            fetch(stub)
    else:
        print(colored(dir_name + ' is used, please chooes another folder name.', 'red'))
Beispiel #6
0
    def deleteFile(self, request, context):
        FilePath = request.path
        # isFolder = request.isFolder
        msg0 = msg1 = 0
        listToDelete = []
        try:
            listToDelete = filetree.FileTree.getLeafNodes(FilePath)
        except:
            return MasterForClient_pb2.ACK(
                msg='Oops, no such directory or file', feedBack=False)

        msg0 = filetree.FileTree.removeNode(FilePath)
        filetree.FileTree.print_tree()
        if listToDelete:
            for fileName in listToDelete:
                msg2 = 0
                fileForFID = FileManager.sys.FindByFilenama(fileName)
                chunkList = fileForFID.getChunkList()
                for chunk in chunkList:
                    did = chunk.getDataserverID()
                    cid = chunk.getChunkId()
                    response = deleteChunkOnDataServer(ConnectDataServer(did),
                                                       cid)
                    if response.feedback:
                        msg2 += 1
                    Backup.BackupManager.insertDeleteTask(
                        chunk.getFileID(), cid)
                if msg2 == len(chunkList):
                    msg1 += 1
                else:
                    break
                FileManager.sys.DeleteFile(fileForFID.getFID())
        if msg0 and msg1 == len(listToDelete):
            return MasterForClient_pb2.ACK(msg='Successful!', feedBack=True)
        else:
            return MasterForClient_pb2.ACK(msg='Failed!', feedBack=False)
Beispiel #7
0
def deleteFile(stub, cur_node, user_input):
    try:
        toDelete = cur_node.path + '/' + user_input.split()[1]
    except:
        print(colored('Please specify file path'))
        return cur_node
    if filetree.FileTree.isUniquePath(toDelete):
        print(colored('No such file.', 'red'))
        return cur_node
    pakage = MasterForClient_pb2.FilePath(
        path=toDelete
    )
    ack = stub.deleteFile(pakage)
    print(ack.msg)
    fetch(stub)
    return filetree.FileTree.seek(cur_node.path)
Beispiel #8
0
    def getChunkInfoAndAllocatedDataServer(self, request, context):
        size = request.size
        path = request.path
        # islegal(path) ? 目录树判断路径是否合法
        Files = FileManager.sys.CreateFile(path, size)
        respondlist = []

        for chunk in Files.ChunkList:
            respond = MasterForClient_pb2.ChunkStructor(
                ChunkSize=chunk.ChunkSize,
                ChunkId=chunk.getChunkId(),
                inFID=chunk.getFileID(),
                offset=chunk.getOffset(),
                StoreDID=chunk.getDataserverID(),
                ip=FileManager.sys.Register.getrow(
                    chunk.getDataserverID()).getIP(),
                port=FileManager.sys.Register.getrow(
                    chunk.getDataserverID()).getport())
            respondlist.append(respond)
        for responds in respondlist:
            yield responds
Beispiel #9
0
def requestDownloadFromMaster(stub, toDownload):
    package = MasterForClient_pb2.downloadRequestInfo(
        path=toDownload
    )
    targetInfo = stub.requestDownloadFromMaster(package)
    return targetInfo
Beispiel #10
0
 def createFolder(self, request, context):
     destination = request.destination
     return MasterForClient_pb2.ACK(feedBack=filetree.FileTree.insertNode(
         destination, True),
                                    msg='dummy message')
Beispiel #11
0
def deleteFile(stub):
    toDelete = input('the file to delete: ')
    pakage = MasterForClient_pb2.FilePath(path=toDelete)
    ack = stub.deleteFile(pakage)
    print(ack.msg)