You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pegasus.apache.org by la...@apache.org on 2022/11/30 07:41:59 UTC

[incubator-pegasus] branch master updated: refactor: remove zkclient dependency (#1264)

This is an automated email from the ASF dual-hosted git repository.

laiyingchun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git


The following commit(s) were added to refs/heads/master by this push:
     new 607884b40 refactor: remove zkclient dependency (#1264)
607884b40 is described below

commit 607884b40afed5b4f4daa326683106d5a9eb8e70
Author: Duo Zhang <zh...@apache.org>
AuthorDate: Wed Nov 30 15:41:53 2022 +0800

    refactor: remove zkclient dependency (#1264)
---
 java-client/pom.xml                                | 47 +++++++++++++++++-----
 .../org/apache/pegasus/client/PConfigUtil.java     | 23 +++++++----
 .../java/org/apache/pegasus/client/TestPingZK.java | 42 +++++++++++--------
 .../{log4j.properties => simplelogger.properties}  |  9 ++---
 4 files changed, 80 insertions(+), 41 deletions(-)

diff --git a/java-client/pom.xml b/java-client/pom.xml
index 1a881dcb7..87f179552 100644
--- a/java-client/pom.xml
+++ b/java-client/pom.xml
@@ -64,14 +64,14 @@
     <mockito.version>2.24.5</mockito.version>
     <dropwizard.version>3.1.2</dropwizard.version>
     <apache.commons.configuration2.version>2.8.0</apache.commons.configuration2.version>
-    <slf4j.version>1.7.2</slf4j.version>
+    <slf4j.version>1.7.36</slf4j.version>
     <apache.commons.lang3.version>3.1</apache.commons.lang3.version>
-    <zkclient.version>0.2</zkclient.version>
     <json.version>20160810</json.version>
     <netty.version>4.1.42.Final</netty.version>
     <zstd-jni.version>1.3.7-1</zstd-jni.version>
     <libthrift.version>0.11.0</libthrift.version>
     <javax.annotation-api.version>1.3.2</javax.annotation-api.version>
+    <zookeeper.version>3.4.14</zookeeper.version>
   </properties>
 
   <dependencies>
@@ -113,15 +113,47 @@
       <artifactId>slf4j-api</artifactId>
       <version>${slf4j.version}</version>
     </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+      <version>${slf4j.version}</version>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-lang3</artifactId>
       <version>${apache.commons.lang3.version}</version>
     </dependency>
     <dependency>
-      <groupId>com.101tec</groupId>
-      <artifactId>zkclient</artifactId>
-      <version>${zkclient.version}</version>
+      <groupId>org.apache.zookeeper</groupId>
+      <artifactId>zookeeper</artifactId>
+      <version>${zookeeper.version}</version>
+      <exclusions>
+          <exclusion>
+            <groupId>javax.jms</groupId>
+            <artifactId>jms</artifactId>
+          </exclusion>
+          <exclusion>
+            <groupId>com.sun.jdmk</groupId>
+            <artifactId>jmxtools</artifactId>
+          </exclusion>
+          <exclusion>
+            <groupId>com.sun.jmx</groupId>
+            <artifactId>jmxri</artifactId>
+          </exclusion>
+          <exclusion>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+          </exclusion>
+          <exclusion>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+          </exclusion>
+          <exclusion>
+            <groupId>jline</groupId>
+            <artifactId>jline</artifactId>
+          </exclusion>
+        </exclusions>
     </dependency>
     <dependency>
       <groupId>io.netty</groupId>
@@ -227,7 +259,6 @@
             <configuration>
               <artifactSet>
                 <includes>
-                  <include>com.101tec</include>
                   <include>com.google.guava</include>
                   <include>org.apache.thrift</include>
                 </includes>
@@ -237,10 +268,6 @@
                   <pattern>com.google</pattern>
                   <shadedPattern>${pegasus.shade.name}.com.google</shadedPattern>
                 </relocation>
-                <relocation>
-                  <pattern>org.I0Itec</pattern>
-                  <shadedPattern>${pegasus.shade.name}.org.I0Itec</shadedPattern>
-                </relocation>
                 <relocation>
                   <pattern>org.apache.thrift</pattern>
                   <shadedPattern>${pegasus.shade.name}.org.apache.thrift</shadedPattern>
diff --git a/java-client/src/main/java/org/apache/pegasus/client/PConfigUtil.java b/java-client/src/main/java/org/apache/pegasus/client/PConfigUtil.java
index becd71a9f..25e6b4962 100644
--- a/java-client/src/main/java/org/apache/pegasus/client/PConfigUtil.java
+++ b/java-client/src/main/java/org/apache/pegasus/client/PConfigUtil.java
@@ -18,11 +18,13 @@
  */
 package org.apache.pegasus.client;
 
-import java.io.*;
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.FileInputStream;
+import java.io.InputStream;
 import java.util.Properties;
-import org.I0Itec.zkclient.ZkClient;
-import org.I0Itec.zkclient.serialize.BytesPushThroughSerializer;
 import org.apache.commons.lang3.tuple.Pair;
+import org.apache.zookeeper.ZooKeeper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -113,15 +115,20 @@ public class PConfigUtil {
     String server = zkServerAndPath.getKey();
     String path = zkServerAndPath.getValue();
     LOGGER.info("Pegasus load client information from zkServer=" + server + ", zkPath=" + path);
-    ZkClient client =
-        new ZkClient(
-            server, ZK_SESSION_TIMEOUT, ZK_CONNECTION_TIMEOUT, new BytesPushThroughSerializer());
+    ZooKeeper zk = null;
     try {
-      return client.readData(path);
+      zk = new ZooKeeper(server, ZK_SESSION_TIMEOUT, null);
+      return zk.getData(path, false, null);
     } catch (Exception e) {
       throw new PException(e);
     } finally {
-      client.close();
+      if (zk != null) {
+        try {
+          zk.close();
+        } catch (InterruptedException e) {
+          LOGGER.warn("failed to close zookeeper", e);
+        }
+      }
     }
   }
 
diff --git a/java-client/src/test/java/org/apache/pegasus/client/TestPingZK.java b/java-client/src/test/java/org/apache/pegasus/client/TestPingZK.java
index c2d8813f5..96952c0e6 100644
--- a/java-client/src/test/java/org/apache/pegasus/client/TestPingZK.java
+++ b/java-client/src/test/java/org/apache/pegasus/client/TestPingZK.java
@@ -18,11 +18,12 @@
  */
 package org.apache.pegasus.client;
 
+import com.google.common.io.ByteStreams;
 import java.io.InputStream;
 import java.util.Arrays;
-import java.util.Scanner;
-import org.I0Itec.zkclient.ZkClient;
-import org.I0Itec.zkclient.serialize.BytesPushThroughSerializer;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.ZooDefs;
+import org.apache.zookeeper.ZooKeeper;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -30,27 +31,34 @@ import org.junit.Test;
 public class TestPingZK {
 
   @Test
-  public void testPingZK() throws PException {
+  public void testPingZK() throws Exception {
     String zkServer = "127.0.0.1:22181";
     String zkPath = "/databases/pegasus/test-java-client";
     String configPath = "zk://" + zkServer + zkPath;
 
     // init zk config
-    ZkClient zkClient = new ZkClient(zkServer, 30000, 30000, new BytesPushThroughSerializer());
-    String[] components = zkPath.split("/");
-    String curPath = "";
-    for (int i = 0; i < components.length; ++i) {
-      if (components[i].isEmpty()) continue;
-      curPath += "/" + components[i];
-      if (!zkClient.exists(curPath)) {
-        zkClient.createPersistent(curPath);
+    ZooKeeper zk = new ZooKeeper(zkServer, 30000, null);
+    try {
+      String[] components = zkPath.split("/");
+      String curPath = "";
+      for (int i = 0; i < components.length; ++i) {
+        if (components[i].isEmpty()) {
+          continue;
+        }
+        curPath += "/" + components[i];
+        if (zk.exists(curPath, false) == null) {
+          zk.create(curPath, null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+        }
       }
+      byte[] configData;
+      try (InputStream is = PegasusClient.class.getResourceAsStream("/pegasus.properties")) {
+        configData = ByteStreams.toByteArray(is);
+      }
+      System.out.println("write config to " + configPath);
+      zk.setData(zkPath, configData, -1);
+    } finally {
+      zk.close();
     }
-    InputStream is = PegasusClient.class.getResourceAsStream("/pegasus.properties");
-    Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
-    String configData = s.hasNext() ? s.next() : "";
-    System.out.println("write config to " + configPath);
-    zkClient.writeData(zkPath, configData.getBytes());
 
     PegasusClientInterface client = PegasusClientFactory.createClient(configPath);
     String tableName = "temp";
diff --git a/java-client/src/test/resources/log4j.properties b/java-client/src/test/resources/simplelogger.properties
similarity index 73%
rename from java-client/src/test/resources/log4j.properties
rename to java-client/src/test/resources/simplelogger.properties
index cab281246..87fa3b5f7 100644
--- a/java-client/src/test/resources/log4j.properties
+++ b/java-client/src/test/resources/simplelogger.properties
@@ -17,9 +17,6 @@
 # under the License.
 #
 
-log4j.rootLogger=DEBUG, stdout
-
-log4j.appender.stdout=org.apache.log4j.ConsoleAppender
-log4j.appender.stdout.Target=System.out
-log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
+org.slf4j.simpleLogger.defaultLogLevel=debug
+org.slf4j.simpleLogger.showDateTime=true
+org.slf4j.simpleLogger.dateTimeFormat=yyyy/MM/dd HH:mm:ss.SSS


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pegasus.apache.org
For additional commands, e-mail: commits-help@pegasus.apache.org