Search in sources :

Example 1 with SeedNodesUpdatedEvent

use of com.couchbase.client.core.cnc.events.config.SeedNodesUpdatedEvent in project couchbase-jvm-clients by couchbase.

the class DefaultConfigurationProvider method updateSeedNodeList.

/**
 * Helper method to take the current config and update the seed node list with the latest topology.
 *
 * <p>If we have a global config it is used for simplicity reasons. Otherwise we iterate the configs and collect
 * all the nodes to build the list.</p>
 */
private void updateSeedNodeList() {
    ClusterConfig config = currentConfig;
    boolean tlsEnabled = core.context().environment().securityConfig().tlsEnabled();
    if (config.globalConfig() != null) {
        Set<SeedNode> seedNodes = unmodifiableSet(config.globalConfig().portInfos().stream().map(ni -> {
            Map<ServiceType, Integer> ports = tlsEnabled ? ni.sslPorts() : ni.ports();
            if (!ports.containsKey(ServiceType.KV)) {
                // We  only want seed nodes where the KV service is enabled
                return null;
            }
            return SeedNode.create(ni.hostname(), Optional.ofNullable(ports.get(ServiceType.KV)), Optional.ofNullable(ports.get(ServiceType.MANAGER)));
        }).filter(Objects::nonNull).collect(Collectors.toSet()));
        if (!seedNodes.isEmpty()) {
            eventBus.publish(new SeedNodesUpdatedEvent(core.context(), currentSeedNodes(), seedNodes));
            setSeedNodes(seedNodes);
        }
        return;
    }
    Set<SeedNode> seedNodes = unmodifiableSet(config.bucketConfigs().values().stream().flatMap(bc -> bc.nodes().stream()).map(ni -> {
        Map<ServiceType, Integer> ports = tlsEnabled ? ni.sslServices() : ni.services();
        if (!ports.containsKey(ServiceType.KV)) {
            // We  only want seed nodes where the KV service is enabled
            return null;
        }
        return SeedNode.create(ni.hostname(), Optional.ofNullable(ports.get(ServiceType.KV)), Optional.ofNullable(ports.get(ServiceType.MANAGER)));
    }).filter(Objects::nonNull).collect(Collectors.toSet()));
    if (!seedNodes.isEmpty()) {
        eventBus.publish(new SeedNodesUpdatedEvent(core.context(), currentSeedNodes(), seedNodes));
        setSeedNodes(seedNodes);
    }
}
Also used : KeyValueBucketRefresher(com.couchbase.client.core.config.refresher.KeyValueBucketRefresher) Retry(reactor.util.retry.Retry) UnsignedLEB128(com.couchbase.client.core.util.UnsignedLEB128) BucketConfigUpdatedEvent(com.couchbase.client.core.cnc.events.config.BucketConfigUpdatedEvent) ClusterManagerBucketLoader(com.couchbase.client.core.config.loader.ClusterManagerBucketLoader) BestEffortRetryStrategy(com.couchbase.client.core.retry.BestEffortRetryStrategy) JsonNode(com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode) EventBus(com.couchbase.client.core.cnc.EventBus) NetworkResolution(com.couchbase.client.core.env.NetworkResolution) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServiceType(com.couchbase.client.core.service.ServiceType) Duration(java.time.Duration) Map(java.util.Map) GlobalConfigRetriedEvent(com.couchbase.client.core.cnc.events.config.GlobalConfigRetriedEvent) GlobalConfigUpdatedEvent(com.couchbase.client.core.cnc.events.config.GlobalConfigUpdatedEvent) CollectionMapRefreshFailedEvent(com.couchbase.client.core.cnc.events.config.CollectionMapRefreshFailedEvent) Mapper(com.couchbase.client.core.json.Mapper) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) BucketNotFoundDuringLoadException(com.couchbase.client.core.error.BucketNotFoundDuringLoadException) Collectors(java.util.stream.Collectors) ResponseStatus(com.couchbase.client.core.msg.ResponseStatus) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) BucketOpenRetriedEvent(com.couchbase.client.core.cnc.events.config.BucketOpenRetriedEvent) ConfigIgnoredEvent(com.couchbase.client.core.cnc.events.config.ConfigIgnoredEvent) SeedNodesUpdatedEvent(com.couchbase.client.core.cnc.events.config.SeedNodesUpdatedEvent) Optional(java.util.Optional) ClusterManagerBucketRefresher(com.couchbase.client.core.config.refresher.ClusterManagerBucketRefresher) Exceptions(reactor.core.Exceptions) GlobalRefresher(com.couchbase.client.core.config.refresher.GlobalRefresher) UnsupportedConfigMechanismException(com.couchbase.client.core.error.UnsupportedConfigMechanismException) NodeIdentifier(com.couchbase.client.core.node.NodeIdentifier) FluxSink(reactor.core.publisher.FluxSink) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SeedNode(com.couchbase.client.core.env.SeedNode) AtomicReference(java.util.concurrent.atomic.AtomicReference) IndividualGlobalConfigLoadFailedEvent(com.couchbase.client.core.cnc.events.config.IndividualGlobalConfigLoadFailedEvent) ConfigException(com.couchbase.client.core.error.ConfigException) CollectionMapRefreshIgnoredEvent(com.couchbase.client.core.cnc.events.config.CollectionMapRefreshIgnoredEvent) RequestCanceledException(com.couchbase.client.core.error.RequestCanceledException) CancellationReason(com.couchbase.client.core.msg.CancellationReason) CbCollections.copyToUnmodifiableSet(com.couchbase.client.core.util.CbCollections.copyToUnmodifiableSet) BucketNotReadyDuringLoadException(com.couchbase.client.core.error.BucketNotReadyDuringLoadException) GlobalLoader(com.couchbase.client.core.config.loader.GlobalLoader) Mono(reactor.core.publisher.Mono) KeyValueBucketLoader(com.couchbase.client.core.config.loader.KeyValueBucketLoader) GetCollectionIdRequest(com.couchbase.client.core.msg.kv.GetCollectionIdRequest) ReplayProcessor(reactor.core.publisher.ReplayProcessor) Flux(reactor.core.publisher.Flux) SeedNodeOutdatedException(com.couchbase.client.core.error.SeedNodeOutdatedException) CollectionMap(com.couchbase.client.core.io.CollectionMap) Collections.unmodifiableSet(java.util.Collections.unmodifiableSet) AlreadyShutdownException(com.couchbase.client.core.error.AlreadyShutdownException) CollectionIdentifier(com.couchbase.client.core.io.CollectionIdentifier) Core(com.couchbase.client.core.Core) CollectionMapRefreshSucceededEvent(com.couchbase.client.core.cnc.events.config.CollectionMapRefreshSucceededEvent) SeedNode(com.couchbase.client.core.env.SeedNode) Objects(java.util.Objects) SeedNodesUpdatedEvent(com.couchbase.client.core.cnc.events.config.SeedNodesUpdatedEvent) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CollectionMap(com.couchbase.client.core.io.CollectionMap)

