-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add oss storage type in blob sink #58
Changes from 51 commits
2a83f52
eb40d6e
24ee818
d918738
d44d1fd
afbbf43
43dfbbc
39ebd15
6287158
491924c
0ec87b4
352ac03
0cc819d
7d47308
f2d6309
5fc7516
f395ffb
393e5a5
6e1ce01
e7218e2
19c3000
84cb363
000be33
2e7dd18
25b1f17
d5ff7d0
eebb607
78b5840
fa1ca1d
732528a
3cc3450
d5af54f
3f08be8
47acbc6
b956912
3531934
79aa530
3f30c22
a49a112
dcca9dd
5d3595e
47a6389
f2c894e
03e5818
5824c4f
4d87820
b1eb591
b4c4594
a32a7ac
c4e5e8f
9025990
9f2c5af
f112dd4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.gotocompany.firehose.config; | ||
|
||
import org.aeonbits.owner.Config; | ||
|
||
public interface OSSConfig extends Config { | ||
|
||
@Key("${OSS_TYPE}_OSS_ENDPOINT") | ||
String getOSSEndpoint(); | ||
|
||
@Key("${OSS_TYPE}_OSS_ACCESS_KEY_ID") | ||
String getOSSAccessKeyId(); | ||
|
||
@Key("${OSS_TYPE}_OSS_ACCESS_KEY_SECRET") | ||
String getOSSAccessKeySecret(); | ||
|
||
@Key("${OSS_TYPE}_OSS_BUCKET_NAME") | ||
String getOSSBucketName(); | ||
|
||
@Key("${OSS_TYPE}_OSS_DIRECTORY_PREFIX") | ||
String getOSSDirectoryPrefix(); | ||
|
||
@Key("${OSS_TYPE}_OSS_MAX_CONNECTIONS") | ||
@DefaultValue("1024") | ||
Integer getOSSMaxConnections(); | ||
|
||
@Key("${OSS_TYPE}_OSS_SOCKET_TIMEOUT") | ||
@DefaultValue("50000") | ||
Integer getOSSSocketTimeout(); | ||
|
||
@Key("${OSS_TYPE}_OSS_CONNECTION_TIMEOUT") | ||
@DefaultValue("50000") | ||
Integer getOSSConnectionTimeout(); | ||
|
||
@Key("${OSS_TYPE}_OSS_MAX_ERROR_RETRY") | ||
@DefaultValue("3") | ||
Integer getOSSMaxErrorRetry(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
|
||
public enum BlobStorageType { | ||
GCS, | ||
S3 | ||
S3, | ||
OSS | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.gotocompany.firehose.sink.common.blobstorage.oss; | ||
|
||
import com.aliyun.oss.OSS; | ||
import com.aliyun.oss.OSSClientBuilder; | ||
import com.aliyun.oss.OSSException; | ||
import com.aliyun.oss.model.ObjectMetadata; | ||
import com.gotocompany.firehose.config.OSSConfig; | ||
import com.gotocompany.firehose.sink.common.blobstorage.BlobStorage; | ||
import com.gotocompany.firehose.sink.common.blobstorage.BlobStorageException; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.File; | ||
import java.nio.file.Paths; | ||
|
||
public class ObjectStorageService implements BlobStorage { | ||
private final OSS ossClient; | ||
private final String bucketName; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we set the OSSConfig as property? This approach encapsulates all related configuration settings within a single object, making the code cleaner and easier to maintain. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i would also recommend this |
||
private final String directoryPrefix; | ||
|
||
public ObjectStorageService(OSSConfig config) { | ||
this.ossClient = createOSSClient( | ||
config.getOSSEndpoint(), | ||
config.getOSSAccessKeyId(), | ||
config.getOSSAccessKeySecret() | ||
); | ||
this.bucketName = config.getOSSBucketName(); | ||
this.directoryPrefix = config.getOSSDirectoryPrefix(); | ||
} | ||
|
||
protected OSS createOSSClient(String endpoint, String accessKeyId, String accessKeySecret) { | ||
return new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we introduce the option to pass configurable socketTimeout, connectionTimeout, connectionRequestTimeout and requestTimeout? There is also an option to pass configurable retry strategy for the OSSClient There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since we are exposing connection parameters in config, the builder should accommodate the values |
||
} | ||
|
||
@Override | ||
public void store(String objectName, String localPath) throws BlobStorageException { | ||
try { | ||
String fullPath = Paths.get(directoryPrefix, objectName).toString(); | ||
ossClient.putObject(bucketName, fullPath, new File(localPath)); | ||
} catch (OSSException e) { | ||
throw new BlobStorageException(e.getErrorCode(), "OSS Upload failed", e); | ||
} | ||
} | ||
|
||
@Override | ||
public void store(String objectName, byte[] content) throws BlobStorageException { | ||
try { | ||
String fullPath = Paths.get(directoryPrefix, objectName).toString(); | ||
ObjectMetadata metadata = new ObjectMetadata(); | ||
metadata.setContentLength(content.length); | ||
ossClient.putObject(bucketName, fullPath, new ByteArrayInputStream(content), metadata); | ||
} catch (OSSException e) { | ||
throw new BlobStorageException(e.getErrorCode(), "OSS Upload failed", e); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this default value in line with Ali documentation and/or recommendation?