Search in sources :

Example 6 with NodeIdentifier

use of com.couchbase.client.core.node.NodeIdentifier in project couchbase-jvm-clients by couchbase.

the class BaseBucketLoaderTest method loadsAndParsesConfig.

@Test
void loadsAndParsesConfig() {
    BucketLoader loader = new BaseBucketLoader(core, SERVICE) {

        @Override
        protected Mono<byte[]> discoverConfig(NodeIdentifier seed, String bucket) {
            return Mono.just(readResource("../config_with_external.json", BaseBucketLoaderTest.class).getBytes(UTF_8));
        }
    };
    when(core.ensureServiceAt(eq(SEED), eq(SERVICE), eq(PORT), eq(Optional.of(BUCKET)), eq(Optional.empty()))).thenReturn(Mono.empty());
    when(core.serviceState(eq(SEED), eq(SERVICE), eq(Optional.of(BUCKET)))).thenReturn(Optional.of(Flux.empty()));
    ProposedBucketConfigContext ctx = loader.load(SEED, PORT, BUCKET, Optional.empty()).block();
    BucketConfig config = BucketConfigParser.parse(ctx.config(), core.context().environment(), ctx.origin());
    assertEquals("default", config.name());
    assertEquals(1073, config.rev());
}
Also used : NodeIdentifier(com.couchbase.client.core.node.NodeIdentifier) ProposedBucketConfigContext(com.couchbase.client.core.config.ProposedBucketConfigContext) BucketConfig(com.couchbase.client.core.config.BucketConfig) Test(org.junit.jupiter.api.Test)

Example 7 with NodeIdentifier

use of com.couchbase.client.core.node.NodeIdentifier in project couchbase-jvm-clients by couchbase.

the class BaseBucketLoaderTest method failsWhenChildDiscoverFails.

@Test
void failsWhenChildDiscoverFails() {
    BucketLoader loader = new BaseBucketLoader(core, SERVICE) {

        @Override
        protected Mono<byte[]> discoverConfig(NodeIdentifier seed, String bucket) {
            return Mono.error(new CouchbaseException("Failed discovering for some reason"));
        }
    };
    when(core.ensureServiceAt(eq(SEED), eq(SERVICE), eq(PORT), eq(Optional.of(BUCKET)), eq(Optional.empty()))).thenReturn(Mono.empty());
    assertThrows(ConfigException.class, () -> loader.load(SEED, PORT, BUCKET, Optional.empty()).block());
}
Also used : CouchbaseException(com.couchbase.client.core.error.CouchbaseException) NodeIdentifier(com.couchbase.client.core.node.NodeIdentifier) Test(org.junit.jupiter.api.Test)

Example 8 with NodeIdentifier

use of com.couchbase.client.core.node.NodeIdentifier in project couchbase-jvm-clients by couchbase.

the class GlobalBucketRefresherIntegrationTest method loadGlobalConfig.

/**
 * Not related, but to test the refresh we first need to load the global config and prime the config provider.
 */
private void loadGlobalConfig(final ConfigurationProvider provider) {
    TestNodeConfig config = config().firstNodeWith(Services.KV).get();
    GlobalLoader loader = new GlobalLoader(core);
    ProposedGlobalConfigContext globalConfigContext = loader.load(new NodeIdentifier(config.hostname(), config.ports().get(Services.MANAGER)), config.ports().get(Services.KV)).block();
    provider.proposeGlobalConfig(globalConfigContext);
}
Also used : GlobalLoader(com.couchbase.client.core.config.loader.GlobalLoader) TestNodeConfig(com.couchbase.client.test.TestNodeConfig) ProposedGlobalConfigContext(com.couchbase.client.core.config.ProposedGlobalConfigContext) NodeIdentifier(com.couchbase.client.core.node.NodeIdentifier)

Example 9 with NodeIdentifier

use of com.couchbase.client.core.node.NodeIdentifier in project couchbase-jvm-clients by couchbase.

the class ClusterManagerBucketLoaderIntegrationTest method loadConfigViaClusterManagerHttp.

/**
 * This is a very simplistic test that makes sure that we can "round trip" in the
 * {@link ClusterManagerBucketLoader} by grabbing a JSON decodable config through the full stack.
 */
@Test
// @Disabled
void loadConfigViaClusterManagerHttp() {
    TestNodeConfig config = config().firstNodeWith(Services.MANAGER).get();
    Core core = Core.create(env, authenticator(), seedNodes());
    ClusterManagerBucketLoader loader = new ClusterManagerBucketLoader(core);
    int port = config.ports().get(Services.MANAGER);
    ProposedBucketConfigContext ctx = loader.load(new NodeIdentifier(config.hostname(), port), port, config().bucketname(), Optional.empty()).block();
    BucketConfig loaded = BucketConfigParser.parse(ctx.config(), env, ctx.origin());
    assertNotNull(loaded);
    assertEquals(config().bucketname(), loaded.name());
    core.shutdown().block();
}
Also used : TestNodeConfig(com.couchbase.client.test.TestNodeConfig) NodeIdentifier(com.couchbase.client.core.node.NodeIdentifier) ProposedBucketConfigContext(com.couchbase.client.core.config.ProposedBucketConfigContext) BucketConfig(com.couchbase.client.core.config.BucketConfig) Core(com.couchbase.client.core.Core) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 10 with NodeIdentifier

use of com.couchbase.client.core.node.NodeIdentifier in project couchbase-jvm-clients by couchbase.

the class DefaultConfigurationProvider method openBucket.

