Copilot commented on code in PR #10147:
URL: https://github.com/apache/ozone/pull/10147#discussion_r3147982740


##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/local/OzoneLocal.java:
##########
@@ -0,0 +1,385 @@
+/*
+ * 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.ozone.local;
+
+import java.nio.file.InvalidPathException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.time.Duration;
+import java.time.format.DateTimeParseException;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.Callable;
+import java.util.concurrent.TimeUnit;
+import org.apache.hadoop.hdds.cli.GenericCli;
+import org.apache.hadoop.hdds.cli.HddsVersionProvider;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import picocli.CommandLine;
+import picocli.CommandLine.Command;
+import picocli.CommandLine.Option;
+
+/**
+ * Internal CLI entry point for local single-node Ozone commands.
+ */
+@Command(name = "ozone local",
+    hidden = true,
+    description = "Internal commands for local single-node Ozone",
+    versionProvider = HddsVersionProvider.class,
+    mixinStandardHelpOptions = true,
+    subcommands = {
+        OzoneLocal.RunCommand.class
+    })
+public class OzoneLocal extends GenericCli {
+
+  static final String ENV_DATA_DIR = "OZONE_LOCAL_DATA_DIR";
+  static final String ENV_FORMAT = "OZONE_LOCAL_FORMAT";
+  static final String ENV_DATANODES = "OZONE_LOCAL_DATANODES";
+  static final String ENV_HOST = "OZONE_LOCAL_HOST";
+  static final String ENV_BIND_HOST = "OZONE_LOCAL_BIND_HOST";
+  static final String ENV_SCM_PORT = "OZONE_LOCAL_SCM_PORT";
+  static final String ENV_OM_PORT = "OZONE_LOCAL_OM_PORT";
+  static final String ENV_S3G_ENABLED = "OZONE_LOCAL_S3G_ENABLED";
+  static final String ENV_S3G_PORT = "OZONE_LOCAL_S3G_PORT";
+  static final String ENV_EPHEMERAL = "OZONE_LOCAL_EPHEMERAL";
+  static final String ENV_STARTUP_TIMEOUT = "OZONE_LOCAL_STARTUP_TIMEOUT";
+  static final String ENV_S3_ACCESS_KEY = "OZONE_LOCAL_S3_ACCESS_KEY";
+  static final String ENV_S3_SECRET_KEY = "OZONE_LOCAL_S3_SECRET_KEY";
+  static final String ENV_S3_REGION = "OZONE_LOCAL_S3_REGION";
+
+  public OzoneLocal() {
+    super();
+  }
+
+  OzoneLocal(CommandLine.IFactory factory) {
+    super(factory);
+  }
+
+  public static void main(String[] args) {
+    new OzoneLocal().run(args);
+  }
+
+  @Command(name = "run",
+      hidden = true,
+      description = "Internal placeholder for a local Ozone runtime")
+  static class RunCommand implements Callable<Void> {
+
+    private final Map<String, String> environment;
+
+    @Option(names = "--data-dir",
+        description = "Persistent data directory for the local cluster")
+    private String dataDir;
+
+    @Option(names = "--format",
+        description = "Storage init mode: if-needed, always, never")
+    private String format;
+
+    @Option(names = "--datanodes",
+        description = "Number of datanodes to start")
+    private Integer datanodes;
+
+    @Option(names = "--host",
+        description = "Advertised host to write into local service addresses")
+    private String host;
+
+    @Option(names = "--bind-host",
+        description = "Bind host for HTTP and RPC listeners")
+    private String bindHost;
+
+    @Option(names = "--scm-port",
+        description = "SCM client RPC port (0 means auto-allocate)")
+    private Integer scmPort;
+
+    @Option(names = "--om-port",
+        description = "OM RPC port (0 means auto-allocate)")
+    private Integer omPort;
+
+    @Option(names = "--s3g-port",
+        description = "S3 Gateway HTTP port (0 means auto-allocate)")
+    private Integer s3gPort;
+
+    @Option(names = "--without-s3g",
+        description = "Disable S3 Gateway")
+    private boolean withoutS3g;
+
+    @Option(names = "--ephemeral",
+        description = "Delete the data directory on shutdown")
+    private boolean ephemeral;
+
+    @Option(names = "--startup-timeout",
+        description = "How long to wait for the local cluster to become ready")
+    private String startupTimeout;
+
+    @Option(names = "--s3-access-key",
+        description = "Suggested local AWS access key to print on startup")
+    private String s3AccessKey;
+
+    @Option(names = "--s3-secret-key",
+        description = "Suggested local AWS secret key to print on startup")
+    private String s3SecretKey;
+
+    @Option(names = "--s3-region",
+        description = "Suggested local AWS region to print on startup")
+    private String s3Region;
+
+    RunCommand() {
+      this(System.getenv());
+    }
+
+    RunCommand(Map<String, String> environment) {
+      this.environment = Objects.requireNonNull(environment, "environment");
+    }
+
+    @Override
+    public Void call() {
+      resolveConfig(new OzoneConfiguration());
+      return null;
+    }
+
+    LocalOzoneClusterConfig resolveConfig(
+        OzoneConfiguration baseConfiguration) {
+      Path resolvedDataDir = resolvePath(dataDir, 
environment.get(ENV_DATA_DIR),
+          "--data-dir", ENV_DATA_DIR, 
LocalOzoneClusterConfig.DEFAULT_DATA_DIR);
+      LocalOzoneClusterConfig.FormatMode resolvedFormat = format != null
+          ? parseFormat(format, "--format")
+          : parseFormat(environment.get(ENV_FORMAT), ENV_FORMAT,
+              LocalOzoneClusterConfig.DEFAULT_FORMAT_MODE);
+      int resolvedDatanodes = datanodes != null
+          ? datanodes
+          : parseInt(environment.get(ENV_DATANODES), ENV_DATANODES,
+              LocalOzoneClusterConfig.DEFAULT_DATANODES);
+      if (resolvedDatanodes < 1) {
+        throw new IllegalArgumentException(
+            "Datanode count for "
+                + (datanodes != null ? "--datanodes" : ENV_DATANODES)
+                + " must be at least 1.");
+      }
+
+      String resolvedHost = firstNonBlank(host, environment.get(ENV_HOST),
+          LocalOzoneClusterConfig.DEFAULT_HOST);
+      String resolvedBindHost = firstNonBlank(bindHost,
+          environment.get(ENV_BIND_HOST),
+          LocalOzoneClusterConfig.DEFAULT_BIND_HOST);
+
+      int resolvedScmPort = scmPort != null
+          ? validatePort(scmPort, "--scm-port")
+          : parsePort(environment.get(ENV_SCM_PORT), ENV_SCM_PORT,
+              LocalOzoneClusterConfig.DEFAULT_PORT);
+      int resolvedOmPort = omPort != null
+          ? validatePort(omPort, "--om-port")
+          : parsePort(environment.get(ENV_OM_PORT), ENV_OM_PORT,
+              LocalOzoneClusterConfig.DEFAULT_PORT);
+      int resolvedS3gPort = s3gPort != null
+          ? validatePort(s3gPort, "--s3g-port")
+          : parsePort(environment.get(ENV_S3G_PORT), ENV_S3G_PORT,
+              LocalOzoneClusterConfig.DEFAULT_PORT);
+
+      boolean resolvedS3gEnabled = withoutS3g ? false
+          : parseBoolean(environment.get(ENV_S3G_ENABLED), ENV_S3G_ENABLED,
+              LocalOzoneClusterConfig.DEFAULT_S3G_ENABLED);
+      boolean resolvedEphemeral = ephemeral || parseBoolean(
+          environment.get(ENV_EPHEMERAL), ENV_EPHEMERAL,
+          LocalOzoneClusterConfig.DEFAULT_EPHEMERAL);

Review Comment:
   `--ephemeral` only forces deletion *on*, but there’s no CLI way to override 
`OZONE_LOCAL_EPHEMERAL=true` back to false for a single run. If the environment 
variables are meant to be a “default” that CLI can override, consider using a 
negatable option (eg `--ephemeral/--no-ephemeral`) so CLI can override in both 
directions.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/local/OzoneLocal.java:
##########
@@ -0,0 +1,385 @@
+/*
+ * 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.ozone.local;
+
+import java.nio.file.InvalidPathException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.time.Duration;
+import java.time.format.DateTimeParseException;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.Callable;
+import java.util.concurrent.TimeUnit;
+import org.apache.hadoop.hdds.cli.GenericCli;
+import org.apache.hadoop.hdds.cli.HddsVersionProvider;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import picocli.CommandLine;
+import picocli.CommandLine.Command;
+import picocli.CommandLine.Option;
+
+/**
+ * Internal CLI entry point for local single-node Ozone commands.
+ */
+@Command(name = "ozone local",
+    hidden = true,
+    description = "Internal commands for local single-node Ozone",
+    versionProvider = HddsVersionProvider.class,
+    mixinStandardHelpOptions = true,
+    subcommands = {
+        OzoneLocal.RunCommand.class
+    })
+public class OzoneLocal extends GenericCli {
+
+  static final String ENV_DATA_DIR = "OZONE_LOCAL_DATA_DIR";
+  static final String ENV_FORMAT = "OZONE_LOCAL_FORMAT";
+  static final String ENV_DATANODES = "OZONE_LOCAL_DATANODES";
+  static final String ENV_HOST = "OZONE_LOCAL_HOST";
+  static final String ENV_BIND_HOST = "OZONE_LOCAL_BIND_HOST";
+  static final String ENV_SCM_PORT = "OZONE_LOCAL_SCM_PORT";
+  static final String ENV_OM_PORT = "OZONE_LOCAL_OM_PORT";
+  static final String ENV_S3G_ENABLED = "OZONE_LOCAL_S3G_ENABLED";
+  static final String ENV_S3G_PORT = "OZONE_LOCAL_S3G_PORT";
+  static final String ENV_EPHEMERAL = "OZONE_LOCAL_EPHEMERAL";
+  static final String ENV_STARTUP_TIMEOUT = "OZONE_LOCAL_STARTUP_TIMEOUT";
+  static final String ENV_S3_ACCESS_KEY = "OZONE_LOCAL_S3_ACCESS_KEY";
+  static final String ENV_S3_SECRET_KEY = "OZONE_LOCAL_S3_SECRET_KEY";
+  static final String ENV_S3_REGION = "OZONE_LOCAL_S3_REGION";
+
+  public OzoneLocal() {
+    super();
+  }
+
+  OzoneLocal(CommandLine.IFactory factory) {
+    super(factory);
+  }
+
+  public static void main(String[] args) {
+    new OzoneLocal().run(args);
+  }
+
+  @Command(name = "run",
+      hidden = true,
+      description = "Internal placeholder for a local Ozone runtime")
+  static class RunCommand implements Callable<Void> {
+
+    private final Map<String, String> environment;
+
+    @Option(names = "--data-dir",
+        description = "Persistent data directory for the local cluster")
+    private String dataDir;
+
+    @Option(names = "--format",
+        description = "Storage init mode: if-needed, always, never")
+    private String format;
+
+    @Option(names = "--datanodes",
+        description = "Number of datanodes to start")
+    private Integer datanodes;
+
+    @Option(names = "--host",
+        description = "Advertised host to write into local service addresses")
+    private String host;
+
+    @Option(names = "--bind-host",
+        description = "Bind host for HTTP and RPC listeners")
+    private String bindHost;
+
+    @Option(names = "--scm-port",
+        description = "SCM client RPC port (0 means auto-allocate)")
+    private Integer scmPort;
+
+    @Option(names = "--om-port",
+        description = "OM RPC port (0 means auto-allocate)")
+    private Integer omPort;
+
+    @Option(names = "--s3g-port",
+        description = "S3 Gateway HTTP port (0 means auto-allocate)")
+    private Integer s3gPort;
+
+    @Option(names = "--without-s3g",
+        description = "Disable S3 Gateway")
+    private boolean withoutS3g;
+
+    @Option(names = "--ephemeral",
+        description = "Delete the data directory on shutdown")
+    private boolean ephemeral;
+
+    @Option(names = "--startup-timeout",
+        description = "How long to wait for the local cluster to become ready")
+    private String startupTimeout;
+
+    @Option(names = "--s3-access-key",
+        description = "Suggested local AWS access key to print on startup")
+    private String s3AccessKey;
+
+    @Option(names = "--s3-secret-key",
+        description = "Suggested local AWS secret key to print on startup")
+    private String s3SecretKey;
+
+    @Option(names = "--s3-region",
+        description = "Suggested local AWS region to print on startup")
+    private String s3Region;
+
+    RunCommand() {
+      this(System.getenv());
+    }
+
+    RunCommand(Map<String, String> environment) {
+      this.environment = Objects.requireNonNull(environment, "environment");
+    }
+
+    @Override
+    public Void call() {
+      resolveConfig(new OzoneConfiguration());
+      return null;
+    }
+
+    LocalOzoneClusterConfig resolveConfig(
+        OzoneConfiguration baseConfiguration) {
+      Path resolvedDataDir = resolvePath(dataDir, 
environment.get(ENV_DATA_DIR),
+          "--data-dir", ENV_DATA_DIR, 
LocalOzoneClusterConfig.DEFAULT_DATA_DIR);
+      LocalOzoneClusterConfig.FormatMode resolvedFormat = format != null
+          ? parseFormat(format, "--format")
+          : parseFormat(environment.get(ENV_FORMAT), ENV_FORMAT,
+              LocalOzoneClusterConfig.DEFAULT_FORMAT_MODE);
+      int resolvedDatanodes = datanodes != null
+          ? datanodes
+          : parseInt(environment.get(ENV_DATANODES), ENV_DATANODES,
+              LocalOzoneClusterConfig.DEFAULT_DATANODES);
+      if (resolvedDatanodes < 1) {
+        throw new IllegalArgumentException(
+            "Datanode count for "
+                + (datanodes != null ? "--datanodes" : ENV_DATANODES)
+                + " must be at least 1.");
+      }
+
+      String resolvedHost = firstNonBlank(host, environment.get(ENV_HOST),
+          LocalOzoneClusterConfig.DEFAULT_HOST);
+      String resolvedBindHost = firstNonBlank(bindHost,
+          environment.get(ENV_BIND_HOST),
+          LocalOzoneClusterConfig.DEFAULT_BIND_HOST);
+
+      int resolvedScmPort = scmPort != null
+          ? validatePort(scmPort, "--scm-port")
+          : parsePort(environment.get(ENV_SCM_PORT), ENV_SCM_PORT,
+              LocalOzoneClusterConfig.DEFAULT_PORT);
+      int resolvedOmPort = omPort != null
+          ? validatePort(omPort, "--om-port")
+          : parsePort(environment.get(ENV_OM_PORT), ENV_OM_PORT,
+              LocalOzoneClusterConfig.DEFAULT_PORT);
+      int resolvedS3gPort = s3gPort != null
+          ? validatePort(s3gPort, "--s3g-port")
+          : parsePort(environment.get(ENV_S3G_PORT), ENV_S3G_PORT,
+              LocalOzoneClusterConfig.DEFAULT_PORT);
+
+      boolean resolvedS3gEnabled = withoutS3g ? false

Review Comment:
   `--without-s3g` can only force S3G *off*. If `OZONE_LOCAL_S3G_ENABLED=false` 
is set in the environment, there is currently no CLI way to force-enable S3G 
for a single invocation, even though the precedence rule elsewhere is “CLI 
overrides env”. Consider switching to a negatable boolean option (eg picocli 
`negatable = true` so users can pass `--s3g`/`--no-s3g`) or adding an explicit 
`--with-s3g` flag.
   



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/local/LocalOzoneClusterConfig.java:
##########
@@ -0,0 +1,254 @@
+/*
+ * 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.ozone.local;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.time.Duration;
+import java.util.Locale;
+import java.util.Objects;
+
+/**
+ * Configuration for a local single-node Ozone runtime.
+ */
+public final class LocalOzoneClusterConfig {
+
+  static final Path DEFAULT_DATA_DIR =
+      Paths.get(System.getProperty("user.home"), ".ozone", "local")
+          .toAbsolutePath()
+          .normalize();
+  static final FormatMode DEFAULT_FORMAT_MODE = FormatMode.IF_NEEDED;
+  static final int DEFAULT_DATANODES = 1;
+  static final String DEFAULT_HOST = "127.0.0.1";
+  static final String DEFAULT_BIND_HOST = "0.0.0.0";
+  static final int DEFAULT_PORT = 0;
+  static final boolean DEFAULT_S3G_ENABLED = true;
+  static final boolean DEFAULT_EPHEMERAL = false;
+  static final Duration DEFAULT_STARTUP_TIMEOUT = Duration.ofMinutes(2);
+  static final String DEFAULT_S3_ACCESS_KEY = "admin";
+  static final String DEFAULT_S3_SECRET_KEY = "admin123";
+  static final String DEFAULT_S3_REGION = "us-east-1";
+
+  private final Path dataDir;
+  private final FormatMode formatMode;
+  private final int datanodes;
+  private final String host;
+  private final String bindHost;
+  private final int scmPort;
+  private final int omPort;
+  private final int s3gPort;
+  private final boolean s3gEnabled;
+  private final boolean ephemeral;
+  private final Duration startupTimeout;
+  private final String s3AccessKey;
+  private final String s3SecretKey;
+  private final String s3Region;
+
+  private LocalOzoneClusterConfig(Builder builder) {
+    dataDir = Objects.requireNonNull(builder.dataDir, "dataDir")
+        .toAbsolutePath()
+        .normalize();
+    formatMode = Objects.requireNonNull(builder.formatMode, "formatMode");
+    datanodes = builder.datanodes;
+    host = Objects.requireNonNull(builder.host, "host");
+    bindHost = Objects.requireNonNull(builder.bindHost, "bindHost");
+    scmPort = builder.scmPort;
+    omPort = builder.omPort;
+    s3gPort = builder.s3gPort;
+    s3gEnabled = builder.s3gEnabled;
+    ephemeral = builder.ephemeral;
+    startupTimeout = Objects.requireNonNull(builder.startupTimeout,
+        "startupTimeout");
+    s3AccessKey = Objects.requireNonNull(builder.s3AccessKey, "s3AccessKey");
+    s3SecretKey = Objects.requireNonNull(builder.s3SecretKey, "s3SecretKey");
+    s3Region = Objects.requireNonNull(builder.s3Region, "s3Region");
+  }
+
+  public Path getDataDir() {
+    return dataDir;
+  }
+
+  public FormatMode getFormatMode() {
+    return formatMode;
+  }
+
+  public int getDatanodes() {
+    return datanodes;
+  }
+
+  public String getHost() {
+    return host;
+  }
+
+  public String getBindHost() {
+    return bindHost;
+  }
+
+  public int getScmPort() {
+    return scmPort;
+  }
+
+  public int getOmPort() {
+    return omPort;
+  }
+
+  public int getS3gPort() {
+    return s3gPort;
+  }
+
+  public boolean isS3gEnabled() {
+    return s3gEnabled;
+  }
+
+  public boolean isEphemeral() {
+    return ephemeral;
+  }
+
+  public Duration getStartupTimeout() {
+    return startupTimeout;
+  }
+
+  public String getS3AccessKey() {
+    return s3AccessKey;
+  }
+
+  public String getS3SecretKey() {
+    return s3SecretKey;
+  }
+
+  public String getS3Region() {
+    return s3Region;
+  }
+
+  public static Builder builder() {
+    return new Builder(DEFAULT_DATA_DIR);
+  }
+
+  public static Builder builder(Path dataDir) {
+    return new Builder(dataDir);
+  }
+
+  /**
+   * Storage initialization mode for the local runtime.
+   */
+  public enum FormatMode {
+    IF_NEEDED,
+    ALWAYS,
+    NEVER;
+
+    public static FormatMode fromString(String value) {
+      String normalized = value.trim().toUpperCase(Locale.ROOT)
+          .replace('-', '_');
+      return valueOf(normalized);
+    }

Review Comment:
   `FormatMode.fromString` is public but will throw a `NullPointerException` if 
called with `null` (because of `value.trim()`). Consider explicitly checking 
for null and throwing an `IllegalArgumentException` with a clear message so 
callers get a predictable validation error.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to