use of com.couchbase.client.core.Core 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.Core in project couchbase-jvm-clients by couchbase.
the class WaitUntilReadyHelper method waitUntilReady.
@Stability.Internal
public static CompletableFuture<Void> waitUntilReady(final Core core, final Set<ServiceType> serviceTypes, final Duration timeout, final ClusterState desiredState, final Optional<String> bucketName) {
final WaitUntilReadyState state = new WaitUntilReadyState();
state.transition(WaitUntilReadyStage.CONFIG_LOAD);
return Flux.interval(Duration.ofMillis(10), core.context().environment().scheduler()).onBackpressureDrop().filter(i -> !(core.configurationProvider().bucketConfigLoadInProgress() || core.configurationProvider().globalConfigLoadInProgress() || (bucketName.isPresent() && core.configurationProvider().collectionRefreshInProgress()) || (bucketName.isPresent() && core.clusterConfig().bucketConfig(bucketName.get()) == null))).filter(i -> {
// created.
if (bucketName.isPresent()) {
state.transition(WaitUntilReadyStage.BUCKET_CONFIG_READY);
BucketConfig bucketConfig = core.clusterConfig().bucketConfig(bucketName.get());
long extNodes = bucketConfig.portInfos().stream().filter(p -> p.ports().containsKey(ServiceType.KV)).count();
long visibleNodes = bucketConfig.nodes().stream().filter(n -> n.services().containsKey(ServiceType.KV)).count();
return extNodes > 0 && extNodes == visibleNodes;
} else {
return true;
}
}).flatMap(i -> {
if (bucketName.isPresent()) {
state.transition(WaitUntilReadyStage.BUCKET_NODES_HEALTHY);
// To avoid tmpfails on the bucket, we double check that all nodes from the nodes list are
// in a healthy status - but for this we need to actually fetch the verbose config, since
// the terse one doesn't have that status in it.
GenericManagerRequest request = new GenericManagerRequest(core.context(), () -> new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/pools/default/buckets/" + bucketName.get()), true, null);
core.send(request);
return Reactor.wrap(request, request.response(), true).filter(response -> {
if (response.status() != ResponseStatus.SUCCESS) {
return false;
}
ObjectNode root = (ObjectNode) Mapper.decodeIntoTree(response.content());
ArrayNode nodes = (ArrayNode) root.get("nodes");
long healthy = StreamSupport.stream(nodes.spliterator(), false).filter(node -> node.get("status").asText().equals("healthy")).count();
return nodes.size() == healthy;
}).map(ignored -> i);
} else {
return Flux.just(i);
}
}).take(1).flatMap(aLong -> {
// to being ready at this point. Bucket level wait until ready is the way to go there.
if (!bucketName.isPresent() && !core.clusterConfig().hasClusterOrBucketConfig()) {
state.transition(WaitUntilReadyStage.COMPLETE);
WaitUntilReadyContext waitUntilReadyContext = new WaitUntilReadyContext(servicesToCheck(core, serviceTypes, bucketName), timeout, desiredState, bucketName, core.diagnostics().collect(Collectors.groupingBy(EndpointDiagnostics::type)), state);
core.context().environment().eventBus().publish(new WaitUntilReadyCompletedEvent(waitUntilReadyContext, WaitUntilReadyCompletedEvent.Reason.CLUSTER_LEVEL_NOT_SUPPORTED));
return Flux.empty();
}
state.transition(WaitUntilReadyStage.PING);
final Flux<ClusterState> diagnostics = Flux.interval(Duration.ofMillis(10), core.context().environment().scheduler()).onBackpressureDrop().map(i -> diagnosticsCurrentState(core)).takeUntil(s -> s == desiredState);
return Flux.concat(ping(core, servicesToCheck(core, serviceTypes, bucketName), timeout, bucketName), diagnostics);
}).then().timeout(timeout, Mono.defer(() -> {
WaitUntilReadyContext waitUntilReadyContext = new WaitUntilReadyContext(servicesToCheck(core, serviceTypes, bucketName), timeout, desiredState, bucketName, core.diagnostics().collect(Collectors.groupingBy(EndpointDiagnostics::type)), state);
CancellationErrorContext errorContext = new CancellationErrorContext(waitUntilReadyContext);
return Mono.error(new UnambiguousTimeoutException("WaitUntilReady timed out", errorContext));
}), core.context().environment().scheduler()).doOnSuccess(unused -> {
state.transition(WaitUntilReadyStage.COMPLETE);
WaitUntilReadyContext waitUntilReadyContext = new WaitUntilReadyContext(servicesToCheck(core, serviceTypes, bucketName), timeout, desiredState, bucketName, core.diagnostics().collect(Collectors.groupingBy(EndpointDiagnostics::type)), state);
core.context().environment().eventBus().publish(new WaitUntilReadyCompletedEvent(waitUntilReadyContext, WaitUntilReadyCompletedEvent.Reason.SUCCESS));
}).toFuture();
}
use of com.couchbase.client.core.Core 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();
}
use of com.couchbase.client.core.Core 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()));
});
});
}
use of com.couchbase.client.core.Core in project couchbase-jvm-clients by couchbase.
the class KeyValueChannelIntegrationTest method beforeAll.
@BeforeAll
static void beforeAll() {
TestNodeConfig node = config().nodes().get(0);
env = environment().eventBus(eventBus).build();
Core core = Core.create(env, authenticator(), seedNodes());
endpointContext = new EndpointContext(core.context(), new HostAndPort(node.hostname(), node.ports().get(Services.KV)), null, ServiceType.KV, Optional.empty(), Optional.of(config().bucketname()), Optional.empty());
eventLoopGroup = new NioEventLoopGroup(1);
}
Aggregations