changeset 5822:ca5622c27d6c attach-custom-data

merged find-refactoring -> attach-custom-data
author Alain Mazy <am@orthanc.team>
date Tue, 01 Oct 2024 16:01:50 +0200
parents 42a7fbf13359 (current diff) 7c2b4fa94633 (diff)
children a856763e5736
files OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp OrthancServer/Sources/ServerContext.cpp OrthancServer/Sources/ServerIndex.cpp
diffstat 8 files changed, 40 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Wed Sep 25 16:36:43 2024 +0200
+++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Tue Oct 01 16:01:50 2024 +0200
@@ -1042,7 +1042,7 @@
       }
     };
 
-    if (GetDatabaseCapabilities().HasUpdateAndGetStatistics())
+    if (GetDatabaseCapabilities().HasUpdateAndGetStatistics() && !IsReadOnly())
     {
       Operations operations;
       Apply(operations);
@@ -2825,8 +2825,8 @@
   }
 
 
-  bool StatelessDatabaseOperations::ReadWriteTransaction::HasReachedMaxStorageSize(uint64_t maximumStorageSize,
-                                                                                   uint64_t addedInstanceSize)
+  bool StatelessDatabaseOperations::ReadOnlyTransaction::HasReachedMaxStorageSize(uint64_t maximumStorageSize,
+                                                                                  uint64_t addedInstanceSize)
   {
     if (maximumStorageSize != 0)
     {
@@ -2847,8 +2847,8 @@
     return false;
   }                                                                           
 
-  bool StatelessDatabaseOperations::ReadWriteTransaction::HasReachedMaxPatientCount(unsigned int maximumPatientCount,
-                                                                                    const std::string& patientId)
+  bool StatelessDatabaseOperations::ReadOnlyTransaction::HasReachedMaxPatientCount(unsigned int maximumPatientCount,
+                                                                                   const std::string& patientId)
   {
     if (maximumPatientCount != 0)
     {
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.h	Wed Sep 25 16:36:43 2024 +0200
+++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.h	Tue Oct 01 16:01:50 2024 +0200
@@ -401,6 +401,12 @@
         transaction_.ListAllLabels(target);
       }
 
+      bool HasReachedMaxStorageSize(uint64_t maximumStorageSize,
+                                    uint64_t addedInstanceSize);
+
+      bool HasReachedMaxPatientCount(unsigned int maximumPatientCount,
+                                     const std::string& patientId);
+
       void ExecuteFind(FindResponse& response,
                        const FindRequest& request,
                        const IDatabaseWrapper::Capabilities& capabilities)
@@ -541,12 +547,6 @@
                    uint64_t addedInstanceSize,
                    const std::string& newPatientId);
 
-      bool HasReachedMaxStorageSize(uint64_t maximumStorageSize,
-                                    uint64_t addedInstanceSize);
-
-      bool HasReachedMaxPatientCount(unsigned int maximumPatientCount,
-                                     const std::string& patientId);
-      
       bool IsRecyclingNeeded(uint64_t maximumStorageSize,
                              unsigned int maximumPatients,
                              uint64_t addedInstanceSize,
@@ -608,6 +608,11 @@
                              uint64_t maximumStorageSize,
                              unsigned int maximumPatientCount);
 
+    bool IsReadOnly()
+    {
+      return readOnly_;
+    }
+
   public:
     explicit StatelessDatabaseOperations(IDatabaseWrapper& database, bool readOnly);
 
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp	Wed Sep 25 16:36:43 2024 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp	Tue Oct 01 16:01:50 2024 +0200
@@ -270,7 +270,16 @@
     RegisterAnonymizeModify();
     RegisterArchive();
 
-    Register("/instances", UploadDicomFile);
+    if (!context_.IsReadOnly())
+    {
+      Register("/instances", UploadDicomFile);
+    }
+    else
+    {
+      LOG(WARNING) << "READ-ONLY SYSTEM: deactivating POST /instances route";
+    }
+
+    
 
     // Auto-generated directories
     Register("/tools", RestApi::AutoListChildren);
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Wed Sep 25 16:36:43 2024 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Tue Oct 01 16:01:50 2024 +0200
@@ -4382,7 +4382,7 @@
     }
     else
     {
-      LOG(WARNING) << "READ-ONLY SYSTEM: DELETE routes are not available";
+      LOG(WARNING) << "READ-ONLY SYSTEM: deactivating DELETE routes";
     }
 
     Register("/instances/{id}", GetSingleResource<ResourceType_Instance>);
