Skip to content

Commit

Permalink
branch-3.0: [fix](cloud) Add check for alter storage vault type (#43489)
Browse files Browse the repository at this point in the history
Cherry-picked from #43352

Co-authored-by: Lei Zhang <[email protected]>
  • Loading branch information
github-actions[bot] and SWJTU-ZhangLei authored Nov 10, 2024
1 parent f8c9b2c commit e077592
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 1 deletion.
17 changes: 17 additions & 0 deletions cloud/src/meta-service/meta_service_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,15 @@ static int alter_hdfs_storage_vault(InstanceInfoPB& instance, std::unique_ptr<Tr
}
StorageVaultPB new_vault;
new_vault.ParseFromString(val);

if (!new_vault.has_hdfs_info()) {
code = MetaServiceCode::INVALID_ARGUMENT;
std::stringstream ss;
ss << name << " is not hdfs storage vault";
msg = ss.str();
return -1;
}

auto origin_vault_info = new_vault.DebugString();
if (vault.has_alter_name()) {
if (!is_valid_storage_vault_name(vault.alter_name())) {
Expand Down Expand Up @@ -671,6 +680,14 @@ static int alter_s3_storage_vault(InstanceInfoPB& instance, std::unique_ptr<Tran
}
StorageVaultPB new_vault;
new_vault.ParseFromString(val);
if (!new_vault.has_obj_info()) {
code = MetaServiceCode::INVALID_ARGUMENT;
std::stringstream ss;
ss << name << " is not s3 storage vault";
msg = ss.str();
return -1;
}

if (vault.has_alter_name()) {
if (!is_valid_storage_vault_name(vault.alter_name())) {
code = MetaServiceCode::INVALID_ARGUMENT;
Expand Down
78 changes: 78 additions & 0 deletions regression-test/suites/vault_p0/alter/test_alter_vault_type.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// 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_vault_type", "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
}

def hdfsVaultName = suiteName + "_HDFS"

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

expectExceptionLike({
sql """
ALTER STORAGE VAULT ${hdfsVaultName}
PROPERTIES (
"type"="s3",
"s3.access_key" = "new_ak"
);
"""
}, "is not s3 storage vault")


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

expectExceptionLike({
sql """
ALTER STORAGE VAULT ${s3VaultName}
PROPERTIES (
"type"="hdfs",
"hadoop.username" = "hdfs"
);
"""
}, "is not hdfs storage vault")
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ suite("test_create_vault", "nonConcurrent") {

expectExceptionLike({
sql """
CREATE STORAGE VAULT IF NOT EXISTS built_in_storage_vault
CREATE STORAGE VAULT built_in_storage_vault
PROPERTIES (
"type"="S3",
"s3.endpoint"="${getS3Endpoint()}",
Expand Down

0 comments on commit e077592

Please sign in to comment.