java.lang.Object
org.glassfish.main.itest.tools.asadmin.Asadmin

public class Asadmin extends Object
Tool for executing asadmin/asadmin.bat commands. The tool is stateless.
Author:
David Matejcek
  • Constructor Details

    • Asadmin

      public Asadmin(File asadmin, String adminUser, File adminPasswordFile)
      Creates a stateless instance of the tool.
      Parameters:
      asadmin - - executable file
      adminUser - - username authorized to use the domain
      adminPasswordFile - - a file containing admin's password set as AS_ADMIN_PASSWORD=...
    • Asadmin

      public Asadmin(File asadmin, String adminUser, File adminPasswordFile, boolean terse)
      Creates a stateless instance of the tool.
      Parameters:
      asadmin - - executable file
      adminUser - - username authorized to use the domain
      adminPasswordFile - - a file containing admin's password set as AS_ADMIN_PASSWORD=...
      terse - - to produce output, minimized and suitable for parsing.
  • Method Details

    • withEnv

      public Asadmin withEnv(String name, String value)
      Adds environment property set for the asadmin execution.
      Parameters:
      name -
      value -
      Returns:
      this
    • withPassword

      public Asadmin withPassword(String name, String secretValue)
      Adds a password to the password file.
      Parameters:
      name - Name in the password file
      secretValue - Value in the password file
      Returns:
      this
    • resetPasswords

      public Asadmin resetPasswords()
      Removes all custom passwords.
      Returns:
      this
    • getCommandName

      public String getCommandName()
      Returns:
      asadmin command file name
    • getValue

      public <T> KeyAndValue<T> getValue(String key, Function<String,T> transformer)
      Gets the value for a given key from the asadmin get command.
      Type Parameters:
      T - expected result type
      Parameters:
      key - the key to get the value for
      transformer - a function to transform the string value to the expected type
      Returns:
      a single KeyAndValue instance if the key is concrete enough to get a single value,
      Throws:
      IllegalArgumentException - if the get command returns more than one value
    • get

      public <T> List<KeyAndValue<T>> get(String key, Function<String,T> transformer)
      Gets values for a given key from the asadmin get command.
      Type Parameters:
      T - expected result type
      Parameters:
      key - the key to get the values for
      transformer - a function to transform the string value to the expected type
      Returns:
      a list of KeyAndValue instances, never null, but can be empty
    • execDetached

      public DetachedTerseAsadminResult execDetached(String... args)
      Executes the command with arguments asynchronously without timeout. The command can be attached by the attach command. You should find the job id in the AsadminResult.getStdOut() as Job ID: [0-9]+
      Parameters:
      args -
      Returns:
      AsadminResult never null.
    • exec

      public AsadminResult exec(String... args)
      Executes the command with arguments synchronously without timeout.
      Parameters:
      args -
      Returns:
      AsadminResult never null.
    • exec

      public AsadminResult exec(int timeout, String... args)
      Executes the command with arguments synchronously with given timeout in millis.
      Parameters:
      timeout - timeout in millis
      args - command and arguments.
      Returns:
      AsadminResult never null.