@@ -4439,7 +4439,7 @@
     }
     else
     {
-      LOG(WARNING) << "READ-ONLY SYSTEM: PUT /patients/{id}/protected route is not available";
+      LOG(WARNING) << "READ-ONLY SYSTEM: deactivating PUT /patients/{id}/protected route";
     }
 
 
--- a/OrthancServer/Sources/ServerContext.cpp	Wed Sep 25 16:36:43 2024 +0200
+++ b/OrthancServer/Sources/ServerContext.cpp	Tue Oct 01 16:01:50 2024 +0200
@@ -406,7 +406,14 @@
           new SharedArchive(lock.GetConfiguration().GetUnsignedIntegerParameter("MediaArchiveSize", 1)));
         defaultLocalAet_ = lock.GetConfiguration().GetOrthancAET();
         jobsEngine_.SetWorkersCount(lock.GetConfiguration().GetUnsignedIntegerParameter("ConcurrentJobs", 2));
+
         saveJobs_ = lock.GetConfiguration().GetBooleanParameter("SaveJobs", true);
+        if (readOnly_ && saveJobs_)
+        {
+          LOG(WARNING) << "READ-ONLY SYSTEM: SaveJobs = true is incompatible with a ReadOnly system, ignoring this configuration";
+          saveJobs_ = false;
+        }
+
         metricsRegistry_->SetEnabled(lock.GetConfiguration().GetBooleanParameter("MetricsEnabled", true));
 
         // New configuration options in Orthanc 1.5.1
--- a/OrthancServer/Sources/ServerIndex.cpp	Wed Sep 25 16:36:43 2024 +0200
+++ b/OrthancServer/Sources/ServerIndex.cpp	Tue Oct 01 16:01:50 2024 +0200
@@ -278,7 +278,7 @@
   {
     Logging::SetCurrentThreadName("DB-STATS");
 
-    static const unsigned int SLEEP_SECONDS = 60;
+    static const unsigned int SLEEP_SECONDS = 10;
 
     if (threadSleepGranularityMilliseconds > 1000)
     {
@@ -359,7 +359,8 @@
     done_(false),
     maximumStorageMode_(MaxStorageMode_Recycle),
     maximumStorageSize_(0),
-    maximumPatients_(0)
+    maximumPatients_(0),
+    readOnly_(readOnly)
   {
     SetTransactionContextFactory(new TransactionContextFactory(context));
 
--- a/OrthancServer/Sources/ServerIndex.h	Wed Sep 25 16:36:43 2024 +0200
+++ b/OrthancServer/Sources/ServerIndex.h	Tue Oct 01 16:01:50 2024 +0200
@@ -50,6 +50,7 @@
     MaxStorageMode  maximumStorageMode_;
     uint64_t        maximumStorageSize_;
     unsigned int    maximumPatients_;
+    bool            readOnly_;
 
     static void FlushThread(ServerIndex* that,
                             unsigned int threadSleep);
--- a/OrthancServer/Sources/main.cpp	Wed Sep 25 16:36:43 2024 +0200
+++ b/OrthancServer/Sources/main.cpp	Tue Oct 01 16:01:50 2024 +0200
@@ -1570,12 +1570,7 @@
 
     if (context.IsReadOnly())
     {
-      LOG(WARNING) << "READ-ONLY SYSTEM: ignoring these configurations: StorageCompression, StoreMD5ForAttachments, OverwriteInstances, MaximumPatientCount, MaximumStorageSize, MaximumStorageMode"; 
-
-      if (context.IsSaveJobs())
-      {
-        throw OrthancException(ErrorCode_IncompatibleConfigurations, "\"SaveJobs\" can not be true when \"ReadOnly\" is true");
-      }
+      LOG(WARNING) << "READ-ONLY SYSTEM: ignoring these configurations: StorageCompression, StoreMD5ForAttachments, OverwriteInstances, MaximumPatientCount, MaximumStorageSize, MaximumStorageMode, SaveJobs"; 
     }
     else
     {