Skip to content

Commit

Permalink
Code Review updates:
Browse files Browse the repository at this point in the history
* Fixed SonarCloud Quality Readability B (required >= A)
* Added missing license files
* YAML-ized Tencent COS configuration from common.properties
* Added remote logger support with Tencent COS
  • Loading branch information
Mighten committed Sep 21, 2024
1 parent 696dcf0 commit aa0eb85
Show file tree
Hide file tree
Showing 23 changed files with 1,041 additions and 107 deletions.
31 changes: 21 additions & 10 deletions docs/docs/en/guide/resource/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,30 @@ resource.huawei.cloud.obs.endpoint=obs.cn-southwest-2.huaweicloud.com
## connect COS

if you want to upload resources to `Resource Center` connected to `COS`, you need to configure `api-server/conf/common.properties` and `worker-server/conf/common.properties`. You can refer to the following:
if you want to upload resources to `Resource Center` connected to `COS`, you need to configure `api-server/conf/resource-center.yaml` and `worker-server/conf/resource-center.yaml`. You can refer to the following:

config the following fields

```properties
# access key id, required if you set resource.storage.type=COS
resource.tencent.cloud.access.key.id=<your-access-key-id>
# access key secret, required if you set resource.storage.type=COS
resource.tencent.cloud.access.key.secret=<your-access-key-secret>
# cos bucket name, required if you set resource.storage.type=COS
resource.tencent.cloud.cos.bucket.name=dolphinscheduler
# cos bucket region, required if you set resource.storage.type=COS, refer to https://cloud.tencent.com/document/product/436/6224
resource.tencent.cloud.cos.region=ap-nanjing
```yaml
resource:
# Tencent Cloud Storage (COS) setup, required if you set resource.storage.type=COS
tencent:
cloud:
access:
key:
id: <your-access-key-id>
secret: <your-access-key-secret>
cos:
# predefined region code: https://cloud.tencent.com/document/product/436/6224
region: ap-nanjing
bucket:
name: dolphinscheduler

```

To enable COS, you also need to configure `api-server/conf/common.properties` and `worker-server/conf/common.properties`. You can refer to the following:

```properties
resource.storage.type=COS
```

31 changes: 21 additions & 10 deletions docs/docs/zh/guide/resource/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,28 @@ resource.huawei.cloud.obs.endpoint=obs.cn-southwest-2.huaweicloud.com
## 对接腾讯云 COS

如果需要使用到资源中心的 COS 上传资源,我们需要对以下路径的进行配置:`api-server/conf/common.properties``worker-server/conf/common.properties`。可参考如下:
如果需要使用到资源中心的 COS 上传资源,我们需要对以下路径的进行配置:`api-server/conf/resource-center.yaml``worker-server/conf/resource-center.yaml`。可参考如下:

```properties
# access key id, required if you set resource.storage.type=COS
resource.tencent.cloud.access.key.id=<your-access-key-id>
# access key secret, required if you set resource.storage.type=COS
resource.tencent.cloud.access.key.secret=<your-access-key-secret>
# cos bucket name, required if you set resource.storage.type=COS
resource.tencent.cloud.cos.bucket.name=dolphinscheduler
# cos bucket region, required if you set resource.storage.type=COS, refer to https://cloud.tencent.com/document/product/436/6224
resource.tencent.cloud.cos.region=ap-nanjing
```yaml
resource:
# 腾讯云 COS 配置
tencent:
cloud:
access:
key:
id: <your-access-key-id>
secret: <your-access-key-secret>
cos:
# COS 区域代码可参考: https://cloud.tencent.com/document/product/436/6224
region: ap-nanjing
bucket:
name: dolphinscheduler

```

为了激活腾讯云存储 COS,还需要对以下路径的进行配置:`api-server/conf/common.properties``worker-server/conf/common.properties`。可参考如下:

```properties
resource.storage.type=COS
```

