activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cshan...@apache.org
Subject activemq-cli-tools git commit: AMQCLI-3 Add a flag for compression on export
Date Wed, 15 Feb 2017 18:52:50 GMT
Repository: activemq-cli-tools
Updated Branches:
  refs/heads/master 419019cfd -> 76ca845ff


AMQCLI-3 Add a flag for compression on export

Also use a BufferedOutputStream to improve performance of writes


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/76ca845f
Tree: http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/tree/76ca845f
Diff: http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/diff/76ca845f

Branch: refs/heads/master
Commit: 76ca845ffe77b3f1eec265a24f3c8c5918ed3df7
Parents: 419019c
Author: Christopher L. Shannon (cshannon) <christopher.l.shannon@gmail.com>
Authored: Wed Feb 15 13:52:14 2017 -0500
Committer: Christopher L. Shannon (cshannon) <christopher.l.shannon@gmail.com>
Committed: Wed Feb 15 13:52:14 2017 -0500

----------------------------------------------------------------------
 .../activemq/cli/kahadb/exporter/Exporter.java  | 27 +++++++++++++++++---
 .../cli/kahadb/exporter/KahaDBExporter.java     |  7 +++++
 .../cli/kahadb/exporter/ExporterTest.java       | 16 ++----------
 .../src/test/resources/log4j.properties         |  4 +--
 4 files changed, 35 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/blob/76ca845f/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 49d9ae7..4439a88 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
@@ -16,10 +16,11 @@
  */
 package org.apache.activemq.cli.kahadb.exporter;
 
-import static org.junit.Assert.fail;
-
+import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.util.zip.GZIPOutputStream;
 
 import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamWriter;
