Illustration Image

Cassandra.Link

The best knowledge base on Apache Cassandra®

Helping platform leaders, architects, engineers, and operators build scalable real time data platforms.

10/23/2020

Reading time:1 min

DataStax-Examples/cluster-topology-java

by DataStax-Examples

The DataStax Drivers store metadata about the database cluster that they are connected to, this information can be useful in applications and tools. This example shows how to access that metadata to retrieve the cluster topology in Java.Contributor(s): Tomasz Lelek - derived from hereObjectivesShow how to gather a Cassandra cluster's topology and schema using driver metadataProject LayoutApp.java - The main application fileHow this WorksThis samples shows how to use the Metadata class to retrieve information about:Cluster topology such as nodes, racks, and data centersKeyspacesTablesSetup and RunningPrerequisitesJava 8A Cassandra cluster is running and accessible through the contacts points identified by basic.contact-points (see application.conf).RunningTo build this application use the following command:mvn clean compileTo run this application use the following command:mvn exec:java -Dexec.mainClass="com.datastax.examples.App"This will produce something similar to the following output:Data Center: dc1; Host: /127.0.0.1:9042; Rack: rack1Keyspace: system_auth; Table: role_membersKeyspace: system_auth; Table: role_permissionsKeyspace: system_auth; Table: rolesKeyspace: system_schema; Table: aggregatesKeyspace: system_schema; Table: columnsKeyspace: system_schema; Table: dropped_columnsKeyspace: system_schema; Table: functionsKeyspace: system_schema; Table: indexesKeyspace: system_schema; Table: keyspacesKeyspace: system_schema; Table: tablesKeyspace: system_schema; Table: triggersKeyspace: system_schema; Table: typesKeyspace: system_schema; Table: viewsKeyspace: examples; Table: videosKeyspace: system_distributed; Table: parent_repair_historyKeyspace: system_distributed; Table: repair_historyKeyspace: system_distributed; Table: view_build_statusKeyspace: system; Table: IndexInfoKeyspace: system; Table: available_rangesKeyspace: system; Table: batchesKeyspace: system; Table: batchlogKeyspace: system; Table: built_viewsKeyspace: system; Table: compaction_historyKeyspace: system; Table: hintsKeyspace: system; Table: localKeyspace: system; Table: paxosKeyspace: system; Table: peer_eventsKeyspace: system; Table: peersKeyspace: system; Table: prepared_statementsKeyspace: system; Table: range_xfersKeyspace: system; Table: size_estimatesKeyspace: system; Table: sstable_activityKeyspace: system; Table: transferred_rangesKeyspace: system; Table: views_builds_in_progressKeyspace: system_traces; Table: eventsKeyspace: system_traces; Table: sessions

Illustration Image

The DataStax Drivers store metadata about the database cluster that they are connected to, this information can be useful in applications and tools. This example shows how to access that metadata to retrieve the cluster topology in Java.

Contributor(s): Tomasz Lelek - derived from here

Objectives

  • Show how to gather a Cassandra cluster's topology and schema using driver metadata

Project Layout

How this Works

This samples shows how to use the Metadata class to retrieve information about:

  • Cluster topology such as nodes, racks, and data centers
  • Keyspaces
  • Tables

Setup and Running

Prerequisites

  • Java 8
  • A Cassandra cluster is running and accessible through the contacts points identified by basic.contact-points (see application.conf).

Running

To build this application use the following command:

mvn clean compile

To run this application use the following command:

mvn exec:java -Dexec.mainClass="com.datastax.examples.App"

This will produce something similar to the following output:

Data Center: dc1; Host: /127.0.0.1:9042; Rack: rack1
Keyspace: system_auth; Table: role_members
Keyspace: system_auth; Table: role_permissions
Keyspace: system_auth; Table: roles
Keyspace: system_schema; Table: aggregates
Keyspace: system_schema; Table: columns
Keyspace: system_schema; Table: dropped_columns
Keyspace: system_schema; Table: functions
Keyspace: system_schema; Table: indexes
Keyspace: system_schema; Table: keyspaces
Keyspace: system_schema; Table: tables
Keyspace: system_schema; Table: triggers
Keyspace: system_schema; Table: types
Keyspace: system_schema; Table: views
Keyspace: examples; Table: videos
Keyspace: system_distributed; Table: parent_repair_history
Keyspace: system_distributed; Table: repair_history
Keyspace: system_distributed; Table: view_build_status
Keyspace: system; Table: IndexInfo
Keyspace: system; Table: available_ranges
Keyspace: system; Table: batches
Keyspace: system; Table: batchlog
Keyspace: system; Table: built_views
Keyspace: system; Table: compaction_history
Keyspace: system; Table: hints
Keyspace: system; Table: local
Keyspace: system; Table: paxos
Keyspace: system; Table: peer_events
Keyspace: system; Table: peers
Keyspace: system; Table: prepared_statements
Keyspace: system; Table: range_xfers
Keyspace: system; Table: size_estimates
Keyspace: system; Table: sstable_activity
Keyspace: system; Table: transferred_ranges
Keyspace: system; Table: views_builds_in_progress
Keyspace: system_traces; Table: events
Keyspace: system_traces; Table: sessions

Related Articles

spring
rest
api

GitHub - DataStax-Examples/spring-data-starter: ⚡️ A sample Spring Data Cassandra REST API

John Doe

2/14/2024

Checkout Planet Cassandra

Claim Your Free Planet Cassandra Contributor T-shirt!

Make your contribution and score a FREE Planet Cassandra Contributor T-Shirt! 
We value our incredible Cassandra community, and we want to express our gratitude by sending an exclusive Planet Cassandra Contributor T-Shirt you can wear with pride.

Join Our Newsletter!

Sign up below to receive email updates and see what's going on with our company

Explore Related Topics

AllKafkaSparkScyllaSStableKubernetesApiGithubGraphQl

Explore Further

examples