From: <btm...@us...> - 2010-12-06 22:09:50
|
Revision: 3997 http://bigdata.svn.sourceforge.net/bigdata/?rev=3997&view=rev Author: btmurphy Date: 2010-12-06 22:09:42 +0000 (Mon, 06 Dec 2010) Log Message: ----------- [branch dev-btm]: CHECKPOINT - changes to allow smart proxy wrapper for zookeeper to be started by ServicesManagerService; also changes to allow TestServiceStarter test to start smart proxy zookeeper [more fixes to junit tests needed] Modified Paths: -------------- branches/dev-btm/bigdata-jini/src/java/com/bigdata/jini/start/ServicesManagerStartupTask.java branches/dev-btm/bigdata-jini/src/java/com/bigdata/jini/start/config/ServicesManagerConfiguration.java branches/dev-btm/bigdata-jini/src/java/com/bigdata/jini/start/config/ZookeeperServerConfiguration.java branches/dev-btm/bigdata-jini/src/java/com/bigdata/jini/start/process/ZookeeperProcessHelper.java branches/dev-btm/bigdata-jini/src/java/com/bigdata/quorum/ServiceImpl.java branches/dev-btm/bigdata-jini/src/java/com/bigdata/service/jini/util/JiniServicesHelper.java branches/dev-btm/bigdata-jini/src/test/com/bigdata/jini/start/AbstractFedZooTestCase.java branches/dev-btm/bigdata-jini/src/test/com/bigdata/jini/start/TestServiceStarter.java branches/dev-btm/bigdata-jini/src/test/com/bigdata/zookeeper/AbstractZooTestCase.java branches/dev-btm/src/resources/config/bigdataCluster.config Modified: branches/dev-btm/bigdata-jini/src/java/com/bigdata/jini/start/ServicesManagerStartupTask.java =================================================================== --- branches/dev-btm/bigdata-jini/src/java/com/bigdata/jini/start/ServicesManagerStartupTask.java 2010-12-06 21:29:19 UTC (rev 3996) +++ branches/dev-btm/bigdata-jini/src/java/com/bigdata/jini/start/ServicesManagerStartupTask.java 2010-12-06 22:09:42 UTC (rev 3997) @@ -141,7 +141,12 @@ if (serviceConfig instanceof ZookeeperServerConfiguration) { System.out.println("\n---- ServicesManagerStartupTask.doStartup: startZookeeperService() ----"); - startZookeeperService(config); +//BTM - PRE_ZOOKEEPER_SMART_PROXY - BEGIN +//BTM - PRE_ZOOKEEPER_SMART_PROXY startZookeeperService(config); + startZookeeperService + ( ((ZookeeperServerConfiguration)serviceConfig).classType, + config ); +//BTM - PRE_ZOOKEEPER_SMART_PROXY - END } @@ -227,23 +232,38 @@ * * @return <code>true</code> if an instance was started successfully. */ - protected boolean startZookeeperService(final Configuration config) - throws ConfigurationException, IOException { - +//BTM - PRE_ZOOKEEPER_SMART_PROXY - BEGIN +//BTM - PRE_ZOOKEEPER_SMART_PROXY protected boolean startZookeeperService(final Configuration config) +//BTM - PRE_ZOOKEEPER_SMART_PROXY throws ConfigurationException, IOException { +//BTM - PRE_ZOOKEEPER_SMART_PROXY +//BTM - PRE_ZOOKEEPER_SMART_PROXY try { +//BTM - PRE_ZOOKEEPER_SMART_PROXY +//BTM - PRE_ZOOKEEPER_SMART_PROXY return ZookeeperProcessHelper.startZookeeper(config, service) > 0; +//BTM - PRE_ZOOKEEPER_SMART_PROXY +//BTM - PRE_ZOOKEEPER_SMART_PROXY } catch (Throwable t) { +//BTM - PRE_ZOOKEEPER_SMART_PROXY +//BTM - PRE_ZOOKEEPER_SMART_PROXY log.error( +//BTM - PRE_ZOOKEEPER_SMART_PROXY "Could not start zookeeper service: " + t, t); +//BTM - PRE_ZOOKEEPER_SMART_PROXY +//BTM - PRE_ZOOKEEPER_SMART_PROXY return false; +//BTM - PRE_ZOOKEEPER_SMART_PROXY +//BTM - PRE_ZOOKEEPER_SMART_PROXY } +//BTM - PRE_ZOOKEEPER_SMART_PROXY +//BTM - PRE_ZOOKEEPER_SMART_PROXY } +//BTM - PRE_ZOOKEEPER_SMART_PROXY + protected boolean startZookeeperService + (Class classType, Configuration config) + throws ConfigurationException, IOException + { try { - - return ZookeeperProcessHelper.startZookeeper(config, service) > 0; - + return ZookeeperProcessHelper.startZookeeper + (classType, config, service) > 0; } catch (Throwable t) { - - log.error( - "Could not start zookeeper service: " + t, t); - + log.error("Could not start zookeeper service: " + t, t); return false; - } - } +//BTM - PRE_ZOOKEEPER_SMART_PROXY - END /** * If necessary, start the jini core services on this host. Modified: branches/dev-btm/bigdata-jini/src/java/com/bigdata/jini/start/config/ServicesManagerConfiguration.java =================================================================== --- branches/dev-btm/bigdata-jini/src/java/com/bigdata/jini/start/config/ServicesManagerConfiguration.java 2010-12-06 21:29:19 UTC (rev 3996) +++ branches/dev-btm/bigdata-jini/src/java/com/bigdata/jini/start/config/ServicesManagerConfiguration.java 2010-12-06 22:09:42 UTC (rev 3997) @@ -225,7 +225,7 @@ } else if (a.equals(QuorumPeerMain.class.getName())) { System.out.println("\n*** ServicesManagerConfiguration.getConfigurations: QuorumPeerMain BEGIN"); - v.add(new ZookeeperServerConfiguration(config)); + v.add(new ZookeeperServerConfiguration(QuorumPeerMain.class, config)); System.out.println("*** ServicesManagerConfiguration.getConfigurations: QuorumPeerMain END\n"); } else if (a.equals(TransactionServer.class.getName())) { @@ -261,6 +261,12 @@ //BTM - BEGIN: smart proxy impls ------------------------------------------------------------ + } else if (a.equals(com.bigdata.quorum.ServiceImpl.class.getName())) { + +System.out.println("\n*** ServicesManagerConfiguration.getConfigurations: com.bigdata.quorum.ServiceImpl BEGIN"); + v.add(new ZookeeperServerConfiguration(com.bigdata.quorum.ServiceImpl.class, config)); +System.out.println("*** ServicesManagerConfiguration.getConfigurations: com.bigdata.quorum.ServiceImpl END\n"); + } else if (a.equals(com.bigdata.transaction.ServiceImpl.class.getName())) {//transaction service System.out.println("\n*** ServicesManagerConfiguration.getConfigurations: com.bigdata.transaction.ServiceImpl BEGIN"); Modified: branches/dev-btm/bigdata-jini/src/java/com/bigdata/jini/start/config/ZookeeperServerConfiguration.java =================================================================== --- branches/dev-btm/bigdata-jini/src/java/com/bigdata/jini/start/config/ZookeeperServerConfiguration.java 2010-12-06 21:29:19 UTC (rev 3996) +++ branches/dev-btm/bigdata-jini/src/java/com/bigdata/jini/start/config/ZookeeperServerConfiguration.java 2010-12-06 22:09:42 UTC (rev 3997) @@ -257,15 +257,32 @@ } +//BTM - PRE_ZOOKEEPER_SMART_PROXY - BEGIN + public Class classType; + private Configuration jiniConfig; +//BTM - PRE_ZOOKEEPER_SMART_PROXY - END + /** * @param className * @param config * @throws ConfigurationException */ - public ZookeeperServerConfiguration(final Configuration config) - throws ConfigurationException { +//BTM - PRE_ZOOKEEPER_SMART_PROXY - BEGIN +//BTM - PRE_ZOOKEEPER_SMART_PROXY public ZookeeperServerConfiguration(final Configuration config) +//BTM - PRE_ZOOKEEPER_SMART_PROXY throws ConfigurationException { +//BTM - PRE_ZOOKEEPER_SMART_PROXY +//BTM - PRE_ZOOKEEPER_SMART_PROXY super(QuorumPeerMain.class.getName(), config); + public ZookeeperServerConfiguration(Class classType, + Configuration config) + throws ConfigurationException + { - super(QuorumPeerMain.class.getName(), config); + super(classType.getName(), config); + this.classType = classType; + this.jiniConfig = config; +//BTM - PRE_ZOOKEEPER_SMART_PROXY - END +//BTM +System.out.println("*** ZookeeperServerConfiguration: constructor ***"); servers = (String) config.getEntry(Options.NAMESPACE, Options.SERVERS, String.class); @@ -455,6 +472,7 @@ public ZookeeperServiceStarter newServiceStarter(IServiceListener listener, ZookeeperServerEntry entry) { +System.out.println("*** ZookeeperServerConfiguration ---> newServiceStarter ***"); return new ZookeeperServiceStarter(listener, entry); } @@ -511,6 +529,7 @@ ZookeeperServerEntry entry) { super(listener); +System.out.println("*** ZookeeperServerConfiguration.ZookeeperServiceStarter: constructor - BEGIN ***"); if (entry == null) throw new IllegalArgumentException(); @@ -524,6 +543,7 @@ */ dataDir = new File(ZookeeperServerConfiguration.this.dataDir, Integer.toString(entry.id)).getAbsoluteFile(); +System.out.println("*** ZookeeperServerConfiguration.ZookeeperServiceStarter: dataDir = "+dataDir); if (log.isInfoEnabled()) log.info(Options.DATA_DIR + "=" + dataDir); @@ -536,6 +556,7 @@ */ dataLogDir = new File(ZookeeperServerConfiguration.this.dataLogDir, Integer.toString(entry.id)).getAbsoluteFile(); +System.out.println("*** ZookeeperServerConfiguration.ZookeeperServiceStarter: dataLogDir = "+dataLogDir); if (log.isInfoEnabled()) log.info(Options.DATA_LOG_DIR + "=" + dataLogDir); @@ -544,9 +565,12 @@ configFile = new File(dataDir, ZookeeperServerConfiguration.this.configFile) .getAbsoluteFile(); +System.out.println("*** ZookeeperServerConfiguration.ZookeeperServiceStarter: generated configFile = "+configFile); // the server id is written on this file. myidFile = new File(dataDir, "myid"); +System.out.println("*** ZookeeperServerConfiguration.ZookeeperServiceStarter: myidFile = "+myidFile); +System.out.println("*** ZookeeperServerConfiguration.ZookeeperServiceStarter: constructor - END ***"); } @@ -618,7 +642,14 @@ /* * Write the zookeeper server configuration file. */ - writeZookeeperConfigFile(); +//BTM - PRE_ZOOKEEPER_SMART_PROXY - BEGIN +//BTM - PRE_ZOOKEEPER_SMART_PROXY writeZookeeperConfigFile(); + if ( (Options.NAMESPACE).equals(classType.getName()) ) { + writeZookeeperConfigFile(); + } else { + writeConfigFile();// Jini config file + } +//BTM - PRE_ZOOKEEPER_SMART_PROXY - END /* * Start the server. @@ -682,7 +713,9 @@ // the configuration file. cmds.add(configFile.toString()); - +//BTM - FOR_ZOOKEEPER_SMART_PROXY - BEGIN + cmds.add("com.bigdata.quorum."+getGroups("groupsToJoin")); +//BTM - FOR_ZOOKEEPER_SMART_PROXY - END } @Override @@ -859,6 +892,113 @@ } +//BTM - FOR_ZOOKEEPER_SMART_PROXY - BEGIN ------------------------------------ + protected void writeConfigFile() throws IOException { + + // 1. generate the contents to be written to the file + final String contents; + { + final StringWriter out = new StringWriter(); + writeConfigFile(out); + out.flush(); + contents = out.toString(); + } + + // 2. write the contents generated above to the file. + { + final Writer out2 = + new OutputStreamWriter + (new BufferedOutputStream + (new FileOutputStream(configFile))); + try { + out2.write(contents); + out2.flush(); + } finally { + out2.close(); + } + } + } + + protected void writeConfigFile(final Writer out) throws IOException { + // 1. Comments + writeComments(out); + out.write("\n"); + + // 2. import statements + for (String i : getImports()) {// write import statements + out.write("import " + i + ";\n"); + } + out.write("\n"); + + // 3. Open component name + out.write("\n\n" + classType.getPackage().getName() + " {\n"); + { + out.write(" "+Options.DATA_DIR+" = new File("+"\""+dataDir.toString()+"\""+");\n"); + out.write(" "+Options.DATA_LOG_DIR+" = new File("+"\""+dataLogDir.toString()+"\""+");\n"); + out.write(" "+Options.CLIENT_PORT+" = "+clientPort+";\n"); + out.write(" "+Options.SERVERS+" = "+"\""+servers+"\""+";\n"); + for(Map.Entry<String, String> entry : other.entrySet()) { + String key = entry.getKey(); + String val = entry.getValue(); + out.write(" "+key+" = "+val+";\n"); + } + + out.write(" "+getGroups("groupsToJoin")+";\n"); + out.write(" locsToJoin=new LookupLocator[]{ };\n"); + out.write(" static discoveryManager = new LookupDiscoveryManager(groupsToJoin,locsToJoin,null,this);\n"); + }// END BLOCK - 4. Close component name + out.write("}\n"); + } + + protected void writeComments(final Writer out) throws IOException { + out.write("// className=" + className + "\n"); + out.write("// date=" + new java.util.Date() + "\n"); + } + + public String[] getImports() { + return new String[] + { "java.net.NetworkInterface", + "com.sun.jini.config.ConfigUtil", + "net.jini.constraint.BasicMethodConstraints", + "net.jini.core.constraint.ConnectionRelativeTime", + "net.jini.core.constraint.InvocationConstraints", + "net.jini.jeri.BasicILFactory", + "net.jini.jeri.BasicJeriExporter", + "net.jini.jeri.tcp.TcpServerEndpoint", + "net.jini.core.discovery.LookupLocator", + "net.jini.discovery.LookupDiscoveryManager", + "com.bigdata.util.config.NicUtil", + "com.bigdata.util.config.ConfigDeployUtil" + }; + } + + protected String getGroups(String entryName) { + String fedname = null; + String zrootname = null;//in some test configs + String defaultGroupName = "UNKNOWN"; + try { + fedname = (String) jiniConfig.getEntry + ("bigdata", "fedname", + String.class, "fedname-unset"); + zrootname = (String) jiniConfig.getEntry + ("bigdata", "zrootname", + String.class, null); + } catch(Exception e) {//swallow + } + if (fedname == null) fedname = defaultGroupName; + + StringBuffer strBuf = + new StringBuffer(entryName+"=new String[]{"); + strBuf.append( com.bigdata.jini.util.ConfigMath.q(fedname) ); + if (zrootname != null) { + strBuf.append + (","+com.bigdata.jini.util.ConfigMath.q(zrootname)); + } + strBuf.append("}"); + + return strBuf.toString(); + } +//BTM - FOR_ZOOKEEPER_SMART_PROXY - END -------------------------------------- } /** Modified: branches/dev-btm/bigdata-jini/src/java/com/bigdata/jini/start/process/ZookeeperProcessHelper.java =================================================================== --- branches/dev-btm/bigdata-jini/src/java/com/bigdata/jini/start/process/ZookeeperProcessHelper.java 2010-12-06 21:29:19 UTC (rev 3996) +++ branches/dev-btm/bigdata-jini/src/java/com/bigdata/jini/start/process/ZookeeperProcessHelper.java 2010-12-06 22:09:42 UTC (rev 3997) @@ -147,13 +147,23 @@ * * @see ZookeeperServerConfiguration#newServiceStarter(IServiceListener, ZookeeperServerEntry) */ - static public int startZookeeper(final Configuration config, - final IServiceListener listener) throws ConfigurationException, - IOException { +//BTM - PRE_ZOOKEEPER_SMART_PROXY - BEGIN +//BTM - PRE_ZOOKEEPER_SMART_PROXY static public int startZookeeper(final Configuration config, +//BTM - PRE_ZOOKEEPER_SMART_PROXY final IServiceListener listener) throws ConfigurationException, +//BTM - PRE_ZOOKEEPER_SMART_PROXY IOException { +//BTM - PRE_ZOOKEEPER_SMART_PROXY +//BTM - PRE_ZOOKEEPER_SMART_PROXY final ZookeeperServerConfiguration serverConfig = new ZookeeperServerConfiguration( +//BTM - PRE_ZOOKEEPER_SMART_PROXY config); + static public int startZookeeper + (final Class classType, + final Configuration config, + final IServiceListener listener) + throws ConfigurationException, IOException + { + final ZookeeperServerConfiguration serverConfig = + new ZookeeperServerConfiguration(classType, config); +//BTM - PRE_ZOOKEEPER_SMART_PROXY - END - final ZookeeperServerConfiguration serverConfig = new ZookeeperServerConfiguration( - config); - //BTM log.warn("\n------------ ZookeeperProcessHelper.startZookeeper: [localhost="+thisInetAddr.getHostName()+", clientPort="+serverConfig.clientPort+"]\n"); //BTM com.bigdata.util.Util.printStr("TestBigdata.debug","\n------------ ZookeeperProcessHelper.startZookeeper: [localhost="+thisInetAddr.getHostName()+", clientPort="+serverConfig.clientPort+"]\n"); Modified: branches/dev-btm/bigdata-jini/src/java/com/bigdata/quorum/ServiceImpl.java =================================================================== --- branches/dev-btm/bigdata-jini/src/java/com/bigdata/quorum/ServiceImpl.java 2010-12-06 21:29:19 UTC (rev 3996) +++ branches/dev-btm/bigdata-jini/src/java/com/bigdata/quorum/ServiceImpl.java 2010-12-06 22:09:42 UTC (rev 3997) @@ -98,6 +98,7 @@ import java.net.SocketException; import java.net.UnknownHostException; import java.rmi.RemoteException; +import java.rmi.RMISecurityManager; import java.rmi.server.ExportException; import java.util.ArrayList; import java.util.Collections; @@ -117,11 +118,20 @@ /** * Backend (admin) zookeeper based implementation of the quorum peer service. + * + * Note: this class is currently declared public rather than the preferred + * package protected scope. This is so that the JiniServicesHelper + * utility can instantiate this class in the tests that are currently + * implemented to interact directly with the service's backend; + * as opposed to starting the service with the ServiceStarter and + * then interacting with the service through the discovered service + * frontend. */ +public class ServiceImpl implements PrivateInterface { - private static Logger logger = LogUtil.getLog4jLogger - ( (ServiceImpl.class).getName() ) ; + private static Logger logger = + LogUtil.getLog4jLogger(COMPONENT_NAME); private static String shutdownStr; private static String killStr; @@ -267,6 +277,9 @@ //Initialize the service from the config private void init(String[] args) throws Exception { + if(System.getSecurityManager() == null) { + System.setSecurityManager(new RMISecurityManager()); + } config = ConfigurationProvider.getInstance ( args, (this.getClass()).getClassLoader() ); @@ -1388,4 +1401,116 @@ } } } + + /** + * This main() method is provided because it may be desirable (for + * testing or other reasons) to be able to start this service using + * a command line that is either manually entered in a command window + * or supplied to the java ProcessBuilder class for execution. + * <p> + * The mechanism that currently employs the ProcessBuilder class to + * execute a dynamically generated command line will be referred to + * as the 'ServiceConfiguration mechanism', which involves the use of + * the following ServiceConfiguration class hierarchy, + * <p> + * <ul> + * <li> ZookeeperConfiguration + * <li> JavaServiceConfiguration + * <li> ServiceConfiguration + * </ul> + * </p> + * The ServicesConfiguration mechanism may involve the use of the + * ServicesManagerService directly to execute this service, or it may + * involve the use of the junit framework to start this service. In + * either case, a command line is constructed from information that is + * specified at each of the various ServiceConfiguration levels, and + * is ultimately executed in a ProcessBuilder instance (in the + * ProcessHelper class). + * <p> + * In order for this method to know whether or not the + * ServiceConfiguration mechanism is being used to start the service, + * this method must be told that the ServiceConfiguration mechanism is + * being used. This is done by setting the system property named + * <code>usingServiceConfiguration</code> to any non-null value. + * <p> + * When the ServiceConfiguration mechanism is <i>not</i> used to start + * this service, this method assumes that the element at index 0 + * of the args array references the path to the jini configuration + * file that will be input by this method to this service's constructor. + * On the other hand, when the ServiceConfiguration mechanism <i>is</i> + * used to start this service, the service's configuration is handled + * differently, as described below. + * <p> + * When using the ServiceConfiguration mechanism, in addition to + * generating a command line to start the service, although an initial, + * pre-constructed jini configuration file is supplied (to the + * ServicesManagerService or the test framework, for example), a + * second jini configuration file is generated <i>on the fly</i> as + * well. When generating that new configuration file, a subset of the + * components and entries specified in the initial jini configuration + * are retrieved and placed in the new configuration being generated. + * It is that second, newly-generated configuration file that is input + * to this method through the args elements at index 0. + * <p> + * When the ServiceConfiguration mechanism is used to invoke this + * method, this method makes a number of assumptions. One assumption + * is that there is a component with name equal to the value, + * "org.apache.zookeeper.server.quorum.QuorumPeerMain", as well as + * either a component itself, or entries corresponding to a component, + * with name equal to the fully qualified name of this class (or both). + * Another assumption is that an entry named 'args' is associated with + * that component. The 'args' entry is assumed to be a <code>String</code> + * array in which one of the elments is specified to be a system + * property named 'config' whose value is equal to the path and + * filename of yet a third jini configuration file; that is, something + * of the form, "-Dconfig=<path-to-another-jini-config>". It is this + * third jini configuration file that the service will ultimately use + * to initialize itself when the ServiceConfiguration mechanism is + * being used to start the service. In that case then, this method + * will retrieve the path to the third jini configuration file from + * the configuration file supplied to this method in the args array + * at index 0, and then replace the element at index 0 with that + * path; so that when the service is instantiated (using this class' + * constructor), that third configuration file is made available to + * the service instance. + * <p> + * Note that, unlike the other service implementations, this service + * always generates its own service id the very first time it is + * started, persists that service id, and retrieves and reuses it + * on restarts. + * <p> + * Note that once an instance of this service implementation class + * has been created, that instance is stored in the <code>thisImpl</code> + * field to prevent the instance from being garbage collected until + * the service is actually shutdown. + */ + + private static ServiceImpl thisImpl; + + public static void main(String[] args) { + logger.debug("[main]: appHome="+System.getProperty("appHome")); + try { + // If the system property with name "config" is set, then + // use the value of that property to override the value + // input in the first element of the args array + ArrayList<String> argsList = new ArrayList<String>(); + int begIndx = 0; + String configFile = System.getProperty("config"); + if(configFile != null) { + // Replace args[0] with config file location + argsList.add(configFile); + begIndx = 1; + } + for(int i=begIndx; i<args.length; i++) { + argsList.add(args[i]); + } + logger.debug("[main]: instantiating service [new ServiceImpl]"); + thisImpl = new ServiceImpl + ( argsList.toArray(new String[argsList.size()]), + new com.bigdata.service.jini.FakeLifeCycle() ); + } catch(Throwable t) { + logger.log(Level.WARN, + "failed to start callable executor service", t); + } + } } Modified: branches/dev-btm/bigdata-jini/src/java/com/bigdata/service/jini/util/JiniServicesHelper.java =================================================================== --- branches/dev-btm/bigdata-jini/src/java/com/bigdata/service/jini/util/JiniServicesHelper.java 2010-12-06 21:29:19 UTC (rev 3996) +++ branches/dev-btm/bigdata-jini/src/java/com/bigdata/service/jini/util/JiniServicesHelper.java 2010-12-06 22:09:42 UTC (rev 3997) @@ -555,8 +555,14 @@ // start zookeeper (a server instance). //BTM log.warn("\n---------------- JiniServicesHelper.innerStart >>> START ZOOKEEPER\n"); //BTM com.bigdata.util.Util.printStr("TestBigdata.debug","\n---------------- JiniServicesHelper.innerStart >>> START ZOOKEEPER\n"); - final int nstarted = ZookeeperProcessHelper.startZookeeper( - config, serviceListener); +//BTM - PRE_ZOOKEEPER_SMART_PROXY - BEGIN +//BTM - PRE_ZOOKEEPER_SMART_PROXY final int nstarted = ZookeeperProcessHelper.startZookeeper( +//BTM - PRE_ZOOKEEPER_SMART_PROXY config, serviceListener); + final int nstarted = + ZookeeperProcessHelper.startZookeeper + (com.bigdata.quorum.ServiceImpl.class, //BTM - was QuorumPeerMain.class + config, serviceListener); +//BTM - PRE_ZOOKEEPER_SMART_PROXY - END //BTM log.warn("\n---------------- JiniServicesHelper.innerStart >>> START ZOOKEEPER - DONE\n"); //BTM com.bigdata.util.Util.printStr("TestBigdata.debug","\n---------------- JiniServicesHelper.innerStart >>> START ZOOKEEPER - DONE\n"); Modified: branches/dev-btm/bigdata-jini/src/test/com/bigdata/jini/start/AbstractFedZooTestCase.java =================================================================== --- branches/dev-btm/bigdata-jini/src/test/com/bigdata/jini/start/AbstractFedZooTestCase.java 2010-12-06 21:29:19 UTC (rev 3996) +++ branches/dev-btm/bigdata-jini/src/test/com/bigdata/jini/start/AbstractFedZooTestCase.java 2010-12-06 22:09:42 UTC (rev 3997) @@ -50,6 +50,16 @@ import com.bigdata.service.jini.JiniClient; import com.bigdata.service.jini.JiniFederation; +//BTM - FOR_ZOOKEEPER_SMART_PROXY - BEGIN +import com.bigdata.service.QuorumPeerService; +import com.sun.jini.admin.DestroyAdmin; +import net.jini.admin.Administrable; +import net.jini.core.lookup.ServiceItem; +import net.jini.core.lookup.ServiceTemplate; +import net.jini.discovery.DiscoveryGroupManagement; +import net.jini.lookup.ServiceDiscoveryManager; +//BTM - FOR_ZOOKEEPER_SMART_PROXY - END + /** * Abstract base class for unit tests requiring a running zookeeper and a * running federation as configured from a test resource. @@ -143,7 +153,11 @@ //BTM - FOR_CLIENT_SERVICE - END // if necessary, start zookeeper (a server instance). - ZookeeperProcessHelper.startZookeeper(config, listener); +//BTM - PRE_ZOOKEEPER_SMART_PROXY - BEGIN +//BTM - PRE_ZOOKEEPER_SMART_PROXY ZookeeperProcessHelper.startZookeeper(config, listener); + ZookeeperProcessHelper.startZookeeper(com.bigdata.quorum.ServiceImpl.class, config, listener); +//ZookeeperProcessHelper.startZookeeper(org.apache.zookeeper.server.quorum.QuorumPeerMain.class, config, listener); +//BTM - PRE_ZOOKEEPER_SMART_PROXY - END /* * FIXME We need to start a jini lookup service for groups = {fedname} @@ -171,6 +185,29 @@ System.err.println(getName() + ": tearing down zrootname=" + zrootname); +//BTM - FOR_ZOOKEEPER_SMART_PROXY - BEGIN + // Graceful shutdown of QuorumPeerService + ServiceDiscoveryManager sdm = fed.getServiceDiscoveryManager(); + DiscoveryGroupManagement ldm = + (DiscoveryGroupManagement)(sdm.getDiscoveryManager()); + Class[] quorumServiceType = + new Class[] {com.bigdata.service.QuorumPeerService.class}; + ServiceTemplate quorumServiceTmpl = + new ServiceTemplate(null, quorumServiceType, null); + ServiceItem[] items = + sdm.lookup(quorumServiceTmpl, Integer.MAX_VALUE, null); + + for (int i=0; i<items.length; i++) { + QuorumPeerService zk = (QuorumPeerService)(items[i].service); + try { + Object admin = ((Administrable)zk).getAdmin(); + ((DestroyAdmin)admin).destroy(); + } catch(Exception e) { + log.warn("failure on zookeeper destroy ["+zk+"]", e); + } + } +//BTM - FOR_ZOOKEEPER_SMART_PROXY - END + // destroy any processes started by this test suite. for (ProcessHelper t : listener.running) { Modified: branches/dev-btm/bigdata-jini/src/test/com/bigdata/jini/start/TestServiceStarter.java =================================================================== --- branches/dev-btm/bigdata-jini/src/test/com/bigdata/jini/start/TestServiceStarter.java 2010-12-06 21:29:19 UTC (rev 3996) +++ branches/dev-btm/bigdata-jini/src/test/com/bigdata/jini/start/TestServiceStarter.java 2010-12-06 22:09:42 UTC (rev 3997) @@ -176,7 +176,8 @@ final ServiceItem serviceItem; IService proxy = null; Service smartProxy = null; - final String physicalServiceZPath; +//BTM (12/06/2010) final String physicalServiceZPath; +String physicalServiceZPath = null; { final List<String> children = zookeeper.getChildren( @@ -194,14 +195,52 @@ * Note: You could explicitly build the correct zpath using the * serviceUUID obtained from the service proxy. */ - physicalServiceZPath = logicalServiceZPath + "/" - + children.get(0); - - // get the serviceUUID from the physicalServiceZNode's data. - final UUID serviceUUID = (UUID) SerializerUtil - .deserialize(zookeeper.getData(physicalServiceZPath, - false/* watch */, new Stat())); - +//BTM - BEGIN (12/06/2010) ---------------------------------------------- +//BTM The note above appears to be no longer true. That is, +//BTM at some point, the tests or infrastructure were changed +//BTM in such a way that there are now 2 children instead of +//BTM the 1 child the note above says is expected. Currently, +//BTM the children are masterElection and physicalServices, +//BTM but the code below that retrieves the serviceUUID from +//BTM zookeeper must retrieve it from the physicalServices +//BTM children, not the masterElection child. The original +//BTM code invoked children.get(0), assuming either there +//BTM was only 1 child or assuming that the physicalServices +//BTM child would always be placed at index 0 of the +//BTM children list above zookeeper.getChildren() was called. +//BTM Unfortunately, this is not alway the case. And when/if +//BTM an attempt is made to deserialize the serviceUUID using +//BTM the masterElection child, an EOF exception is encountered +//BTM because serviceUUID information was never stored under +//BTM the masterElection znode. To address this then, the +//BTM code below was changed to loop through the children +//BTM list, catching the exception and exiting when a +//BTM a valid serviceUUID is successfully deserialized. +//BTM +//BTM physicalServiceZPath = logicalServiceZPath + "/" +//BTM + children.get(0); +//BTM // get the serviceUUID from the physicalServiceZNode's data. +//BTM final UUID serviceUUID = (UUID) SerializerUtil +//BTM .deserialize(zookeeper.getData(physicalServiceZPath, +//BTM false/* watch */, new Stat())); +//BTM + UUID serviceUUID = null; + for (String child : children) { + physicalServiceZPath = logicalServiceZPath+"/"+child; + try { + serviceUUID = + (UUID) SerializerUtil.deserialize + ( zookeeper.getData(physicalServiceZPath, + false,//watch + new Stat()) ); + break; + } catch(Exception e) {//swallow + } + } + assertTrue( "failed to deserialize serviceUUID " + +"[children="+children+"]", + (serviceUUID != null) ); +//BTM - END -------------------------------------------------------------- serviceItem = discoverService(serviceUUID); // verify that the service item is registered with jini. Modified: branches/dev-btm/bigdata-jini/src/test/com/bigdata/zookeeper/AbstractZooTestCase.java =================================================================== --- branches/dev-btm/bigdata-jini/src/test/com/bigdata/zookeeper/AbstractZooTestCase.java 2010-12-06 21:29:19 UTC (rev 3996) +++ branches/dev-btm/bigdata-jini/src/test/com/bigdata/zookeeper/AbstractZooTestCase.java 2010-12-06 22:09:42 UTC (rev 3997) @@ -153,12 +153,16 @@ if (log.isInfoEnabled()) log.info(getName()); - + // find ports that are not in use. clientPort = getPort(2181/* suggestedPort */); final int peerPort = getPort(2888/* suggestedPort */); final int leaderPort = getPort(3888/* suggestedPort */); - final String servers = "1=localhost:" + peerPort + ":" + leaderPort; +//BTM - PRE_ZOOKEEPER_SMART_PROXY - BEGIN +//BTM - PRE_ZOOKEEPER_SMART_PROXY final String servers = "1=localhost:" + peerPort + ":" + leaderPort; + String hostname = com.bigdata.util.config.NicUtil.getIpAddress("default.nic", "default", true); + final String servers = "1="+hostname+":" + peerPort + ":" + leaderPort; +//BTM - PRE_ZOOKEEPER_SMART_PROXY - END // create a temporary file for zookeeper's state. dataDir = File.createTempFile("test", ".zoo"); @@ -200,9 +204,14 @@ this.sessionTimeout = tickTime * 2; // if necessary, start zookeeper (a server instance). - ZookeeperProcessHelper.startZookeeper(config, listener); +//BTM - PRE_ZOOKEEPER_SMART_PROXY - BEGIN +//BTM - PRE_ZOOKEEPER_SMART_PROXY ZookeeperProcessHelper.startZookeeper(config, listener); +//BTM - PRE_ZOOKEEPER_SMART_PROXY +//BTM - PRE_ZOOKEEPER_SMART_PROXY zookeeperAccessor = new ZooKeeperAccessor("localhost:" + clientPort, sessionTimeout); - zookeeperAccessor = new ZooKeeperAccessor("localhost:" + clientPort, sessionTimeout); + zookeeperAccessor = new ZooKeeperAccessor(hostname+":" + clientPort, sessionTimeout); + ZookeeperProcessHelper.startZookeeper(com.bigdata.quorum.ServiceImpl.class, config, listener); +//BTM - PRE_ZOOKEEPER_SMART_PROXY - END zookeeper = zookeeperAccessor.getZookeeper(); Modified: branches/dev-btm/src/resources/config/bigdataCluster.config =================================================================== --- branches/dev-btm/src/resources/config/bigdataCluster.config 2010-12-06 21:29:19 UTC (rev 3996) +++ branches/dev-btm/src/resources/config/bigdataCluster.config 2010-12-06 22:09:42 UTC (rev 3997) @@ -1371,6 +1371,21 @@ properties = new NV[] { }; } + +com.bigdata.quorum.ServiceImpl { + + args = new String[]{ + "-Xmx200m", + + "-Djava.util.logging.config.file=@NAS@/dist/bigdata/var/config/logging/quorum-logging.properties", + "-Dlog4j.configuration=@NAS@/dist/bigdata/var/config/logging/quorum-logging.properties", + "-Dlog4j.primary.configuration=@NAS@/dist/bigdata/var/config/logging/quorum-logging.properties", + "-DusingServiceConfiguration=true", + "-Dbigdata.logDir=@NAS@/dist/bigdata/var/log", + "-DappHome=@APP_HOME@", + "-Dconfig=@NAS@/dist/bigdata/var/config/jini/quorum.config" + }; +} //BTM - END /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |