Repository: activemq-cli-tools
Updated Branches:
  refs/heads/master c5b6230d9 -> 3eb6fdfe6


AMQCLI-6: Add initial CLI for exporter tool


Project: http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/commit/3eb6fdfe
Tree: http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/tree/3eb6fdfe
Diff: http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/diff/3eb6fdfe

Branch: refs/heads/master
Commit: 3eb6fdfe6119998c26d9b3f791e69f48f93720db
Parents: c5b6230
Author: Christopher L. Shannon (cshannon) <[email protected]>
Authored: Tue Mar 7 11:30:21 2017 -0500
Committer: Christopher L. Shannon (cshannon) <[email protected]>
Committed: Tue Mar 7 11:30:21 2017 -0500

----------------------------------------------------------------------
 activemq-kahadb-exporter/pom.xml                |  19 +++-
 .../activemq/cli/kahadb/exporter/Exporter.java  |  65 ++++++++++-
 .../src/main/resources/bin/export               | 107 +++++++++++++++++++
 .../src/main/resources/conf/log4j.properties    |  35 ++++++
 .../src/main/resources/unix-bin.xml             |  67 ++++++++++++
 5 files changed, 288 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/blob/3eb6fdfe/activemq-kahadb-exporter/pom.xml
----------------------------------------------------------------------
diff --git a/activemq-kahadb-exporter/pom.xml b/activemq-kahadb-exporter/pom.xml
index 9bcbb72..e926823 100644
--- a/activemq-kahadb-exporter/pom.xml
+++ b/activemq-kahadb-exporter/pom.xml
@@ -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>

http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/blob/3eb6fdfe/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/Exporter.java
----------------------------------------------------------------------
diff --git 
a/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/Exporter.java
 
b/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/Exporter.java
index 5cb7992..0022d51 100644
--- 
a/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/Exporter.java
+++ 
b/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/Exporter.java
@@ -25,13 +25,11 @@ import java.util.stream.Collectors;
 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,6 +38,14 @@ import org.slf4j.LoggerFactory;
 
 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
  */
@@ -47,9 +53,64 @@ 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 {

http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/blob/3eb6fdfe/activemq-kahadb-exporter/src/main/resources/bin/export
----------------------------------------------------------------------
diff --git a/activemq-kahadb-exporter/src/main/resources/bin/export 
b/activemq-kahadb-exporter/src/main/resources/bin/export
new file mode 100644
index 0000000..0ccc33b
--- /dev/null
+++ b/activemq-kahadb-exporter/src/main/resources/bin/export
@@ -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 "$@"
+

http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/blob/3eb6fdfe/activemq-kahadb-exporter/src/main/resources/conf/log4j.properties
----------------------------------------------------------------------
diff --git a/activemq-kahadb-exporter/src/main/resources/conf/log4j.properties 
b/activemq-kahadb-exporter/src/main/resources/conf/log4j.properties
new file mode 100644
index 0000000..e4f054a
--- /dev/null
+++ b/activemq-kahadb-exporter/src/main/resources/conf/log4j.properties
@@ -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

http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/blob/3eb6fdfe/activemq-kahadb-exporter/src/main/resources/unix-bin.xml
----------------------------------------------------------------------
diff --git a/activemq-kahadb-exporter/src/main/resources/unix-bin.xml 
b/activemq-kahadb-exporter/src/main/resources/unix-bin.xml
new file mode 100644
index 0000000..7c34ae0
--- /dev/null
+++ b/activemq-kahadb-exporter/src/main/resources/unix-bin.xml
@@ -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>

Reply via email to