hadoop-zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r718659 - in /hadoop/zookeeper/branches/branch-3.0: ./ src/java/jmx/org/apache/zookeeper/server/ src/java/jmx/org/apache/zookeeper/server/quorum/ src/java/main/org/apache/zookeeper/server/ src/java/main/org/apache/zookeeper/server/quorum/
Date Tue, 18 Nov 2008 17:23:10 GMT
Author: mahadev
Date: Tue Nov 18 09:23:10 2008
New Revision: 718659

URL: http://svn.apache.org/viewvc?rev=718659&view=rev
Log:
ZOOKEEPER-217. Fix errors in config to be thrown as Exceptions. (mahadev)

Modified:
    hadoop/zookeeper/branches/branch-3.0/CHANGES.txt
    hadoop/zookeeper/branches/branch-3.0/src/java/jmx/org/apache/zookeeper/server/ManagedZooKeeperServerMain.java
    hadoop/zookeeper/branches/branch-3.0/src/java/jmx/org/apache/zookeeper/server/quorum/ManagedQuorumPeerMain.java
    hadoop/zookeeper/branches/branch-3.0/src/java/main/org/apache/zookeeper/server/ServerConfig.java
    hadoop/zookeeper/branches/branch-3.0/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java
    hadoop/zookeeper/branches/branch-3.0/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java
    hadoop/zookeeper/branches/branch-3.0/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java

Modified: hadoop/zookeeper/branches/branch-3.0/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.0/CHANGES.txt?rev=718659&r1=718658&r2=718659&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.0/CHANGES.txt (original)
+++ hadoop/zookeeper/branches/branch-3.0/CHANGES.txt Tue Nov 18 09:23:10 2008
@@ -15,6 +15,8 @@
 
    ZOOKEEPER-219. fix events.poll timeout in watcher test to be longer. (pat
 via mahadev)
+   
+   ZOOKEEPER-217. Fix errors in config to be thrown as Exceptions. (mahadev)
 
 Release 3.0.0 - 2008-10-21
 

Modified: hadoop/zookeeper/branches/branch-3.0/src/java/jmx/org/apache/zookeeper/server/ManagedZooKeeperServerMain.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.0/src/java/jmx/org/apache/zookeeper/server/ManagedZooKeeperServerMain.java?rev=718659&r1=718658&r2=718659&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.0/src/java/jmx/org/apache/zookeeper/server/ManagedZooKeeperServerMain.java
(original)
+++ hadoop/zookeeper/branches/branch-3.0/src/java/jmx/org/apache/zookeeper/server/ManagedZooKeeperServerMain.java
Tue Nov 18 09:23:10 2008
@@ -23,6 +23,7 @@
 import java.io.File;
 import java.io.IOException;
 
+import org.apache.log4j.Logger;
 import org.apache.zookeeper.jmx.server.ConnectionMXBean;
 import org.apache.zookeeper.jmx.server.DataTreeMXBean;
 import org.apache.zookeeper.jmx.server.ZooKeeperServerMXBean;
