dxichen commented on code in PR #1666:
URL: https://github.com/apache/samza/pull/1666#discussion_r1189194496


##########
samza-core/src/main/java/org/apache/samza/zk/ZkSystemEnvironmentSetter.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.samza.zk;
+
+import com.google.common.collect.ImmutableList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import org.apache.samza.config.Config;
+
+
+/**
+ * Reads the configs to set zookeeper environment variables for TLS.
+ * 
+ * See 
https://cwiki.apache.org/confluence/display/zookeeper/zookeeper+ssl+user+guide
+ */
+public class ZkSystemEnvironmentSetter {
+
+  private static final String SAMZA_PREFIX = "samza.system.";
+  private static final String ZOOKEEPER_CLIENT_SECURE = 
"zookeeper.client.secure";
+  private static final String ZOOKEEPER_CLIENT_CNXN_SOCKET = 
"zookeeper.clientCnxnSocket";
+  private static final String ZOOKEEPER_SSL_KEY_STORE_LOCATION = 
"zookeeper.ssl.keyStore.location";
+  private static final String ZOOKEEPER_SSL_KEY_STORE_PASSWORD = 
"zookeeper.ssl.keyStore.password";
+  private static final String ZOOKEEPER_SSL_KEY_STORE_TYPE = 
"zookeeper.ssl.keyStore.type";
+  private static final String ZOOKEEPER_SSL_TRUST_STORE_LOCATION = 
"zookeeper.ssl.trustStore.location";
+  private static final String ZOOKEEPER_SSL_TRUST_STORE_PASSWORD = 
"zookeeper.ssl.trustStore.password";
+  private static final String ZOOKEEPER_SSL_TRUST_STORE_TYPE = 
"zookeeper.ssl.trustStore.type";
+
+
+  private static final List<String> ZOOKEEPER_SSL_KEYS = ImmutableList.of(
+    ZOOKEEPER_CLIENT_SECURE,
+    ZOOKEEPER_CLIENT_CNXN_SOCKET,
+    ZOOKEEPER_SSL_KEY_STORE_LOCATION,
+    ZOOKEEPER_SSL_KEY_STORE_PASSWORD,
+    ZOOKEEPER_SSL_KEY_STORE_TYPE,
+    ZOOKEEPER_SSL_TRUST_STORE_LOCATION,
+    ZOOKEEPER_SSL_TRUST_STORE_PASSWORD,
+    ZOOKEEPER_SSL_TRUST_STORE_TYPE);
+
+  private ZkSystemEnvironmentSetter(){}
+
+  public static void setZkEnvironment(Config config) {
+    Map<String, String> zookeeperSettings = new HashMap<>();
+    for(String key: ZOOKEEPER_SSL_KEYS){
+      Optional<String> override =
+          Optional.ofNullable(config.get(SAMZA_PREFIX + key));
+      if(override.isPresent()) {
+        zookeeperSettings.put(key, override.get());
+      }
+    }
+
+    zookeeperSettings.entrySet().stream()

Review Comment:
   I prefer you wrap this in a single functional flatmap call of 
ZOOKEEPER_SSL_KEYS list instead of creating an intermediate map in between. Or 
directly set the system properly instead of writing it to a hashmap.



##########
samza-core/src/test/java/org/apache/samza/zk/TestZkSystemEnvironmentSetter.java:
##########
@@ -0,0 +1,55 @@
+/*
+ * 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.samza.zk;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.samza.config.Config;
+import org.apache.samza.config.MapConfig;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+public class TestZkSystemEnvironmentSetter {
+  @Test
+  public void testDefaultConfig() {
+    Map<String, String> configMap= new HashMap<>();
+    configMap.put("samza.system.zookeeper.client.secure", "true");
+    configMap.put("samza.system.zookeeper.clientCnxnSocket", 
"org.apache.zookeeper.ClientCnxnSocketNetty");
+    configMap.put("samza.system.zookeeper.ssl.keyStore.location", 
"keyStoreLocation");
+    configMap.put("samza.system.zookeeper.ssl.keyStore.password", 
"keyStorePassword");
+    configMap.put("samza.system.zookeeper.ssl.keyStore.type", "PKCS12");
+    configMap.put("samza.system.zookeeper.ssl.trustStore.location", 
"trustStoreLocation");
+    configMap.put("samza.system.zookeeper.ssl.trustStore.password", 
"trustStorePassword");
+    configMap.put("samza.system.zookeeper.ssl.trustStore.type", "JKS");
+    Config config = new MapConfig(configMap);

Review Comment:
   add a unit test where configMap = Collections.EmptyMap()



##########
samza-core/src/main/java/org/apache/samza/zk/ZkSystemEnvironmentSetter.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.samza.zk;
+
+import com.google.common.collect.ImmutableList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import org.apache.samza.config.Config;
+
+
+/**
+ * Reads the configs to set zookeeper environment variables for TLS.
+ * 
+ * See 
https://cwiki.apache.org/confluence/display/zookeeper/zookeeper+ssl+user+guide
+ */
+public class ZkSystemEnvironmentSetter {
+
+  private static final String SAMZA_PREFIX = "samza.system.";
+  private static final String ZOOKEEPER_CLIENT_SECURE = 
"zookeeper.client.secure";
+  private static final String ZOOKEEPER_CLIENT_CNXN_SOCKET = 
"zookeeper.clientCnxnSocket";
+  private static final String ZOOKEEPER_SSL_KEY_STORE_LOCATION = 
"zookeeper.ssl.keyStore.location";
+  private static final String ZOOKEEPER_SSL_KEY_STORE_PASSWORD = 
"zookeeper.ssl.keyStore.password";
+  private static final String ZOOKEEPER_SSL_KEY_STORE_TYPE = 
"zookeeper.ssl.keyStore.type";
+  private static final String ZOOKEEPER_SSL_TRUST_STORE_LOCATION = 
"zookeeper.ssl.trustStore.location";
+  private static final String ZOOKEEPER_SSL_TRUST_STORE_PASSWORD = 
"zookeeper.ssl.trustStore.password";
+  private static final String ZOOKEEPER_SSL_TRUST_STORE_TYPE = 
"zookeeper.ssl.trustStore.type";
+
+
+  private static final List<String> ZOOKEEPER_SSL_KEYS = ImmutableList.of(
+    ZOOKEEPER_CLIENT_SECURE,
+    ZOOKEEPER_CLIENT_CNXN_SOCKET,
+    ZOOKEEPER_SSL_KEY_STORE_LOCATION,
+    ZOOKEEPER_SSL_KEY_STORE_PASSWORD,
+    ZOOKEEPER_SSL_KEY_STORE_TYPE,
+    ZOOKEEPER_SSL_TRUST_STORE_LOCATION,
+    ZOOKEEPER_SSL_TRUST_STORE_PASSWORD,
+    ZOOKEEPER_SSL_TRUST_STORE_TYPE);

Review Comment:
   Should we provide defaults for ease of use?
   type may not be required as it has a default already 
https://cwiki.apache.org/confluence/display/zookeeper/zookeeper+ssl+user+guide



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

Reply via email to