cancel
Showing results for 
Search instead for 
Did you mean: 

Problem this snippet solves:

This Java application allows for the graceful shutdown of a pool member. As an added bonus it also allows you to query pools, pool members, pool member status, and enable and disable the pool members.

This question comes up quite often here on DevCentral: "How can I gracefully shut down my servers for maintenance without disrupting current user sessions?". In fact, I answered this question just the other day again in the iControl forum and figured I'd throw out an application that accomplished this. So I went about writing this application to allow for the graceful shutdown of a given pool member. Of course, the application wouldn't be complete without listing the pools and members for a specified pool as well as allowing for enabling and disabling of the server so I went ahead and included those pieces as a bonus.

Code :

public class PoolMemberControl {

  public iControl.Interfaces m_interfaces = new iControl.Interfaces();
  
  public void Run(String [] args) throws Exception
  {
    if ( args.length < 3 )
    {
      usage();
    }
    else
    {
      boolean init = m_interfaces.initialize(args[0], args[1], args[2]);
      if ( init )
      {
        if ( args.length == 3)
        {
          getPoolList();
        }
        else if ( args.length == 4)
        {
          getPoolMembers(args[3]);
        }
        else if ( args.length == 5)
        {
          getPoolMemberStatus(args[3], args[4]);
        }
        else if (args.length == 6)
        {
          if ( args[5].equals("enable"))
          {
            enablePoolMember(args[3],args[4]);
          }
          else
          {
            disablePoolMember(args[3],args[4]);
          }
        }
      }
    }
  }
  
  public void getPoolList() throws Exception
  {
    String [] pool_list = m_interfaces.getLocalLBPool().get_list();
    System.out.println("Available Pools");
    for(int i=0; i 0 )
    {
      iControl.LocalLBPoolMemberMemberStatistics [] memberStatsA = 
        m_interfaces.getLocalLBPoolMember().get_statistics(pool_list, memberDefAofA);
      
      iControl.LocalLBPoolMemberMemberStatistics memberStats = memberStatsA[0];
      
      iControl.LocalLBPoolMemberMemberStatisticEntry [] statsEntryA = 
        memberStats.getStatistics();
      iControl.LocalLBPoolMemberMemberStatisticEntry  statsEntry = statsEntryA[0];
      
      iControl.CommonStatistic [] statsA = statsEntry.getStatistics();
      
      for(int i=0; i
Comments
Russ_Baker_2113
Nimbostratus
Nimbostratus
Thanks for the example, this really clears a lot up for me. However, there is a bug in the disableMember method. It is trying to query the member's status after it has disabled the memberSessionState which throws an error. I commented out that portion of the code, and it works fine.
HemanthBonthu_3
Nimbostratus
Nimbostratus

Thanks for the detail explanation

 

Version history
Last update:
‎07-Mar-2015 16:04
Updated by:
Contributors