-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature-13331][Remote Logging] Add support for writing task logs to OSS
- Loading branch information
1 parent
ccad56e
commit 952fff4
Showing
9 changed files
with
334 additions
and
7 deletions.
There are no files selected for viewing
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
105 changes: 105 additions & 0 deletions
105
...mmon/src/main/java/org/apache/dolphinscheduler/common/log/remote/OssRemoteLogHandler.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,105 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.dolphinscheduler.common.log.remote; | ||
|
||
import org.apache.dolphinscheduler.common.constants.Constants; | ||
import org.apache.dolphinscheduler.common.factory.OssClientFactory; | ||
import org.apache.dolphinscheduler.common.model.OssConnection; | ||
import org.apache.dolphinscheduler.common.utils.PropertyUtils; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.aliyun.oss.OSS; | ||
import com.aliyun.oss.model.GetObjectRequest; | ||
import com.aliyun.oss.model.PutObjectRequest; | ||
|
||
public class OssRemoteLogHandler implements RemoteLogHandler { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(OssRemoteLogHandler.class); | ||
@Override | ||
public void sendRemoteLog(String logPath) { | ||
String accessKeyId = readOssAccessKeyId(); | ||
String accessKeySecret = readOssAccessKeySecret(); | ||
String endpoint = readOssEndpoint(); | ||
OSS ossClient = OssClientFactory.buildOssClient(new OssConnection(accessKeyId, accessKeySecret, endpoint)); | ||
|
||
String bucketName = readOssBucketName(); | ||
String objectName = Paths.get(readOssBaseDir(), getObjectNameFromLogPath(logPath)).toString(); | ||
|
||
try { | ||
logger.info("send remote log {} to OSS {}", logPath, objectName); | ||
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, new File(logPath)); | ||
ossClient.putObject(putObjectRequest); | ||
} catch (Exception e) { | ||
logger.error("error while sending remote log {} to OSS {}", logPath, objectName, e); | ||
} | ||
} | ||
|
||
@Override | ||
public void getRemoteLog(String logPath) { | ||
String accessKeyId = readOssAccessKeyId(); | ||
String accessKeySecret = readOssAccessKeySecret(); | ||
String endpoint = readOssEndpoint(); | ||
OSS ossClient = OssClientFactory.buildOssClient(new OssConnection(accessKeyId, accessKeySecret, endpoint)); | ||
|
||
String bucketName = readOssBucketName(); | ||
String objectName = Paths.get(readOssBaseDir(), getObjectNameFromLogPath(logPath)).toString(); | ||
|
||
try { | ||
logger.info("get remote log on OSS {} to {}", objectName, logPath); | ||
ossClient.getObject(new GetObjectRequest(bucketName, objectName), new File(logPath)); | ||
} catch (Exception e) { | ||
logger.error("error while getting remote log on OSS {} to {}", objectName, logPath); | ||
} | ||
} | ||
|
||
private String getObjectNameFromLogPath(String logPath) { | ||
Path path = Paths.get(logPath); | ||
int nameCount = path.getNameCount(); | ||
if (nameCount < 2) { | ||
return logPath; | ||
} else { | ||
return path.subpath(nameCount - 2, nameCount).toString(); | ||
} | ||
} | ||
|
||
private String readOssAccessKeyId() { | ||
return PropertyUtils.getString(Constants.REMOTE_LOGGING_OSS_ACCESS_KEY_ID); | ||
} | ||
|
||
private String readOssAccessKeySecret() { | ||
return PropertyUtils.getString(Constants.REMOTE_LOGGING_OSS_ACCESS_KEY_SECRET); | ||
} | ||
|
||
private String readOssEndpoint() { | ||
return PropertyUtils.getString(Constants.REMOTE_LOGGING_OSS_ENDPOINT); | ||
} | ||
|
||
private String readOssBucketName() { | ||
return PropertyUtils.getString(Constants.REMOTE_LOGGING_OSS_BUCKET_NAME); | ||
} | ||
|
||
private String readOssBaseDir() { | ||
return PropertyUtils.getString(Constants.REMOTE_LOGGING_OSS_BASE_DIR); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...-common/src/main/java/org/apache/dolphinscheduler/common/log/remote/RemoteLogHandler.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,25 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.dolphinscheduler.common.log.remote; | ||
|
||
public interface RemoteLogHandler { | ||
|
||
void sendRemoteLog(String logPath); | ||
|
||
void getRemoteLog(String logPath); | ||
} |
39 changes: 39 additions & 0 deletions
39
.../src/main/java/org/apache/dolphinscheduler/common/log/remote/RemoteLogHandlerFactory.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,39 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.dolphinscheduler.common.log.remote; | ||
|
||
import org.apache.dolphinscheduler.common.constants.Constants; | ||
import org.apache.dolphinscheduler.common.utils.PropertyUtils; | ||
|
||
import lombok.experimental.UtilityClass; | ||
|
||
@UtilityClass | ||
public class RemoteLogHandlerFactory { | ||
|
||
public RemoteLogHandler getRemoteLogHandler() { | ||
if ("true".equalsIgnoreCase(PropertyUtils.getString(Constants.REMOTE_LOGGING_ENABLE))) { | ||
if ("OSS".equalsIgnoreCase(PropertyUtils.getString(Constants.REMOTE_LOGGING_TARGET))) { | ||
return new OssRemoteLogHandler(); | ||
} else { | ||
return null; | ||
} | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.