Search code examples
websphere

com.ibm.websphere.runtime.servername.getDisplayName() is None


As suggested in the below linked question.... Getting instance name of a WebSphere app Server

I am calling ServerName.getDisplayName() in an existing python file but i get None as the result. Basically I want the above displayname to set as "Generic JVM arguments" in websphere console. The pyton script runs fine through our ant target, and I can see the one of the jvm args set as None in websphere console.

Any ideas why I am getting None? The websphere console is showing server name as "server1", so I expect ServerName.getDisplayName() should return that.

=================================== Response to covener:

file1.py is called from an ant target. Please see attachment for the result.

file1.py start---------------------------------------

import file2

file2.configSystemProperties()
file2.saveConfiguration()

end---------------------------------------

file2.py start---------------------------------------

from com.ibm.websphere.runtime import *

import websphere
.....
def configSystemProperties():
    websphere.setGenericJvmArguments("-Dtangosol.coherence.override=coherence.xml -DlogsDirName=" + str(ServerName.getDisplayName()));
.....

def saveConfiguration() :
    websphere.save()

end---------------------------------------

websphere.py file start---------------------------------------

....
AdminConfig      = AdminConfigClient.getInstance();
....
def setGenericJvmArguments(genericJvmArguments):
    print "JVM generic arguments " + str(genericJvmArguments);
    AdminConfig.modify(jvm, [
        ["genericJvmArguments", genericJvmArguments]
    ])

def save() :
    logMajor("Saving...")
    AdminConfig.save()
    logMajor("Save complete.")

....

end---------------------------------------

Result: screenshot of websphere console showing None


Solution

  • It seems to me that you can't call the static method Server.getDisplayName() if your code isn't running in an application server process. This is not really a wsadmin / scripting library API

    Instead, you need to lookup the server with the Admin APIs.

    https://www.ibm.com/support/knowledgecenter/SSAW57_8.5.5/com.ibm.websphere.nd.doc/ae/txml_listrunapp.html