Search in sources :

Example 1 with InitGlobalConfigFailedEvent

use of com.couchbase.client.core.cnc.events.core.InitGlobalConfigFailedEvent 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));
    });
}
Also used : RequestCanceledException(com.couchbase.client.core.error.RequestCanceledException) InitGlobalConfigFailedEvent(com.couchbase.client.core.cnc.events.core.InitGlobalConfigFailedEvent) GlobalConfigNotFoundException(com.couchbase.client.core.error.GlobalConfigNotFoundException) ConfigException(com.couchbase.client.core.error.ConfigException) RequestContext(com.couchbase.client.core.msg.RequestContext) AlreadyShutdownException(com.couchbase.client.core.error.AlreadyShutdownException) UnsupportedConfigMechanismException(com.couchbase.client.core.error.UnsupportedConfigMechanismException)

Example 2 with InitGlobalConfigFailedEvent

use of com.couchbase.client.core.cnc.events.core.InitGlobalConfigFailedEvent 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);
}
Also used : GlobalConfigNotFoundException(com.couchbase.client.core.error.GlobalConfigNotFoundException) InitGlobalConfigFailedEvent(com.couchbase.client.core.cnc.events.core.InitGlobalConfigFailedEvent) ConfigurationProvider(com.couchbase.client.core.config.ConfigurationProvider) InitGlobalConfigFailedEvent(com.couchbase.client.core.cnc.events.core.InitGlobalConfigFailedEvent) Event(com.couchbase.client.core.cnc.Event) UnsupportedConfigMechanismException(com.couchbase.client.core.error.UnsupportedConfigMechanismException) Test(org.junit.jupiter.api.Test)

Aggregations

InitGlobalConfigFailedEvent (com.couchbase.client.core.cnc.events.core.InitGlobalConfigFailedEvent)2 GlobalConfigNotFoundException (com.couchbase.client.core.error.GlobalConfigNotFoundException)2 UnsupportedConfigMechanismException (com.couchbase.client.core.error.UnsupportedConfigMechanismException)2 Event (com.couchbase.client.core.cnc.Event)1 ConfigurationProvider (com.couchbase.client.core.config.ConfigurationProvider)1 AlreadyShutdownException (com.couchbase.client.core.error.AlreadyShutdownException)1 ConfigException (com.couchbase.client.core.error.ConfigException)1 RequestCanceledException (com.couchbase.client.core.error.RequestCanceledException)1 RequestContext (com.couchbase.client.core.msg.RequestContext)1 Test (org.junit.jupiter.api.Test)1