use of com.couchbase.client.core.endpoint.http.CoreCommonOptions in project couchbase-jdbc-driver by couchbaselabs.
the class ConnectionHandle method rawAnalyticsQuery.
/**
* Sends a raw analytics query, allows to be used where the regular API does not suffice.
* <p>
* It should really only be used if the primary query API cannot be used for some reason.
*
* @param method the http method to use.
* @param path the http path to execute.
* @param headers the optional http headers to send.
* @param content the optional payload to send.
* @param timeout the timeout to use.
* @return the core response to use.
* @throws SQLException in case the query failed.
*/
public CoreHttpResponse rawAnalyticsQuery(HttpMethod method, String path, Map<String, Object> headers, byte[] content, Duration timeout) throws SQLException {
CoreHttpClient client = cluster.core().httpClient(RequestTarget.analytics());
CoreCommonOptions options = CoreCommonOptions.of(timeout == null || timeout.isZero() ? null : timeout, null, null);
CoreHttpRequest.Builder builder;
switch(method) {
case GET:
builder = client.get(path(path), options);
break;
case DELETE:
builder = client.delete(path(path), options);
break;
case POST:
builder = client.post(path(path), options);
if (content != null) {
builder = builder.json(content);
}
break;
default:
throw new IllegalStateException("Unsupported http verb: " + method);
}
if (headers != null) {
for (Map.Entry<String, Object> header : headers.entrySet()) {
builder = builder.header(header.getKey(), header.getValue());
}
}
try {
return builder.build().exec(cluster.core()).get();
} catch (ExecutionException ex) {
if (ex.getCause() instanceof CouchbaseException) {
String ctx = ((CouchbaseException) ex.getCause()).context().exportAsString(Context.ExportFormat.JSON);
throw new SQLException("Failed to perform analytics query: " + ctx, ex);
} else {
throw new SQLException("Failed to perform analytics query - cause: " + ex.getMessage(), ex);
}
} catch (Exception ex) {
throw new SQLException("Failed to perform analytics query - cause: " + ex.getMessage(), ex);
}
}
use of com.couchbase.client.core.endpoint.http.CoreCommonOptions in project couchbase-jvm-clients by couchbase.
the class CoreAnalyticsLinkManager method sendLink.
private CompletableFuture<Void> sendLink(HttpMethod method, Map<String, String> link, CoreCommonOptions options, String tracingId) {
// ensure mutability, and don't modify caller's map
link = new HashMap<>(link);
CoreHttpPath path = getLinkPathAndAdjustMap(link);
UrlQueryStringBuilder form = newForm();
link.forEach(form::set);
return httpClient.newRequest(method, path, options).trace(tracingId).form(form).exec(core).exceptionally(t -> {
throw translateCompilationFailureToInvalidArgument(t);
}).thenApply(result -> null);
}
use of com.couchbase.client.core.endpoint.http.CoreCommonOptions in project couchbase-jvm-clients by couchbase.
the class HealthPinger method pingKv.
private static Mono<EndpointPingReport> pingKv(final Core core, final RequestTarget target, final CoreCommonOptions options) {
return Mono.defer(() -> {
Duration timeout = options.timeout().orElse(core.context().environment().timeoutConfig().kvTimeout());
CollectionIdentifier collectionIdentifier = CollectionIdentifier.fromDefault(target.bucketName());
KvPingRequest request = new KvPingRequest(timeout, core.context(), options.retryStrategy().orElse(null), collectionIdentifier, target.nodeIdentifier());
core.send(request);
return Reactor.wrap(request, request.response(), true).map(response -> {
request.context().logicallyComplete();
return assembleSuccessReport(request.context(), ((KvPingResponse) response).channelId(), Optional.ofNullable(target.bucketName()));
}).onErrorResume(throwable -> {
request.context().logicallyComplete();
return Mono.just(assembleFailureReport(throwable, request.context(), Optional.ofNullable(target.bucketName())));
});
});
}
use of com.couchbase.client.core.endpoint.http.CoreCommonOptions in project couchbase-jvm-clients by couchbase.
the class CoreViewIndexManager method publishDesignDocument.
/**
* Convenience method that gets a the document from the development namespace
* and upserts it to the production namespace.
*
* @param name name of the development design document
* @throws DesignDocumentNotFoundException if the development namespace does not contain a document with the given name
*/
public CompletableFuture<Void> publishDesignDocument(String name, CoreCommonOptions options) {
notNullOrEmpty(name, "Name", () -> new ReducedViewErrorContext(null, null, bucket));
RequestSpan span = buildSpan(TracingIdentifiers.SPAN_REQUEST_MV_PUBLISH_DD, options.parentSpan());
CoreCommonOptions childOptions = options.withParentSpan(span);
return getDesignDocument(name, false, childOptions).thenCompose(doc -> upsertDesignDocument(name, doc, true, childOptions)).whenComplete((r, t) -> span.end());
}
use of com.couchbase.client.core.endpoint.http.CoreCommonOptions in project couchbase-jvm-clients by couchbase.
the class CoreBucketManager method updateBucket.
public CompletableFuture<Void> updateBucket(Map<String, String> settings, final CoreCommonOptions options) {
String bucketName = getBucketName(settings);
RequestSpan span = CbTracing.newSpan(core.context(), TracingIdentifiers.SPAN_REQUEST_MB_UPDATE_BUCKET, options.parentSpan().orElse(null));
span.attribute(TracingIdentifiers.ATTR_NAME, bucketName);
CoreCommonOptions getAllBucketOptions = options.withParentSpan(span);
return Mono.fromFuture(() -> getAllBuckets(getAllBucketOptions)).map(buckets -> buckets.containsKey(bucketName)).flatMap(bucketExists -> {
if (!bucketExists) {
return Mono.error(BucketNotFoundException.forBucket(bucketName));
}
return Mono.fromFuture(httpClient.post(pathForBucket(bucketName), options).form(convertSettingsToParams(settings, true)).exec(core).thenApply(response -> null));
}).then().doOnTerminate(span::end).toFuture();
}
Aggregations