/** * 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(); } }
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);
@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))); }
public TestHost(InetSocketAddress address) { super(address, new ConvictionPolicy.DefaultConvictionPolicy.Factory(), Cluster.builder().addContactPoints("localhost").build().manager); } }
@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(); }
@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; } }
@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); }
/** * 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(); }
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)));
/** * 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(); }
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)));
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(); } }
@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); }
@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(); } }
/** * 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); } }
/** * 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(); }
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) {
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());