Mercurial > hg > orthanc-object-storage
annotate Common/StoragePlugin.cpp @ 210:408c90c9027f default tip
todo: google soft delete
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Wed, 09 Oct 2024 11:48:14 +0200 |
parents | df0b6998fd27 |
children |
rev | line source |
---|---|
1 | 1 /** |
2 * Cloud storage plugins for Orthanc | |
145
3c7e0374f28e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
3 * Copyright (C) 2020-2023 Osimis S.A., Belgium |
3c7e0374f28e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
4 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
3c7e0374f28e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
143
diff
changeset
|
5 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
56
b922ae86bbe1
full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
43
diff
changeset
|
21 |
1 | 22 #if GOOGLE_STORAGE_PLUGIN==1 |
56
b922ae86bbe1
full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
43
diff
changeset
|
23 # include "../Google/GoogleStoragePlugin.h" |
b922ae86bbe1
full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
43
diff
changeset
|
24 # define StoragePluginFactory GoogleStoragePluginFactory |
1 | 25 #elif AZURE_STORAGE_PLUGIN==1 |
56
b922ae86bbe1
full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
43
diff
changeset
|
26 # include "../Azure/AzureBlobStoragePlugin.h" |
b922ae86bbe1
full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
43
diff
changeset
|
27 # define StoragePluginFactory AzureBlobStoragePluginFactory |
1 | 28 #elif AWS_STORAGE_PLUGIN==1 |
56
b922ae86bbe1
full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
43
diff
changeset
|
29 # include "../Aws/AwsS3StoragePlugin.h" |
b922ae86bbe1
full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
43
diff
changeset
|
30 # define StoragePluginFactory AwsS3StoragePluginFactory |
1 | 31 #else |
56
b922ae86bbe1
full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
43
diff
changeset
|
32 # pragma message(error "define a plugin") |
1 | 33 #endif |
34 | |
35 #include <string.h> | |
36 #include <stdio.h> | |
37 #include <string> | |
38 | |
39 #include <iostream> | |
15 | 40 #include <boost/filesystem.hpp> |
41 #include <boost/filesystem/fstream.hpp> | |
42 | |
1 | 43 #include "../Common/EncryptionHelpers.h" |
44 #include "../Common/EncryptionConfigurator.h" | |
78 | 45 #include "../Common/FileSystemStorage.h" |
35
8a7a5defd5d0
upgrade orthanc framework to 1.8.2 in AWS S3 plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
33
diff
changeset
|
46 |
8a7a5defd5d0
upgrade orthanc framework to 1.8.2 in AWS S3 plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
33
diff
changeset
|
47 #include <Logging.h> |
15 | 48 #include <SystemToolbox.h> |
83
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
49 #include "MoveStorageJob.h" |
84 | 50 #include "StoragePlugin.h" |
51 #include <Toolbox.h> | |
52 | |
159
99c14487f96b
fix mingw compilation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
53 #ifdef _WIN32 |
99c14487f96b
fix mingw compilation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
54 // This is a hotfix for: https://orthanc.uclouvain.be/hg/orthanc/rev/e4d9a872998f |
99c14487f96b
fix mingw compilation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
55 # undef ORTHANC_PLUGINS_API |
99c14487f96b
fix mingw compilation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
56 # define ORTHANC_PLUGINS_API __declspec(dllexport) |
99c14487f96b
fix mingw compilation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
57 #endif |
99c14487f96b
fix mingw compilation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
58 |
1 | 59 |
78 | 60 static std::unique_ptr<IStorage> primaryStorage; |
61 static std::unique_ptr<IStorage> secondaryStorage; | |
1 | 62 |
63 static std::unique_ptr<EncryptionHelpers> crypto; | |
64 static bool cryptoEnabled = false; | |
15 | 65 static std::string fileSystemRootPath; |
20 | 66 static std::string objectsRootPath; |
77 | 67 static std::string hybridModeNameForLogs = ""; |
68 | |
69 typedef enum | |
70 { | |
71 HybridMode_WriteToFileSystem, // write to disk, try to read first from disk and then, from object-storage | |
72 HybridMode_WriteToObjectStorage, // write to object storage, try to read first from object storage and then, from disk | |
73 HybridMode_Disabled // read and write only from/to object-storage | |
74 } HybridMode; | |
75 | |
76 static HybridMode hybridMode = HybridMode_Disabled; | |
77 | |
78 static bool IsReadFromDisk() | |
79 { | |
80 return hybridMode != HybridMode_Disabled; | |
81 } | |
82 | |
83 static bool IsHybridModeEnabled() | |
84 { | |
85 return hybridMode != HybridMode_Disabled; | |
86 } | |
87 | |
88 typedef void LogErrorFunction(const std::string& message); | |
89 | |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
90 static void LogErrorAsWarning(const std::string& message) |
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
91 { |
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
92 LOG(WARNING) << message; |
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
93 } |
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
94 |
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
95 static void LogErrorAsError(const std::string& message) |
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
96 { |
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
97 LOG(ERROR) << message; |
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
98 } |
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
99 |
1 | 100 |
101 | |
102 static OrthancPluginErrorCode StorageCreate(const char* uuid, | |
103 const void* content, | |
104 int64_t size, | |
105 OrthancPluginContentType type) | |
106 { | |
107 try | |
108 { | |
119
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
98
diff
changeset
|
109 Orthanc::Toolbox::ElapsedTimer timer; |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
110 LOG(INFO) << primaryStorage->GetNameForLogs() << ": creating attachment " << uuid |
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
111 << " of type " << boost::lexical_cast<std::string>(type); |
78 | 112 std::unique_ptr<IStorage::IWriter> writer(primaryStorage->GetWriterForObject(uuid, type, cryptoEnabled)); |
1 | 113 |
114 if (cryptoEnabled) | |
115 { | |
116 std::string encryptedFile; | |
117 | |
118 try | |
119 { | |
120 crypto->Encrypt(encryptedFile, (const char*)content, size); | |
121 } | |
122 catch (EncryptionException& ex) | |
123 { | |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
124 LOG(ERROR) << primaryStorage->GetNameForLogs() << ": error while encrypting object " << uuid << ": " << ex.what(); |
1 | 125 return OrthancPluginErrorCode_StorageAreaPlugin; |
126 } | |
127 | |
128 writer->Write(encryptedFile.data(), encryptedFile.size()); | |
129 } | |
130 else | |
131 { | |
132 writer->Write(reinterpret_cast<const char*>(content), size); | |
133 } | |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
134 LOG(INFO) << primaryStorage->GetNameForLogs() << ": created attachment " << uuid |
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
135 << " (" << timer.GetHumanTransferSpeed(true, size) << ")"; |
1 | 136 } |
137 catch (StoragePluginException& ex) | |
138 { | |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
139 LOG(ERROR) << primaryStorage->GetNameForLogs() << ": error while creating object " << uuid << ": " << ex.what(); |
1 | 140 return OrthancPluginErrorCode_StorageAreaPlugin; |
141 } | |
142 | |
143 return OrthancPluginErrorCode_Success; | |
144 } | |
145 | |
146 | |
78 | 147 static OrthancPluginErrorCode StorageReadRange(IStorage* storage, |
77 | 148 LogErrorFunction logErrorFunction, |
149 OrthancPluginMemoryBuffer64* target, // Memory buffer where to store the content of the range. The memory buffer is allocated and freed by Orthanc. The length of the range of interest corresponds to the size of this buffer. | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
150 const char* uuid, |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
151 OrthancPluginContentType type, |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
152 uint64_t rangeStart) |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
153 { |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
154 assert(!cryptoEnabled); |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
155 |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
156 try |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
157 { |
119
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
98
diff
changeset
|
158 Orthanc::Toolbox::ElapsedTimer timer; |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
159 LOG(INFO) << storage->GetNameForLogs() << ": reading range of attachment " << uuid |
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
160 << " of type " << boost::lexical_cast<std::string>(type); |
77 | 161 |
78 | 162 std::unique_ptr<IStorage::IReader> reader(storage->GetReaderForObject(uuid, type, cryptoEnabled)); |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
163 reader->ReadRange(reinterpret_cast<char*>(target->data), target->size, rangeStart); |
77 | 164 |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
165 LOG(INFO) << storage->GetNameForLogs() << ": read range of attachment " << uuid |
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
166 << " (" << timer.GetHumanTransferSpeed(true, target->size) << ")"; |
77 | 167 return OrthancPluginErrorCode_Success; |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
168 } |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
169 catch (StoragePluginException& ex) |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
170 { |
77 | 171 logErrorFunction(std::string(StoragePluginFactory::GetStoragePluginName()) + ": error while reading object " + std::string(uuid) + ": " + std::string(ex.what())); |
172 return OrthancPluginErrorCode_StorageAreaPlugin; | |
173 } | |
174 } | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
175 |
77 | 176 static OrthancPluginErrorCode StorageReadRange(OrthancPluginMemoryBuffer64* target, // Memory buffer where to store the content of the range. The memory buffer is allocated and freed by Orthanc. The length of the range of interest corresponds to the size of this buffer. |
177 const char* uuid, | |
178 OrthancPluginContentType type, | |
179 uint64_t rangeStart) | |
180 { | |
78 | 181 OrthancPluginErrorCode res = StorageReadRange(primaryStorage.get(), |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
182 (IsHybridModeEnabled() ? LogErrorAsWarning : LogErrorAsError), // log errors as warning on first try |
77 | 183 target, |
184 uuid, | |
185 type, | |
186 rangeStart); | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
187 |
77 | 188 if (res != OrthancPluginErrorCode_Success && IsHybridModeEnabled()) |
189 { | |
78 | 190 res = StorageReadRange(secondaryStorage.get(), |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
191 LogErrorAsError, // log errors as errors on second try |
77 | 192 target, |
193 uuid, | |
194 type, | |
195 rangeStart); | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
196 } |
77 | 197 return res; |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
198 } |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
199 |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
200 |
77 | 201 |
78 | 202 static OrthancPluginErrorCode StorageReadWhole(IStorage* storage, |
77 | 203 LogErrorFunction logErrorFunction, |
204 OrthancPluginMemoryBuffer64* target, // Memory buffer where to store the content of the file. It must be allocated by the plugin using OrthancPluginCreateMemoryBuffer64(). The core of Orthanc will free it. | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
205 const char* uuid, |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
206 OrthancPluginContentType type) |
1 | 207 { |
208 try | |
209 { | |
119
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
98
diff
changeset
|
210 Orthanc::Toolbox::ElapsedTimer timer; |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
211 LOG(INFO) << storage->GetNameForLogs() << ": reading whole attachment " << uuid |
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
212 << " of type " << boost::lexical_cast<std::string>(type); |
78 | 213 std::unique_ptr<IStorage::IReader> reader(storage->GetReaderForObject(uuid, type, cryptoEnabled)); |
1 | 214 |
215 size_t fileSize = reader->GetSize(); | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
216 size_t size; |
1 | 217 |
218 if (cryptoEnabled) | |
219 { | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
220 size = fileSize - crypto->OVERHEAD_SIZE; |
1 | 221 } |
222 else | |
223 { | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
224 size = fileSize; |
1 | 225 } |
226 | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
227 if (size <= 0) |
1 | 228 { |
78 | 229 logErrorFunction(storage->GetNameForLogs() + ": error while reading object " + std::string(uuid) + ", size of file is too small: " + boost::lexical_cast<std::string>(fileSize) + " bytes"); |
1 | 230 return OrthancPluginErrorCode_StorageAreaPlugin; |
231 } | |
232 | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
233 if (OrthancPluginCreateMemoryBuffer64(OrthancPlugins::GetGlobalContext(), target, size) != OrthancPluginErrorCode_Success) |
1 | 234 { |
78 | 235 logErrorFunction(storage->GetNameForLogs() + ": error while reading object " + std::string(uuid) + ", cannot allocate memory of size " + boost::lexical_cast<std::string>(size) + " bytes"); |
1 | 236 return OrthancPluginErrorCode_StorageAreaPlugin; |
237 } | |
238 | |
239 if (cryptoEnabled) | |
240 { | |
241 std::vector<char> encrypted(fileSize); | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
242 reader->ReadWhole(encrypted.data(), fileSize); |
1 | 243 |
244 try | |
245 { | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
246 crypto->Decrypt(reinterpret_cast<char*>(target->data), encrypted.data(), fileSize); |
1 | 247 } |
248 catch (EncryptionException& ex) | |
249 { | |
78 | 250 logErrorFunction(storage->GetNameForLogs() + ": error while decrypting object " + std::string(uuid) + ": " + ex.what()); |
1 | 251 return OrthancPluginErrorCode_StorageAreaPlugin; |
252 } | |
253 } | |
254 else | |
255 { | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
256 reader->ReadWhole(reinterpret_cast<char*>(target->data), fileSize); |
1 | 257 } |
119
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
98
diff
changeset
|
258 |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
259 LOG(INFO) << storage->GetNameForLogs() << ": read whole attachment " << uuid |
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
260 << " (" << timer.GetHumanTransferSpeed(true, fileSize) << ")"; |
1 | 261 } |
262 catch (StoragePluginException& ex) | |
263 { | |
98 | 264 logErrorFunction(storage->GetNameForLogs() + ": error while reading object " + std::string(uuid) + ": " + ex.what()); |
77 | 265 return OrthancPluginErrorCode_StorageAreaPlugin; |
1 | 266 } |
267 | |
268 return OrthancPluginErrorCode_Success; | |
269 } | |
270 | |
77 | 271 static OrthancPluginErrorCode StorageReadWhole(OrthancPluginMemoryBuffer64* target, // Memory buffer where to store the content of the file. It must be allocated by the plugin using OrthancPluginCreateMemoryBuffer64(). The core of Orthanc will free it. |
272 const char* uuid, | |
273 OrthancPluginContentType type) | |
274 { | |
78 | 275 OrthancPluginErrorCode res = StorageReadWhole(primaryStorage.get(), |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
276 (IsHybridModeEnabled() ? LogErrorAsWarning : LogErrorAsError), // log errors as warning on first try |
77 | 277 target, |
278 uuid, | |
279 type); | |
280 | |
281 if (res != OrthancPluginErrorCode_Success && IsHybridModeEnabled()) | |
282 { | |
78 | 283 res = StorageReadWhole(secondaryStorage.get(), |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
284 LogErrorAsError, // log errors as errors on second try |
77 | 285 target, |
286 uuid, | |
287 type); | |
288 } | |
289 return res; | |
290 } | |
291 | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
292 static OrthancPluginErrorCode StorageReadWholeLegacy(void** content, |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
293 int64_t* size, |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
294 const char* uuid, |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
295 OrthancPluginContentType type) |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
296 { |
43
4c71c5e2edce
fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents:
39
diff
changeset
|
297 OrthancPluginMemoryBuffer64 buffer; |
4c71c5e2edce
fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents:
39
diff
changeset
|
298 OrthancPluginErrorCode result = StorageReadWhole(&buffer, uuid, type); // will allocate OrthancPluginMemoryBuffer64 |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
299 |
43
4c71c5e2edce
fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents:
39
diff
changeset
|
300 if (result == OrthancPluginErrorCode_Success) |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
301 { |
43
4c71c5e2edce
fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents:
39
diff
changeset
|
302 *size = buffer.size; |
4c71c5e2edce
fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents:
39
diff
changeset
|
303 *content = buffer.data; // orthanc will free the buffer (we don't have to delete it ourselves) |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
304 } |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
305 |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
306 return result; |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
307 } |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
308 |
1 | 309 |
78 | 310 static OrthancPluginErrorCode StorageRemove(IStorage* storage, |
77 | 311 LogErrorFunction logErrorFunction, |
312 const char* uuid, | |
1 | 313 OrthancPluginContentType type) |
314 { | |
315 try | |
316 { | |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
317 LOG(INFO) << storage->GetNameForLogs() << ": deleting attachment " << uuid |
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
318 << " of type " << boost::lexical_cast<std::string>(type); |
78 | 319 storage->DeleteObject(uuid, type, cryptoEnabled); |
320 if ((storage == primaryStorage.get()) && IsHybridModeEnabled()) | |
77 | 321 { |
322 // not 100% sure the file has been deleted, try the secondary plugin | |
323 return OrthancPluginErrorCode_StorageAreaPlugin; | |
324 } | |
325 | |
326 return OrthancPluginErrorCode_Success; | |
1 | 327 } |
328 catch (StoragePluginException& ex) | |
329 { | |
77 | 330 logErrorFunction(std::string(StoragePluginFactory::GetStoragePluginName()) + ": error while deleting object " + std::string(uuid) + ": " + std::string(ex.what())); |
331 return OrthancPluginErrorCode_StorageAreaPlugin; | |
332 } | |
333 } | |
15 | 334 |
77 | 335 static OrthancPluginErrorCode StorageRemove(const char* uuid, |
336 OrthancPluginContentType type) | |
337 { | |
78 | 338 OrthancPluginErrorCode res = StorageRemove(primaryStorage.get(), |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
339 (IsHybridModeEnabled() ? LogErrorAsWarning : LogErrorAsError), // log errors as warning on first try |
77 | 340 uuid, |
341 type); | |
15 | 342 |
77 | 343 if (res != OrthancPluginErrorCode_Success && IsHybridModeEnabled()) |
344 { | |
78 | 345 res = StorageRemove(secondaryStorage.get(), |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
346 LogErrorAsError, // log errors as errors on second try |
77 | 347 uuid, |
348 type); | |
1 | 349 } |
77 | 350 return res; |
1 | 351 } |
352 | |
353 | |
84 | 354 static MoveStorageJob* CreateMoveStorageJob(const std::string& targetStorage, const std::vector<std::string>& instances, const Json::Value& resourcesForJobContent) |
355 { | |
356 std::unique_ptr<MoveStorageJob> job(new MoveStorageJob(targetStorage, instances, resourcesForJobContent, cryptoEnabled)); | |
357 | |
358 if (hybridMode == HybridMode_WriteToFileSystem) | |
359 { | |
360 job->SetStorages(primaryStorage.get(), secondaryStorage.get()); | |
361 } | |
362 else | |
363 { | |
364 job->SetStorages(secondaryStorage.get(), primaryStorage.get()); | |
365 } | |
366 | |
367 return job.release(); | |
368 } | |
369 | |
370 | |
83
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
371 static void AddResourceForJobContent(Json::Value& resourcesForJobContent /* out */, Orthanc::ResourceType resourceType, const std::string& resourceId) |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
372 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
373 const char* resourceGroup = Orthanc::GetResourceTypeText(resourceType, true, true); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
374 |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
375 if (!resourcesForJobContent.isMember(resourceGroup)) |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
376 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
377 resourcesForJobContent[resourceGroup] = Json::arrayValue; |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
378 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
379 |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
380 resourcesForJobContent[resourceGroup].append(resourceId); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
381 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
382 |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
383 void MoveStorage(OrthancPluginRestOutput* output, |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
384 const char* /*url*/, |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
385 const OrthancPluginHttpRequest* request) |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
386 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
387 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
388 |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
389 if (request->method != OrthancPluginHttpMethod_Post) |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
390 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
391 OrthancPluginSendMethodNotAllowed(context, output, "POST"); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
392 return; |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
393 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
394 |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
395 Json::Value requestPayload; |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
396 |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
397 if (!OrthancPlugins::ReadJson(requestPayload, request->body, request->bodySize)) |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
398 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
399 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "A JSON payload was expected"); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
400 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
401 |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
402 std::vector<std::string> instances; |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
403 Json::Value resourcesForJobContent; |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
404 |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
405 if (requestPayload.type() != Json::objectValue || |
84 | 406 !requestPayload.isMember(KEY_RESOURCES) || |
407 requestPayload[KEY_RESOURCES].type() != Json::arrayValue) | |
83
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
408 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
409 throw Orthanc::OrthancException( |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
410 Orthanc::ErrorCode_BadFileFormat, |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
411 "A request to the move-storage endpoint must provide a JSON object " |
84 | 412 "with the field \"" + std::string(KEY_RESOURCES) + |
83
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
413 "\" containing an array of resources to be sent"); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
414 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
415 |
84 | 416 if (!requestPayload.isMember(KEY_TARGET_STORAGE) |
417 || requestPayload[KEY_TARGET_STORAGE].type() != Json::stringValue | |
418 || (requestPayload[KEY_TARGET_STORAGE].asString() != STORAGE_TYPE_FILE_SYSTEM && requestPayload[KEY_TARGET_STORAGE].asString() != STORAGE_TYPE_OBJECT_STORAGE)) | |
83
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
419 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
420 throw Orthanc::OrthancException( |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
421 Orthanc::ErrorCode_BadFileFormat, |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
422 "A request to the move-storage endpoint must provide a JSON object " |
84 | 423 "with the field \"" + std::string(KEY_TARGET_STORAGE) + |
424 "\" set to \"" + std::string(STORAGE_TYPE_FILE_SYSTEM) + "\" or \"" + std::string(STORAGE_TYPE_OBJECT_STORAGE) + "\""); | |
83
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
425 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
426 |
84 | 427 const std::string& targetStorage = requestPayload[KEY_TARGET_STORAGE].asString(); |
428 const Json::Value& resources = requestPayload[KEY_RESOURCES]; | |
83
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
429 |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
430 // Extract information about all the child instances |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
431 for (Json::Value::ArrayIndex i = 0; i < resources.size(); i++) |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
432 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
433 if (resources[i].type() != Json::stringValue) |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
434 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
435 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
436 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
437 |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
438 std::string resource = resources[i].asString(); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
439 if (resource.empty()) |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
440 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
441 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
442 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
443 |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
444 // Test whether this resource is an instance |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
445 Json::Value tmpResource; |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
446 Json::Value tmpInstances; |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
447 if (OrthancPlugins::RestApiGet(tmpResource, "/instances/" + resource, false)) |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
448 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
449 instances.push_back(resource); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
450 AddResourceForJobContent(resourcesForJobContent, Orthanc::ResourceType_Instance, resource); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
451 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
452 // This was not an instance, successively try with series/studies/patients |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
453 else if ((OrthancPlugins::RestApiGet(tmpResource, "/series/" + resource, false) && |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
454 OrthancPlugins::RestApiGet(tmpInstances, "/series/" + resource + "/instances", false)) || |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
455 (OrthancPlugins::RestApiGet(tmpResource, "/studies/" + resource, false) && |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
456 OrthancPlugins::RestApiGet(tmpInstances, "/studies/" + resource + "/instances", false)) || |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
457 (OrthancPlugins::RestApiGet(tmpResource, "/patients/" + resource, false) && |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
458 OrthancPlugins::RestApiGet(tmpInstances, "/patients/" + resource + "/instances", false))) |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
459 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
460 if (tmpInstances.type() != Json::arrayValue) |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
461 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
462 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
463 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
464 |
84 | 465 AddResourceForJobContent(resourcesForJobContent, Orthanc::StringToResourceType(tmpResource["Type"].asString().c_str()), resource); |
466 | |
83
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
467 for (Json::Value::ArrayIndex j = 0; j < tmpInstances.size(); j++) |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
468 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
469 instances.push_back(tmpInstances[j]["ID"].asString()); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
470 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
471 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
472 else |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
473 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
474 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
475 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
476 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
477 |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
478 LOG(INFO) << "Moving " << instances.size() << " instances to " << targetStorage; |
83
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
479 |
84 | 480 std::unique_ptr<MoveStorageJob> job(CreateMoveStorageJob(targetStorage, instances, resourcesForJobContent)); |
83
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
481 |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
482 OrthancPlugins::OrthancJob::SubmitFromRestApiPost(output, requestPayload, job.release()); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
483 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
484 |
84 | 485 OrthancPluginJob* JobUnserializer(const char* jobType, |
486 const char* serialized) | |
487 { | |
488 if (jobType == NULL || | |
489 serialized == NULL) | |
490 { | |
491 return NULL; | |
492 } | |
493 | |
494 std::string type(jobType); | |
495 | |
496 if (type != JOB_TYPE_MOVE_STORAGE) | |
497 { | |
498 return NULL; | |
499 } | |
500 | |
501 try | |
502 { | |
503 std::string tmp(serialized); | |
504 | |
505 Json::Value source; | |
506 if (Orthanc::Toolbox::ReadJson(source, tmp)) | |
507 { | |
508 std::unique_ptr<OrthancPlugins::OrthancJob> job; | |
509 | |
510 if (type == JOB_TYPE_MOVE_STORAGE) | |
511 { | |
512 std::vector<std::string> instances; | |
513 | |
514 for (size_t i = 0; i < source[KEY_INSTANCES].size(); ++i) | |
515 { | |
516 instances.push_back(source[KEY_INSTANCES][static_cast<int>(i)].asString()); | |
517 } | |
518 | |
519 job.reset(CreateMoveStorageJob(source[KEY_TARGET_STORAGE].asString(), instances, source[KEY_CONTENT])); | |
520 } | |
521 | |
522 if (job.get() == NULL) | |
523 { | |
524 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
525 } | |
526 else | |
527 { | |
528 return OrthancPlugins::OrthancJob::Create(job.release()); | |
529 } | |
530 } | |
531 else | |
532 { | |
533 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
534 } | |
535 } | |
536 catch (Orthanc::OrthancException& e) | |
537 { | |
538 LOG(ERROR) << "Error while unserializing a job from the " << StoragePluginFactory::GetStoragePluginName() << " plugin: " | |
539 << e.What(); | |
540 return NULL; | |
541 } | |
542 catch (...) | |
543 { | |
544 LOG(ERROR) << "Error while unserializing a job from the " << StoragePluginFactory::GetStoragePluginName() << " plugin"; | |
545 return NULL; | |
546 } | |
547 } | |
548 | |
549 | |
1 | 550 extern "C" |
551 { | |
552 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) | |
553 { | |
554 OrthancPlugins::SetGlobalContext(context); | |
555 | |
151
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
556 #if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 12, 4) |
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
557 Orthanc::Logging::InitializePluginContext(context, StoragePluginFactory::GetStoragePluginName()); |
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
558 #elif ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 7, 2) |
15 | 559 Orthanc::Logging::InitializePluginContext(context); |
151
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
560 #else |
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
561 Orthanc::Logging::Initialize(context); |
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
562 #endif |
1 | 563 |
564 /* Check the version of the Orthanc core */ | |
565 if (OrthancPluginCheckVersion(context) == 0) | |
566 { | |
567 char info[1024]; | |
568 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin", | |
569 context->orthancVersion, | |
570 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, | |
571 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, | |
572 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); | |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
573 LOG(ERROR) << info; |
1 | 574 return -1; |
575 } | |
576 | |
151
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
577 Orthanc::InitializeFramework("", false); |
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
578 |
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
579 OrthancPlugins::OrthancConfiguration orthancConfig; |
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
580 |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
581 LOG(WARNING) << StoragePluginFactory::GetStoragePluginName() << " plugin is initializing"; |
151
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
582 OrthancPlugins::SetDescription(StoragePluginFactory::GetStoragePluginName(), StoragePluginFactory::GetStorageDescription()); |
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
583 |
27
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
584 try |
8 | 585 { |
77 | 586 const char* pluginSectionName = StoragePluginFactory::GetConfigurationSectionName(); |
27
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
587 static const char* const ENCRYPTION_SECTION = "StorageEncryption"; |
20 | 588 |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
589 if (!orthancConfig.IsSection(pluginSectionName)) |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
590 { |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
591 LOG(WARNING) << StoragePluginFactory::GetStoragePluginName() << ": no \"" << pluginSectionName |
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
592 << "\" section found in configuration, plugin is disabled"; |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
593 return 0; |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
594 } |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
595 |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
596 OrthancPlugins::OrthancConfiguration pluginSection; |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
597 orthancConfig.GetSection(pluginSection, pluginSectionName); |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
598 |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
599 bool migrationFromFileSystemEnabled = pluginSection.GetBooleanValue("MigrationFromFileSystemEnabled", false); |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
600 std::string hybridModeString = pluginSection.GetStringValue("HybridMode", "Disabled"); |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
601 |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
602 if (migrationFromFileSystemEnabled && hybridModeString == "Disabled") |
15 | 603 { |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
604 hybridMode = HybridMode_WriteToObjectStorage; |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
605 LOG(WARNING) << StoragePluginFactory::GetStoragePluginName() << ": 'MigrationFromFileSystemEnabled' configuration is deprecated, use 'HybridMode': 'WriteToObjectStorage' instead"; |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
606 } |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
607 else if (hybridModeString == "WriteToObjectStorage") |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
608 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
609 hybridMode = HybridMode_WriteToObjectStorage; |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
610 LOG(WARNING) << StoragePluginFactory::GetStoragePluginName() << ": WriteToObjectStorage HybridMode is enabled: writing to object-storage, try reading first from object-storage and, then, from file system"; |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
611 } |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
612 else if (hybridModeString == "WriteToFileSystem") |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
613 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
614 hybridMode = HybridMode_WriteToFileSystem; |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
615 LOG(WARNING) << StoragePluginFactory::GetStoragePluginName() << ": WriteToFileSystem HybridMode is enabled: writing to file system, try reading first from file system and, then, from object-storage"; |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
616 } |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
617 else |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
618 { |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
619 LOG(WARNING) << StoragePluginFactory::GetStoragePluginName() << ": HybridMode is disabled: writing to object-storage and reading only from object-storage"; |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
620 } |
27
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
621 |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
622 if (IsReadFromDisk()) |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
623 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
624 fileSystemRootPath = orthancConfig.GetStringValue("StorageDirectory", "OrthancStorageNotDefined"); |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
625 LOG(WARNING) << StoragePluginFactory::GetStoragePluginName() << ": HybridMode: reading from file system is enabled, source: " << fileSystemRootPath; |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
626 } |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
627 |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
628 objectsRootPath = pluginSection.GetStringValue("RootPath", std::string()); |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
629 |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
630 if (objectsRootPath.size() >= 1 && objectsRootPath[0] == '/') |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
631 { |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
632 LOG(ERROR) << StoragePluginFactory::GetStoragePluginName() << ": The RootPath shall not start with a '/': " << objectsRootPath; |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
633 return -1; |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
634 } |
77 | 635 |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
636 std::string objecstStoragePluginName = StoragePluginFactory::GetStoragePluginName(); |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
637 if (hybridMode == HybridMode_WriteToFileSystem) |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
638 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
639 objecstStoragePluginName += " (Secondary: object-storage)"; |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
640 } |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
641 else if (hybridMode == HybridMode_WriteToObjectStorage) |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
642 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
643 objecstStoragePluginName += " (Primary: object-storage)"; |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
644 } |
27
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
645 |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
646 std::unique_ptr<IStorage> objectStoragePlugin(StoragePluginFactory::CreateStorage(objecstStoragePluginName, orthancConfig)); |
33 | 647 |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
648 if (objectStoragePlugin.get() == nullptr) |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
649 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
650 return -1; |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
651 } |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
652 |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
653 objectStoragePlugin->SetRootPath(objectsRootPath); |
15 | 654 |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
655 std::unique_ptr<IStorage> fileSystemStoragePlugin; |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
656 if (IsHybridModeEnabled()) |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
657 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
658 bool fsync = orthancConfig.GetBooleanValue("SyncStorageArea", true); |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
659 |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
660 std::string filesystemStoragePluginName = StoragePluginFactory::GetStoragePluginName(); |
77 | 661 if (hybridMode == HybridMode_WriteToFileSystem) |
662 { | |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
663 filesystemStoragePluginName += " (Primary: file-system)"; |
77 | 664 } |
665 else if (hybridMode == HybridMode_WriteToObjectStorage) | |
666 { | |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
667 filesystemStoragePluginName += " (Secondary: file-system)"; |
77 | 668 } |
669 | |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
670 fileSystemStoragePlugin.reset(new FileSystemStoragePlugin(filesystemStoragePluginName, fileSystemRootPath, fsync)); |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
671 } |
27
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
672 |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
673 if (hybridMode == HybridMode_Disabled || hybridMode == HybridMode_WriteToObjectStorage) |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
674 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
675 primaryStorage.reset(objectStoragePlugin.release()); |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
676 |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
677 if (hybridMode == HybridMode_WriteToObjectStorage) |
27
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
678 { |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
679 secondaryStorage.reset(fileSystemStoragePlugin.release()); |
27
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
680 } |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
681 } |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
682 else if (hybridMode == HybridMode_WriteToFileSystem) |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
683 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
684 primaryStorage.reset(fileSystemStoragePlugin.release()); |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
685 secondaryStorage.reset(objectStoragePlugin.release()); |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
686 } |
77 | 687 |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
688 if (pluginSection.IsSection(ENCRYPTION_SECTION)) |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
689 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
690 OrthancPlugins::OrthancConfiguration cryptoSection; |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
691 pluginSection.GetSection(cryptoSection, ENCRYPTION_SECTION); |
83
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
692 |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
693 crypto.reset(EncryptionConfigurator::CreateEncryptionHelpers(cryptoSection)); |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
694 cryptoEnabled = crypto.get() != nullptr; |
15 | 695 } |
696 | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
697 if (cryptoEnabled) |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
698 { |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
699 LOG(WARNING) << StoragePluginFactory::GetStoragePluginName() << ": client-side encryption is enabled"; |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
700 } |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
701 else |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
702 { |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
703 LOG(WARNING) << StoragePluginFactory::GetStoragePluginName() << ": client-side encryption is disabled"; |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
704 } |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
705 |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
706 |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
707 if (IsHybridModeEnabled()) |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
708 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
709 OrthancPlugins::RegisterRestCallback<MoveStorage>("/move-storage", true); |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
710 OrthancPluginRegisterJobsUnserializer(context, JobUnserializer); |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
711 } |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
712 |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
713 if (cryptoEnabled) |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
714 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
715 // with encrypted file, we can not support ReadRange. Therefore, we register the old interface |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
716 OrthancPluginRegisterStorageArea(context, StorageCreate, StorageReadWholeLegacy, StorageRemove); |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
717 } |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
718 else |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
719 { |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
720 OrthancPluginRegisterStorageArea2(context, StorageCreate, StorageReadWhole, StorageReadRange, StorageRemove); |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
721 } |
1 | 722 } |
27
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
723 catch (Orthanc::OrthancException& e) |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
724 { |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
725 LOG(ERROR) << "Exception while creating the object storage plugin: " << e.What(); |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
726 return -1; |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
727 } |
1 | 728 |
729 return 0; | |
730 } | |
731 | |
732 | |
733 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | |
734 { | |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
735 LOG(WARNING) << StoragePluginFactory::GetStoragePluginName() << " plugin is finalizing"; |
78 | 736 primaryStorage.reset(); |
737 secondaryStorage.reset(); | |
57
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
738 Orthanc::FinalizeFramework(); |
1 | 739 } |
740 | |
741 | |
742 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
743 { | |
744 return StoragePluginFactory::GetStoragePluginName(); | |
745 } | |
746 | |
747 | |
748 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
749 { | |
750 return PLUGIN_VERSION; | |
751 } | |
752 } | |
753 |