1. How to Use Script Mode and How to Write Scripts

This section describes how to use script mode and how to write scripts.

1.1. How to Use Script Mode

Run jeusadmin by using script mode.

  • Example

    The following is an example of jeusadmin script mode which runs the test.py script with the assumption that the JEUS user name is 'administrator' and the password is 'jeus'.

    JEUS_HOME/bin$jeusadmin -u administrator -p jeus -script "test.py"
    Attempting to connect to 127.0.0.1:9736.
    The connection has been established to JEUS Master Server [adminServer] in the domain [domain1].
    JEUS 9 Administration Tool
    To view help, use the 'help' command.

    When using the script mode, you can use an additional option that ignores JEUS command exceptions. The -i or -ignore option allows the script to continue running even if a JEUS command error occurs.

    [-i, --ignore] option can be used only in the script mode.

    JEUS_HOME/bin$jeusadmin -u administrator -p jeus -script "test.py" -i
    JEUS_HOME/bin$jeusadmin -u administrator -p jeus -script "test.py" --ignore

    Arguments can be given to a script as shown below.

    JEUS_HOME/bin$jeusadmin -u administrator -p jeus -script "test.py arg1 arg2"

1.2. How to Write Scripts

jeusadmin provides the results data and methods for executing commands when it is executed in script mode.

  • Executing a command

    Commands can be executed for each script language as shown below.

    • Python and Ruby

      result = command("server-info")
    • Ruby

      result = command "server-info"

      The verbose option can be executed with a JEUS command. By default, this option is deactivated (set to 'false'). If the verbose option is enabled (set to 'true') with a JEUS command, the result of the command execution is displayed in detail.

    • Python:

      result = command("server-info", [True | False])
    • Ruby:

      result = command "server-info", [true | false]
  • Results data

    The JeusResult object is returned from executing a JEUS command. If the returned results include results in the table format, then the JeusTabularData object can be obtained from JeusResult.

    • JeusResult

      Method Description

      isComplete()

      Returns whether a JEUS command has been successfully executed.

      getMessage()

      Returns a results message.

      getData()

      Returns the list of JeusTabularData which is the table data of results.

    • JeusTabularData

      Method Description

      getTitle()

      Returns the title of a table.

      getHeader()

      Returns the header of a table.

      getFooter()

      Returns the footer of a table.

      getColumnNames()

      Returns only the title of each column in a table in list format.

      getRows()

      Returns the list of each column of table data.

  • Example

    • Searches and displays the servers in SHUTDOWN status.

      result = command("server-info")
      tables = result.getData();
      table = tables[0];
      rows = table.getRows();
      shutdown_servers = []
      for row in rows:
          if "SHUTDOWN" in row[1]:
              shutdown_servers.append(row[0])
              print("Server : %s, Node : %s" % (row[0], row[2]))
    • Use the script argument to receive the application path and the list of servers to be deployed, and then install and deploy applications.

      import time
      import sys
      import os
      
      path = sys.argv[0]
      servers = sys.argv[1]
      direc, app = os.path.split(path)
      apptype = os.path.splitext(app)[1][1:].upper()
      
      command("undeploy -f %s " % app)
      command("uninstall-application %s" % app)
      command("install-application %s -id %s" % (path, app))
      command("deploy %s -servers %s -type %s" % (app, servers, apptype))

Currently, jeusadmin provides script mode only for two script languages, Python and Ruby, and they are separated with an extension. Only scripts with .py and .rb extensions are recognized and executed.