CCM 2.0 and Windows

By Kishan Karunaratne -  January 26, 2015 | 4 Comments

 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:

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.









DataStax has many ways for you to advance in your career and knowledge.

You can take free classes, get certified, or read one of our many white papers.



register for classes

get certified

DBA's Guide to NoSQL







Comments

  1. Dinesh says:

    Hello,

    I installed ccm perfectly on windows 10 using below pacakges

    python-3.4.4.amd64.msi, PyYAML-3.11.win-amd64-py3.4.exe, six-1.10.0-py2.py3-none-any.whl, psutil-4.1.0.win-amd64-py3.4.exe, jdk-8u73-windows-x64.exe, apache-ant-1.9.6-bin
    ccm-master zip file from GitHub.

    I tried to create a cluster named cluster1, getting below error.

    $ ccm create cluster1 -v 2.1.5
    Current cluster is now: cluster1
    $ ccm populate -n 3
    $ ccm status
    Cluster: ‘cluster1’
    ——————-
    node2: DOWN (Not initialized)
    node1: DOWN (Not initialized)
    node3: DOWN (Not initialized)

    $ ccm start
    Traceback (most recent call last):
    File “E:\Studies\Cassandra\ccm\ccm-master\ccm.py”, line 74, in
    cmd.run()
    File “E:\Studies\Cassandra\ccm\ccm-master\ccmlib\cmds\cluster_cmds.py”, line 583, in run
    allow_root=self.options.allow_root) is None:
    File “E:\Studies\Cassandra\ccm\ccm-master\ccmlib\cluster.py”, line 335, in start
    p = node.start(update_pid=False, jvm_args=jvm_args, profile_options=profile_options, verbose=verbose, quiet_start=quiet_start, allow_root=allow_root)
    File “E:\Studies\Cassandra\ccm\ccm-master\ccmlib\node.py”, line 499, in start
    if common.is_win() and not common.is_ps_unrestricted() and self.cluster.version() >= ‘2.1’:
    File “E:\Studies\Cassandra\ccm\ccm-master\ccmlib\common.py”, line 270, in is_ps_unrestricted
    if “Unrestricted” in p.communicate()[0]:
    TypeError: ‘str’ does not support the buffer interface

    I have a question. Do I need to create alias loopback IPs(127.0.0.2, 127.0.0.3, 127.0.0.3, etc..) as same like Mac OS in Windows as well?

    Even I tried for C* version 3.0.3, getting the same error.

    Please help me to fix this.

    1. Kishan Karunaratne says:

      Looks like you were able to file the issue on GitHub. Thanks for reporting it! As for your other question, no, you do not need to set up loopback aliases for Windows.

      1. Dinesh says:

        Yes Kishan. I got the solution from GitHub. I reinstalled Python 3.4 to Python 2.7 and related dependent packages(pyyaml, psutil, pip). Now I am able to create clusters without any issues.

        Yes, I got clarification on loopback aliases as well. No need to create any loopback aliases on Windows and Linux.

        Thanks.

  2. Rajaryan says:

    Can any one help. Getting error while starting ccm.

    Traceback (most recent call last):
    File “C:\CCM\ccm.py”, line 74, in
    cmd.run()
    File “C:\CCM\ccmlib\cmds\cluster_cmds.py”, line 576, in run
    allow_root=self.options.allow_root) is None:
    File “C:\CCM\ccmlib\cluster.py”, line 286, in start
    p = node.start(update_pid=False, jvm_args=jvm_args, profile_options=profile_
    options, verbose=verbose, quiet_start=quiet_start, allow_root=allow_root)
    File “C:\CCM\ccmlib\node.py”, line 499, in start
    common.check_socket_available(itf)
    File “C:\CCM\ccmlib\common.py”, line 413, in check_socket_available
    raise UnavailableSocketError(“Inet address %s:%s is not available: %s” % (ad
    dr, port, msg))
    ccmlib.common.UnavailableSocketError: Inet address 127.0.0.1:9042 is not availab
    le: [Errno 10013] An attempt was made to access a socket in a way forbidden by i
    ts access permissions

Comments

Your email address will not be published. Required fields are marked *




Subscribe for newsletter:

Tel. +1 (650) 389-6000 sales@datastax.com Offices France GermanyJapan

DataStax Enterprise is powered by the best distribution of Apache Cassandra™.

© 2017 DataStax, All Rights Reserved. DataStax, Titan, and TitanDB are registered trademark of DataStax, Inc. and its subsidiaries in the United States and/or other countries.
Apache Cassandra, Apache, Tomcat, Lucene, Solr, Hadoop, Spark, TinkerPop, and Cassandra are trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries.