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);
mySID.setWidth("300");
Group host = new Group();
host.setTitle("Host: "+me);
host.setWidth("300");
mySID.addComponent(host);
Group myGroup = new Group();
host.addComponent(myGroup);
myGroup.setWidth("350");
myGroup.setTitle("Instance number: "+num);
myGroup.setDesign(GroupDesign.SAPCOLOR);
myForm.addComponent(mySID);
GridLayout gl = new GridLayout();
myGroup.addComponent(gl);
int row = 1;
InputField ifHere = new InputField("here");
ifHere.setString("You are here");
ifHere.setTooltip("standort");
ifHere.setEnabled(false);
InputField ifServer = new InputField("server");
ifServer.setString(dir);
ifServer.setEnabled(false);
Label label = new Label("Server number");
ifServer.setLabel(label);
gl.addComponent(row, 1, label);
gl.addComponent(row, 2, ifServer);
gl.addComponent(row, 3, ifHere);
row++;
InputField ifNode = new InputField("node");
ifNode.setString(node);
ifNode.setEnabled(false);
label = new Label("Node number");
ifNode.setLabel(label);
gl.addComponent(row, 1, label);
gl.addComponent(row, 2, ifNode);
gl.addComponent(row, 3, ifHere);
myContext.render();
When run, it should look similar to:
