Skip to content

Commit

Permalink
Add minio client
Browse files Browse the repository at this point in the history
Signed-off-by: Jin Hai <[email protected]>
  • Loading branch information
JinHai-CN committed Oct 7, 2024
1 parent 2bc87d9 commit f7570ab
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 1,244 deletions.
488 changes: 0 additions & 488 deletions src/storage/io/local_file_system.cpp

This file was deleted.

106 changes: 0 additions & 106 deletions src/storage/io/local_file_system.cppm

This file was deleted.

35 changes: 18 additions & 17 deletions src/storage/io/s3_client.cppm
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
module;

import stl;
#include <miniocpp/client.h>

export module s3_client;

import stl;
import status;

namespace infinity {

export class S3Client {
public:
S3Client(String _url = "http://localhost:9000",
bool _https = false,
String _access_key = "minioadmin",
String _secret_key = "minioadmin") : url(_url), https(_https), access_key(_access_key), secret_key(_secret_key) {}
public:
S3Client(String _url = "http://localhost:9000", bool _https = false, String _access_key = "minioadmin", String _secret_key = "minioadmin")
: url(_url), https(_https), access_key(_access_key), secret_key(_secret_key) {}

~S3Client() = default;
virtual ~S3Client() = default;

virtual void DownloadObject(const String & bucket_name, const String &object_name, const String &file_path)=0;
virtual Status DownloadObject(const String &bucket_name, const String &object_name, const String &file_path) = 0;

virtual void UploadObject(const String & bucket_name, const String &object_name, const String &file_path)=0;
virtual Status UploadObject(const String &bucket_name, const String &object_name, const String &file_path) = 0;

virtual void RemoveObject(const String & bucket_name, const String &object_name)=0;
virtual Status RemoveObject(const String &bucket_name, const String &object_name) = 0;

virtual void CopyObject(const String & src_bucket_name, const String &src_object_name, const String & dst_bucket_name, const String &dst_object_name)=0;
virtual Status
CopyObject(const String &src_bucket_name, const String &src_object_name, const String &dst_bucket_name, const String &dst_object_name) = 0;

protected:
String url;
bool https;
String access_key;
String secret_key;
protected:
String url;
bool https;
String access_key;
String secret_key;
};
}
} // namespace infinity
42 changes: 24 additions & 18 deletions src/storage/io/s3_client_minio.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
module;

import stl;
import infinity_exception;
#include <miniocpp/client.h>

module s3_client_minio;

import stl;
import infinity_exception;
import status;

