File tree Expand file tree Collapse file tree 7 files changed +86
-10
lines changed
Expand file tree Collapse file tree 7 files changed +86
-10
lines changed Original file line number Diff line number Diff line change @@ -11,11 +11,17 @@ struct ExternalBlockStorageAws : ExternalBlockStorageBackend
1111private:
1212 Aws::S3::S3Client m_client;
1313 std::string m_bucketName;
14+ std::optional<std::string> m_endpoint;
1415
1516public:
16- ExternalBlockStorageAws (Aws::S3::S3Client, std::string bucketName);
17+ ExternalBlockStorageAws (
18+ Aws::S3::S3Client,
19+ std::string bucketName,
20+ std::optional<std::string> endpoint);
1721 auto put (std::string const &identifier, void const *data, size_t len)
1822 -> std::string override ;
23+ [[nodiscard]] auto externalStorageLocation () const
24+ -> nlohmann::json override ;
1925 ~ExternalBlockStorageAws () override ;
2026};
2127} // namespace openPMD::internal
Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ struct ExternalBlockStorageBackend
2424 virtual auto
2525 put (std::string const &identifier, void const *data, size_t len)
2626 -> std::string = 0 ;
27+ [[nodiscard]] virtual auto externalStorageLocation () const
28+ -> nlohmann::json = 0;
29+
2730 virtual ~ExternalBlockStorageBackend ();
2831};
2932} // namespace openPMD::internal
@@ -71,10 +74,7 @@ class ExternalBlockStorage
7174 std::optional<std::string> infix, // e.g. for distinguishing MPI ranks
7275 T const *data) -> std::string;
7376
74- auto externalStorageLocation () const -> nlohmann::json
75- {
76- return " implement me" ;
77- }
77+ [[nodiscard]] auto externalStorageLocation () const -> nlohmann::json;
7878
7979 static void sanitizeString (std::string &s);
8080};
Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ struct ExternalBlockStorageStdio : ExternalBlockStorageBackend
1414 ExternalBlockStorageStdio (std::string directory, std::string openMode);
1515 auto put (std::string const &identifier, void const *data, size_t len)
1616 -> std::string override ;
17+ [[nodiscard]] auto externalStorageLocation () const
18+ -> nlohmann::json override ;
1719 ~ExternalBlockStorageStdio () override ;
1820};
1921} // namespace openPMD::internal
Original file line number Diff line number Diff line change @@ -30,8 +30,12 @@ struct imemstream : std::iostream
3030namespace openPMD ::internal
3131{
3232ExternalBlockStorageAws::ExternalBlockStorageAws (
33- Aws::S3::S3Client client, std::string bucketName)
34- : m_client{std::move (client)}, m_bucketName(std::move(bucketName))
33+ Aws::S3::S3Client client,
34+ std::string bucketName,
35+ std::optional<std::string> endpoint)
36+ : m_client{std::move (client)}
37+ , m_bucketName(std::move(bucketName))
38+ , m_endpoint(std::move(endpoint))
3539{
3640 Aws::S3::Model::CreateBucketRequest create_request;
3741 create_request.SetBucket (m_bucketName);
@@ -77,4 +81,17 @@ auto ExternalBlockStorageAws::put(
7781 return sanitized;
7882}
7983
84+ [[nodiscard]] auto ExternalBlockStorageAws::externalStorageLocation () const
85+ -> nlohmann::json
86+ {
87+ nlohmann::json j;
88+ j[" provider" ] = " s3" ;
89+ if (m_endpoint.has_value ())
90+ {
91+ j[" endpoint" ] = *m_endpoint;
92+ }
93+ j[" bucket" ] = m_bucketName;
94+ return j;
95+ }
96+
8097} // namespace openPMD::internal
Original file line number Diff line number Diff line change @@ -117,7 +117,9 @@ AwsBuilder::operator ExternalBlockStorage()
117117 false );
118118
119119 return ExternalBlockStorage{std::make_unique<ExternalBlockStorageAws>(
120- std::move (s3_client), std::move (m_bucketName))};
120+ std::move (s3_client),
121+ std::move (m_bucketName),
122+ std::move (m_endpointOverride))};
121123}
122124
123125auto AwsBuilder::build () -> ExternalBlockStorage
Original file line number Diff line number Diff line change @@ -134,6 +134,12 @@ auto ExternalBlockStorage::store(
134134 return index_as_str;
135135}
136136
137+ [[nodiscard]] auto ExternalBlockStorage::externalStorageLocation () const
138+ -> nlohmann::json
139+ {
140+ return m_worker->externalStorageLocation ();
141+ }
142+
137143void ExternalBlockStorage::sanitizeString (std::string &s)
138144{
139145 for (char &c : s)
Original file line number Diff line number Diff line change 55#include < cstdio>
66#include < stdexcept>
77
8+ namespace
9+ {
10+ auto concat_filepath (std::string const &s1, std::string const &s2)
11+ -> std::string
12+ {
13+ if (s1.empty ())
14+ {
15+ return s2;
16+ }
17+ if (s2.empty ())
18+ {
19+ return s1;
20+ }
21+ bool ends_with_slash =
22+ *s1.crbegin () == openPMD::auxiliary::directory_separator;
23+ bool starts_with_slash =
24+ *s2.cbegin () == openPMD::auxiliary::directory_separator;
25+
26+ if (ends_with_slash ^ starts_with_slash)
27+ {
28+ return s1 + s2;
29+ }
30+ else if (ends_with_slash && starts_with_slash)
31+ {
32+ return s1 + (s2.c_str () + 1 );
33+ }
34+ else
35+ {
36+ return s1 + openPMD::auxiliary::directory_separator + s2;
37+ }
38+ }
39+ } // namespace
40+
841namespace openPMD ::internal
942{
1043ExternalBlockStorageStdio::ExternalBlockStorageStdio (
@@ -33,7 +66,7 @@ auto ExternalBlockStorageStdio::put(
3366{
3467 auto sanitized = identifier + " .dat" ;
3568 ExternalBlockStorage::sanitizeString (sanitized);
36- std::string filepath = m_directory + " / " + sanitized;
69+ std::string filepath = concat_filepath ( m_directory, sanitized) ;
3770
3871 if (len == 0 )
3972 {
@@ -63,6 +96,16 @@ auto ExternalBlockStorageStdio::put(
6396 filepath);
6497 }
6598
66- return filepath;
99+ return sanitized;
100+ }
101+
102+ [[nodiscard]] auto ExternalBlockStorageStdio::externalStorageLocation () const
103+ -> nlohmann::json
104+ {
105+ nlohmann::json j;
106+ j[" provider" ] = " stdio" ;
107+ j[" directory" ] = m_directory;
108+ j[" open_mode" ] = m_openMode;
109+ return j;
67110}
68111} // namespace openPMD::internal
You can’t perform that action at this time.
0 commit comments