Thursday, June 23, 2011

WebSphere Application Server 7 Federated Repository Configuration - Microsoft AD configuration

Some people are confusing how to configure the Federated Repository to Connect to Microsoft Active directory LDAP server.  IBM docs do not provide a clean configuration steps.

Here are the steps what I configured Federated Repository to connect to Microsoft Active Directory LDAP

1) Log on to Admin Console and go to Security-Global Security

2) select "Federated Repositor" from drop down list and click "Configure..." button

Global Security

3) Specify a Primary administrative user name. Note: this user name should not be same user in Microsoft AD LDAP

Primary User

4) Click "Add Base Entry to Realm..." button in this page

5) click "Add Repository" button

Add Repository

6)  enter the Repository Identifier,  host name, port, binging user, and password, Then click "Apply"

Configuration

7) click "LDAP entity types" link

LDAP Entity Type

8) then click "PersonalAccount" link, and set the Search base like "DC=mydomain,DC=com", then click "Ok"

Personal Account

9) this step is very import, find the file named wimconfig.xml at the directory <ProfileDir>/Config/cells/<NodeName>/wim/config, add the highlighted entry in the correct section

WIM Configuration

Most Microsoft active directory use sAMAccountName to authenticate the user, so we need to map sAMAccountName attribute to uid in order to search the user.

After changing the file, we need to restart the server. and then we should be able to find the active directory user from the console.

Monday, June 20, 2011

Using API to get WebSphere Application Server Information–get WAS Applications information

Using WebSphere Application Server MBean to get the application status

private void getApplicationStatus() throws MalformedObjectNameException, NullPointerException, ConnectorException, AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException{

String queryString="WebSphere:type=Application,*";
ObjectName queryAppObj=new ObjectName(queryString);
Set s=adminClient.queryNames(queryAppObj,null);
Iterator itApp=s.iterator();
while(itApp.hasNext()){
String appStr=itApp.next().toString();
int appNameidx=appStr.indexOf("name");
int appProcessidx=appStr.indexOf("process");
int startAppNameidx=appStr.indexOf("=",appNameidx);
int startAppProcessidx=appStr.indexOf("=",appProcessidx);
int endAppNameidx=appStr.indexOf(",",appNameidx);
int endAppProcessidx=appStr.indexOf(",",appProcessidx);
String appName=appStr.substring(startAppNameidx+1,endAppNameidx);
String processName=appStr.substring(startAppProcessidx+1,endAppProcessidx);

System.out.println(appName+"@"+processName+" is running");
}
}

However, the above procedure can only get the applications which are running on the server. If the application is stopped, this procedure will not get them.

The following procedure can get all applications deployed on the server. the procedure will get all WAS servers if there is a cluster in the environment.

private void  getApplicationList() throws Exception {

ArrayList appList=new ArrayList();
Hashtable props=new Hashtable();
AppManagement appM = AppManagementProxy.getJMXProxyForClient(adminClient);
ConfigService configService=new ConfigServiceProxy(adminClient);
Vector v=null;
Object[] appObj=null;
Session session=new Session();
ObjectName[] servers=configService.resolve(session,"Server");

for (ObjectName server:servers) {
String[] serverConfig=server.getKeyProperty("_Websphere_Config_Data_Id").split("/");
String serverName=server.getKeyProperty("_Websphere_Config_Data_Display_Name");
props.put(AppConstants.APPDEPL_LOCALE, Locale.getDefault());
String scope="WebSphere:cell="+serverConfig[1]+",node="+serverConfig[3]+",server="+serverName;
v=appM.listApplications(scope,props,session.getSessionId());
appObj=v.toArray();
for (Object app:appObj){
System.out.println(app.toString()+" is deployed "+serverName);
}
}
}

Tuesday, June 14, 2011

Using API to get WebSphere Application Server Information--get WAS Server information

Following the last post, after we connect to the server, we can get the server information

