changeset 5817:272b0d0eef38 find-refactoring tip

ReadOnly mode continued
author Alain Mazy <am@orthanc.team>
date Thu, 26 Sep 2024 17:23:43 +0200
parents 8a8756b2dd0b
children
files OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp OrthancServer/Sources/Database/StatelessDatabaseOperations.h OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp OrthancServer/Sources/ServerContext.cpp OrthancServer/Sources/ServerIndex.cpp OrthancServer/Sources/ServerIndex.h OrthancServer/Sources/main.cpp
diffstat 8 files changed, 29 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Mon Sep 23 16:03:02 2024 +0200
+++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Thu Sep 26 17:23:43 2024 +0200
@@ -1042,7 +1042,7 @@
       }
     };
 
-    if (GetDatabaseCapabilities().HasUpdateAndGetStatistics())
+    if (GetDatabaseCapabilities().HasUpdateAndGetStatistics() && !IsReadOnly())
     {
       Operations operations;
       Apply(operations);
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.h	Mon Sep 23 16:03:02 2024 +0200
+++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.h	Thu Sep 26 17:23:43 2024 +0200
@@ -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	Mon Sep 23 16:03:02 2024 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp	Thu Sep 26 17:23:43 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	Mon Sep 23 16:03:02 2024 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Thu Sep 26 17:23:43 2024 +0200
@@ -4380,7 +4380,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>);
@@ -4437,7 +4437,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	Mon Sep 23 16:03:02 2024 +0200
+++ b/OrthancServer/Sources/ServerContext.cpp	Thu Sep 26 17:23:43 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	Mon Sep 23 16:03:02 2024 +0200
+++ b/OrthancServer/Sources/ServerIndex.cpp	Thu Sep 26 17:23:43 2024 +0200
@@ -352,7 +352,8 @@
     done_(false),
     maximumStorageMode_(MaxStorageMode_Recycle),
     maximumStorageSize_(0),
-    maximumPatients_(0)
+    maximumPatients_(0),
+    readOnly_(readOnly)
   {
     SetTransactionContextFactory(new TransactionContextFactory(context));
 
--- a/OrthancServer/Sources/ServerIndex.h	Mon Sep 23 16:03:02 2024 +0200
+++ b/OrthancServer/Sources/ServerIndex.h	Thu Sep 26 17:23:43 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	Mon Sep 23 16:03:02 2024 +0200
+++ b/OrthancServer/Sources/main.cpp	Thu Sep 26 17:23:43 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
     {