How to use the rucio.common.exception.DataIdentifierNotFound function in rucio

To help you get started, we’ve selected a few rucio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rucio / rucio / lib / rucio / core / did.py View on Github external
Get all metadata for a given did

    :param scope: the scope of did
    :param name: the name of the did
    """
    if session.bind.dialect.name == 'oracle':
        oracle_version = int(session.connection().connection.version.split('.')[0])
        if oracle_version < 12:
            raise NotImplementedError

    try:
        row = session.query(models.DidMeta).filter_by(scope=scope, name=name).one()
        meta = getattr(row, 'meta')
        return json.loads(meta) if session.bind.dialect.name in ['oracle', 'sqlite'] else meta
    except NoResultFound:
        raise exception.DataIdentifierNotFound("No generic metadata found for '%(scope)s:%(name)s'" % locals())
github rucio / rucio / lib / rucio / web / rest / flaskapi / v1 / redirect.py View on Github external
replicas = sort_ranking(dictreplica, client_location)
                else:
                    replicas = sort_random(dictreplica)

                # stream URLs
                idx = 1
                for replica in replicas:
                    data += '  ' + replica + '\n'
                    idx += 1

                data += ' \n'

            # don't forget to send the metalink footer
            data += '\n'
            return Response(data, content_type='application/metalink4+xml')
        except DataIdentifierNotFound as error:
            return generate_http_error_flask(404, 'DataIdentifierNotFound', error.args[0])
        except ReplicaNotFound as error:
            return generate_http_error_flask(404, 'ReplicaNotFound', error.args[0])
        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
github rucio / rucio / lib / rucio / core / did.py View on Github external
"""
    Return list of users following a did

    :param scope: The scope name.
    :param name: The data identifier name.
    :param session: The database session in use.
    """
    try:
        query = session.query(models.DidsFollowed).filter_by(scope=scope, name=name).all()

        for user in query:
            # Return a dictionary of users to be rendered as json.
            yield {'user': user.account}

    except NoResultFound:
        raise exception.DataIdentifierNotFound("Data identifier '%s:%s' not found" % (scope, name))
github rucio / rucio / lib / rucio / core / rule.py View on Github external
if rule.source_replica_expression:
            source_rses = parse_expression(rule.source_replica_expression, session=session)
        else:
            source_rses = []

    # 2. Create the rse selector
    with record_timer_block('rule.add_rule.create_rse_selector'):
        rseselector = RSESelector(account=rule['account'], rses=rses, weight=rule.weight, copies=rule.copies, ignore_account_limit=rule.ignore_account_limit, session=session)

    # 3. Get the did
    with record_timer_block('rule.add_rule.get_did'):
        try:
            did = session.query(models.DataIdentifier).filter(models.DataIdentifier.scope == rule.scope,
                                                              models.DataIdentifier.name == rule.name).one()
        except NoResultFound:
            raise DataIdentifierNotFound('Data identifier %s:%s is not valid.' % (rule.scope, rule.name))
        except TypeError, e:
            raise InvalidObject(e.args)

    # 5. Resolve the did to its contents
    with record_timer_block('rule.add_rule.resolve_dids_to_locks_replicas'):
        # Get all Replicas, not only the ones interesting for the rse_expression
        datasetfiles, locks, replicas, source_replicas = __resolve_did_to_locks_and_replicas(did=did,
                                                                                             nowait=True,
                                                                                             restrict_rses=[rse['id'] for rse in rses],
                                                                                             source_rses=[rse['id'] for rse in source_rses],
                                                                                             session=session)

    # 6. Apply the replication rule to create locks, replicas and transfers
    with record_timer_block('rule.add_rule.create_locks_replicas_transfers'):
        try:
            __create_locks_replicas_transfers(datasetfiles=datasetfiles,
github rucio / rucio / lib / rucio / core / did.py View on Github external
"""

    did_r = {'scope': None, 'name': None, 'type': None}
    try:
        r = session.query(models.DataIdentifier).filter_by(scope=scope, name=name, deleted=False).one()
        if r:
            if r.type == models.DataIdType.FILE:
                did_r = {'scope': r.scope, 'name': r.name, 'type': r.type, 'account': r.account}
            else:
                did_r = {'scope': r.scope, 'name': r.name, 'type': r.type,
                         'account': r.account, 'open': r.open, 'monotonic': r.monotonic}

            #  To add:  created_at, updated_at, deleted_at, deleted, monotonic, hidden, obsolete, complete
            #  ToDo: Add json encoder for datetime
    except NoResultFound:
        raise exception.DataIdentifierNotFound("Data identifier '%(scope)s:%(name)s' not found" % locals())

    return did_r
