Skip to content

Commit

Permalink
[cloud](storage vault) Rewrite vaults regression test and fix two err…
Browse files Browse the repository at this point in the history
…or (apache#42411)

* Rewrite vaults regression test
* Fix show storage vault stmt `default` column incorrectly
* Fix create table cannot find storage vault after creating the vault
  • Loading branch information
SWJTU-ZhangLei authored Oct 28, 2024
1 parent fe58d40 commit de93c26
Show file tree
Hide file tree
Showing 16 changed files with 832 additions and 846 deletions.
2 changes: 2 additions & 0 deletions cloud/src/meta-service/meta_service_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,7 @@ void MetaServiceImpl::alter_storage_vault(google::protobuf::RpcController* contr
instance.set_default_storage_vault_id(vault.id());
instance.set_default_storage_vault_name(vault.name());
}
response->set_storage_vault_id(vault.id());
LOG_INFO("try to put storage vault_id={}, vault_name={}, vault_key={}", vault.id(),
vault.name(), hex(vault_key));
} break;
Expand All @@ -1006,6 +1007,7 @@ void MetaServiceImpl::alter_storage_vault(google::protobuf::RpcController* contr
instance.set_default_storage_vault_id(*instance.resource_ids().rbegin());
instance.set_default_storage_vault_name(*instance.storage_vault_names().rbegin());
}
response->set_storage_vault_id(request->vault().id());
break;
}
case AlterObjStoreInfoRequest::ADD_BUILT_IN_VAULT: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public static void setDefaultVaultToShowVaultResult(List<List<String>> rows, Str
}

