def _get_path_nondeterministic_server(self, scope, name): # pylint: disable=invalid-name """ Provides the path of a replica for non-deterministic sites. Will be assigned to get path by the __init__ method if neccessary. """ rep = replica.get_replica(rse=self.rse['rse'], scope=scope, name=name, rse_id=self.rse['id']) if 'path' in rep and rep['path'] is not None: path = rep['path'] elif 'state' in rep and (rep['state'] is None or rep['state'] == 'UNAVAILABLE'): raise exception.ReplicaUnAvailable('Missing path information and state is UNAVAILABLE for replica %s:%s on non-deterministic storage named %s' % (scope, name, self.rse['rse'])) else: raise exception.ReplicaNotFound('Missing path information for replica %s:%s on non-deterministic storage named %s' % (scope, name, self.rse['rse'])) if path.startswith('/'): path = path[1:] if path.endswith('/'): path = path[:-1] return path
def declare_bad_file_replicas(dids, rse_id, reason, issuer, status=BadFilesStatus.BAD, scheme=None, session=None): """ Declare a list of bad replicas. :param dids: The list of DIDs. :param rse_id: The RSE id. :param reason: The reason of the loss. :param issuer: The issuer account. :param status: Either BAD or SUSPICIOUS. :param scheme: The scheme of the PFNs. :param session: The database session in use. """ unknown_replicas = [] replicas = [] for did in dids: scope = InternalScope(did['scope'], vo=issuer.vo) name = did['name'] path = None scope, name, path, exists, already_declared, size = __exist_replicas( rse_id, [(scope, name, path)], session=session)[0] if exists and ( (str(status) == str(BadFilesStatus.BAD) and not already_declared) or str(status) == str(BadFilesStatus.SUSPICIOUS)): replicas.append({ 'scope': scope, 'name': name, 'rse_id': rse_id, 'state': ReplicaState.BAD }) new_bad_replica = models.BadReplicas(scope=scope, name=name, rse_id=rse_id, reason=reason, state=status, account=issuer, bytes=size) new_bad_replica.save(session=session, flush=False) session.query(models.Source).filter_by( scope=scope, name=name, rse_id=rse_id).delete(synchronize_session=False) else: if already_declared: unknown_replicas.append( '%s:%s %s' % (did['scope'], did['name'], 'Already declared')) else: unknown_replicas.append( '%s:%s %s' % (did['scope'], did['name'], 'Unknown replica')) if str(status) == str(BadFilesStatus.BAD): # For BAD file, we modify the replica state, not for suspicious try: # there shouldn't be any exceptions since all replicas exist update_replicas_states(replicas, session=session) except exception.UnsupportedOperation: raise exception.ReplicaNotFound( "One or several replicas don't exist.") try: session.flush() except IntegrityError as error: raise exception.RucioException(error.args) except DatabaseError as error: raise exception.RucioException(error.args) except FlushError as error: raise exception.RucioException(error.args) return unknown_replicas