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. :status 500: Internal Error. :returns: List of dicts of bad file replicas. """ result = [] state = request.args.get('state', None) rse = request.args.get('rse', None) younger_than = request.args.get('younger_than', None) older_than = request.args.get('older_than', None) limit = request.args.get('limit', None) list_pfns = request.args.get('list_pfns', None) if isinstance(state, string_types): state = BadFilesStatus.from_string(state) if younger_than: younger_than = datetime.strptime(younger_than, "%Y-%m-%dT%H:%M:%S.%f") if older_than: older_than = datetime.strptime(older_than, "%Y-%m-%dT%H:%M:%S.%f") if 'limit': limit = int(limit) if 'list_pfns': list_pfns = bool(list_pfns) 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=request.environ.get('vo')) except RucioException as error: return generate_http_error_flask(500, error.__class__.__name__, error.args[0]) except Exception as error: print(format_exc()) return error, 500 data = "" for row in result: data += dumps(row, cls=APIEncoder) + '\n' return Response(data, content_type='application/x-json-stream')
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. :status 500: Internal Error. :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.from_string(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: 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'))) except RucioException as error: return generate_http_error_flask(500, error.__class__.__name__, error.args[0]) except Exception as error: print(format_exc()) return str(error), 500
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.from_string(state) if 'rse' in params: rse = params['rse'][0] if 'younger_than' in params: younger_than = datetime.strptime(params['younger_than'], "%Y-%m-%dT%H:%M:%S.%f") if 'older_than' in params and params['older_than']: older_than = datetime.strptime(params['older_than'], "%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'
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 500: Internal Error. :returns: List of dicts of bad file replicas. """ result = [] state = request.args.get('state', None) rse = request.args.get('rse', None) younger_than = request.args.get('younger_than', None) older_than = request.args.get('older_than', None) limit = request.args.get('limit', None) list_pfns = request.args.get('list_pfns', None) if type(state) is str or type(state) is unicode: state = BadFilesStatus.from_string(state) if younger_than: younger_than = datetime.strptime(younger_than, "%Y-%m-%dT%H:%M:%S.%f") if older_than: older_than = datetime.strptime(older_than, "%Y-%m-%dT%H:%M:%S.%f") if 'limit': limit = int(limit) if 'list_pfns': list_pfns = bool(list_pfns) try: result = list_bad_replicas_status(state=state, rse=rse, younger_than=younger_than, older_than=older_than, limit=limit, list_pfns=list_pfns) except RucioException, e: return generate_http_error_flask(500, e.__class__.__name__, e.args[0][0])
def GET(self): """ List the bad or suspicious replicas by states. HTTP Success: 200 OK HTTP Error: 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 type(state) is str or type(state) is unicode: state = BadFilesStatus.from_string(state) if 'rse' in params: rse = params['rse'][0] if 'younger_than' in params: younger_than = datetime.strptime(params['younger_than'], "%Y-%m-%dT%H:%M:%S.%f") if 'older_than' in params: older_than = datetime.strptime(params['older_than'], "%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) except RucioException, e: raise generate_http_error(500, e.__class__.__name__, e.args[0][0])