public static void getWASServerList() throws MalformedObjectNameException, InstanceNotFoundException, ReflectionException, ConnectorException,AttributeNotFoundException, MBeanException, ConfigServiceException{

ArrayList serverList=new ArrayList();
String queryString="WebSphere:type=Server,*";

long jvm_heapsize;
long jvm_usedmem;
long jvm_cpuusage;
ObjectName queryServerObj=new ObjectName(queryString);
Set s=adminClient.queryNames(queryServerObj,null);
Properties prop=new Properties();
Iterator itrServer=s.iterator();
ConfigService configService=new ConfigServiceProxy(adminClient);
Session session=new Session();
while (itrServer.hasNext()){
String serverStr=itrServer.next().toString();
ObjectName sobj=new ObjectName(serverStr);
List attrList=adminClient.getAttributes(sobj,new String[]{"name","serverVersion","state","processType","nodeName"});

//*********************************************************
//* this Command is used to get the server name, WAS server version, WAS server state, and server Process Type, and the node name server belongs to
//***********************************************************

String serverName=((Attribute)attrList.get(0)).getValue().toString();
String serverVersion=((Attribute)attrList.get(1)).getValue().toString();
String serverStatus=((Attribute)attrList.get(2)).getValue().toString();
String serverType=((Attribute)attrList.get(3)).getValue().toString();
String nodeName=((Attribute)attrList.get(4)).getValue().toString();


System.out.println("get Perf Information");
System.out.println("------------------");

//*************************************************
//Following codes are used to get WAS server dynamic heap size utilization information
//******************************************************

if (serverType.equals("DeploymentManager")){
jvm_heapsize=0;
jvm_usedmem=0;
jvm_cpuusage=0;
} else {
String PMIQueryString="WebSphere:type=Perf,process="+serverName+",node="+nodeName+",*";
ObjectName PMIObject=new ObjectName(PMIQueryString);
Set perf=adminClient.queryNames(PMIObject,null);
ObjectName perfObj=(ObjectName)perf.iterator().next();

String JVMQueryString="WebSphere:type=JVM,process="+serverName+",node="+nodeName+",*";
ObjectName JVMObject=new ObjectName(JVMQueryString);
Set jvm=adminClient.queryNames(JVMObject,null);
ObjectName jvmMBean=(ObjectName)jvm.iterator().next();
String[] signature = new String[] {"javax.management.ObjectName","java.lang.Boolean"};
Object[] params = new Object[] {jvmMBean, new Boolean(false)};
WSStats jvmStats = (WSStats) adminClient.invoke(perfObj, "getStatsObject", params, signature);
WSRangeStatistic jvmStatistic_Heapsize = (WSRangeStatistic)jvmStats.getStatistic(WSJVMStats.HeapSize);
WSCountStatistic jvmStatistic_UsedMem=(WSCountStatistic)jvmStats.getStatistic(WSJVMStats.UsedMemory);
WSCountStatistic jvmStatistic_CPUUsage=(WSCountStatistic)jvmStats.getStatistic(WSJVMStats.cpuUsage);

jvm_heapsize=jvmStatistic_Heapsize.getCurrent();
jvm_usedmem=jvmStatistic_UsedMem.getCount();
jvm_cpuusage=jvmStatistic_CPUUsage.getCount();
}

//*******************************************************************
//*Following codes to get the server static heap size config
//***************************************************************************

ObjectName[] servers=configService.resolve(session,"Server="+serverName);
Object attr=configService.getAttribute(session,servers[0],"processDefinitions");
int initHeapSizeidx=attr.toString().indexOf("initialHeapSize");
int maxHeapSizeidx=attr.toString().indexOf("maximumHeapSize");
int startInitHeapSizeidx=attr.toString().indexOf("=",initHeapSizeidx);
int startMaxHeapSizeidx=attr.toString().indexOf("=",maxHeapSizeidx);
int endInitHeapSizeidx=attr.toString().indexOf(",",initHeapSizeidx);
int endMaxHeapSizeidx=attr.toString().indexOf(",",maxHeapSizeidx);
String InitHeapSize=attr.toString().substring(startInitHeapSizeidx+2,endInitHeapSizeidx);
String MaxHeapSize=attr.toString().substring(startMaxHeapSizeidx+2,endMaxHeapSizeidx);


System.out.println(serverName+" "+serverStatus +" "+serverType +" "+InitHeapSize+" "+MaxHeapSize+" "+Float.toString((float)jvm_heapsize/1024)+" "+Float.toString((float)jvm_usedmem/1024)+" "+Long.toString(jvm_cpuusage));
}
}

