accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [46/50] [abbrv] git commit: ACCUMULO-378 Utility to just print the replication records repeatedly
Date Wed, 21 May 2014 02:00:05 GMT
ACCUMULO-378 Utility to just print the replication records repeatedly


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/2817f42d
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/2817f42d
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/2817f42d

Branch: refs/heads/ACCUMULO-378
Commit: 2817f42d4d2758b8fe8b9789d992a2ae06ec5486
Parents: 50117b3
Author: Josh Elser <elserj@apache.org>
Authored: Tue May 20 18:47:32 2014 -0400
Committer: Josh Elser <elserj@apache.org>
Committed: Tue May 20 18:47:32 2014 -0400

----------------------------------------------------------------------
 .../replication/PrintReplicationRecords.java    | 98 ++++++++++++++++++++
 .../ReplicationTablesPrinterThread.java         | 51 ++++++++++
 2 files changed, 149 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/2817f42d/core/src/main/java/org/apache/accumulo/core/replication/PrintReplicationRecords.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/replication/PrintReplicationRecords.java
b/core/src/main/java/org/apache/accumulo/core/replication/PrintReplicationRecords.java
new file mode 100644
index 0000000..60aae9c
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/replication/PrintReplicationRecords.java
@@ -0,0 +1,98 @@
+/*
+ * 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.accumulo.core.replication;
+
+import java.io.PrintStream;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Map.Entry;
+
+import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.Scanner;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.client.replication.ReplicationTable;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.metadata.MetadataTable;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema.ReplicationSection;
+import org.apache.accumulo.core.protobuf.ProtobufUtil;
+import org.apache.accumulo.core.replication.proto.Replication.Status;
+import org.apache.accumulo.core.security.Authorizations;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.protobuf.InvalidProtocolBufferException;
+
+/**
+ * 
+ */
+public class PrintReplicationRecords implements Runnable {
+  private static final Logger log = LoggerFactory.getLogger(PrintReplicationRecords.class);
+
+  private Connector conn;
+  private PrintStream out;
+  private SimpleDateFormat sdf;
+
+  public PrintReplicationRecords(Connector conn,PrintStream out) {
+    this.conn = conn;
+    this.out = out;
+    this.sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS");
+  }
+
+  @Override
+  public void run() {
+    Scanner s;
+
+    out.println(sdf.format(new Date()) + " Replication entries from metadata table");
+    out.println("------------------------------------------------------------------");
+    try {
+      s = conn.createScanner(MetadataTable.NAME, Authorizations.EMPTY);
+    } catch (TableNotFoundException e) {
+      log.error("Metadata table does not exist");
+      return;
+    }
+
+    s.setRange(ReplicationSection.getRange());
+    s.fetchColumnFamily(ReplicationSection.COLF);
+    for (Entry<Key,Value> entry : s) {
+      try {
+        out.println(entry.getKey().toStringNoTruncate() + "=" + ProtobufUtil.toString(Status.parseFrom(entry.getValue().get())));
+      } catch (InvalidProtocolBufferException e) {
+        out.println(entry.getKey().toStringNoTruncate() + "= Could not deserialize Status
message");
+      }
+    }
+
+    out.println();
+    out.println(sdf.format(new Date()) + "Replication entries from replication table");
+    out.println("--------------------------------------------------------------------");
+
+    try {
+      s = conn.createScanner(ReplicationTable.NAME, Authorizations.EMPTY);
+    } catch (TableNotFoundException e) {
+      log.error("Replication table does not exist");
+      return;
+    }
+
+    for (Entry<Key,Value> entry : s) {
+      try {
+        out.println(entry.getKey().toStringNoTruncate() + "=" + ProtobufUtil.toString(Status.parseFrom(entry.getValue().get())));
+      } catch (InvalidProtocolBufferException e) {
+        out.println(entry.getKey().toStringNoTruncate() + "= Could not deserialize Status
message");
+      }
+    }    
+  }
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/2817f42d/test/src/main/java/org/apache/accumulo/test/replication/ReplicationTablesPrinterThread.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/accumulo/test/replication/ReplicationTablesPrinterThread.java
b/test/src/main/java/org/apache/accumulo/test/replication/ReplicationTablesPrinterThread.java
new file mode 100644
index 0000000..750557c
--- /dev/null
+++ b/test/src/main/java/org/apache/accumulo/test/replication/ReplicationTablesPrinterThread.java
@@ -0,0 +1,51 @@
+/*
+ * 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.accumulo.test.replication;
+
+import java.io.PrintStream;
+
+import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.replication.PrintReplicationRecords;
+import org.apache.accumulo.core.util.Daemon;
+
+/**
+ * 
+ */
+public class ReplicationTablesPrinterThread extends Daemon {
+
+  private PrintStream out;
+  private PrintReplicationRecords printer;
+
+  public ReplicationTablesPrinterThread(Connector conn, PrintStream out) {
+    printer = new PrintReplicationRecords(conn, out);
+    this.out = out;
+  }
+
+  @Override
+  public void run() {
+    while (true) {
+      printer.run();
+      out.println();
+      try {
+        Thread.sleep(1000);
+      } catch (InterruptedException e) {
+        Thread.currentThread().interrupt();
+        return;
+      }
+    }
+  }
+}


Mime
View raw message