Search in sources :

Example 1 with KV

use of com.couchbase.client.core.service.ServiceType.KV in project couchbase-elasticsearch-connector by couchbase.

the class SeedNodeHelper method getKvNodes.

/**
 * Returns complete host and port information for every node running the KV service.
 */
public static Set<SeedNode> getKvNodes(Bucket bucket, String connectionString, boolean tls, NetworkResolution networkResolution, Duration timeout) {
    // Bucket config is most reliable way to determine KV ports
    BucketConfig config = CouchbaseHelper.getConfig(bucket, timeout);
    // so the actual node names can be used.
    if (networkResolution.equals(NetworkResolution.AUTO)) {
        EventBus eventBus = bucket.environment().eventBus();
        // The Java client calls seedNodesFromConnectionString during bootstrap, but the results
        // are not accessible here. Call it again.
        Set<String> seedHosts = ConnectionStringUtil.seedNodesFromConnectionString(connectionString, true, tls, eventBus).stream().map(SeedNode::address).collect(toSet());
        networkResolution = inferNetwork(config, networkResolution, seedHosts);
    }
    // Resolve alternate addresses
    // so lambda can access it
    NetworkResolution finalNetworkResolution = networkResolution;
    return config.nodes().stream().map(node -> new ResolvedNodeInfo(node, tls, finalNetworkResolution)).map(node -> SeedNode.create(node.host(), node.port(KV), node.port(MANAGER))).filter(node -> node.kvPort().isPresent()).collect(toSet());
}
Also used : KV(com.couchbase.client.core.service.ServiceType.KV) NodeInfo(com.couchbase.client.core.config.NodeInfo) CouchbaseException(com.couchbase.client.dcp.core.CouchbaseException) Set(java.util.Set) AlternateAddress(com.couchbase.client.core.config.AlternateAddress) ConnectionStringUtil(com.couchbase.client.core.util.ConnectionStringUtil) HashMap(java.util.HashMap) SeedNode(com.couchbase.client.core.env.SeedNode) MANAGER(com.couchbase.client.core.service.ServiceType.MANAGER) RedactableArgument.system(com.couchbase.client.dcp.core.logging.RedactableArgument.system) Bucket(com.couchbase.client.java.Bucket) EventBus(com.couchbase.client.core.cnc.EventBus) NetworkResolution(com.couchbase.client.core.env.NetworkResolution) ServiceType(com.couchbase.client.core.service.ServiceType) CouchbaseHelper(com.couchbase.connector.dcp.CouchbaseHelper) Duration(java.time.Duration) Map(java.util.Map) Optional(java.util.Optional) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap) BucketConfig(com.couchbase.client.core.config.BucketConfig) Collectors.toSet(java.util.stream.Collectors.toSet) NetworkResolution(com.couchbase.client.core.env.NetworkResolution) EventBus(com.couchbase.client.core.cnc.EventBus) BucketConfig(com.couchbase.client.core.config.BucketConfig)

Example 2 with KV

use of com.couchbase.client.core.service.ServiceType.KV in project kafka-connect-couchbase by couchbase.

the class SeedNodeHelper method getKvNodes.

/**
 * Returns complete host and port information for every node running the KV service.
 */
public static Set<SeedNode> getKvNodes(Bucket bucket, String connectionString, boolean tls, NetworkResolution networkResolution, Duration timeout) {
    // Bucket config is most reliable way to determine KV ports
    BucketConfig config = CouchbaseHelper.getConfig(bucket, timeout);
    // so the actual node names can be used.
    if (networkResolution.equals(NetworkResolution.AUTO)) {
        EventBus eventBus = bucket.environment().eventBus();
        // The Java client calls seedNodesFromConnectionString during bootstrap, but the results
        // are not accessible here. Call it again.
        Set<String> seedHosts = ConnectionStringUtil.seedNodesFromConnectionString(connectionString, true, tls, eventBus).stream().map(SeedNode::address).collect(toSet());
        networkResolution = inferNetwork(config, networkResolution, seedHosts);
    }
    // Resolve alternate addresses
    // so lambda can access it
    NetworkResolution finalNetworkResolution = networkResolution;
    return config.nodes().stream().map(node -> new ResolvedNodeInfo(node, tls, finalNetworkResolution)).map(node -> SeedNode.create(node.host(), node.port(KV), node.port(MANAGER))).filter(node -> node.kvPort().isPresent()).collect(toSet());
}
Also used : KV(com.couchbase.client.core.service.ServiceType.KV) NodeInfo(com.couchbase.client.core.config.NodeInfo) CouchbaseException(com.couchbase.client.dcp.core.CouchbaseException) Set(java.util.Set) AlternateAddress(com.couchbase.client.core.config.AlternateAddress) ConnectionStringUtil(com.couchbase.client.core.util.ConnectionStringUtil) HashMap(java.util.HashMap) SeedNode(com.couchbase.client.core.env.SeedNode) MANAGER(com.couchbase.client.core.service.ServiceType.MANAGER) RedactableArgument.system(com.couchbase.client.dcp.core.logging.RedactableArgument.system) Bucket(com.couchbase.client.java.Bucket) EventBus(com.couchbase.client.core.cnc.EventBus) NetworkResolution(com.couchbase.client.core.env.NetworkResolution) ServiceType(com.couchbase.client.core.service.ServiceType) Duration(java.time.Duration) Map(java.util.Map) Optional(java.util.Optional) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap) BucketConfig(com.couchbase.client.core.config.BucketConfig) Collectors.toSet(java.util.stream.Collectors.toSet) NetworkResolution(com.couchbase.client.core.env.NetworkResolution) EventBus(com.couchbase.client.core.cnc.EventBus) BucketConfig(com.couchbase.client.core.config.BucketConfig)

Aggregations

EventBus (com.couchbase.client.core.cnc.EventBus)2 AlternateAddress (com.couchbase.client.core.config.AlternateAddress)2 BucketConfig (com.couchbase.client.core.config.BucketConfig)2 NodeInfo (com.couchbase.client.core.config.NodeInfo)2 NetworkResolution (com.couchbase.client.core.env.NetworkResolution)2 SeedNode (com.couchbase.client.core.env.SeedNode)2 ServiceType (com.couchbase.client.core.service.ServiceType)2 KV (com.couchbase.client.core.service.ServiceType.KV)2 MANAGER (com.couchbase.client.core.service.ServiceType.MANAGER)2 ConnectionStringUtil (com.couchbase.client.core.util.ConnectionStringUtil)2 CouchbaseException (com.couchbase.client.dcp.core.CouchbaseException)2 RedactableArgument.system (com.couchbase.client.dcp.core.logging.RedactableArgument.system)2 Bucket (com.couchbase.client.java.Bucket)2 Duration (java.time.Duration)2 Collections.unmodifiableMap (java.util.Collections.unmodifiableMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors.toSet (java.util.stream.Collectors.toSet)2