This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
905739f
commit 961c2b0
Showing
10 changed files
with
155 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
kafka-impl/src/main/java/io/streamnative/pulsar/handlers/kop/utils/ZooKeeperUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.streamnative.pulsar.handlers.kop.utils; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.zookeeper.CreateMode; | ||
import org.apache.zookeeper.ZooDefs; | ||
import org.apache.zookeeper.ZooKeeper; | ||
import org.apache.zookeeper.data.Stat; | ||
|
||
/** | ||
* Utils for ZooKeeper. | ||
*/ | ||
@Slf4j | ||
public class ZooKeeperUtils { | ||
public static void createPath(ZooKeeper zooKeeper, String zkPath, String subPath, byte[] data) { | ||
try { | ||
if (zooKeeper.exists(zkPath, false) == null) { | ||
zooKeeper.create(zkPath, | ||
data, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); | ||
} | ||
String addSubPath = zkPath + subPath; | ||
if (zooKeeper.exists(addSubPath, false) == null) { | ||
zooKeeper.create(addSubPath, | ||
data, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); | ||
} else { | ||
zooKeeper.setData(addSubPath, data, -1); | ||
} | ||
log.debug("create zk path, addSubPath:{} data:{}.", | ||
addSubPath, new String(data)); | ||
} catch (Exception e) { | ||
log.error("create zookeeper path error", e); | ||
} | ||
} | ||
|
||
public static String getData(ZooKeeper zooKeeper, String zkPath, String subPath) { | ||
String data = ""; | ||
try { | ||
String addSubPath = zkPath + subPath; | ||
Stat zkStat = zooKeeper.exists(addSubPath, true); | ||
if (zkStat != null) { | ||
data = new String(zooKeeper.getData(addSubPath, false, zkStat)); | ||
} | ||
} catch (Exception e) { | ||
log.error("get zookeeper path data error", e); | ||
} | ||
return data; | ||
} | ||
|
||
public static String groupIdPathFormat(String clientHost, String clientId) { | ||
String path = clientHost.split(":")[0] + "-" + clientId; | ||
return path; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters