<< Click here to Goto HomePage


Tuesday, September 05, 2006

Which SAP Enterprise Portal server node am I running on?

It is often useful to be able to work out which server node of your SAP NetWeaver Enterprise Portal cluster you are connected to. For example, if you have an SAP NetWeaver Portal with a SID of ABC, consisting of two dispatchers (central instance 12 and dialog instance 13) each with two server nodes, you could be connected to instance 12 server0 or instance 12 server1 or instance 13 server0 or instance server1. If you are having some problems, the support people in your organization will need to know which server node to start looking at.

This blog entry will describe a code fragment that can be used in a portal component to present details of the current server node that you are connected to.

The good news is that most of the values we need to display are available as System properties, and so can be accessed via:

String SID = System.getProperty("SAPSYSTEMNAME").toString();
String num = System.getProperty("SAPSYSTEM").toString();
String dir = System.getProperty("user.dir").toString();
String sep = System.getProperty("file.separator").toString();
dir = dir.substring(1+dir.lastIndexOf(sep));
String me = System.getProperty("SAPMYNAME").toString();
me = me.substring(0,me.indexOf("_"));

We use the file.system property to work out if we are on a Windows or Unix type system, and then use that to skip to the last part of the user.dir property, whcih shows us if we are on server0, server1 etc...

To get our node number is a bit more complicated, and requires we find a property created as part of the use of DSR (Distributed Statistics Records). The property name contains the node ID, so we get a list of all the properties and run through the list finding a name that matches that node name...

Here's the code...

String node = "";
Enumeration props = System.getProperties().keys();
while (props.hasMoreElements())

String thisProp = props.nextElement().toString();
if (thisProp.startsWith("dsr."+me+"_") && thisProp.endsWith(".buffersize"))
node = thisProp.substring(5+thisProp.indexOf("_"+SID+"_"),thisProp.lastIndexOf("_"));

Now we need to present the details - I'll use some HTMLB structures, so remember to include an appropriate ServicesReference definition in portalapp.xml...

IPageContext myContext;
myContext = PageContextFactory.createPageContext(request, response);
Form myForm =myContext.createFormDocument("Where am I running?");

Group mySID = new Group();
mySID.setTitle("SID: "+SID);

Group host = new Group();
host.setTitle("Host: "+me);

Group myGroup = new Group();
myGroup.setTitle("Instance number: "+num);


GridLayout gl = new GridLayout();
int row = 1;

InputField ifHere = new InputField("here");
ifHere.setString("You are here");
InputField ifServer = new InputField("server");

Label label = new Label("Server number");
gl.addComponent(row, 1, label);
gl.addComponent(row, 2, ifServer);
gl.addComponent(row, 3, ifHere);

InputField ifNode = new InputField("node");
label = new Label("Node number");
gl.addComponent(row, 1, label);
gl.addComponent(row, 2, ifNode);
gl.addComponent(row, 3, ifHere);


When run, it should look similar to:


  1. Anonymous said,

    good blog....

    u can also get node information from html cookie...

    javascript: alert(document.cookie);

    on 2/04/2008 4:47 PM