You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ph...@apache.org on 2011/12/28 07:06:10 UTC
svn commit: r1225107 - in /zookeeper/branches/branch-3.4: ./ bin/
src/java/main/org/apache/zookeeper/client/
src/java/test/org/apache/zookeeper/test/
Author: phunt
Date: Wed Dec 28 06:06:10 2011
New Revision: 1225107
URL: http://svn.apache.org/viewvc?rev=1225107&view=rev
Log:
ZOOKEEPER-1089. zkServer.sh status does not work due to invalid option of nc (Roman Shaposhnik via phunt)
Added:
zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/client/FourLetterWordMain.java
Modified:
zookeeper/branches/branch-3.4/CHANGES.txt
zookeeper/branches/branch-3.4/bin/zkServer.sh
zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ClientBase.java
zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/FourLetterWordsQuorumTest.java
zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java
Modified: zookeeper/branches/branch-3.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/CHANGES.txt?rev=1225107&r1=1225106&r2=1225107&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.4/CHANGES.txt Wed Dec 28 06:06:10 2011
@@ -1,3 +1,13 @@
+Release 3.4.3 - TBD
+
+Backward compatible changes:
+
+BUGFIXES:
+
+ ZOOKEEPER-1089. zkServer.sh status does not work due to invalid
+ option of nc (Roman Shaposhnik via phunt)
+
+
Release 3.4.2 - 2011-12-21
Backward compatible changes:
Modified: zookeeper/branches/branch-3.4/bin/zkServer.sh
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/bin/zkServer.sh?rev=1225107&r1=1225106&r2=1225107&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/bin/zkServer.sh (original)
+++ zookeeper/branches/branch-3.4/bin/zkServer.sh Wed Dec 28 06:06:10 2011
@@ -153,7 +153,10 @@ restart)
;;
status)
# -q is necessary on some versions of linux where nc returns too quickly, and no stat result is output
- STAT=`echo stat | nc -q 1 localhost $(grep "^[[:space:]]*clientPort" "$ZOOCFG" | sed -e 's/.*=//') 2> /dev/null| grep Mode`
+ STAT=`$JAVA "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" \
+ -cp "$CLASSPATH" $JVMFLAGS org.apache.zookeeper.client.FourLetterWordMain localhost \
+ $(grep "^[[:space:]]*clientPort" "$ZOOCFG" | sed -e 's/.*=//') srvr 2> /dev/null \
+ | grep Mode`
if [ "x$STAT" = "x" ]
then
echo "Error contacting service. It is probably not running."
Added: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/client/FourLetterWordMain.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/client/FourLetterWordMain.java?rev=1225107&view=auto
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/client/FourLetterWordMain.java (added)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/client/FourLetterWordMain.java Wed Dec 28 06:06:10 2011
@@ -0,0 +1,79 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zookeeper.client;
+
+import org.apache.log4j.Logger;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.Socket;
+
+public class FourLetterWordMain {
+ protected static final Logger LOG = Logger.getLogger(FourLetterWordMain.class);
+
+ /**
+ * Send the 4letterword
+ * @param host the destination host
+ * @param port the destination port
+ * @param cmd the 4letterword
+ * @return server response
+ * @throws java.io.IOException
+ */
+ public static String send4LetterWord(String host, int port, String cmd)
+ throws IOException
+ {
+ LOG.info("connecting to " + host + " " + port);
+ Socket sock = new Socket(host, port);
+ BufferedReader reader = null;
+ try {
+ OutputStream outstream = sock.getOutputStream();
+ outstream.write(cmd.getBytes());
+ outstream.flush();
+ // this replicates NC - close the output stream before reading
+ sock.shutdownOutput();
+
+ reader =
+ new BufferedReader(
+ new InputStreamReader(sock.getInputStream()));
+ StringBuilder sb = new StringBuilder();
+ String line;
+ while((line = reader.readLine()) != null) {
+ sb.append(line + "\n");
+ }
+ return sb.toString();
+ } finally {
+ sock.close();
+ if (reader != null) {
+ reader.close();
+ }
+ }
+ }
+
+ public static void main(String[] args)
+ throws IOException
+ {
+ if (args.length != 3) {
+ System.out.println("Usage: FourLetterWordMain <host> <port> <cmd>");
+ } else {
+ System.out.println(send4LetterWord(args[0], Integer.parseInt(args[1]), args[2]));
+ }
+ }
+}
Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ClientBase.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ClientBase.java?rev=1225107&r1=1225106&r2=1225107&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ClientBase.java (original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ClientBase.java Wed Dec 28 06:06:10 2011
@@ -53,6 +53,7 @@ import org.apache.zookeeper.server.Serve
import org.apache.zookeeper.server.ZKDatabase;
import org.apache.zookeeper.server.ZooKeeperServer;
import org.apache.zookeeper.server.persistence.FileTxnLog;
+import static org.apache.zookeeper.client.FourLetterWordMain.send4LetterWord;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@@ -213,44 +214,6 @@ public abstract class ClientBase extends
return alist;
}
- /**
- * Send the 4letterword
- * @param host the destination host
- * @param port the destination port
- * @param cmd the 4letterword
- * @return
- * @throws IOException
- */
- public static String send4LetterWord(String host, int port, String cmd)
- throws IOException
- {
- LOG.info("connecting to " + host + " " + port);
- Socket sock = new Socket(host, port);
- BufferedReader reader = null;
- try {
- OutputStream outstream = sock.getOutputStream();
- outstream.write(cmd.getBytes());
- outstream.flush();
- // this replicates NC - close the output stream before reading
- sock.shutdownOutput();
-
- reader =
- new BufferedReader(
- new InputStreamReader(sock.getInputStream()));
- StringBuilder sb = new StringBuilder();
- String line;
- while((line = reader.readLine()) != null) {
- sb.append(line + "\n");
- }
- return sb.toString();
- } finally {
- sock.close();
- if (reader != null) {
- reader.close();
- }
- }
- }
-
public static boolean waitForServerUp(String hp, long timeout) {
long start = System.currentTimeMillis();
while (true) {
Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/FourLetterWordsQuorumTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/FourLetterWordsQuorumTest.java?rev=1225107&r1=1225106&r2=1225107&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/FourLetterWordsQuorumTest.java (original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/FourLetterWordsQuorumTest.java Wed Dec 28 06:06:10 2011
@@ -23,6 +23,7 @@ import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.zookeeper.TestableZooKeeper;
+import static org.apache.zookeeper.client.FourLetterWordMain.send4LetterWord;
import org.junit.Assert;
import org.junit.Test;
Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java?rev=1225107&r1=1225106&r2=1225107&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java (original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java Wed Dec 28 06:06:10 2011
@@ -25,6 +25,7 @@ import java.util.regex.Pattern;
import org.apache.zookeeper.TestableZooKeeper;
import org.apache.zookeeper.ZooKeeper;
+import static org.apache.zookeeper.client.FourLetterWordMain.send4LetterWord;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
@@ -97,7 +98,7 @@ public class FourLetterWordsTest extends
private String sendRequest(String cmd) throws IOException {
HostPort hpobj = ClientBase.parseHostPortList(hostPort).get(0);
- return ClientBase.send4LetterWord(hpobj.host, hpobj.port, cmd);
+ return send4LetterWord(hpobj.host, hpobj.port, cmd);
}
private void verify(String cmd, String expected) throws IOException {