Search in sources :

Example 21 with CouchbaseException

use of com.couchbase.client.core.error.CouchbaseException 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 22 with CouchbaseException

use of com.couchbase.client.core.error.CouchbaseException in project connectors-se by Talend.

the class BinaryParser method parse.

@Override
public Record parse(Collection collection, String id) {
    GetResult result;
    try {
        result = collection.get(id, GetOptions.getOptions().transcoder(RawBinaryTranscoder.INSTANCE));
    } catch (TimeoutException | CouchbaseException e) {
        LOG.error(e.getMessage());
        throw new ComponentException(e.getMessage());
    }
    byte[] data = result.contentAs(byte[].class);
    final Record.Builder recordBuilder = builderFactory.newRecordBuilder(schemaBinaryDocument);
    recordBuilder.withString("id", id);
    recordBuilder.withBytes("content", data);
    return recordBuilder.build();
}
Also used : CouchbaseException(com.couchbase.client.core.error.CouchbaseException) GetResult(com.couchbase.client.java.kv.GetResult) ComponentException(org.talend.sdk.component.api.exception.ComponentException) Record(org.talend.sdk.component.api.record.Record) TimeoutException(com.couchbase.client.core.deps.io.netty.handler.timeout.TimeoutException)

Example 23 with CouchbaseException

use of com.couchbase.client.core.error.CouchbaseException in project connectors-se by Talend.

the class CouchbaseOutput method onNext.

@ElementListener
public void onNext(@Input final Record rec) {
    if (configuration.isUseN1QLQuery()) {
        Map<String, String> mappings = configuration.getQueryParams().stream().collect(Collectors.toMap(N1QLQueryParameter::getColumn, N1QLQueryParameter::getQueryParameterName));
        JsonObject namedParams = buildJsonObject(rec, mappings);
        try {
            cluster.query(configuration.getQuery(), QueryOptions.queryOptions().parameters(namedParams));
        } catch (CouchbaseException ex) {
            log.error("N1QL failed: {}.", ex.getMessage());
            throw new ComponentException(ex.getMessage());
        }
    } else {
        if (configuration.isPartialUpdate()) {
            updatePartiallyDocument(rec);
        } else {
            if (configuration.getDataSet().getDocumentType() == DocumentType.BINARY) {
                collection.upsert(rec.getString(idFieldName), rec.getBytes(CONTENT_FIELD_NAME), UpsertOptions.upsertOptions().transcoder(RawBinaryTranscoder.INSTANCE));
            } else if (configuration.getDataSet().getDocumentType() == DocumentType.STRING) {
                collection.upsert(rec.getString(idFieldName), rec.getString(CONTENT_FIELD_NAME), UpsertOptions.upsertOptions().transcoder(RawStringTranscoder.INSTANCE));
            } else {
                collection.upsert(rec.getString(idFieldName), buildJsonObjectWithoutId(rec));
            }
        }
    }
}
Also used : CouchbaseException(com.couchbase.client.core.error.CouchbaseException) ComponentException(org.talend.sdk.component.api.exception.ComponentException) JsonObject(com.couchbase.client.java.json.JsonObject) ElementListener(org.talend.sdk.component.api.processor.ElementListener)

Example 24 with CouchbaseException

use of com.couchbase.client.core.error.CouchbaseException in project connectors-se by Talend.

the class StringParser method parse.

@Override
public Record parse(Collection collection, String id) {
    GetResult result;
    try {
        result = collection.get(id, GetOptions.getOptions().transcoder(RawStringTranscoder.INSTANCE));
    } catch (CouchbaseException e) {
        LOG.error(e.getMessage());
        throw new ComponentException(e.getMessage());
    }
    String data = result.contentAs(String.class);
    final Record.Builder recordBuilder = builderFactory.newRecordBuilder(schemaStringDocument);
    recordBuilder.withString("id", id);
    recordBuilder.withString("content", data);
    return recordBuilder.build();
}
Also used : CouchbaseException(com.couchbase.client.core.error.CouchbaseException) GetResult(com.couchbase.client.java.kv.GetResult) ComponentException(org.talend.sdk.component.api.exception.ComponentException) Record(org.talend.sdk.component.api.record.Record)

Example 25 with CouchbaseException

use of com.couchbase.client.core.error.CouchbaseException in project connectors-se by Talend.

the class CouchbaseInput method init.

@PostConstruct
public void init() {
    Cluster cluster = service.openConnection(configuration.getDataSet().getDatastore());
    Bucket bucket = cluster.bucket(configuration.getDataSet().getBucket());
    collection = service.openDefaultCollection(cluster, configuration.getDataSet().getBucket());
    if (configuration.isCreatePrimaryIndex()) {
        cluster.queryIndexes().createPrimaryIndex(bucket.name(), CreatePrimaryQueryIndexOptions.createPrimaryQueryIndexOptions().ignoreIfExists(true));
    }
    columnsSet = new HashSet<>();
    if (configuration.getSelectAction() == SelectAction.ANALYTICS) {
        AnalyticsResult analyticsResult = null;
        try {
            analyticsResult = cluster.analyticsQuery(configuration.getQuery());
        } catch (CouchbaseException e) {
            LOG.error(i18n.queryResultError(e.getMessage()));
            throw new ComponentException(i18n.queryResultError(e.getMessage()));
        }
        queryResultsIterator = analyticsResult.rowsAsObject().iterator();
    } else {
        // DSL API (Statement, AsPath classes etc. was deprecated, cannot use it anymore!)
        // In most cases, a simple string statement is the best replacement.
        QueryResult n1qlResult;
        StringBuilder statementBuilder;
        switch(configuration.getSelectAction()) {
            case ALL:
                statementBuilder = new StringBuilder();
                statementBuilder.append("SELECT meta().id as `_meta_id_`, * FROM `").append(bucket.name()).append("`");
                if (!configuration.getLimit().isEmpty()) {
                    statementBuilder.append(" LIMIT ").append(configuration.getLimit().trim());
                }
                n1qlResult = cluster.query(statementBuilder.toString());
                break;
            case N1QL:
                /*
                 * should contain "meta().id as `_meta_id_`" field for non-json (binary) documents
                 */
                n1qlResult = cluster.query(configuration.getQuery());
                break;
            case ONE:
                statementBuilder = new StringBuilder();
                statementBuilder.append("SELECT meta().id as `_meta_id_`, * FROM `").append(bucket.name()).append("`");
                statementBuilder.append(" USE KEYS \"").append(configuration.getDocumentId()).append("\"");
                n1qlResult = cluster.query(statementBuilder.toString());
                break;
            default:
                throw new ComponentException("Select action: '" + configuration.getSelectAction() + "' is unsupported");
        }
        queryResultsIterator = n1qlResult.rowsAsObject().iterator();
    }
}
Also used : QueryResult(com.couchbase.client.java.query.QueryResult) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) Bucket(com.couchbase.client.java.Bucket) ComponentException(org.talend.sdk.component.api.exception.ComponentException) Cluster(com.couchbase.client.java.Cluster) AnalyticsResult(com.couchbase.client.java.analytics.AnalyticsResult) PostConstruct(javax.annotation.PostConstruct)

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