Search in sources :

Example 1 with RequestTarget

use of com.couchbase.client.core.msg.RequestTarget 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())));
        });
    });
}
Also used : ClusterConfig(com.couchbase.client.core.config.ClusterConfig) CbCollections.isNullOrEmpty(com.couchbase.client.core.util.CbCollections.isNullOrEmpty) CoreHttpRequest(com.couchbase.client.core.endpoint.http.CoreHttpRequest) TimeoutException(com.couchbase.client.core.error.TimeoutException) RequestTarget(com.couchbase.client.core.msg.RequestTarget) KvPingRequest(com.couchbase.client.core.msg.kv.KvPingRequest) CoreCommonOptions(com.couchbase.client.core.endpoint.http.CoreCommonOptions) HashSet(java.util.HashSet) ServiceType(com.couchbase.client.core.service.ServiceType) Duration(java.time.Duration) Map(java.util.Map) CoreHttpPath.path(com.couchbase.client.core.endpoint.http.CoreHttpPath.path) Stability(com.couchbase.client.core.annotation.Stability) RequestContext(com.couchbase.client.core.msg.RequestContext) BucketConfig(com.couchbase.client.core.config.BucketConfig) KvPingResponse(com.couchbase.client.core.msg.kv.KvPingResponse) Reactor(com.couchbase.client.core.Reactor) NodeInfo(com.couchbase.client.core.config.NodeInfo) Set(java.util.Set) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Flux(reactor.core.publisher.Flux) Optional(java.util.Optional) CollectionIdentifier(com.couchbase.client.core.io.CollectionIdentifier) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) Core(com.couchbase.client.core.Core) PortInfo(com.couchbase.client.core.config.PortInfo) KvPingRequest(com.couchbase.client.core.msg.kv.KvPingRequest) KvPingResponse(com.couchbase.client.core.msg.kv.KvPingResponse) Duration(java.time.Duration) CollectionIdentifier(com.couchbase.client.core.io.CollectionIdentifier)

Example 2 with RequestTarget

use of com.couchbase.client.core.msg.RequestTarget in project couchbase-jvm-clients by couchbase.

the class HealthPinger method pingHttpEndpoint.

private static Mono<EndpointPingReport> pingHttpEndpoint(final Core core, final RequestTarget target, final CoreCommonOptions options, final String path) {
    return Mono.defer(() -> {
        CoreHttpRequest request = core.httpClient(target).get(path(path), options).build();
        core.send(request);
        return Reactor.wrap(request, request.response(), true).map(response -> {
            request.context().logicallyComplete();
            return assembleSuccessReport(request.context(), response.channelId(), Optional.empty());
        }).onErrorResume(throwable -> {
            request.context().logicallyComplete();
            return Mono.just(assembleFailureReport(throwable, request.context(), Optional.empty()));
        });
    });
}
Also used : ClusterConfig(com.couchbase.client.core.config.ClusterConfig) CbCollections.isNullOrEmpty(com.couchbase.client.core.util.CbCollections.isNullOrEmpty) CoreHttpRequest(com.couchbase.client.core.endpoint.http.CoreHttpRequest) TimeoutException(com.couchbase.client.core.error.TimeoutException) RequestTarget(com.couchbase.client.core.msg.RequestTarget) KvPingRequest(com.couchbase.client.core.msg.kv.KvPingRequest) CoreCommonOptions(com.couchbase.client.core.endpoint.http.CoreCommonOptions) HashSet(java.util.HashSet) ServiceType(com.couchbase.client.core.service.ServiceType) Duration(java.time.Duration) Map(java.util.Map) CoreHttpPath.path(com.couchbase.client.core.endpoint.http.CoreHttpPath.path) Stability(com.couchbase.client.core.annotation.Stability) RequestContext(com.couchbase.client.core.msg.RequestContext) BucketConfig(com.couchbase.client.core.config.BucketConfig) KvPingResponse(com.couchbase.client.core.msg.kv.KvPingResponse) Reactor(com.couchbase.client.core.Reactor) NodeInfo(com.couchbase.client.core.config.NodeInfo) Set(java.util.Set) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Flux(reactor.core.publisher.Flux) Optional(java.util.Optional) CollectionIdentifier(com.couchbase.client.core.io.CollectionIdentifier) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) Core(com.couchbase.client.core.Core) PortInfo(com.couchbase.client.core.config.PortInfo) CoreHttpRequest(com.couchbase.client.core.endpoint.http.CoreHttpRequest)

Aggregations

Core (com.couchbase.client.core.Core)2 Reactor (com.couchbase.client.core.Reactor)2 Stability (com.couchbase.client.core.annotation.Stability)2 BucketConfig (com.couchbase.client.core.config.BucketConfig)2 ClusterConfig (com.couchbase.client.core.config.ClusterConfig)2 NodeInfo (com.couchbase.client.core.config.NodeInfo)2 PortInfo (com.couchbase.client.core.config.PortInfo)2 CoreCommonOptions (com.couchbase.client.core.endpoint.http.CoreCommonOptions)2 CoreHttpPath.path (com.couchbase.client.core.endpoint.http.CoreHttpPath.path)2 CoreHttpRequest (com.couchbase.client.core.endpoint.http.CoreHttpRequest)2 TimeoutException (com.couchbase.client.core.error.TimeoutException)2 CollectionIdentifier (com.couchbase.client.core.io.CollectionIdentifier)2 RequestContext (com.couchbase.client.core.msg.RequestContext)2 RequestTarget (com.couchbase.client.core.msg.RequestTarget)2 KvPingRequest (com.couchbase.client.core.msg.kv.KvPingRequest)2 KvPingResponse (com.couchbase.client.core.msg.kv.KvPingResponse)2 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)2 ServiceType (com.couchbase.client.core.service.ServiceType)2 CbCollections.isNullOrEmpty (com.couchbase.client.core.util.CbCollections.isNullOrEmpty)2 Duration (java.time.Duration)2