use of com.couchbase.client.core.error.UnsupportedConfigMechanismException in project couchbase-jvm-clients by couchbase.
the class DefaultConfigurationProvider method loadAndRefreshGlobalConfig.
@Override
public Mono<Void> loadAndRefreshGlobalConfig() {
return Mono.defer(() -> {
if (!shutdown.get()) {
globalConfigLoadInProgress = true;
boolean tls = core.context().environment().securityConfig().tlsEnabled();
int kvPort = tls ? DEFAULT_KV_TLS_PORT : DEFAULT_KV_PORT;
final AtomicBoolean hasErrored = new AtomicBoolean();
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 -> {
long start = System.nanoTime();
if (!currentSeedNodes().contains(seed)) {
// node we are about to load is still part of the list.
return Mono.empty();
}
NodeIdentifier identifier = new NodeIdentifier(seed.address(), seed.clusterManagerPort().orElse(DEFAULT_MANAGER_PORT));
return globalLoader.load(identifier, seed.kvPort().orElse(kvPort)).doOnError(throwable -> core.context().environment().eventBus().publish(new IndividualGlobalConfigLoadFailedEvent(Duration.ofNanos(System.nanoTime() - start), core.context(), throwable, seed.address())));
}).retryWhen(Retry.from(companion -> companion.flatMap(rs -> {
Throwable f = rs.failure();
if (shutdown.get()) {
return Mono.error(new AlreadyShutdownException());
}
if (f instanceof UnsupportedConfigMechanismException) {
return Mono.error(Exceptions.propagate(f));
}
Duration delay = Duration.ofMillis(1);
eventBus.publish(new GlobalConfigRetriedEvent(delay, core.context(), f));
return Mono.just(rs.totalRetries()).delayElement(delay, core.context().environment().scheduler());
}))).onErrorResume(throwable -> {
if (hasErrored.compareAndSet(false, true)) {
return Mono.error(throwable);
}
return Mono.empty();
})).take(1).switchIfEmpty(Mono.error(new ConfigException("Could not locate a single global configuration"))).map(ctx -> {
proposeGlobalConfig(ctx);
return ctx;
}).then(globalRefresher.start()).doOnTerminate(() -> globalConfigLoadInProgress = false);
} else {
return Mono.error(new AlreadyShutdownException());
}
});
}
use of com.couchbase.client.core.error.UnsupportedConfigMechanismException in project couchbase-jvm-clients by couchbase.
the class Core method initGlobalConfig.
/**
* Instructs the client to, if possible, load and initialize the global config.
*
* <p>Since global configs are an "optional" feature depending on the cluster version, if an error happens
* this method will not fail. Rather it will log the exception (with some logic dependent on the type of error)
* and will allow the higher level components to move on where possible.</p>
*/
@Stability.Internal
public void initGlobalConfig() {
long start = System.nanoTime();
configurationProvider.loadAndRefreshGlobalConfig().subscribe(v -> {
}, throwable -> {
InitGlobalConfigFailedEvent.Reason reason = InitGlobalConfigFailedEvent.Reason.UNKNOWN;
if (throwable instanceof UnsupportedConfigMechanismException) {
reason = InitGlobalConfigFailedEvent.Reason.UNSUPPORTED;
} else if (throwable instanceof GlobalConfigNotFoundException) {
reason = InitGlobalConfigFailedEvent.Reason.NO_CONFIG_FOUND;
} else if (throwable instanceof ConfigException) {
if (throwable.getCause() instanceof RequestCanceledException) {
RequestContext ctx = ((RequestCanceledException) throwable.getCause()).context().requestContext();
if (ctx.request().cancellationReason() == CancellationReason.SHUTDOWN) {
reason = InitGlobalConfigFailedEvent.Reason.SHUTDOWN;
}
} else if (throwable.getMessage().contains("NO_ACCESS")) {
reason = InitGlobalConfigFailedEvent.Reason.NO_ACCESS;
}
} else if (throwable instanceof AlreadyShutdownException) {
reason = InitGlobalConfigFailedEvent.Reason.SHUTDOWN;
}
eventBus.publish(new InitGlobalConfigFailedEvent(reason.severity(), Duration.ofNanos(System.nanoTime() - start), context(), reason, throwable));
});
}
use of com.couchbase.client.core.error.UnsupportedConfigMechanismException 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());
}
});
}
use of com.couchbase.client.core.error.UnsupportedConfigMechanismException in project couchbase-jvm-clients by couchbase.
the class CoreTest method ignoresFailedGlobalConfigInitAttempt.
@Test
void ignoresFailedGlobalConfigInitAttempt() {
final ConfigurationProvider configProvider = mock(ConfigurationProvider.class);
when(configProvider.configs()).thenReturn(Flux.empty());
Core core = new Core(ENV, AUTHENTICATOR, SeedNode.LOCALHOST) {
@Override
public ConfigurationProvider createConfigurationProvider() {
return configProvider;
}
};
when(configProvider.loadAndRefreshGlobalConfig()).thenReturn(Mono.error(new GlobalConfigNotFoundException()));
core.initGlobalConfig();
when(configProvider.loadAndRefreshGlobalConfig()).thenReturn(Mono.error(new UnsupportedConfigMechanismException()));
core.initGlobalConfig();
int numRaised = 0;
for (Event event : EVENT_BUS.publishedEvents()) {
if (event instanceof InitGlobalConfigFailedEvent) {
numRaised++;
}
}
assertEquals(2, numRaised);
}
Aggregations