morningman commented on code in PR #18005: URL: https://github.com/apache/doris/pull/18005#discussion_r1148393130
########## fe/fe-core/src/main/java/org/apache/doris/datasource/property/BeAWSProperties.java: ########## @@ -0,0 +1,60 @@ +// 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.doris.datasource.property; + +import org.apache.doris.datasource.property.constants.S3Properties; + +import org.apache.hadoop.fs.obs.OBSConstants; +import org.apache.hadoop.fs.s3a.Constants; + +import java.util.Map; + +public class BeAWSProperties { + + public static void setBeAWSPropertiesFromS3(Map<String, String> properties) { + String endpoint = properties.get(Constants.ENDPOINT); + properties.put(S3Properties.Environment.ENDPOINT, endpoint); + String region = PropertyConverter.getRegionOfEndpoint(endpoint); + properties.put(S3Properties.Environment.REGION, properties.getOrDefault(Constants.AWS_REGION, region)); + if (properties.containsKey(Constants.ACCESS_KEY)) { + properties.put(S3Properties.Environment.ACCESS_KEY, properties.get(Constants.ACCESS_KEY)); + } + if (properties.containsKey(Constants.SECRET_KEY)) { + properties.put(S3Properties.Environment.SECRET_KEY, properties.get(Constants.SECRET_KEY)); + } + if (properties.containsKey(Constants.SESSION_TOKEN)) { + properties.put(S3Properties.Environment.TOKEN, properties.get(Constants.SESSION_TOKEN)); + } + } + + public static void setBeAWSPropertiesFromObs(Map<String, String> properties) { + String endpoint = properties.get(OBSConstants.ENDPOINT); + properties.put(S3Properties.Environment.ENDPOINT, endpoint); + String region = PropertyConverter.getRegionOfEndpoint(endpoint); + properties.put(S3Properties.Environment.REGION, region); + if (properties.containsKey(OBSConstants.ACCESS_KEY)) { + properties.put(S3Properties.Environment.ACCESS_KEY, properties.get(OBSConstants.ACCESS_KEY)); + } + if (properties.containsKey(OBSConstants.SECRET_KEY)) { + properties.put(S3Properties.Environment.SECRET_KEY, properties.get(OBSConstants.SECRET_KEY)); + } + if (properties.containsKey("fs.obs.session.token")) { Review Comment: Why not define `fs.obs.session.token` in `OBSConstants`? ########## fe/fe-core/src/main/java/org/apache/doris/datasource/property/PropertyConverter.java: ########## @@ -0,0 +1,337 @@ +// 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.doris.datasource.property; + +import org.apache.doris.datasource.credentials.CloudCredential; +import org.apache.doris.datasource.credentials.CloudCredentialWithEndpoint; +import org.apache.doris.datasource.property.constants.CosProperties; +import org.apache.doris.datasource.property.constants.DLFProperties; +import org.apache.doris.datasource.property.constants.GlueProperties; +import org.apache.doris.datasource.property.constants.HMSProperties; +import org.apache.doris.datasource.property.constants.ObsProperties; +import org.apache.doris.datasource.property.constants.OssProperties; +import org.apache.doris.datasource.property.constants.S3Properties; + +import com.aliyun.datalake.metastore.common.DataLakeConfig; +import com.amazonaws.glue.catalog.util.AWSGlueConfig; +import com.google.common.base.Strings; +import com.google.common.collect.Maps; +import org.apache.hadoop.fs.obs.OBSConstants; +import org.apache.hadoop.fs.s3a.Constants; +import org.apache.hadoop.fs.s3a.S3AFileSystem; +import org.apache.hadoop.fs.s3a.TemporaryAWSCredentialsProvider; +import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.Map; + +public class PropertyConverter { + + private static final Logger LOG = LogManager.getLogger(PropertyConverter.class); + public static final String USE_PATH_STYLE = "use_path_style"; + + public static String getRegionOfEndpoint(String endpoint) { + String[] endpointSplit = endpoint.split("\\."); + if (endpointSplit.length < 2) { + throw new IllegalArgumentException("Need endpoint with region: " + endpoint); + } + return endpointSplit[1]; + } + + public static Map<String, String> metaConvert(Map<String, String> props) { + if (props.containsKey(GlueProperties.ENDPOINT) + || props.containsKey(AWSGlueConfig.AWS_GLUE_ENDPOINT)) { + return convertToGlueProperties(props, GlueProperties.getCredential(props)); + } else if (props.containsKey(DLFProperties.ENDPOINT) + || props.containsKey(DataLakeConfig.CATALOG_ENDPOINT)) { + return convertToDLFProperties(props, DLFProperties.getCredential(props)); + } + return props; + } + + /** + * Convert properties defined at doris to FE S3 client properties and BE S3 client properties + */ + public static Map<String, String> storageConvert(Map<String, String> props) { + if (props.containsKey(S3Properties.Environment.ENDPOINT)) { + // compatible with the s3,obs,oss,cos when they use aws client. + return convertToS3EnvProperties(props, S3Properties.getCompatibleCredential(props)); + } else if (props.containsKey(S3Properties.ENDPOINT)) { + return convertToS3Properties(props, S3Properties.getCredential(props)); + } else if (props.containsKey(ObsProperties.ENDPOINT)) { + return convertToOBSProperties(props, ObsProperties.getCredential(props)); + } else if (props.containsKey(OssProperties.ENDPOINT)) { + return convertToOSSProperties(props, OssProperties.getCredential(props)); + } else if (props.containsKey(CosProperties.ENDPOINT)) { + return convertToCOSProperties(props, CosProperties.getCredential(props)); + } + return props; + } + + + private static Map<String, String> convertToOBSProperties(Map<String, String> props, + CloudCredential credential) { + Map<String, String> obsProperties = Maps.newHashMap(); + obsProperties.put(OBSConstants.ENDPOINT, props.get(ObsProperties.ENDPOINT)); + obsProperties.put("fs.obs.impl.disable.cache", "true"); + if (credential.isWhole()) { + obsProperties.put(OBSConstants.ACCESS_KEY, credential.getAccessKey()); + obsProperties.put(OBSConstants.SECRET_KEY, credential.getSecretKey()); + } + if (credential.isTemporary()) { + obsProperties.put("fs.obs.session.token", credential.getSessionToken()); + } + for (Map.Entry<String, String> entry : props.entrySet()) { + if (entry.getKey().startsWith(ObsProperties.OBS_FS_PREFIX)) { + obsProperties.put(entry.getKey(), entry.getValue()); + } + } + BeAWSProperties.setBeAWSPropertiesFromObs(obsProperties); + return obsProperties; + } + + private static Map<String, String> convertToS3EnvProperties(Map<String, String> properties, Review Comment: ```suggestion private static Map<String, String> convertToS3HadoopFSProperties(Map<String, String> properties, ``` ########## fe/fe-core/src/main/java/org/apache/doris/datasource/property/BeAWSProperties.java: ########## @@ -0,0 +1,60 @@ +// 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.doris.datasource.property; + +import org.apache.doris.datasource.property.constants.S3Properties; + +import org.apache.hadoop.fs.obs.OBSConstants; +import org.apache.hadoop.fs.s3a.Constants; + +import java.util.Map; + +public class BeAWSProperties { Review Comment: How about naming it as `S3ClientProperties`? And better add some comment to this class ########## fe/fe-core/src/main/java/org/apache/doris/datasource/property/PropertyConverter.java: ########## @@ -0,0 +1,337 @@ +// 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.doris.datasource.property; + +import org.apache.doris.datasource.credentials.CloudCredential; +import org.apache.doris.datasource.credentials.CloudCredentialWithEndpoint; +import org.apache.doris.datasource.property.constants.CosProperties; +import org.apache.doris.datasource.property.constants.DLFProperties; +import org.apache.doris.datasource.property.constants.GlueProperties; +import org.apache.doris.datasource.property.constants.HMSProperties; +import org.apache.doris.datasource.property.constants.ObsProperties; +import org.apache.doris.datasource.property.constants.OssProperties; +import org.apache.doris.datasource.property.constants.S3Properties; + +import com.aliyun.datalake.metastore.common.DataLakeConfig; +import com.amazonaws.glue.catalog.util.AWSGlueConfig; +import com.google.common.base.Strings; +import com.google.common.collect.Maps; +import org.apache.hadoop.fs.obs.OBSConstants; +import org.apache.hadoop.fs.s3a.Constants; +import org.apache.hadoop.fs.s3a.S3AFileSystem; +import org.apache.hadoop.fs.s3a.TemporaryAWSCredentialsProvider; +import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.Map; + +public class PropertyConverter { + + private static final Logger LOG = LogManager.getLogger(PropertyConverter.class); + public static final String USE_PATH_STYLE = "use_path_style"; + + public static String getRegionOfEndpoint(String endpoint) { + String[] endpointSplit = endpoint.split("\\."); + if (endpointSplit.length < 2) { + throw new IllegalArgumentException("Need endpoint with region: " + endpoint); + } + return endpointSplit[1]; + } + + public static Map<String, String> metaConvert(Map<String, String> props) { + if (props.containsKey(GlueProperties.ENDPOINT) + || props.containsKey(AWSGlueConfig.AWS_GLUE_ENDPOINT)) { + return convertToGlueProperties(props, GlueProperties.getCredential(props)); + } else if (props.containsKey(DLFProperties.ENDPOINT) + || props.containsKey(DataLakeConfig.CATALOG_ENDPOINT)) { + return convertToDLFProperties(props, DLFProperties.getCredential(props)); + } + return props; + } + + /** + * Convert properties defined at doris to FE S3 client properties and BE S3 client properties + */ + public static Map<String, String> storageConvert(Map<String, String> props) { Review Comment: ```suggestion public static Map<String, String> convertToHadoopFSProperties(Map<String, String> props) { ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org