Beispiel #1
0
def file_info(lfn, verbose=None):
    query = 'find file.name, file.numevents, file.size, file.createdate, file.createby, file.moddate, file.modby where file=%s' % lfn
    params = {"api": "executeQuery", "apiversion": "DBS_2_0_9", "query": query}
    default_instance = os.environ.get('DBS_INSTANCE')
    for inst in dbs_instances():
        os.environ['DBS_INSTANCE'] = inst
        data = urllib2.urlopen(dbs_url(), urllib.urlencode(params))
        try:
            rec = [f for f in qlxml_parser(data, 'file')][0]
        except:
            continue
        rec['logical_file_name'] = rec['file']['file.name']
        rec['size'] = rec['file']['file.size']
        rec['nevents'] = rec['file']['file.numevents']
        rec['created'] = time.strftime(
            "%Y-%m-%d %H:%M:%S GMT",
            time.gmtime(rec['file']['file.createdate']))
        rec['createdby'] = rec['file']['file.createby']
        rec['modified'] = time.strftime(
            "%Y-%m-%d %H:%M:%S GMT", time.gmtime(rec['file']['file.moddate']))
        rec['modifiedby'] = rec['file']['file.modby']
        del rec['file']
        lfnobj = File(rec)
        try:
            pfnlist, selist = get_pfns(lfn, verbose)
            if not selist:
                query = 'find site where file=%s' % lfn
                params.update({"query": query})
                data = urllib2.urlopen(dbs_url(), urllib.urlencode(params))
                try:
                    rec = [f for f in qlxml_parser(data, 'site')][0]
                    sename = rec['site']['site']
                    selist = [sename]
                    pfnlist = lfn2pfn(lfn, sename)
                except:
                    pass
            lfnobj.assign('pfn', pfnlist)
            lfnobj.assign('se', selist)
        except:
            traceback.print_exc()
            lfnobj.assign('pfn', [])
            lfnobj.assign('se', [])
        os.environ['DBS_INSTANCE'] = default_instance
        lfnobj.assign('dbs_instance', inst)
        return lfnobj
    os.environ['DBS_INSTANCE'] = default_instance
    msg = 'Fail to look-up LFN in %s DBS instances' % dbs_instances()
    print_error(msg)
Beispiel #2
0
def file_info(lfn, verbose=None):
    query  = 'find file.name, file.numevents, file.size, file.createdate, file.createby, file.moddate, file.modby where file=%s' % lfn
    params = {"api":"executeQuery", "apiversion": "DBS_2_0_9", "query":query}
    default_instance = os.environ.get('DBS_INSTANCE')
    for inst in dbs_instances():
        os.environ['DBS_INSTANCE'] = inst
        data   = urllib2.urlopen(dbs_url(), urllib.urlencode(params))
        try:
            rec = [f for f in qlxml_parser(data, 'file')][0]
        except:
            continue
        rec['logical_file_name'] = rec['file']['file.name']
        rec['size'] = rec['file']['file.size']
        rec['nevents'] = rec['file']['file.numevents']
        rec['created'] = time.strftime("%Y-%m-%d %H:%M:%S GMT", time.gmtime(rec['file']['file.createdate']))
        rec['createdby'] = rec['file']['file.createby']
        rec['modified'] = time.strftime("%Y-%m-%d %H:%M:%S GMT", time.gmtime(rec['file']['file.moddate']))
        rec['modifiedby'] = rec['file']['file.modby']
        del rec['file']
        lfnobj = File(rec)
        try:
            pfnlist, selist = get_pfns(lfn, verbose)
            if  not selist:
                query = 'find site where file=%s' % lfn
                params.update({"query":query})
                data  = urllib2.urlopen(dbs_url(), urllib.urlencode(params))
                try:
                    rec = [f for f in qlxml_parser(data, 'site')][0]
                    sename = rec['site']['site']
                    selist = [sename]
                    pfnlist = lfn2pfn(lfn, sename)
                except:
                    pass
            lfnobj.assign('pfn', pfnlist)
            lfnobj.assign('se', selist)
        except:
            traceback.print_exc()
            lfnobj.assign('pfn', [])
            lfnobj.assign('se', [])
        os.environ['DBS_INSTANCE'] = default_instance
        lfnobj.assign('dbs_instance', inst)
        return lfnobj
    os.environ['DBS_INSTANCE'] = default_instance
    msg = 'Fail to look-up LFN in %s DBS instances' % dbs_instances()
    print_error(msg)
