Search in sources :

Example 1 with EtcdCluster

use of io.etcd.jetcd.launcher.EtcdCluster in project jetcd by coreos.

the class EtcdClusterExtension method before.

protected synchronized void before(ExtensionContext context) {
    EtcdCluster oldCluster = CLUSTERS.put(cluster.clusterName(), cluster);
    if (oldCluster != null) {
        oldCluster.stop();
    }
    cluster.start();
}
Also used : EtcdCluster(io.etcd.jetcd.launcher.EtcdCluster)

Example 2 with EtcdCluster

use of io.etcd.jetcd.launcher.EtcdCluster in project jetcd by coreos.

the class EtcdClusterNameResolver method doResolve.

private void doResolve() {
    Listener savedListener;
    synchronized (lock) {
        if (shutdown) {
            return;
        }
        resolving = true;
        savedListener = listener;
    }
    try {
        if (authority == null) {
            throw new RuntimeException("Unable to resolve endpoint " + targetUri);
        }
        EtcdCluster cluster = EtcdClusterExtension.cluster(authority);
        if (cluster == null) {
            throw new RuntimeException("Unable to find cluster " + authority);
        }
        List<EquivalentAddressGroup> servers = cluster.containers().stream().map(container -> {
            return new EquivalentAddressGroup(container.getClientAddress(), Attributes.newBuilder().set(EquivalentAddressGroup.ATTR_AUTHORITY_OVERRIDE, container.node()).build());
        }).collect(Collectors.toList());
        savedListener.onAddresses(servers, Attributes.EMPTY);
    } catch (Exception e) {
        LOGGER.warn("Error wile getting list of servers", e);
        savedListener.onError(Status.NOT_FOUND);
    } finally {
        resolving = false;
    }
}
Also used : Logger(org.slf4j.Logger) Attributes(io.grpc.Attributes) Executor(java.util.concurrent.Executor) LoggerFactory(org.slf4j.LoggerFactory) Collectors(java.util.stream.Collectors) EquivalentAddressGroup(io.grpc.EquivalentAddressGroup) List(java.util.List) EtcdCluster(io.etcd.jetcd.launcher.EtcdCluster) GrpcUtil(io.grpc.internal.GrpcUtil) SharedResourceHolder(io.grpc.internal.SharedResourceHolder) Preconditions(com.google.common.base.Preconditions) URI(java.net.URI) NameResolver(io.grpc.NameResolver) Status(io.grpc.Status) EtcdCluster(io.etcd.jetcd.launcher.EtcdCluster) EquivalentAddressGroup(io.grpc.EquivalentAddressGroup)

Aggregations

EtcdCluster (io.etcd.jetcd.launcher.EtcdCluster)2 Preconditions (com.google.common.base.Preconditions)1 Attributes (io.grpc.Attributes)1 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)1 NameResolver (io.grpc.NameResolver)1 Status (io.grpc.Status)1 GrpcUtil (io.grpc.internal.GrpcUtil)1 SharedResourceHolder (io.grpc.internal.SharedResourceHolder)1 URI (java.net.URI)1 List (java.util.List)1 Executor (java.util.concurrent.Executor)1 Collectors (java.util.stream.Collectors)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1