@transactional_session
def add_replicas(rse_id, files, account, ignore_availability=True, dataset_meta=None, session=None):
    '\n    Bulk add file replicas.\n\n    :param rse_id:  The RSE id.\n    :param files:   The list of files.\n    :param account: The account owner.\n    :param ignore_availability: Ignore the RSE blocklisting.\n    :param session: The database session in use.\n\n    :returns: True is successful.\n    '

    def _expected_pfns(lfns, rse_settings, scheme, operation='write', domain='wan', protocol_attr=None):
        p = rsemgr.create_protocol(rse_settings=rse_settings, operation='write', scheme=scheme, domain=domain, protocol_attr=protocol_attr)
        expected_pfns = p.lfns2pfns(lfns)
        return clean_surls(expected_pfns.values())
    replica_rse = get_rse(rse_id=rse_id, session=session)
    if (replica_rse.volatile is True):
        raise exception.UnsupportedOperation(('Cannot add replicas on volatile RSE %s ' % replica_rse.rse))
    if ((not (replica_rse.availability & 2)) and (not ignore_availability)):
        raise exception.ResourceTemporaryUnavailable(('%s is temporary unavailable for writing' % replica_rse.rse))
    replicas = __bulk_add_file_dids(files=files, account=account, dataset_meta=dataset_meta, session=session)
    (pfns, scheme) = ({}, None)
    for file in files:
        if ('pfn' not in file):
            if (not replica_rse.deterministic):
                raise exception.UnsupportedOperation(('PFN needed for this (non deterministic) RSE %s ' % replica_rse.rse))
        else:
            scheme = file['pfn'].split(':')[0]
            pfns.setdefault(scheme, []).append(file['pfn'])
    if pfns:
        rse_settings = rsemgr.get_rse_info(rse_id=rse_id, session=session)
        for scheme in pfns.keys():
            if (not replica_rse.deterministic):
                p = rsemgr.create_protocol(rse_settings=rse_settings, operation='write', scheme=scheme)
                pfns[scheme] = p.parse_pfns(pfns=pfns[scheme])
                for file in files:
                    if file['pfn'].startswith(scheme):
                        tmp = pfns[scheme][file['pfn']]
                        file['path'] = ''.join([tmp['path'], tmp['name']])
            else:
                lfns = [{'scope': i['scope'].external, 'name': i['name']} for i in files if i['pfn'].startswith(scheme)]
                pfns[scheme] = clean_surls(pfns[scheme])
                found_on_wan = False
                available_wan_protocols = rsemgr.get_protocols_ordered(rse_settings=rse_settings, operation='write', scheme=scheme, domain='wan')
                expected_pfns_wan = None
                for protocol_attr in available_wan_protocols:
                    pfns_wan_buffer = _expected_pfns(lfns, rse_settings, scheme, operation='write', domain='wan', protocol_attr=protocol_attr)
                    if ((not expected_pfns_wan) and pfns_wan_buffer):
                        expected_pfns_wan = pfns_wan_buffer
                    found_on_wan = (found_on_wan or (pfns_wan_buffer == pfns[scheme]))
                    if found_on_wan:
                        break
                if (not found_on_wan):
                    found_on_lan = False
                    available_lan_protocols = rsemgr.get_protocols_ordered(rse_settings=rse_settings, operation='write', scheme=scheme, domain='lan')
                    for protocol_attr in available_lan_protocols:
                        pfns_lan_buffer = _expected_pfns(lfns, rse_settings, scheme, operation='write', domain='lan', protocol_attr=protocol_attr)
                        found_on_lan = (found_on_lan or (pfns_lan_buffer == pfns[scheme]))
                        if found_on_lan:
                            break
                    if (found_on_lan == pfns[scheme]):
                        pfns[scheme] = expected_pfns_wan
                    else:
                        raise exception.InvalidPath(('One of the PFNs provided does not match the Rucio expected PFN : got %s, expected %s (%s)' % (str(pfns), str(expected_pfns_wan), str(lfns))))
    (nbfiles, bytes) = __bulk_add_replicas(rse_id=rse_id, files=files, account=account, session=session)
    increase(rse_id=rse_id, files=nbfiles, bytes=bytes, session=session)
    return replicas
Bulk add file replicas.

