Skip to content

Commit

Permalink
finish r/m of -f option. use log4j of WARN,stderr so that doesn't get…
Browse files Browse the repository at this point in the history
… in the way of redirecting stdout.

patch by jbellis; reviewed by eevans for CASSANDRA-766

git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@908652 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
jbellis committed Feb 10, 2010
1 parent 509d630 commit ef6f023
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 33 deletions.
4 changes: 3 additions & 1 deletion bin/clustertool
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ case "`uname`" in
;;
esac

$JAVA -cp $CLASSPATH org.apache.cassandra.tools.ClusterCmd $@
$JAVA -cp $CLASSPATH \
-Dlog4j.configuration=log4j-tools.properties \
org.apache.cassandra.tools.ClusterCmd $@

# vi:ai sw=4 ts=4 tw=0 et
1 change: 1 addition & 0 deletions bin/json2sstable
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ if [ -z $CLASSPATH ]; then
fi

$JAVA -cp $CLASSPATH -Dstorage-config=$CASSANDRA_CONF \
-Dlog4j.configuration=log4j-tools.properties \
org.apache.cassandra.tools.SSTableImport "$@"

# vi:ai sw=4 ts=4 tw=0 et
1 change: 1 addition & 0 deletions bin/nodetool
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ case "`uname`" in
esac

$JAVA -cp $CLASSPATH -Dstorage-config=$CASSANDRA_CONF \
-Dlog4j.configuration=log4j-tools.properties \
org.apache.cassandra.tools.NodeCmd $@

# vi:ai sw=4 ts=4 tw=0 et
1 change: 1 addition & 0 deletions bin/sstable2json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ if [ -z $CLASSPATH ]; then
fi

$JAVA -cp $CLASSPATH -Dstorage-config=$CASSANDRA_CONF \
-Dlog4j.configuration=log4j-tools.properties \
org.apache.cassandra.tools.SSTableExport "$@"

# vi:ai sw=4 ts=4 tw=0 et
1 change: 1 addition & 0 deletions bin/sstablekeys
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ if [ $# -eq "0" ]; then
fi

$JAVA -cp $CLASSPATH -Dstorage-config=$CASSANDRA_CONF \
-Dlog4j.configuration=log4j-tools.properties \
org.apache.cassandra.tools.SSTableExport "$1" -e

# vi:ai sw=4 ts=4 tw=0 et
27 changes: 27 additions & 0 deletions conf/log4j-tools.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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.

# for production, you should probably set the root to INFO
# and the pattern to %c instead of %l. (%l is slower.)

# output messages into a rolling log file as well as stdout
log4j.rootLogger=WARN,stderr

# stderr
log4j.appender.stderr=org.apache.log4j.ConsoleAppender
log4j.appender.stderr.target=System.err
log4j.appender.stderr.layout=org.apache.log4j.PatternLayout
log4j.appender.stderr.layout.ConversionPattern=%5p %d{HH:mm:ss,SSS} %m%n
41 changes: 9 additions & 32 deletions src/java/org/apache/cassandra/tools/SSTableExport.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public class SSTableExport
{
private static int INPUT_FILE_BUFFER_SIZE = 8 * 1024 * 1024;

private static final String OUTFILE_OPTION = "f";
private static final String KEY_OPTION = "k";
private static final String ENUMERATEKEYS_OPTION = "e";
private static Options options;
Expand All @@ -55,19 +54,13 @@ public class SSTableExport
static
{
options = new Options();
Option optOutfile = new Option(OUTFILE_OPTION, true, "output file");
optOutfile.setRequired(false);
options.addOption(optOutfile);


Option optKey = new Option(KEY_OPTION, true, "Row key");
// Number of times -k <key> can be passed on the command line.
optKey.setArgs(500);
optKey.setRequired(false);
options.addOption(optKey);

options = new Options();
Option optEnumerate = new Option(ENUMERATEKEYS_OPTION, false, "enumerate keys only");
optOutfile.setRequired(false);
options.addOption(optEnumerate);
}

Expand Down Expand Up @@ -327,8 +320,7 @@ public static void export(String ssTableFile) throws IOException
*/
public static void main(String[] args) throws IOException
{
String usage = String.format("Usage: %s [-f outfile] <sstable> [-k key [-k key [...]]]%n",
SSTableExport.class.getName());
String usage = String.format("Usage: %s <sstable> [-k key [-k key [...]]]%n", SSTableExport.class.getName());

CommandLineParser parser = new PosixParser();
try
Expand All @@ -341,7 +333,6 @@ public static void main(String[] args) throws IOException
System.exit(1);
}

String outFile = cmd.getOptionValue(OUTFILE_OPTION);

if (cmd.getArgs().length != 1)
{
Expand All @@ -354,27 +345,13 @@ public static void main(String[] args) throws IOException
String[] keys = cmd.getOptionValues(KEY_OPTION);
String ssTableFileName = new File(cmd.getArgs()[0]).getAbsolutePath();

if (outFile != null)
{
if (cmd.hasOption(ENUMERATEKEYS_OPTION))
enumeratekeys(ssTableFileName, outFile);
else {
if ((keys != null) && (keys.length > 0))
export(ssTableFileName, outFile, keys);
else
export(ssTableFileName, outFile);
}
}
else
{
if (cmd.hasOption(ENUMERATEKEYS_OPTION))
enumeratekeys(ssTableFileName, System.out);
else {
if ((keys != null) && (keys.length > 0))
export(ssTableFileName, System.out, keys);
else
export(ssTableFileName);
}
if (cmd.hasOption(ENUMERATEKEYS_OPTION))
enumeratekeys(ssTableFileName, System.out);
else {
if ((keys != null) && (keys.length > 0))
export(ssTableFileName, System.out, keys);
else
export(ssTableFileName);
}
System.exit(0);
}
Expand Down

0 comments on commit ef6f023

Please sign in to comment.