コード例 #1
0
ファイル: replica.py プロジェクト: ricsxn/rucio
    def post(self):
        """
        List dataset replicas for multiple DIDs.

        .. :quickref: DatasetReplicasBulk; List dataset replicas (bulk).

        :<json list dids: List of DIDs for querying the datasets.
        :resheader Content-Type: application/x-json-stream
        :status 200: OK.
        :status 400: Bad Request.
        :status 401: Invalid auth token.
        :status 406: Not Acceptable.
        :status 500: Internal Error.
        :returns: A dictionary containing all replicas information.
        """

        json_data = request.data
        try:
            params = parse_response(json_data)
            dids = params['dids']
            didslength = len(dids)
        except KeyError as error:
            return generate_http_error_flask(
                400, 'KeyError',
                'Cannot find mandatory parameter : %s' % str(error))
        except ValueError:
            return generate_http_error_flask(
                400, 'ValueError', 'Cannot decode json parameter list')
        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
        if didslength == 0:
            return generate_http_error_flask(400, 'ValueError',
                                             'List of DIDs is empty')
        try:
            data = ""
            for row in list_dataset_replicas_bulk(
                    dids=dids, vo=request.environ.get('vo')):
                data += dumps(row, cls=APIEncoder) + '\n'
            return Response(data, content_type='application/x-json-stream')
        except InvalidObject as error:
            return generate_http_error_flask(
                400, 'InvalidObject',
                'Cannot validate DIDs: %s' % (str(error)))
        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
コード例 #2
0
    def POST(self):
        """
        List dataset replicas for multiple DIDs.

        HTTP Success:
            200 OK

        HTTP Error:
            400 Bad Request
            401 Unauthorized
            406 Not Acceptable
            500 InternalError

        :returns: A dictionary containing all replicas information.
        """
        header('Content-Type', 'application/x-json-stream')
        json_data = data()
        try:
            params = parse_response(json_data)
            dids = params['dids']
            didslength = len(dids)
        except KeyError as error:
            raise generate_http_error(
                400, 'KeyError',
                'Cannot find mandatory parameter : %s' % str(error))
        except ValueError:
            raise generate_http_error(400, 'ValueError',
                                      'Cannot decode json parameter list')
        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)
        if didslength == 0:
            raise generate_http_error(400, 'ValueError',
                                      'List of DIDs is empty')
        try:
            for row in list_dataset_replicas_bulk(dids=dids,
                                                  vo=ctx.env.get('vo')):
                yield dumps(row, cls=APIEncoder) + '\n'
        except InvalidObject as error:
            raise generate_http_error(
                400, 'InvalidObject',
                'Cannot validate DIDs: %s' % (str(error)))
        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)
コード例 #3
0
ファイル: replicas.py プロジェクト: vokac/rucio
 def generate(vo):
     for row in list_dataset_replicas_bulk(dids=dids, vo=vo):
         yield dumps(row, cls=APIEncoder) + '\n'