Repository: rucio/rucio

Issue:
Add the possibility to remove suspicious files from the bad files summary plots
Motivation
----------
The number of suspicious is way more bigger than the actually big one. One should have the possibility to filter out the suspicious files from the bad files summary plots



Discussion:

Resolving patch:
diff --git a/lib/rucio/db/sqla/constants.py b/lib/rucio/db/sqla/constants.py
--- a/lib/rucio/db/sqla/constants.py
+++ b/lib/rucio/db/sqla/constants.py
@@ -125,7 +125,6 @@ class ReplicaState(DeclEnum):
     COPYING = 'C', 'COPYING'
     BEING_DELETED = 'B', 'BEING_DELETED'
     BAD = 'D', 'BAD'
-    SOURCE = 'S', 'SOURCE'
     TEMPORARY_UNAVAILABLE = 'T', 'TEMPORARY_UNAVAILABLE'
 
 
diff --git a/lib/rucio/db/sqla/migrate_repo/versions/45378a1e76a8_create_collection_replica_table.py b/lib/rucio/db/sqla/migrate_repo/versions/45378a1e76a8_create_collection_replica_table.py
--- a/lib/rucio/db/sqla/migrate_repo/versions/45378a1e76a8_create_collection_replica_table.py
+++ b/lib/rucio/db/sqla/migrate_repo/versions/45378a1e76a8_create_collection_replica_table.py
@@ -13,7 +13,7 @@
 # limitations under the License.
 #
 # Authors:
-# - Martin Barisits <martin.barisits@cern.ch>, 2015
+# - Martin Barisits <martin.barisits@cern.ch>, 2015-2019
 # - Vincent Garonne <vincent.garonne@cern.ch>, 2017
 # - Mario Lassnig <mario.lassnig@cern.ch>, 2019
 
@@ -23,9 +23,10 @@
 
 import sqlalchemy as sa
 
-from alembic import context
+from alembic import context, op
 from alembic.op import (create_table, create_primary_key, create_foreign_key,
-                        create_check_constraint, create_index, drop_table)
+                        create_check_constraint, create_index, drop_table,
+                        drop_constraint)
 
 from rucio.db.sqla.constants import ReplicaState, DIDType
 from rucio.db.sqla.types import GUID
@@ -59,6 +60,7 @@ def upgrade():
         create_foreign_key('COLLECTION_REPLICAS_RSE_ID_FK', 'collection_replicas', 'rses', ['rse_id'], ['id'])
         create_check_constraint('COLLECTION_REPLICAS_SIZE_NN', 'collection_replicas', 'bytes IS NOT NULL')
         create_check_constraint('COLLECTION_REPLICAS_STATE_NN', 'collection_replicas', 'state IS NOT NULL')
+        create_check_constraint('COLLECTION_REPLICAS_STATE_CHK', 'collection_replicas', "state in ('A', 'U', 'C', 'B', 'D', 'S')")
         create_index('COLLECTION_REPLICAS_RSE_ID_IDX', 'collection_replicas', ['rse_id'])
 
 
@@ -67,5 +69,15 @@ def downgrade():
     Downgrade the database to the previous revision
     '''
 
-    if context.get_context().dialect.name in ['oracle', 'mysql', 'postgresql']:
+    if context.get_context().dialect.name == 'oracle':
+        drop_constraint('COLLECTION_REPLICAS_STATE_CHK', 'collection_replicas', type_='check')
+        drop_table('collection_replicas')
+
+    elif context.get_context().dialect.name == 'postgresql':
+        schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else ''
+        op.execute('ALTER TABLE ' + schema + 'collection_replicas ALTER COLUMN state TYPE CHAR')  # pylint: disable=no-member
+        drop_constraint('COLLECTION_REPLICAS_STATE_CHK', 'collection_replicas', type_='check')
+        drop_table('collection_replicas')
+
+    elif context.get_context().dialect.name == 'mysql':
         drop_table('collection_replicas')
diff --git a/lib/rucio/db/sqla/migrate_repo/versions/b7d287de34fd_removal_of_replicastate_source.py b/lib/rucio/db/sqla/migrate_repo/versions/b7d287de34fd_removal_of_replicastate_source.py
new file mode 100644
--- /dev/null
+++ b/lib/rucio/db/sqla/migrate_repo/versions/b7d287de34fd_removal_of_replicastate_source.py
@@ -0,0 +1,66 @@
+# Copyright 2013-2019 CERN for the benefit of the ATLAS collaboration.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Authors:
+# - Martin Barisits <martin.barisits@cern.ch>, 2019
+
+''' Removal of ReplicaState.SOURCE '''
+
+from alembic import context
+from alembic.op import (create_check_constraint, drop_constraint)
+
+
+# Alembic revision identifiers
+revision = 'b7d287de34fd'
+down_revision = 'f1b14a8c2ac1'
+
+
+def upgrade():
+    '''
+    Upgrade the database to this revision
+    '''
+
+    if context.get_context().dialect.name in ['oracle', 'postgresql']:
+        drop_constraint('REPLICAS_STATE_CHK', 'replicas', type_='check')
+        create_check_constraint(constraint_name='REPLICAS_STATE_CHK', table_name='replicas',
+                                condition="state in ('A', 'U', 'C', 'B', 'D', 'T')")
+        drop_constraint('COLLECTION_REPLICAS_STATE_CHK', 'collection_replicas', type_='check')
+        create_check_constraint(constraint_name='COLLECTION_REPLICAS_STATE_CHK', table_name='collection_replicas',
+                                condition="state in ('A', 'U', 'C', 'B', 'D', 'T')")
+
+    elif context.get_context().dialect.name == 'mysql':
+        create_check_constraint(constraint_name='REPLICAS_STATE_CHK', table_name='replicas',
+                                condition="state in ('A', 'U', 'C', 'B', 'D', 'T')")
+        create_check_constraint(constraint_name='COLLECTION_REPLICAS_STATE_CHK', table_name='collection_replicas',
+                                condition="state in ('A', 'U', 'C', 'B', 'D', 'T')")
+
+
+def downgrade():
+    '''
+    Downgrade the database to the previous revision
+    '''
+
+    if context.get_context().dialect.name in ['oracle', 'postgresql']:
+        drop_constraint('REPLICAS_STATE_CHK', 'replicas', type_='check')
+        create_check_constraint(constraint_name='REPLICAS_STATE_CHK', table_name='replicas',
+                                condition="state in ('A', 'U', 'C', 'B', 'D', 'S', 'T')")
+        drop_constraint('COLLECTION_REPLICAS_STATE_CHK', 'collection_replicas', type_='check')
+        create_check_constraint(constraint_name='COLLECTION_REPLICAS_STATE_CHK', table_name='collection_replicas',
+                                condition="state in ('A', 'U', 'C', 'B', 'D', 'S', 'T')")
+
+    elif context.get_context().dialect.name == 'mysql':
+        create_check_constraint(constraint_name='REPLICAS_STATE_CHK', table_name='replicas',
+                                condition="state in ('A', 'U', 'C', 'B', 'D', 'S', 'T')")
+        create_check_constraint(constraint_name='COLLECTION_REPLICAS_STATE_CHK', table_name='collection_replicas',
+                                condition="state in ('A', 'U', 'C', 'B', 'D', 'S', 'T')")


Test patch: