Search in sources :

Example 26 with CouchbaseException

use of com.couchbase.client.core.error.CouchbaseException in project spring-data-couchbase by spring-projects.

the class QueryCriteria method in.

public QueryCriteria in(@Nullable Object... o) {
    operator = "IN";
    format = "%1$s in %3$s";
    value = new Object[1];
    if (o.length > 0) {
        if (o[0] instanceof JsonArray || o[0] instanceof List || o[0] instanceof Object[]) {
            if (o.length != 1) {
                throw new RuntimeException("IN cannot take multiple lists");
            }
            if (o[0] instanceof Object[]) {
                value[0] = o[0];
            } else if (o[0] instanceof JsonArray) {
                JsonArray ja = ((JsonArray) o[0]);
                value[0] = ja.toList().toArray();
            } else if (o[0] instanceof List) {
                List l = ((List) o[0]);
                value[0] = l.toArray();
            }
        } else {
            // Query expected = (new Query()).addCriteria(where(i("firstname")).in("Oliver", "Charles"));
            if (o instanceof Object[]) {
                value[0] = o;
            } else {
                // notIn((Object) new String[] { "Alabama", "Florida" }));
                throw new CouchbaseException("unhandled parameters " + o);
            }
        }
    }
    return this;
}
Also used : JsonArray(com.couchbase.client.java.json.JsonArray) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) JsonObject(com.couchbase.client.java.json.JsonObject)

Example 27 with CouchbaseException

use of com.couchbase.client.core.error.CouchbaseException in project spring-data-couchbase by spring-projects.

the class JavaIntegrationTests method createFtsCollectionIndex.

public static void createFtsCollectionIndex(Cluster cluster, String indexName, String bucketName, String scopeName, String collectionName) {
    SearchIndex searchIndex = new SearchIndex(indexName, bucketName);
    if (scopeName != null) {
        // searchIndex = searchIndex.forScopeCollection(scopeName, collectionName);
        throw new RuntimeException("forScopeCollection not implemented in current java client version");
    }
    cluster.searchIndexes().upsertIndex(searchIndex, UpsertSearchIndexOptions.upsertSearchIndexOptions().timeout(Duration.ofSeconds(60)));
    int maxTries = 5;
    for (int i = 0; i < maxTries; i++) {
        try {
            SearchResult result = cluster.searchQuery(indexName, SearchQuery.queryString("junk"));
            break;
        } catch (CouchbaseException | IllegalStateException ex) {
            // this is a pretty dirty hack to avoid a race where we don't know if the index is ready yet
            if (i < (maxTries - 1) && (ex.getMessage().contains("no planPIndexes for indexName") || ex.getMessage().contains("pindex_consistency mismatched partition") || ex.getMessage().contains("pindex not available"))) {
                sleepMs(1000);
                continue;
            }
            throw ex;
        }
    }
}
Also used : CouchbaseException(com.couchbase.client.core.error.CouchbaseException) SearchIndex(com.couchbase.client.java.manager.search.SearchIndex) SearchResult(com.couchbase.client.java.search.result.SearchResult)

Example 28 with CouchbaseException

use of com.couchbase.client.core.error.CouchbaseException in project spring-data-couchbase by spring-projects.

the class JavaIntegrationTests method setupScopeCollection.