github rucio / rucio / lib / rucio / core / did.py View on Github external
"""
    Get data identifier metadata

    :param scope: The scope name.
    :param name: The data identifier name.
    :param session: The database session in use.
    """
    try:
        row = session.query(models.DataIdentifier).filter_by(scope=scope, name=name).\
            with_hint(models.DataIdentifier, "INDEX(DIDS DIDS_PK)", 'oracle').one()
        d = {}
        for column in row.__table__.columns:
            d[column.name] = getattr(row, column.name)
        return d
    except NoResultFound:
        raise exception.DataIdentifierNotFound("Data identifier '%(scope)s:%(name)s' not found" % locals())
github rucio / rucio / lib / rucio / core / did.py View on Github external
def __diddriller(pdid):
        query_associ = session.query(models.DataIdentifierAssociation).filter_by(scope=pdid['scope'], name=pdid['name'])
        for row in query_associ.order_by('child_name').yield_per(5):
            parent = {'scope': pdid['scope'], 'name': pdid['name']}
            cdid = {'scope': row.child_scope, 'name': row.child_name, 'type': row.child_type, 'parent': parent, 'level': pdid['level'] + 1}
            yield cdid
            if cdid['type'] != DIDType.FILE and recursive:
                for did in __diddriller(cdid):
                    yield did

    if name is None:
        topdids = __topdids(scope)
    else:
        topdids = session.query(models.DataIdentifier).filter_by(scope=scope, name=name).first()
        if topdids is None:
            raise exception.DataIdentifierNotFound("Data identifier '%(scope)s:%(name)s' not found" % locals())
        topdids = [{'scope': topdids.scope, 'name': topdids.name, 'type': topdids.did_type, 'parent': None, 'level': 0}]

    if name is None:
        for topdid in topdids:
            yield topdid
            if recursive:
                for did in __diddriller(topdid):
                    yield did
    else:
        for topdid in topdids:
            for did in __diddriller(topdid):
                yield did
github rucio / rucio / lib / rucio / core / did.py View on Github external
def __didtree(topdids, parent=None, level=0, depth=-1):
        # depth > 0 for limited recursive, -1 for complete recursive
        dids = []
        for pdid in topdids:
            dids.append({'scope': pdid['scope'], 'name': pdid['name'], 'type': pdid['type'], 'parent': parent, 'level': level})
            if pdid['type'] != models.DataIdType.FILE and (depth > 0 or depth == -1):
                if depth != -1:
                    depth -= 1
                try:
                    for row in query_associ.filter_by(name=pdid['name']):
                        cdid = {'scope': row.child_scope, 'name': row.child_name, 'type': row.child_type}
                        dids.extend(__didtree([cdid], parent={'scope': row.scope, 'name': row.name}, level=level + 1, depth=depth))
                except NoResultFound:
                    raise exception.DataIdentifierNotFound("Data identifier '%(scope)s:%(name)s' not found" % locals())
        return dids
github rucio / rucio / lib / rucio / core / did.py View on Github external
'account': result.account, 'bytes': result.bytes, 'length': 1,
                    'md5': result.md5, 'adler32': result.adler32}
        else:
            if dynamic:
                bytes, length, events = __resolve_bytes_length_events_did(scope=scope, name=name, session=session)
                # replace None value for bytes with zero
                if bytes is None:
                    bytes = 0
            else:
                bytes, length = result.bytes, result.length
            return {'scope': result.scope, 'name': result.name, 'type': result.did_type,
                    'account': result.account, 'open': result.is_open,
                    'monotonic': result.monotonic, 'expired_at': result.expired_at,
                    'length': length, 'bytes': bytes}
    except NoResultFound:
        raise exception.DataIdentifierNotFound("Data identifier '%(scope)s:%(name)s' not found" % locals())
github rucio / rucio / lib / rucio / core / did.py View on Github external
session=session)

            elif parent_did.did_type == DIDType.CONTAINER:
                __add_collections_to_container(scope=attachment['scope'],
                                               name=attachment['name'],
                                               collections=attachment['dids'],
                                               account=account, session=session)

            parent_did_condition.append(and_(models.DataIdentifier.scope == parent_did.scope,
                                             models.DataIdentifier.name == parent_did.name))

            parent_dids.append({'scope': parent_did.scope,
                                'name': parent_did.name,
                                'rule_evaluation_action': DIDReEvaluation.ATTACH})
        except NoResultFound:
            raise exception.DataIdentifierNotFound("Data identifier '%s:%s' not found" % (attachment['scope'], attachment['name']))

        session.bulk_insert_mappings(models.UpdatedDID, parent_dids)