5 changes: 5 additions & 0 deletions dolphinscheduler-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@
<artifactId>esdk-obs-java-bundle</artifactId>
</dependency>

<dependency>
<groupId>com.qcloud</groupId>
<artifactId>cos_api</artifactId>
</dependency>

<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public final class Constants {

public static final String REMOTE_LOGGING_YAML_PATH = "/remote-logging.yaml";
public static final String AWS_YAML_PATH = "/aws.yaml";
public static final String RESOURCE_CENTER_YAML_PATH = "/resource-center.yaml";

public static final String FORMAT_SS = "%s%s";
public static final String FORMAT_S_S = "%s/%s";
Expand Down Expand Up @@ -684,6 +685,17 @@ public final class Constants {
public static final String REMOTE_LOGGING_ABS_ACCOUNT_KEY = "remote.logging.abs.account.key";
public static final String REMOTE_LOGGING_ABS_CONTAINER_NAME = "remote.logging.abs.container.name";

/**
* remote logging for COS
*/
public static final String REMOTE_LOGGING_COS_ACCESS_KEY_ID = "remote.logging.cos.access.key.id";

public static final String REMOTE_LOGGING_COS_ACCESS_KEY_SECRET = "remote.logging.cos.access.key.secret";

public static final String REMOTE_LOGGING_COS_BUCKET_NAME = "remote.logging.cos.bucket.name";

public static final String REMOTE_LOGGING_COS_REGION = "remote.logging.cos.region";

/**
* data quality
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* 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 org.apache.commons.lang3.StringUtils;

import java.io.Closeable;
import java.io.File;
import java.io.IOException;

import lombok.extern.slf4j.Slf4j;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.http.HttpProtocol;
import com.qcloud.cos.model.GetObjectRequest;
import com.qcloud.cos.model.PutObjectRequest;
import com.qcloud.cos.region.Region;

@Slf4j
public class CosRemoteLogHandler implements RemoteLogHandler, Closeable {

private final COSClient cosClient;

private final String bucketName;

private static CosRemoteLogHandler instance;

private CosRemoteLogHandler() {
String secretId = PropertyUtils.getString(Constants.REMOTE_LOGGING_COS_ACCESS_KEY_ID);
String secretKey = PropertyUtils.getString(Constants.REMOTE_LOGGING_COS_ACCESS_KEY_SECRET);
COSCredentials cosCredentials = new BasicCOSCredentials(secretId, secretKey);
String regionName = PropertyUtils.getString(Constants.REMOTE_LOGGING_COS_REGION);
ClientConfig clientConfig = new ClientConfig(new Region(regionName));
clientConfig.setHttpProtocol(HttpProtocol.https);
this.cosClient = new COSClient(cosCredentials, clientConfig);
this.bucketName = PropertyUtils.getString(Constants.REMOTE_LOGGING_COS_BUCKET_NAME);
checkBucketNameExists(this.bucketName);
}

public static synchronized CosRemoteLogHandler getInstance() {
if (instance == null) {
instance = new CosRemoteLogHandler();
}
return instance;
}

@Override
public void sendRemoteLog(String logPath) {
String objectName = RemoteLogUtils.getObjectNameFromLogPath(logPath);

try {
log.info("send remote log {} to COS {}", logPath, objectName);
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, new File(logPath));
cosClient.putObject(putObjectRequest);
} catch (Exception e) {
log.error("error while sending remote log {} to COS {}", logPath, objectName, e);
}
}

@Override
public void getRemoteLog(String logPath) {
String objectName = RemoteLogUtils.getObjectNameFromLogPath(logPath);

try {
log.info("get remote log on COS {} to {}", objectName, logPath);
cosClient.getObject(new GetObjectRequest(bucketName, objectName), new File(logPath));
} catch (Exception e) {
log.error("error while getting remote log on COS {} to {}", objectName, logPath, e);
}
}

@Override
public void close() throws IOException {
if (cosClient != null) {
cosClient.shutdown();
}
}

private void checkBucketNameExists(String bucketName) {
if (StringUtils.isBlank(bucketName)) {
throw new IllegalArgumentException(Constants.REMOTE_LOGGING_COS_BUCKET_NAME + " is empty");
}
boolean existsBucket = cosClient.doesBucketExist(bucketName);
if (!existsBucket) {
throw new IllegalArgumentException(
"bucketName: " + bucketName + " is not exists, you need to create them by yourself");
}

log.info("Tencent COS bucket '{}' has been found for remote logging", bucketName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public RemoteLogHandler getRemoteLogHandler() {
return GcsRemoteLogHandler.getInstance();
} else if ("ABS".equals(target)) {
return AbsRemoteLogHandler.getInstance();
} else if ("COS".equals(target)) {
return CosRemoteLogHandler.getInstance();
}

log.error("No suitable remote logging target for {}", target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.apache.dolphinscheduler.common.constants.Constants.AWS_YAML_PATH;
import static org.apache.dolphinscheduler.common.constants.Constants.COMMON_PROPERTIES_PATH;
import static org.apache.dolphinscheduler.common.constants.Constants.REMOTE_LOGGING_YAML_PATH;
import static org.apache.dolphinscheduler.common.constants.Constants.RESOURCE_CENTER_YAML_PATH;

import org.apache.dolphinscheduler.common.config.ImmutablePriorityPropertyDelegate;
import org.apache.dolphinscheduler.common.config.ImmutablePropertyDelegate;
Expand All @@ -43,7 +44,7 @@ public class PropertyUtils {
private final ImmutablePriorityPropertyDelegate propertyDelegate =
new ImmutablePriorityPropertyDelegate(
new ImmutablePropertyDelegate(COMMON_PROPERTIES_PATH),
new ImmutableYamlDelegate(REMOTE_LOGGING_YAML_PATH, AWS_YAML_PATH));
new ImmutableYamlDelegate(REMOTE_LOGGING_YAML_PATH, AWS_YAML_PATH, RESOURCE_CENTER_YAML_PATH));

public static String getString(String key) {
return propertyDelegate.get(key.trim());
Expand Down
35 changes: 0 additions & 35 deletions dolphinscheduler-common/src/main/resources/common.properties
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,6 @@ resource.huawei.cloud.obs.bucket.name=dolphinscheduler
resource.huawei.cloud.obs.endpoint=obs.cn-southwest-2.huaweicloud.com


# tencent cloud access key id, required if you set resource.storage.type=COS
resource.tencent.cloud.access.key.id=<your-access-key-id>
# access key secret, required if you set resource.storage.type=COS
resource.tencent.cloud.access.key.secret=<your-access-key-secret>
# cos bucket name, required if you set resource.storage.type=COS
resource.tencent.cloud.cos.bucket.name=dolphinscheduler
# cos bucket region, required if you set resource.storage.type=COS, see: https://cloud.tencent.com/document/product/436/6224
resource.tencent.cloud.cos.region=ap-nanjing


# if resource.storage.type=HDFS, the user must have the permission to create directories under the HDFS root path
resource.hdfs.root.user=hdfs
# if resource.storage.type=S3, the value like: s3a://dolphinscheduler; if resource.storage.type=HDFS and namenode HA is enabled, you need to copy core-site.xml and hdfs-site.xml to conf dir
Expand Down Expand Up @@ -173,28 +163,3 @@ shell.interceptor.type=bash

# Whether to enable remote logging
remote.logging.enable=false
# if remote.logging.enable = true, set the target of remote logging
remote.logging.target=OSS
# if remote.logging.enable = true, set the log base directory
remote.logging.base.dir=logs
# if remote.logging.enable = true, set the number of threads to send logs to remote storage
remote.logging.thread.pool.size=10
# oss access key id, required if you set remote.logging.target=OSS
remote.logging.oss.access.key.id=<access.key.id>
# oss access key secret, required if you set remote.logging.target=OSS
remote.logging.oss.access.key.secret=<access.key.secret>
# oss bucket name, required if you set remote.logging.target=OSS
remote.logging.oss.bucket.name=<bucket.name>
# oss endpoint, required if you set remote.logging.target=OSS
remote.logging.oss.endpoint=<endpoint>

# the location of the google cloud credential, required if you set remote.logging.target=GCS
remote.logging.google.cloud.storage.credential=/path/to/credential
# gcs bucket name, required if you set remote.logging.target=GCS
remote.logging.google.cloud.storage.bucket.name=<your-bucket>
# abs account name, required if you set resource.storage.type=ABS
remote.logging.abs.account.name=<your-account-name>
# abs account key, required if you set resource.storage.type=ABS
remote.logging.abs.account.key=<your-account-key>
# abs container name, required if you set resource.storage.type=ABS
remote.logging.abs.container.name=<your-container-name>
34 changes: 20 additions & 14 deletions dolphinscheduler-common/src/main/resources/remote-logging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,27 @@
# limitations under the License.
#

remote-logging:
# Whether to enable remote logging
enable: false
# if remote-logging.enable = true, set the target of remote logging
remote.logging:
# if remote.logging.enable = true, set the target of remote logging
target: OSS
# if remote-logging.enable = true, set the log base directory
# if remote.logging.enable = true, set the log base directory
base.dir: logs
# if remote-logging.enable = true, set the number of threads to send logs to remote storage
# if remote.logging.enable = true, set the number of threads to send logs to remote storage
thread.pool.size: 10
# required if you set remote-logging.target=OSS
# required if you set remote.logging.target=OSS
oss:
# oss access key id, required if you set remote-logging.target=OSS
# oss access key id, required if you set remote.logging.target=OSS
access.key.id: <access.key.id>
# oss access key secret, required if you set remote-logging.target=OSS
# oss access key secret, required if you set remote.logging.target=OSS
access.key.secret: <access.key.secret>
# oss bucket name, required if you set remote-logging.target=OSS
# oss bucket name, required if you set remote.logging.target=OSS
bucket.name: <bucket.name>
# oss endpoint, required if you set remote-logging.target=OSS
# oss endpoint, required if you set remote.logging.target=OSS
endpoint: <endpoint>
google.cloud.storage:
# the location of the google cloud credential, required if you set remote-logging.target=GCS
# the location of the google cloud credential, required if you set remote.logging.target=GCS
credential: /path/to/credential
# gcs bucket name, required if you set remote-logging.target=GCS
# gcs bucket name, required if you set remote.logging.target=GCS
bucket.name: <your-bucket>
abs:
# abs account name, required if you set resource.storage.type=ABS
Expand All @@ -46,4 +44,12 @@ remote-logging:
account.key: <your-account-key>
# abs container name, required if you set resource.storage.type=ABS
container.name: <your-container-name>

cos:
# cos access key id, required if you set remote-logging.target=COS
access.key.id: <access.key.id>
# cos access key secret, required if you set remote-logging.target=COS
access.key.secret: <access.key.secret>
# cos bucket name, required if you set remote-logging.target=COS
bucket.name: <bucket.name>
# cos region, required if you set remote-logging.target=COS
region: <region>
30 changes: 30 additions & 0 deletions dolphinscheduler-common/src/main/resources/resource-center.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# 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.
#

resource:
# Tencent Cloud Storage (COS) setup, required if you set resource.storage.type=COS
tencent:
cloud:
access:
key:
id: <your-access-key-id>
secret: <your-access-key-secret>
cos:
# predefined region code: https://cloud.tencent.com/document/product/436/6224
region: ap-nanjing
bucket:
name: dolphinscheduler
Loading

0 comments on commit aa0eb85

Please sign in to comment.