Configuring database session persistence using scripting

You can use scripting and the wsadmin tool to configure database persistence.

Before you begin

Before starting this task, the wsadmin tool must be running. See the Starting the wsadmin scripting client using wsadmin scripting topic for more information.

About this task

Perform the following steps to configure database persistence. Within these steps, the following variables apply to the Jython and Jacl commands:
  • node_name is the affected node within your configuration.
  • server_name is the affected server within your configuration.
  • cell_name is the affected cell within your configuration.
  • db2_administrator is the ID for the database administrator.
  • db2_password is the password for the ID that is associated with the database administrator.

Procedure

  1. Retrieve the configuration ID of the server to enable database persistence and store its values in the server variable.
    • Using Jacl:

      set server [$AdminConfig getid /Node:node_name/Server:server_name/]
      Example output:
      server_name(cells/cell_name/nodes/node_name/servers/server_name
      |server.xml#Server_1265038035855)
    • Using Jython:
      server = AdminConfig.getid('/Node:node_name/Server:server_name/')

      Example output: None

  2. Retrieve the name of the session manager, which is associated with the server values in the previous step, and assign the session manager to the sm variable.
    • Using Jacl:

      set sm [$AdminConfig list SessionManager $server]
      Example output:
      (cells/cell_name/nodes/node_name/servers/server_name
      |server.xml#SessionManager_1256932276179)
    • Using Jython:
      sm = AdminConfig.list('SessionManager', server)

      Example output: None

  3. Add the database session persistence mode value to the sm variable, which already contains the session manager value from the previous steps.
    • Using Jacl:

      $AdminConfig modify $sm {{sessionPersistenceMode "DATABASE"}}

      Example output: None

    • Using Jython:
      AdminConfig.modify(sm,'[[sessionPersistenceMode "DATABASE"]]')

      Example output: None

  4. Retrieve the database session persistence value for the session manager and the database session persistence mode that are set to the sm variable. Set this value to the sesdb variable.
    • Using Jacl:

      set sesdb [$AdminConfig list SessionDatabasePersistence $sm]
      Example output:
      (cells/cell_name/nodes/node_name/servers/server_name
      |server.xml#SessionDatabasePersistence_1256932276179)
    • Using Jython:
      sesdb = AdminConfig.list('SessionDatabasePersistence',sm)

      Example output: None

  5. Modify the sesdb variable to include the user ID and password to access the database and the table space name; and the Java™ naming and directory interface (JNDI) name.
    • Using Jacl:

      $AdminConfig modify $sesdb { {userId "db2_administrator"} {password "db2_password"}
       {tableSpaceName ""} {datasourceJNDIName "jdbc/SessionDataSource"} }

      Example output: None

    • Using Jython:
      AdminConfig.modify(sesdb,'[[userId "db2_administrator"] [password "db2_password"] 
      [tableSpaceName ""] [datasourceJNDIName "jdbc/SessionDataSource"]]')

      Example output: None

  6. Save the configuration changes. For more information, see the documentation on saving configuration changes with the wsadmin tool.