Skip to content
Permalink
Browse files
AMQCLI-6: Add initial CLI for exporter tool
  • Loading branch information
cshannon committed Mar 7, 2017
1 parent c5b6230 commit 3eb6fdfe6119998c26d9b3f791e69f48f93720db
Show file tree
Hide file tree
Showing 5 changed files with 288 additions and 5 deletions.
@@ -54,17 +54,14 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

@@ -148,6 +145,22 @@
</xsdOptions>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>source</id>
<configuration>
<descriptor>src/main/resources/unix-bin.xml</descriptor>
<tarLongFileMode>posix</tarLongFileMode>
</configuration>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -25,13 +25,11 @@
import java.util.zip.GZIPOutputStream;

import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

import org.apache.activemq.cli.artemis.schema.ArtemisJournalMarshaller;
import org.apache.activemq.cli.kahadb.exporter.artemis.ArtemisXmlMessageRecoveryListener;
import org.apache.activemq.cli.kahadb.exporter.artemis.ArtemisXmlMetadataExporter;
import org.apache.activemq.store.PersistenceAdapter;
import org.apache.activemq.store.kahadb.FilteredKahaDBPersistenceAdapter;
import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
import org.apache.activemq.store.kahadb.MultiKahaDBPersistenceAdapter;
@@ -40,16 +38,79 @@

import com.google.common.collect.Lists;

import io.airlift.airline.Arguments;
import io.airlift.airline.Cli;
import io.airlift.airline.Cli.CliBuilder;
import io.airlift.airline.Command;
import io.airlift.airline.Help;
import io.airlift.airline.Option;
import io.airlift.airline.OptionType;

/**
* KahaDB Exporter
*/
public class Exporter {

static final Logger LOG = LoggerFactory.getLogger(Exporter.class);

@SuppressWarnings("unchecked")
public static void main(String[] args) {

CliBuilder<Runnable> builder = Cli.<Runnable>builder("export")
.withDescription("Export a KahaDB or MultiKahaDB store to Artemis XML")
.withDefaultCommand(Help.class)
.withCommands(Help.class, ExportKahaDb.class, ExportMultiKahaDb.class);

Cli<Runnable> gitParser = builder.build();

gitParser.parse(args).run();

}

@Command(name = "kahadb", description = "Export KahaDb")
public static class ExportKahaDb implements Runnable
{
@Option(name="-source", type = OptionType.COMMAND, description = "Data store directory location")
public String source;

@Option(name = "-target", type = OptionType.COMMAND, description = "Xml output file location")
public String target;

@Option(name = "-c", type = OptionType.COMMAND, description = "Compress output xml file")
public boolean compress;

/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
LOG.info("Starting store export");
try {
Exporter.exportKahaDbStore(new File(source), new File(target), compress);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}

}
}

@Command(name = "mkahadb", description = "Export MultiKahaDb")
public static class ExportMultiKahaDb extends ExportKahaDb
{

/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
LOG.info("Exporting");
try {
Exporter.exportMultiKahaDbStore(new File(source), new File(target), compress);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}

}
}

