congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
Cluster.builder
Code IndexAdd Tabnine to your IDE (free)

How to use
builder
method
in
com.datastax.driver.core.Cluster

Best Java code snippets using com.datastax.driver.core.Cluster.builder (Showing top 20 results out of 1,188)

Refine searchRefine arrow

  • Cluster.Builder.withPort
  • Cluster.Builder.build
  • Cluster.Builder.addContactPoints
  • Cluster.connect
origin: kaaproject/kaa

/**
 *  Creates new  EndpointSpecificConfigurationMigration instance.
 */
public EndpointSpecificConfigurationMigration(String host, String db, String nosql) {
 cluster = Cluster.builder()
   .addContactPoint(host)
   .build();
 dbName = db;
 this.nosql = nosql;
}
origin: kaaproject/kaa

 /**
  * Add field use_raw_configuration_schema to endpointProfile that used to support devices using
  * SDK version 0.9.0
  */
 public void transform() {
  //mongo
  MongoClient client = new MongoClient(host);
  MongoDatabase database = client.getDatabase(dbName);
  MongoCollection<Document> endpointProfile = database.getCollection("endpoint_profile");
  endpointProfile.updateMany(new Document(), eq("$set", eq("use_raw_schema", false)));

  //cassandra
  Cluster cluster = Cluster.builder().addContactPoint(host).build();
  Session session = cluster.connect(dbName);
  session.execute("ALTER TABLE ep_profile ADD use_raw_schema boolean");
  session.close();
  cluster.close();

 }
}
origin: brianfrankcooper/YCSB

 cluster = Cluster.builder().withCredentials(username, password)
   .withPort(Integer.valueOf(port)).addContactPoints(hosts).build();
} else {
 cluster = Cluster.builder().withPort(Integer.valueOf(port))
   .addContactPoints(hosts).build();
session = cluster.connect(keyspace);
origin: testcontainers/testcontainers-java

public static Cluster getCluster(ContainerState containerState) {
  return Cluster.builder()
    .addContactPoint(containerState.getContainerIpAddress())
    .withPort(containerState.getMappedPort(CQL_PORT))
    .build();
}
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void testMissingRpcAddressAtStartup() throws Exception {
 deleteNode2RpcAddressFromNode1();
 // Use only one contact point to make sure that the control connection is on node1
 Cluster cluster =
   register(
     Cluster.builder()
       .addContactPoints(getContactPoints().get(0))
       .withPort(ccm().getBinaryPort())
       .build());
 cluster.connect();
 // Since node2's RPC address is unknown on our control host, it should have been ignored
 assertEquals(cluster.getMetrics().getConnectedToHosts().getValue().intValue(), 1);
 assertNull(cluster.getMetadata().getHost(getContactPointsWithPorts().get(1)));
}
origin: prestodb/presto

  public TestHost(InetSocketAddress address)
  {
    super(address, new ConvictionPolicy.DefaultConvictionPolicy.Factory(), Cluster.builder().addContactPoints("localhost").build().manager);
  }
}
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short", expectedExceptions = AuthenticationException.class)
public void should_fail_to_connect_without_credentials() {
 Cluster cluster =
   register(
     Cluster.builder()
       .addContactPoints(getContactPoints())
       .withPort(ccm().getBinaryPort())
       .build());
 cluster.connect();
}
origin: Netflix/conductor

  @Override
  public Cluster get() {
    String host = configuration.getHostAddress();
    int port = configuration.getPort();

    LOGGER.info("Connecting to cassandra cluster with host:{}, port:{}", host, port);

    Cluster cluster = Cluster.builder()
        .addContactPoint(host)
        .withPort(port)
        .build();

    Metadata metadata = cluster.getMetadata();
    LOGGER.info("Connected to cluster: {}", metadata.getClusterName());
    metadata.getAllHosts().forEach(h -> {
      LOGGER.info("Datacenter:{}, host:{}, rack: {}", h.getDatacenter(), h.getAddress(), h.getRack());
    });
    return cluster;
  }
}
origin: com.datastax.cassandra/cassandra-driver-core

@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);
}
origin: kaaproject/kaa

/**
 * Create a new instance of UpdateUuidsMigration.
 *
 * @param connection the connection to relational database
 * @param options    the options for configuring NoSQL databases
 */
public UpdateUuidsMigration(Connection connection, Options options) {
 this.connection = connection;
 client = new MongoClient(options.getHost());
 cluster = Cluster.builder()
   .addContactPoint(options.getHost())
   .build();
 dbName = options.getDbName();
 this.nosql = options.getNoSql();
}
origin: com.datastax.cassandra/cassandra-driver-core

