epugh commented on code in PR #2712:
URL: https://github.com/apache/solr/pull/2712#discussion_r1759625530


##########
solr/core/src/java/org/apache/solr/cli/SolrProcessMgr.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.solr.cli;
+
+import static 
org.apache.solr.servlet.SolrDispatchFilter.SOLR_INSTALL_DIR_ATTRIBUTE;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Optional;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.solr.common.util.EnvUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Class to interact with Solr OS processes */
+public class SolrProcessMgr {

Review Comment:
   Nit picky, but how about `SolrProcessManager`?   Is `Mgr` a short cut we say 
a lot...?



##########
solr/core/src/java/org/apache/solr/cli/StatusTool.java:
##########
@@ -65,37 +74,119 @@ public String getName() {
           .desc("Wait up to the specified number of seconds to see Solr 
running.")
           .build();
 
+  public static final Option OPTION_PORT =
+      Option.builder("p")
+          .longOpt("port")
+          .argName("PORT")
+          .required(false)
+          .hasArg()
+          .desc("Port on localhost to check status for")
+          .build();
+
+  public static final Option OPTION_SHORT =
+      Option.builder()
+          .longOpt("short")
+          .argName("SHORT")
+          .required(false)
+          .desc("Short format. Prints one URL per line for running instances")
+          .build();
+
   @Override
   public List<Option> getOptions() {
-    return List.of(
-        // The solr-url option is not exposed to the end user, and is
-        // created by the bin/solr script and passed into this command 
directly,
-        // therefore we don't use the SolrCLI.OPTION_SOLRURL.
-        Option.builder()
-            .argName("URL")
-            .longOpt("solr-url")
-            .hasArg()
-            .required(false)
-            .desc("Property set by calling scripts, not meant for user 
configuration.")
-            .build(),
-        OPTION_MAXWAITSECS);
+    return List.of(OPTION_SOLRURL, OPTION_MAXWAITSECS, OPTION_PORT, 
OPTION_SHORT);

Review Comment:
   this is a nice clean up..  I love that we flip the script and embrace the 
argument.  the whole "hiding" it thing was a total pain in the past..   And now 
we get MORE capability out of the tool!



##########
solr/core/src/java/org/apache/solr/cli/StatusTool.java:
##########
@@ -65,37 +74,119 @@ public String getName() {
           .desc("Wait up to the specified number of seconds to see Solr 
running.")
           .build();
 
+  public static final Option OPTION_PORT =
+      Option.builder("p")
+          .longOpt("port")
+          .argName("PORT")
+          .required(false)
+          .hasArg()
+          .desc("Port on localhost to check status for")
+          .build();
+
+  public static final Option OPTION_SHORT =
+      Option.builder()
+          .longOpt("short")
+          .argName("SHORT")
+          .required(false)
+          .desc("Short format. Prints one URL per line for running instances")
+          .build();
+
   @Override
   public List<Option> getOptions() {
-    return List.of(
-        // The solr-url option is not exposed to the end user, and is
-        // created by the bin/solr script and passed into this command 
directly,
-        // therefore we don't use the SolrCLI.OPTION_SOLRURL.
-        Option.builder()
-            .argName("URL")
-            .longOpt("solr-url")
-            .hasArg()
-            .required(false)
-            .desc("Property set by calling scripts, not meant for user 
configuration.")
-            .build(),
-        OPTION_MAXWAITSECS);
+    return List.of(OPTION_SOLRURL, OPTION_MAXWAITSECS, OPTION_PORT, 
OPTION_SHORT);
   }
 
   @Override
   public void runImpl(CommandLine cli) throws Exception {
-    // Override the default help behaviour to put out a customized message 
that only list user
-    // settable Options.
-    if ((cli.getOptions().length == 0 && cli.getArgs().length == 0)
-        || cli.hasOption("h")
-        || cli.hasOption("help")) {
-      final Options options = new Options();
-      options.addOption(OPTION_MAXWAITSECS);
-      new HelpFormatter().printHelp("status", options);
-      return;
+    String solrUrl = cli.getOptionValue(OPTION_SOLRURL);

Review Comment:
   we need to check the deprecated option as welL?   Actually, I guess not!!!!  
  



##########
solr/core/src/test/org/apache/solr/cli/SolrProcessMgrTest.java:
##########


Review Comment:
   Wow!  Some great tests..   I don't know that I could ever have written, but 
I loved reading it!



##########
solr/packaging/test/test_help.bats:
##########
@@ -60,10 +60,8 @@ setup() {
 
 @test "status help flag prints help" {
   run solr status --help
-  assert_output --partial 'usage: status'
+  assert_output --partial 'usage: bin/solr status [--max-wait-secs <SECS>] [-p 
<PORT>] [--short] [-url <HOST>]'

Review Comment:
   love it!



##########
solr/core/src/java/org/apache/solr/cli/StatusTool.java:
##########
@@ -65,37 +74,119 @@ public String getName() {
           .desc("Wait up to the specified number of seconds to see Solr 
running.")
           .build();
 
+  public static final Option OPTION_PORT =
+      Option.builder("p")
+          .longOpt("port")
+          .argName("PORT")
+          .required(false)
+          .hasArg()
+          .desc("Port on localhost to check status for")
+          .build();
+
+  public static final Option OPTION_SHORT =
+      Option.builder()
+          .longOpt("short")
+          .argName("SHORT")
+          .required(false)
+          .desc("Short format. Prints one URL per line for running instances")
+          .build();
+
   @Override
   public List<Option> getOptions() {
-    return List.of(
-        // The solr-url option is not exposed to the end user, and is
-        // created by the bin/solr script and passed into this command 
directly,
-        // therefore we don't use the SolrCLI.OPTION_SOLRURL.
-        Option.builder()
-            .argName("URL")
-            .longOpt("solr-url")
-            .hasArg()
-            .required(false)
-            .desc("Property set by calling scripts, not meant for user 
configuration.")
-            .build(),
-        OPTION_MAXWAITSECS);
+    return List.of(OPTION_SOLRURL, OPTION_MAXWAITSECS, OPTION_PORT, 
OPTION_SHORT);
   }
 
   @Override
   public void runImpl(CommandLine cli) throws Exception {
-    // Override the default help behaviour to put out a customized message 
that only list user
-    // settable Options.
-    if ((cli.getOptions().length == 0 && cli.getArgs().length == 0)
-        || cli.hasOption("h")
-        || cli.hasOption("help")) {
-      final Options options = new Options();
-      options.addOption(OPTION_MAXWAITSECS);
-      new HelpFormatter().printHelp("status", options);
-      return;
+    String solrUrl = cli.getOptionValue(OPTION_SOLRURL);
+    Integer port =
+        cli.hasOption(OPTION_PORT) ? 
Integer.parseInt(cli.getOptionValue(OPTION_PORT)) : null;
+    boolean shortFormat = cli.hasOption(OPTION_SHORT);
+
+    if (port != null && solrUrl != null) {

Review Comment:
   it really does seem like commons-cli should help us on this logic..  sigh..  
we have other places where this is the case.



##########
solr/core/src/java/org/apache/solr/cli/StatusTool.java:
##########
@@ -65,37 +74,119 @@ public String getName() {
           .desc("Wait up to the specified number of seconds to see Solr 
running.")
           .build();
 
+  public static final Option OPTION_PORT =
+      Option.builder("p")
+          .longOpt("port")
+          .argName("PORT")
+          .required(false)
+          .hasArg()
+          .desc("Port on localhost to check status for")
+          .build();
+
+  public static final Option OPTION_SHORT =
+      Option.builder()
+          .longOpt("short")
+          .argName("SHORT")
+          .required(false)
+          .desc("Short format. Prints one URL per line for running instances")
+          .build();
+
   @Override
   public List<Option> getOptions() {
-    return List.of(
-        // The solr-url option is not exposed to the end user, and is
-        // created by the bin/solr script and passed into this command 
directly,
-        // therefore we don't use the SolrCLI.OPTION_SOLRURL.
-        Option.builder()
-            .argName("URL")
-            .longOpt("solr-url")
-            .hasArg()
-            .required(false)
-            .desc("Property set by calling scripts, not meant for user 
configuration.")
-            .build(),
-        OPTION_MAXWAITSECS);
+    return List.of(OPTION_SOLRURL, OPTION_MAXWAITSECS, OPTION_PORT, 
OPTION_SHORT);
   }
 
   @Override
   public void runImpl(CommandLine cli) throws Exception {
-    // Override the default help behaviour to put out a customized message 
that only list user
-    // settable Options.
-    if ((cli.getOptions().length == 0 && cli.getArgs().length == 0)
-        || cli.hasOption("h")
-        || cli.hasOption("help")) {
-      final Options options = new Options();
-      options.addOption(OPTION_MAXWAITSECS);
-      new HelpFormatter().printHelp("status", options);
-      return;
+    String solrUrl = cli.getOptionValue(OPTION_SOLRURL);
+    Integer port =
+        cli.hasOption(OPTION_PORT) ? 
Integer.parseInt(cli.getOptionValue(OPTION_PORT)) : null;
+    boolean shortFormat = cli.hasOption(OPTION_SHORT);
+
+    if (port != null && solrUrl != null) {
+      CLIO.err("Please provide either --port or --solr-url, not both");

Review Comment:
   you know, other places we throw an exception instead of doing this...   and 
that percolates up and does the exit...  Something about IllegalStateException 
maybe...



##########
solr/core/src/java/org/apache/solr/cli/StatusTool.java:
##########
@@ -65,37 +74,119 @@ public String getName() {
           .desc("Wait up to the specified number of seconds to see Solr 
running.")
           .build();
 
+  public static final Option OPTION_PORT =
+      Option.builder("p")
+          .longOpt("port")
+          .argName("PORT")
+          .required(false)
+          .hasArg()
+          .desc("Port on localhost to check status for")
+          .build();
+
+  public static final Option OPTION_SHORT =
+      Option.builder()
+          .longOpt("short")
+          .argName("SHORT")
+          .required(false)
+          .desc("Short format. Prints one URL per line for running instances")
+          .build();
+
   @Override
   public List<Option> getOptions() {
-    return List.of(
-        // The solr-url option is not exposed to the end user, and is
-        // created by the bin/solr script and passed into this command 
directly,
-        // therefore we don't use the SolrCLI.OPTION_SOLRURL.
-        Option.builder()
-            .argName("URL")
-            .longOpt("solr-url")
-            .hasArg()
-            .required(false)
-            .desc("Property set by calling scripts, not meant for user 
configuration.")
-            .build(),
-        OPTION_MAXWAITSECS);
+    return List.of(OPTION_SOLRURL, OPTION_MAXWAITSECS, OPTION_PORT, 
OPTION_SHORT);
   }
 
   @Override
   public void runImpl(CommandLine cli) throws Exception {
-    // Override the default help behaviour to put out a customized message 
that only list user

Review Comment:
   and great to see all of this go away as well!



-- 
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