-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[feat](storage vault) Add object storage op check when creating resource #48073
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,12 +19,13 @@ | |
|
|
||
| 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.S3FileSystem; | ||
| import org.apache.doris.fs.obj.ObjStorage; | ||
| import org.apache.doris.fs.obj.RemoteObjects; | ||
| import org.apache.doris.fs.obj.S3ObjStorage; | ||
|
|
||
| import com.google.common.base.Preconditions; | ||
| import com.google.common.collect.Lists; | ||
|
|
@@ -33,6 +34,7 @@ | |
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
|
|
||
| import java.io.ByteArrayInputStream; | ||
| import java.util.Arrays; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
|
|
@@ -102,45 +104,65 @@ protected void setProperties(Map<String, String> properties) throws DdlException | |
| } | ||
| 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); | ||
| pingS3(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 { | ||
| S3FileSystem fileSystem = new S3FileSystem(properties); | ||
| String testFile = "s3://" + bucketName + "/" + rootPath + "/test-object-valid.txt"; | ||
| String content = "doris will be better"; | ||
| if (FeConstants.runningUnitTest) { | ||
| return; | ||
| protected static void pingS3(String bucketName, String rootPath, Map<String, String> newProperties) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comments to this section like AzureResource.java |
||
| throws DdlException { | ||
|
|
||
| Long timestamp = System.currentTimeMillis(); | ||
| String prefix = "s3://" + bucketName + "/" + rootPath; | ||
| String testObj = prefix + "/doris-test-object-valid-" + timestamp.toString() + ".txt"; | ||
|
|
||
| byte[] contentData = new byte[2 * ObjStorage.CHUNK_SIZE]; | ||
| Arrays.fill(contentData, (byte) 'A'); | ||
| S3ObjStorage s3ObjStorage = new S3ObjStorage(newProperties); | ||
|
|
||
| Status status = s3ObjStorage.putObject(testObj, new ByteArrayInputStream(contentData), contentData.length); | ||
| if (!Status.OK.equals(status)) { | ||
| String errMsg = "pingS3 failed(put)," | ||
| + " please check your endpoint, ak/sk or permissions(put/head/delete/list/multipartUpload)," | ||
| + " status: " + status + ", properties: " + new PrintableMap<>( | ||
| newProperties, "=", true, false, true, false); | ||
| throw new DdlException(errMsg); | ||
| } | ||
| Status status = Status.OK; | ||
| try { | ||
| status = fileSystem.directUpload(content, testFile); | ||
| if (status != Status.OK) { | ||
| throw new DdlException( | ||
| "ping s3 failed(upload), status: " + status + ", properties: " + new PrintableMap<>( | ||
| properties, "=", true, false, true, false)); | ||
| } | ||
| } finally { | ||
| if (status.ok()) { | ||
| Status delete = fileSystem.delete(testFile); | ||
| if (delete != Status.OK) { | ||
| LOG.warn("delete test file failed, status: {}, properties: {}", delete, new PrintableMap<>( | ||
| properties, "=", true, false, true, false)); | ||
| } | ||
| } | ||
|
|
||
| status = s3ObjStorage.headObject(testObj); | ||
| if (!Status.OK.equals(status)) { | ||
| String errMsg = "pingS3 failed(head)," | ||
| + " please check your endpoint, ak/sk or permissions(put/head/delete/list/multipartUpload)," | ||
| + " status: " + status + ", properties: " + new PrintableMap<>( | ||
| newProperties, "=", true, false, true, false); | ||
| throw new DdlException(errMsg); | ||
| } | ||
|
|
||
| RemoteObjects remoteObjects = s3ObjStorage.listObjects(testObj, null); | ||
| LOG.info("remoteObjects: {}", remoteObjects); | ||
|
|
||
| status = s3ObjStorage.multipartUpload(testObj, new ByteArrayInputStream(contentData), contentData.length); | ||
| if (!Status.OK.equals(status)) { | ||
| String errMsg = "pingS3 failed(multipartUpload)," | ||
| + " please check your endpoint, ak/sk or permissions(put/head/delete/list/multipartUpload)," | ||
| + " status: " + status + ", properties: " + new PrintableMap<>( | ||
| newProperties, "=", true, false, true, false); | ||
| throw new DdlException(errMsg); | ||
| } | ||
|
|
||
| status = s3ObjStorage.deleteObject(testObj); | ||
| if (!Status.OK.equals(status)) { | ||
| String errMsg = "pingS3 failed(delete)," | ||
| + " please check your endpoint, ak/sk or permissions(put/head/delete/list/multipartUpload)," | ||
| + " status: " + status + ", properties: " + new PrintableMap<>( | ||
| newProperties, "=", true, false, true, false); | ||
| throw new DdlException(errMsg); | ||
| } | ||
|
|
||
| LOG.info("success to ping s3"); | ||
|
|
@@ -172,7 +194,7 @@ public void modifyProperties(Map<String, String> properties) throws DdlException | |
| String rootPath = properties.getOrDefault(S3Properties.ROOT_PATH, | ||
| this.properties.get(S3Properties.ROOT_PATH)); | ||
|
|
||
| pingS3(getS3PingCredentials(changedProperties), bucketName, rootPath, changedProperties); | ||
| pingS3(bucketName, rootPath, changedProperties); | ||
| } | ||
|
|
||
| // modify properties | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,10 @@ | |
| * @param <C> cloud SDK Client | ||
| */ | ||
| public interface ObjStorage<C> { | ||
|
|
||
| // CHUNK_SIZE for multi part upload | ||
| public static final int CHUNK_SIZE = 5 * 1024 * 1024; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add comment what is chunk_size and what it is for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
done |
||
|
|
||
| C getClient() throws UserException; | ||
|
|
||
| Triple<String, String, String> getStsToken() throws DdlException; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we may need to convert the raw message to what user can understand.
e.g.
if status is 403, return "failed try to test to put object, lack of permission of PUT"
if status is connection refused, return "failed to connect to azure, please check your connection or endpoint"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not necessary, keep the same as before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you show me the code, what you expect to deal with