Exemplo n.º 1
0
    def get(self, scope, name, rse):
        """
        List request for given DID to a destination RSE.

        .. :quickref: RequestGet; list requests

        :param scope: data identifier scope.
        :param name: data identifier name.
        :param rse: destination RSE.
        :reqheader Content-Type: application/json
        :status 200: Request found.
        :status 404: Request not found.
        :status 406: Not Acceptable.
        """

        try:
            res = json.dumps(request.get_request_by_did(
                scope=scope,
                name=name,
                rse=rse,
                issuer=f_request.environ.get('issuer')),
                             cls=APIEncoder)
            return Response(res, content_type="application/json")
        except Exception:
            return generate_http_error_flask(
                404, 'RequestNotFound',
                'No request found for DID %s:%s at RSE %s' %
                (scope, name, rse))
Exemplo n.º 2
0
    def GET(self, scope, name, rse):
        """
        List request for given DID to a destination RSE.

        HTTP Success:
            200 OK

        HTTP Error:
            401 Unauthorized
            404 Request Not Found
            406 Not Acceptable
        """

        header('Content-Type', 'application/json')

        try:
            return render_json(
                **request.get_request_by_did(scope=scope,
                                             name=name,
                                             rse=rse,
                                             issuer=ctx.env.get('issuer'),
                                             vo=ctx.env.get('vo')))
        except:
            raise generate_http_error(
                404, 'RequestNotFound',
                'No request found for DID %s:%s at RSE %s' %
                (scope, name, rse))
Exemplo n.º 3
0
    def get(self, scope_name, rse):
        """
        List request for given DID to a destination RSE.

        .. :quickref: RequestGet; list requests

        :param scope_name: data identifier (scope)/(name).
        :param rse: destination RSE.
        :reqheader Content-Type: application/json
        :status 200: Request found.
        :status 404: Request not found.
        :status 406: Not Acceptable.
        """
        try:
            scope, name = parse_scope_name(scope_name)
        except ValueError as error:
            return generate_http_error_flask(400, 'ValueError', error.args[0])
        except Exception as error:
            print(format_exc())
            return str(error), 500

        try:
            request_data = request.get_request_by_did(
                scope=scope,
                name=name,
                rse=rse,
                issuer=f_request.environ.get('issuer'),
                vo=f_request.environ.get('vo'))
            return Response(json.dumps(request_data, cls=APIEncoder),
                            content_type='application/json')
        except Exception:
            return generate_http_error_flask(
                404, 'RequestNotFound',
                'No request found for DID %s:%s at RSE %s' %
                (scope, name, rse))
Exemplo n.º 4
0
    def get(self, scope_name, rse):
        """
        List request for given DID to a destination RSE.

        .. :quickref: RequestGet; list requests

        :param scope_name: data identifier (scope)/(name).
        :param rse: destination RSE.
        :reqheader Content-Type: application/json
        :status 200: Request found.
        :status 404: Request not found.
        :status 406: Not Acceptable.
        """
        try:
            scope, name = parse_scope_name(scope_name,
                                           flask.request.environ.get('vo'))
        except ValueError as error:
            return generate_http_error_flask(400, error)

        try:
            request_data = request.get_request_by_did(
                scope=scope,
                name=name,
                rse=rse,
                issuer=flask.request.environ.get('issuer'),
                vo=flask.request.environ.get('vo'),
            )
            return Response(json.dumps(request_data, cls=APIEncoder),
                            content_type='application/json')
        except RequestNotFound as error:
            return generate_http_error_flask(
                404, error.__class__.__name__,
                f'No request found for DID {scope}:{name} at RSE {rse}')
Exemplo n.º 5
0
    def test_api_request(self):
        """ REQUEST (API): Test external representation of requests """

        did = generate_uuid()
        add_did(self.scope_name, did, 'dataset', issuer='root', account=self.account_name, rse=self.rse_name, **self.vo)

        requests = [{
            'dest_rse_id': self.rse2_id,
            'source_rse_id': self.rse_id,
            'request_type': constants.RequestType.TRANSFER,
            'request_id': generate_uuid(),
            'name': did,
            'scope': self.scope_name,
            'account': self.account_name,
            'rule_id': generate_uuid(),
            'retry_count': 1,
            'requested_at': datetime.now(),
            'attributes': {
                'activity': 'User Subscription',
                'bytes': 10,
                'md5': '',
                'adler32': ''
            }
        }]

        reqs = queue_requests(requests, issuer='root', **self.vo)  # this does not pass in the source rse
        reqs = list(reqs)
        assert_not_equal(0, len(reqs))
        for r in reqs:
            assert_equal(r['scope'], self.scope_name)
            assert_equal(r['account'], self.account_name)
            assert_equal(r['source_rse'], self.rse_name)
            assert_equal(r['dest_rse'], self.rse2_name)

        out = get_request_by_did(self.scope_name, did, self.rse2_name, issuer='root', **self.vo)
        assert_equal(out['scope'], self.scope_name)
        assert_equal(out['account'], self.account_name)
        assert_equal(out['dest_rse'], self.rse2_name)
        assert_equal(out['source_rse'], self.rse_name)

        out = list_requests([self.rse_name], [self.rse2_name], [constants.RequestState.QUEUED], issuer='root', **self.vo)
        out = list(out)
        assert_not_equal(0, len(out))
        assert_in(self.scope_name, [req['scope'] for req in out])
        for req in out:
            if req['scope'] == self.scope_name:
                assert_equal(req['scope'], self.scope_name)
                assert_equal(req['account'], self.account_name)
                assert_equal(req['dest_rse'], self.rse2_name)
                assert_equal(req['source_rse'], self.rse_name)
