Example #1
0
def infoFile(setting, filename):
    '''Display information of a file.'''
    metadata = common.FileMetadata(filename, 0, 0, 0)
    storage.downloadMetadata(setting, metadata)
    #Display file info:
    print metadata.filename,
    print metadata.filesize,
    print metadata.coding
Example #2
0
File: info.py Project: ialzuru/ncfs
def infoFile(setting, filename):
    '''Display information of a file.'''
    metadata = common.FileMetadata(filename,0,0,0)
    storage.downloadMetadata(setting, metadata)
    #Display file info:
    print metadata.filename,
    print metadata.filesize,
    print metadata.coding
Example #3
0
def deleteFile(setting, metadata):
    '''Workflow of Delete file.'''
    if setting.deduplication == False:
        #Acquire write lock if using ZooKeeper:
        #if setting.zookeeper: setting.zk.getWriteLock(metadata) #cq
        #Download metadata:
        storage.downloadMetadata(setting, metadata)
        #Delete chunk files and metadata:
        storage.deleteChunkAndMetadata(setting, metadata)
        #Release write lock:
        #if setting.zookeeper: setting.zk.releaseWriteLock(metadata) #cq
    else:
        orgState = storage.detectOrgState(setting, metadata)
        if orgState == 3:
            # non_dup
            print "remove non_dup"      
            #Download metadata:
            storage.downloadMetadata(setting, metadata)
            #Delete chunk files and metadata:
            storage.deleteChunkAndMetadata(setting, metadata)
        elif orgState == 2:
            # leaf
            print "remove leaf"
            storage.deletePointer(setting, metadata)
        elif orgState == 1:
            # org
            print "remove org"
            storage.downloadMetadata(setting, metadata)
            storage.deleteChunkAndMetadata(setting, metadata)
            dupFileName = storage.findOnePointer(setting, metadata)
            dupMetadata = common.FileMetadata(dupFileName, 0, setting.totalnode, setting.coding)
            storage.deletePointer(setting, dupMetadata)
            coding.encodeFile(setting,dupMetadata)
            storage.uploadFileAndMetadata(setting, dupMetadata,'upload')
            storage.updatePointers(setting,metadata,dupMetadata)
Example #4
0
def downloadFile(setting, metadata):
    '''Workflow of Download file.'''
    if setting.deduplication == False:
        #Acquire read lock if using ZooKeeper:
        #if setting.zookeeper: setting.zk.getReadLock(metadata) #cq
        #Download metadata:
        storage.downloadMetadata(setting, metadata)
        #Update metadata for requesting chunks for decode:
        coding.updateMetadataForDecode(setting, metadata, 'download')
        #Download chunk files:
        storage.downloadFile(setting, metadata)
        #Release read lock:
        #if setting.zookeeper: setting.zk.releaseReadLock(metadata) #cq
        #Decode file:
        coding.decodeFile(setting, metadata, 'download')
    else:
        retState = storage.detectPointer(setting,metadata)
        if retState == False:
            '''The file detected is non_dup or org file'''
            storage.downloadMetadata(setting, metadata)
            coding.updateMetadataForDecode(setting, metadata, 'download')
            storage.downloadFile(setting, metadata)
            coding.decodeFile(setting, metadata, 'download')
        else:
            '''The file detected is a leaf'''
            storage.downloadPointer(setting,metadata)
            targetFile = storage.getPointerContent(setting, metadata)
            targetMetadata = common.FileMetadata(targetFile,0,setting.totalnode,setting.coding)
            storage.downloadMetadata(setting, targetMetadata)
            coding.updateMetadataForDecode(setting, targetMetadata, 'download')
            storage.downloadFile(setting, targetMetadata)
            coding.decodeFile(setting,targetMetadata, 'download')
            storage.genPtLocalFile(setting,targetMetadata,metadata)
Example #5
0
def downloadFile(setting, metadata):
    '''Workflow of Download file.'''
    if setting.deduplication == False:
        #Acquire read lock if using ZooKeeper:
        #if setting.zookeeper: setting.zk.getReadLock(metadata) #cq
        #Download metadata:
        storage.downloadMetadata(setting, metadata)
        #Update metadata for requesting chunks for decode:
        coding.updateMetadataForDecode(setting, metadata, 'download')
        #Download chunk files:
        storage.downloadFile(setting, metadata)
        #Release read lock:
        #if setting.zookeeper: setting.zk.releaseReadLock(metadata) #cq
        #Decode file:
        coding.decodeFile(setting, metadata, 'download')
    else:
        retState = storage.detectPointer(setting, metadata)
        if retState == False:
            '''The file detected is non_dup or org file'''
            storage.downloadMetadata(setting, metadata)
            coding.updateMetadataForDecode(setting, metadata, 'download')
            storage.downloadFile(setting, metadata)
            coding.decodeFile(setting, metadata, 'download')
        else:
            '''The file detected is a leaf'''
            storage.downloadPointer(setting, metadata)
            targetFile = storage.getPointerContent(setting, metadata)
            targetMetadata = common.FileMetadata(targetFile, 0,
                                                 setting.totalnode,
                                                 setting.coding)
            storage.downloadMetadata(setting, targetMetadata)
            coding.updateMetadataForDecode(setting, targetMetadata, 'download')
            storage.downloadFile(setting, targetMetadata)
            coding.decodeFile(setting, targetMetadata, 'download')
            storage.genPtLocalFile(setting, targetMetadata, metadata)
