diff --git a/hadoop-ozone/dist/src/main/smoketest/s3/s3_getsecret.robot b/hadoop-ozone/dist/src/main/smoketest/s3/s3_getsecret.robot new file mode 100644 index 000000000000..4218cc1934c8 --- /dev/null +++ b/hadoop-ozone/dist/src/main/smoketest/s3/s3_getsecret.robot @@ -0,0 +1,37 @@ +# 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. + +*** Settings *** +Documentation Test ozone s3 getsecret command +Resource ../commonlib.robot +Test Timeout 2 minutes + +*** Keywords *** +Verify output + [arguments] ${output} + Should contain ${output} awsAccessKey + Should contain ${output} awsSecret + +*** Test Cases *** +Without OM service ID + Pass Execution If '${SECURITY_ENABLED}' == 'false' N/A + ${output} = Execute ozone s3 getsecret -u testuser2 + Verify output ${output} + +With OM service ID + Pass Execution If '${OM_HA_PARAM}' == '${EMPTY}' duplicate test in non-HA env. + Pass Execution If '${SECURITY_ENABLED}' == 'false' N/A + ${output} = Execute ozone s3 getsecret -u testuser2 ${OM_HA_PARAM} + Verify output ${output} \ No newline at end of file diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/OzoneAddress.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/OzoneAddress.java index 4a9882404e7b..cef95dcf0f8e 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/OzoneAddress.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/OzoneAddress.java @@ -187,6 +187,8 @@ public OzoneClient createClientForS3Commands( String omServiceID ) throws IOException, OzoneClientException { + Collection serviceIds = conf. + getTrimmedStringCollection(OZONE_OM_SERVICE_IDS_KEY); if (omServiceID != null) { // OM HA cluster if (OmUtils.isOmHAServiceId(conf, omServiceID)) { @@ -195,20 +197,19 @@ public OzoneClient createClientForS3Commands( throw new OzoneClientException("Service ID specified does not match" + " with " + OZONE_OM_SERVICE_IDS_KEY + " defined in the " + "configuration. Configured " + OZONE_OM_SERVICE_IDS_KEY + " are" + - conf.getTrimmedStringCollection(OZONE_OM_SERVICE_IDS_KEY)); + serviceIds); } - } else { - // If om service id is not specified, consider it as a non-HA cluster. - // But before that check if serviceId is defined. If it is defined - // throw an error om service ID needs to be specified. - if (OmUtils.isServiceIdsDefined(conf)) { - throw new OzoneClientException("Service ID must not" - + " be omitted when " + OZONE_OM_SERVICE_IDS_KEY + " is defined. " + - "Configured " + OZONE_OM_SERVICE_IDS_KEY + " are " + - conf.getTrimmedStringCollection(OZONE_OM_SERVICE_IDS_KEY)); - } - return OzoneClientFactory.getRpcClient(conf); + } else if (serviceIds.size() > 1) { + // If multiple om service ids are there, + // throw an error "om service ID must not be omitted" + throw new OzoneClientException("Service ID must not" + + " be omitted when cluster has multiple OM Services." + + " Configured " + OZONE_OM_SERVICE_IDS_KEY + " are " + + serviceIds); } + // for non-HA cluster and HA cluster with only 1 service ID + // get service ID from configurations + return OzoneClientFactory.getRpcClient(conf); } /** diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/s3/S3Handler.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/s3/S3Handler.java index 34e3b9afa82a..91cde308cb2c 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/s3/S3Handler.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/s3/S3Handler.java @@ -34,8 +34,8 @@ public abstract class S3Handler extends Handler { @CommandLine.Option(names = {"--om-service-id"}, required = false, - description = "OM Service ID is required to be specified for OM HA" + - " cluster") + description = "OM Service ID for OM HA, " + + "required when cluster has multiple OM services") private String omServiceID; public String getOmServiceID() {