Skip to content

Commit 3f12e66

Browse files
committed
OMID-310 Make Zookeeper SASL login context name configurable
1 parent 35f734e commit 3f12e66

File tree

10 files changed

+64
-12
lines changed

10 files changed

+64
-12
lines changed

common/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@
4444
<artifactId>curator-framework</artifactId>
4545
</dependency>
4646

47+
<dependency>
48+
<groupId>org.apache.zookeeper</groupId>
49+
<artifactId>zookeeper</artifactId>
50+
<version>${zookeeper.version}</version>
51+
<scope>provided</scope>
52+
</dependency>
53+
4754
<dependency>
4855
<groupId>com.google.protobuf</groupId>
4956
<artifactId>protobuf-java</artifactId>

common/src/main/java/org/apache/omid/zk/ZKUtils.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.curator.framework.CuratorFramework;
2222
import org.apache.curator.framework.CuratorFrameworkFactory;
2323
import org.apache.curator.retry.ExponentialBackoffRetry;
24+
import org.apache.zookeeper.client.ZKClientConfig;
2425
import org.slf4j.Logger;
2526
import org.slf4j.LoggerFactory;
2627

@@ -31,16 +32,25 @@ public class ZKUtils {
3132

3233
private static final Logger LOG = LoggerFactory.getLogger(ZKUtils.class);
3334

34-
public static CuratorFramework initZKClient(String zkCluster, String namespace, int zkConnectionTimeoutInSec)
35+
public static CuratorFramework initZKClient(String zkCluster, String namespace, int zkConnectionTimeoutInSec, String zkLoginContextName)
3536
throws IOException {
3637

3738
LOG.info("Creating Zookeeper Client connecting to {}", zkCluster);
3839

40+
ZKClientConfig zkConfig = new ZKClientConfig();
41+
if (zkLoginContextName != null) {
42+
// TODO should we check if this exists ?
43+
// Or just error out with an unsuccessful connection, as we do now ?
44+
LOG.info("Using Login Context {} for Zookeeper", zkCluster);
45+
zkConfig.setProperty(ZKClientConfig.LOGIN_CONTEXT_NAME_KEY, zkLoginContextName);
46+
}
47+
3948
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
4049
CuratorFramework zkClient = CuratorFrameworkFactory.builder()
4150
.namespace(namespace)
4251
.connectString(zkCluster)
4352
.retryPolicy(retryPolicy)
53+
.zkClientConfig(zkConfig)
4454
.build();
4555

4656
zkClient.start();

hbase-client/src/test/java/org/apache/omid/transaction/TestHALeaseManagementModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class TestHALeaseManagementModule extends AbstractModule {
5454

5555
@Override
5656
protected void configure() {
57-
install(new ZKModule(zkCluster, zkNamespace));
57+
install(new ZKModule(zkCluster, zkNamespace, null));
5858
}
5959

6060
@Provides

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@
168168
<guava.version>32.1.3-jre</guava.version>
169169
<!-- 2.12+ shades guava -->
170170
<curator.version>5.6.0</curator.version>
171+
<zookeeper.version>3.8.4</zookeeper.version>
171172
<snakeyaml.version>2.2</snakeyaml.version>
172173
<beanutils.version>1.9.4</beanutils.version>
173174
<commons-io.version>2.18.0</commons-io.version>

timestamp-storage/src/main/java/org/apache/omid/timestamp/storage/DefaultZKTimestampStorageModule.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ public class DefaultZKTimestampStorageModule extends AbstractModule {
2727

2828
private String zkCluster = "localhost:2181";
2929
private String namespace = "omid";
30+
private String zkLoginContextName;
3031

3132
@Override
3233
public void configure() {
33-
install(new ZKModule(zkCluster, namespace));
34+
install(new ZKModule(zkCluster, namespace, zkLoginContextName));
3435
install(new ZKTimestampStorageModule());
3536
}
3637

@@ -54,4 +55,12 @@ public void setNamespace(String namespace) {
5455
this.namespace = namespace;
5556
}
5657

58+
public String getZkLoginContextName() {
59+
return zkLoginContextName;
60+
}
61+
62+
public void setZkLoginContextName(String zkLoginContextName) {
63+
this.zkLoginContextName = zkLoginContextName;
64+
}
65+
5766
}

timestamp-storage/src/main/java/org/apache/omid/timestamp/storage/ZKModule.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,19 @@
2525
import javax.inject.Singleton;
2626
import java.io.IOException;
2727

28-
//TODO:IK: move to common?
28+
// TODO:IK: move to common?
29+
// The problem is that common doesn't depend on Guice, and we want to keep that that way.
30+
// Ideally, this would be in a new module, something like omid-server-common
2931
public class ZKModule extends AbstractModule {
3032

3133
private final String zkCluster;
3234
private final String namespace;
35+
private final String zkLoginContextName;
3336

34-
public ZKModule(String zkCluster, String namespace) {
37+
public ZKModule(String zkCluster, String namespace, String zkLoginContextName) {
3538
this.zkCluster = zkCluster;
3639
this.namespace = namespace;
40+
this.zkLoginContextName = zkLoginContextName;
3741
}
3842

3943
@Override
@@ -43,7 +47,7 @@ public void configure() {
4347
@Provides
4448
@Singleton
4549
CuratorFramework provideInitializedZookeeperClient() throws IOException {
46-
return ZKUtils.initZKClient(zkCluster, namespace, 10);
50+
return ZKUtils.initZKClient(zkCluster, namespace, 10, zkLoginContextName);
4751
}
4852

4953
// ----------------------------------------------------------------------------------------------------------------

transaction-client/src/main/java/org/apache/omid/tso/client/OmidClientConfiguration.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public enum ConflictDetectionLevel {CELL, ROW}
4545
private String zkCurrentTsoPath;
4646
private String zkNamespace;
4747
private int zkConnectionTimeoutInSecs;
48+
private String zkLoginContextName;
4849

4950
// Communication protocol related params
5051

@@ -202,6 +203,16 @@ public void setZkNamespace(String zkNamespace) {
202203
this.zkNamespace = zkNamespace;
203204
}
204205

206+
public String getZkLoginContextName() {
207+
return zkLoginContextName;
208+
}
209+
210+
@Inject(optional = true)
211+
@Named("omid.ha.zkLoginContextName")
212+
public void setZkLoginContextName(String zkLoginContextName) {
213+
this.zkLoginContextName = zkLoginContextName;
214+
}
215+
205216
public PostCommitMode getPostCommitMode() {
206217
return postCommitMode;
207218
}

transaction-client/src/main/java/org/apache/omid/tso/client/TSOClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ private TSOClient(OmidClientConfiguration omidConf) throws IOException {
135135
case HA:
136136
zkClient = ZKUtils.initZKClient(omidConf.getConnectionString(),
137137
omidConf.getZkNamespace(),
138-
omidConf.getZkConnectionTimeoutInSecs());
138+
omidConf.getZkConnectionTimeoutInSecs(),
139+
omidConf.getZkLoginContextName());
139140
zkCurrentTsoPath = omidConf.getZkCurrentTsoPath();
140141
configureCurrentTSOServerZNodeCache(zkCurrentTsoPath);
141142
String tsoInfo = getCurrentTSOInfoFoundInZK(zkCurrentTsoPath);

tso-server/src/main/java/org/apache/omid/tso/HALeaseManagementModule.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class HALeaseManagementModule extends AbstractModule {
4040
private String currentTsoPath = "/current-tso";
4141
private String zkCluster = "localhost:2181";
4242
private String zkNamespace = "omid";
43+
private String zkLoginContextName;
4344

4445
// ----------------------------------------------------------------------------------------------------------------
4546
// WARNING: Do not remove empty constructor, needed by snake_yaml!
@@ -51,20 +52,20 @@ public HALeaseManagementModule() {
5152

5253
@VisibleForTesting
5354
public HALeaseManagementModule(long leasePeriodInMs, String tsoLeasePath, String currentTsoPath,
54-
String zkCluster, String zkNamespace) {
55+
String zkCluster, String zkNamespace, String zkLoginContextName) {
5556

5657
this.leasePeriodInMs = leasePeriodInMs;
5758
this.tsoLeasePath = tsoLeasePath;
5859
this.currentTsoPath = currentTsoPath;
5960
this.zkCluster = zkCluster;
6061
this.zkNamespace = zkNamespace;
62+
this.zkLoginContextName = zkLoginContextName;
6163

6264
}
6365

6466
@Override
6567
protected void configure() {
66-
67-
install(new ZKModule(zkCluster, zkNamespace));
68+
install(new ZKModule(zkCluster, zkNamespace, zkLoginContextName));
6869

6970
}
7071

@@ -133,4 +134,12 @@ public void setZkNamespace(String zkNamespace) {
133134
this.zkNamespace = zkNamespace;
134135
}
135136

137+
public String getZkLoginContextName() {
138+
return zkLoginContextName;
139+
}
140+
141+
public void setZkLoginContextName(String zkLoginContextName) {
142+
this.zkLoginContextName = zkLoginContextName;
143+
}
144+
136145
}

tso-server/src/test/java/org/apache/omid/tso/client/TestTSOClientConnectionToTSO.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ public void testSuccessfulConnectionToTSOThroughZK() throws Exception {
589589
TSOServerConfig config = new TSOServerConfig();
590590
config.setConflictMapSize(1000);
591591
config.setPort(tsoPortForTest);
592-
config.setLeaseModule(new HALeaseManagementModule(1000, TSO_LEASE_PATH, CURRENT_TSO_PATH, zkClusterForTest, "omid"));
592+
config.setLeaseModule(new HALeaseManagementModule(1000, TSO_LEASE_PATH, CURRENT_TSO_PATH, zkClusterForTest, "omid", null));
593593
injector = Guice.createInjector(new TSOMockModule(config));
594594
LOG.info("Starting TSO");
595595
tsoServer = injector.getInstance(TSOServer.class);
@@ -629,7 +629,7 @@ public void testSuccessOfTSOClientReconnectionsToARestartedTSOWithZKPublishing()
629629
TSOServerConfig config = new TSOServerConfig();
630630
config.setConflictMapSize(1000);
631631
config.setPort(tsoPortForTest);
632-
config.setLeaseModule(new HALeaseManagementModule(1000, TSO_LEASE_PATH, CURRENT_TSO_PATH, zkClusterForTest, "omid"));
632+
config.setLeaseModule(new HALeaseManagementModule(1000, TSO_LEASE_PATH, CURRENT_TSO_PATH, zkClusterForTest, "omid", null));
633633
injector = Guice.createInjector(new TSOMockModule(config));
634634
LOG.info("Starting Initial TSO");
635635
tsoServer = injector.getInstance(TSOServer.class);

0 commit comments

Comments
 (0)