def statusHandler(srvObj, reqPropsObj, sessionId):
    """
    Handles the status handling
    """
    res = None
    if (statusResDic.has_key(sessionId)):
        res = statusResDic[sessionId]
    else:
        res = AsyncListRetrieveStatusResponse()
        res.errorcode = AsyncListRetrieveProtocolError.INVALID_UUID
        res.session_uuid = sessionId
    return res
Exemplo n.º 2
0
def genInstantResponse(srvObj, asyncListReqObj):
    """
    Generate instance response this is why the command is called "asynch" because
    it instantly return to users and launch threads to handle the file retrieval behind the scene
    Major motivation is to deal with files offline (i.e. on Tapes)
    """
    clientUrl = asyncListReqObj.url
    sessionId = asyncListReqObj.session_uuid
    res = AsyncListRetrieveResponse(sessionId, 0, [])
    statuRes = AsyncListRetrieveStatusResponse()
    statuRes.errorcode = AsyncListRetrieveProtocolError.OK
    statuRes.session_uuid = sessionId

    if (clientUrl is None or sessionId is None):
        res.errorcode = -1
        return res
    fileInfoList = srvObj.getDb().getFileSummary1(None, [],
                                                  asyncListReqObj.file_id,
                                                  None, [], None, 0)
    baseNameDic = {}
    for f in fileInfoList:
        file_id = f[ngamsDbCore.SUM1_FILE_ID]
        if (baseNameDic.has_key(file_id)):
            #info(3, "duplication detected %s" % basename)
            continue  #get rid of multiple versions
        else:
            baseNameDic[file_id] = 1
        file_size = f[ngamsDbCore.SUM1_FILE_SIZE]
        filename = f[ngamsDbCore.SUM1_MT_PT] + "/" + f[
            ngamsDbCore.SUM1_FILENAME]
        status = AsyncListRetrieveProtocolError.OK  #online
        if (ngamsMWACortexTapeApi.isFileOnTape(filename) == 1):
            status = AsyncListRetrieveProtocolError.FILE_NOT_ONLINE  #offline
        finfo = FileInfo(file_id, file_size, status)
        res.file_info.append(finfo)
        statuRes.number_bytes_to_be_delivered += file_size
        statuRes.number_files_to_be_delivered += 1
    statusResDic[sessionId] = statuRes
    for ff in asyncListReqObj.file_id:
        if (not baseNameDic.has_key(ff)):
            finfo = FileInfo(ff, 0,
                             AsyncListRetrieveProtocolError.FILE_NOT_FOUND)
            res.file_info.append(finfo)

    return res