Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[CURATOR-558] - Updates for ZooKeeper 3.6.0 (#350)
* CURATOR-558 Bring Curator up to ZooKeeper 3.5.6 in preparation for supporting persistent recursive watchers while maintaining background compatability with previous versions of ZK. Added a new module to make sure we maintain compatibility with ZK 3.5.x. ZooKeeper 3.6.0 has some significant changes from previous versions. The reconfig APIs have moved into a new class, ZooKeeperAdmin. This class existed in 3.5.x but wasn't required. Now it is. A bunch of little things changed in the ZK server code which affected Curator's test classes. I moved it all into reflection based calls in Compatibility.java in the test module. We now have modules that test ZK 3.4, 3.5 and 3.6 so we're safe with compatibility. ZooKeeper's MultiTransactionRecord has been removed it seems. That forced CuratorMultiTransactionRecord to be re-written. It's not a public class so hopefully it won't affect anyone. There is a new module, curator-test-zk35. It forces ZooKeeper 3.5.6 and performs selected tests from the other modules to ensure compatibility. Tests annotated with TestNG groups zk35 and zk35Compatibility are tested. Group zk36 is excluded. Note: these tests will only run from Maven. I don't think IntelliJ/Eclipse support the Maven syntax I used. Support persistent watchers in ZK 3.6+ while maintaining background compatability with previous versions of ZK. Added a new module to make sure we maintain comaptibility with ZK 3.5.x * CURATOR-558 - change to version 5.0.0-SNAPSHOT Co-authored-by: randgalt <randgalt@apache.org>
- Loading branch information
Showing
47 changed files
with
781 additions
and
87 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
@@ -0,0 +1,104 @@ | ||
/** | ||
* 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.utils; | ||
|
||
import org.apache.zookeeper.server.quorum.QuorumPeer; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Method; | ||
import java.net.InetSocketAddress; | ||
|
||
/** | ||
* Utils to help with ZK version compatibility | ||
*/ | ||
public class Compatibility | ||
{ | ||
private static final Method getReachableOrOneMethod; | ||
private static final Field addrField; | ||
|
||
private static final Logger log = LoggerFactory.getLogger(Compatibility.class); | ||
|
||
static | ||
{ | ||
Method localGetReachableOrOneMethod; | ||
try | ||
{ | ||
Class<?> multipleAddressesClass = Class.forName("org.apache.zookeeper.server.quorum.MultipleAddresses"); | ||
localGetReachableOrOneMethod = multipleAddressesClass.getMethod("getReachableOrOne"); | ||
log.info("Using org.apache.zookeeper.server.quorum.MultipleAddresses"); | ||
} | ||
catch ( ReflectiveOperationException ignore ) | ||
{ | ||
localGetReachableOrOneMethod = null; | ||
} | ||
getReachableOrOneMethod = localGetReachableOrOneMethod; | ||
|
||
Field localAddrField; | ||
try | ||
{ | ||
localAddrField = QuorumPeer.QuorumServer.class.getField("addr"); | ||
} | ||
catch ( NoSuchFieldException e ) | ||
{ | ||
localAddrField = null; | ||
log.error("Could not get addr field! Reconfiguration fail!"); | ||
} | ||
addrField = localAddrField; | ||
} | ||
|
||
public static boolean hasGetReachableOrOneMethod() | ||
{ | ||
return (getReachableOrOneMethod != null); | ||
} | ||
|
||
public static boolean hasAddrField() | ||
{ | ||
return (addrField != null); | ||
} | ||
|
||
public static String getHostAddress(QuorumPeer.QuorumServer server) | ||
{ | ||
InetSocketAddress address = null; | ||
if ( getReachableOrOneMethod != null ) | ||
{ | ||
try | ||
{ | ||
address = (InetSocketAddress)getReachableOrOneMethod.invoke(server.addr); | ||
} | ||
catch ( Exception e ) | ||
{ | ||
log.error("Could not call getReachableOrOneMethod.invoke({})", server.addr, e); | ||
} | ||
} | ||
else if (addrField != null) | ||
{ | ||
try | ||
{ | ||
address = (InetSocketAddress)addrField.get(server); | ||
} | ||
catch ( Exception e ) | ||
{ | ||
log.error("Could not call addrField.get({})", server, e); | ||
} | ||
} | ||
return (address != null) ? address.getAddress().getHostAddress() : "unknown"; | ||
} | ||
} |
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
@@ -0,0 +1,31 @@ | ||
/** | ||
* 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.utils; | ||
|
||
import org.apache.zookeeper.Watcher; | ||
import org.apache.zookeeper.ZooKeeper; | ||
|
||
public class NonAdminZookeeperFactory implements ZookeeperFactory | ||
{ | ||
@Override | ||
public ZooKeeper newZooKeeper(String connectString, int sessionTimeout, Watcher watcher, boolean canBeReadOnly) throws Exception | ||
{ | ||
return new ZooKeeper(connectString, sessionTimeout, watcher, canBeReadOnly); | ||
} | ||
} |
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
@@ -0,0 +1,40 @@ | ||
/** | ||
* 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; | ||
|
||
import org.apache.curator.test.compatibility.CuratorTestBase; | ||
import org.apache.curator.utils.Compatibility; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
public class TestIs36 extends CuratorTestBase | ||
{ | ||
@Test(groups = zk36Group) | ||
public void testIsZk36() | ||
{ | ||
Assert.assertTrue(Compatibility.hasGetReachableOrOneMethod()); | ||
Assert.assertTrue(Compatibility.hasAddrField()); | ||
} | ||
|
||
@Override | ||
protected void createServer() | ||
{ | ||
// NOP | ||
} | ||
} |
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
@@ -194,6 +194,7 @@ public interface CuratorFramework extends Closeable | ||
|
||
/** | ||
* Start a remove watches builder. | ||
* | ||
* @return builder object | ||
*/ | ||
public RemoveWatchesBuilder watches(); | ||
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
@@ -96,5 +96,10 @@ | ||
/** | ||
* Event sent when client is being closed | ||
*/ | ||
CLOSING | ||
CLOSING, | ||
|
||
/** | ||
* Corresponds to {@link CuratorFramework#watches()} | ||
*/ | ||
ADD_WATCH | ||
} |
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
Oops, something went wrong.