namespace infinity {
void S3ClientMinio::DownloadObject(const String & bucket_name, const String &object_name, const String &file_path){
Status S3ClientMinio::DownloadObject(const String &bucket_name, const String &object_name, const String &file_path) {
// Create S3 client.
minio::s3::Client client = GetClient();

Expand All @@ -22,14 +24,14 @@ void S3ClientMinio::DownloadObject(const String & bucket_name, const String &obj

// Handle response.
if (resp) {
std::cout << object_name<<" is successfully downloaded to "<<file_path
<< std::endl;
std::cout << object_name << " is successfully downloaded to " << file_path << std::endl;
} else {
UnrecoverableError("unable to download object; "+resp.Error().String());
UnrecoverableError("unable to download object; " + resp.Error().String());
}
return Status::OK();
}

void S3ClientMinio::UploadObject(const String & bucket_name, const String &object_name, const String &file_path){
Status S3ClientMinio::UploadObject(const String &bucket_name, const String &object_name, const String &file_path) {
// Create S3 client.
minio::s3::Client client = GetClient();

Expand All @@ -44,14 +46,14 @@ void S3ClientMinio::UploadObject(const String & bucket_name, const String &objec

// Handle response.
if (resp) {
std::cout << file_path<<" is successfully uploaded to "<<object_name
<< std::endl;
std::cout << file_path << " is successfully uploaded to " << object_name << std::endl;
} else {
UnrecoverableError("unable to upload object; "+resp.Error().String());
UnrecoverableError("unable to upload object; " + resp.Error().String());
}
return Status::OK();
}

void S3ClientMinio::RemoveObject(const String & bucket_name, const String &object_name){
Status S3ClientMinio::RemoveObject(const String &bucket_name, const String &object_name) {
// Create S3 client.
minio::s3::Client client = GetClient();
// Create remove object arguments.
Expand All @@ -64,13 +66,17 @@ void S3ClientMinio::RemoveObject(const String & bucket_name, const String &objec

// Handle response.
if (resp) {
std::cout << object_name<<" is removed successfully" << std::endl;
std::cout << object_name << " is removed successfully" << std::endl;
} else {
UnrecoverableError("unable to remove object; "+resp.Error().String());
UnrecoverableError("unable to remove object; " + resp.Error().String());
}
return Status::OK();
}

void S3ClientMinio::CopyObject(const String & src_bucket_name, const String &src_object_name, const String & dst_bucket_name, const String &dst_object_name){
Status S3ClientMinio::CopyObject(const String &src_bucket_name,
const String &src_object_name,
const String &dst_bucket_name,
const String &dst_object_name) {
// Create S3 client.
minio::s3::Client client = GetClient();
// Create copy object arguments.
Expand All @@ -88,11 +94,11 @@ void S3ClientMinio::CopyObject(const String & src_bucket_name, const String &src

// Handle response.
if (resp) {
std::cout << dst_object_name<<" is successfully created from "
<< src_object_name << std::endl;
std::cout << dst_object_name << " is successfully created from " << src_object_name << std::endl;
} else {
UnrecoverableError("unable to do copy object; "+resp.Error().String());
UnrecoverableError("unable to do copy object; " + resp.Error().String());
}
return Status::OK();
}

}
} // namespace infinity
38 changes: 18 additions & 20 deletions src/storage/io/s3_client_minio.cppm
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
module;

import stl;
import s3_client;
#include <miniocpp/client.h>

export module s3_client_minio;

import stl;
import s3_client;
import status;

namespace infinity {

class S3ClientMinio final: public S3Client {
public:
S3ClientMinio(String _url = "http://localhost:9000",
bool _https = false,
String _access_key = "minioadmin",
String _secret_key = "minioadmin") : S3Client(_url, _https, _access_key, _secret_key),
base_url(_url, _https),
provider(_access_key, _secret_key) {}
export class S3ClientMinio final : public S3Client {
public:
S3ClientMinio(String _url = "http://localhost:9000", bool _https = false, String _access_key = "minioadmin", String _secret_key = "minioadmin")
: S3Client(_url, _https, _access_key, _secret_key), base_url(_url, _https), provider(_access_key, _secret_key) {}

~S3ClientMinio() = default;
~S3ClientMinio() = default;

void DownloadObject(const String & bucket_name, const String &object_name, const String &file_path);
Status DownloadObject(const String &bucket_name, const String &object_name, const String &file_path);

void UploadObject(const String & bucket_name, const String &object_name, const String &file_path);
Status UploadObject(const String &bucket_name, const String &object_name, const String &file_path);

void RemoveObject(const String & bucket_name, const String &object_name);
Status RemoveObject(const String &bucket_name, const String &object_name);

void CopyObject(const String & src_bucket_name, const String &src_object_name, const String & dst_bucket_name, const String &dst_object_name);
Status CopyObject(const String &src_bucket_name, const String &src_object_name, const String &dst_bucket_name, const String &dst_object_name);

minio::s3::Client GetClient() { return minio::s3::Client(base_url, &provider); }
minio::s3::Client GetClient() { return minio::s3::Client(base_url, &provider); }

private:
minio::s3::BaseUrl base_url;
minio::creds::StaticProvider provider;
private:
minio::s3::BaseUrl base_url;
minio::creds::StaticProvider provider;
};
}
} // namespace infinity
Loading

0 comments on commit f7570ab

Please sign in to comment.