Example #6
0
def rebuildFile(settingOld, settingNew, metadata, filename):
    '''Workflow of File rebuid.'''
    if settingNew.deduplication == False:
        #Acquire write lock if using ZooKeeper:
        #if settingOld.zookeeper: settingOld.zk.getWriteLock(metadata) #cq
        #Download metadata:
        print "downloadMetadata"
        storage.downloadMetadata(settingOld, metadata)
        #Update metadata for repair:
        print "updateMetadataForDecode"
        coding.updateMetadataForDecode(settingOld, metadata, 'repair')
        #Download file chunks:
        print "downloadFile"
        storage.downloadFile(settingOld, metadata)
        #Reapir file:
        print "repair File"
        coding.repairFile(settingOld, settingNew, metadata)
        #Upload repaired chunks:
        print "upload file and metadata"
        storage.uploadFileAndMetadata(settingNew, metadata, 'repair')
        #Release write lock:
        #if settingOld.zookeeper: settingOld.zk.releaseWriteLock(metadata) #cq
        coding.decodeFile(settingNew, metadata, 'download')
    else:
        retState = storage.detectPointer(settingNew, metadata)
        if retState == False:
            #org or non_dup
           print "rebuild org or non_dup %s" % (metadata.filename)
           storage.downloadMetadata(settingOld, metadata)
           coding.updateMetadataForDecode(settingOld, metadata, 'repair')
           storage.downloadFile(settingOld, metadata)
           coding.repairFile(settingOld, settingNew, metadata)
           storage.uploadFileAndMetadata(settingNew, metadata, 'repair')
           coding.decodeFile(settingNew, metadata, 'download')
        else:
            print "rebuild pointer %s" % (metadata.filename)
            storage.repairPointer(settingOld, settingNew, metadata)
Example #7
0
def rebuildFile(settingOld, settingNew, metadata, filename):
    '''Workflow of File rebuid.'''
    if settingNew.deduplication == False:
        #Acquire write lock if using ZooKeeper:
        #if settingOld.zookeeper: settingOld.zk.getWriteLock(metadata) #cq
        #Download metadata:
        print "downloadMetadata"
        storage.downloadMetadata(settingOld, metadata)
        #Update metadata for repair:
        print "updateMetadataForDecode"
        coding.updateMetadataForDecode(settingOld, metadata, 'repair')
        #Download file chunks:
        print "downloadFile"
        storage.downloadFile(settingOld, metadata)
        #Reapir file:
        print "repair File"
        coding.repairFile(settingOld, settingNew, metadata)
        #Upload repaired chunks:
        print "upload file and metadata"
        storage.uploadFileAndMetadata(settingNew, metadata, 'repair')
        #Release write lock:
        #if settingOld.zookeeper: settingOld.zk.releaseWriteLock(metadata) #cq
        coding.decodeFile(settingNew, metadata, 'download')
    else:
        retState = storage.detectPointer(settingNew, metadata)
        if retState == False:
            #org or non_dup
            print "rebuild org or non_dup %s" % (metadata.filename)
            storage.downloadMetadata(settingOld, metadata)
            coding.updateMetadataForDecode(settingOld, metadata, 'repair')
            storage.downloadFile(settingOld, metadata)
            coding.repairFile(settingOld, settingNew, metadata)
            storage.uploadFileAndMetadata(settingNew, metadata, 'repair')
            coding.decodeFile(settingNew, metadata, 'download')
        else:
            print "rebuild pointer %s" % (metadata.filename)
            storage.repairPointer(settingOld, settingNew, metadata)
Example #8
0
def deleteFile(setting, metadata):
    '''Workflow of Delete file.'''
    if setting.deduplication == False:
        #Acquire write lock if using ZooKeeper:
        #if setting.zookeeper: setting.zk.getWriteLock(metadata) #cq
        #Download metadata:
        storage.downloadMetadata(setting, metadata)
        #Delete chunk files and metadata:
        storage.deleteChunkAndMetadata(setting, metadata)
        #Release write lock:
        #if setting.zookeeper: setting.zk.releaseWriteLock(metadata) #cq
    else:
        orgState = storage.detectOrgState(setting, metadata)
        if orgState == 3:
            # non_dup
            print "remove non_dup"
            #Download metadata:
            storage.downloadMetadata(setting, metadata)
            #Delete chunk files and metadata:
            storage.deleteChunkAndMetadata(setting, metadata)
        elif orgState == 2:
            # leaf
            print "remove leaf"
            storage.deletePointer(setting, metadata)
        elif orgState == 1:
            # org
            print "remove org"
            storage.downloadMetadata(setting, metadata)
            storage.deleteChunkAndMetadata(setting, metadata)
            dupFileName = storage.findOnePointer(setting, metadata)
            dupMetadata = common.FileMetadata(dupFileName, 0,
                                              setting.totalnode,
                                              setting.coding)
            storage.deletePointer(setting, dupMetadata)
            coding.encodeFile(setting, dupMetadata)
            storage.uploadFileAndMetadata(setting, dupMetadata, 'upload')
            storage.updatePointers(setting, metadata, dupMetadata)