public static void exportKahaDbStore(final File kahaDbDir, final File artemisXml) throws Exception {
@@ -0,0 +1,107 @@
#!/usr/bin/env sh
# 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.


# a simple helper to get the current user
setCurrentUser(){
CUSER="`whoami 2>/dev/null`"
# Solaris hack
if [ ! $? -eq 0 ]; then
CUSER="`/usr/ucb/whoami 2>/dev/null`"
fi
}

# get a canonical path, macosx and slowlaris does not support radlink -f :-)
pathCanonical() {
local dst="${1}"
while [ -h "${dst}" ] ; do
ls=`ls -ld "${dst}"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
dst="$link"
else
dst="`dirname "${dst}"`/$link"
fi
done
local bas="`basename "${dst}"`"
local dir="`dirname "${dst}"`"
if [ "$bas" != "$dir" ]; then
dst="`pathCanonical "$dir"`/$bas"
fi
echo "${dst}" | sed -e 's#//#/#g' -e 's#/\./#/#g' -e 's#/[^/]*/\.\./#/#g'
}


# a simple helper to get the activemq installation dir
getActiveMQHome(){
# get the real path to the binary
local REAL_BIN="`pathCanonical $0`"
local REAL_DIR="`dirname $REAL_BIN`/../"
REAL_DIR="`cd $REAL_DIR && pwd -P`"
if [ -z "$REAL_DIR" ];then
echo 'ERROR: unable to find real installtion path fo activemq, you have to define ACTIVEMQ_HOME manually in the config' >&2
exit 1
fi
echo "$REAL_DIR/"

}

# Active MQ installation dir
if [ -z "$ACTIVEMQ_HOME" ] ; then
ACTIVEMQ_HOME="`getActiveMQHome`"
fi

# Active MQ base dir
if [ -z "$ACTIVEMQ_BASE" ] ; then
ACTIVEMQ_BASE="$ACTIVEMQ_HOME"
fi

# Configure user specified classpath here or externally using this variable
if [ -z "$ACTIVEMQ_USER_CLASSPATH" ] ; then
ACTIVEMQ_USER_CLASSPATH=""
fi

# ActiveMQ Classpath configuration
ACTIVEMQ_CLASSPATH="$ACTIVEMQ_BASE/lib/*:$ACTIVEMQ_BASE/conf/:$ACTIVEMQ_USER_CLASSPATH"

ACTIVEMQ_DATA="$ACTIVEMQ_BASE/data/"


if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD=java
fi
fi


JAVA_ARGS=

exec "$JAVACMD" \
$JAVA_ARGS \
-classpath "$ACTIVEMQ_CLASSPATH" \
-Dactivemq.data=${ACTIVEMQ_DATA} \
$DEBUG_ARGS \
org.apache.activemq.cli.kahadb.exporter.Exporter "$@"

@@ -0,0 +1,35 @@
## ---------------------------------------------------------------------------
## 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.
## ---------------------------------------------------------------------------

#
# The logging properties used during tests..
#
log4j.rootLogger=INFO, out, stdout

log4j.logger.org.apache.activemq=INFO

# CONSOLE appender not used by default
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] - %-5p %-30.30c{1} - %m%n

# File appender
log4j.appender.out=org.apache.log4j.FileAppender
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] - %-5p %-30.30c{1} - %m%n
log4j.appender.out.file=${activemq.data}/activemq-exporter.log
log4j.appender.out.append=true
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<assembly>

<id>bin</id>
<formats>
<format>tar.gz</format>
</formats>

<includeBaseDirectory>true</includeBaseDirectory>


<dependencySets>
<dependencySet>
<directoryMode>755</directoryMode>
<fileMode>644</fileMode>
<outputDirectory>lib</outputDirectory>

<unpack>false</unpack>
<useTransitiveDependencies>true</useTransitiveDependencies>
<!-- >includes>
<include>org.apache.activemq:activemq-kahadb-exporter</include>
</includes-->
</dependencySet>
</dependencySets>

<fileSets>
<fileSet>
<directory>src/main/resources/bin</directory>
<outputDirectory>bin</outputDirectory>
<includes>
<include>export</include>
</includes>
<fileMode>0755</fileMode>
<directoryMode>0755</directoryMode>
<lineEnding>unix</lineEnding>
<filtered>false</filtered>
</fileSet>
<fileSet>
<directory>src/main/resources/conf</directory>
<outputDirectory>conf</outputDirectory>
<includes>
<include>log4j.properties</include>
</includes>
<fileMode>0644</fileMode>
<directoryMode>0755</directoryMode>
<lineEnding>unix</lineEnding>
<filtered>false</filtered>
</fileSet>
</fileSets>

</assembly>

0 comments on commit 3eb6fdf

Please sign in to comment.