Search in sources :

Example 1 with ExponentialBackoffRetry

use of org.apache.flink.shaded.curator.org.apache.curator.retry.ExponentialBackoffRetry in project Taier by DTStack.

the class SessionClientFactory method initZkClient.

private void initZkClient() {
    String zkAddress = flinkConfiguration.getValue(HighAvailabilityOptions.HA_ZOOKEEPER_QUORUM);
    if (StringUtils.isBlank(zkAddress)) {
        throw new PluginDefineException("zkAddress is error");
    }
    this.zkClient = CuratorFrameworkFactory.builder().connectString(zkAddress).retryPolicy(new ExponentialBackoffRetry(1000, 3)).connectionTimeoutMs(flinkConfig.getZkConnectionTimeout()).sessionTimeoutMs(flinkConfig.getZkSessionTimeout()).build();
    this.zkClient.start();
    try {
        if (null == this.leaderLatch) {
            this.leaderLatch = getLeaderLatch();
            this.leaderLatch.addListener(new LeaderLatchListener() {

                @Override
                public void isLeader() {
                    isLeader.set(true);
                    LOG.info(">>>My monitor role is Leader.");
                }

                @Override
                public void notLeader() {
                    isLeader.set(false);
                    LOG.info(">>>My monitor role is Follower.");
                }
            });
            this.leaderLatch.start();
            // 这里需要sleep一下,避免leader还未选举完就走到下一步 默认5S
            Thread.sleep(flinkConfig.getMonitorElectionWaitTime());
        }
    } catch (Exception e) {
        LOG.error("join leader election failed.", e);
    }
    LOG.warn("connector zk success...");
}
Also used : PluginDefineException(com.dtstack.taier.pluginapi.exception.PluginDefineException) ExponentialBackoffRetry(org.apache.flink.shaded.curator.org.apache.curator.retry.ExponentialBackoffRetry) LeaderLatchListener(org.apache.flink.shaded.curator.org.apache.curator.framework.recipes.leader.LeaderLatchListener) ProgramMissingJobException(org.apache.flink.client.program.ProgramMissingJobException) FlinkException(org.apache.flink.util.FlinkException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) PluginDefineException(com.dtstack.taier.pluginapi.exception.PluginDefineException)

Aggregations

PluginDefineException (com.dtstack.taier.pluginapi.exception.PluginDefineException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 ProgramMissingJobException (org.apache.flink.client.program.ProgramMissingJobException)1 LeaderLatchListener (org.apache.flink.shaded.curator.org.apache.curator.framework.recipes.leader.LeaderLatchListener)1 ExponentialBackoffRetry (org.apache.flink.shaded.curator.org.apache.curator.retry.ExponentialBackoffRetry)1 FlinkException (org.apache.flink.util.FlinkException)1