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;
}
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;
}
}
}
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));
}
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);
}
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);
}
Aggregations