Browse Source

[RemoteLogging] Move init into loghandler (#15780)

Co-authored-by: 旺阳 <wang@lqwang.net>
dev_wenjun_refactorMaster
John Huang 8 months ago committed by GitHub
parent
commit
d39bdcb165
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 21
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/log/remote/GcsRemoteLogHandler.java
  2. 17
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/log/remote/OssRemoteLogHandler.java
  3. 19
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/log/remote/S3RemoteLogHandler.java

21
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/log/remote/GcsRemoteLogHandler.java

@ -49,19 +49,6 @@ public class GcsRemoteLogHandler implements RemoteLogHandler, Closeable {
private static GcsRemoteLogHandler instance; private static GcsRemoteLogHandler instance;
private GcsRemoteLogHandler() { private GcsRemoteLogHandler() {
}
public static synchronized GcsRemoteLogHandler getInstance() {
if (instance == null) {
instance = new GcsRemoteLogHandler();
instance.init();
}
return instance;
}
public void init() {
try { try {
credential = readCredentials(); credential = readCredentials();
bucketName = readBucketName(); bucketName = readBucketName();
@ -73,6 +60,14 @@ public class GcsRemoteLogHandler implements RemoteLogHandler, Closeable {
} }
} }
public static synchronized GcsRemoteLogHandler getInstance() {
if (instance == null) {
instance = new GcsRemoteLogHandler();
}
return instance;
}
@Override @Override
public void close() throws IOException { public void close() throws IOException {
try { try {

17
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/log/remote/OssRemoteLogHandler.java

@ -44,28 +44,23 @@ public class OssRemoteLogHandler implements RemoteLogHandler, Closeable {
private static OssRemoteLogHandler instance; private static OssRemoteLogHandler instance;
private OssRemoteLogHandler() { private OssRemoteLogHandler() {
String accessKeyId = readOssAccessKeyId();
String accessKeySecret = readOssAccessKeySecret();
String endpoint = readOssEndpoint();
ossClient = OssClientFactory.buildOssClient(new OssConnection(accessKeyId, accessKeySecret, endpoint));
bucketName = readOssBucketName();
checkBucketNameExists(bucketName);
} }
public static synchronized OssRemoteLogHandler getInstance() { public static synchronized OssRemoteLogHandler getInstance() {
if (instance == null) { if (instance == null) {
instance = new OssRemoteLogHandler(); instance = new OssRemoteLogHandler();
instance.init();
} }
return instance; return instance;
} }
public void init() {
String accessKeyId = readOssAccessKeyId();
String accessKeySecret = readOssAccessKeySecret();
String endpoint = readOssEndpoint();
ossClient = OssClientFactory.buildOssClient(new OssConnection(accessKeyId, accessKeySecret, endpoint));
bucketName = readOssBucketName();
checkBucketNameExists(bucketName);
}
@Override @Override
public void sendRemoteLog(String logPath) { public void sendRemoteLog(String logPath) {
String objectName = RemoteLogUtils.getObjectNameFromLogPath(logPath); String objectName = RemoteLogUtils.getObjectNameFromLogPath(logPath);

19
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/log/remote/S3RemoteLogHandler.java

@ -56,28 +56,23 @@ public class S3RemoteLogHandler implements RemoteLogHandler, Closeable {
private static S3RemoteLogHandler instance; private static S3RemoteLogHandler instance;
private S3RemoteLogHandler() { private S3RemoteLogHandler() {
accessKeyId = readAccessKeyID();
accessKeySecret = readAccessKeySecret();
region = readRegion();
bucketName = readBucketName();
endPoint = readEndPoint();
s3Client = buildS3Client();
checkBucketNameExists(bucketName);
} }
public static synchronized S3RemoteLogHandler getInstance() { public static synchronized S3RemoteLogHandler getInstance() {
if (instance == null) { if (instance == null) {
instance = new S3RemoteLogHandler(); instance = new S3RemoteLogHandler();
instance.init();
} }
return instance; return instance;
} }
public void init() {
accessKeyId = readAccessKeyID();
accessKeySecret = readAccessKeySecret();
region = readRegion();
bucketName = readBucketName();
endPoint = readEndPoint();
s3Client = buildS3Client();
checkBucketNameExists(bucketName);
}
protected AmazonS3 buildS3Client() { protected AmazonS3 buildS3Client() {
if (StringUtils.isNotEmpty(endPoint)) { if (StringUtils.isNotEmpty(endPoint)) {
return AmazonS3ClientBuilder return AmazonS3ClientBuilder

Loading…
Cancel
Save