:param rse_id:  The RSE id.
:param files:   The list of files.
:param account: The account owner.
:param ignore_availability: Ignore the RSE blocklisting.
:param session: The database session in use.

:returns: True is successful.
@transactional_session
def add_replicas(rse_id, files, account, ignore_availability=True, dataset_meta=None, session=None):
    '\n    Bulk add file replicas.\n\n    :param rse_id:  The RSE id.\n    :param files:   The list of files.\n    :param account: The account owner.\n    :param ignore_availability: Ignore the RSE blocklisting.\n    :param session: The database session in use.\n\n    :returns: True is successful.\n    '

    def _expected_pfns(lfns, rse_settings, scheme, operation='write', domain='wan', protocol_attr=None):
        p = rsemgr.create_protocol(rse_settings=rse_settings, operation='write', scheme=scheme, domain=domain, protocol_attr=protocol_attr)
        expected_pfns = p.lfns2pfns(lfns)
        return clean_surls(expected_pfns.values())
    replica_rse = get_rse(rse_id=rse_id, session=session)
    if (replica_rse.volatile is True):
        raise exception.UnsupportedOperation(('Cannot add replicas on volatile RSE %s ' % replica_rse.rse))
    if ((not (replica_rse.availability & 2)) and (not ignore_availability)):
        raise exception.ResourceTemporaryUnavailable(('%s is temporary unavailable for writing' % replica_rse.rse))
    replicas = __bulk_add_file_dids(files=files, account=account, dataset_meta=dataset_meta, session=session)
    (pfns, scheme) = ({}, None)
    for file in files:
        if ('pfn' not in file):
            if (not replica_rse.deterministic):
                raise exception.UnsupportedOperation(('PFN needed for this (non deterministic) RSE %s ' % replica_rse.rse))
        else:
            scheme = file['pfn'].split(':')[0]
            pfns.setdefault(scheme, []).append(file['pfn'])
    if pfns:
        rse_settings = rsemgr.get_rse_info(rse_id=rse_id, session=session)
        for scheme in pfns.keys():
            if (not replica_rse.deterministic):
                p = rsemgr.create_protocol(rse_settings=rse_settings, operation='write', scheme=scheme)
                pfns[scheme] = p.parse_pfns(pfns=pfns[scheme])
                for file in files:
                    if file['pfn'].startswith(scheme):
                        tmp = pfns[scheme][file['pfn']]
                        file['path'] = .join([tmp['path'], tmp['name']])
            else:
                lfns = [{'scope': i['scope'].external, 'name': i['name']} for i in files if i['pfn'].startswith(scheme)]
                pfns[scheme] = clean_surls(pfns[scheme])
                found_on_wan = False
                available_wan_protocols = rsemgr.get_protocols_ordered(rse_settings=rse_settings, operation='write', scheme=scheme, domain='wan')
                expected_pfns_wan = None
                for protocol_attr in available_wan_protocols:
                    pfns_wan_buffer = _expected_pfns(lfns, rse_settings, scheme, operation='write', domain='wan', protocol_attr=protocol_attr)
                    if ((not expected_pfns_wan) and pfns_wan_buffer):
                        expected_pfns_wan = pfns_wan_buffer
                    found_on_wan = (found_on_wan or (pfns_wan_buffer == pfns[scheme]))
                    if found_on_wan:
                        break
                if (not found_on_wan):
                    found_on_lan = False
                    available_lan_protocols = rsemgr.get_protocols_ordered(rse_settings=rse_settings, operation='write', scheme=scheme, domain='lan')
                    for protocol_attr in available_lan_protocols:
                        pfns_lan_buffer = _expected_pfns(lfns, rse_settings, scheme, operation='write', domain='lan', protocol_attr=protocol_attr)
                        found_on_lan = (found_on_lan or (pfns_lan_buffer == pfns[scheme]))
                        if found_on_lan:
                            break
                    if (found_on_lan == pfns[scheme]):
                        pfns[scheme] = expected_pfns_wan
                    else:
                        raise exception.InvalidPath(('One of the PFNs provided does not match the Rucio expected PFN : got %s, expected %s (%s)' % (str(pfns), str(expected_pfns_wan), str(lfns))))
    (nbfiles, bytes) = __bulk_add_replicas(rse_id=rse_id, files=files, account=account, session=session)
    increase(rse_id=rse_id, files=nbfiles, bytes=bytes, session=session)
    return replicas