TechnologyJanuary 26, 2015

CCM 2.0 and Windows

CCM 2.0 and Windows

 Introduction

Cassandra Cluster Manager, or CCM for short, is a powerful tool that lets you spin up any number of Apache Cassandra instances, create a cluster, and perform many cluster operations on localhost. It has been around for while but it wasn’t until the recent 2.0 release that Windows support was added, allowing the ability to natively run Cassandra instances on Windows. This post will go over the steps for getting CCM set up and running on Windows as well as some helpful tips on running Cassandra in the Windows environment via the command prompt.

Install CCM

CCM is a Python-based tool and it is now available via PyPi. CCM can be installed through pip:

Linux and Windows:
pip install ccm

On Windows, pip will install ccm into the C:\Python27\Scripts directory. Navigate to this directory and rename "ccm" to "ccm.py". This will allow you to run CCM via “ccm” rather than “python ccm”.

On Windows only (critical):

You must set the execution policy of Windows Powershell to allow CCM to launch instances of Cassandra. Open up a Powershell and type: “Set-ExecutionPolicy Unrestricted” and press Y in the resulting prompt. An unrestricted execution policy will also allow CCM to run on the regular command prompt (cmd) as well as Windows Powershell:

Set-ExecutionPolicy Unrestricted

Install Dependencies

Running CCM on a Windows-based system is similar to running it on a Linux-based system (in this post, I will assume Ubuntu-based), and requires a few dependencies if not already installed. Although the dependencies between the two platforms are largely the same, installing the dependencies on Windows is slightly more complicated and must be configured properly for CCM to run.

Java Dependencies

First and foremost, a Java Development Kit (JDK) must be installed in order for CCM to build and run the requested instance(s) of Cassandra. The version of the JDK to install depends on the version of Cassandra you want to use and should match the architecture of operating system you are using (32-bit or 64-bit). JDK7 should be used for any recent recent Cassandra release.

On Linux:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
On Windows:

After JDK installation, create a new system variable called JAVA_HOME and point it to the root of your JDK installation directory. In addition, add %JAVA_HOME%\bin to your system Path variable:

JAVA_HOME -> C:\Program Files\Java\<jdk_root>\
PATH: %JAVA_HOME%\bin;

As an aside, if you want to use the SSL functionality available in Cassandra, you will also need to install the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files

On Linux:
sudo apt-get install oracle-java7-unlimited-jce-policy
On Windows:

Download the jar files from the above link, and place them into C:\Program Files\Java\<jdk_root>\jre\lib\security\

Next, install Apache Ant:

On Linux:
sudo apt-get install ant
On Windows:

Ant should be unzipped and moved to a permanent directory such as C:\apache-ant-1.9.4. Create a new system variable ANT_HOME and point it to this directory, and add %ANT_HOME%\bin to your Path variable:

ANT_HOME -> C:\<ant_root>\
PATH: %ANT_HOME%\bin;

Python Dependencies

Python 2.7 should be installed and should once again match the architecture of your operating system:

On Linux:
sudo apt-get install python
On Windows:

After Python installation, create a new system variable %PYTHON_HOME% and point it to the root directory of the Python installation. Add %PYTHON_HOME% and %PYTHON_HOME%\Scripts to your Path variable. In addition, add .PY to your PATHEXT to allow the direct execution of Python files:

PYTHON_HOME -> C:\<python_root>\
PATH: %PYTHON_HOME%; %PYTHON_HOME%\Scripts;
PATHEXT: .PY;
On Windows only:

Finally, download and install the Python 2.7 version of psutil manually via the MS Windows Installer that matches the architecture of Windows. This is the only Windows-only dependency and must be installed via the .exe to work correctly.

Creating a Cluster

To create a CCM Cassandra cluster, you need to specify the cluster name, Cassandra version and the number of nodes in the cluster. For example:

ccm create test -v 2.1.2
ccm populate -n 3
ccm start

Let’s have a look at each of these steps individually.

The “create” command downloads a source tarball of the specified Cassandra version and uses ant to compile it. On Windows, this is placed into C:\Users\<user>\.ccm\repository\ directory and in this case, it will download and compile Cassandra 2.1.2 into \.ccm\repository\2.1.2\. CCM will download and compile the source tarball the first time a specific version of Cassandra is used and thus will take some time. Thereafter, a previously compiled version will be used and should be quick.

The “populate” command creates X number of directories under \.ccm\<cluster_name>\, where each X is a node number such as \.ccm\<cluster_name>\node1. Inside of each of these node directories is a simple compiled copy of Cassandra from \.ccm\repository\2.1.2\, as well as a node.conf which holds the configuration information for that specific node such as interfaces, ports and initial token values.

The “start” command launches into the background an independent java process running Cassandra per each node, listening on 127.0.0.X, where X is the node number. If a Cassandra version prior to 2.1 is being launched, a number of new windows will pop up running Cassandra, rather than running in the background.

Similarly, “stop” can be used to stop all running Cassandra processes and “remove” will destroy the cluster and all configurations for the current cluster.

Command Line Interface

Mutliple CCM clusters can be configured concurrently. For example “ccm create test2 -v 2.1.2” will create a new CCM cluster called “test2” and switch to it. However, to start new this cluster, any previous clusters must be stopped first. “ccm list” can show a list of all configured CCM clusters (with the active cluster denoted via an asterisk *), and “ccm switch” can be used to switch between any CCM cluster.

Once a cluster is up and running, it can be accessed via cqlsh, nodetool or any DataStax driver. For example, “ccm node1 cqlsh” will launch and connect to cqlsh on node1. Similarly, “ccm node1 nodetool status” will launch and run many nodetool command on node1 of the cluster.

CCM Example

The following example demonstrates the use of CCM programmatically in a simple test case using the DataStax Ruby Driver:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

require 'cassandra'

 

cluster_status = `ccm status`

`ccm create test_cluster -v 2.1.2 -n 1 -s` unless cluster_status.include?("test_cluster")

raise "Node not UP" unless cluster_status.include?("UP")

 

cassandra_version = `ccm node1 version`

raise "Wrong Cassandra version" unless cassandra_version.include?("2.1.2")

 

cluster = Cassandra.cluster

session = cluster.connect()

 

session.execute("CREATE KEYSPACE IF NOT EXISTS simplex WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};")

session.execute("USE simplex")

 

session.execute("CREATE TABLE IF NOT EXISTS test (k text, v int, PRIMARY KEY (k, v));")

session.execute("INSERT INTO test (k, v) VALUES ('a', 1)")

result = session.execute("SELECT * FROM test").first

raise "Unsuccessful insert" unless result == {"k"=>"a", "v"=>1}

 

cluster.close

 

`ccm stop && ccm start`

sleep(2)

cluster_status = `ccm node1 status`

raise "Node not ready" unless cluster_status.include?("UN")

 

`ccm remove`

Conclusion

CCM provides full functionality of a real Apache Cassandra cluster for development purposes, and now it is also supported on Windows. It should not be used in any production or benchmarking environments. Although Cassandra 1.2.X and 2.0.X are not officially supported on Windows, they do work on CCM. Cassandra 2.1.X currently has beta support and full Windows support is planned in Cassandra 3.0. We hope you give CCM a test drive on Windows and as always, pull requests are appreciated on GitHub.

Discover more
Apache Cassandra®
Share

One-stop Data API for Production GenAI

Astra DB gives JavaScript developers a complete data API and out-of-the-box integrations that make it easier to build production RAG apps with high relevancy and low latency.