steveloughran commented on code in PR #6308:
URL: https://github.com/apache/hadoop/pull/6308#discussion_r1410722984


##########
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/tools/BucketTool.java:
##########
@@ -0,0 +1,315 @@
+/*
+ * 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.
+ */
+
+package org.apache.hadoop.fs.s3a.tools;
+
+import java.io.FileNotFoundException;
+import java.io.PrintStream;
+import java.net.URI;
+import java.util.List;
+import java.util.Optional;
+import java.util.function.BiFunction;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.services.s3.S3Client;
+import software.amazon.awssdk.services.s3.model.BucketType;
+import software.amazon.awssdk.services.s3.model.CreateBucketConfiguration;
+import software.amazon.awssdk.services.s3.model.CreateBucketRequest;
+import software.amazon.awssdk.services.s3.model.DataRedundancy;
+import software.amazon.awssdk.services.s3.model.LocationInfo;
+import software.amazon.awssdk.services.s3.model.LocationType;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.classification.VisibleForTesting;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.fs.s3a.S3AFileSystem;
+import org.apache.hadoop.fs.s3a.s3guard.S3GuardTool;
+import org.apache.hadoop.fs.shell.CommandFormat;
+import org.apache.hadoop.io.IOUtils;
+import org.apache.hadoop.util.DurationInfo;
+import org.apache.hadoop.util.ExitUtil;
+
+import static org.apache.commons.lang3.StringUtils.isNotEmpty;
+import static org.apache.hadoop.fs.s3a.Constants.AWS_REGION;
+import static org.apache.hadoop.fs.s3a.Constants.ENDPOINT;
+import static org.apache.hadoop.fs.s3a.Constants.S3A_BUCKET_PROBE;
+import static org.apache.hadoop.fs.s3a.impl.S3ExpressStorage.PRODUCT_NAME;
+import static 
org.apache.hadoop.fs.s3a.impl.S3ExpressStorage.STORE_CAPABILITY_S3_EXPRESS_STORAGE;
+import static org.apache.hadoop.fs.s3a.Invoker.once;
+import static 
org.apache.hadoop.fs.s3a.audit.S3AAuditConstants.REJECT_OUT_OF_SPAN_OPERATIONS;
+import static 
org.apache.hadoop.fs.s3a.impl.S3ExpressStorage.hasS3ExpressSuffix;
+import static org.apache.hadoop.fs.s3a.impl.S3ExpressStorage.isAwsEndpoint;
+import static 
org.apache.hadoop.service.launcher.LauncherExitCodes.EXIT_BAD_CONFIGURATION;
+import static 
org.apache.hadoop.service.launcher.LauncherExitCodes.EXIT_NOT_ACCEPTABLE;
+import static org.apache.hadoop.service.launcher.LauncherExitCodes.EXIT_USAGE;
+
+/**
+ * Bucket operations, e.g. create/delete/probe.
+ */
+public final class BucketTool extends S3GuardTool {
+
+  private static final Logger LOG = LoggerFactory.getLogger(BucketTool.class);
+
+  /**
+   * Name of this tool: {@value}.
+   */
+  public static final String NAME = "bucket";
+
+  /**
+   * Purpose of this tool: {@value}.
+   */
+  public static final String PURPOSE =
+      "View and manipulate S3 buckets";
+
+  /**
+   * Error text when too few arguments are found.
+   */
+  static final String E_ARGUMENTS = "Wrong number of arguments: %d";
+
+  /**
+   * create command.
+   */
+  public static final String CREATE = "create";
+
+  /**
+   * region {@value}.
+   */
+  public static final String OPT_REGION = "region";
+
+  /**
+   * endpoint {@value}.
+   */
+  public static final String OPT_ENDPOINT = "endpoint";
+
+  /**
+   * Zone for a store.
+   */
+  public static final String OPT_ZONE = "zone";
+
+  /**
+   * Error message if -zone is set but the name doesn't match.
+   * Value {@value}.
+   */
+  static final String UNSUPPORTED_ZONE_ARG =
+      "The -zone option is only supported for " + PRODUCT_NAME;
+
+  /**
+   * Error message if the bucket is S3 Express but -zone wasn't set.
+   * Value {@value}.
+   */
+  static final String NO_ZONE_SUPPLIED = "Required option -zone missing for "
+      + PRODUCT_NAME + " bucket";
+
+  /**
+   * Error Message logged/thrown when the tool could not start as
+   * the bucket probe was not disabled and the probe (inevitably)
+   * failed.
+   */
+  public static final String PROBE_FAILURE =
+      "Initialization failed because the bucket existence probe"
+          + S3A_BUCKET_PROBE + " was not disabled. Check core-site settings.";
+
+  public BucketTool(final Configuration conf) {
+    super(conf, 1, 1,
+        CREATE,
+        VERBOSE);
+    CommandFormat format = getCommandFormat();
+    format.addOptionWithValue(OPT_REGION);
+    format.addOptionWithValue(OPT_ENDPOINT);
+    format.addOptionWithValue(OPT_ZONE);
+  }
+
+  public String getUsage() {
+    return "bucket "
+        + "-" + CREATE + " "
+        + "[-" + OPT_ENDPOINT + " <endpoint>] "
+        + "[-" + OPT_REGION + " <region>] "
+        + "[-" + OPT_ZONE + " <zone>] "
+        + "[-" + VERBOSE + "] "
+
+        + " <s3a-URL>";
+  }
+
+  public String getName() {
+    return NAME;
+  }
+
+  private Optional<String> getOptionalString(String key) {
+    String value = getCommandFormat().getOptValue(key);
+    return isNotEmpty(value) ? Optional.of(value) : Optional.empty();
+  }
+
+  @VisibleForTesting
+  int exec(final String...args) throws Exception {
+
+    return run(args, System.out);
+  }
+
+
+  @Override
+  public int run(final String[] args, final PrintStream out)

Review Comment:
   leave that to the docs. Or you fix your error messages...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to