You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@curator.apache.org by GitBox <gi...@apache.org> on 2020/05/10 16:43:48 UTC

[GitHub] [curator] chevaris opened a new pull request #366: [CURATOR-569] API TO HANDLE PROTECTED MODE ZNODE NAMES

chevaris opened a new pull request #366:
URL: https://github.com/apache/curator/pull/366


   I would appreciate your comments on this commit to solve CURATOR-569


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [curator] chevaris commented on pull request #366: [CURATOR-569] API TO HANDLE PROTECTED MODE ZNODE NAMES

Posted by GitBox <gi...@apache.org>.
chevaris commented on pull request #366:
URL: https://github.com/apache/curator/pull/366#issuecomment-629186171


   Thanks for your previous comments.
   New version of the code that should refelect your previous feedback


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [curator] Randgalt commented on a change in pull request #366: [CURATOR-569] API TO HANDLE PROTECTED MODE ZNODE NAMES

Posted by GitBox <gi...@apache.org>.
Randgalt commented on a change in pull request #366:
URL: https://github.com/apache/curator/pull/366#discussion_r424856746



##########
File path: curator-framework/src/main/java/org/apache/curator/framework/imps/ProtectedUtils.java
##########
@@ -0,0 +1,95 @@
+/**
+ * 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.curator.framework.imps;
+
+import java.util.UUID;
+
+import org.apache.curator.framework.api.CreateBuilderMain;
+
+/**
+ * Utility class to handle ZNode names when using {@link CreateBuilderMain#withProtection()}
+ */
+public final class ProtectedUtils {
+
+    private ProtectedUtils() {
+        throw new RuntimeException("Protected Utils is a helper class");
+    }
+
+    /**
+     * First 3 characters in the prefix on ZNode names when using {@link CreateBuilderMain#withProtection()}
+     */
+    public static final String PROTECTED_PREFIX = "_c_";
+
+    /**
+     * Last character used in the prefix on ZNode names when using {@link CreateBuilderMain#withProtection()}
+     */
+    public static final char PROTECTED_SEPARATOR = '-';
+
+    /**
+     * Prefix length on ZNode name when using {@link #withProtection()}
+     */
+    public static final int PROTECTED_PREFIX_WITH_UUID_LENGTH = 
+            PROTECTED_PREFIX.length() 
+            + 36 // UUID canonical text representation produced by {@link UUID#toString()}
+            + 1; // Separator length
+
+    /**
+     * Provides a prefix to be appended to a ZNode name when protected. The method assumes that the provided string
+     * adjusts to the required format
+     * 
+     * @param protectedId canonical text representation of a UUID
+     * @return string that concatenates {@value #PROTECTED_PREFIX}, the given id and {@value #PROTECTED_SEPARATOR}
+     */
+    static String getProtectedPrefix(final String protectedId)

Review comment:
       > Any particular reason?
   
   I get frustrated with other libraries when I want to use something (for debugging, etc.) and it's not public. Any reason not to make this public?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [curator] Randgalt commented on a change in pull request #366: [CURATOR-569] API TO HANDLE PROTECTED MODE ZNODE NAMES

Posted by GitBox <gi...@apache.org>.
Randgalt commented on a change in pull request #366:
URL: https://github.com/apache/curator/pull/366#discussion_r422765176



##########
File path: curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
##########
@@ -751,7 +748,7 @@ public String forPath(String path) throws Exception {
 
     private static String getProtectedPrefix(String protectedId)

Review comment:
       This method should be public as well. Also, move the whole bit (all 4 APIs into a helper util class in the root).




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [curator] TisonKun commented on a change in pull request #366: [CURATOR-569] API TO HANDLE PROTECTED MODE ZNODE NAMES

Posted by GitBox <gi...@apache.org>.
TisonKun commented on a change in pull request #366:
URL: https://github.com/apache/curator/pull/366#discussion_r422768298



##########
File path: curator-framework/src/main/java/org/apache/curator/framework/api/CreateBuilderMain.java
##########
@@ -27,6 +29,56 @@
     Compressible<CreateBackgroundModeStatACLable>,
     Statable<CreateProtectACLCreateModePathAndBytesable<String>>
 {
+
+    /**
+     * First 3 characters in the prefix on ZNode names when using {@link #withProtection()}
+     */
+    static final String PROTECTED_PREFIX = "_c_";
+
+    /**
+     * Last character used in the prefix on ZNode names when using {@link #withProtection()}
+     */
+    static final char PROTECTED_SEPARATOR = '-';
+
+    /**
+     * Prefix length on ZNode name when using {@link #withProtection()}
+     */
+    static final int PROTECTED_PREFIX_WITH_UUID_LENGTH = 
+            PROTECTED_PREFIX.length() 
+            + 36 // UUID canonical text representation produced by {@link UUID#toString()}
+            + 1; // Separator length
+
+    /**
+     * Utility method to determine if a given ZNode name starts with Curator's generated protected prefix.
+     * 
+     * @param znodeName ZNode name
+     * @return {@code true} if the given ZNode name starts with Curator's generated protected prefix
+     */
+    public static boolean isProtectedZNode(final String znodeName) {
+        if (znodeName.length() > PROTECTED_PREFIX_WITH_UUID_LENGTH
+                && znodeName.startsWith(PROTECTED_PREFIX)
+                && znodeName.charAt(PROTECTED_PREFIX_WITH_UUID_LENGTH-1) == PROTECTED_SEPARATOR
+           ) {
+            try {
+                UUID.fromString(znodeName.substring(PROTECTED_PREFIX.length(), PROTECTED_PREFIX_WITH_UUID_LENGTH-2));
+                return true;
+            } catch (IllegalArgumentException e) {
+                // Just false

Review comment:
       nit - (personal taste) explicitly return `false` does no harm and more expressive

##########
File path: curator-framework/src/main/java/org/apache/curator/framework/api/CreateBuilderMain.java
##########
@@ -27,6 +29,56 @@
     Compressible<CreateBackgroundModeStatACLable>,
     Statable<CreateProtectACLCreateModePathAndBytesable<String>>
 {
+
+    /**
+     * First 3 characters in the prefix on ZNode names when using {@link #withProtection()}
+     */
+    static final String PROTECTED_PREFIX = "_c_";
+
+    /**
+     * Last character used in the prefix on ZNode names when using {@link #withProtection()}
+     */
+    static final char PROTECTED_SEPARATOR = '-';
+
+    /**
+     * Prefix length on ZNode name when using {@link #withProtection()}
+     */
+    static final int PROTECTED_PREFIX_WITH_UUID_LENGTH = 
+            PROTECTED_PREFIX.length() 
+            + 36 // UUID canonical text representation produced by {@link UUID#toString()}
+            + 1; // Separator length
+
+    /**
+     * Utility method to determine if a given ZNode name starts with Curator's generated protected prefix.
+     * 
+     * @param znodeName ZNode name
+     * @return {@code true} if the given ZNode name starts with Curator's generated protected prefix
+     */
+    public static boolean isProtectedZNode(final String znodeName) {
+        if (znodeName.length() > PROTECTED_PREFIX_WITH_UUID_LENGTH
+                && znodeName.startsWith(PROTECTED_PREFIX)
+                && znodeName.charAt(PROTECTED_PREFIX_WITH_UUID_LENGTH-1) == PROTECTED_SEPARATOR
+           ) {
+            try {
+                UUID.fromString(znodeName.substring(PROTECTED_PREFIX.length(), PROTECTED_PREFIX_WITH_UUID_LENGTH-2));
+                return true;
+            } catch (IllegalArgumentException e) {
+                // Just false
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Utility method to remove Curator's generated protected prefix if present
+     * 
+     * @param znodeName ZNode name
+     * @return string without Curator's generated protected prefix if present; original string if prefix not present
+     */
+    public static String removeProtectedPrefix(final String znodeName) {

Review comment:
       What if returns `Optional<String>` which equals `isProtectedZNode(znodeName) ? Optional.of(znodeName.substring(PROTECTED_PREFIX_WITH_UUID_LENGTH)) : Optional.empty()`.
   
   For API semantic it fits in "if present" and user can easily get the original sting by `.orElse` but hard to filter non-protected znodes with this API(the user of this method seems interested in protected znodes only.)




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [curator] Randgalt closed pull request #366: [CURATOR-569] API TO HANDLE PROTECTED MODE ZNODE NAMES

Posted by GitBox <gi...@apache.org>.
Randgalt closed pull request #366:
URL: https://github.com/apache/curator/pull/366


   


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [curator] Randgalt commented on pull request #366: [CURATOR-569] API TO HANDLE PROTECTED MODE ZNODE NAMES

Posted by GitBox <gi...@apache.org>.
Randgalt commented on pull request #366:
URL: https://github.com/apache/curator/pull/366#issuecomment-629454862


   merged


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [curator] chevaris commented on a change in pull request #366: [CURATOR-569] API TO HANDLE PROTECTED MODE ZNODE NAMES

Posted by GitBox <gi...@apache.org>.
chevaris commented on a change in pull request #366:
URL: https://github.com/apache/curator/pull/366#discussion_r424922714



##########
File path: curator-framework/src/main/java/org/apache/curator/framework/imps/ProtectedUtils.java
##########
@@ -0,0 +1,95 @@
+/**
+ * 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.curator.framework.imps;
+
+import java.util.UUID;
+
+import org.apache.curator.framework.api.CreateBuilderMain;
+
+/**
+ * Utility class to handle ZNode names when using {@link CreateBuilderMain#withProtection()}
+ */
+public final class ProtectedUtils {
+
+    private ProtectedUtils() {
+        throw new RuntimeException("Protected Utils is a helper class");
+    }
+
+    /**
+     * First 3 characters in the prefix on ZNode names when using {@link CreateBuilderMain#withProtection()}
+     */
+    public static final String PROTECTED_PREFIX = "_c_";
+
+    /**
+     * Last character used in the prefix on ZNode names when using {@link CreateBuilderMain#withProtection()}
+     */
+    public static final char PROTECTED_SEPARATOR = '-';
+
+    /**
+     * Prefix length on ZNode name when using {@link #withProtection()}
+     */
+    public static final int PROTECTED_PREFIX_WITH_UUID_LENGTH = 
+            PROTECTED_PREFIX.length() 
+            + 36 // UUID canonical text representation produced by {@link UUID#toString()}
+            + 1; // Separator length
+
+    /**
+     * Provides a prefix to be appended to a ZNode name when protected. The method assumes that the provided string
+     * adjusts to the required format
+     * 
+     * @param protectedId canonical text representation of a UUID
+     * @return string that concatenates {@value #PROTECTED_PREFIX}, the given id and {@value #PROTECTED_SEPARATOR}
+     */
+    static String getProtectedPrefix(final String protectedId)

Review comment:
       Thx for the explanation. Let me explain my reasoning.
   
   When building libraries, I like to think in this way:
   End user interest -> public APIs
   Library developers Interest -> reduce visibility as much as possible (protected/private APIs)
   
   This method is only interesting for interface implementations, because end users will limit to use withProtection() method. Other methods (normalize...) are interesting for end users to potentially remove non semantic part of the name when watching a ZNode.
   I think that there is no way (maybe I am wrong) for the end user to provide an implementation of the CreateBuilderMain interface.
   
   I will make the methods public, unless I have convinced you :) and you say the opposite




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [curator] Randgalt commented on a change in pull request #366: [CURATOR-569] API TO HANDLE PROTECTED MODE ZNODE NAMES

Posted by GitBox <gi...@apache.org>.
Randgalt commented on a change in pull request #366:
URL: https://github.com/apache/curator/pull/366#discussion_r425769677



##########
File path: curator-framework/src/main/java/org/apache/curator/framework/imps/ProtectedUtils.java
##########
@@ -0,0 +1,157 @@
+/**
+ * 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.curator.framework.imps;
+
+import java.util.Optional;
+import java.util.UUID;
+
+import org.apache.curator.framework.api.CreateBuilderMain;
+import org.apache.curator.utils.ZKPaths;
+
+import com.google.common.annotations.VisibleForTesting;
+
+/**
+ * Utility class to handle ZNode names when using {@link CreateBuilderMain#withProtection()}
+ */
+public final class ProtectedUtils {
+
+    private ProtectedUtils() {
+        throw new RuntimeException("Protected Utils is a helper class");
+    }
+
+    /**
+     * First 3 characters in the prefix on ZNode names when using {@link CreateBuilderMain#withProtection()}
+     */
+    @VisibleForTesting
+    static final String PROTECTED_PREFIX = "_c_";
+
+    /**
+     * Last character used in the prefix on ZNode names when using {@link CreateBuilderMain#withProtection()}
+     */
+    @VisibleForTesting
+    static final char PROTECTED_SEPARATOR = '-';
+
+    /**
+     * Prefix length on ZNode name when using {@link #withProtection()}
+     */
+    @VisibleForTesting
+    static final int PROTECTED_PREFIX_WITH_UUID_LENGTH = 
+            PROTECTED_PREFIX.length() 
+            + 36 // UUID canonical text representation produced by {@link UUID#toString()}
+            + 1; // Separator length
+
+    /**
+     * Provides a prefix to be appended to a ZNode name when protected. The method assumes that the provided string

Review comment:
       nit - should be "prepended". I'll fix it when I merge.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [curator] Randgalt commented on pull request #366: [CURATOR-569] API TO HANDLE PROTECTED MODE ZNODE NAMES

Posted by GitBox <gi...@apache.org>.
Randgalt commented on pull request #366:
URL: https://github.com/apache/curator/pull/366#issuecomment-626455540


   > Looks OK to me. I wonder if this should be moved to some sort of util class though rather than packaging it within the CreateBuilder.
   
   I was thinking the same thing. `CreateBuilder` is hidden and not normally used.


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [curator] Randgalt commented on a change in pull request #366: [CURATOR-569] API TO HANDLE PROTECTED MODE ZNODE NAMES

Posted by GitBox <gi...@apache.org>.
Randgalt commented on a change in pull request #366:
URL: https://github.com/apache/curator/pull/366#discussion_r425153209



##########
File path: curator-framework/src/main/java/org/apache/curator/framework/imps/ProtectedUtils.java
##########
@@ -0,0 +1,95 @@
+/**
+ * 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.curator.framework.imps;
+
+import java.util.UUID;
+
+import org.apache.curator.framework.api.CreateBuilderMain;
+
+/**
+ * Utility class to handle ZNode names when using {@link CreateBuilderMain#withProtection()}
+ */
+public final class ProtectedUtils {
+
+    private ProtectedUtils() {
+        throw new RuntimeException("Protected Utils is a helper class");
+    }
+
+    /**
+     * First 3 characters in the prefix on ZNode names when using {@link CreateBuilderMain#withProtection()}
+     */
+    public static final String PROTECTED_PREFIX = "_c_";
+
+    /**
+     * Last character used in the prefix on ZNode names when using {@link CreateBuilderMain#withProtection()}
+     */
+    public static final char PROTECTED_SEPARATOR = '-';
+
+    /**
+     * Prefix length on ZNode name when using {@link #withProtection()}
+     */
+    public static final int PROTECTED_PREFIX_WITH_UUID_LENGTH = 
+            PROTECTED_PREFIX.length() 
+            + 36 // UUID canonical text representation produced by {@link UUID#toString()}
+            + 1; // Separator length
+
+    /**
+     * Provides a prefix to be appended to a ZNode name when protected. The method assumes that the provided string
+     * adjusts to the required format
+     * 
+     * @param protectedId canonical text representation of a UUID
+     * @return string that concatenates {@value #PROTECTED_PREFIX}, the given id and {@value #PROTECTED_SEPARATOR}
+     */
+    static String getProtectedPrefix(final String protectedId)

Review comment:
       I think you're making a huge assumption there. We really don't know how clients will use the library - I've been very surprised over the years. Further, I've had to go to great lengths to get around stuff that's hidden in ZooKeeper. Remember, this is Java, nothing is truly hidden. You can access anything via reflection. 
   
   tbh - I'd also like to see a method: `public static String extractProtectId(String znodeName)`. Let's give people as many tools as possible.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org