This is an automated email from the ASF dual-hosted git repository.

dataroaring pushed a commit to branch branch-4.0-preview
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 5bd086fad88c65e02af707aee81ce353bc6377eb
Author: AlexYue <yj976240...@gmail.com>
AuthorDate: Thu Apr 25 14:17:48 2024 +0800

    [enhance](Cloud) Add case to test if vault is forbid for cloud mode without 
vault (#34006)
---
 .../doris/analysis/ShowStorageVaultStmt.java       | 12 ++++++
 regression-test/suites/vaults/forbid/forbid.groovy | 50 ++++++++++++++++++++++
 2 files changed, 62 insertions(+)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowStorageVaultStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowStorageVaultStmt.java
index e4af07e43b1..ddf25292846 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowStorageVaultStmt.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowStorageVaultStmt.java
@@ -19,9 +19,12 @@ package org.apache.doris.analysis;
 
 import org.apache.doris.catalog.Env;
 import org.apache.doris.catalog.StorageVault;
+import org.apache.doris.cloud.catalog.CloudEnv;
 import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.Config;
 import org.apache.doris.common.ErrorCode;
 import org.apache.doris.common.ErrorReport;
+import org.apache.doris.common.FeConstants;
 import org.apache.doris.common.UserException;
 import org.apache.doris.mysql.privilege.PrivPredicate;
 import org.apache.doris.qe.ConnectContext;
@@ -41,6 +44,15 @@ public class ShowStorageVaultStmt extends ShowStmt {
 
     @Override
     public void analyze(Analyzer analyzer) throws AnalysisException, 
UserException {
+        if (Config.isNotCloudMode()) {
+            throw new AnalysisException("Storage Vault is only supported for 
cloud mode");
+        }
+        if (!FeConstants.runningUnitTest) {
+            // In legacy cloud mode, some s3 back-ended storage does need to 
use storage vault.
+            if (!((CloudEnv) Env.getCurrentEnv()).getEnableStorageVault()) {
+                throw new AnalysisException("Your cloud instance doesn't 
support storage vault");
+            }
+        }
         super.analyze(analyzer);
         // check auth
         if 
(!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), 
PrivPredicate.ADMIN)) {
diff --git a/regression-test/suites/vaults/forbid/forbid.groovy 
b/regression-test/suites/vaults/forbid/forbid.groovy
new file mode 100644
index 00000000000..15fba18fc6d
--- /dev/null
+++ b/regression-test/suites/vaults/forbid/forbid.groovy
@@ -0,0 +1,50 @@
+// 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.
+
+suite("forbid_vault") {
+    if (enableStoragevault()) {
+        logger.info("skip forbid storage vault case because storage vault 
enabled")
+        return
+    }
+
+    if (!isCloudMode()) {
+        logger.info("skip forbid storage vault case because not cloud mode")
+        return
+    }
+
+    expectExceptionLike({
+        sql """
+            set not_exist as default storage vault
+        """
+    }, "Your cloud instance doesn't support storage vault")
+
+    expectExceptionLike({
+        sql """
+            CREATE STORAGE VAULT IF NOT EXISTS hdfs_vault
+            PROPERTIES (
+            "type"="hdfs",
+            "fs.defaultFS"="hdfs://127.0.0.1:8020"
+            );
+        """
+    }, "Your cloud instance doesn't support storage vault")
+
+    expectExceptionLike({
+        sql """
+            show storage vault
+        """
+    }, "Your cloud instance doesn't support storage vault")
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to