Example #1
0
def getCombinedDASPopInfo(request, lastAcc=False):
    stop = datetime.now()
    start = datetime.now() - timedelta(days=30)
    par = victorinterfaceparams()

    try:
        par.setSiteName(request.GET.get('sitename', 'T%'))
        logger.info('debug. siteName = %s' % par.SiteName)
        #data = replicaPopularity(par)

        source = request.GET.get('source', '')
        if source=='':
            if par.SiteName == 'T2_CH_CERN' or par.SiteName == 'T0_CH_CERN':
                source = 'xrootd'
                par.SiteName = 'T2_CH_CERN'
            else:
                source = 'crab'
        par.setSource(source)

        if lastAcc:
            combiner = replicaCombiner(lastAcc = True)
        else:
            par.setTStart(request.GET.get('tstart', start.strftime("%Y-%m-%d")))
            par.setTStop(request.GET.get('tstop', stop.strftime("%Y-%m-%d")))
            combiner = replicaCombiner()
        data = combiner.combine(par)

    except Paramvalidationexception as e:
        #return HttpResponseBadRequest("Given %s not valid (%s)" % (e.param, e.cause))
        return HttpResponseBadRequest(e.getmessage())
    except Exception as ex:
        return HttpResponseServerError(ex)

    return HttpResponse(json.dumps(data))
Example #2
0
def getDirsInSiteWithStat(request):
    par = victorinterfaceparams()
    try:
        par.setSiteName(request.GET.get('sitename'))
        logger.info('debug. siteName = %s' % par.SiteName)

        source = request.GET.get('source', '')
        if source=='':
            par.setSource('xrootd')
        else:
            par.setSource(source)
        
        par.setTopDir(request.GET.get('topdir'))
            
        data = victorinterfaceDB.AccessStatsByDirAtSite(par)

        logger.info('getDirsInSiteWithStat data: %s' % data)

    except Paramvalidationexception as e:
        return HttpResponseBadRequest(e.getmessage())
    except victorinterfaceDB.PopularityDBException as dbe:
        return HttpResponseServerError(dbe.getmessage())
    except Exception as ex:
        return HttpResponseServerError(ex)

    return HttpResponse(json.dumps(data))
Example #3
0
def getCollectionInSiteWithStat(request, collType, lastAcc=False, source=''):
    stop = datetime.now()
    start = datetime.now() - timedelta(days=30)
    par = victorinterfaceparams()
    try:
        par.setSiteName(request.GET.get('sitename', 'T%'))
        logger.info('debug. siteName = %s' % par.SiteName)
    
        source = request.GET.get('source', '')
        if source=='':
            if par.SiteName == 'T2_CH_CERN' or par.SiteName == 'T0_CH_CERN':
                source = 'xrootd'
                par.SiteName = 'T2_CH_CERN'
            else:
                source = 'crab'
        par.setSource(source)


        if lastAcc:
            data = victorinterfaceDB.WhatInSiteWithStatLastAcc(collType, par)
        else:
            par.setTStart(request.GET.get('tstart', start.strftime("%Y-%m-%d")))
            par.setTStop(request.GET.get('tstop', stop.strftime("%Y-%m-%d")))
            data = victorinterfaceDB.WhatInSiteWithStat(collType, par)
    except Paramvalidationexception as e:
        #return HttpResponseBadRequest("Given %s not valid (%s)" % (e.param, e.cause))
        return HttpResponseBadRequest(e.getmessage())
    except victorinterfaceDB.PopularityDBException as dbe:
        #return HttpResponseBadRequest("Given %s not valid (%s)" % (e.param, e.cause))
        return HttpResponseServerError(dbe.getmessage())
    except Exception as ex:
        return HttpResponseServerError(ex)

    return HttpResponse(json.dumps(data))
Example #4
0
def getCombinedDASPopInfo(request, lastAcc=False):
    stop = datetime.now()
    start = datetime.now() - timedelta(days=30)
    par = victorinterfaceparams()

    try:
        par.setSiteName(request.GET.get('sitename', 'T%'))
        logger.info('debug. siteName = %s' % par.SiteName)
        #data = replicaPopularity(par)

        source = request.GET.get('source', '')
        if source == '':
            if par.SiteName == 'T2_CH_CERN' or par.SiteName == 'T0_CH_CERN':
                source = 'xrootd'
                par.SiteName = 'T2_CH_CERN'
            else:
                source = 'crab'
        par.setSource(source)

        if lastAcc:
            combiner = replicaCombiner(lastAcc=True)
        else:
            par.setTStart(request.GET.get('tstart',
                                          start.strftime("%Y-%m-%d")))
            par.setTStop(request.GET.get('tstop', stop.strftime("%Y-%m-%d")))
            combiner = replicaCombiner()
        data = combiner.combine(par)

    except Paramvalidationexception as e:
        #return HttpResponseBadRequest("Given %s not valid (%s)" % (e.param, e.cause))
        return HttpResponseBadRequest(e.getmessage())
    except Exception as ex:
        return HttpResponseServerError(ex)

    return HttpResponse(json.dumps(data))
