Forum Discussion
Vladimir_Budilo
Jan 11, 2010Nimbostratus
Hello again!
This is a sample method that returns a boolean based on a status of a pool member (it's very rough -- almost no error checking is done here, so it's not something you'd want to use in PRD, but it's just a sample I wanted to share, since I can't find many java examples on this website, especially utilizing GlobalLB):
/**
* 1. Retrieves the WideIP
* 2. Gets the WideIP's pool name (There could be
* more than one pool, but that's improbable here
* 3. Retrieves the pool
* member information for this one particular pool
* 4. Checks whether the
* pool member is enabled/disabled
*
* @param aInterfaces
* @param aWideIp
* @param aPoolMember
* @return
* @throws RemoteException
* @throws Exception
*/
public static boolean isPoolMemberEnabled(Interfaces aInterfaces,
String aWideIp, String aPoolMember) throws RemoteException,
Exception {
String poolName = null;
GlobalLBWideIPBindingStub wideIpStub = aInterfaces.getGlobalLBWideIP();
String wideIpArr[] = { aWideIp }; // Need to make this into an array
/*
* Check to see if the WideIp is enabled or disabled If the WideIp is
* disabled we can't check the status of the farm, so an exception is
* thrown.
*/
CommonEnabledState enabled[] = wideIpStub.get_enabled_state(wideIpArr);
if (!CommonEnabledState._STATE_ENABLED.equals(enabled[0].getValue())) {
throw new Exception(
"The WideIp "
+ aWideIp
+ " is not enabled. Cannot check the status of the pool members");
}
// Get an array of wide ips, specifically the one in question
GlobalLBWideIPWideIPPool wideIpPools[][] = wideIpStub
.get_wideip_pool(wideIpArr);
// Get the wideip pool object
GlobalLBWideIPWideIPPool wideIpPool = wideIpPools[0][0];
// Get the pool name in question
poolName = wideIpPool.getPool_name();
System.out.println("Pool Name: " + poolName);
String poolNameArr[] = { poolName }; // Need to make this into an array
GlobalLBPoolMemberBindingStub poolMemberStub = aInterfaces
.getGlobalLBPoolMember();
// I need to pass it in to the get_enabled_state() method
CommonIPPortDefinition testPoolMember[][] = new CommonIPPortDefinition[1][1];
CommonIPPortDefinition pMember1 = new CommonIPPortDefinition(aPoolMember, 443);
testPoolMember[0][0] = pMember1;
GlobalLBPoolMemberMemberEnabledState[][] poolMembers = poolMemberStub
.get_enabled_state(poolNameArr, testPoolMember);
CommonEnabledState state = poolMembers[0][0].getState();
System.out.println("state value: " + state.getValue());
return CommonEnabledState._STATE_ENABLED.equals(state.getValue());
}