webspherejythonwsadmin

How do you automate setting the preferred coordinator servers in Websphere Application Server using Jython scripts?


We are trying to automate the "Preferred Coordinator of Servers" JVM list using Jython code and running it with the wsadmin utility. The manual method is to login to the Admin Console and select Servers > Core Groups > Coure group settings > DefaultCoreGroup > Preferred Coordinator Servers

We have automated most of the Websphere Application Server build by doing the changes in the Admin Console and using the "Command Assistance" link that shows the Jython code to use. This task does not have that feature.

The code looks something like the following: AdminTask.listChains('(cells/wamt13Cell01/nodes/wamt13CellManager01/servers/dmgr|server.xml#TransportChannelService_1)', '[-acceptorFilter DCSInboundChannel]')

When completed we expect to have JVMs set for the Preferred Coordinator Servers box.


Solution

  • Use the below code snippet for configuring "Preferred coordinator servers" for a coregroup

    Update variables "coreGroupPrefServer" & "coreGroupName", before running the script to update the preferred server name and core group name respectively, based on your environment configuration.

    #User Input: Define preferred server name below
    coreGroupPrefServer='server1'
    
    
    #Get config id of the preferred coreGroup Server
    coreGroupPrefServerId=AdminConfig.getid('/CoreGroupServer:%s' %coreGroupPrefServer)
    
    #Define coreGroupName below, default is 'DefaultCoreGroup'
    coreGroupName='DefaultCoreGroup'
    
    #Get config id for the coreGroup defined above
    coreGroupId=AdminConfig.getid('/CoreGroup:%s' %coreGroupName)
    
    
    #Remove preferredCoordinatorServers if any already configured
    AdminConfig.unsetAttributes(coreGroupId, '[preferredCoordinatorServers]')
    
    #Set the user provided coreGroupPrefServer as the preferredCoordinatorServer for the coreGroup
    AdminConfig.modify(coreGroupId, '[[preferredCoordinatorServers %s]]' %coreGroupPrefServerId)
    
    #Save the changes
    AdminConfig.save()