Exemplo n.º 6
0
    def GET(self, scope, name, rse):
        """
        List request for given DID to a destination RSE.

        HTTP Success:
            200 OK

        HTTP Error:
            401 Unauthorized
            404 Request Not Found
        """

        header("Content-Type", "application/json")

        try:
            return json.dumps(
                request.get_request_by_did(scope=scope, name=name, rse=rse, issuer=ctx.env.get("issuer")),
                default=json_serial,
            )
        except:
            raise generate_http_error(
                404, "RequestNotFound", "No request found for DID %s:%s at RSE %s" % (scope, name, rse)
            )
Exemplo n.º 7
0
    def get(self, scope_name, rse):
        """
        ---
        summary: Get Request
        description: Get a request for a given DID to a destinaion RSE.
        tags:
          - Requests
        parameters:
        - name: scope_name
          in: path
          description: Data identifier (scope)/(name).
          schema:
            type: string
          style: simple
        - name: rse
          in: path
          description: Destination rse.
          schema:
            type: string
          style: simple
        responses:
          200:
            description: OK
            content:
              application/json:
                schema:
                  description: The request associated with the DID and destination RSE.
                  type: object
                  properties:
                    id:
                      description: The id of the request.
                      type: strig
                    request_type:
                      description: The request type.
                      type: string
                      enum: ["T", "U", "D", "I", "O"]
                    scope:
                      description: The scope of the transfer.
                      type: string
                    name:
                      description: The name of the transfer.
                      type: string
                    did_type:
                      description: The did type.
                      type: string
                    dest_rse_id:
                      description: The destination RSE id.
                      type: string
                    source_rse_id:
                      description: The source RSE id.
                      type: string
                    attributes:
                      description: All attributes associated with the request.
                      type: string
                    state:
                      description: The state of the request.
                      type: string
                      enum: ["Q", "G", "S", "F", "D", "L", "N", "O", "A", "M", "U", "W", "P"]
                    external_id:
                      description: External id of the request.
                      type: string
                    external_host:
                      description: External host of the request.
                      type: string
                    retry_count:
                      description: The numbers of attempted retires.
                      type: integer
                    err_msg:
                      description: An error message if one occured.
                      type: string
                    previous_attempt_id:
                      description: The id of the previous attempt.
                      type: string
                    rule_id:
                      description: The id of the associated replication rule.
                      type: string
                    activity:
                      description: The activity of the request.
                      type: string
                    bytes:
                      description: The size of the did in bytes.
                      type: integer
                    md5:
                      description: The md5 checksum of the did to transfer.
                      type: string
                    adler32:
                      description: The adler32 checksum of the did to transfer.
                      type: string
                    dest_url:
                      description: The destination url.
                      type: string
                    submitted_at:
                      description: The time the request got submitted.
                      type: string
                    started_at:
                      description: The time the request got started.
                      type: string
                    transferred_at:
                      description: The time the request got transfered.
                      type: string
                    estimated_at:
                      description: The time the request got estimated.
                      type: string
                    submitter_id:
                      description: The id of the submitter.
                      type: string
                    estimated_stated_at:
                      description: The estimation of the started at value.
                      type: string
                    estimated_transferred_at:
                      description: The estimation of the transfered at value.
                      type: string
                    staging_started_at:
                      description: The time the staging got started.
                      type: string
                    staging_finished_at:
                      description: The time the staging got finished.
                      type: string
                    account:
                      description: The account which issued the request.
                      type: string
                    requested_at:
                      description: The time the request got requested.
                      type: string
                    priority:
                      description: The priority of the request.
                      type: integer
                    transfertool:
                      description: The transfertool used.
                      type: string
                    source_rse:
                      description: The name of the source RSE.
                      type: string
                    dest_rse:
                      description: The name of the destination RSE.
                      type: string
          401:
            description: Invalid Auth Token
          404:
            description: Not found
          406:
            description: Not acceptable
        """
        try:
            scope, name = parse_scope_name(scope_name,
                                           flask.request.environ.get('vo'))
        except ValueError as error:
            return generate_http_error_flask(400, error)

        try:
            request_data = request.get_request_by_did(
                scope=scope,
                name=name,
                rse=rse,
                issuer=flask.request.environ.get('issuer'),
                vo=flask.request.environ.get('vo'),
            )
            return Response(json.dumps(request_data, cls=APIEncoder),
                            content_type='application/json')
        except RequestNotFound as error:
            return generate_http_error_flask(
                404, error.__class__.__name__,
                f'No request found for DID {scope}:{name} at RSE {rse}')