Using API to get WebSphere Application Server Information--Connect to WebSphere Application Server

In general, we connect to WebSphere Application Server Instance using jython or jacl scripts . IBM WebSphere Application Server also provide various APIs to let the user to connect to the server instance and get the server information. The following is the code to use API to connect to WAS server application.

import com.ibm.websphere.management.AdminClient;
import com.ibm.websphere.management.AdminClientFactory;
import com.ibm.websphere.management.Session;
import com.ibm.websphere.management.configservice.ConfigService;
import com.ibm.websphere.management.configservice.ConfigServiceHelper;
import com.ibm.websphere.management.configservice.ConfigServiceProxy;
import com.ibm.websphere.management.exception.ConfigServiceException;
import com.ibm.websphere.management.exception.ConnectorException;
import com.ibm.websphere.management.exception.AdminException;
import com.ibm.websphere.management.application.*;
import com.ibm.websphere.pmi.*;
import com.ibm.websphere.pmi.stat.*;

public static void connectToServer(){

Properties props = new Properties();
props.put("type", "SOAP");
props.put("host", hostName);
props.put("port", "8880");
props.put("username", "username");
props.put("password", "password");

//***********************************************************
// if global security enabled. you need the following configurations
//***********************************************************

props.put(AdminClient.CONNECTOR_SECURITY_ENABLED, "true");
props.put("com.ibm.ssl.keyStoreFileBased", "true");
props.put("com.ibm.ssl.trustStoreFileBased", "true");
props.put("com.ibm.ssl.keyStore", keyStoreFile);
props.put("javax.net.ssl.keyStore", keyStoreFile);
props.put("com.ibm.ssl.keyStorePassword", keyPassword);
props.put("javax.net.ssl.keyStorePassword", keyPassword);
if (keyStoreFile.endsWith(".p12") || keyStoreFile.endsWith(".P12"))
{
props.put("com.ibm.ssl.keyStoreType", "PKCS12");
props.put("javax.net.ssl.keyStoreType", "PKCS12");
} else
{
props.put("com.ibm.ssl.keyStoreType", "JKS");
props.put("javax.net.ssl.keyStoreType", "JKS");
}
props.put("com.ibm.ssl.trustStore", trustStoreFile);
props.put("javax.net.ssl.trustStore", trustStoreFile);
props.put("com.ibm.ssl.trustStorePassword", trustPassword);
props.put("javax.net.ssl.trustStorePassword", trustPassword);
if (trustStoreFile.endsWith(".p12") || trustStoreFile.endsWith(".P12"))
{
props.put("com.ibm.ssl.trustStoreType", "PKCS12");
props.put("javax.net.ssl.trustStoreType", "PKCS12");
} else
{
props.put("com.ibm.ssl.trustStoreType", "JKS");
props.put("javax.net.ssl.trustStoreType", "JKS");
}
try
{
adminClient = AdminClientFactory.createAdminClient(props);
System.out.println("Connect to "+hostName+":"+portNumber+" Successfully");
}
catch (ConnectorException e)
{
System.out.println("Failed to Connect to "+hostName+":"+portNumber);
System.out.println("Exception creating admin client: " + e);
e.printStackTrace();
System.exit(-1);
}
}

it is better to use IBM WebSphere Application java  to run the application. I see some exceptions if we use SUN Java.