Search in sources :

Example 6 with ReducedAnalyticsErrorContext

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

the class AsyncCluster method analyticsRequest.

/**
 * Helper method to craft an analytics request.
 *
 * @param statement the statement to use.
 * @param opts the built analytics options.
 * @return the created analytics request.
 */
AnalyticsRequest analyticsRequest(final String statement, final AnalyticsOptions.Built opts) {
    notNullOrEmpty(statement, "Statement", () -> new ReducedAnalyticsErrorContext(statement));
    Duration timeout = opts.timeout().orElse(environment.get().timeoutConfig().analyticsTimeout());
    RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.get().retryStrategy());
    JsonObject query = JsonObject.create();
    query.put("statement", statement);
    query.put("timeout", encodeDurationToMs(timeout));
    opts.injectParams(query);
    final byte[] queryBytes = query.toString().getBytes(StandardCharsets.UTF_8);
    final String clientContextId = query.getString("client_context_id");
    final RequestSpan span = environment().requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_ANALYTICS, opts.parentSpan().orElse(null));
    AnalyticsRequest request = new AnalyticsRequest(timeout, core.context(), retryStrategy, authenticator, queryBytes, opts.priority(), opts.readonly(), clientContextId, statement, span, null, null);
    request.context().clientContext(opts.clientContext());
    return request;
}
Also used : ReducedAnalyticsErrorContext(com.couchbase.client.core.error.context.ReducedAnalyticsErrorContext) AnalyticsRequest(com.couchbase.client.core.msg.analytics.AnalyticsRequest) JsonObject(com.couchbase.client.java.json.JsonObject) Duration(java.time.Duration) ConnectionStringUtil.asConnectionString(com.couchbase.client.core.util.ConnectionStringUtil.asConnectionString) ConnectionStringUtil.checkConnectionString(com.couchbase.client.core.util.ConnectionStringUtil.checkConnectionString) ConnectionString(com.couchbase.client.core.util.ConnectionString) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Aggregations

ReducedAnalyticsErrorContext (com.couchbase.client.core.error.context.ReducedAnalyticsErrorContext)6 AnalyticsOptions (com.couchbase.client.java.analytics.AnalyticsOptions)4 JsonSerializer (com.couchbase.client.java.codec.JsonSerializer)4 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)2 AnalyticsRequest (com.couchbase.client.core.msg.analytics.AnalyticsRequest)2 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)2 JsonObject (com.couchbase.client.java.json.JsonObject)2 Duration (java.time.Duration)2 ConnectionString (com.couchbase.client.core.util.ConnectionString)1 ConnectionStringUtil.asConnectionString (com.couchbase.client.core.util.ConnectionStringUtil.asConnectionString)1 ConnectionStringUtil.checkConnectionString (com.couchbase.client.core.util.ConnectionStringUtil.checkConnectionString)1