use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project storm by apache.
the class AdminCommands method initialize.
private static void initialize() {
conf = ConfigUtils.readStormConfig();
nimbusBlobStore = Utils.getNimbusBlobStore(conf, NimbusInfo.fromConf(conf));
List<String> servers = (List<String>) conf.get(Config.STORM_ZOOKEEPER_SERVERS);
Object port = conf.get(Config.STORM_ZOOKEEPER_PORT);
List<ACL> acls = null;
if (Utils.isZkAuthenticationConfiguredStormServer(conf)) {
acls = adminZkAcls();
}
try {
stormClusterState = ClusterUtils.mkStormClusterState(conf, acls, new ClusterStateContext(DaemonType.NIMBUS));
} catch (Exception e) {
LOG.error("admin can't create stormClusterState");
new RuntimeException(e);
}
CuratorFramework zk = Zookeeper.mkClient(conf, servers, port, "", new DefaultWatcherCallBack(), conf);
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project hadoop by apache.
the class CuratorService method createCurator.
/**
* Create a new curator instance off the root path; using configuration
* options provided in the service configuration to set timeouts and
* retry policy.
* @return the newly created creator
*/
private CuratorFramework createCurator() throws IOException {
Configuration conf = getConfig();
createEnsembleProvider();
int sessionTimeout = conf.getInt(KEY_REGISTRY_ZK_SESSION_TIMEOUT, DEFAULT_ZK_SESSION_TIMEOUT);
int connectionTimeout = conf.getInt(KEY_REGISTRY_ZK_CONNECTION_TIMEOUT, DEFAULT_ZK_CONNECTION_TIMEOUT);
int retryTimes = conf.getInt(KEY_REGISTRY_ZK_RETRY_TIMES, DEFAULT_ZK_RETRY_TIMES);
int retryInterval = conf.getInt(KEY_REGISTRY_ZK_RETRY_INTERVAL, DEFAULT_ZK_RETRY_INTERVAL);
int retryCeiling = conf.getInt(KEY_REGISTRY_ZK_RETRY_CEILING, DEFAULT_ZK_RETRY_CEILING);
if (LOG.isDebugEnabled()) {
LOG.debug("Creating CuratorService with connection {}", connectionDescription);
}
CuratorFramework framework;
synchronized (CuratorService.class) {
// set the security options
// build up the curator itself
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
builder.ensembleProvider(ensembleProvider).connectionTimeoutMs(connectionTimeout).sessionTimeoutMs(sessionTimeout).retryPolicy(new BoundedExponentialBackoffRetry(retryInterval, retryCeiling, retryTimes));
// set up the builder AND any JVM context
registrySecurity.applySecurityEnvironment(builder);
//log them
securityConnectionDiagnostics = buildSecurityDiagnostics();
framework = builder.build();
framework.start();
}
return framework;
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project hadoop by apache.
the class TestRMStoreCommands method testRemoveApplicationFromStateStoreCmdForZK.
@Test
public void testRemoveApplicationFromStateStoreCmdForZK() throws Exception {
StateChangeRequestInfo req = new StateChangeRequestInfo(HAServiceProtocol.RequestSource.REQUEST_BY_USER);
try (TestingServer curatorTestingServer = TestZKRMStateStore.setupCuratorServer();
CuratorFramework curatorFramework = TestZKRMStateStore.setupCuratorFramework(curatorTestingServer)) {
Configuration conf = TestZKRMStateStore.createHARMConf("rm1,rm2", "rm1", 1234, false, curatorTestingServer);
ResourceManager rm = new MockRM(conf);
rm.start();
rm.getRMContext().getRMAdminService().transitionToActive(req);
rm.close();
String appId = ApplicationId.newInstance(System.currentTimeMillis(), 1).toString();
String appRootPath = YarnConfiguration.DEFAULT_ZK_RM_STATE_STORE_PARENT_PATH + "/" + ZKRMStateStore.ROOT_ZNODE_NAME + "/" + RMStateStore.RM_APP_ROOT;
String appIdPath = appRootPath + "/" + appId;
curatorFramework.create().forPath(appIdPath);
assertEquals("Application node for " + appId + "should exist", appId, curatorFramework.getChildren().forPath(appRootPath).get(0));
try {
ResourceManager.removeApplication(conf, appId);
} catch (Exception e) {
fail("Exception should not be thrown while removing app from " + "rm state store.");
}
assertTrue("After remove app from store there should be no child nodes" + " in app root path", curatorFramework.getChildren().forPath(appRootPath).isEmpty());
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project flink by apache.
the class ZooKeeperLeaderElectionTest method testMultipleLeaders.
/**
* Tests that the current leader is notified when his leader connection information in ZooKeeper
* are overwritten. The leader must re-establish the correct leader connection information in
* ZooKeeper.
*/
@Test
public void testMultipleLeaders() throws Exception {
final String FAULTY_CONTENDER_URL = "faultyContender";
final String leaderPath = "/leader";
Configuration configuration = new Configuration();
configuration.setString(HighAvailabilityOptions.HA_ZOOKEEPER_QUORUM, testingServer.getConnectString());
configuration.setString(HighAvailabilityOptions.HA_MODE, "zookeeper");
configuration.setString(ConfigConstants.HA_ZOOKEEPER_LEADER_PATH, leaderPath);
ZooKeeperLeaderElectionService leaderElectionService = null;
ZooKeeperLeaderRetrievalService leaderRetrievalService = null;
ZooKeeperLeaderRetrievalService leaderRetrievalService2 = null;
TestingListener listener = new TestingListener();
TestingListener listener2 = new TestingListener();
TestingContender contender;
try {
leaderElectionService = ZooKeeperUtils.createLeaderElectionService(configuration);
leaderRetrievalService = ZooKeeperUtils.createLeaderRetrievalService(configuration);
leaderRetrievalService2 = ZooKeeperUtils.createLeaderRetrievalService(configuration);
contender = new TestingContender(TEST_URL, leaderElectionService);
leaderElectionService.start(contender);
leaderRetrievalService.start(listener);
listener.waitForNewLeader(timeout.toMillis());
assertEquals(listener.getLeaderSessionID(), contender.getLeaderSessionID());
assertEquals(TEST_URL, listener.getAddress());
CuratorFramework client = ZooKeeperUtils.startCuratorFramework(configuration);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeUTF(FAULTY_CONTENDER_URL);
oos.writeObject(null);
oos.close();
// overwrite the current leader address, the leader should notice that and correct it
boolean dataWritten = false;
while (!dataWritten) {
client.delete().forPath(leaderPath);
try {
client.create().forPath(leaderPath, baos.toByteArray());
dataWritten = true;
} catch (KeeperException.NodeExistsException e) {
// this can happen if the leader election service was faster
}
}
leaderRetrievalService2.start(listener2);
listener2.waitForNewLeader(timeout.toMillis());
if (FAULTY_CONTENDER_URL.equals(listener2.getAddress())) {
listener2.waitForNewLeader(timeout.toMillis());
}
assertEquals(listener2.getLeaderSessionID(), contender.getLeaderSessionID());
assertEquals(listener2.getAddress(), contender.getAddress());
} finally {
if (leaderElectionService != null) {
leaderElectionService.stop();
}
if (leaderRetrievalService != null) {
leaderRetrievalService.stop();
}
if (leaderRetrievalService2 != null) {
leaderRetrievalService2.stop();
}
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project flink by apache.
the class ZooKeeperLeaderRetrievalTest method testConnectingAddressRetrievalWithDelayedLeaderElection.
/**
* Tests that LeaderRetrievalUtils.findConnectingAdress finds the correct connecting address
* in case of an old leader address in ZooKeeper and a subsequent election of a new leader.
* The findConnectingAddress should block until the new leader has been elected and his
* address has been written to ZooKeeper.
*/
@Test
public void testConnectingAddressRetrievalWithDelayedLeaderElection() throws Exception {
FiniteDuration timeout = new FiniteDuration(1, TimeUnit.MINUTES);
Configuration config = new Configuration();
long sleepingTime = 1000;
config.setString(HighAvailabilityOptions.HA_MODE, "zookeeper");
config.setString(HighAvailabilityOptions.HA_ZOOKEEPER_QUORUM, testingServer.getConnectString());
LeaderElectionService leaderElectionService = null;
LeaderElectionService faultyLeaderElectionService;
ServerSocket serverSocket;
InetAddress localHost;
Thread thread;
CuratorFramework[] client = new CuratorFramework[2];
try {
client[0] = ZooKeeperUtils.startCuratorFramework(config);
client[1] = ZooKeeperUtils.startCuratorFramework(config);
String wrongHostPort = NetUtils.unresolvedHostAndPortToNormalizedString("1.1.1.1", 1234);
String wrongAddress = JobManager.getRemoteJobManagerAkkaURL(AkkaUtils.getAkkaProtocol(config), wrongHostPort, Option.<String>empty());
try {
localHost = InetAddress.getLocalHost();
serverSocket = new ServerSocket(0, 50, localHost);
} catch (UnknownHostException e) {
// may happen if disconnected. skip test.
System.err.println("Skipping 'testNetworkInterfaceSelection' test.");
return;
} catch (IOException e) {
// may happen in certain test setups, skip test.
System.err.println("Skipping 'testNetworkInterfaceSelection' test.");
return;
}
InetSocketAddress correctInetSocketAddress = new InetSocketAddress(localHost, serverSocket.getLocalPort());
String hostPort = NetUtils.unresolvedHostAndPortToNormalizedString(localHost.getHostName(), correctInetSocketAddress.getPort());
String correctAddress = JobManager.getRemoteJobManagerAkkaURL(AkkaUtils.getAkkaProtocol(config), hostPort, Option.<String>empty());
faultyLeaderElectionService = ZooKeeperUtils.createLeaderElectionService(client[0], config);
TestingContender wrongLeaderAddressContender = new TestingContender(wrongAddress, faultyLeaderElectionService);
faultyLeaderElectionService.start(wrongLeaderAddressContender);
FindConnectingAddress findConnectingAddress = new FindConnectingAddress(config, timeout);
thread = new Thread(findConnectingAddress);
thread.start();
leaderElectionService = ZooKeeperUtils.createLeaderElectionService(client[1], config);
TestingContender correctLeaderAddressContender = new TestingContender(correctAddress, leaderElectionService);
Thread.sleep(sleepingTime);
faultyLeaderElectionService.stop();
leaderElectionService.start(correctLeaderAddressContender);
thread.join();
InetAddress result = findConnectingAddress.getInetAddress();
// check that we can connect to the localHost
Socket socket = new Socket();
try {
// port 0 = let the OS choose the port
SocketAddress bindP = new InetSocketAddress(result, 0);
// machine
socket.bind(bindP);
socket.connect(correctInetSocketAddress, 1000);
} finally {
socket.close();
}
} finally {
if (leaderElectionService != null) {
leaderElectionService.stop();
}
if (client[0] != null) {
client[0].close();
}
if (client[1] != null) {
client[1].close();
}
}
}
Aggregations