@@ -53,6 +54,7 @@
  */
 public class ManagedZooKeeperServerMain extends ZooKeeperServerMain {
     
+    private static final Logger LOG = Logger.getLogger(ManagedZooKeeperServerMain.class);
     /**
      * To start the server specify the client port number and the data directory
      * on the command line.
@@ -60,7 +62,12 @@
      * @param args command line parameters.
      */
     public static void main(String[] args) {
-        ServerConfig.parse(args);
+        try {
+            ServerConfig.parse(args);
+        } catch(Exception e) {
+            LOG.fatal("Error in config", e);
+            System.exit(2);
+        }
         ZooKeeperObserverManager.setAsConcrete();
         runStandalone(new ZooKeeperServer.Factory() {
             public NIOServerCnxn.Factory createConnectionFactory()throws IOException {

Modified: hadoop/zookeeper/branches/branch-3.0/src/java/jmx/org/apache/zookeeper/server/quorum/ManagedQuorumPeerMain.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.0/src/java/jmx/org/apache/zookeeper/server/quorum/ManagedQuorumPeerMain.java?rev=718659&r1=718658&r2=718659&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.0/src/java/jmx/org/apache/zookeeper/server/quorum/ManagedQuorumPeerMain.java
(original)
+++ hadoop/zookeeper/branches/branch-3.0/src/java/jmx/org/apache/zookeeper/server/quorum/ManagedQuorumPeerMain.java
Tue Nov 18 09:23:10 2008
@@ -85,7 +85,12 @@
             ManagedZooKeeperServerMain.main(args);
             return;
         }
-        QuorumPeerConfig.parse(args);
+        try {
+            QuorumPeerConfig.parse(args);
+        } catch(Exception e) {
+            LOG.fatal("Error in config ", e);
+            System.exit(2);
+        }
         if (!QuorumPeerConfig.isStandalone()) {
             ZooKeeperObserverManager.setAsConcrete();
             runPeer(new QuorumPeer.Factory() {

Modified: hadoop/zookeeper/branches/branch-3.0/src/java/main/org/apache/zookeeper/server/ServerConfig.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.0/src/java/main/org/apache/zookeeper/server/ServerConfig.java?rev=718659&r1=718658&r2=718659&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.0/src/java/main/org/apache/zookeeper/server/ServerConfig.java
(original)
+++ hadoop/zookeeper/branches/branch-3.0/src/java/main/org/apache/zookeeper/server/ServerConfig.java
Tue Nov 18 09:23:10 2008
@@ -51,18 +51,16 @@
     
     protected static ServerConfig instance=null;
     
-    public static void parse(String[] args) {
+    public static void parse(String[] args) throws Exception {
         if(instance!=null)
             return;
         if (args.length != 2) {
-            System.err.println("USAGE: ZooKeeperServer port datadir\n");
-            System.exit(2);
+            throw new IllegalArgumentException("Invalid usage.");
         }
         try {
               instance=new ServerConfig(Integer.parseInt(args[0]),args[1],args[1]);
         } catch (NumberFormatException e) {
-            System.err.println(args[0] + " is not a valid port number");
-            System.exit(2);
+            throw new IllegalArgumentException(args[0] + " is not a valid port number");
         }
     }
 

Modified: hadoop/zookeeper/branches/branch-3.0/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.0/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java?rev=718659&r1=718658&r2=718659&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.0/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java
(original)
+++ hadoop/zookeeper/branches/branch-3.0/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java
Tue Nov 18 09:23:10 2008
@@ -31,14 +31,20 @@
 public class ZooKeeperServerMain {
 
     private static final Logger LOG = Logger.getLogger(ZooKeeperServerMain.class);
-
+    private static final String USAGE = "Usage: ZooKeeperServerMain port datadir";
     /*
      * Start up the ZooKeeper server.
      *
      * @param args the port and data directory
      */
     public static void main(String[] args) {
-        ServerConfig.parse(args);
+        try {
+            ServerConfig.parse(args);
+        } catch(Exception e) {
+            LOG.fatal("Error in config", e);
+            LOG.info(USAGE);
+            System.exit(2);
+        }
         runStandalone(new ZooKeeperServer.Factory() {
             public NIOServerCnxn.Factory createConnectionFactory() throws IOException {
                 return new NIOServerCnxn.Factory(ServerConfig.getClientPort());

Modified: hadoop/zookeeper/branches/branch-3.0/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.0/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java?rev=718659&r1=718658&r2=718659&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.0/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java
(original)
+++ hadoop/zookeeper/branches/branch-3.0/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java
Tue Nov 18 09:23:10 2008
@@ -47,145 +47,137 @@
         super(port, dataDir, dataLogDir);
     }
 
-    public static void parse(String[] args) {
-        if(instance!=null)
+    public static void parse(String[] args) throws Exception {
+        if (instance != null)
             return;
-
+        if (args.length != 1) {
+            throw new IllegalArgumentException("Invalid usage.");
+        }
+        File zooCfgFile = new File(args[0]);
+        if (!zooCfgFile.exists()) {
+            throw new IllegalArgumentException(zooCfgFile.toString()
+                    + " file is missing");
+        }
+        Properties cfg = new Properties();
+        FileInputStream zooCfgStream = new FileInputStream(zooCfgFile);
         try {
-            if (args.length != 1) {
-                System.err.println("USAGE: configFile");
-                System.exit(2);
-            }
-            File zooCfgFile = new File(args[0]);
-            if (!zooCfgFile.exists()) {
-                LOG.error(zooCfgFile.toString() + " file is missing");
-                System.exit(2);
+            cfg.load(zooCfgStream);
+        } finally {
+            zooCfgStream.close();
+        }
+        HashMap<Long, QuorumServer> servers = new HashMap<Long, QuorumServer>();
+        String dataDir = null;
+        String dataLogDir = null;
+        int clientPort = 0;
+        int tickTime = 0;
+        int initLimit = 0;
+        int syncLimit = 0;
+        int electionAlg = 3;
+        int electionPort = 2182;
+        for (Entry<Object, Object> entry : cfg.entrySet()) {
+            String key = entry.getKey().toString();
+            String value = entry.getValue().toString();
+            if (key.equals("dataDir")) {
+                dataDir = value;
+            } else if (key.equals("dataLogDir")) {
+                dataLogDir = value;
+            } else if (key.equals("clientPort")) {
+                clientPort = Integer.parseInt(value);
+            } else if (key.equals("tickTime")) {
+                tickTime = Integer.parseInt(value);
+            } else if (key.equals("initLimit")) {
+                initLimit = Integer.parseInt(value);
+            } else if (key.equals("syncLimit")) {
+                syncLimit = Integer.parseInt(value);
+            } else if (key.equals("electionAlg")) {
+                electionAlg = Integer.parseInt(value);
+            } else if (key.startsWith("server.")) {
+                int dot = key.indexOf('.');
+                long sid = Long.parseLong(key.substring(dot + 1));
+                String parts[] = value.split(":");
+                if ((parts.length != 2) && (parts.length != 3)) {
+                    LOG
+                            .error(value
+                                    + " does not have the form host:port or host:port:port");
+                }
+                InetSocketAddress addr = new InetSocketAddress(parts[0],
+                        Integer.parseInt(parts[1]));
+                if (parts.length == 2)
+                    servers.put(Long.valueOf(sid), new QuorumServer(sid, addr));
+                else if (parts.length == 3) {
+                    InetSocketAddress electionAddr = new InetSocketAddress(
+                            parts[0], Integer.parseInt(parts[2]));
+                    servers.put(Long.valueOf(sid), new QuorumServer(sid, addr,
+                            electionAddr));
+                }
+            } else {
+                System.setProperty("zookeeper." + key, value);
             }
-            Properties cfg = new Properties();
-            FileInputStream zooCfgStream = new FileInputStream(zooCfgFile);
-            try {
-                cfg.load(zooCfgStream);
-            } finally {
-                zooCfgStream.close();
+        }
+        if (dataDir == null) {
+            throw new IllegalArgumentException("dataDir is not set");
+        }
+        if (dataLogDir == null) {
+            dataLogDir = dataDir;
+        } else {
+            if (!new File(dataLogDir).isDirectory()) {
+                throw new IllegalArgumentException("dataLogDir " + dataLogDir
+                        + " is missing.");
             }
-            HashMap<Long,QuorumServer> servers = new HashMap<Long,QuorumServer>();
-            String dataDir = null;
-            String dataLogDir = null;
-            int clientPort = 0;
-            int tickTime = 0;
-            int initLimit = 0;
-            int syncLimit = 0;
-            int electionAlg = 3;
-            int electionPort = 2182;
-            for (Entry<Object, Object> entry : cfg.entrySet()) {
-                String key = entry.getKey().toString();
-                String value = entry.getValue().toString();
-                if (key.equals("dataDir")) {
-                    dataDir = value;
-                } else if (key.equals("dataLogDir")) {
-                    dataLogDir = value;
-                } else if (key.equals("clientPort")) {
-                    clientPort = Integer.parseInt(value);
-                } else if (key.equals("tickTime")) {
-                    tickTime = Integer.parseInt(value);
-                } else if (key.equals("initLimit")) {
-                    initLimit = Integer.parseInt(value);
-                } else if (key.equals("syncLimit")) {
-                    syncLimit = Integer.parseInt(value);
-                } else if (key.equals("electionAlg")) {
-                    electionAlg = Integer.parseInt(value);
-                } else if (key.startsWith("server.")) {
-                    int dot = key.indexOf('.');
-                    long sid = Long.parseLong(key.substring(dot + 1));
-                    String parts[] = value.split(":");
-                    if ((parts.length != 2) && 
-                            (parts.length != 3)){
-                        LOG.error(value
-                                + " does not have the form host:port or host:port:port");
-                    }
-                    InetSocketAddress addr = new InetSocketAddress(parts[0],
-                            Integer.parseInt(parts[1])); 
-                    if(parts.length == 2)
-                        servers.put(Long.valueOf(sid), new QuorumServer(sid, addr));
-                    else if(parts.length == 3){
-                        InetSocketAddress electionAddr = new InetSocketAddress(parts[0],
-                                Integer.parseInt(parts[2]));
-                        servers.put(Long.valueOf(sid), new QuorumServer(sid, addr, electionAddr));
-                    }
-                } else {
-                    System.setProperty("zookeeper." + key, value);
+        }
+        if (clientPort == 0) {
+            throw new IllegalArgumentException("clientPort is not set");
+        }
+        if (tickTime == 0) {
+            throw new IllegalArgumentException("tickTime is not set");
+        }
+        if (servers.size() > 1 && initLimit == 0) {
+            throw new IllegalArgumentException("initLimit is not set");
+        }
+        if (servers.size() > 1 && syncLimit == 0) {
+            throw new IllegalArgumentException("syncLimit is not set");
+        }
+        QuorumPeerConfig conf = new QuorumPeerConfig(clientPort, dataDir,
+                dataLogDir);
+        conf.tickTime = tickTime;
+        conf.initLimit = initLimit;
+        conf.syncLimit = syncLimit;
+        conf.electionAlg = electionAlg;
+        conf.servers = servers;
+        if (servers.size() > 1) {
+            /*
+             * If using FLE, then every server requires a separate election
+             * port.
+             */
+            if (electionAlg != 0) {
+                for (QuorumServer s : servers.values()) {
+                    if (s.electionAddr == null)
+                        throw new IllegalArgumentException(
+                                "Missing election port for server: " + s.id);
                 }
             }
-            if (dataDir == null) {
-                LOG.error("dataDir is not set");
-                System.exit(2);
+
+            File myIdFile = new File(dataDir, "myid");
+            if (!myIdFile.exists()) {
+                throw new IllegalArgumentException(myIdFile.toString()
+                        + " file is missing");
             }
-            if (dataLogDir == null) {
-                dataLogDir = dataDir;
-            } else {
-                if (!new File(dataLogDir).isDirectory()) {
-                    LOG.error("dataLogDir " + dataLogDir+ " is missing.");
-                    System.exit(2);
-                }
+            BufferedReader br = new BufferedReader(new FileReader(myIdFile));
+            String myIdString;
+            try {
+                myIdString = br.readLine();
+            } finally {
+                br.close();
             }
-            if (clientPort == 0) {
-                LOG.error("clientPort is not set");
-                System.exit(2);
-            }
-            if (tickTime == 0) {
-                LOG.error("tickTime is not set");
-                System.exit(2);
-            }
-            if (servers.size() > 1 && initLimit == 0) {
-                LOG.error("initLimit is not set");
-                System.exit(2);
-            }
-            if (servers.size() > 1 && syncLimit == 0) {
-                LOG.error("syncLimit is not set");
-                System.exit(2);
-            }
-            QuorumPeerConfig conf = new QuorumPeerConfig(clientPort, dataDir,
-                    dataLogDir);
-            conf.tickTime = tickTime;
-            conf.initLimit = initLimit;
-            conf.syncLimit = syncLimit;
-            conf.electionAlg = electionAlg;
-            conf.servers = servers;
-            if (servers.size() > 1) {
-                /*
-                 * If using FLE, then every server requires a separate election port.
-                 */
-                if(electionAlg != 0){
-                   for(QuorumServer s : servers.values()){
-                       if(s.electionAddr == null)
-                           LOG.error("Missing election port for server: " + s.id);
-                   }
-                }
-                
-                File myIdFile = new File(dataDir, "myid");
-                if (!myIdFile.exists()) {
-                    LOG.error(myIdFile.toString() + " file is missing");
-                    System.exit(2);
-                }
-                BufferedReader br = new BufferedReader(new FileReader(myIdFile));
-                String myIdString;
-                try {
-                    myIdString = br.readLine();
-                } finally {
-                    br.close();
-                }
-                try {
-                    conf.serverId = Long.parseLong(myIdString);
-                } catch (NumberFormatException e) {
-                    LOG.error(myIdString + " is not a number");
-                    System.exit(2);
-                }
+            try {
+                conf.serverId = Long.parseLong(myIdString);
+            } catch (NumberFormatException e) {
+                throw new IllegalArgumentException("serverid " + myIdString
+                        + " is not a number");
             }
-            instance=conf;
-        } catch (Exception e) {
-            LOG.error("FIXMSG",e);
-            System.exit(2);
         }
+        instance = conf;
+       
     }
 
     @Override

Modified: hadoop/zookeeper/branches/branch-3.0/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.0/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java?rev=718659&r1=718658&r2=718659&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.0/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java
(original)
+++ hadoop/zookeeper/branches/branch-3.0/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java
Tue Nov 18 09:23:10 2008
@@ -67,7 +67,12 @@
             ZooKeeperServerMain.main(args);
             return;
         }
-        QuorumPeerConfig.parse(args);
+        try {
+            QuorumPeerConfig.parse(args);
+        } catch(Exception e) {
+            LOG.fatal("Error in config", e);
+            System.exit(2);
+        }
         if (!QuorumPeerConfig.isStandalone()) {
             runPeer(new QuorumPeer.Factory() {
                 public QuorumPeer create(NIOServerCnxn.Factory cnxnFactory) throws IOException
{



Mime
View raw message