@Override
public Mono<Void> openBucket(final String name) {
    return Mono.defer(() -> {
        if (!shutdown.get()) {
            bucketConfigLoadInProgress.incrementAndGet();
            boolean tls = core.context().environment().securityConfig().tlsEnabled();
            int kvPort = tls ? DEFAULT_KV_TLS_PORT : DEFAULT_KV_PORT;
            int managerPort = tls ? DEFAULT_MANAGER_TLS_PORT : DEFAULT_MANAGER_PORT;
            final Optional<String> alternate = core.context().alternateAddress();
            return Flux.range(1, Math.min(MAX_PARALLEL_LOADERS, currentSeedNodes().size())).flatMap(index -> Flux.fromIterable(currentSeedNodes()).take(Math.min(index, currentSeedNodes().size())).last().flatMap(seed -> {
                NodeIdentifier identifier = new NodeIdentifier(seed.address(), seed.clusterManagerPort().orElse(DEFAULT_MANAGER_PORT));
                final AtomicReference<Map<ServiceType, Integer>> alternatePorts = new AtomicReference<>();
                final Optional<String> alternateAddress = alternate.map(a -> mapAlternateAddress(a, seed, tls, alternatePorts));
                final int mappedKvPort;
                final int mappedManagerPort;
                if (alternateAddress.isPresent()) {
                    Map<ServiceType, Integer> ports = alternatePorts.get();
                    mappedKvPort = ports.get(ServiceType.KV);
                    mappedManagerPort = ports.get(ServiceType.MANAGER);
                } else {
                    mappedKvPort = seed.kvPort().orElse(kvPort);
                    mappedManagerPort = seed.clusterManagerPort().orElse(managerPort);
                }
                return loadBucketConfigForSeed(identifier, mappedKvPort, mappedManagerPort, name, alternateAddress);
            }).retryWhen(Retry.from(companion -> companion.flatMap(rs -> {
                final Throwable f = rs.failure();
                if (shutdown.get()) {
                    return Mono.error(new AlreadyShutdownException());
                }
                if (f instanceof UnsupportedConfigMechanismException) {
                    return Mono.error(Exceptions.propagate(f));
                }
                boolean bucketNotFound = f instanceof BucketNotFoundDuringLoadException;
                boolean bucketNotReady = f instanceof BucketNotReadyDuringLoadException;
                // For bucket not found or not ready wait a bit longer, retry the rest quickly
                Duration delay = bucketNotFound || bucketNotReady ? Duration.ofMillis(500) : Duration.ofMillis(1);
                eventBus.publish(new BucketOpenRetriedEvent(name, delay, core.context(), f));
                return Mono.just(rs.totalRetries()).delayElement(delay, core.context().environment().scheduler());
            })))).take(1).switchIfEmpty(Mono.error(new ConfigException("Could not locate a single bucket configuration for bucket: " + name))).map(ctx -> {
                proposeBucketConfig(ctx);
                return ctx;
            }).then(registerRefresher(name)).doOnTerminate(bucketConfigLoadInProgress::decrementAndGet).onErrorResume(t -> closeBucketIgnoreShutdown(name).then(Mono.error(t)));
        } else {
            return Mono.error(new AlreadyShutdownException());
        }
    });
}
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) AtomicReference(java.util.concurrent.atomic.AtomicReference) Duration(java.time.Duration) ConfigException(com.couchbase.client.core.error.ConfigException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServiceType(com.couchbase.client.core.service.ServiceType) BucketNotFoundDuringLoadException(com.couchbase.client.core.error.BucketNotFoundDuringLoadException) NodeIdentifier(com.couchbase.client.core.node.NodeIdentifier) BucketOpenRetriedEvent(com.couchbase.client.core.cnc.events.config.BucketOpenRetriedEvent) BucketNotReadyDuringLoadException(com.couchbase.client.core.error.BucketNotReadyDuringLoadException) AlreadyShutdownException(com.couchbase.client.core.error.AlreadyShutdownException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CollectionMap(com.couchbase.client.core.io.CollectionMap) UnsupportedConfigMechanismException(com.couchbase.client.core.error.UnsupportedConfigMechanismException)

Aggregations

NodeIdentifier (com.couchbase.client.core.node.NodeIdentifier)15 Test (org.junit.jupiter.api.Test)11 Optional (java.util.Optional)9 BucketConfig (com.couchbase.client.core.config.BucketConfig)8 SeedNode (com.couchbase.client.core.env.SeedNode)8 Core (com.couchbase.client.core.Core)7 ServiceType (com.couchbase.client.core.service.ServiceType)7 HashMap (java.util.HashMap)6 ClusterConfig (com.couchbase.client.core.config.ClusterConfig)5 ConfigurationProvider (com.couchbase.client.core.config.ConfigurationProvider)5 Node (com.couchbase.client.core.node.Node)5 TestNodeConfig (com.couchbase.client.test.TestNodeConfig)4 ProposedBucketConfigContext (com.couchbase.client.core.config.ProposedBucketConfigContext)3 GlobalLoader (com.couchbase.client.core.config.loader.GlobalLoader)3 EventBus (com.couchbase.client.core.cnc.EventBus)2 BucketConfigUpdatedEvent (com.couchbase.client.core.cnc.events.config.BucketConfigUpdatedEvent)2 BucketOpenRetriedEvent (com.couchbase.client.core.cnc.events.config.BucketOpenRetriedEvent)2 CollectionMapRefreshFailedEvent (com.couchbase.client.core.cnc.events.config.CollectionMapRefreshFailedEvent)2 CollectionMapRefreshIgnoredEvent (com.couchbase.client.core.cnc.events.config.CollectionMapRefreshIgnoredEvent)2 CollectionMapRefreshSucceededEvent (com.couchbase.client.core.cnc.events.config.CollectionMapRefreshSucceededEvent)2