gavinchou commented on code in PR #35990: URL: https://github.com/apache/doris/pull/35990#discussion_r1641265744
########## fe/fe-core/src/main/java/org/apache/doris/catalog/AzureResource.java: ########## @@ -0,0 +1,211 @@ +// 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.catalog; + +import org.apache.doris.backup.Status; +import org.apache.doris.common.DdlException; +import org.apache.doris.common.FeConstants; +import org.apache.doris.common.credentials.CloudCredentialWithEndpoint; +import org.apache.doris.common.proc.BaseProcResult; +import org.apache.doris.common.util.PrintableMap; +import org.apache.doris.datasource.property.constants.S3Properties; +import org.apache.doris.fs.remote.AzureFileSystem; + +import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +public class AzureResource extends Resource { + + private static final Logger LOG = LogManager.getLogger(AzureResource.class); + private Map<String, String> properties; + + public AzureResource() { + super(); + } + + public AzureResource(String name) { + super(name, ResourceType.AZURE); + } + + @Override + protected void setProperties(Map<String, String> properties) throws DdlException { + Preconditions.checkState(properties != null); + // check properties + S3Properties.requiredS3PingProperties(properties); + // default need check resource conf valid, so need fix ut and regression case + boolean needCheck = isNeedCheck(properties); + if (LOG.isDebugEnabled()) { + LOG.debug("azure info need check validity : {}", needCheck); + } + + // the endpoint for ping need add uri scheme. + String pingEndpoint = properties.get(S3Properties.ENDPOINT); + if (!pingEndpoint.startsWith("http://")) { + pingEndpoint = "http://" + properties.get(S3Properties.ENDPOINT); + properties.put(S3Properties.ENDPOINT, pingEndpoint); + properties.put(S3Properties.Env.ENDPOINT, pingEndpoint); + } + String region = S3Properties.getRegionOfEndpoint(pingEndpoint); + properties.putIfAbsent(S3Properties.REGION, region); + String ak = properties.get(S3Properties.ACCESS_KEY); + String sk = properties.get(S3Properties.SECRET_KEY); + String token = properties.get(S3Properties.SESSION_TOKEN); + CloudCredentialWithEndpoint credential = new CloudCredentialWithEndpoint(pingEndpoint, region, ak, sk, token); + + if (needCheck) { + String bucketName = properties.get(S3Properties.BUCKET); + String rootPath = properties.get(S3Properties.ROOT_PATH); + pingS3(credential, bucketName, rootPath, properties); + } + // optional + S3Properties.optionalS3Property(properties); + this.properties = properties; + } + + private static void pingS3(CloudCredentialWithEndpoint credential, String bucketName, String rootPath, + Map<String, String> properties) throws DdlException { + String bucket = "s3://" + bucketName + "/"; + AzureFileSystem fileSystem = new AzureFileSystem(properties); + String testFile = bucket + rootPath + "/test-object-valid.txt"; + String content = "doris will be better"; + if (FeConstants.runningUnitTest) { + return; + } + Status status = Status.OK; + try { + status = fileSystem.directUpload(content, testFile); Review Comment: Use list instead of upload a file to pollute the remote storage. 404 or 200 of list represents success -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
