private static void checkRootAcls(Configuration conf, String path, String user) { int stime = conf.getInt(ZK_DTSM_ZK_SESSION_TIMEOUT, ZK_DTSM_ZK_SESSION_TIMEOUT_DEFAULT), ctime = conf.getInt(ZK_DTSM_ZK_CONNECTION_TIMEOUT, ZK_DTSM_ZK_CONNECTION_TIMEOUT_DEFAULT); CuratorFramework zkClient = CuratorFrameworkFactory.builder().namespace(null) .retryPolicy(new RetryOneTime(10)).sessionTimeoutMs(stime).connectionTimeoutMs(ctime) .ensembleProvider(new FixedEnsembleProvider(conf.get(ZK_DTSM_ZK_CONNECTION_STRING))) .build(); // Hardcoded from a private field in ZKDelegationTokenSecretManager. // We need to check the path under what it sets for namespace, since the namespace is // created with world ACLs. String nsPath = "/" + path + "/ZKDTSMRoot"; Id currentUser = new Id("sasl", user); try { zkClient.start(); List<String> children = zkClient.getChildren().forPath(nsPath); for (String child : children) { String childPath = nsPath + "/" + child; checkAcls(zkClient, currentUser, childPath); } } catch (Exception e) { throw new RuntimeException(e); } finally { zkClient.close(); } }
throw new RuntimeException("Could not Load ZK acls or auth"); zkClient = builder.ensembleProvider(new FixedEnsembleProvider(connString)) .build(); isExternalClient = false;
@Provides @LazySingleton public EnsembleProvider makeEnsembleProvider(CuratorConfig config, ExhibitorConfig exConfig) { if (exConfig.getHosts().isEmpty()) { return new FixedEnsembleProvider(config.getZkHosts()); } return new ExhibitorEnsembleProvider( new Exhibitors( exConfig.getHosts(), exConfig.getRestPort(), newBackupProvider(config.getZkHosts()) ), new DefaultExhibitorRestClient(exConfig.getUseSsl()), exConfig.getRestUriPath(), exConfig.getPollingMs(), new BoundedExponentialBackoffRetry(BASE_SLEEP_TIME_MS, MAX_SLEEP_TIME_MS, MAX_RETRIES) ) { @Override public void start() throws Exception { log.info("Poll the list of zookeeper servers for initial ensemble"); this.pollForInitialEnsemble(); super.start(); } }; }
/** * Set the list of servers to connect to. IMPORTANT: use either this or {@link #ensembleProvider(EnsembleProvider)} * but not both. * * @param connectString list of servers to connect to * @return this */ public Builder connectString(String connectString) { ensembleProvider = new FixedEnsembleProvider(connectString); return this; }
/** * Set the list of servers to connect to. IMPORTANT: use either this or {@link #ensembleProvider(EnsembleProvider)} * but not both. * * @param connectString list of servers to connect to * @return this */ public Builder connectString(String connectString) { ensembleProvider = new FixedEnsembleProvider(connectString); return this; }
/** * * @param connectString list of servers to connect to * @param sessionTimeoutMs session timeout * @param connectionTimeoutMs connection timeout * @param watcher default watcher or null * @param retryPolicy the retry policy to use */ public CuratorZookeeperClient(String connectString, int sessionTimeoutMs, int connectionTimeoutMs, Watcher watcher, RetryPolicy retryPolicy) { this(new DefaultZookeeperFactory(), new FixedEnsembleProvider(connectString), sessionTimeoutMs, connectionTimeoutMs, watcher, retryPolicy, false); }
/** * * @param connectString list of servers to connect to * @param sessionTimeoutMs session timeout * @param connectionTimeoutMs connection timeout * @param watcher default watcher or null * @param retryPolicy the retry policy to use */ public CuratorZookeeperClient(String connectString, int sessionTimeoutMs, int connectionTimeoutMs, Watcher watcher, RetryPolicy retryPolicy) { this(new DefaultZookeeperFactory(), new FixedEnsembleProvider(connectString), sessionTimeoutMs, connectionTimeoutMs, watcher, retryPolicy, false); }
/** * * @param connectString list of servers to connect to * @param sessionTimeoutMs session timeout * @param connectionTimeoutMs connection timeout * @param watcher default watcher or null * @param retryPolicy the retry policy to use */ public CuratorZookeeperClient(String connectString, int sessionTimeoutMs, int connectionTimeoutMs, Watcher watcher, RetryPolicy retryPolicy) { this(new DefaultZookeeperFactory(), new FixedEnsembleProvider(connectString), sessionTimeoutMs, connectionTimeoutMs, watcher, retryPolicy, false); }
/** * * @param connectString list of servers to connect to * @param sessionTimeoutMs session timeout * @param connectionTimeoutMs connection timeout * @param watcher default watcher or null * @param retryPolicy the retry policy to use */ public CuratorZookeeperClient(String connectString, int sessionTimeoutMs, int connectionTimeoutMs, Watcher watcher, RetryPolicy retryPolicy) { this(new DefaultZookeeperFactory(), new FixedEnsembleProvider(connectString), sessionTimeoutMs, connectionTimeoutMs, watcher, retryPolicy, false, new StandardConnectionHandlingPolicy()); }
protected void connect() { log.info("Connecting to ZooKeeper at {}", connection); if (connection == null || connection.trim().isEmpty()) { throw new IllegalArgumentException("Cannot connect to ZooKeeper: missing connection property"); } CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder() .ensembleProvider(new FixedEnsembleProvider(connection)) .connectionTimeoutMs(connectionTimeout) .sessionTimeoutMs(sessionTimeout) .retryPolicy(new RetryNTimes(maxRetry, retryInterval)); if (password != null && password.length() > 0) { builder = builder.authorization("digest", password.getBytes()); } curator = builder.build(); curator.start(); }
public void init() throws Exception { Preconditions.checkArgument(StringUtils.isNotEmpty(zookeeperBrokers), "zookeeperBrokers must not be empty"); final RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); final EnsembleProvider ensembleProvider; if (StringUtils.isNotEmpty(exhibitorAddresses)) { final Collection<String> exhibitorHosts = Arrays.asList(exhibitorAddresses.split("\\s*,\\s*")); final Exhibitors exhibitors = new Exhibitors(exhibitorHosts, exhibitorPort, () -> zookeeperBrokers); final ExhibitorRestClient exhibitorRestClient = new DefaultExhibitorRestClient(); ensembleProvider = new ExhibitorEnsembleProvider(exhibitors, exhibitorRestClient, "/exhibitor/v1/cluster/list", 300000, retryPolicy); ((ExhibitorEnsembleProvider) ensembleProvider).pollForInitialEnsemble(); } else { ensembleProvider = new FixedEnsembleProvider(zookeeperBrokers); } curator = CuratorFrameworkFactory.builder().ensembleProvider(ensembleProvider).retryPolicy(retryPolicy).build(); curator.start(); }
/** * Supply the binding information. * This implementation returns a fixed ensemble bonded to * the quorum supplied by {@link #buildConnectionString()} * @return the binding information */ @Override public BindingInformation supplyBindingInformation() { BindingInformation binding = new BindingInformation(); String connectString = buildConnectionString(); binding.ensembleProvider = new FixedEnsembleProvider(connectString); binding.description = "fixed ZK quorum \"" + connectString + "\""; return binding; }
/** * Supply the binding information. * This implementation returns a fixed ensemble bonded to * the quorum supplied by {@link #buildConnectionString()}. * * @return the binding information */ @Override public BindingInformation supplyBindingInformation() { BindingInformation binding = new BindingInformation(); String connectString = buildConnectionString(); binding.ensembleProvider = new FixedEnsembleProvider(connectString); binding.description = "fixed ZK quorum \"" + connectString + "\""; return binding; }
throw new RuntimeException("Could not Load ZK acls or auth"); zkClient = builder.ensembleProvider(new FixedEnsembleProvider(connString)) .build(); isExternalClient = false;
throw new RuntimeException("Could not Load ZK acls or auth"); zkClient = builder.ensembleProvider(new FixedEnsembleProvider(connString)) .build(); isExternalClient = false;
protected CuratorFramework createCurator() throws KeeperException { log.info(String.format("Creating curator [%s], mode: %s", connection, getCreateMode())); CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder() .ensembleProvider(new FixedEnsembleProvider(connection)) .connectionTimeoutMs(connectionTimeout) .sessionTimeoutMs(sessionTimeout) .retryPolicy(new RetryNTimes(maxRetry, retryInterval)); if (password != null && password.length() > 0) { builder = builder.authorization(getScheme(), getAuth()).aclProvider(aclProvider); } return builder.build(); }
throw new RuntimeException("Could not Load ZK acls or auth"); zkClient = builder.ensembleProvider(new FixedEnsembleProvider(connString)) .build(); isExternalClient = false;
throw new RuntimeException("Could not Load ZK acls or auth"); zkClient = builder.ensembleProvider(new FixedEnsembleProvider(connString)) .build(); isExternalClient = false;
binding.ensembleProvider = new FixedEnsembleProvider(connectString); binding.description = getName() + " reachable at \"" + connectString + "\"";
binding.ensembleProvider = new FixedEnsembleProvider(connectString); binding.description = getName() + " reachable at \"" + connectString + "\"";