int vaultIdIndex = IntStream.range(0, columns.size())
.filter(i -> columns.get(i).getName().equals("StorageVaultId"))
.filter(i -> columns.get(i).getName().equals("Id"))
.findFirst()
.orElse(-1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3407,8 +3407,7 @@ private void handleShowStorageVault() throws AnalysisException {
UserIdentity user = ctx.getCurrentUserIdentity();
rows = resp.getStorageVaultList().stream()
.filter(storageVault -> auth.checkStorageVaultPriv(user, storageVault.getName(),
PrivPredicate.USAGE)
)
PrivPredicate.USAGE))
.map(StorageVault::convertToShowStorageVaultProperties)
.collect(Collectors.toList());
if (resp.hasDefaultStorageVaultId()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@

package org.apache.doris.regression.suite

import org.awaitility.Awaitility
import static java.util.concurrent.TimeUnit.SECONDS
import groovy.json.JsonOutput

import com.google.common.base.Strings
import com.google.common.collect.ImmutableList
import com.google.common.collect.Maps
import com.google.common.util.concurrent.Futures
import com.google.common.util.concurrent.ListenableFuture
import com.google.common.util.concurrent.MoreExecutors
import com.google.gson.Gson
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import com.google.common.collect.ImmutableList
import groovy.util.logging.Slf4j

import org.awaitility.Awaitility
import org.apache.commons.lang3.ObjectUtils
import org.apache.doris.regression.Config
import org.apache.doris.regression.RegressionTest
Expand All @@ -53,7 +57,6 @@ import org.jetbrains.annotations.NotNull
import org.junit.jupiter.api.Assertions
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import groovy.util.logging.Slf4j

import java.sql.Connection
import java.io.File
Expand Down Expand Up @@ -1512,12 +1515,13 @@ class Suite implements GroovyInterceptable {
}

boolean enableStoragevault() {
boolean ret = false;
if (context.config.metaServiceHttpAddress == null || context.config.metaServiceHttpAddress.isEmpty() ||
context.config.instanceId == null || context.config.instanceId.isEmpty() ||
context.config.metaServiceToken == null || context.config.metaServiceToken.isEmpty()) {
return ret;
if (Strings.isNullOrEmpty(context.config.metaServiceHttpAddress)
|| Strings.isNullOrEmpty(context.config.instanceId)
|| Strings.isNullOrEmpty(context.config.metaServiceToken)) {
return false;
}

boolean ret = false;
def getInstanceInfo = { check_func ->
httpTest {
endpoint context.config.metaServiceHttpAddress
Expand Down
98 changes: 98 additions & 0 deletions regression-test/suites/vault_p0/alter/test_alter_hdfs_vault.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// 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("test_alter_hdfs_vault", "nonConcurrent") {
def suiteName = name;
if (!isCloudMode()) {
logger.info("skip ${name} case, because not cloud mode")
return
}

if (!enableStoragevault()) {
logger.info("skip ${name} case, because storage vault not enabled")
return
}

sql """
CREATE STORAGE VAULT IF NOT EXISTS ${suiteName}
PROPERTIES (
"type"="HDFS",
"fs.defaultFS"="${getHmsHdfsFs()}",
"path_prefix" = "${suiteName}",
"hadoop.username" = "hadoop"
);
"""

expectExceptionLike({
sql """
ALTER STORAGE VAULT ${suiteName}
PROPERTIES (
"type"="hdfs",
"path_prefix" = "${suiteName}"
);
"""
}, "Alter property")

expectExceptionLike({
sql """
ALTER STORAGE VAULT ${suiteName}
PROPERTIES (
"type"="hdfs",
"fs.defaultFS" = "not_exist_vault"
);
"""
}, "Alter property")

def vaultName = suiteName
String properties;

def vaultInfos = try_sql """show storage vault"""

for (int i = 0; i < vaultInfos.size(); i++) {
def name = vaultInfos[i][0]
if (name.equals(vaultName)) {
properties = vaultInfos[i][2]
}
}

def newVaultName = suiteName + "_new";
sql """
ALTER STORAGE VAULT ${vaultName}
PROPERTIES (
"type"="hdfs",
"VAULT_NAME" = "${newVaultName}",
"hadoop.username" = "hdfs"
);
"""

vaultInfos = sql """ SHOW STORAGE VAULT; """
boolean exist = false

for (int i = 0; i < vaultInfos.size(); i++) {
def name = vaultInfos[i][0]
logger.info("name is ${name}, info ${vaultInfos[i]}")
if (name.equals(vaultName)) {
assertTrue(false);
}
if (name.equals(newVaultName)) {
assertTrue(vaultInfos[i][2].contains("""user: "hdfs" """))
exist = true
}
}
assertTrue(exist)
expectExceptionLike({sql """insert into ${suiteName} values("2", "2");"""}, "")
}
106 changes: 106 additions & 0 deletions regression-test/suites/vault_p0/alter/test_alter_s3_vault.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// 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("test_alter_s3_vault", "nonConcurrent") {
def suiteName = name;
if (!isCloudMode()) {
logger.info("skip ${suiteName} case, because not cloud mode")
return
}

if (!enableStoragevault()) {
logger.info("skip ${suiteName} case, because storage vault not enabled")
return
}

sql """
CREATE STORAGE VAULT IF NOT EXISTS ${suiteName}
PROPERTIES (
"type"="S3",
"s3.endpoint"="${getS3Endpoint()}",
"s3.region" = "${getS3Region()}",
"s3.access_key" = "${getS3AK()}",
"s3.secret_key" = "${getS3SK()}",
"s3.root.path" = "${suiteName}",
"s3.bucket" = "${getS3BucketName()}",
"s3.external_endpoint" = "",
"provider" = "${getS3Provider()}"
);
"""

expectExceptionLike({
sql """
ALTER STORAGE VAULT ${suiteName}
PROPERTIES (
"type"="S3",
"s3.bucket" = "error_bucket"
);
"""
}, "Alter property")

expectExceptionLike({
sql """
ALTER STORAGE VAULT ${suiteName}
PROPERTIES (
"type"="S3",
"provider" = "${getS3Provider()}"
);
"""
}, "Alter property")


def vaultName = suiteName
String properties;

def vaultInfos = try_sql """show storage vault"""

for (int i = 0; i < vaultInfos.size(); i++) {
def name = vaultInfos[i][0]
if (name.equals(vaultName)) {
properties = vaultInfos[i][2]
}
}

def newVaultName = suiteName + "_new";

sql """
ALTER STORAGE VAULT ${vaultName}
PROPERTIES (
"type"="S3",
"VAULT_NAME" = "${newVaultName}",
"s3.access_key" = "new_ak"
);
"""

vaultInfos = sql """SHOW STORAGE VAULT;"""
boolean exist = false

for (int i = 0; i < vaultInfos.size(); i++) {
def name = vaultInfos[i][0]
logger.info("name is ${name}, info ${vaultInfos[i]}")
if (name.equals(vaultName)) {
assertTrue(false);
}
if (name.equals(newVaultName)) {
assertTrue(vaultInfos[i][2].contains("new_ak"))
exist = true
}
}
assertTrue(exist)
// failed to insert due to the wrong ak
expectExceptionLike({ sql """insert into alter_s3_vault_tbl values("2", "2");""" }, "")
}
Loading

0 comments on commit de93c26

Please sign in to comment.