Example #5
0
def getCollectionInSiteWithStat(request, collType, lastAcc=False, source=''):
    stop = datetime.now()
    start = datetime.now() - timedelta(days=30)
    par = victorinterfaceparams()
    try:
        par.setSiteName(request.GET.get('sitename', 'T%'))
        logger.info('debug. siteName = %s' % par.SiteName)

        source = request.GET.get('source', '')
        if source == '':
            if par.SiteName == 'T2_CH_CERN' or par.SiteName == 'T0_CH_CERN':
                source = 'xrootd'
                par.SiteName = 'T2_CH_CERN'
            else:
                source = 'crab'
        par.setSource(source)

        if lastAcc:
            data = victorinterfaceDB.WhatInSiteWithStatLastAcc(collType, par)
        else:
            par.setTStart(request.GET.get('tstart',
                                          start.strftime("%Y-%m-%d")))
            par.setTStop(request.GET.get('tstop', stop.strftime("%Y-%m-%d")))
            data = victorinterfaceDB.WhatInSiteWithStat(collType, par)
    except Paramvalidationexception as e:
        #return HttpResponseBadRequest("Given %s not valid (%s)" % (e.param, e.cause))
        return HttpResponseBadRequest(e.getmessage())
    except victorinterfaceDB.PopularityDBException as dbe:
        #return HttpResponseBadRequest("Given %s not valid (%s)" % (e.param, e.cause))
        return HttpResponseServerError(dbe.getmessage())
    except Exception as ex:
        return HttpResponseServerError(ex)

    return HttpResponse(json.dumps(data))
Example #6
0
def getDirsInSiteWithStat(request):
    par = victorinterfaceparams()
    try:
        par.setSiteName(request.GET.get('sitename'))
        logger.info('debug. siteName = %s' % par.SiteName)

        source = request.GET.get('source', '')
        if source == '':
            par.setSource('xrootd')
        else:
            par.setSource(source)

        par.setTopDir(request.GET.get('topdir'))

        data = victorinterfaceDB.AccessStatsByDirAtSite(par)

        logger.info('getDirsInSiteWithStat data: %s' % data)

    except Paramvalidationexception as e:
        return HttpResponseBadRequest(e.getmessage())
    except victorinterfaceDB.PopularityDBException as dbe:
        return HttpResponseServerError(dbe.getmessage())
    except Exception as ex:
        return HttpResponseServerError(ex)

    return HttpResponse(json.dumps(data))
Example #7
0
    def get_json_data(self,
                      site='T%',
                      source='',
                      timestart=datetime.now(),
                      timestop=(datetime.now() - timedelta(days=30))):

        self.validateSiteName(site)

        if not Lexicon.accsource(source):
            raise popularityInterfaceException(
                "Given source (access data source) is not valid")

        par = victorinterfaceparams()
        try:
            par.setSiteName(site)
            logger.info('debug. siteName = %s' % par.SiteName)

            if source == '':
                if par.SiteName == 'T2_CH_CERN' or par.SiteName == 'T0_CH_CERN':
                    source = 'xrootd'
                    par.SiteName = 'T2_CH_CERN'
                else:
                    source = 'crab'
            par.setSource(source)

            if self.lastAcc:
                pop_data = victorinterfaceDB.WhatInSiteWithStatLastAcc(
                    collType='BlocksStat', params=par)
            else:
                par.setTStart(timestart)
                par.setTStop(timestop)
                pop_data = victorinterfaceDB.WhatInSiteWithStat(
                    collType='BlocksStat', params=par)
        except Paramvalidationexception as e:
            raise popularityInterfaceException(e.getmessage())
        except victorinterfaceDB.PopularityDBException as dbe:
            raise popularityInterfaceException(dbe.getmessage())
        except Exception as ex:
            raise popularityInterfaceException(ex)

        try:
            pop_data[site]
        except KeyError:
            logger.warning('WARNING: empty popularity results for %s' % site)
        return pop_data
Example #8
0
    def get_json_data(self, site='T%', source='', timestart=datetime.now(), timestop=(datetime.now() - timedelta(days=30))):
        
        self.validateSiteName(site)
            
        if not Lexicon.accsource(source):
            raise popularityInterfaceException("Given source (access data source) is not valid")

        par = victorinterfaceparams()
        try:
            par.setSiteName(site)
            logger.info('debug. siteName = %s' % par.SiteName)
    
            if source=='':
                if par.SiteName == 'T2_CH_CERN' or par.SiteName == 'T0_CH_CERN':
                    source = 'xrootd'
                    par.SiteName = 'T2_CH_CERN'
                else:
                    source = 'crab'
            par.setSource(source)

            
            if self.lastAcc:
                pop_data = victorinterfaceDB.WhatInSiteWithStatLastAcc(collType='BlocksStat', params=par)
            else:
                par.setTStart(timestart)
                par.setTStop(timestop)
                pop_data = victorinterfaceDB.WhatInSiteWithStat(collType='BlocksStat', params=par)
        except Paramvalidationexception as e:
            raise popularityInterfaceException(e.getmessage())
        except victorinterfaceDB.PopularityDBException as dbe:
            raise popularityInterfaceException(dbe.getmessage())
        except Exception as ex:
            raise popularityInterfaceException(ex)

        try:
            pop_data[site]
        except KeyError:
            logger.warning('WARNING: empty popularity results for %s' % site)
        return pop_data