forked from raystack/firehose
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rename OSS class to ObjectStorageService
- Loading branch information
1 parent
0cc819d
commit 7d47308
Showing
2 changed files
with
56 additions
and
58 deletions.
There are no files selected for viewing
58 changes: 0 additions & 58 deletions
58
src/main/java/com/gotocompany/firehose/sink/common/blobstorage/oss/OSS.java
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
src/main/java/com/gotocompany/firehose/sink/common/blobstorage/oss/ObjectStorageService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
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.PutObjectRequest; | ||
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.File; | ||
import java.nio.file.Paths; | ||
|
||
public class ObjectStorageService implements BlobStorage { | ||
private final OSS ossClient; | ||
private final String bucketName; | ||
private final String directoryPrefix; | ||
|
||
public ObjectStorageService(OSSConfig config) { | ||
this.ossClient = new OSSClientBuilder() | ||
.build(config.getOSSEndpoint(), | ||
config.getOSSAccessKeyId(), | ||
config.getOSSAccessKeySecret()); | ||
|
||
this.bucketName = config.getOSSBucketName(); | ||
this.directoryPrefix = config.getOSSDirectoryPrefix(); | ||
} | ||
|
||
@Override | ||
public void store(String objectName, String localPath) throws BlobStorageException { | ||
try { | ||
String fullObjectPath = Paths.get(directoryPrefix, objectName).toString(); | ||
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, fullObjectPath, new File(localPath)); | ||
ossClient.putObject(putObjectRequest); | ||
} catch (OSSException e) { | ||
throw new BlobStorageException(e.getErrorCode(), "OSS Upload failed", e); | ||
} | ||
} | ||
|
||
@Override | ||
public void store(String objectName, byte[] content) throws BlobStorageException { | ||
try { | ||
String fullObjectPath = Paths.get(directoryPrefix, objectName).toString(); | ||
ossClient.putObject(bucketName, fullObjectPath, content); | ||
} catch (OSSException e) { | ||
throw new BlobStorageException(e.getErrorCode(), "OSS Upload failed", e); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
if (ossClient != null) { | ||
ossClient.shutdown(); | ||
} | ||
} | ||
} |