Mercurial > hg > orthanc-object-storage
annotate Aws/AwsS3StoragePlugin.cpp @ 197:df0b6998fd27
integration 2.3.0: back to mainline
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 25 Jun 2024 12:38:31 +0200 |
parents | 6dd8bb916573 addccb7ad900 |
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:
141
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:
141
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:
141
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 | |
21 #include "AwsS3StoragePlugin.h" | |
119
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
22 #include <Logging.h> |
1 | 23 |
24 #include <aws/core/Aws.h> | |
25 #include <aws/s3/S3Client.h> | |
26 #include <aws/s3/model/PutObjectRequest.h> | |
27 #include <aws/s3/model/GetObjectRequest.h> | |
28 #include <aws/s3/model/ListObjectsRequest.h> | |
29 #include <aws/s3/model/DeleteObjectRequest.h> | |
30 #include <aws/core/auth/AWSCredentialsProvider.h> | |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
31 #include <aws/core/utils/HashingUtils.h> |
119
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
32 #include <aws/core/utils/logging/DefaultLogSystem.h> |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
33 #include <aws/core/utils/logging/DefaultCRTLogSystem.h> |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
34 #include <aws/core/utils/logging/AWSLogging.h> |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
35 #include <aws/core/utils/memory/stl/AWSStreamFwd.h> |
1 | 36 #include <aws/core/utils/memory/stl/AWSStringStream.h> |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
37 #include <aws/core/utils/memory/AWSMemory.h> |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
38 #include <aws/core/utils/stream/PreallocatedStreamBuf.h> |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
39 #include <aws/core/utils/StringUtils.h> |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
40 #include <aws/transfer/TransferManager.h> |
57
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
41 #include <aws/crt/Api.h> |
119
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
42 #include <iostream> |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
43 #include <fstream> |
1 | 44 |
45 #include <boost/lexical_cast.hpp> | |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
46 #include <boost/interprocess/streams/bufferstream.hpp> |
1 | 47 #include <iostream> |
48 #include <fstream> | |
49 | |
50 const char* ALLOCATION_TAG = "OrthancS3"; | |
51 | |
78 | 52 class AwsS3StoragePlugin : public BaseStorage |
1 | 53 { |
54 public: | |
55 | |
56 std::string bucketName_; | |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
57 bool storageContainsUnknownFiles_; |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
58 bool useTransferManager_; |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
59 std::shared_ptr<Aws::S3::S3Client> client_; |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
60 std::shared_ptr<Aws::Utils::Threading::Executor> executor_; |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
61 std::shared_ptr<Aws::Transfer::TransferManager> transferManager_; |
1 | 62 |
63 public: | |
64 | |
113 | 65 AwsS3StoragePlugin(const std::string& nameForLogs, std::shared_ptr<Aws::S3::S3Client> client, const std::string& bucketName, bool enableLegacyStorageStructure, bool storageContainsUnknownFiles, bool useTransferManager, unsigned int transferThreadPoolSize, unsigned int transferBufferSizeMB); |
1 | 66 |
57
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
67 virtual ~AwsS3StoragePlugin(); |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
68 |
153 | 69 virtual IWriter* GetWriterForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) ORTHANC_OVERRIDE; |
70 virtual IReader* GetReaderForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) ORTHANC_OVERRIDE; | |
71 virtual void DeleteObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) ORTHANC_OVERRIDE; | |
72 | |
73 virtual bool HasFileExists() ORTHANC_OVERRIDE | |
74 { | |
75 return false; | |
76 } | |
1 | 77 }; |
78 | |
79 | |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
80 class DirectWriter : public IStorage::IWriter |
1 | 81 { |
82 std::string path_; | |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
83 std::shared_ptr<Aws::S3::S3Client> client_; |
1 | 84 std::string bucketName_; |
85 | |
86 public: | |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
87 DirectWriter(std::shared_ptr<Aws::S3::S3Client> client, const std::string& bucketName, const std::string& path) |
1 | 88 : path_(path), |
89 client_(client), | |
90 bucketName_(bucketName) | |
91 { | |
92 } | |
93 | |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
94 virtual ~DirectWriter() |
1 | 95 { |
96 } | |
97 | |
153 | 98 virtual void Write(const char* data, size_t size) ORTHANC_OVERRIDE |
1 | 99 { |
100 Aws::S3::Model::PutObjectRequest putObjectRequest; | |
101 | |
102 putObjectRequest.SetBucket(bucketName_.c_str()); | |
103 putObjectRequest.SetKey(path_.c_str()); | |
104 | |
105 std::shared_ptr<Aws::StringStream> stream = Aws::MakeShared<Aws::StringStream>(ALLOCATION_TAG, std::ios_base::in | std::ios_base::binary); | |
106 | |
107 stream->rdbuf()->pubsetbuf(const_cast<char*>(data), size); | |
108 stream->rdbuf()->pubseekpos(size); | |
109 stream->seekg(0); | |
110 | |
111 putObjectRequest.SetBody(stream); | |
74
a25b4140e7e4
AWS: added the content MD5 in the request when writing
Alain Mazy <am@osimis.io>
parents:
70
diff
changeset
|
112 putObjectRequest.SetContentMD5(Aws::Utils::HashingUtils::Base64Encode(Aws::Utils::HashingUtils::CalculateMD5(*stream))); |
1 | 113 |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
114 auto result = client_->PutObject(putObjectRequest); |
1 | 115 |
116 if (!result.IsSuccess()) | |
117 { | |
62 | 118 throw StoragePluginException(std::string("error while writing file ") + path_ + ": response code = " + boost::lexical_cast<std::string>((int)result.GetError().GetResponseCode()) + " " + result.GetError().GetExceptionName().c_str() + " " + result.GetError().GetMessage().c_str()); |
1 | 119 } |
120 } | |
121 }; | |
122 | |
123 | |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
124 class DirectReader : public IStorage::IReader |
1 | 125 { |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
126 protected: |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
127 std::shared_ptr<Aws::S3::S3Client> client_; |
1 | 128 std::string bucketName_; |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
129 std::list<std::string> paths_; |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
130 std::string uuid_; |
1 | 131 |
132 public: | |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
133 DirectReader(std::shared_ptr<Aws::S3::S3Client> client, const std::string& bucketName, const std::list<std::string>& paths, const char* uuid) |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
134 : client_(client), |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
135 bucketName_(bucketName), |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
136 paths_(paths), |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
137 uuid_(uuid) |
1 | 138 { |
139 } | |
140 | |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
141 virtual ~DirectReader() |
1 | 142 { |
143 | |
144 } | |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
145 |
153 | 146 virtual size_t GetSize() ORTHANC_OVERRIDE |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
147 { |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
148 std::string firstExceptionMessage; |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
149 |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
150 for (auto& path: paths_) |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
151 { |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
152 try |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
153 { |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
154 return _GetSize(path); |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
155 } |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
156 catch (StoragePluginException& ex) |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
157 { |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
158 if (firstExceptionMessage.empty()) |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
159 { |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
160 firstExceptionMessage = ex.what(); |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
161 } |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
162 //ignore to retry |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
163 } |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
164 } |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
165 throw StoragePluginException(firstExceptionMessage); |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
166 } |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
167 |
153 | 168 virtual void ReadWhole(char* data, size_t size) ORTHANC_OVERRIDE |
41 | 169 { |
170 _Read(data, size, 0, false); | |
171 } | |
172 | |
153 | 173 virtual void ReadRange(char* data, size_t size, size_t fromOffset) ORTHANC_OVERRIDE |
41 | 174 { |
175 _Read(data, size, fromOffset, true); | |
176 } | |
177 | |
70
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
178 private: |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
179 |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
180 size_t _GetSize(const std::string& path) |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
181 { |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
182 Aws::S3::Model::ListObjectsRequest listObjectRequest; |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
183 listObjectRequest.SetBucket(bucketName_.c_str()); |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
184 listObjectRequest.SetPrefix(path.c_str()); |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
185 |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
186 auto result = client_->ListObjects(listObjectRequest); |
70
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
187 |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
188 if (result.IsSuccess()) |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
189 { |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
190 Aws::Vector<Aws::S3::Model::Object> objectList = |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
191 result.GetResult().GetContents(); |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
192 |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
193 if (objectList.size() == 1) |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
194 { |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
195 return objectList[0].GetSize(); |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
196 } |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
197 else if (objectList.size() > 1) |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
198 { |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
199 throw StoragePluginException(std::string("error while reading file ") + path + ": multiple objet with same name !"); |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
200 } |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
201 throw StoragePluginException(std::string("error while reading file ") + path + ": object not found !"); |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
202 } |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
203 else |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
204 { |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
205 throw StoragePluginException(std::string("error while reading file ") + path + ": " + result.GetError().GetExceptionName().c_str() + " " + result.GetError().GetMessage().c_str()); |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
206 } |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
207 } |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
208 |
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
209 |
41 | 210 void _Read(char* data, size_t size, size_t fromOffset, bool useRange) |
1 | 211 { |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
212 std::string firstExceptionMessage; |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
213 |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
214 for (auto& path: paths_) |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
215 { |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
216 try |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
217 { |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
218 return __Read(path, data, size, fromOffset, useRange); |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
219 } |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
220 catch (StoragePluginException& ex) |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
221 { |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
222 if (firstExceptionMessage.empty()) |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
223 { |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
224 firstExceptionMessage = ex.what(); |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
225 } |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
226 //ignore to retry |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
227 } |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
228 } |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
229 throw StoragePluginException(firstExceptionMessage); |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
230 } |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
231 |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
232 void __Read(const std::string& path, char* data, size_t size, size_t fromOffset, bool useRange) |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
233 { |
1 | 234 Aws::S3::Model::GetObjectRequest getObjectRequest; |
235 getObjectRequest.SetBucket(bucketName_.c_str()); | |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
236 getObjectRequest.SetKey(path.c_str()); |
1 | 237 |
41 | 238 if (useRange) |
239 { | |
240 // https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests | |
241 std::string range = std::string("bytes=") + boost::lexical_cast<std::string>(fromOffset) + "-" + boost::lexical_cast<std::string>(fromOffset + size -1); | |
242 getObjectRequest.SetRange(range.c_str()); | |
243 } | |
244 | |
1 | 245 getObjectRequest.SetResponseStreamFactory( |
246 [data, size]() | |
247 { | |
248 std::unique_ptr<Aws::StringStream> | |
249 istream(Aws::New<Aws::StringStream>(ALLOCATION_TAG)); | |
250 | |
251 istream->rdbuf()->pubsetbuf(static_cast<char*>(data), | |
252 size); | |
253 | |
254 return istream.release(); | |
255 }); | |
256 | |
257 // Get the object | |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
258 auto result = client_->GetObject(getObjectRequest); |
1 | 259 if (result.IsSuccess()) |
260 { | |
261 } | |
262 else | |
263 { | |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
264 throw StoragePluginException(std::string("error while reading file ") + path + ": response code = " + boost::lexical_cast<std::string>((int)result.GetError().GetResponseCode()) + " " + result.GetError().GetExceptionName().c_str() + " " + result.GetError().GetMessage().c_str()); |
1 | 265 } |
266 } | |
267 | |
268 }; | |
269 | |
270 | |
271 | |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
272 class TransferWriter : public IStorage::IWriter |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
273 { |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
274 std::string path_; |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
275 std::shared_ptr<Aws::Transfer::TransferManager> transferManager_; |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
276 std::string bucketName_; |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
277 |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
278 public: |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
279 TransferWriter(std::shared_ptr<Aws::Transfer::TransferManager> transferManager, const std::string& bucketName, const std::string& path) |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
280 : path_(path), |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
281 transferManager_(transferManager), |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
282 bucketName_(bucketName) |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
283 { |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
284 } |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
285 |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
286 virtual ~TransferWriter() |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
287 { |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
288 } |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
289 |
153 | 290 virtual void Write(const char* data, size_t size) ORTHANC_OVERRIDE |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
291 { |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
292 boost::interprocess::bufferstream buffer(const_cast<char*>(static_cast<const char*>(data)), static_cast<size_t>(size)); |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
293 std::shared_ptr<Aws::IOStream> body = Aws::MakeShared<Aws::IOStream>(ALLOCATION_TAG, buffer.rdbuf()); |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
294 |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
295 std::shared_ptr<Aws::Transfer::TransferHandle> transferHandle = transferManager_->UploadFile(body, bucketName_, path_.c_str(), "application/binary", Aws::Map<Aws::String, Aws::String>()); |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
296 transferHandle->WaitUntilFinished(); |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
297 |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
298 if (transferHandle->GetStatus() != Aws::Transfer::TransferStatus::COMPLETED) |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
299 { |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
300 throw StoragePluginException(std::string("error while writing file ") + path_ + ": response code = " + boost::lexical_cast<std::string>(static_cast<int>(transferHandle->GetLastError().GetResponseCode())) + " " + transferHandle->GetLastError().GetMessage()); |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
301 } |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
302 } |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
303 }; |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
304 |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
305 |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
306 class TransferReader : public DirectReader |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
307 { |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
308 std::shared_ptr<Aws::Transfer::TransferManager> transferManager_; |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
309 |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
310 public: |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
311 TransferReader(std::shared_ptr<Aws::Transfer::TransferManager> transferManager, std::shared_ptr<Aws::S3::S3Client> client, const std::string& bucketName, const std::list<std::string>& paths, const char* uuid) |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
312 : DirectReader(client, bucketName, paths, uuid), |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
313 transferManager_(transferManager) |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
314 { |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
315 } |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
316 |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
317 virtual ~TransferReader() |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
318 { |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
319 |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
320 } |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
321 |
153 | 322 virtual void ReadWhole(char* data, size_t size) ORTHANC_OVERRIDE |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
323 { |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
324 std::string firstExceptionMessage; |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
325 |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
326 for (auto& path: paths_) |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
327 { |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
328 try |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
329 { |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
330 // The local variable 'streamBuffer' is captured by reference in a lambda. |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
331 // It must persist until all downloading by the 'transfer_manager' is complete. |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
332 Aws::Utils::Stream::PreallocatedStreamBuf streamBuffer(reinterpret_cast<unsigned char*>(data), size); |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
333 |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
334 std::shared_ptr<Aws::Transfer::TransferHandle> downloadHandler = transferManager_->DownloadFile(bucketName_, path, [&]() { //Define a lambda expression for the callback method parameter to stream back the data. |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
335 return Aws::New<Aws::IOStream>(ALLOCATION_TAG, &streamBuffer); |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
336 }); |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
337 |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
338 downloadHandler->WaitUntilFinished(); |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
339 |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
340 if (downloadHandler->GetStatus() == Aws::Transfer::TransferStatus::COMPLETED) |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
341 { |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
342 return; |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
343 } |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
344 else if (firstExceptionMessage.empty()) |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
345 { |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
346 firstExceptionMessage = downloadHandler->GetLastError().GetMessage(); |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
347 } |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
348 // getObjectRequest.SetResponseStreamFactory( |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
349 // [data, size]() |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
350 // { |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
351 // std::unique_ptr<Aws::StringStream> |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
352 // istream(Aws::New<Aws::StringStream>(ALLOCATION_TAG)); |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
353 |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
354 // istream->rdbuf()->pubsetbuf(static_cast<char*>(data), |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
355 // size); |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
356 |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
357 // return istream.release(); |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
358 // }); |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
359 |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
360 |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
361 } |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
362 catch (StoragePluginException& ex) |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
363 { |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
364 if (firstExceptionMessage.empty()) |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
365 { |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
366 firstExceptionMessage = ex.what(); |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
367 } |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
368 //ignore to retry |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
369 } |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
370 } |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
371 throw StoragePluginException(firstExceptionMessage); |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
372 } |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
373 |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
374 }; |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
375 |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
376 |
41 | 377 |
378 | |
1 | 379 const char* AwsS3StoragePluginFactory::GetStoragePluginName() |
380 { | |
381 return "AWS S3 Storage"; | |
382 } | |
383 | |
94
1bc055199cd2
Added a description for all plugins
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
384 const char* AwsS3StoragePluginFactory::GetStorageDescription() |
1bc055199cd2
Added a description for all plugins
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
385 { |
1bc055199cd2
Added a description for all plugins
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
386 return "Stores the Orthanc storage area in AWS S3"; |
1bc055199cd2
Added a description for all plugins
Alain Mazy <am@osimis.io>
parents:
78
diff
changeset
|
387 } |
57
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
388 |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
389 static std::unique_ptr<Aws::Crt::ApiHandle> api_; |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
390 static std::unique_ptr<Aws::SDKOptions> sdkOptions_; |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
391 |
119
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
392 #include <stdarg.h> |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
393 |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
394 class AwsOrthancLogger : public Aws::Utils::Logging::LogSystemInterface |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
395 { |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
396 public: |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
397 virtual ~AwsOrthancLogger() {} |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
398 |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
399 /** |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
400 * Gets the currently configured log level for this logger. |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
401 */ |
153 | 402 virtual Aws::Utils::Logging::LogLevel GetLogLevel() const ORTHANC_OVERRIDE |
119
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
403 { |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
404 return Aws::Utils::Logging::LogLevel::Trace; |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
405 } |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
406 /** |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
407 * Does a printf style output to the output stream. Don't use this, it's unsafe. See LogStream |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
408 */ |
153 | 409 virtual void Log(Aws::Utils::Logging::LogLevel logLevel, const char* tag, const char* formatStr, ...) ORTHANC_OVERRIDE |
119
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
410 { |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
411 Aws::StringStream ss; |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
412 |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
413 va_list args; |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
414 va_start(args, formatStr); |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
415 |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
416 va_list tmp_args; //unfortunately you cannot consume a va_list twice |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
417 va_copy(tmp_args, args); //so we have to copy it |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
418 #ifdef _WIN32 |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
419 const int requiredLength = _vscprintf(formatStr, tmp_args) + 1; |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
420 #else |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
421 const int requiredLength = vsnprintf(nullptr, 0, formatStr, tmp_args) + 1; |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
422 #endif |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
423 va_end(tmp_args); |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
424 |
141
3e9cced85a5b
fix build for MSVC 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
425 assert(requiredLength > 0); |
3e9cced85a5b
fix build for MSVC 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
426 std::string outputBuff; |
3e9cced85a5b
fix build for MSVC 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
427 outputBuff.resize(requiredLength); |
119
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
428 #ifdef _WIN32 |
141
3e9cced85a5b
fix build for MSVC 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
429 vsnprintf_s(&outputBuff[0], requiredLength, _TRUNCATE, formatStr, args); |
119
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
430 #else |
141
3e9cced85a5b
fix build for MSVC 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
119
diff
changeset
|
431 vsnprintf(&outputBuff[0], requiredLength, formatStr, args); |
119
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
432 #endif // _WIN32 |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
433 |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
434 if (logLevel == Aws::Utils::Logging::LogLevel::Debug || logLevel == Aws::Utils::Logging::LogLevel::Trace) |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
435 { |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
436 LOG(INFO) << outputBuff; |
119
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
437 } |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
438 else if (logLevel == Aws::Utils::Logging::LogLevel::Warn) |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
439 { |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
440 LOG(WARNING) << outputBuff; |
119
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
441 } |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
442 else |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
443 { |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
444 LOG(ERROR) << outputBuff; |
119
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
445 } |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
446 |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
447 va_end(args); |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
448 } |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
449 /** |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
450 * Writes the stream to the output stream. |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
451 */ |
153 | 452 virtual void LogStream(Aws::Utils::Logging::LogLevel logLevel, const char* tag, const Aws::OStringStream &messageStream) ORTHANC_OVERRIDE |
119
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
453 { |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
454 if (logLevel == Aws::Utils::Logging::LogLevel::Debug || logLevel == Aws::Utils::Logging::LogLevel::Trace) |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
455 { |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
456 LOG(INFO) << tag << messageStream.str(); |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
457 } |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
458 else if (logLevel == Aws::Utils::Logging::LogLevel::Warn) |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
459 { |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
460 LOG(WARNING) << tag << messageStream.str(); |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
461 } |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
462 else |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
463 { |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
464 LOG(ERROR) << tag << messageStream.str(); |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
465 } |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
466 |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
467 } |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
468 /** |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
469 * Writes any buffered messages to the underlying device if the logger supports buffering. |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
470 */ |
153 | 471 virtual void Flush() ORTHANC_OVERRIDE {} |
119
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
472 }; |
57
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
473 |
78 | 474 IStorage* AwsS3StoragePluginFactory::CreateStorage(const std::string& nameForLogs, const OrthancPlugins::OrthancConfiguration& orthancConfig) |
1 | 475 { |
57
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
476 if (sdkOptions_.get() != NULL) |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
477 { |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
478 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls, "Cannot initialize twice"); |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
479 } |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
480 |
15 | 481 bool enableLegacyStorageStructure; |
70
16e419fe80c5
Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
482 bool storageContainsUnknownFiles; |
15 | 483 |
77 | 484 if (!orthancConfig.IsSection(GetConfigurationSectionName())) |
1 | 485 { |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
486 LOG(WARNING) << GetStoragePluginName() << " plugin, section missing. Plugin is not enabled."; |
1 | 487 return nullptr; |
488 } | |
489 | |
490 OrthancPlugins::OrthancConfiguration pluginSection; | |
77 | 491 orthancConfig.GetSection(pluginSection, GetConfigurationSectionName()); |
1 | 492 |
78 | 493 if (!BaseStorage::ReadCommonConfiguration(enableLegacyStorageStructure, storageContainsUnknownFiles, pluginSection)) |
15 | 494 { |
495 return nullptr; | |
496 } | |
497 | |
1 | 498 std::string bucketName; |
499 std::string region; | |
500 std::string accessKey; | |
501 std::string secretKey; | |
502 | |
503 if (!pluginSection.LookupStringValue(bucketName, "BucketName")) | |
504 { | |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
505 LOG(ERROR) << "AwsS3Storage/BucketName configuration missing. Unable to initialize plugin"; |
1 | 506 return nullptr; |
507 } | |
508 | |
509 if (!pluginSection.LookupStringValue(region, "Region")) | |
510 { | |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
511 LOG(ERROR) << "AwsS3Storage/Region configuration missing. Unable to initialize plugin"; |
1 | 512 return nullptr; |
513 } | |
514 | |
57
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
515 const std::string endpoint = pluginSection.GetStringValue("Endpoint", ""); |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
516 const unsigned int connectTimeout = pluginSection.GetUnsignedIntegerValue("ConnectTimeout", 30); |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
517 const unsigned int requestTimeout = pluginSection.GetUnsignedIntegerValue("RequestTimeout", 1200); |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
518 const bool virtualAddressing = pluginSection.GetBooleanValue("VirtualAddressing", true); |
119
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
519 const bool enableAwsSdkLogs = pluginSection.GetBooleanValue("EnableAwsSdkLogs", false); |
57
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
520 const std::string caFile = orthancConfig.GetStringValue("HttpsCACertificates", ""); |
119
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
521 |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
522 |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
523 api_.reset(new Aws::Crt::ApiHandle); |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
524 |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
525 sdkOptions_.reset(new Aws::SDKOptions); |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
526 sdkOptions_->cryptoOptions.initAndCleanupOpenSSL = false; // Done by the Orthanc framework |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
527 sdkOptions_->httpOptions.initAndCleanupCurl = false; // Done by the Orthanc framework |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
528 |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
529 if (enableAwsSdkLogs) |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
530 { |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
531 // Set up logging |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
532 Aws::Utils::Logging::InitializeAWSLogging(Aws::MakeShared<AwsOrthancLogger>(ALLOCATION_TAG)); |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
533 // strangely, this seems to disable logging !!!! sdkOptions_->loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Trace; |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
534 } |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
535 |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
536 Aws::InitAPI(*sdkOptions_); |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
537 |
e39aa88ec20e
AWS: new 'EnableAwsSdkLogs' config + show timings for read/write operations
Alain Mazy <am@osimis.io>
parents:
113
diff
changeset
|
538 |
1 | 539 try |
540 { | |
541 Aws::Client::ClientConfiguration configuration; | |
57
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
542 |
1 | 543 configuration.region = region.c_str(); |
6
393fcf337462
AWS: added 3 configurations: Endpoint, ConnectionTimeout, RequestTimeout
Alain Mazy
parents:
1
diff
changeset
|
544 configuration.scheme = Aws::Http::Scheme::HTTPS; |
393fcf337462
AWS: added 3 configurations: Endpoint, ConnectionTimeout, RequestTimeout
Alain Mazy
parents:
1
diff
changeset
|
545 configuration.connectTimeoutMs = connectTimeout * 1000; |
393fcf337462
AWS: added 3 configurations: Endpoint, ConnectionTimeout, RequestTimeout
Alain Mazy
parents:
1
diff
changeset
|
546 configuration.requestTimeoutMs = requestTimeout * 1000; |
27
e1f52b851827
Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
15
diff
changeset
|
547 configuration.httpRequestTimeoutMs = requestTimeout * 1000; |
6
393fcf337462
AWS: added 3 configurations: Endpoint, ConnectionTimeout, RequestTimeout
Alain Mazy
parents:
1
diff
changeset
|
548 |
393fcf337462
AWS: added 3 configurations: Endpoint, ConnectionTimeout, RequestTimeout
Alain Mazy
parents:
1
diff
changeset
|
549 if (!endpoint.empty()) |
393fcf337462
AWS: added 3 configurations: Endpoint, ConnectionTimeout, RequestTimeout
Alain Mazy
parents:
1
diff
changeset
|
550 { |
393fcf337462
AWS: added 3 configurations: Endpoint, ConnectionTimeout, RequestTimeout
Alain Mazy
parents:
1
diff
changeset
|
551 configuration.endpointOverride = endpoint.c_str(); |
393fcf337462
AWS: added 3 configurations: Endpoint, ConnectionTimeout, RequestTimeout
Alain Mazy
parents:
1
diff
changeset
|
552 } |
393fcf337462
AWS: added 3 configurations: Endpoint, ConnectionTimeout, RequestTimeout
Alain Mazy
parents:
1
diff
changeset
|
553 |
57
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
554 if (!caFile.empty()) |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
555 { |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
556 configuration.caFile = caFile; |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
557 } |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
558 |
113 | 559 bool useTransferManager = false; // new in v 2.3.0 |
560 unsigned int transferPoolSize = 10; | |
561 unsigned int transferBufferSizeMB = 5; | |
562 | |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
563 pluginSection.LookupBooleanValue(useTransferManager, "UseTransferManager"); |
113 | 564 pluginSection.LookupUnsignedIntegerValue(transferPoolSize, "TransferPoolSize"); |
565 pluginSection.LookupUnsignedIntegerValue(transferBufferSizeMB, "TransferBufferSize"); | |
566 | |
567 | |
568 std::shared_ptr<Aws::S3::S3Client> client; | |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
569 |
53
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
570 if (pluginSection.LookupStringValue(accessKey, "AccessKey") && pluginSection.LookupStringValue(secretKey, "SecretKey")) |
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
571 { |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
572 LOG(INFO) << "AWS S3 Storage: using credentials from the configuration file"; |
53
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
573 Aws::Auth::AWSCredentials credentials(accessKey.c_str(), secretKey.c_str()); |
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
574 |
113 | 575 client = Aws::MakeShared<Aws::S3::S3Client>(ALLOCATION_TAG, credentials, configuration, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never, virtualAddressing); |
53
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
576 } |
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
577 else |
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
578 { |
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
579 // when using default credentials, credentials are not checked at startup but only the first time you try to access the bucket ! |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
580 LOG(INFO) << "AWS S3 Storage: using default credentials provider"; |
113 | 581 client = Aws::MakeShared<Aws::S3::S3Client>(ALLOCATION_TAG, configuration, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never, virtualAddressing); |
582 } | |
1 | 583 |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
584 LOG(INFO) << "AWS S3 storage initialized"; |
53
1c3e34f5c5c6
AWS S3: if no access & secret keys are provided, now getting the credentials from the default credentials manager
Alain Mazy <am@osimis.io>
parents:
41
diff
changeset
|
585 |
113 | 586 return new AwsS3StoragePlugin(nameForLogs, client, bucketName, enableLegacyStorageStructure, storageContainsUnknownFiles, useTransferManager, transferPoolSize, transferBufferSizeMB); |
1 | 587 } |
588 catch (const std::exception& e) | |
589 { | |
151
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
590 Aws::ShutdownAPI(*sdkOptions_); |
152
d62f52be1943
use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
591 LOG(ERROR) << "AWS S3 Storage plugin: failed to initialize plugin: " << e.what(); |
1 | 592 return nullptr; |
593 } | |
594 } | |
595 | |
57
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
596 |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
597 AwsS3StoragePlugin::~AwsS3StoragePlugin() |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
598 { |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
599 assert(sdkOptions_.get() != NULL); |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
600 Aws::ShutdownAPI(*sdkOptions_); |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
601 api_.reset(); |
151
00cd1f01dd5d
fix initialization and finalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
145
diff
changeset
|
602 sdkOptions_.reset(); |
57
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
603 } |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
604 |
ba1be668e475
fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
605 |
113 | 606 AwsS3StoragePlugin::AwsS3StoragePlugin(const std::string& nameForLogs, |
607 std::shared_ptr<Aws::S3::S3Client> client, | |
608 const std::string& bucketName, | |
609 bool enableLegacyStorageStructure, | |
610 bool storageContainsUnknownFiles, | |
611 bool useTransferManager, | |
612 unsigned int transferThreadPoolSize, | |
613 unsigned int transferBufferSizeMB) | |
78 | 614 : BaseStorage(nameForLogs, enableLegacyStorageStructure), |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
615 bucketName_(bucketName), |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
616 storageContainsUnknownFiles_(storageContainsUnknownFiles), |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
617 useTransferManager_(useTransferManager), |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
618 client_(client) |
1 | 619 { |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
620 if (useTransferManager_) |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
621 { |
113 | 622 executor_ = Aws::MakeShared<Aws::Utils::Threading::PooledThreadExecutor>(ALLOCATION_TAG, transferThreadPoolSize); |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
623 Aws::Transfer::TransferManagerConfiguration transferConfig(executor_.get()); |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
624 transferConfig.s3Client = client_; |
113 | 625 transferConfig.bufferSize = static_cast<uint64_t>(transferBufferSizeMB) * 1024 * 1024; |
626 transferConfig.transferBufferMaxHeapSize = static_cast<uint64_t>(transferBufferSizeMB) * 1024 * 1024 * transferThreadPoolSize; | |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
627 |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
628 transferManager_ = Aws::Transfer::TransferManager::Create(transferConfig); |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
629 } |
1 | 630 } |
631 | |
78 | 632 IStorage::IWriter* AwsS3StoragePlugin::GetWriterForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) |
1 | 633 { |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
634 if (useTransferManager_) |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
635 { |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
636 return new TransferWriter(transferManager_, bucketName_, GetPath(uuid, type, encryptionEnabled)); |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
637 } |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
638 else |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
639 { |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
640 return new DirectWriter(client_, bucketName_, GetPath(uuid, type, encryptionEnabled)); |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
641 } |
1 | 642 } |
643 | |
78 | 644 IStorage::IReader* AwsS3StoragePlugin::GetReaderForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) |
1 | 645 { |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
646 std::list<std::string> paths; |
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
647 paths.push_back(GetPath(uuid, type, encryptionEnabled, false)); |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
648 if (storageContainsUnknownFiles_) |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
649 { |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
650 paths.push_back(GetPath(uuid, type, encryptionEnabled, true)); |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
651 } |
64
c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
Alain Mazy <am@osimis.io>
parents:
62
diff
changeset
|
652 |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
653 if (useTransferManager_) |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
654 { |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
655 return new TransferReader(transferManager_, client_, bucketName_, paths, uuid); |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
656 } |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
657 else |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
658 { |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
659 return new DirectReader(client_, bucketName_, paths, uuid); |
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
660 } |
1 | 661 } |
662 | |
663 void AwsS3StoragePlugin::DeleteObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) | |
664 { | |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
665 std::string firstExceptionMessage; |
1 | 666 |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
667 std::list<std::string> paths; |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
668 paths.push_back(GetPath(uuid, type, encryptionEnabled, false)); |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
669 if (storageContainsUnknownFiles_) |
1 | 670 { |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
671 paths.push_back(GetPath(uuid, type, encryptionEnabled, true)); |
1 | 672 } |
673 | |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
674 // DeleteObject succeeds even if the file does not exist -> we need to try to delete every path |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
675 for (auto& path: paths) |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
676 { |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
677 Aws::S3::Model::DeleteObjectRequest deleteObjectRequest; |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
678 deleteObjectRequest.SetBucket(bucketName_.c_str()); |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
679 deleteObjectRequest.SetKey(path.c_str()); |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
680 |
106
c9356e42af99
added TransferMode for S3 (currently affected by https://github.com/aws/aws-sdk-cpp/issues/2319 since we are using version 1.9.45)
Alain Mazy <am@osimis.io>
parents:
94
diff
changeset
|
681 auto result = client_->DeleteObject(deleteObjectRequest); |
68
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
682 |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
683 if (!result.IsSuccess() && firstExceptionMessage.empty()) |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
684 { |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
685 firstExceptionMessage = std::string("error while deleting file ") + path + ": response code = " + boost::lexical_cast<std::string>((int)result.GetError().GetResponseCode()) + " " + result.GetError().GetExceptionName().c_str() + " " + result.GetError().GetMessage().c_str(); |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
686 } |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
687 } |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
688 |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
689 if (!firstExceptionMessage.empty()) |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
690 { |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
691 throw StoragePluginException(firstExceptionMessage); |
58a03fce4897
new option for AWS: EnableLegacyUnknownFiles
Alain Mazy <am@osimis.io>
parents:
64
diff
changeset
|
692 } |
1 | 693 } |