def get(self): """ List the bad or suspicious replicas by states. .. :quickref: BadReplicasStates; List bad replicas. :query state: The state of the file (SUSPICIOUS or BAD). :query rse: The RSE name. :query younger_than: date in format "%Y-%m-%dT%H:%M:%S.%f" to select bad replicas younger than this date. :query older_than: date in format "%Y-%m-%dT%H:%M:%S.%f" to select bad replicas older than this date. :query limit: The maximum number of replicas returned. :query list_pfns: Flag to include pfns. :resheader Content-Type: application/x-json-stream :status 200: OK. :status 401: Invalid auth token. :status 406: Not Acceptable. :returns: List of dicts of bad file replicas. """ state, rse, younger_than, older_than, limit, list_pfns = None, None, None, None, None, None if request.query_string: query_string = request.query_string.decode(encoding='utf-8') try: params = loads(unquote(query_string)) except ValueError: params = parse_qs(query_string) if 'state' in params: state = params['state'][0] if isinstance(state, string_types): state = BadFilesStatus(state) if 'rse' in params: rse = params['rse'][0] if 'younger_than' in params: younger_than = datetime.strptime(params['younger_than'][0], "%Y-%m-%dT%H:%M:%S.%f") if 'older_than' in params and params['older_than']: older_than = datetime.strptime(params['older_than'][0], "%Y-%m-%dT%H:%M:%S.%f") if 'limit' in params: limit = int(params['limit'][0]) if 'list_pfns' in params: list_pfns = bool(params['list_pfns'][0]) def generate(vo): for row in list_bad_replicas_status(state=state, rse=rse, younger_than=younger_than, older_than=older_than, limit=limit, list_pfns=list_pfns, vo=vo): yield dumps(row, cls=APIEncoder) + '\n' return try_stream(generate(vo=request.environ.get('vo')))
def GET(self): """ List the bad or suspicious replicas by states. HTTP Success: 200 OK HTTP Error: 406 Not Acceptable 500 InternalError """ header('Content-Type', 'application/x-json-stream') result = [] state, rse, younger_than, older_than, limit, list_pfns = None, None, None, None, None, None if ctx.query: try: params = loads(unquote(ctx.query[1:])) except ValueError: params = parse_qs(ctx.query[1:]) if 'state' in params: state = params['state'][0] if isinstance(state, string_types): state = BadFilesStatus(state) if 'rse' in params: rse = params['rse'][0] if 'younger_than' in params: younger_than = datetime.strptime(params['younger_than'][0], "%Y-%m-%dT%H:%M:%S.%f") if 'older_than' in params and params['older_than']: older_than = datetime.strptime(params['older_than'][0], "%Y-%m-%dT%H:%M:%S.%f") if 'limit' in params: limit = int(params['limit'][0]) if 'list_pfns' in params: list_pfns = bool(params['list_pfns'][0]) try: result = list_bad_replicas_status(state=state, rse=rse, younger_than=younger_than, older_than=older_than, limit=limit, list_pfns=list_pfns, vo=ctx.env.get('vo')) except RucioException as error: raise generate_http_error(500, error.__class__.__name__, error.args[0]) except Exception as error: print(format_exc()) raise InternalError(error) for row in result: yield dumps(row, cls=APIEncoder) + '\n'