Search in sources :

Example 1 with HostBuilder

use of com.netflix.dyno.connectionpool.HostBuilder in project conductor by Netflix.

the class RedisQueuesDiscoveryProvider method get.

@Override
public RedisQueues get() {
    logger.info("DynoQueueDAO::INIT");
    String domain = configuration.getDomain();
    String cluster = configuration.getCluster();
    final int readConnPort = configuration.getNonQuorumPort();
    EurekaHostsSupplier hostSupplier = new EurekaHostsSupplier(cluster, discoveryClient) {

        @Override
        public List<Host> getHosts() {
            List<Host> hosts = super.getHosts();
            List<Host> updatedHosts = new ArrayList<>(hosts.size());
            hosts.forEach(host -> updatedHosts.add(new HostBuilder().setHostname(host.getHostName()).setIpAddress(host.getIpAddress()).setPort(readConnPort).setRack(host.getRack()).setDatacenter(host.getDatacenter()).setStatus(host.isUp() ? Host.Status.Up : Host.Status.Down).createHost()));
            return updatedHosts;
        }
    };
    DynoJedisClient dynoClient = new DynoJedisClient.Builder().withApplicationName(configuration.getAppId()).withDynomiteClusterName(cluster).withDiscoveryClient(discoveryClient).build();
    DynoJedisClient dynoClientRead = new DynoJedisClient.Builder().withApplicationName(configuration.getAppId()).withDynomiteClusterName(cluster).withHostSupplier(hostSupplier).withConnectionPoolConsistency("DC_ONE").build();
    String region = configuration.getRegion();
    String localDC = configuration.getAvailabilityZone();
    if (localDC == null) {
        throw new Error("Availability zone is not defined.  " + "Ensure Configuration.getAvailabilityZone() returns a non-null and non-empty value.");
    }
    localDC = localDC.replaceAll(region, "");
    ShardSupplier ss = new DynoShardSupplier(dynoClient.getConnPool().getConfiguration().getHostSupplier(), region, localDC);
    RedisQueues queues = new RedisQueues(dynoClient, dynoClientRead, configuration.getQueuePrefix(), ss, 60_000, 60_000);
    logger.info("DynoQueueDAO initialized with prefix " + configuration.getQueuePrefix() + "!");
    return queues;
}
Also used : DynoShardSupplier(com.netflix.dyno.queues.shard.DynoShardSupplier) HostBuilder(com.netflix.dyno.connectionpool.HostBuilder) ArrayList(java.util.ArrayList) DynoJedisClient(com.netflix.dyno.jedis.DynoJedisClient) Host(com.netflix.dyno.connectionpool.Host) RedisQueues(com.netflix.dyno.queues.redis.RedisQueues) HostBuilder(com.netflix.dyno.connectionpool.HostBuilder) ShardSupplier(com.netflix.dyno.queues.ShardSupplier) DynoShardSupplier(com.netflix.dyno.queues.shard.DynoShardSupplier) EurekaHostsSupplier(com.netflix.dyno.contrib.EurekaHostsSupplier)

Example 2 with HostBuilder

use of com.netflix.dyno.connectionpool.HostBuilder in project conductor by Netflix.

the class ConfigurationHostSupplierProvider method parseHostsFrom.

private List<Host> parseHostsFrom(String hostConfig) {
    List<String> hostConfigs = Arrays.asList(hostConfig.split(";"));
    List<Host> hosts = hostConfigs.stream().map(hc -> {
        String[] hostConfigValues = hc.split(":");
        String host = hostConfigValues[0];
        int port = Integer.parseInt(hostConfigValues[1]);
        String rack = hostConfigValues[2];
        if (hostConfigValues.length >= 4) {
            String password = hostConfigValues[3];
            return new HostBuilder().setHostname(host).setPort(port).setRack(rack).setStatus(Host.Status.Up).setPassword(password).createHost();
        }
        return new HostBuilder().setHostname(host).setPort(port).setRack(rack).setStatus(Host.Status.Up).createHost();
    }).collect(Collectors.toList());
    return hosts;
}
Also used : Inject(javax.inject.Inject) Arrays(java.util.Arrays) List(java.util.List) DynomiteConfiguration(com.netflix.conductor.dyno.DynomiteConfiguration) HostBuilder(com.netflix.dyno.connectionpool.HostBuilder) Logger(org.slf4j.Logger) Host(com.netflix.dyno.connectionpool.Host) Provider(javax.inject.Provider) LoggerFactory(org.slf4j.LoggerFactory) HostSupplier(com.netflix.dyno.connectionpool.HostSupplier) Collectors(java.util.stream.Collectors) Host(com.netflix.dyno.connectionpool.Host) HostBuilder(com.netflix.dyno.connectionpool.HostBuilder)

Aggregations

Host (com.netflix.dyno.connectionpool.Host)2 HostBuilder (com.netflix.dyno.connectionpool.HostBuilder)2 DynomiteConfiguration (com.netflix.conductor.dyno.DynomiteConfiguration)1 HostSupplier (com.netflix.dyno.connectionpool.HostSupplier)1 EurekaHostsSupplier (com.netflix.dyno.contrib.EurekaHostsSupplier)1 DynoJedisClient (com.netflix.dyno.jedis.DynoJedisClient)1 ShardSupplier (com.netflix.dyno.queues.ShardSupplier)1 RedisQueues (com.netflix.dyno.queues.redis.RedisQueues)1 DynoShardSupplier (com.netflix.dyno.queues.shard.DynoShardSupplier)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Provider (javax.inject.Provider)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1