Search in sources :

Example 1 with AlternateAddress

use of com.couchbase.client.core.config.AlternateAddress in project couchbase-jvm-clients by couchbase.

the class Core method reconfigureBuckets.

/**
 * Contains logic to perform reconfiguration for a bucket config.
 *
 * @param bucketConfigs the flux of bucket configs currently open.
 * @return a mono once reconfiguration for all buckets is complete
 */
private Mono<Void> reconfigureBuckets(final Flux<BucketConfig> bucketConfigs) {
    return bucketConfigs.flatMap(bc -> Flux.fromIterable(bc.nodes()).flatMap(ni -> {
        boolean tls = coreContext.environment().securityConfig().tlsEnabled();
        Set<Map.Entry<ServiceType, Integer>> aServices = null;
        Optional<String> alternateAddress = coreContext.alternateAddress();
        String aHost = null;
        if (alternateAddress.isPresent()) {
            AlternateAddress aa = ni.alternateAddresses().get(alternateAddress.get());
            aHost = aa.hostname();
            aServices = tls ? aa.sslServices().entrySet() : aa.services().entrySet();
        }
        if (isNullOrEmpty(aServices)) {
            aServices = tls ? ni.sslServices().entrySet() : ni.services().entrySet();
        }
        final String alternateHost = aHost;
        final Set<Map.Entry<ServiceType, Integer>> services = aServices;
        Flux<Void> serviceRemoveFlux = Flux.fromIterable(Arrays.asList(ServiceType.values())).filter(s -> {
            for (Map.Entry<ServiceType, Integer> inConfig : services) {
                if (inConfig.getKey() == s) {
                    return false;
                }
            }
            return true;
        }).flatMap(s -> removeServiceFrom(ni.identifier(), s, s.scope() == ServiceScope.BUCKET ? Optional.of(bc.name()) : Optional.empty()).onErrorResume(throwable -> {
            eventBus.publish(new ServiceReconfigurationFailedEvent(coreContext, ni.hostname(), s, throwable));
            return Mono.empty();
        }));
        Flux<Void> serviceAddFlux = Flux.fromIterable(services).flatMap(s -> ensureServiceAt(ni.identifier(), s.getKey(), s.getValue(), s.getKey().scope() == ServiceScope.BUCKET ? Optional.of(bc.name()) : Optional.empty(), Optional.ofNullable(alternateHost)).onErrorResume(throwable -> {
            eventBus.publish(new ServiceReconfigurationFailedEvent(coreContext, ni.hostname(), s.getKey(), throwable));
            return Mono.empty();
        }));
        return Flux.merge(serviceAddFlux, serviceRemoveFlux);
    })).then();
}
Also used : InitGlobalConfigFailedEvent(com.couchbase.client.core.cnc.events.core.InitGlobalConfigFailedEvent) CbCollections.isNullOrEmpty(com.couchbase.client.core.util.CbCollections.isNullOrEmpty) Arrays(java.util.Arrays) RequestTarget(com.couchbase.client.core.msg.RequestTarget) WatchdogInvalidStateIdentifiedEvent(com.couchbase.client.core.cnc.events.core.WatchdogInvalidStateIdentifiedEvent) Request(com.couchbase.client.core.msg.Request) SecureRandom(java.security.SecureRandom) EventBus(com.couchbase.client.core.cnc.EventBus) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KeyValueLocator(com.couchbase.client.core.node.KeyValueLocator) ServiceType(com.couchbase.client.core.service.ServiceType) Duration(java.time.Duration) Map(java.util.Map) CoreCreatedEvent(com.couchbase.client.core.cnc.events.core.CoreCreatedEvent) Locator(com.couchbase.client.core.node.Locator) BucketConfig(com.couchbase.client.core.config.BucketConfig) ReconfigurationIgnoredEvent(com.couchbase.client.core.cnc.events.core.ReconfigurationIgnoredEvent) ShutdownCompletedEvent(com.couchbase.client.core.cnc.events.core.ShutdownCompletedEvent) BucketOpenedEvent(com.couchbase.client.core.cnc.events.core.BucketOpenedEvent) CoreHttpClient(com.couchbase.client.core.endpoint.http.CoreHttpClient) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) GlobalConfigNotFoundException(com.couchbase.client.core.error.GlobalConfigNotFoundException) Set(java.util.Set) CoreEnvironment(com.couchbase.client.core.env.CoreEnvironment) InvalidArgumentException(com.couchbase.client.core.error.InvalidArgumentException) BucketOpenFailedEvent(com.couchbase.client.core.cnc.events.core.BucketOpenFailedEvent) Collectors(java.util.stream.Collectors) RoundRobinLocator(com.couchbase.client.core.node.RoundRobinLocator) Objects(java.util.Objects) ValueRecorder(com.couchbase.client.core.cnc.ValueRecorder) List(java.util.List) Stream(java.util.stream.Stream) BucketClosedEvent(com.couchbase.client.core.cnc.events.core.BucketClosedEvent) Optional(java.util.Optional) ShutdownInitiatedEvent(com.couchbase.client.core.cnc.events.core.ShutdownInitiatedEvent) Response(com.couchbase.client.core.msg.Response) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ClusterConfig(com.couchbase.client.core.config.ClusterConfig) UnsupportedConfigMechanismException(com.couchbase.client.core.error.UnsupportedConfigMechanismException) NodeIdentifier(com.couchbase.client.core.node.NodeIdentifier) Disposable(reactor.core.Disposable) GlobalConfig(com.couchbase.client.core.config.GlobalConfig) AnalyticsLocator(com.couchbase.client.core.node.AnalyticsLocator) ViewLocator(com.couchbase.client.core.node.ViewLocator) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AlternateAddress(com.couchbase.client.core.config.AlternateAddress) HashMap(java.util.HashMap) SeedNode(com.couchbase.client.core.env.SeedNode) BeforeSendRequestCallback(com.couchbase.client.core.callbacks.BeforeSendRequestCallback) ReconfigurationCompletedEvent(com.couchbase.client.core.cnc.events.core.ReconfigurationCompletedEvent) ArrayList(java.util.ArrayList) ServiceState(com.couchbase.client.core.service.ServiceState) TracingIdentifiers(com.couchbase.client.core.cnc.TracingIdentifiers) Stability(com.couchbase.client.core.annotation.Stability) BucketOpenInitiatedEvent(com.couchbase.client.core.cnc.events.core.BucketOpenInitiatedEvent) RequestContext(com.couchbase.client.core.msg.RequestContext) ConfigException(com.couchbase.client.core.error.ConfigException) EndpointDiagnostics(com.couchbase.client.core.diagnostics.EndpointDiagnostics) RequestCanceledException(com.couchbase.client.core.error.RequestCanceledException) CancellationReason(com.couchbase.client.core.msg.CancellationReason) ServiceReconfigurationFailedEvent(com.couchbase.client.core.cnc.events.core.ServiceReconfigurationFailedEvent) ConfigurationProvider(com.couchbase.client.core.config.ConfigurationProvider) ReconfigurationErrorDetectedEvent(com.couchbase.client.core.cnc.events.core.ReconfigurationErrorDetectedEvent) ServiceScope(com.couchbase.client.core.service.ServiceScope) Mono(reactor.core.publisher.Mono) Event(com.couchbase.client.core.cnc.Event) WatchdogRunFailedEvent(com.couchbase.client.core.cnc.events.core.WatchdogRunFailedEvent) TimeUnit(java.util.concurrent.TimeUnit) Flux(reactor.core.publisher.Flux) Node(com.couchbase.client.core.node.Node) AlreadyShutdownException(com.couchbase.client.core.error.AlreadyShutdownException) Authenticator(com.couchbase.client.core.env.Authenticator) DefaultConfigurationProvider(com.couchbase.client.core.config.DefaultConfigurationProvider) AlternateAddress(com.couchbase.client.core.config.AlternateAddress) ServiceReconfigurationFailedEvent(com.couchbase.client.core.cnc.events.core.ServiceReconfigurationFailedEvent)

