builder.withAuthProvider(m_authProvider);
builder = builder.withAuthProvider(authProvider);
cluster.withAuthProvider(new PlainTextAuthProvider(username, password));
.addContactPoints(getContactPoints()) .withPort(ccm().getBinaryPort()) .withAuthProvider(authProvider) .build()); cluster.init();
public void init(String keyspace) { Cluster.Builder builder = Cluster.builder().addContactPoints(hosts).withPort(port); if (sslOptions != null) builder.withSSL(sslOptions); if (authProvider != null) builder = builder.withAuthProvider(authProvider); try (Cluster cluster = builder.build(); Session session = cluster.connect()) { Metadata metadata = cluster.getMetadata(); Set<TokenRange> tokenRanges = metadata.getTokenRanges(); IPartitioner partitioner = FBUtilities.newPartitioner(metadata.getPartitioner()); TokenFactory tokenFactory = partitioner.getTokenFactory(); for (TokenRange tokenRange : tokenRanges) { Set<Host> endpoints = metadata.getReplicas(Metadata.quote(keyspace), tokenRange); Range<Token> range = new Range<>(tokenFactory.fromString(tokenRange.getStart().getValue().toString()), tokenFactory.fromString(tokenRange.getEnd().getValue().toString())); for (Host endpoint : endpoints) addRangeForEndpoint(range, endpoint.getAddress()); } Types types = fetchTypes(keyspace, session); tables.putAll(fetchTables(keyspace, session, partitioner, types)); // We only need the CFMetaData for the views, so we only load that. tables.putAll(fetchViews(keyspace, session, partitioner, types)); } }
public static Cluster getInputCluster(String[] hosts, Configuration conf) { int port = getInputNativePort(conf); Optional<AuthProvider> authProvider = getAuthProvider(conf); Optional<SSLOptions> sslOptions = getSSLOptions(conf); Optional<Integer> protocolVersion = getProtocolVersion(conf); LoadBalancingPolicy loadBalancingPolicy = getReadLoadBalancingPolicy(conf, hosts); SocketOptions socketOptions = getReadSocketOptions(conf); QueryOptions queryOptions = getReadQueryOptions(conf); PoolingOptions poolingOptions = getReadPoolingOptions(conf); Cluster.Builder builder = Cluster.builder() .addContactPoints(hosts) .withPort(port) .withCompression(ProtocolOptions.Compression.NONE); if (authProvider.isPresent()) builder.withAuthProvider(authProvider.get()); if (sslOptions.isPresent()) builder.withSSL(sslOptions.get()); if (protocolVersion.isPresent()) { builder.withProtocolVersion(protocolVersion.get()); } builder.withLoadBalancingPolicy(loadBalancingPolicy) .withSocketOptions(socketOptions) .withQueryOptions(queryOptions) .withPoolingOptions(poolingOptions); return builder.build(); }
public static Cluster getCluster(String[] hosts, Configuration conf, int port) { Optional<AuthProvider> authProvider = getAuthProvider(conf); Optional<SSLOptions> sslOptions = getSSLOptions(conf); Optional<Integer> protocolVersion = getProtocolVersion(conf); LoadBalancingPolicy loadBalancingPolicy = getReadLoadBalancingPolicy(hosts); SocketOptions socketOptions = getReadSocketOptions(conf); QueryOptions queryOptions = getReadQueryOptions(conf); PoolingOptions poolingOptions = getReadPoolingOptions(conf); Cluster.Builder builder = Cluster.builder() .addContactPoints(hosts) .withPort(port) .withCompression(ProtocolOptions.Compression.NONE); if (authProvider.isPresent()) builder.withAuthProvider(authProvider.get()); if (sslOptions.isPresent()) builder.withSSL(sslOptions.get()); if (protocolVersion.isPresent()) { builder.withProtocolVersion(ProtocolVersion.fromInt(protocolVersion.get())); } builder.withLoadBalancingPolicy(loadBalancingPolicy) .withSocketOptions(socketOptions) .withQueryOptions(queryOptions) .withPoolingOptions(poolingOptions); return builder.build(); }
public static Cluster getCluster(String[] hosts, Configuration conf, int port) { Optional<AuthProvider> authProvider = getAuthProvider(conf); Optional<SSLOptions> sslOptions = getSSLOptions(conf); Optional<Integer> protocolVersion = getProtocolVersion(conf); LoadBalancingPolicy loadBalancingPolicy = getReadLoadBalancingPolicy(hosts); SocketOptions socketOptions = getReadSocketOptions(conf); QueryOptions queryOptions = getReadQueryOptions(conf); PoolingOptions poolingOptions = getReadPoolingOptions(conf); Cluster.Builder builder = Cluster.builder() .addContactPoints(hosts) .withPort(port) .withCompression(ProtocolOptions.Compression.NONE); if (authProvider.isPresent()) builder.withAuthProvider(authProvider.get()); if (sslOptions.isPresent()) builder.withSSL(sslOptions.get()); if (protocolVersion.isPresent()) { builder.withProtocolVersion(ProtocolVersion.fromInt(protocolVersion.get())); } builder.withLoadBalancingPolicy(loadBalancingPolicy) .withSocketOptions(socketOptions) .withQueryOptions(queryOptions) .withPoolingOptions(poolingOptions); return builder.build(); }
public void init(String keyspace) { Cluster.Builder builder = Cluster.builder().addContactPoints(hosts).withPort(port); if (sslOptions != null) builder.withSSL(sslOptions); if (authProvider != null) builder = builder.withAuthProvider(authProvider); try (Cluster cluster = builder.build(); Session session = cluster.connect()) { Metadata metadata = cluster.getMetadata(); Set<TokenRange> tokenRanges = metadata.getTokenRanges(); IPartitioner partitioner = FBUtilities.newPartitioner(metadata.getPartitioner()); TokenFactory tokenFactory = partitioner.getTokenFactory(); for (TokenRange tokenRange : tokenRanges) { Set<Host> endpoints = metadata.getReplicas(Metadata.quote(keyspace), tokenRange); Range<Token> range = new Range<>(tokenFactory.fromString(tokenRange.getStart().getValue().toString()), tokenFactory.fromString(tokenRange.getEnd().getValue().toString())); for (Host endpoint : endpoints) addRangeForEndpoint(range, endpoint.getAddress()); } Types types = fetchTypes(keyspace, session); tables.putAll(fetchTables(keyspace, session, partitioner, types)); // We only need the CFMetaData for the views, so we only load that. tables.putAll(fetchViews(keyspace, session, partitioner, types)); } }
public void init(String keyspace) { Cluster.Builder builder = Cluster.builder().addContactPoints(hosts).withPort(port); if (sslOptions != null) builder.withSSL(sslOptions); if (authProvider != null) builder = builder.withAuthProvider(authProvider); try (Cluster cluster = builder.build(); Session session = cluster.connect()) { Metadata metadata = cluster.getMetadata(); Set<TokenRange> tokenRanges = metadata.getTokenRanges(); IPartitioner partitioner = FBUtilities.newPartitioner(metadata.getPartitioner()); TokenFactory tokenFactory = partitioner.getTokenFactory(); for (TokenRange tokenRange : tokenRanges) { Set<Host> endpoints = metadata.getReplicas(Metadata.quote(keyspace), tokenRange); Range<Token> range = new Range<>(tokenFactory.fromString(tokenRange.getStart().getValue().toString()), tokenFactory.fromString(tokenRange.getEnd().getValue().toString())); for (Host endpoint : endpoints) addRangeForEndpoint(range, endpoint.getAddress()); } Types types = fetchTypes(keyspace, session); tables.putAll(fetchTables(keyspace, session, partitioner, types)); // We only need the CFMetaData for the views, so we only load that. tables.putAll(fetchViews(keyspace, session, partitioner, types)); } }
public static Cluster getCluster(String[] hosts, Configuration conf, int port) { Optional<AuthProvider> authProvider = getAuthProvider(conf); Optional<SSLOptions> sslOptions = getSSLOptions(conf); Optional<Integer> protocolVersion = getProtocolVersion(conf); LoadBalancingPolicy loadBalancingPolicy = getReadLoadBalancingPolicy(hosts); SocketOptions socketOptions = getReadSocketOptions(conf); QueryOptions queryOptions = getReadQueryOptions(conf); PoolingOptions poolingOptions = getReadPoolingOptions(conf); Cluster.Builder builder = Cluster.builder() .addContactPoints(hosts) .withPort(port) .withCompression(ProtocolOptions.Compression.NONE); if (authProvider.isPresent()) builder.withAuthProvider(authProvider.get()); if (sslOptions.isPresent()) builder.withSSL(sslOptions.get()); if (protocolVersion.isPresent()) { builder.withProtocolVersion(ProtocolVersion.fromInt(protocolVersion.get())); } builder.withLoadBalancingPolicy(loadBalancingPolicy) .withSocketOptions(socketOptions) .withQueryOptions(queryOptions) .withPoolingOptions(poolingOptions); return builder.build(); }
public static Cluster getInputCluster(String host, Configuration conf) { int port = getInputNativePort(conf); Optional<AuthProvider> authProvider = getAuthProvider(conf); Optional<SSLOptions> sslOptions = getSSLOptions(conf); String[] hosts = {host}; LoadBalancingPolicy loadBalancingPolicy = getReadLoadBalancingPolicy(conf, hosts); SocketOptions socketOptions = getReadSocketOptions(conf); QueryOptions queryOptions = getReadQueryOptions(conf); PoolingOptions poolingOptions = getReadPoolingOptions(conf); Cluster.Builder builder = Cluster.builder() .addContactPoint(host) .withPort(port) .withCompression(ProtocolOptions.Compression.NONE); if (authProvider.isPresent()) builder.withAuthProvider(authProvider.get()); if (sslOptions.isPresent()) builder.withSSL(sslOptions.get()); builder.withLoadBalancingPolicy(loadBalancingPolicy) .withSocketOptions(socketOptions) .withQueryOptions(queryOptions) .withPoolingOptions(poolingOptions); return builder.build(); }
/** Get a Cassandra cluster using hosts and port. */ private Cluster getCluster( List<String> hosts, int port, String username, String password, String localDc, String consistencyLevel) { Cluster.Builder builder = Cluster.builder().addContactPoints(hosts.toArray(new String[0])).withPort(port); if (username != null) { builder.withAuthProvider(new PlainTextAuthProvider(username, password)); } DCAwareRoundRobinPolicy.Builder dcAwarePolicyBuilder = new DCAwareRoundRobinPolicy.Builder(); if (localDc != null) { dcAwarePolicyBuilder.withLocalDc(localDc); } builder.withLoadBalancingPolicy(new TokenAwarePolicy(dcAwarePolicyBuilder.build())); if (consistencyLevel != null) { builder.withQueryOptions( new QueryOptions().setConsistencyLevel(ConsistencyLevel.valueOf(consistencyLevel))); } return builder.build(); }
/** * Create a new connection to a Cassandra cluster. * * @param clusterKey The cluster key which defines the contact points, ports, and authentication * parameters for the connection. * @return A new cluster connection. */ private static Cluster createConnectionToInstance( final ClusterKey clusterKey ) { LOG.info("Creating new cluster connection with key: {}", clusterKey); final Set<String> contactPoints = clusterKey.getContactPoints(); final Builder clusterBuilder = Cluster .builder() .addContactPoints(contactPoints.toArray(new String[contactPoints.size()])) .withPort(clusterKey.getContactPort()); if (clusterKey.getUsername() != null) { clusterBuilder.withAuthProvider( new PlainTextAuthProvider(clusterKey.getUsername(), clusterKey.getPassword())); } return clusterBuilder.build(); }
/** * Ensures that authentication is possible even if the server is busy during SASL handshake. * * @jira_ticket JAVA-1429 */ @Test(groups = "short") @CCMConfig(dirtiesContext = true) public void should_connect_with_slow_server() { Cluster cluster = Cluster.builder() .addContactPoints(getContactPoints()) .withPort(ccm().getBinaryPort()) .withAuthProvider(new SlowAuthProvider()) .withPoolingOptions(new PoolingOptions().setHeartbeatIntervalSeconds(1)) .build(); cluster.connect(); }
@Test(groups = "short") public void should_connect_with_credentials() { PlainTextAuthProvider authProvider = spy(new PlainTextAuthProvider("cassandra", "cassandra")); Cluster cluster = Cluster.builder() .addContactPoints(getContactPoints()) .withPort(ccm().getBinaryPort()) .withAuthProvider(authProvider) .build(); cluster.connect(); verify(authProvider, atLeastOnce()) .newAuthenticator( findHost(cluster, 1).getSocketAddress(), "org.apache.cassandra.auth.PasswordAuthenticator"); assertThat(cluster.getMetrics().getErrorMetrics().getAuthenticationErrors().getCount()) .isEqualTo(0); }
.withPort(ccm().getBinaryPort()) .withAuthProvider(authProvider) .withReconnectionPolicy(reconnectionPolicy) .build());
.addContactPoints(getContactPoints()) .withPort(ccm().getBinaryPort()) .withAuthProvider(authProvider) .build()); cluster.init();
@Test(groups = "short") public void should_connect_with_credentials() { PlainTextAuthProvider authProvider = spy(new PlainTextAuthProvider("cassandra", "cassandra")); Cluster cluster = Cluster.builder() .addContactPoints(getContactPoints()) .withPort(ccm().getBinaryPort()) .withAuthProvider(authProvider) .build(); cluster.connect(); verify(authProvider, atLeastOnce()) .newAuthenticator( findHost(cluster, 1).getSocketAddress(), "org.apache.cassandra.auth.PasswordAuthenticator"); assertThat(cluster.getMetrics().getErrorMetrics().getAuthenticationErrors().getCount()) .isEqualTo(0); }
/** * Ensures that authentication is possible even if the server is busy during SASL handshake. * * @jira_ticket JAVA-1429 */ @Test(groups = "short") @CCMConfig(dirtiesContext = true) public void should_connect_with_slow_server() { Cluster cluster = Cluster.builder() .addContactPoints(getContactPoints()) .withPort(ccm().getBinaryPort()) .withAuthProvider(new SlowAuthProvider()) .withPoolingOptions(new PoolingOptions().setHeartbeatIntervalSeconds(1)) .build(); cluster.connect(); }