Beispiel #3
0
def get_dbs_se(lfn):
    "Get original SE from DBS for given LFN"
    # TODO: should have transparent access to DBS2/DBS3
    query = 'find site where file=%s' % lfn
    params = {"api": "executeQuery", "apiversion": "DBS_2_0_9", "query": query}
    default_instance = os.environ.get('DBS_INSTANCE')
    for inst in dbs_instances():
        params.update({"query": query})
        os.environ['DBS_INSTANCE'] = inst
        data = urllib2.urlopen(dbs_url(), urllib.urlencode(params))
        try:
            rec = [f for f in qlxml_parser(data, 'site')][0]
            sename = rec['site']['site']
        except:
            continue
        os.environ['DBS_INSTANCE'] = default_instance
        return sename
    os.environ['DBS_INSTANCE'] = default_instance
Beispiel #4
0
def get_dbs_se(lfn):
    "Get original SE from DBS for given LFN"
    # TODO: should have transparent access to DBS2/DBS3
    query = 'find site where file=%s' % lfn
    params = {"api":"executeQuery", "apiversion": "DBS_2_0_9", "query":query}
    default_instance = os.environ.get('DBS_INSTANCE')
    for inst in dbs_instances():
        params.update({"query":query})
        os.environ['DBS_INSTANCE'] = inst
        data  = urllib2.urlopen(dbs_url(), urllib.urlencode(params))
        try:
            rec = [f for f in qlxml_parser(data, 'site')][0]
            sename = rec['site']['site']
        except:
            continue
        os.environ['DBS_INSTANCE'] = default_instance
        return sename
    os.environ['DBS_INSTANCE'] = default_instance
Beispiel #5
0
def dbs_instance(arg=None):
    """
    cmssh command to show or set DBS instance
    Examples:
        cmssh> dbs_instance
        cmssh> dbs_instance cms_dbs_prod_global
    """
    arg = arg.strip()
    if arg:
        if validate_dbs_instance(arg):
            os.environ['DBS_INSTANCE'] = arg
            print "Switch to %s DBS instance" % arg
        else:
            print "Invalid DBS instance"
    else:
        msg  = "DBS instance is set to: %s" \
                % os.environ.get('DBS_INSTANCE', 'global')
        print msg
    print '\nAvailable DBS instances:'
    for inst in dbs_instances():
        print inst
Beispiel #6
0
def dbs_instance(arg=None):
    """
    cmssh command to show or set DBS instance
    Examples:
        cmssh> dbs_instance
        cmssh> dbs_instance cms_dbs_prod_global
    """
    arg = arg.strip()
    if  arg:
        if  validate_dbs_instance(arg):
            os.environ['DBS_INSTANCE'] = arg
            print "Switch to %s DBS instance" % arg
        else:
            print "Invalid DBS instance"
    else:
        msg  = "DBS instance is set to: %s" \
                % os.environ.get('DBS_INSTANCE', 'global')
        print msg
    print '\nAvailable DBS instances:'
    for inst in dbs_instances():
        print inst
Beispiel #7
0
def validate_dbs_instance(inst):
    "Validate DBS url"
    if inst in dbs_instances():
        return True
    return False
Beispiel #8
0
def validate_dbs_instance(inst):
    "Validate DBS url"
    if inst in dbs_instances():
        return True
    return False