Aggregations

Core (com.couchbase.client.core.Core)1 EventBus (com.couchbase.client.core.cnc.EventBus)1 BucketConfigUpdatedEvent (com.couchbase.client.core.cnc.events.config.BucketConfigUpdatedEvent)1 BucketOpenRetriedEvent (com.couchbase.client.core.cnc.events.config.BucketOpenRetriedEvent)1 CollectionMapRefreshFailedEvent (com.couchbase.client.core.cnc.events.config.CollectionMapRefreshFailedEvent)1 CollectionMapRefreshIgnoredEvent (com.couchbase.client.core.cnc.events.config.CollectionMapRefreshIgnoredEvent)1 CollectionMapRefreshSucceededEvent (com.couchbase.client.core.cnc.events.config.CollectionMapRefreshSucceededEvent)1 ConfigIgnoredEvent (com.couchbase.client.core.cnc.events.config.ConfigIgnoredEvent)1 GlobalConfigRetriedEvent (com.couchbase.client.core.cnc.events.config.GlobalConfigRetriedEvent)1 GlobalConfigUpdatedEvent (com.couchbase.client.core.cnc.events.config.GlobalConfigUpdatedEvent)1 IndividualGlobalConfigLoadFailedEvent (com.couchbase.client.core.cnc.events.config.IndividualGlobalConfigLoadFailedEvent)1 SeedNodesUpdatedEvent (com.couchbase.client.core.cnc.events.config.SeedNodesUpdatedEvent)1 ClusterManagerBucketLoader (com.couchbase.client.core.config.loader.ClusterManagerBucketLoader)1 GlobalLoader (com.couchbase.client.core.config.loader.GlobalLoader)1 KeyValueBucketLoader (com.couchbase.client.core.config.loader.KeyValueBucketLoader)1 ClusterManagerBucketRefresher (com.couchbase.client.core.config.refresher.ClusterManagerBucketRefresher)1 GlobalRefresher (com.couchbase.client.core.config.refresher.GlobalRefresher)1 KeyValueBucketRefresher (com.couchbase.client.core.config.refresher.KeyValueBucketRefresher)1 JsonNode (com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode)1 NetworkResolution (com.couchbase.client.core.env.NetworkResolution)1