def sort_rses(rses, session=None): """ Sort a list of RSES by free space (ascending order). :param rses: List of RSEs. :param session: The database session in use. :returns: Sorted list of RSEs """ if not rses: raise exception.InputValidationError( 'The list rses should not be empty!') if len(rses) == 1: return rses false_value = False query = session.query(models.RSE.rse, models.RSE.staging_area, models.RSEUsage.rse_id).\ filter(models.RSEUsage.source == 'storage').\ filter(models.RSEUsage.rse_id == models.RSE.id).\ filter(models.RSE.deleted == false_value) condition = [] for rse in rses: condition.append(models.RSE.id == rse['id']) query = query.filter(or_(*condition)).order_by(models.RSEUsage.free.asc()) return [{ 'rse': rse, 'staging_area': staging_area, 'id': rse_id } for rse, staging_area, rse_id in query]
def add_bad_pfns(pfns, issuer, state, reason=None, expires_at=None, vo='def'): """ Add bad PFNs. :param pfns: the list of new files. :param issuer: The issuer account. :param state: One of the possible states : BAD, SUSPICIOUS, TEMPORARY_UNAVAILABLE. :param reason: A string describing the reason of the loss. :param expires_at: Specify a timeout for the TEMPORARY_UNAVAILABLE replicas. None for BAD files. :param vo: The VO to act on. :param session: The database session in use. :returns: True is successful. """ kwargs = {'state': state} if not permission.has_permission( issuer=issuer, vo=vo, action='add_bad_pfns', kwargs=kwargs): raise exception.AccessDenied('Account %s can not declare bad PFNs' % (issuer)) if expires_at and datetime.datetime.utcnow( ) <= expires_at and expires_at > datetime.datetime.utcnow( ) + datetime.timedelta(days=30): raise exception.InputValidationError( 'The given duration of %s days exceeds the maximum duration of 30 days.' % (expires_at - datetime.datetime.utcnow()).days) issuer = InternalAccount(issuer, vo=vo) return replica.add_bad_pfns(pfns=pfns, account=issuer, state=state, reason=reason, expires_at=expires_at)