Commit 67ca3cde authored by Patrick D. Hunt's avatar Patrick D. Hunt
Browse files

Cleaned eol chars in files. See ZOOKEEPER-45

git-svn-id: https://svn.apache.org/repos/asf/hadoop/zookeeper/trunk@671303 13f79535-47bb-0310-9956-ffa450edef68
parent 2e867bf9
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation", "Jakarta-Oro"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* or "Jakarta-Oro", nor may "Apache" or "Jakarta-Oro" appear in their
* name, without prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation", "Jakarta-Oro"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* or "Jakarta-Oro", nor may "Apache" or "Jakarta-Oro" appear in their
* name, without prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
SvnAnt license
This license applies to all portions of svnant library, which
are not externally-maintained libraries (e.g. JavaHL).
Such libraries have their own licenses; we recommend you read them, as
their terms may differ from the terms below.
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
SvnAnt license
This license applies to all portions of svnant library, which
are not externally-maintained libraries (e.g. JavaHL).
Such libraries have their own licenses; we recommend you read them, as
their terms may differ from the terms below.
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
/**
* 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;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.util.StringTokenizer;
import org.apache.log4j.Logger;
import org.apache.zookeeper.server.ZooTrace;
public class ServerAdminClient {
private static final Logger LOG = Logger.getLogger(ServerAdminClient.class);
private static long getMask(String mask) {
long retv = 0;
if (mask.equalsIgnoreCase("CLIENT_REQUEST_TRACE_MASK")) {
retv = ZooTrace.CLIENT_REQUEST_TRACE_MASK;
} else if (mask.equalsIgnoreCase("CLIENT_DATA_PACKET_TRACE_MASK")) {
retv = ZooTrace.CLIENT_DATA_PACKET_TRACE_MASK;
} else if (mask.equalsIgnoreCase("CLIENT_PING_TRACE_MASK")) {
retv = ZooTrace.CLIENT_PING_TRACE_MASK;
} else if (mask.equalsIgnoreCase("SERVER_PACKET_TRACE_MASK")) {
retv = ZooTrace.SERVER_PACKET_TRACE_MASK;
} else if (mask.equalsIgnoreCase("SESSION_TRACE_MASK")) {
retv = ZooTrace.SESSION_TRACE_MASK;
} else if (mask.equalsIgnoreCase("EVENT_DELIVERY_TRACE_MASK")) {
retv = ZooTrace.EVENT_DELIVERY_TRACE_MASK;
} else if (mask.equalsIgnoreCase("SERVER_PING_TRACE_MASK")) {
retv = ZooTrace.SERVER_PING_TRACE_MASK;
} else if (mask.equalsIgnoreCase("WARNING_TRACE_MASK")) {
retv = ZooTrace.WARNING_TRACE_MASK;
}
return retv;
}
private static long getMasks(String masks) {
long retv = 0;
StringTokenizer st = new StringTokenizer(masks, "|");
while (st.hasMoreTokens()) {
String mask = st.nextToken().trim();
retv = retv | getMask(mask);
}
return retv;
}
public static void ruok(String host, int port) {
try {
byte[] reqBytes = new byte[4];
ByteBuffer req = ByteBuffer.wrap(reqBytes);
req.putInt(ByteBuffer.wrap("ruok".getBytes()).getInt());
Socket s = null;
s = new Socket();
s.setSoLinger(false, 10);
s.setSoTimeout(20000);
s.connect(new InetSocketAddress(host, port));
InputStream is = s.getInputStream();
OutputStream os = s.getOutputStream();
os.write(reqBytes);
byte[] resBytes = new byte[4];
int rc = is.read(resBytes);
String retv = new String(resBytes);
System.out.println("rc=" + rc + " retv=" + retv);
} catch (IOException ioe) {
LOG.warn("Unexpected exception", ioe);
}
}
public static void dump(String host, int port) {
try {
byte[] reqBytes = new byte[4];
ByteBuffer req = ByteBuffer.wrap(reqBytes);
req.putInt(ByteBuffer.wrap("dump".getBytes()).getInt());
Socket s = null;
s = new Socket();
s.setSoLinger(false, 10);
s.setSoTimeout(20000);
s.connect(new InetSocketAddress(host, port));
InputStream is = s.getInputStream();
OutputStream os = s.getOutputStream();
os.write(reqBytes);
byte[] resBytes = new byte[1024];
int rc = is.read(resBytes);
String retv = new String(resBytes);
System.out.println("rc=" + rc + " retv=" + retv);
} catch (IOException ioe) {
LOG.warn("Unexpected exception", ioe);
}
}
public static void stat(String host, int port) {
try {
byte[] reqBytes = new byte[4];
ByteBuffer req = ByteBuffer.wrap(reqBytes);
req.putInt(ByteBuffer.wrap("stat".getBytes()).getInt());
Socket s = null;
s = new Socket();
s.setSoLinger(false, 10);
s.setSoTimeout(20000);
s.connect(new InetSocketAddress(host, port));
InputStream is = s.getInputStream();
OutputStream os = s.getOutputStream();
os.write(reqBytes);
byte[] resBytes = new byte[1024];
int rc = is.read(resBytes);
String retv = new String(resBytes);
System.out.println("rc=" + rc + " retv=" + retv);
} catch (IOException ioe) {
LOG.warn("Unexpected exception", ioe);
}
}
public static void kill(String host, int port) {
try {
byte[] reqBytes = new byte[4];
ByteBuffer req = ByteBuffer.wrap(reqBytes);
req.putInt(ByteBuffer.wrap("kill".getBytes()).getInt());
Socket s = null;
s = new Socket();
s.setSoLinger(false, 10);
s.setSoTimeout(20000);
s.connect(new InetSocketAddress(host, port));
InputStream is = s.getInputStream();
OutputStream os = s.getOutputStream();
os.write(reqBytes);
byte[] resBytes = new byte[4];
int rc = is.read(resBytes);
String retv = new String(resBytes);
System.out.println("rc=" + rc + " retv=" + retv);
} catch (IOException ioe) {
LOG.warn("Unexpected exception", ioe);
}
}
public static void setTraceMask(String host, int port, String traceMaskStr) {
try {
byte[] reqBytes = new byte[12];
ByteBuffer req = ByteBuffer.wrap(reqBytes);
long traceMask = Long.parseLong(traceMaskStr, 8);
req.putInt(ByteBuffer.wrap("stmk".getBytes()).getInt());
req.putLong(traceMask);
Socket s = null;
s = new Socket();
s.setSoLinger(false, 10);
s.setSoTimeout(20000);
s.connect(new InetSocketAddress(host, port));
InputStream is = s.getInputStream();
OutputStream os = s.getOutputStream();
os.write(reqBytes);
byte[] resBytes = new byte[8];
int rc = is.read(resBytes);
ByteBuffer res = ByteBuffer.wrap(resBytes);
long retv = res.getLong();
System.out.println("rc=" + rc + " retv=0"
+ Long.toOctalString(retv) + " masks=0"
+ Long.toOctalString(traceMask));
assert (retv == traceMask);
} catch (IOException ioe) {
LOG.warn("Unexpected exception", ioe);
}
}
public static void getTraceMask(String host, int port) {
try {
byte[] reqBytes = new byte[12];
ByteBuffer req = ByteBuffer.wrap(reqBytes);
req.putInt(ByteBuffer.wrap("gtmk".getBytes()).getInt());
Socket s = null;
s = new Socket();
s.setSoLinger(false, 10);
s.setSoTimeout(20000);
s.connect(new InetSocketAddress(host, port));
InputStream is = s.getInputStream();
OutputStream os = s.getOutputStream();
os.write(reqBytes);
byte[] resBytes = new byte[8];
int rc = is.read(resBytes);
ByteBuffer res = ByteBuffer.wrap(resBytes);
long retv = res.getLong();
System.out.println("rc=" + rc + " retv=0"
+ Long.toOctalString(retv));
} catch (IOException ioe) {
LOG.warn("Unexpected exception", ioe);
}
}
private static void usage() {
System.out
.println("usage: java [-cp CLASSPATH] org.apache.zookeeper.ServerAdminClient "
+ "host port op (ruok|stat|dump|kill|gettracemask|settracemask) [arguments]");
}
public static void main(String[] args) {
if (args.length < 3) {
usage();
return;
}
String host = args[0];
int port = Integer.parseInt(args[1]);
String op = args[2];
if (op.equalsIgnoreCase("gettracemask")) {
getTraceMask(host, port);
} else if (op.equalsIgnoreCase("settracemask")) {
setTraceMask(host, port, args[3]);
} else if (op.equalsIgnoreCase("ruok")) {
ruok(host, port);
} else if (op.equalsIgnoreCase("kill")) {
kill(host, port);
} else if (op.equalsIgnoreCase("stat")) {
stat(host, port);
} else if (op.equalsIgnoreCase("dump")) {
dump(host, port);
} else {
System.out.println("Unrecognized op: " + op);
}
}
}
/**
* 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;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.util.StringTokenizer;
import org.apache.log4j.Logger;
import org.apache.zookeeper.server.ZooTrace;
public class ServerAdminClient {
private static final Logger LOG = Logger.getLogger(ServerAdminClient.class);
private static long getMask(String mask) {
long retv = 0;
if (mask.equalsIgnoreCase("CLIENT_REQUEST_TRACE_MASK")) {
retv = ZooTrace.CLIENT_REQUEST_TRACE_MASK;
} else if (mask.equalsIgnoreCase("CLIENT_DATA_PACKET_TRACE_MASK")) {
retv = ZooTrace.CLIENT_DATA_PACKET_TRACE_MASK;
} else if (mask.equalsIgnoreCase("CLIENT_PING_TRACE_MASK")) {
retv = ZooTrace.CLIENT_PING_TRACE_MASK;
} else if (mask.equalsIgnoreCase("SERVER_PACKET_TRACE_MASK")) {
retv = ZooTrace.SERVER_PACKET_TRACE_MASK;
} else if (mask.equalsIgnoreCase("SESSION_TRACE_MASK")) {
retv = ZooTrace.SESSION_TRACE_MASK;
} else if (mask.equalsIgnoreCase("EVENT_DELIVERY_TRACE_MASK")) {
retv = ZooTrace.EVENT_DELIVERY_TRACE_MASK;
} else if (mask.equalsIgnoreCase("SERVER_PING_TRACE_MASK")) {
retv = ZooTrace.SERVER_PING_TRACE_MASK;
} else if (mask.equalsIgnoreCase("WARNING_TRACE_MASK")) {
retv = ZooTrace.WARNING_TRACE_MASK;
}
return retv;
}
private static long getMasks(String masks) {
long retv = 0;
StringTokenizer st = new StringTokenizer(masks, "|");
while (st.hasMoreTokens()) {
String mask = st.nextToken().trim();
retv = retv | getMask(mask);
}
return retv;
}
public static void ruok(String host, int port) {
try {
byte[] reqBytes = new byte[4];
ByteBuffer req = ByteBuffer.wrap(reqBytes);
req.putInt(ByteBuffer.wrap("ruok".getBytes()).getInt());
Socket s = null;
s = new Socket();
s.setSoLinger(false, 10);
s.setSoTimeout(20000);
s.connect(new InetSocketAddress(host, port));
InputStream is = s.getInputStream();
OutputStream os = s.getOutputStream();
os.write(reqBytes);
byte[] resBytes = new byte[4];