Marcosrico commented on code in PR #2343:
URL: https://github.com/apache/helix/pull/2343#discussion_r1082808508
##########
meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/util/ZkMetaClientUtil.java:
##########
@@ -0,0 +1,156 @@
+package org.apache.helix.metaclient.impl.zk.util;
+
+import org.apache.helix.metaclient.api.MetaClientInterface;
+import org.apache.helix.metaclient.api.OpResult;
+import org.apache.helix.metaclient.constants.*;
+import org.apache.helix.zookeeper.zkclient.exception.*;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.Op;
+import org.apache.zookeeper.ZooDefs;
+import org.apache.zookeeper.data.ACL;
+import org.apache.zookeeper.server.EphemeralType;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.ArrayList;
+import java.util.function.Function;
+
+public class ZkMetaClientUtil {
+ //Default ACL value until metaClient Op has ACL of its own.
+ private static final List<ACL> DEFAULT_ACL =
Collections.unmodifiableList(ZooDefs.Ids.OPEN_ACL_UNSAFE);
+
+ private ZkMetaClientUtil(){
+ }
+
+ /**
+ * Helper function for transactionOp. Converts MetaClient Op's into Zk Ops
to execute
+ * zk transactional support.
+ * @param ops
+ * @return
+ */
+ public static List<Op>
metaClientOpToZk(Iterable<org.apache.helix.metaclient.api.Op> ops) {
+ Map<org.apache.helix.metaclient.api.Op.Type,
Function<org.apache.helix.metaclient.api.Op, Op>> opMap = new HashMap<>();
+
+ opMap.put(org.apache.helix.metaclient.api.Op.Type.CREATE, op -> {
+ try {
+ CreateMode mode =
convertMetaClientMode(((org.apache.helix.metaclient.api.Op.Create)
op).getEntryMode());
+ return Op.create(op.getPath(),
((org.apache.helix.metaclient.api.Op.Create) op).getData(), DEFAULT_ACL, mode);
+ } catch (KeeperException e) {
+ throw translateZkExceptionToMetaclientException(ZkException.create(e));
+ }
+ });
+
+ opMap.put(org.apache.helix.metaclient.api.Op.Type.DELETE,
+ op -> Op.delete(op.getPath(),
((org.apache.helix.metaclient.api.Op.Delete) op).getVersion()));
+
+ opMap.put(org.apache.helix.metaclient.api.Op.Type.SET,
+ op -> Op.setData(op.getPath(),
+ ((org.apache.helix.metaclient.api.Op.Set) op).getData(),
((org.apache.helix.metaclient.api.Op.Set) op).getVersion()));
+
+ opMap.put(org.apache.helix.metaclient.api.Op.Type.CHECK,
+ op -> Op.check(op.getPath(),
((org.apache.helix.metaclient.api.Op.Check) op).getVersion()));
+
+ List<Op> zkOps = new ArrayList<>();
+ for (org.apache.helix.metaclient.api.Op op : ops) {
+ Op temp = opMap.get(op.getType()).apply(op);
+ zkOps.add(temp);
+ }
+ return zkOps;
+ }
+
+ private static CreateMode
convertMetaClientMode(MetaClientInterface.EntryMode entryMode) throws
KeeperException {
+ String mode = entryMode.name();
+ if (mode.equals(MetaClientInterface.EntryMode.PERSISTENT.name())) {
+ return CreateMode.fromFlag(0);
+ }
+ if (mode.equals(MetaClientInterface.EntryMode.EPHEMERAL.name())) {
+ return CreateMode.fromFlag(1);
+ }
+ return CreateMode.fromFlag(-1);
Review Comment:
Yes that's correct and sounds good
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]