List Servers and Domains

/* Example Program : 

	 Obtain lists of servers and domains for each AADS specified on the command line.

     Compile: javac -classpath sconfig.jar;jaas.jar;wcp.jar ListServersAndDomains.java

     Run: java -classpath sconfig.jar;jaas.jar;wcp.jar ListServersAndDomains <AADS1> ;[AADS2] ... [AADSn]

	 Before running this program, run the 'ObtainAADSCertificates' program to obtain certificates
       for the AADS servers of interest.
*/
import java.util.*;
import com.wrq.vhi.sconfig.*;

class ListServersAndDomains
{
	public static final String CERTFILE = "certificates.aads";
	public static final String DIVIDER = "========================================";

	/* List the servers and domains registered with an AADS server. */
	static void displayList(String AADSName)
	{
		List srvrs, doms;

		System.out.println( DIVIDER );
		System.out.println("AADS: " + AADSName);

		try {
			IAADSConnection aadsConn = ServerConfig.newAADSConnection(AADSName);
			IAADSConfiguration aadsConf = ServerConfig.newAADSConfiguration(aadsConn);

			/* Obtain a list of all servers registered with AADS. */
			srvrs = aadsConf.getServerNames();
			System.out.println( DIVIDER );
			System.out.println( "List of all servers: (" + srvrs.size() + ")");
		
			for(Iterator it2=srvrs.iterator(); it2.hasNext(); ) {
				ServerListItem si = (ServerListItem)it2.next();
				System.out.println( "   \"" + si.getName() + "\" " + (si.running() ? "Running" : "Not Running"));
			}


			/* Obtain a list of domains registered with AADS */
			doms = aadsConf.getDomainNames();
			System.out.println( DIVIDER );
			System.out.println( "List of all domains: (" + doms.size() + ")");

			for(Iterator it2=doms.iterator(); it2.hasNext(); ) {
				String domainName = (String)it2.next();
				System.out.println( "   \"" + domainName + "\"");
				
				/* Obtain a list of the servers within each domain. */
				srvrs = aadsConf.getServerNamesInDomain(domainName);
				for(Iterator i2=srvrs.iterator(); i2.hasNext(); ) {
					ServerListItem si = (ServerListItem)i2.next();
					System.out.println( "      \"" + si.getName() + "\" " + (si.running() ? "Running" : "Not Running"));
				}
			}
			System.out.println( DIVIDER );
		}
		catch(Exception e) {
			System.err.println("Exception caught: " + e);
		}
	}

	static public void main(String [] args)
	{
		SCCertificate scc;
		IAADSConnection aadsConn = ServerConfig.newAADSConnection();

		if(args.length == 0) {
			System.out.println("Usage: ListServersAndDomains <AADS1> ;[AADS2] ... [AADSn]");
			return;
		}
		try {
			System.out.println("Attempting to load keystore file \"" + CERTFILE + "\"");
			aadsConn.loadKeystore( CERTFILE );
		}
		catch(Exception e) {
			System.err.println("Error loading keystore file: " + e);
		}

		/* Display the servers and/or domains for each AADS specified on the command line. */
 		for(int i=0; i<args.length; i++) {
 			displayList(args[i]);
		}
	}
}






 

 

  Attachmate