org.apache.curator.ensemble.exhibitor.Exhibitors Java Examples

The following examples show how to use org.apache.curator.ensemble.exhibitor.Exhibitors. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ZkClient.java    From xio with Apache License 2.0 6 votes vote down vote up
public static ZkClient fromExhibitor(Collection<String> serverSet, int restPort) {
  try {
    Exhibitors exhibitors = new Exhibitors(serverSet, restPort, () -> "");
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
    ExhibitorEnsembleProvider ensemble =
        new ExhibitorEnsembleProvider(
            exhibitors,
            new DefaultExhibitorRestClient(),
            "/exhibitor/v1/cluster/list",
            61000,
            retryPolicy);
    ensemble.pollForInitialEnsemble();
    CuratorFramework curatorClient =
        CuratorFrameworkFactory.builder()
            .ensembleProvider(ensemble)
            .retryPolicy(retryPolicy)
            .build();
    return new ZkClient(curatorClient);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example #2
Source File: CuratorFrameworkBuilder.java    From chassis with Apache License 2.0 6 votes vote down vote up
public CuratorFrameworkBuilder withExhibitors(int port, final String... exhibitors) {
    Preconditions.checkNotNull(exhibitors);
    Preconditions.checkArgument(exhibitors.length > 0);
    Preconditions.checkArgument(port > 0);
    if (this.zookeeperConnectionString != null) {
        BootstrapException.zookeeperExhibitorConflict();
    }
    this.exhibitors = new Exhibitors(Arrays.asList(exhibitors), port, new Exhibitors.BackupConnectionStringProvider() {
        @Override
        public String getBackupConnectionString() throws Exception {
            //no backup zookeeper connection string
            return "";
        }
    });
    return this;
}
 
Example #3
Source File: ZooKeeperHolder.java    From nakadi with MIT License 5 votes vote down vote up
private EnsembleProvider createEnsembleProvider() throws Exception {
    switch (conn.getType()) {
        case EXHIBITOR:
            final Exhibitors exhibitors = new Exhibitors(
                    conn.getAddresses().stream().map(AddressPort::getAddress).collect(Collectors.toList()),
                    conn.getAddresses().get(0).getPort(),
                    () -> {
                        throw new RuntimeException("There is no backup connection string (or it is wrong)");
                    });
            final ExhibitorRestClient exhibitorRestClient = new DefaultExhibitorRestClient();
            final ExhibitorEnsembleProvider result = new ExhibitorEnsembleProvider(
                    exhibitors,
                    exhibitorRestClient,
                    "/exhibitor/v1/cluster/list",
                    EXHIBITOR_POLLING_MS,
                    new ExponentialBackoffRetry(EXHIBITOR_RETRY_TIME, EXHIBITOR_RETRY_MAX)) {
                @Override
                public String getConnectionString() {
                    return super.getConnectionString() + conn.getPathPrepared();
                }
            };
            result.pollForInitialEnsemble();
            return result;
        case ZOOKEEPER:
            final String addressesJoined = conn.getAddresses().stream()
                    .map(AddressPort::asAddressPort)
                    .collect(Collectors.joining(","));
            return new ChrootedFixedEnsembleProvider(addressesJoined, conn.getPathPrepared());
        default:
            throw new RuntimeException("Connection type " + conn.getType() + " is not supported");
    }
}
 
Example #4
Source File: AwsDeployment.java    From xio with Apache License 2.0 5 votes vote down vote up
private EnsembleProvider buildEnsembleProvider(ExhibitorConfig config) throws Exception {
  Exhibitors exhibitors = new Exhibitors(config.getHostnames(), config.getRestPort(), () -> "");
  RetryPolicy retryPolicy = buildRetryPolicy(config.getRetryConfig());
  ExhibitorEnsembleProvider ensembleProvider =
      new ExhibitorEnsembleProvider(
          exhibitors,
          new DefaultExhibitorRestClient(),
          config.getRestUriPath(),
          config.getPollingMs(),
          retryPolicy);
  ensembleProvider.pollForInitialEnsemble();
  return ensembleProvider;
}
 
Example #5
Source File: ExhibitorCreator.java    From exhibitor with Apache License 2.0 4 votes vote down vote up
private CuratorFramework makeCurator(final String connectString, int baseSleepTimeMs, int maxRetries, int exhibitorPort, String exhibitorRestPath, int pollingMs)
{
    List<String>    hostnames = Lists.newArrayList();
    String[]        parts = connectString.split(",");
    for ( String spec : parts )
    {
        String[]        subParts = spec.split(":");
        try
        {
            if ( subParts.length != 2 )
            {
                log.error("Bad connection string: " + connectString);
                return null;
            }
        }
        catch ( NumberFormatException e )
        {
            log.error("Bad connection string: " + connectString);
            return null;
        }

        hostnames.add(subParts[0]);
    }

    ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(baseSleepTimeMs, maxRetries);
    Exhibitors.BackupConnectionStringProvider   backupConnectionStringProvider = new Exhibitors.BackupConnectionStringProvider()
    {
        @Override
        public String getBackupConnectionString() throws Exception
        {
            return connectString;
        }
    };

    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory
        .builder()
        .connectString(connectString)
        .retryPolicy(retryPolicy);
    if ( exhibitorPort > 0 )
    {
        Exhibitors                  exhibitors = new Exhibitors(hostnames, exhibitorPort, backupConnectionStringProvider);
        ExhibitorEnsembleProvider   ensembleProvider = new ExhibitorEnsembleProvider(exhibitors, new DefaultExhibitorRestClient(), exhibitorRestPath + "exhibitor/v1/cluster/list", pollingMs, retryPolicy);
        builder = builder.ensembleProvider(ensembleProvider);
    }
    else
    {
        log.warn("Exhibitor on the shared ZooKeeper config ensemble is not being used.");
    }
    return builder.build();
}
 
Example #6
Source File: BootstrapException.java    From chassis with Apache License 2.0 4 votes vote down vote up
public static void zookeeperInitializationFailed(String zookeeperHost, Exhibitors exhibitors, Exception e) {
    throw new ZookeeperInitializationException(zookeeperHost, exhibitors, e);
}
 
Example #7
Source File: BootstrapException.java    From chassis with Apache License 2.0 4 votes vote down vote up
public ZookeeperInitializationException(String zookeeperHost, Exhibitors exhibitors, Exception e) {
    super("Unable to initialize zookeeper configuration for zookeeper " + zookeeperHost + ". Exhibitors:" + ReflectionToStringBuilder.reflectionToString(exhibitors), e);
}
 
Example #8
Source File: KixeyeExhibitorEnsembleProvider.java    From chassis with Apache License 2.0 2 votes vote down vote up
/**
 * @param exhibitors  the current set of exhibitor instances (can be changed later via {@link #setExhibitors(org.apache.curator.ensemble.exhibitor.Exhibitors)})
 * @param restClient  the rest client to use (use {@link org.apache.curator.ensemble.exhibitor.DefaultExhibitorRestClient} for most cases)
 * @param restUriPath the path of the REST call used to get the server set. Usually: <code>/exhibitor/v1/cluster/list</code>
 * @param pollingMs   how ofter to poll the exhibitors for the list
 * @param retryPolicy retry policy to use when connecting to the exhibitors
 */
public KixeyeExhibitorEnsembleProvider(Exhibitors exhibitors, ExhibitorRestClient restClient, String restUriPath, int pollingMs, RetryPolicy retryPolicy) {
    super(exhibitors, restClient, restUriPath, pollingMs, retryPolicy);
    this.initialExhibitors = exhibitors;
}