Cluster cluster =
  register(
    Cluster.builder()
      .addContactPoints(getContactPoints())
      .withPort(ccm().getBinaryPort())
      .withCodecRegistry(codecRegistry)
      .build());
Session session = cluster.connect(keyspace);
setUpTupleTypes(cluster);
codecRegistry.register(new LocationCodec(TypeCodec.tuple(locationType)));
origin: kaaproject/kaa

/**
 * Create entity that responsible for data migration from old tables notification to
 * new ctl based ones.
 *
 * @param connection the connection to relational database
 * @param options    the options for configuring NoSQL databases
 */
public CtlNotificationMigration(Connection connection, Options options) {
 super(connection);
 client = new MongoClient(options.getHost());
 cluster = Cluster.builder()
   .addContactPoint(options.getHost())
   .build();
 dbName = options.getDbName();
 this.nosql = options.getDbName();
}
origin: com.datastax.cassandra/cassandra-driver-core

Cluster cluster =
  register(
    Cluster.builder()
      .addContactPoints(getContactPoints())
      .withPort(ccm().getBinaryPort())
      .withCodecRegistry(codecRegistry)
      .build());
Session session = cluster.connect(keyspace);
setUpTupleTypes(cluster);
codecRegistry.register(new LocationCodec(TypeCodec.tuple(locationType)));
origin: apache/nifi

  private Cluster createCluster(List<InetSocketAddress> contactPoints, SSLContext sslContext,
                 String username, String password) {
    Cluster.Builder builder = Cluster.builder().addContactPointsWithPorts(contactPoints);

    if (sslContext != null) {
      JdkSSLOptions sslOptions = JdkSSLOptions.builder()
          .withSSLContext(sslContext)
          .build();
      builder = builder.withSSL(sslOptions);
    }

    if (username != null && password != null) {
      builder = builder.withCredentials(username, password);
    }

    return builder.build();
  }
}
origin: com.datastax.cassandra/cassandra-driver-core

@BeforeMethod(groups = "short")
public void setUp() {
 sCluster = ScassandraCluster.builder().withNodes(4).build();
 sCluster.init();
 cluster =
   Cluster.builder()
     .addContactPoints(sCluster.address(1).getAddress())
     .withPort(sCluster.getBinaryPort())
     .withLoadBalancingPolicy(lbSpy)
     .withNettyOptions(nonQuietClusterCloseOptions)
     .build();
 session = cluster.connect();
 // Reset invocations before entering test.
 Mockito.reset(lbSpy);
}
origin: spring-projects/spring-data-examples

@Override
protected void before() throws Throwable {
  dependency.before();
  Cluster cluster = Cluster.builder().addContactPoint(getHost()).withPort(getPort())
      .withNettyOptions(new NettyOptions() {
        @Override
        public void onClusterClose(EventLoopGroup eventLoopGroup) {
          eventLoopGroup.shutdownGracefully(0, 0, TimeUnit.MILLISECONDS).syncUninterruptibly();
        }
      }).build();
  Session session = cluster.newSession();
  try {
    if (requiredVersion != null) {
      Version cassandraReleaseVersion = CassandraVersion.getReleaseVersion(session);
      if (cassandraReleaseVersion.isLessThan(requiredVersion)) {
        throw new AssumptionViolatedException(
            String.format("Cassandra at %s:%s runs in Version %s but we require at least %s", getHost(), getPort(),
                cassandraReleaseVersion, requiredVersion));
      }
    }
    session.execute(String.format("CREATE KEYSPACE IF NOT EXISTS %s \n"
        + "WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };", keyspaceName));
  } finally {
    session.close();
    cluster.close();
  }
}
origin: com.datastax.cassandra/cassandra-driver-core

 /**
  * Verifies that the driver can connect to 3.10 with the following combination of options: Version
  * UNSET Flag UNSET Expected version: V4
  *
  * @jira_ticket JAVA-1248
  */
 @Test(groups = "short")
 public void
   should_connect_after_renegotiation_when_no_version_explicitly_required_and_flag_not_set()
     throws Exception {
  // Note: when the driver's ProtocolVersion.NEWEST_SUPPORTED will be incremented to V6 or higher
  // the renegotiation will start downgrading the version from V6 to V4 instead of V5 to V4,
  // but the test should remain valid since it's executed against 3.10 exclusively
  Cluster cluster =
    Cluster.builder()
      .addContactPoints(getContactPoints())
      .withPort(ccm().getBinaryPort())
      .build();
  cluster.connect();
  assertThat(cluster.getConfiguration().getProtocolOptions().getProtocolVersion()).isEqualTo(V4);
 }
}
origin: apache/nifi