Aggregations

Stability (com.couchbase.client.core.annotation.Stability)1 BeforeSendRequestCallback (com.couchbase.client.core.callbacks.BeforeSendRequestCallback)1 Event (com.couchbase.client.core.cnc.Event)1 EventBus (com.couchbase.client.core.cnc.EventBus)1 TracingIdentifiers (com.couchbase.client.core.cnc.TracingIdentifiers)1 ValueRecorder (com.couchbase.client.core.cnc.ValueRecorder)1 BucketClosedEvent (com.couchbase.client.core.cnc.events.core.BucketClosedEvent)1 BucketOpenFailedEvent (com.couchbase.client.core.cnc.events.core.BucketOpenFailedEvent)1 BucketOpenInitiatedEvent (com.couchbase.client.core.cnc.events.core.BucketOpenInitiatedEvent)1 BucketOpenedEvent (com.couchbase.client.core.cnc.events.core.BucketOpenedEvent)1 CoreCreatedEvent (com.couchbase.client.core.cnc.events.core.CoreCreatedEvent)1 InitGlobalConfigFailedEvent (com.couchbase.client.core.cnc.events.core.InitGlobalConfigFailedEvent)1 ReconfigurationCompletedEvent (com.couchbase.client.core.cnc.events.core.ReconfigurationCompletedEvent)1 ReconfigurationErrorDetectedEvent (com.couchbase.client.core.cnc.events.core.ReconfigurationErrorDetectedEvent)1 ReconfigurationIgnoredEvent (com.couchbase.client.core.cnc.events.core.ReconfigurationIgnoredEvent)1 ServiceReconfigurationFailedEvent (com.couchbase.client.core.cnc.events.core.ServiceReconfigurationFailedEvent)1 ShutdownCompletedEvent (com.couchbase.client.core.cnc.events.core.ShutdownCompletedEvent)1 ShutdownInitiatedEvent (com.couchbase.client.core.cnc.events.core.ShutdownInitiatedEvent)1 WatchdogInvalidStateIdentifiedEvent (com.couchbase.client.core.cnc.events.core.WatchdogInvalidStateIdentifiedEvent)1 WatchdogRunFailedEvent (com.couchbase.client.core.cnc.events.core.WatchdogRunFailedEvent)1