use of com.couchbase.client.core.config.AlternateAddress in project couchbase-jvm-clients by couchbase.
the class Core method reconfigureBuckets.
/**
* Contains logic to perform reconfiguration for a bucket config.
*
* @param bucketConfigs the flux of bucket configs currently open.
* @return a mono once reconfiguration for all buckets is complete
*/
private Mono<Void> reconfigureBuckets(final Flux<BucketConfig> bucketConfigs) {
return bucketConfigs.flatMap(bc -> Flux.fromIterable(bc.nodes()).flatMap(ni -> {
boolean tls = coreContext.environment().securityConfig().tlsEnabled();
Set<Map.Entry<ServiceType, Integer>> aServices = null;
Optional<String> alternateAddress = coreContext.alternateAddress();
String aHost = null;
if (alternateAddress.isPresent()) {
AlternateAddress aa = ni.alternateAddresses().get(alternateAddress.get());
aHost = aa.hostname();
aServices = tls ? aa.sslServices().entrySet() : aa.services().entrySet();
}
if (isNullOrEmpty(aServices)) {
aServices = tls ? ni.sslServices().entrySet() : ni.services().entrySet();
}
final String alternateHost = aHost;
final Set<Map.Entry<ServiceType, Integer>> services = aServices;
Flux<Void> serviceRemoveFlux = Flux.fromIterable(Arrays.asList(ServiceType.values())).filter(s -> {
for (Map.Entry<ServiceType, Integer> inConfig : services) {
if (inConfig.getKey() == s) {
return false;
}
}
return true;
}).flatMap(s -> removeServiceFrom(ni.identifier(), s, s.scope() == ServiceScope.BUCKET ? Optional.of(bc.name()) : Optional.empty()).onErrorResume(throwable -> {
eventBus.publish(new ServiceReconfigurationFailedEvent(coreContext, ni.hostname(), s, throwable));
return Mono.empty();
}));
Flux<Void> serviceAddFlux = Flux.fromIterable(services).flatMap(s -> ensureServiceAt(ni.identifier(), s.getKey(), s.getValue(), s.getKey().scope() == ServiceScope.BUCKET ? Optional.of(bc.name()) : Optional.empty(), Optional.ofNullable(alternateHost)).onErrorResume(throwable -> {
eventBus.publish(new ServiceReconfigurationFailedEvent(coreContext, ni.hostname(), s.getKey(), throwable));
return Mono.empty();
}));
return Flux.merge(serviceAddFlux, serviceRemoveFlux);
})).then();
}
Aggregations