/**
 * Uses a Cluster.Builder to create a Cassandra cluster reference using the given parameters
 *
 * @param contactPoints The contact points (hostname:port list of Cassandra nodes)
 * @param sslContext    The SSL context (used for secure connections)
 * @param username      The username for connection authentication
 * @param password      The password for connection authentication
 * @return A reference to the Cluster object associated with the given Cassandra configuration
 */
protected Cluster createCluster(List<InetSocketAddress> contactPoints, SSLContext sslContext,
                String username, String password) {
  Cluster.Builder builder = Cluster.builder().addContactPointsWithPorts(contactPoints);
  if (sslContext != null) {
    JdkSSLOptions sslOptions = JdkSSLOptions.builder()
        .withSSLContext(sslContext)
        .build();
    builder = builder.withSSL(sslOptions);
  }
  if (username != null && password != null) {
    builder = builder.withCredentials(username, password);
  }
  return builder.build();
}
origin: com.datastax.cassandra/cassandra-driver-core

Cluster cluster =
  register(
    Cluster.builder()
      .addContactPoints(getContactPoints())
      .withPort(ccm().getBinaryPort())
      .withCredentials("bogus", "bogus")
      .build());
 cluster.connect();
 fail("Should throw AuthenticationException when attempting to connect");
} catch (AuthenticationException e) {
 try {
  cluster.connect();
  fail("Should throw IllegalStateException when attempting to connect again.");
 } catch (IllegalStateException e1) {
origin: prestodb/presto

requireNonNull(extraColumnMetadataCodec, "extraColumnMetadataCodec is null");
Cluster.Builder clusterBuilder = Cluster.builder()
    .withProtocolVersion(config.getProtocolVersion());
clusterBuilder.withPort(config.getNativeProtocolPort());
clusterBuilder.withReconnectionPolicy(new ExponentialReconnectionPolicy(500, 10000));
clusterBuilder.withRetryPolicy(config.getRetryPolicy().getPolicy());
    new ReopeningCluster(() -> {
      contactPoints.forEach(clusterBuilder::addContactPoint);
      return clusterBuilder.build();
    }),
    config.getNoHostAvailableRetryTimeout());
com.datastax.driver.coreClusterbuilder

Javadoc

Creates a new Cluster.Builder instance.

This is a convenience method for new Cluster.Builder().

Popular methods of Cluster

  • connect
    Creates a new session on this cluster, initialize it and sets the keyspace to the provided one. Note
  • getMetadata
    Returns read-only metadata on the connected cluster. This includes the known nodes with their status
  • close
    Initiates a shutdown of this cluster instance and blocks until that shutdown completes. This method
  • getConfiguration
    The cluster configuration.
  • isClosed
    Whether this Cluster instance has been closed. Note that this method returns true as soon as one of
  • getClusterName
    The name of this cluster object. Note that this is not the Cassandra cluster name, but rather a name
  • closeAsync
    Initiates a shutdown of this cluster instance. This method is asynchronous and return a future on th
  • register
    Registers the provided listener to be updated with schema change events. Registering the same liste
  • newSession
    Creates a new session on this cluster but does not initialize it. Because this method does not perfo
  • getMetrics
    The cluster metrics.
  • init
    Initialize this Cluster instance. This method creates an initial connection to one of the contact po
  • connectAsync
    Creates a new session on this cluster, and initializes it to the given keyspace asynchronously. This
  • init,
  • connectAsync,
  • unregister,
  • <init>,
  • buildFrom,
  • checkNotEmpty,
  • timeSince,
  • checkNotClosed,
  • getDriverVersion

Popular in Java

  • Finding current android device location
  • onRequestPermissionsResult (Fragment)
  • getContentResolver (Context)
  • getSharedPreferences (Context)
  • FileInputStream (java.io)
    An input stream that reads bytes from a file. File file = ...finally if (in != null) in.clos
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • TimerTask (java.util)
    The TimerTask class represents a task to run at a specified time. The task may be run once or repeat
  • Collectors (java.util.stream)
  • JComboBox (javax.swing)
  • JTable (javax.swing)
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now