Mercurial > hg > orthanc-object-storage
annotate Common/StoragePlugin.cpp @ 151:00cd1f01dd5d
fix initialization and finalization
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 21 Jun 2024 10:29:52 +0200 |
parents | 3c7e0374f28e |
children | d62f52be1943 |
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 | |
1 | 53 |
78 | 54 static std::unique_ptr<IStorage> primaryStorage; |
55 static std::unique_ptr<IStorage> secondaryStorage; | |
1 | 56 |
57 static std::unique_ptr<EncryptionHelpers> crypto; | |
58 static bool cryptoEnabled = false; | |
15 | 59 static std::string fileSystemRootPath; |
20 | 60 static std::string objectsRootPath; |
77 | 61 static std::string hybridModeNameForLogs = ""; |
62 | |
63 typedef enum | |
64 { | |
65 HybridMode_WriteToFileSystem, // write to disk, try to read first from disk and then, from object-storage | |
66 HybridMode_WriteToObjectStorage, // write to object storage, try to read first from object storage and then, from disk | |
67 HybridMode_Disabled // read and write only from/to object-storage | |
68 } HybridMode; | |
69 | |
70 static HybridMode hybridMode = HybridMode_Disabled; | |
71 | |
72 static bool IsReadFromDisk() | |
73 { | |
74 return hybridMode != HybridMode_Disabled; | |
75 } | |
76 | |
77 static bool IsHybridModeEnabled() | |
78 { | |
79 return hybridMode != HybridMode_Disabled; | |
80 } | |
81 | |
82 typedef void LogErrorFunction(const std::string& message); | |
83 | |
1 | 84 |
85 | |
86 static OrthancPluginErrorCode StorageCreate(const char* uuid, | |
87 const void* content, | |
88 int64_t size, | |
89 OrthancPluginContentType type) | |
90 { | |
91 try | |
92 { | |
120
12ea59c97c40
sync orthanc folder + show timings + EnableAwsSdkLogs
Alain Mazy <am@osimis.io>
parents:
98
diff
changeset
|
93 Orthanc::Toolbox::ElapsedTimer timer; |
78 | 94 OrthancPlugins::LogInfo(primaryStorage->GetNameForLogs() + ": creating attachment " + std::string(uuid) + " of type " + boost::lexical_cast<std::string>(type)); |
95 std::unique_ptr<IStorage::IWriter> writer(primaryStorage->GetWriterForObject(uuid, type, cryptoEnabled)); | |
1 | 96 |
97 if (cryptoEnabled) | |
98 { | |
99 std::string encryptedFile; | |
100 | |
101 try | |
102 { | |
103 crypto->Encrypt(encryptedFile, (const char*)content, size); | |
104 } | |
105 catch (EncryptionException& ex) | |
106 { | |
78 | 107 OrthancPlugins::LogError(primaryStorage->GetNameForLogs() + ": error while encrypting object " + std::string(uuid) + ": " + ex.what()); |
1 | 108 return OrthancPluginErrorCode_StorageAreaPlugin; |
109 } | |
110 | |
111 writer->Write(encryptedFile.data(), encryptedFile.size()); | |
112 } | |
113 else | |
114 { | |
115 writer->Write(reinterpret_cast<const char*>(content), size); | |
116 } | |
120
12ea59c97c40
sync orthanc folder + show timings + EnableAwsSdkLogs
Alain Mazy <am@osimis.io>
parents:
98
diff
changeset
|
117 OrthancPlugins::LogInfo(primaryStorage->GetNameForLogs() + ": created attachment " + std::string(uuid) + " (" + timer.GetHumanTransferSpeed(true, size) + ")"); |
1 | 118 } |
119 catch (StoragePluginException& ex) | |
120 { | |
78 | 121 OrthancPlugins::LogError(primaryStorage->GetNameForLogs() + ": error while creating object " + std::string(uuid) + ": " + ex.what()); |
1 | 122 return OrthancPluginErrorCode_StorageAreaPlugin; |
123 } | |
124 | |
125 return OrthancPluginErrorCode_Success; | |
126 } | |
127 | |
128 | |
78 | 129 static OrthancPluginErrorCode StorageReadRange(IStorage* storage, |
77 | 130 LogErrorFunction logErrorFunction, |
131 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
|
132 const char* uuid, |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
133 OrthancPluginContentType type, |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
134 uint64_t rangeStart) |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
135 { |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
136 assert(!cryptoEnabled); |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
137 |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
138 try |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
139 { |
120
12ea59c97c40
sync orthanc folder + show timings + EnableAwsSdkLogs
Alain Mazy <am@osimis.io>
parents:
98
diff
changeset
|
140 Orthanc::Toolbox::ElapsedTimer timer; |
78 | 141 OrthancPlugins::LogInfo(storage->GetNameForLogs() + ": reading range of attachment " + std::string(uuid) + " of type " + boost::lexical_cast<std::string>(type)); |
77 | 142 |
78 | 143 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
|
144 reader->ReadRange(reinterpret_cast<char*>(target->data), target->size, rangeStart); |
77 | 145 |
120
12ea59c97c40
sync orthanc folder + show timings + EnableAwsSdkLogs
Alain Mazy <am@osimis.io>
parents:
98
diff
changeset
|
146 OrthancPlugins::LogInfo(storage->GetNameForLogs() + ": read range of attachment " + std::string(uuid) + " (" + timer.GetHumanTransferSpeed(true, target->size) + ")"); |
77 | 147 return OrthancPluginErrorCode_Success; |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
148 } |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
149 catch (StoragePluginException& ex) |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
150 { |
77 | 151 logErrorFunction(std::string(StoragePluginFactory::GetStoragePluginName()) + ": error while reading object " + std::string(uuid) + ": " + std::string(ex.what())); |
152 return OrthancPluginErrorCode_StorageAreaPlugin; | |
153 } | |
154 } | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
155 |
77 | 156 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. |
157 const char* uuid, | |
158 OrthancPluginContentType type, | |
159 uint64_t rangeStart) | |
160 { | |
78 | 161 OrthancPluginErrorCode res = StorageReadRange(primaryStorage.get(), |
77 | 162 (IsHybridModeEnabled() ? OrthancPlugins::LogWarning : OrthancPlugins::LogError), // log errors as warning on first try |
163 target, | |
164 uuid, | |
165 type, | |
166 rangeStart); | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
167 |
77 | 168 if (res != OrthancPluginErrorCode_Success && IsHybridModeEnabled()) |
169 { | |
78 | 170 res = StorageReadRange(secondaryStorage.get(), |
77 | 171 OrthancPlugins::LogError, // log errors as errors on second try |
172 target, | |
173 uuid, | |
174 type, | |
175 rangeStart); | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
176 } |
77 | 177 return res; |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
178 } |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
179 |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
180 |
77 | 181 |
78 | 182 static OrthancPluginErrorCode StorageReadWhole(IStorage* storage, |
77 | 183 LogErrorFunction logErrorFunction, |
184 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
|
185 const char* uuid, |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
186 OrthancPluginContentType type) |
1 | 187 { |
188 try | |
189 { | |
120
12ea59c97c40
sync orthanc folder + show timings + EnableAwsSdkLogs
Alain Mazy <am@osimis.io>
parents:
98
diff
changeset
|
190 Orthanc::Toolbox::ElapsedTimer timer; |
78 | 191 OrthancPlugins::LogInfo(storage->GetNameForLogs() + ": reading whole attachment " + std::string(uuid) + " of type " + boost::lexical_cast<std::string>(type)); |
192 std::unique_ptr<IStorage::IReader> reader(storage->GetReaderForObject(uuid, type, cryptoEnabled)); | |
1 | 193 |
194 size_t fileSize = reader->GetSize(); | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
195 size_t size; |
1 | 196 |
197 if (cryptoEnabled) | |
198 { | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
199 size = fileSize - crypto->OVERHEAD_SIZE; |
1 | 200 } |
201 else | |
202 { | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
203 size = fileSize; |
1 | 204 } |
205 | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
206 if (size <= 0) |
1 | 207 { |
78 | 208 logErrorFunction(storage->GetNameForLogs() + ": error while reading object " + std::string(uuid) + ", size of file is too small: " + boost::lexical_cast<std::string>(fileSize) + " bytes"); |
1 | 209 return OrthancPluginErrorCode_StorageAreaPlugin; |
210 } | |
211 | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
212 if (OrthancPluginCreateMemoryBuffer64(OrthancPlugins::GetGlobalContext(), target, size) != OrthancPluginErrorCode_Success) |
1 | 213 { |
78 | 214 logErrorFunction(storage->GetNameForLogs() + ": error while reading object " + std::string(uuid) + ", cannot allocate memory of size " + boost::lexical_cast<std::string>(size) + " bytes"); |
1 | 215 return OrthancPluginErrorCode_StorageAreaPlugin; |
216 } | |
217 | |
218 if (cryptoEnabled) | |
219 { | |
220 std::vector<char> encrypted(fileSize); | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
221 reader->ReadWhole(encrypted.data(), fileSize); |
1 | 222 |
223 try | |
224 { | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
225 crypto->Decrypt(reinterpret_cast<char*>(target->data), encrypted.data(), fileSize); |
1 | 226 } |
227 catch (EncryptionException& ex) | |
228 { | |
78 | 229 logErrorFunction(storage->GetNameForLogs() + ": error while decrypting object " + std::string(uuid) + ": " + ex.what()); |
1 | 230 return OrthancPluginErrorCode_StorageAreaPlugin; |
231 } | |
232 } | |
233 else | |
234 { | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
235 reader->ReadWhole(reinterpret_cast<char*>(target->data), fileSize); |
1 | 236 } |
120
12ea59c97c40
sync orthanc folder + show timings + EnableAwsSdkLogs
Alain Mazy <am@osimis.io>
parents:
98
diff
changeset
|
237 |
12ea59c97c40
sync orthanc folder + show timings + EnableAwsSdkLogs
Alain Mazy <am@osimis.io>
parents:
98
diff
changeset
|
238 OrthancPlugins::LogInfo(storage->GetNameForLogs() + ": read whole attachment " + std::string(uuid) + " (" + timer.GetHumanTransferSpeed(true, fileSize) + ")"); |
1 | 239 } |
240 catch (StoragePluginException& ex) | |
241 { | |
98 | 242 logErrorFunction(storage->GetNameForLogs() + ": error while reading object " + std::string(uuid) + ": " + ex.what()); |
77 | 243 return OrthancPluginErrorCode_StorageAreaPlugin; |
1 | 244 } |
245 | |
246 return OrthancPluginErrorCode_Success; | |
247 } | |
248 | |
77 | 249 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. |
250 const char* uuid, | |
251 OrthancPluginContentType type) | |
252 { | |
78 | 253 OrthancPluginErrorCode res = StorageReadWhole(primaryStorage.get(), |
77 | 254 (IsHybridModeEnabled() ? OrthancPlugins::LogWarning : OrthancPlugins::LogError), // log errors as warning on first try |
255 target, | |
256 uuid, | |
257 type); | |
258 | |
259 if (res != OrthancPluginErrorCode_Success && IsHybridModeEnabled()) | |
260 { | |
78 | 261 res = StorageReadWhole(secondaryStorage.get(), |
77 | 262 OrthancPlugins::LogError, // log errors as errors on second try |
263 target, | |
264 uuid, | |
265 type); | |
266 } | |
267 return res; | |
268 } | |
269 | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
270 static OrthancPluginErrorCode StorageReadWholeLegacy(void** content, |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
271 int64_t* size, |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
272 const char* uuid, |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
273 OrthancPluginContentType type) |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
274 { |
43
4c71c5e2edce
fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents:
39
diff
changeset
|
275 OrthancPluginMemoryBuffer64 buffer; |
4c71c5e2edce
fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents:
39
diff
changeset
|
276 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
|
277 |
43
4c71c5e2edce
fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents:
39
diff
changeset
|
278 if (result == OrthancPluginErrorCode_Success) |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
279 { |
43
4c71c5e2edce
fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents:
39
diff
changeset
|
280 *size = buffer.size; |
4c71c5e2edce
fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents:
39
diff
changeset
|
281 *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
|
282 } |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
283 |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
284 return result; |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
285 } |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
286 |
1 | 287 |
78 | 288 static OrthancPluginErrorCode StorageRemove(IStorage* storage, |
77 | 289 LogErrorFunction logErrorFunction, |
290 const char* uuid, | |
1 | 291 OrthancPluginContentType type) |
292 { | |
293 try | |
294 { | |
78 | 295 OrthancPlugins::LogInfo(storage->GetNameForLogs() + ": deleting attachment " + std::string(uuid) + " of type " + boost::lexical_cast<std::string>(type)); |
296 storage->DeleteObject(uuid, type, cryptoEnabled); | |
297 if ((storage == primaryStorage.get()) && IsHybridModeEnabled()) | |
77 | 298 { |
299 // not 100% sure the file has been deleted, try the secondary plugin | |
300 return OrthancPluginErrorCode_StorageAreaPlugin; | |
301 } | |
302 | |
303 return OrthancPluginErrorCode_Success; | |
1 | 304 } |
305 catch (StoragePluginException& ex) | |
306 { | |
77 | 307 logErrorFunction(std::string(StoragePluginFactory::GetStoragePluginName()) + ": error while deleting object " + std::string(uuid) + ": " + std::string(ex.what())); |
308 return OrthancPluginErrorCode_StorageAreaPlugin; | |
309 } | |
310 } | |
15 | 311 |
77 | 312 static OrthancPluginErrorCode StorageRemove(const char* uuid, |
313 OrthancPluginContentType type) | |
314 { | |
78 | 315 OrthancPluginErrorCode res = StorageRemove(primaryStorage.get(), |
77 | 316 (IsHybridModeEnabled() ? OrthancPlugins::LogWarning : OrthancPlugins::LogError), // log errors as warning on first try |
317 uuid, | |
318 type); | |
15 | 319 |
77 | 320 if (res != OrthancPluginErrorCode_Success && IsHybridModeEnabled()) |
321 { | |
78 | 322 res = StorageRemove(secondaryStorage.get(), |
77 | 323 OrthancPlugins::LogError, // log errors as errors on second try |
324 uuid, | |
325 type); | |
1 | 326 } |
77 | 327 return res; |
1 | 328 } |
329 | |
330 | |
84 | 331 static MoveStorageJob* CreateMoveStorageJob(const std::string& targetStorage, const std::vector<std::string>& instances, const Json::Value& resourcesForJobContent) |
332 { | |
333 std::unique_ptr<MoveStorageJob> job(new MoveStorageJob(targetStorage, instances, resourcesForJobContent, cryptoEnabled)); | |
334 | |
335 if (hybridMode == HybridMode_WriteToFileSystem) | |
336 { | |
337 job->SetStorages(primaryStorage.get(), secondaryStorage.get()); | |
338 } | |
339 else | |
340 { | |
341 job->SetStorages(secondaryStorage.get(), primaryStorage.get()); | |
342 } | |
343 | |
344 return job.release(); | |
345 } | |
346 | |
347 | |
83
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
348 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
|
349 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
350 const char* resourceGroup = Orthanc::GetResourceTypeText(resourceType, true, true); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
351 |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
352 if (!resourcesForJobContent.isMember(resourceGroup)) |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
353 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
354 resourcesForJobContent[resourceGroup] = Json::arrayValue; |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
355 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
356 |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
357 resourcesForJobContent[resourceGroup].append(resourceId); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
358 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
359 |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
360 void MoveStorage(OrthancPluginRestOutput* output, |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
361 const char* /*url*/, |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
362 const OrthancPluginHttpRequest* request) |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
363 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
364 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
365 |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
366 if (request->method != OrthancPluginHttpMethod_Post) |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
367 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
368 OrthancPluginSendMethodNotAllowed(context, output, "POST"); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
369 return; |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
370 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
371 |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
372 Json::Value requestPayload; |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
373 |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
374 if (!OrthancPlugins::ReadJson(requestPayload, request->body, request->bodySize)) |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
375 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
376 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
|
377 } |
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 std::vector<std::string> instances; |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
380 Json::Value resourcesForJobContent; |
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 if (requestPayload.type() != Json::objectValue || |
84 | 383 !requestPayload.isMember(KEY_RESOURCES) || |
384 requestPayload[KEY_RESOURCES].type() != Json::arrayValue) | |
83
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
385 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
386 throw Orthanc::OrthancException( |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
387 Orthanc::ErrorCode_BadFileFormat, |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
388 "A request to the move-storage endpoint must provide a JSON object " |
84 | 389 "with the field \"" + std::string(KEY_RESOURCES) + |
83
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
390 "\" containing an array of resources to be sent"); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
391 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
392 |
84 | 393 if (!requestPayload.isMember(KEY_TARGET_STORAGE) |
394 || requestPayload[KEY_TARGET_STORAGE].type() != Json::stringValue | |
395 || (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
|
396 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
397 throw Orthanc::OrthancException( |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
398 Orthanc::ErrorCode_BadFileFormat, |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
399 "A request to the move-storage endpoint must provide a JSON object " |
84 | 400 "with the field \"" + std::string(KEY_TARGET_STORAGE) + |
401 "\" 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
|
402 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
403 |
84 | 404 const std::string& targetStorage = requestPayload[KEY_TARGET_STORAGE].asString(); |
405 const Json::Value& resources = requestPayload[KEY_RESOURCES]; | |
83
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
406 |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
407 // Extract information about all the child instances |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
408 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
|
409 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
410 if (resources[i].type() != Json::stringValue) |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
411 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
412 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
413 } |
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 std::string resource = resources[i].asString(); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
416 if (resource.empty()) |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
417 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
418 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); |
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 |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
421 // Test whether this resource is an instance |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
422 Json::Value tmpResource; |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
423 Json::Value tmpInstances; |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
424 if (OrthancPlugins::RestApiGet(tmpResource, "/instances/" + resource, false)) |
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 instances.push_back(resource); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
427 AddResourceForJobContent(resourcesForJobContent, Orthanc::ResourceType_Instance, resource); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
428 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
429 // 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
|
430 else if ((OrthancPlugins::RestApiGet(tmpResource, "/series/" + resource, false) && |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
431 OrthancPlugins::RestApiGet(tmpInstances, "/series/" + resource + "/instances", false)) || |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
432 (OrthancPlugins::RestApiGet(tmpResource, "/studies/" + resource, false) && |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
433 OrthancPlugins::RestApiGet(tmpInstances, "/studies/" + resource + "/instances", false)) || |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
434 (OrthancPlugins::RestApiGet(tmpResource, "/patients/" + resource, false) && |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
435 OrthancPlugins::RestApiGet(tmpInstances, "/patients/" + resource + "/instances", false))) |
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 if (tmpInstances.type() != Json::arrayValue) |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
438 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
439 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
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 |
84 | 442 AddResourceForJobContent(resourcesForJobContent, Orthanc::StringToResourceType(tmpResource["Type"].asString().c_str()), resource); |
443 | |
83
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
444 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
|
445 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
446 instances.push_back(tmpInstances[j]["ID"].asString()); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
447 } |
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 else |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
450 { |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
451 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
452 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
453 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
454 |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
455 OrthancPlugins::LogInfo("Moving " + boost::lexical_cast<std::string>(instances.size()) + " instances to " + targetStorage); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
456 |
84 | 457 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
|
458 |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
459 OrthancPlugins::OrthancJob::SubmitFromRestApiPost(output, requestPayload, job.release()); |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
460 } |
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
461 |
84 | 462 OrthancPluginJob* JobUnserializer(const char* jobType, |
463 const char* serialized) | |
464 { | |
465 if (jobType == NULL || | |
466 serialized == NULL) | |
467 { | |
468 return NULL; | |
469 } | |
470 | |
471 std::string type(jobType); | |
472 | |
473 if (type != JOB_TYPE_MOVE_STORAGE) | |
474 { | |
475 return NULL; | |
476 } | |
477 | |
478 try | |
479 { | |
480 std::string tmp(serialized); | |
481 | |
482 Json::Value source; | |
483 if (Orthanc::Toolbox::ReadJson(source, tmp)) | |
484 { | |
485 std::unique_ptr<OrthancPlugins::OrthancJob> job; | |
486 | |
487 if (type == JOB_TYPE_MOVE_STORAGE) | |
488 { | |
489 std::vector<std::string> instances; | |
490 | |
491 for (size_t i = 0; i < source[KEY_INSTANCES].size(); ++i) | |
492 { | |
493 instances.push_back(source[KEY_INSTANCES][static_cast<int>(i)].asString()); | |
494 } | |
495 | |
496 job.reset(CreateMoveStorageJob(source[KEY_TARGET_STORAGE].asString(), instances, source[KEY_CONTENT])); | |
497 } | |
498 | |
499 if (job.get() == NULL) | |
500 { | |
501 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
502 } | |
503 else | |
504 { | |
505 return OrthancPlugins::OrthancJob::Create(job.release()); | |
506 } | |
507 } | |
508 else | |
509 { | |
510 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
511 } | |
512 } | |
513 catch (Orthanc::OrthancException& e) | |
514 { | |
515 LOG(ERROR) << "Error while unserializing a job from the " << StoragePluginFactory::GetStoragePluginName() << " plugin: " | |
516 << e.What(); | |
517 return NULL; | |
518 } | |
519 catch (...) | |
520 { | |
521 LOG(ERROR) << "Error while unserializing a job from the " << StoragePluginFactory::GetStoragePluginName() << " plugin"; | |
522 return NULL; | |
523 } | |
524 } | |
525 | |
526 | |
1 | 527 extern "C" |
528 { | |
529 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) | |
530 { | |
531 OrthancPlugins::SetGlobalContext(context); | |
532 | |
151
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
533 #if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 12, 4) |
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
534 Orthanc::Logging::InitializePluginContext(context, StoragePluginFactory::GetStoragePluginName()); |
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
535 #elif ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 7, 2) |
15 | 536 Orthanc::Logging::InitializePluginContext(context); |
151
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
537 #else |
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
538 Orthanc::Logging::Initialize(context); |
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
539 #endif |
1 | 540 |
541 /* Check the version of the Orthanc core */ | |
542 if (OrthancPluginCheckVersion(context) == 0) | |
543 { | |
544 char info[1024]; | |
545 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin", | |
546 context->orthancVersion, | |
547 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, | |
548 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, | |
549 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); | |
550 OrthancPlugins::LogError(info); | |
551 return -1; | |
552 } | |
553 | |
151
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
554 Orthanc::InitializeFramework("", false); |
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
555 |
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
556 OrthancPlugins::OrthancConfiguration orthancConfig; |
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
557 |
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
558 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + " plugin is initializing"); |
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
559 OrthancPlugins::SetDescription(StoragePluginFactory::GetStoragePluginName(), StoragePluginFactory::GetStorageDescription()); |
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
560 |
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
|
561 try |
8 | 562 { |
77 | 563 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
|
564 static const char* const ENCRYPTION_SECTION = "StorageEncryption"; |
20 | 565 |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
566 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
|
567 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
568 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": no \"" + pluginSectionName + "\" section found in configuration, plugin is disabled"); |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
569 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
|
570 } |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
571 |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
572 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
|
573 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
|
574 |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
575 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
|
576 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
|
577 |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
578 if (migrationFromFileSystemEnabled && hybridModeString == "Disabled") |
15 | 579 { |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
580 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
|
581 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": 'MigrationFromFileSystemEnabled' configuration is deprecated, use 'HybridMode': 'WriteToObjectStorage' instead"); |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
582 } |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
583 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
|
584 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
585 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
|
586 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": WriteToObjectStorage HybridMode is enabled: writing to object-storage, try reading first from object-storage and, then, from file system"); |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
587 } |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
588 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
|
589 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
590 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
|
591 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": WriteToFileSystem HybridMode is enabled: writing to file system, try reading first from file system and, then, from 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
|
592 } |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
593 else |
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 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": HybridMode is disabled: writing to object-storage and reading only from 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
|
596 } |
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
|
597 |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
598 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
|
599 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
600 fileSystemRootPath = orthancConfig.GetStringValue("StorageDirectory", "OrthancStorageNotDefined"); |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
601 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": HybridMode: reading from file system is enabled, source: " + fileSystemRootPath); |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
602 } |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
603 |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
604 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
|
605 |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
606 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
|
607 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
608 OrthancPlugins::LogError(std::string(StoragePluginFactory::GetStoragePluginName()) + ": The RootPath shall not start with a '/': " + objectsRootPath); |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
609 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
|
610 } |
77 | 611 |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
612 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
|
613 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
|
614 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
615 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
|
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 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
|
618 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
619 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
|
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 std::unique_ptr<IStorage> objectStoragePlugin(StoragePluginFactory::CreateStorage(objecstStoragePluginName, orthancConfig)); |
33 | 623 |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
624 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
|
625 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
626 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
|
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 |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
629 objectStoragePlugin->SetRootPath(objectsRootPath); |
15 | 630 |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
631 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
|
632 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
|
633 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
634 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
|
635 |
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 filesystemStoragePluginName = StoragePluginFactory::GetStoragePluginName(); |
77 | 637 if (hybridMode == HybridMode_WriteToFileSystem) |
638 { | |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
639 filesystemStoragePluginName += " (Primary: file-system)"; |
77 | 640 } |
641 else if (hybridMode == HybridMode_WriteToObjectStorage) | |
642 { | |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
643 filesystemStoragePluginName += " (Secondary: file-system)"; |
77 | 644 } |
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 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
|
647 } |
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
|
648 |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
649 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
|
650 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
651 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
|
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 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
|
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 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
|
656 } |
95
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 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
|
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 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
|
661 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
|
662 } |
77 | 663 |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
664 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
|
665 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
666 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
|
667 pluginSection.GetSection(cryptoSection, ENCRYPTION_SECTION); |
83
431ab61b5760
/move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
668 |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
669 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
|
670 cryptoEnabled = crypto.get() != nullptr; |
15 | 671 } |
672 | |
39
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
673 if (cryptoEnabled) |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
674 { |
95
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
675 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": client-side encryption is enabled"); |
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 else |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
678 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
679 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": client-side encryption is disabled"); |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
680 } |
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 |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
683 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
|
684 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
685 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
|
686 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
|
687 } |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
688 |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
689 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
|
690 { |
33790e0000bb
Plugins are now disabled if their section is missing in the configuration file.
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
691 // 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
|
692 OrthancPluginRegisterStorageArea(context, StorageCreate, StorageReadWholeLegacy, StorageRemove); |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
693 } |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
694 else |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
695 { |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
696 OrthancPluginRegisterStorageArea2(context, StorageCreate, StorageReadWhole, StorageReadRange, StorageRemove); |
50d0be413c42
implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents:
37
diff
changeset
|
697 } |
1 | 698 } |
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
|
699 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
|
700 { |
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
701 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
|
702 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
|
703 } |
1 | 704 |
705 return 0; | |
706 } | |
707 | |
708 | |
709 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | |
710 { | |
711 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + " plugin is finalizing"); | |
78 | 712 primaryStorage.reset(); |
713 secondaryStorage.reset(); | |
57
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
714 Orthanc::FinalizeFramework(); |
1 | 715 } |
716 | |
717 | |
718 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
719 { | |
720 return StoragePluginFactory::GetStoragePluginName(); | |
721 } | |
722 | |
723 | |
724 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
725 { | |
726 return PLUGIN_VERSION; | |
727 } | |
728 } | |
729 |