public static void setupScopeCollection(Cluster cluster, String scopeName, String collectionName, CollectionManager collectionManager) {
    // Create the scope.collection (borrowed from CollectionManagerIntegrationTest )
    ScopeSpec scopeSpec = ScopeSpec.create(scopeName);
    CollectionSpec collSpec = CollectionSpec.create(collectionName, scopeName);
    if (!scopeName.equals(CollectionIdentifier.DEFAULT_SCOPE)) {
        try {
            collectionManager.createScope(scopeName);
            waitUntilCondition(() -> scopeExists(collectionManager, scopeName));
            ScopeSpec found = collectionManager.getScope(scopeName);
            assertEquals(scopeSpec, found);
        } catch (CouchbaseException e) {
            if (!e.toString().contains("already exists")) {
                e.printStackTrace();
                throw e;
            }
        }
    }
    try {
        collectionManager.createCollection(collSpec);
    } catch (CouchbaseException e) {
        if (!e.toString().contains("already exists")) {
            e.printStackTrace();
            throw e;
        }
    }
    waitUntilCondition(() -> collectionExists(collectionManager, collSpec));
    waitUntilCondition(() -> collectionReady(cluster.bucket(config().bucketname()).scope(scopeName).collection(collectionName)));
    assertNotEquals(scopeSpec, collectionManager.getScope(scopeName));
    assertTrue(collectionManager.getScope(scopeName).collections().contains(collSpec));
    waitForQueryIndexerToHaveBucket(cluster, collectionName);
    try {
        block(createPrimaryIndex(cluster, config().bucketname(), scopeName, collectionName));
    } catch (Exception e) {
        e.printStackTrace();
    }
    waitUntilCondition(() -> collectionReadyQuery(cluster.bucket(config().bucketname()).scope(scopeName), collectionName));
}
Also used : ScopeSpec(com.couchbase.client.java.manager.collection.ScopeSpec) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) CollectionSpec(com.couchbase.client.java.manager.collection.CollectionSpec) UnambiguousTimeoutException(com.couchbase.client.core.error.UnambiguousTimeoutException) IndexExistsException(com.couchbase.client.core.error.IndexExistsException) ParsingFailureException(com.couchbase.client.core.error.ParsingFailureException) DocumentNotFoundException(com.couchbase.client.core.error.DocumentNotFoundException) CollectionNotFoundException(com.couchbase.client.core.error.CollectionNotFoundException) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) QueryException(com.couchbase.client.core.error.QueryException) ScopeNotFoundException(com.couchbase.client.core.error.ScopeNotFoundException) IOException(java.io.IOException)

Example 29 with CouchbaseException

use of com.couchbase.client.core.error.CouchbaseException in project couchbase-jvm-clients by couchbase.

the class SelectBucketHandler method channelRead.

@Override
public void channelRead(final ChannelHandlerContext ctx, final Object msg) {
    Optional<Duration> latency = ConnectTimings.stop(ctx.channel(), this.getClass(), false);
    if (msg instanceof ByteBuf) {
        short status = status((ByteBuf) msg);
        if (status == MemcacheProtocol.Status.SUCCESS.status()) {
            endpointContext.environment().eventBus().publish(new SelectBucketCompletedEvent(latency.orElse(Duration.ZERO), ioContext, bucketName));
            interceptedConnectPromise.trySuccess();
            ctx.pipeline().remove(this);
            ctx.fireChannelActive();
        } else if (status == MemcacheProtocol.Status.ACCESS_ERROR.status()) {
            // If the promise has been already completed with an error from a downstream handler, there is no
            // need to WARN because it will just spam and reduce the visibility of the actual source error.
            Event.Severity severity = interceptedConnectPromise.isDone() && !interceptedConnectPromise.isSuccess() ? Event.Severity.DEBUG : Event.Severity.WARN;
            endpointContext.environment().eventBus().publish(new SelectBucketFailedEvent(severity, ioContext, status));
            interceptedConnectPromise.tryFailure(new AuthenticationFailureException("Either the bucket with name \"" + redactMeta(bucketName) + "\" is not present or the user does not have " + "the right privileges to access it", new KeyValueIoErrorContext(MemcacheProtocol.decodeStatus(status), endpointContext, null), null));
        } else if (status == MemcacheProtocol.Status.NOT_FOUND.status()) {
            // NOT_FOUND severity is lowered to debug because it shows up when bootstrapping against
            // a node in a MDS setup without the kv service / bucket enabled. If the bucket is legit not
            // present, we'd get the access error from above (which is an error).
            endpointContext.environment().eventBus().publish(new SelectBucketFailedEvent(Event.Severity.DEBUG, ioContext, status));
            interceptedConnectPromise.tryFailure(BucketNotFoundException.forBucket(bucketName));
        } else {
            endpointContext.environment().eventBus().publish(new SelectBucketFailedEvent(Event.Severity.ERROR, ioContext, status));
            interceptedConnectPromise.tryFailure(new CouchbaseException("Select bucket failed with unexpected status code 0x" + Integer.toHexString(status)));
        }
    } else {
        interceptedConnectPromise.tryFailure(new CouchbaseException("Unexpected response type on channel read, this is a bug " + "- please report." + msg));
    }
    ReferenceCountUtil.release(msg);
}
Also used : SelectBucketFailedEvent(com.couchbase.client.core.cnc.events.io.SelectBucketFailedEvent) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) KeyValueIoErrorContext(com.couchbase.client.core.error.context.KeyValueIoErrorContext) SelectBucketCompletedEvent(com.couchbase.client.core.cnc.events.io.SelectBucketCompletedEvent) Duration(java.time.Duration) AuthenticationFailureException(com.couchbase.client.core.error.AuthenticationFailureException) ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)

