mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

jvergara
23.56.2007 fd724f1439c50c1d9dcf076d42c1bff6de2482d3
Fix for issue 2494.

Add a scriptFriendly option so that the output of the status panel is easier to parse.
2 files modified
146 ■■■■ changed files
opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java 124 ●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/statuspanel/StatusCliArgumentParser.java 22 ●●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java
@@ -578,43 +578,61 @@
        INFO_JAVA_VERSION_LABEL.get()
      };
    int labelWidth = 0;
    for (int i=0; i<labels.length; i++)
    {
      labelWidth = Math.max(labelWidth, labels[i].length());
    }
    out.println();
    Message title = INFO_SERVER_STATUS_TITLE.get();
    out.println(centerTitle(title));
    if (!isScriptFriendly())
    {
      for (int i=0; i<labels.length; i++)
      {
        labelWidth = Math.max(labelWidth, labels[i].length());
      }
      out.println();
      out.println(centerTitle(title));
    }
    writeStatusContents(desc, labelWidth);
    writeCurrentConnectionContents(desc, labelWidth);
    out.println();
    if (!isScriptFriendly())
    {
      out.println();
    }
    title = INFO_SERVER_DETAILS_TITLE.get();
    out.println(centerTitle(title));
    if (!isScriptFriendly())
    {
      out.println(centerTitle(title));
    }
    writeHostnameContents(desc, labelWidth);
    writeAdministrativeUserContents(desc, labelWidth);
    writeInstallPathContents(desc, labelWidth);
    writeVersionContents(desc, labelWidth);
    writeJavaVersionContents(desc, labelWidth);
    out.println();
    if (!isScriptFriendly())
    {
      out.println();
    }
    writeListenerContents(desc);
    out.println();
    if (!isScriptFriendly())
    {
      out.println();
    }
    writeDatabaseContents(desc);
    writeErrorContents(desc);
    if (displayMustStartLegend)
    if (!isScriptFriendly())
    {
      out.println();
      out.println(wrap(INFO_NOT_AVAILABLE_SERVER_DOWN_CLI_LEGEND.get()));
    }
    else if (displayMustAuthenticateLegend)
    {
      out.println();
      out.println(
          wrap(INFO_NOT_AVAILABLE_AUTHENTICATION_REQUIRED_CLI_LEGEND.get()));
      if (displayMustStartLegend)
      {
        out.println();
        out.println(wrap(INFO_NOT_AVAILABLE_SERVER_DOWN_CLI_LEGEND.get()));
      }
      else if (displayMustAuthenticateLegend)
      {
        out.println();
        out.println(
            wrap(INFO_NOT_AVAILABLE_AUTHENTICATION_REQUIRED_CLI_LEGEND.get()));
      }
    }
    out.println();
  }
@@ -830,8 +848,11 @@
   */
  private void writeListenerContents(ServerStatusDescriptor desc)
  {
    Message title = INFO_LISTENERS_TITLE.get();
    out.println(centerTitle(title));
    if (!isScriptFriendly())
    {
      Message title = INFO_LISTENERS_TITLE.get();
      out.println(centerTitle(title));
    }
    Set<ListenerDescriptor> allListeners = desc.getListeners();
@@ -879,7 +900,10 @@
  private void writeDatabaseContents(ServerStatusDescriptor desc)
  {
    Message title = INFO_DATABASES_TITLE.get();
    out.println(centerTitle(title));
    if (!isScriptFriendly())
    {
      out.println(centerTitle(title));
    }
    Set<DatabaseDescriptor> databases = desc.getDatabases();
@@ -1039,19 +1063,30 @@
        headerLine.append(" ");
      }
    }
    out.println(wrap(headerLine.toMessage()));
    MessageBuilder t = new MessageBuilder();
    for (int i=0; i<headerLine.length(); i++)
    if (!isScriptFriendly())
    {
      t.append("=");
      out.println(wrap(headerLine.toMessage()));
      MessageBuilder t = new MessageBuilder();
      for (int i=0; i<headerLine.length(); i++)
      {
        t.append("=");
      }
      out.println(wrap(t.toMessage()));
    }
    out.println(wrap(t.toMessage()));
    for (int i=0; i<tableModel.getRowCount(); i++)
    {
      if (isScriptFriendly())
      {
        out.println("-");
      }
      MessageBuilder line = new MessageBuilder();
      for (int j=0; j<tableModel.getColumnCount(); j++)
      {
        if (isScriptFriendly())
        {
          line.append(tableModel.getColumnName(j)+": ");
        }
        int extra = maxWidths[j];
        Object v = tableModel.getValueAt(i, j);
        if (v != null)
@@ -1085,14 +1120,24 @@
          {
            throw new IllegalStateException("Unknown object type: "+v);
          }
          if (isScriptFriendly())
          {
            out.println(wrap(line.toMessage()));
            line = new MessageBuilder();
          }
        }
        for (int k=0; k<extra; k++)
        if (!isScriptFriendly())
        {
          line.append(" ");
          for (int k=0; k<extra; k++)
          {
            line.append(" ");
          }
        }
      }
      out.println(wrap(line.toMessage()));
      if (!isScriptFriendly())
      {
        out.println(wrap(line.toMessage()));
      }
    }
  }
@@ -1128,7 +1173,11 @@
    Message replicatedLabel = INFO_BASEDN_REPLICATED_LABEL.get();
    for (int i=0; i<tableModel.getRowCount(); i++)
    {
      if (i > 0)
      if (isScriptFriendly())
      {
        out.println("-");
      }
      else if (i > 0)
      {
        out.println();
      }
@@ -1254,4 +1303,15 @@
  {
    return argParser.getTrustManager();
  }
  /**
   * Tells whether the user specified to have a script-friendly output or not.
   * This method must be called after calling parseArguments.
   * @return <CODE>true</CODE> if the user specified to have a script-friendly
   * output and <CODE>false</CODE> otherwise.
   */
  private boolean isScriptFriendly()
  {
    return argParser.isScriptFriendly();
  }
}
opends/src/guitools/org/opends/guitools/statuspanel/StatusCliArgumentParser.java
@@ -49,6 +49,11 @@
  private BooleanArgument noPromptArg;
  /**
   * The 'scriptFriendly' argument.
   */
  private BooleanArgument scriptFriendlyArg;
  /**
   * Creates a new instance of this argument parser with no arguments.
   *
   * @param mainClassName
@@ -86,6 +91,12 @@
        ToolConstants.OPTION_LONG_NO_PROMPT,
        INFO_DESCRIPTION_NO_PROMPT.get());
    defaultArgs.add(0, noPromptArg);
    scriptFriendlyArg = new BooleanArgument(
        "script-friendly",
        's',
        "script-friendly",
        INFO_DESCRIPTION_SCRIPT_FRIENDLY.get());
    defaultArgs.add(1, scriptFriendlyArg);
    initializeGlobalArguments(defaultArgs);
  }
@@ -101,6 +112,17 @@
  }
  /**
   * Tells whether the user specified to have a script-friendly output or not.
   * This method must be called after calling parseArguments.
   * @return <CODE>true</CODE> if the user specified to have a script-friendly
   * output and <CODE>false</CODE> otherwise.
   */
  public boolean isScriptFriendly()
  {
    return scriptFriendlyArg.isPresent();
  }
  /**
   * Returns the first server bind dn explicitly provided in the enable
   * replication subcommand.
   * @return the first server bind dn explicitly provided in the enable