本文整理匯總了Java中com.datastax.driver.core.Metadata類的典型用法代碼示例。如果您正苦於以下問題:Java Metadata類的具體用法?Java Metadata怎麽用?Java Metadata使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Metadata類屬於com.datastax.driver.core包,在下文中一共展示了Metadata類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: connect
import com.datastax.driver.core.Metadata; //導入依賴的package包/類
private void connect(String seeds) {
if (getWithSSL()) {
LOGGER.info("SSL mode enabled");
try {
SSLOptions sslOptions = new SSLOptions(SSLContext.getDefault(), CIPHERS);
builder = Cluster.builder().withSSL(sslOptions);
} catch (NoSuchAlgorithmException e) {
LOGGER.error("Unable to setup SSL Options for Cassandra");
}
}
String[] contactPoints = seeds.split(",");
for (String contactPoint : contactPoints) {
LOGGER.info("Adding Cassandra contact point " + contactPoint);
builder.addContactPoints(contactPoint);
}
cluster = builder.build();
Metadata metadata = cluster.getMetadata();
for (Host host : metadata.getAllHosts()) {
LOGGER.info("Datacenter "+ host.getDatacenter() + "Host " + host.getAddress() + "Rack " + host.getRack());
session = cluster.connect();
}
}
開發者ID:emc-cloudfoundry,項目名稱:cassandra-cf-service-boshrelease,代碼行數:27,代碼來源:CassandraAdminService.java
示例2: execute
import com.datastax.driver.core.Metadata; //導入依賴的package包/類
@Override
public ResultSet<CassandraDBContext> execute(Query<CassandraDBContext> query) throws QueryExecutionException {
try (Cluster cassandraConnection = buildConnection()) {
final Metadata metadata = cassandraConnection.getMetadata();
System.out.printf("Connected to cluster: %s", metadata.getClusterName());
for (final Host host : metadata.getAllHosts()) {
System.out.printf("Datacenter: %s; Host: %s; Rack: %s", host.getDatacenter(), host.getAddress(),
host.getRack());
}
try (Session session = cassandraConnection.connect()) {
String queryToExecute = query.getQuery();
System.out.println(queryToExecute);
com.datastax.driver.core.ResultSet resultSet = session.execute(queryToExecute);
printResultSet(resultSet);
ExecutionInfo executionInfo = resultSet.getExecutionInfo();
System.out.println(executionInfo);
}
}
// There isn't any resultset for these use-case
return new CassandraResultSet();
}
示例3: connectToMultipleAddresses
import com.datastax.driver.core.Metadata; //導入依賴的package包/類
private void connectToMultipleAddresses(String address) {
PoolingOptions poolingOptions =
new PoolingOptions()
.setConnectionsPerHost(HostDistance.LOCAL, 4, 10)
.setConnectionsPerHost(HostDistance.REMOTE, 2, 4);
String[] music_hosts = address.split(",");
if (cluster == null) {
logger.debug("Initializing MUSIC Client with endpoints "+address);
cluster = Cluster.builder()
.withPort(9042)
.withPoolingOptions(poolingOptions)
.withoutMetrics()
.addContactPoints(music_hosts)
.build();
Metadata metadata = cluster.getMetadata();
logger.debug("Connected to cluster:"+metadata.getClusterName()+" at address:"+address);
}
session = cluster.connect();
}
示例4: connectToCassaCluster
import com.datastax.driver.core.Metadata; //導入依賴的package包/類
@SuppressWarnings("unused")
private void connectToCassaCluster(String address) {
PoolingOptions poolingOptions =
new PoolingOptions()
.setConnectionsPerHost(HostDistance.LOCAL, 4, 10)
.setConnectionsPerHost(HostDistance.REMOTE, 2, 4);
Iterator<String> it = getAllPossibleLocalIps().iterator();
logger.debug("Iterating through possible ips:"+getAllPossibleLocalIps());
while (it.hasNext()) {
try {
cluster = Cluster.builder()
.withPort(9042)
.withPoolingOptions(poolingOptions)
.withoutMetrics()
.addContactPoint(address)
.build();
//cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(Integer.MAX_VALUE);
Metadata metadata = cluster.getMetadata();
logger.debug("Connected to cluster:"+metadata.getClusterName()+" at address:"+address);
session = cluster.connect();
break;
} catch (NoHostAvailableException e) {
address = it.next();
}
}
}
示例5: connectToCassaCluster
import com.datastax.driver.core.Metadata; //導入依賴的package包/類
private void connectToCassaCluster(){
Iterator<String> it = getAllPossibleLocalIps().iterator();
String address= "localhost";
logger.debug("Connecting to cassa cluster: Iterating through possible ips:"+getAllPossibleLocalIps());
while(it.hasNext()){
try {
cluster = Cluster.builder().withPort(9042).addContactPoint(address).build();
//cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(Integer.MAX_VALUE);
Metadata metadata = cluster.getMetadata();
logger.debug("Connected to cassa cluster "+metadata.getClusterName()+" at "+address);
/* for ( Host host : metadata.getAllHosts() ) {
.out.printf("Datacenter: %s; Host broadcast: %s; Rack: %s\n",
host.getDatacenter(), host.getBroadcastAddress(), host.getRack());
}*/
session = cluster.connect();
break;
} catch (NoHostAvailableException e) {
address= it.next();
}
}
}
示例6: connectToCassaCluster
import com.datastax.driver.core.Metadata; //導入依賴的package包/類
private void connectToCassaCluster(){
Iterator<String> it = getAllPossibleLocalIps().iterator();
String address= "localhost";
// logger.debug("Connecting to cassa cluster: Iterating through possible ips:"+getAllPossibleLocalIps());
while(it.hasNext()){
try {
cluster = Cluster.builder().withPort(9042).addContactPoint(address).build();
//cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(Integer.MAX_VALUE);
Metadata metadata = cluster.getMetadata();
// logger.debug("Connected to cassa cluster "+metadata.getClusterName()+" at "+address);
/* for ( Host host : metadata.getAllHosts() ) {
System.out.printf("Datacenter: %s; Host broadcast: %s; Rack: %s\n",
host.getDatacenter(), host.getBroadcastAddress(), host.getRack());
}*/
session = cluster.connect();
break;
} catch (NoHostAvailableException e) {
address= it.next();
}
}
}
示例7: testClusterHintsPollerWhenNodeDown
import com.datastax.driver.core.Metadata; //導入依賴的package包/類
@Test
public void testClusterHintsPollerWhenNodeDown() throws UnknownHostException {
ClusterHintsPoller clusterHintsPoller = new ClusterHintsPoller();
Session mockSession = mock(Session.class);
Cluster mockCluster = mock(Cluster.class);
Metadata mockMetadata = mock(Metadata.class);
when(mockCluster.getMetadata()).thenReturn(mockMetadata);
when(mockCluster.getClusterName()).thenReturn("test-cluster");
Host node1 = mock(Host.class);
when(node1.getAddress()).thenReturn(InetAddress.getByName("127.0.0.1"));
Host node2 = mock(Host.class);
when(node2.getAddress()).thenReturn(InetAddress.getByName("127.0.0.2"));
Host node3 = mock(Host.class);
when(node3.getAddress()).thenReturn(InetAddress.getByName("127.0.0.3"));
when(mockSession.getCluster()).thenReturn(mockCluster);
// The first node queried is down
when(mockSession.execute(any(Statement.class))).thenThrow(new NoHostAvailableException(ImmutableMap.<InetSocketAddress, Throwable>of()));
when(mockMetadata.getAllHosts()).thenReturn(ImmutableSet.of(node1, node2, node3));
HintsPollerResult actualResult = clusterHintsPoller.getOldestHintsInfo(mockSession);
// Make sure HintsPollerResult fails
assertFalse(actualResult.areAllHostsPolling(), "Result should show hosts failing");
assertEquals(actualResult.getHostFailure(), ImmutableSet.of(InetAddress.getByName("127.0.0.1")), "Node 1 should return with host failure");
}
示例8: ensureMockCassandraRunningAndEstablished
import com.datastax.driver.core.Metadata; //導入依賴的package包/類
/**
* Ensures that the Mock Cassandra instance is up and running. Will reinit
* the database every time it is called.
*
* @param cassandraKeyspace Cassandra keyspace to setup.
* @return A cluster object.
* @throws ConfigurationException
* @throws IOException
* @throws InterruptedException
* @throws TTransportException
*/
public static Cluster ensureMockCassandraRunningAndEstablished(String cassandraKeyspace) throws ConfigurationException, IOException, InterruptedException, TTransportException
{
Cluster cluster;
long timeout = 60000;
EmbeddedCassandraServerHelper.startEmbeddedCassandra(timeout);
cluster = Cluster.builder().addContactPoints("127.0.0.1").withPort(9142).build();
//Thread.sleep(20000);//time to let cassandra startup
final Metadata metadata = cluster.getMetadata();
Session session = cluster.connect();
Utils.initDatabase(DB_CQL, session);
session = cluster.connect(cassandraKeyspace);
logger.info("Connected to cluster: " + metadata.getClusterName() + '\n');
return cluster;
}
示例9: loadTablesFromRemote
import com.datastax.driver.core.Metadata; //導入依賴的package包/類
public static Cluster loadTablesFromRemote(String host, int port, String cfidOverrides) throws IOException {
Map<String, UUID> cfs = parseOverrides(cfidOverrides);
Cluster.Builder builder = Cluster.builder().addContactPoints(host).withPort(port);
Cluster cluster = builder.build();
Metadata metadata = cluster.getMetadata();
IPartitioner partitioner = FBUtilities.newPartitioner(metadata.getPartitioner());
if (DatabaseDescriptor.getPartitioner() == null)
DatabaseDescriptor.setPartitionerUnsafe(partitioner);
for (com.datastax.driver.core.KeyspaceMetadata ksm : metadata.getKeyspaces()) {
if (!ksm.getName().equals("system")) {
for (TableMetadata tm : ksm.getTables()) {
String name = ksm.getName()+"."+tm.getName();
try {
CassandraUtils.tableFromCQL(
new ByteArrayInputStream(tm.asCQLQuery().getBytes()),
cfs.get(name) != null ? cfs.get(name) : tm.getId());
} catch(SyntaxException e) {
// ignore tables that we cant parse (probably dse)
logger.debug("Ignoring table " + name + " due to syntax exception " + e.getMessage());
}
}
}
}
return cluster;
}
示例10: StoreConnection
import com.datastax.driver.core.Metadata; //導入依賴的package包/類
/**
* Constructor
*
* @param nodes a list of one or more Cassandra nodes to connect to. Note
* that not all Cassandra nodes in the cluster need be
* supplied; one will suffice however if that node is
* unavailable the connection attempt will fail, even if the
* others are available.
*/
public StoreConnection(List<String> nodes) {
Cluster.Builder builder = Cluster.builder();
for (String node : nodes) {
builder.addContactPoint(node);
}
cluster = builder.build();
Metadata metadata = cluster.getMetadata();
System.out.printf("Connected to cluster: %s%n",
metadata.getClusterName());
for (Host host : metadata.getAllHosts()) {
System.out.printf("Datacenter: %s; Host: %s; Rack: %s%n",
host.getDatacenter(), host.getAddress(), host.getRack());
}
session = cluster.connect();
}
示例11: SmartThriftClient
import com.datastax.driver.core.Metadata; //導入依賴的package包/類
public SmartThriftClient(StressSettings settings, String keyspace, Metadata metadata)
{
this.metadata = metadata;
this.keyspace = keyspace;
this.settings = settings;
if (!settings.node.isWhiteList)
{
whiteset = null;
whitelist = null;
}
else
{
whiteset = settings.node.resolveAllSpecified();
whitelist = Arrays.asList(whiteset.toArray(new InetAddress[0]));
}
}
示例12: connectsToTheCassandraCluster
import com.datastax.driver.core.Metadata; //導入依賴的package包/類
@Test
@ConditionalIgnoreRule.IgnoreIf(condition = NoRunningCassandraDbForTests.class)
public void connectsToTheCassandraCluster() throws Exception {
Cluster cluster = Cluster.builder()
.addContactPoint(new NoRunningCassandraDbForTests().getHost())
.withPort(9042)
.withClusterName("BluePrint")
.build();
Metadata metadata = cluster.getMetadata();
LOG.info("Clustername:" + metadata.getClusterName());
LOG.info("Partitioner:" + metadata.getPartitioner());
LOG.info("Hosts:" + metadata.getAllHosts());
LOG.info("KeySpaces:" + metadata.getKeyspaces());
Session session = cluster.connect("system");//system keyspace should always be present
assertNotNull(session);
session.close();
}
示例13: getSchema
import com.datastax.driver.core.Metadata; //導入依賴的package包/類
public List<Column> getSchema(String keySpace, String tableName) {
Metadata m = session.getCluster().getMetadata();
KeyspaceMetadata km = m.getKeyspace(keySpace);
if (km == null)
return null;
TableMetadata tm = km.getTable(tableName);
if (tm == null)
return null;
// build schema
List<Column> columns = new LinkedList<Column>();
for (ColumnMetadata cm : tm.getColumns()) {
if (!meta.contains(cm.getName()))
columns.add(Column.newBuilder().setName(cm.getName())
.setType(toSimbaType(cm.getType().toString())).build());
}
return columns;
}
示例14: fetchKeys
import com.datastax.driver.core.Metadata; //導入依賴的package包/類
private void fetchKeys()
{
// get CF meta data
TableMetadata tableMetadata = session.getCluster()
.getMetadata()
.getKeyspace(Metadata.quote(keyspace))
.getTable(Metadata.quote(cfName));
if (tableMetadata == null)
{
throw new RuntimeException("No table metadata found for " + keyspace + "." + cfName);
}
//Here we assume that tableMetadata.getPartitionKey() always
//returns the list of columns in order of component_index
for (ColumnMetadata partitionKey : tableMetadata.getPartitionKey())
{
partitionKeys.add(partitionKey.getName());
}
}
示例15: provideCluster
import com.datastax.driver.core.Metadata; //導入依賴的package包/類
@Provides @Singleton Cluster provideCluster() {
try {
Cluster cluster = Cluster.builder()
.addContactPointsWithPorts(Arrays.asList(
// new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 9042) // mvn cassandra:run + nodetool enablebinary
new InetSocketAddress(InetAddress.getByName("localhost"), 9142) // cassandraunit
))
.withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE)
.withReconnectionPolicy(new ExponentialReconnectionPolicy(100L, 5000L))
.build();
Metadata metadata = cluster.getMetadata();
LOGGER.info("Connected to cluster: '{}'", metadata.getClusterName());
metadata.getAllHosts()
.forEach(host -> LOGGER.info("Datacenter: '{}'; Host: '{}'; Rack: '{}'",
new Object[] { host.getDatacenter(), host.getAddress(), host.getRack() })
);
return cluster;
} catch (UnknownHostException e) {
LOGGER.error("Can't connect to Cassandra", e);
return null;
}
}