use of org.apache.curator.retry.ExponentialBackoffRetry in project phoenix by apache.
the class ZookeeperRegistry method registerServer.
@Override
public void registerServer(LoadBalanceZookeeperConf configuration, int pqsPort, String zookeeperConnectString, String pqsHost) throws Exception {
this.client = CuratorFrameworkFactory.newClient(zookeeperConnectString, new ExponentialBackoffRetry(1000, 10));
this.client.start();
HostAndPort hostAndPort = HostAndPort.fromParts(pqsHost, pqsPort);
String path = configuration.getFullPathToNode(hostAndPort);
String node = hostAndPort.toString();
this.client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath(path, node.getBytes(StandardCharsets.UTF_8));
Stat stat = this.client.setACL().withACL(configuration.getAcls()).forPath(path);
if (stat != null) {
LOG.info(" node created with right ACL");
} else {
LOG.error("could not create node with right ACL. So, system would exit now.");
throw new RuntimeException(" Unable to connect to Zookeeper");
}
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project SpinalTap by airbnb.
the class SpinalTapStandaloneApp method main.
public static void main(String[] args) throws Exception {
if (args.length != 1) {
log.error("Usage: SpinalTapStandaloneApp <config.yaml>");
System.exit(1);
}
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
SpinalTapStandaloneConfiguration config = objectMapper.readValue(new File(args[0]), SpinalTapStandaloneConfiguration.class);
MySQLPipeFactory mySQLPipeFactory = new MySQLPipeFactory(config.getMysqlUser(), config.getMysqlPassword(), config.getMysqlServerId(), () -> new KafkaDestinationBuilder<>(config.getKafkaProducerConfig()), config.getMysqlSchemaStoreConfig(), new TaggedMetricRegistry());
CuratorFramework zkClient = CuratorFrameworkFactory.builder().namespace(config.getZkNamespace()).connectString(config.getZkConnectionString()).retryPolicy(new ExponentialBackoffRetry(100, 3)).build();
ZookeeperRepositoryFactory zkRepositoryFactory = new ZookeeperRepositoryFactory(zkClient);
zkClient.start();
PipeManager pipeManager = new PipeManager();
for (MysqlConfiguration mysqlSourceConfig : config.getMysqlSources()) {
String sourceName = mysqlSourceConfig.getName();
String partitionName = String.format("%s_0", sourceName);
pipeManager.addPipes(sourceName, partitionName, mySQLPipeFactory.createPipes(mysqlSourceConfig, partitionName, zkRepositoryFactory, 0));
}
Runtime.getRuntime().addShutdownHook(new Thread(() -> pipeManager.stop()));
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project iris by chicc999.
the class ZookeeperService method beforeStart.
@Override
public void beforeStart() throws Exception {
ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(1000, 3);
zk = CuratorFrameworkFactory.builder().connectString(connectionString).retryPolicy(retryPolicy).connectionTimeoutMs(connectionTimeout).sessionTimeoutMs(sessionTimeout).namespace(NAME_SPACE).build();
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project iris by chicc999.
the class MetaManager method beforeStart.
@Override
public void beforeStart() throws Exception {
if (zkClient == null) {
ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(metaConfig.getZookeeperBaseSleepTimeMs(), metaConfig.getZookeeperMaxRetries());
zkClient = CuratorFrameworkFactory.builder().connectString(metaConfig.getConnectionString()).retryPolicy(retryPolicy).connectionTimeoutMs(metaConfig.getConnectionTimeout()).sessionTimeoutMs(metaConfig.getSessionTimeout()).namespace(metaConfig.getNameSpace()).build();
}
// 初始化本地broker
if (this.broker == null) {
this.broker = new Broker(System.getProperty(ServerType.Broker.nameKey()));
}
// 初始化本地所在brokerGroup
if (this.brokerGroup == null) {
this.brokerGroup = new BrokerGroup();
}
this.brokerGroup.addBroker(this.broker);
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project flink by apache.
the class ZooKeeperUtils method startCuratorFramework.
/**
* Starts a {@link CuratorFramework} instance and connects it to the given ZooKeeper quorum.
*
* @param configuration {@link Configuration} object containing the configuration values
* @param fatalErrorHandler {@link FatalErrorHandler} fatalErrorHandler to handle unexpected
* errors of {@link CuratorFramework}
* @return {@link CuratorFrameworkWithUnhandledErrorListener} instance
*/
public static CuratorFrameworkWithUnhandledErrorListener startCuratorFramework(Configuration configuration, FatalErrorHandler fatalErrorHandler) {
checkNotNull(configuration, "configuration");
String zkQuorum = configuration.getValue(HighAvailabilityOptions.HA_ZOOKEEPER_QUORUM);
if (zkQuorum == null || StringUtils.isBlank(zkQuorum)) {
throw new RuntimeException("No valid ZooKeeper quorum has been specified. " + "You can specify the quorum via the configuration key '" + HighAvailabilityOptions.HA_ZOOKEEPER_QUORUM.key() + "'.");
}
int sessionTimeout = configuration.getInteger(HighAvailabilityOptions.ZOOKEEPER_SESSION_TIMEOUT);
int connectionTimeout = configuration.getInteger(HighAvailabilityOptions.ZOOKEEPER_CONNECTION_TIMEOUT);
int retryWait = configuration.getInteger(HighAvailabilityOptions.ZOOKEEPER_RETRY_WAIT);
int maxRetryAttempts = configuration.getInteger(HighAvailabilityOptions.ZOOKEEPER_MAX_RETRY_ATTEMPTS);
String root = configuration.getValue(HighAvailabilityOptions.HA_ZOOKEEPER_ROOT);
String namespace = configuration.getValue(HighAvailabilityOptions.HA_CLUSTER_ID);
boolean disableSaslClient = configuration.getBoolean(SecurityOptions.ZOOKEEPER_SASL_DISABLE);
ACLProvider aclProvider;
ZkClientACLMode aclMode = ZkClientACLMode.fromConfig(configuration);
if (disableSaslClient && aclMode == ZkClientACLMode.CREATOR) {
String errorMessage = "Cannot set ACL role to " + ZkClientACLMode.CREATOR + " since SASL authentication is " + "disabled through the " + SecurityOptions.ZOOKEEPER_SASL_DISABLE.key() + " property";
LOG.warn(errorMessage);
throw new IllegalConfigurationException(errorMessage);
}
if (aclMode == ZkClientACLMode.CREATOR) {
LOG.info("Enforcing creator for ZK connections");
aclProvider = new SecureAclProvider();
} else {
LOG.info("Enforcing default ACL for ZK connections");
aclProvider = new DefaultACLProvider();
}
String rootWithNamespace = generateZookeeperPath(root, namespace);
LOG.info("Using '{}' as Zookeeper namespace.", rootWithNamespace);
final CuratorFrameworkFactory.Builder curatorFrameworkBuilder = CuratorFrameworkFactory.builder().connectString(zkQuorum).sessionTimeoutMs(sessionTimeout).connectionTimeoutMs(connectionTimeout).retryPolicy(new ExponentialBackoffRetry(retryWait, maxRetryAttempts)).namespace(trimStartingSlash(rootWithNamespace)).aclProvider(aclProvider);
if (configuration.get(HighAvailabilityOptions.ZOOKEEPER_TOLERATE_SUSPENDED_CONNECTIONS)) {
curatorFrameworkBuilder.connectionStateErrorPolicy(new SessionConnectionStateErrorPolicy());
}
return startCuratorFramework(curatorFrameworkBuilder, fatalErrorHandler);
}
Aggregations