@@ -32,23 +33,40 @@ import org.apache.activemq.cli.schema.QueueBindingType;
 import org.apache.activemq.command.ActiveMQTopic;
 import org.apache.activemq.command.SubscriptionInfo;
 import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * KahaDB Exporter
  */
 public class Exporter {
 
+    static final Logger LOG = LoggerFactory.getLogger(Exporter.class);
+
     public static void main(String[] args) {
 
+
     }
 
     public static void exportKahaDbStore(final File kahaDbDir, final File artemisXml) throws
Exception {
+        Exporter.exportKahaDbStore(kahaDbDir, artemisXml, false);
+    }
+
+    public static void exportKahaDbStore(final File kahaDbDir, final File artemisXml,
+            boolean compress) throws Exception {
 
         KahaDBPersistenceAdapter adapter = new KahaDBPersistenceAdapter();
         adapter.setDirectory(kahaDbDir);
         adapter.start();
 
-        try(FileOutputStream fos = new FileOutputStream(artemisXml)) {
+        if (artemisXml.exists()) {
+            throw new IllegalStateException("File: " + artemisXml + " already exists");
+        }
+
+        long start = System.currentTimeMillis();
+        try(OutputStream fos = new BufferedOutputStream(compress ? new GZIPOutputStream(
+                new FileOutputStream(artemisXml)) : new FileOutputStream(artemisXml))) {
+
             XMLStreamWriter xmlWriter = XMLOutputFactory.newFactory().createXMLStreamWriter(fos);
             ArtemisJournalMarshaller xmlMarshaller = new ArtemisJournalMarshaller(xmlWriter);
 
@@ -90,5 +108,8 @@ public class Exporter {
         } finally {
             adapter.stop();
         }
+        long end = System.currentTimeMillis();
+
+        LOG.info("Total export time: " + (end - start) + " ms");
     }
 }

http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/blob/76ca845f/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/KahaDBExporter.java
----------------------------------------------------------------------
diff --git a/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/KahaDBExporter.java
b/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/KahaDBExporter.java
index 9c12644..7eee0aa 100644
--- a/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/KahaDBExporter.java
+++ b/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/KahaDBExporter.java
@@ -28,9 +28,13 @@ import org.apache.activemq.store.MessageStore;
 import org.apache.activemq.store.TopicMessageStore;
 import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
 import org.apache.activemq.util.IOExceptionSupport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class KahaDBExporter implements MessageStoreExporter {
 
+    static final Logger LOG = LoggerFactory.getLogger(KahaDBExporter.class);
+
     private final KahaDBPersistenceAdapter adapter;
     private final MessageRecoveryListener recoveryListener;
 
@@ -49,6 +53,7 @@ public class KahaDBExporter implements MessageStoreExporter {
         // loop through all queues and export them
         for (final ActiveMQDestination destination : destinations) {
 
+            LOG.info("Starting export of: " + destination);
             final ActiveMQQueue queue = (ActiveMQQueue) destination;
             final MessageStore messageStore = adapter.createQueueMessageStore(queue);
 
@@ -68,6 +73,8 @@ public class KahaDBExporter implements MessageStoreExporter {
                 dest -> dest.isTopic()).collect(Collectors.toSet());
 
         for (ActiveMQDestination destination : destinations) {
+            LOG.info("Starting export of: " + destination);
+
             final ActiveMQTopic topic = (ActiveMQTopic) destination;
             final TopicMessageStore messageStore = adapter.createTopicMessageStore(topic);
 

http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/blob/76ca845f/activemq-kahadb-exporter/src/test/java/org/apache/activemq/cli/kahadb/exporter/ExporterTest.java
----------------------------------------------------------------------
diff --git a/activemq-kahadb-exporter/src/test/java/org/apache/activemq/cli/kahadb/exporter/ExporterTest.java
b/activemq-kahadb-exporter/src/test/java/org/apache/activemq/cli/kahadb/exporter/ExporterTest.java
index 4a4d47a..6ed9681 100644
--- a/activemq-kahadb-exporter/src/test/java/org/apache/activemq/cli/kahadb/exporter/ExporterTest.java
+++ b/activemq-kahadb-exporter/src/test/java/org/apache/activemq/cli/kahadb/exporter/ExporterTest.java
@@ -20,17 +20,14 @@ import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
 
 import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.IOException;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Set;
 
 import javax.jms.BytesMessage;
 import javax.jms.Connection;
@@ -44,28 +41,19 @@ import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Unmarshaller;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamWriter;
 
-import org.apache.activemq.artemis.api.core.RoutingType;
 import org.apache.activemq.artemis.api.core.TransportConfiguration;
 import org.apache.activemq.artemis.cli.commands.tools.XmlDataImporter;
 import org.apache.activemq.artemis.core.config.Configuration;
-import org.apache.activemq.artemis.core.config.CoreAddressConfiguration;
-import org.apache.activemq.artemis.core.config.CoreQueueConfiguration;
 import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl;
 import org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptorFactory;
 import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;
 import org.apache.activemq.artemis.core.server.ActiveMQServer;
 import org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl;
 import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
-import org.apache.activemq.artemis.jms.client.ActiveMQDestination;
 import org.apache.activemq.broker.ConnectionContext;
-import org.apache.activemq.cli.artemis.schema.ArtemisJournalMarshaller;
-import org.apache.activemq.cli.kahadb.exporter.artemis.ArtemisXmlMessageRecoveryListener;
 import org.apache.activemq.cli.schema.ActivemqJournalType;
 import org.apache.activemq.cli.schema.ObjectFactory;
-import org.apache.activemq.cli.schema.QueueBindingType;
 import org.apache.activemq.command.ActiveMQBytesMessage;
 import org.apache.activemq.command.ActiveMQMapMessage;
 import org.apache.activemq.command.ActiveMQObjectMessage;
@@ -165,7 +153,7 @@ public class ExporterTest {
 
         adapter.stop();
 
-        File xmlFile = storeFolder.newFile();
+        File xmlFile = new File(storeFolder.getRoot().getAbsoluteFile(), "outputXml.xml");
         Exporter.exportKahaDbStore(kahaDbDir, xmlFile);
 
         try (BufferedReader br = new BufferedReader(new FileReader(xmlFile))) {
@@ -281,7 +269,7 @@ public class ExporterTest {
 
         adapter.stop();
 
-        File xmlFile = storeFolder.newFile();
+        File xmlFile = new File(storeFolder.getRoot().getAbsoluteFile(), "outputXml.xml");
         Exporter.exportKahaDbStore(kahaDbDir, xmlFile);
 
 

http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/blob/76ca845f/activemq-kahadb-exporter/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/activemq-kahadb-exporter/src/test/resources/log4j.properties b/activemq-kahadb-exporter/src/test/resources/log4j.properties
index b9e69aa..ba1ef49 100644
--- a/activemq-kahadb-exporter/src/test/resources/log4j.properties
+++ b/activemq-kahadb-exporter/src/test/resources/log4j.properties
@@ -18,9 +18,9 @@
 #
 # The logging properties used during tests..
 #
-log4j.rootLogger=DEBUG, out, stdout
+log4j.rootLogger=INFO, out, stdout
 
-log4j.logger.org.apache.activemq=DEBUG
+log4j.logger.org.apache.activemq=INFO
 
 # CONSOLE appender not used by default
 log4j.appender.stdout=org.apache.log4j.ConsoleAppender


Mime
View raw message