From c72ff15c0e7d25359291a929c30f00e6fd66ecb1 Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Wed, 25 May 2016 09:52:48 +0000
Subject: [PATCH] SSDM-3574: get data set codes from all commands of all queues
 not just the default queue

SVN: 36574
---
 .../plugins/ResetArchivePendingTask.java      | 59 ++++++++++---------
 .../server/DataSetCommandExecutor.java        |  3 +-
 .../IDataSetCommandExecutorProvider.java      |  5 +-
 ...eyBasedDataSetCommandExecutorProvider.java |  7 +++
 4 files changed, 43 insertions(+), 31 deletions(-)

diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/ResetArchivePendingTask.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/ResetArchivePendingTask.java
index 1b0d7bd0fc0..31805fceb12 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/ResetArchivePendingTask.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/ResetArchivePendingTask.java
@@ -1,7 +1,7 @@
 package ch.systemsx.cisd.etlserver.plugins;
 
 import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Properties;
 import java.util.Set;
@@ -58,37 +58,38 @@ public class ResetArchivePendingTask implements IMaintenanceTask
         // 1. Find datasets with DataSetArchivingStatus.ARCHIVE_PENDING
         IEncapsulatedOpenBISService service = ServiceProvider.getOpenBISService();
         List<SimpleDataSetInformationDTO> inArchivePendings = service.listPhysicalDataSetsByArchivingStatus(DataSetArchivingStatus.ARCHIVE_PENDING);
-        operationLog.info("Found " + inArchivePendings.size() + " datasets in " + DataSetArchivingStatus.ARCHIVE_PENDING.name() + " status.");
-
-        // 2. Filter out datasets that are not on the command queue
-        IDataSetCommandExecutorProvider commandExecutorProvider =
-                (IDataSetCommandExecutorProvider) ServiceProvider
-                        .getApplicationContext()
-                        .getBean(COMMAND_EXECUTOR_BEAN);
-        IDataSetCommandExecutor commandExecutor = commandExecutorProvider.getDefaultExecutor();
-
-        Set<String> inQueue = commandExecutor.getDataSetCodesFromCommandQueue();
-        operationLog.info("Found " + inQueue.size() + " datasets in the command queue.");
-
-        List<SimpleDataSetInformationDTO> dataSetsToUpdate = new ArrayList<SimpleDataSetInformationDTO>();
-        for (SimpleDataSetInformationDTO inArchivePending : inArchivePendings)
+        if (inArchivePendings.isEmpty() == false)
         {
-            if (inQueue.contains(inArchivePending.getDataSetCode()) == false 
-                    && inArchivePending.isPresentInArchive() == false)
+            operationLog.info("Found " + inArchivePendings.size() + " datasets in " + DataSetArchivingStatus.ARCHIVE_PENDING.name() + " status.");
+            
+            // 2. Filter out datasets that are not on the command queue
+            IDataSetCommandExecutorProvider commandExecutorProvider =
+                    (IDataSetCommandExecutorProvider) ServiceProvider
+                    .getApplicationContext()
+                    .getBean(COMMAND_EXECUTOR_BEAN);
+            Set<String> inQueue = new HashSet<>();
+            List<IDataSetCommandExecutor> executors = commandExecutorProvider.getAllExecutors();
+            for (IDataSetCommandExecutor executor : executors)
             {
-                dataSetsToUpdate.add(inArchivePending);
-                operationLog.info(inArchivePending.getDataSetCode() + " not found in command queue, scheduled to update.");
+                inQueue.addAll(executor.getDataSetCodesFromCommandQueue());
             }
-        }
-
-        // 3. Update datasets status to AVAILABLE
-        operationLog.info("Going to update " + dataSetsToUpdate.size() + " datasets.");
-        for (SimpleDataSetInformationDTO dataSetToUpdate : dataSetsToUpdate)
-        {
-            DataSetCodesWithStatus codesWithStatus = new DataSetCodesWithStatus(
-                    Arrays.asList(dataSetToUpdate.getDataSetCode()),
-                    DataSetArchivingStatus.AVAILABLE,
-                    dataSetToUpdate.isPresentInArchive());
+            operationLog.info("Found " + inQueue.size() + " datasets in the command queue.");
+            
+            List<String> dataSetsToUpdate = new ArrayList<>();
+            for (SimpleDataSetInformationDTO inArchivePending : inArchivePendings)
+            {
+                if (inQueue.contains(inArchivePending.getDataSetCode()) == false 
+                        && inArchivePending.isPresentInArchive() == false)
+                {
+                    dataSetsToUpdate.add(inArchivePending.getDataSetCode());
+                    operationLog.info(inArchivePending.getDataSetCode() + " not found in command queue, scheduled to update.");
+                }
+            }
+            
+            // 3. Update datasets status to AVAILABLE
+            operationLog.info("Going to update " + dataSetsToUpdate.size() + " datasets.");
+            DataSetCodesWithStatus codesWithStatus = new DataSetCodesWithStatus(dataSetsToUpdate,
+                    DataSetArchivingStatus.AVAILABLE, false);
             QueueingDataSetStatusUpdaterService.update(codesWithStatus);
         }
         operationLog.info(ResetArchivePendingTask.class.getSimpleName() + " Finished");
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DataSetCommandExecutor.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DataSetCommandExecutor.java
index 86e85312730..909d8839cdd 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DataSetCommandExecutor.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DataSetCommandExecutor.java
@@ -18,7 +18,6 @@ package ch.systemsx.cisd.openbis.dss.generic.server;
 
 import java.io.File;
 import java.io.FilenameFilter;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