Example 30 with CouchbaseException

use of com.couchbase.client.core.error.CouchbaseException in project couchbase-jvm-clients by couchbase.

the class SaslListMechanismsHandler method channelRead.

/**
 * As soon as we get a response, turn it into a list of SASL mechanisms the server supports.
 * <p>
 * If the server responds with an empty list this is an issue and as a result we need to fail the connection
 * immediately.
 *
 * @param ctx the {@link ChannelHandlerContext} for which the channel read operation is made.
 * @param msg the incoming msg that needs to be parsed.
 */
@Override
public void channelRead(final ChannelHandlerContext ctx, final Object msg) {
    if (msg instanceof ByteBuf) {
        Optional<Duration> latency = ConnectTimings.stop(ctx.channel(), this.getClass(), false);
        if (successful((ByteBuf) msg)) {
            String[] rawMechansisms = body((ByteBuf) msg).orElse(Unpooled.EMPTY_BUFFER).toString(UTF_8).split(" ");
            boolean isEmpty = rawMechansisms.length == 1 && rawMechansisms[0].isEmpty();
            if (rawMechansisms.length > 0 && !isEmpty) {
                final Set<SaslMechanism> serverMechanisms = decodeMechanisms(rawMechansisms);
                ioContext.environment().eventBus().publish(new SaslMechanismsListedEvent(ioContext, serverMechanisms, latency.orElse(Duration.ZERO)));
                ctx.channel().attr(ChannelAttributes.SASL_MECHS_KEY).set(serverMechanisms);
                interceptedConnectPromise.trySuccess();
                ctx.pipeline().remove(this);
            } else {
                failConnection("Received empty mechanism list from server", status((ByteBuf) msg), latency);
            }
        } else {
            failConnection("Received non-success status from server", status((ByteBuf) msg), latency);
        }
    } else {
        interceptedConnectPromise.tryFailure(new CouchbaseException("Unexpected response " + "type on channel read, this is a bug - please report. " + msg));
    }
    ReferenceCountUtil.release(msg);
}
Also used : SaslMechanismsListedEvent(com.couchbase.client.core.cnc.events.io.SaslMechanismsListedEvent) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) SaslMechanism(com.couchbase.client.core.env.SaslMechanism) Duration(java.time.Duration) ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)

Aggregations

CouchbaseException (com.couchbase.client.core.error.CouchbaseException)46 DocumentNotFoundException (com.couchbase.client.core.error.DocumentNotFoundException)8 Test (org.junit.jupiter.api.Test)8 ByteBuf (com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)7 CasMismatchException (com.couchbase.client.core.error.CasMismatchException)7 RetryExhaustedException (com.couchbase.client.core.retry.reactor.RetryExhaustedException)7 LookupInResult (com.couchbase.client.java.kv.LookupInResult)7 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)7 Duration (java.time.Duration)7 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)6 ArrayList (java.util.ArrayList)6 AuthenticationFailureException (com.couchbase.client.core.error.AuthenticationFailureException)5 RateLimitedException (com.couchbase.client.core.error.RateLimitedException)5 IndexNotFoundException (com.couchbase.client.core.error.IndexNotFoundException)4 UnambiguousTimeoutException (com.couchbase.client.core.error.UnambiguousTimeoutException)4 PathNotFoundException (com.couchbase.client.core.error.subdoc.PathNotFoundException)4 JsonObject (com.couchbase.client.java.json.JsonObject)4 SearchIndex (com.couchbase.client.java.manager.search.SearchIndex)4 List (java.util.List)4 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)3