@@ -194,6 +193,7 @@ class DataSetCommandExecutor implements IDataSetCommandExecutor
             operationLog.debug("Scheduling " + command);
         }
         commandQueue.add(command);
+        operationLog.info("Scheduled: " + command.getDescription());
     }
 
     private IShareIdManager getShareIdManager()
@@ -221,6 +221,7 @@ class DataSetCommandExecutor implements IDataSetCommandExecutor
         for (IDataSetCommand command : commandQueue)
         {
             dataSetCodes.addAll(command.getDataSetCodes());
+            operationLog.info("Gather data set codes from command [" + command.getDescription() + "]");
         }
         return dataSetCodes;
     }
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/IDataSetCommandExecutorProvider.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/IDataSetCommandExecutorProvider.java
index 3be969f55ce..5902cd2bbc1 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/IDataSetCommandExecutorProvider.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/IDataSetCommandExecutorProvider.java
@@ -17,6 +17,7 @@
 package ch.systemsx.cisd.openbis.dss.generic.server;
 
 import java.io.File;
+import java.util.List;
 
 import ch.systemsx.cisd.openbis.dss.generic.shared.IProcessingPluginTask;
 
@@ -30,6 +31,8 @@ public interface IDataSetCommandExecutorProvider
     public void init(File storeRoot);
 
     public IDataSetCommandExecutor getDefaultExecutor();
-
+    
+    public List<IDataSetCommandExecutor> getAllExecutors();
+    
     public IDataSetCommandExecutor getExecutor(IProcessingPluginTask processingTask, String processingTaskKey);
 }
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/KeyBasedDataSetCommandExecutorProvider.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/KeyBasedDataSetCommandExecutorProvider.java
index 6373eba288b..57526e420dc 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/KeyBasedDataSetCommandExecutorProvider.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/KeyBasedDataSetCommandExecutorProvider.java
@@ -159,6 +159,13 @@ public class KeyBasedDataSetCommandExecutorProvider implements IDataSetCommandEx
         }
         return defaultExecutor;
     }
+    
+
+    @Override
+    public List<IDataSetCommandExecutor> getAllExecutors()
+    {
+        return new ArrayList<>(executorsByName.values());
+    }
 
     @Override
     public IDataSetCommandExecutor getExecutor(IProcessingPluginTask processingTask, String processingTaskKey)
-- 
GitLab