arrow_back

Migrating an application and data from Apache Cassandra™ to DataStax Enterprise

Sign in Join
Test and share your knowledge with our community!
done
Get access to over 700 hands-on labs, skill badges, and courses

Migrating an application and data from Apache Cassandra™ to DataStax Enterprise

Lab 1 hour universal_currency_alt 1 Credit show_chart Introductory
Test and share your knowledge with our community!
done
Get access to over 700 hands-on labs, skill badges, and courses

GSP707

Google Cloud self-paced labs logo

Overview

In this lab, you will learn how to migrate an application running on Apache Cassandra™ to DataStax Enterprise (DSE). To do this, you will deploy a Cassandra™ database and an application that writes data into it. You will then deploy a DataStax Enterprise database and connect the same application to the database. Finally, you will learn how to migrate data from Apache Cassandra™ to DSE using the DataStax Bulk Loader dsbulk.

Objectives

In this lab, you will learn how to perform the following tasks:

  • Deploy an Apache Cassandra™ database using Docker
  • Deploy a DataStax Enterprise database using Docker
  • Connect an application to both Cassandra™ and DSE
  • Migrate data from Apache Cassandra™ to DSE using dsbulk

Setup and requirements

Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.

This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito or private browser window to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.
  • Time to complete the lab---remember, once you start, you cannot pause a lab.
Note: If you already have your own personal Google Cloud account or project, do not use it for this lab to avoid extra charges to your account.

How to start your lab and sign in to the Google Cloud console

  1. Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:

    • The Open Google Cloud console button
    • Time remaining
    • The temporary credentials that you must use for this lab
    • Other information, if needed, to step through this lab
  2. Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).

    The lab spins up resources, and then opens another tab that shows the Sign in page.

    Tip: Arrange the tabs in separate windows, side-by-side.

    Note: If you see the Choose an account dialog, click Use Another Account.
  3. If necessary, copy the Username below and paste it into the Sign in dialog.

    {{{user_0.username | "Username"}}}

    You can also find the Username in the Lab Details panel.

  4. Click Next.

  5. Copy the Password below and paste it into the Welcome dialog.

    {{{user_0.password | "Password"}}}

    You can also find the Password in the Lab Details panel.

  6. Click Next.

    Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges.
  7. Click through the subsequent pages:

    • Accept the terms and conditions.
    • Do not add recovery options or two-factor authentication (because this is a temporary account).
    • Do not sign up for free trials.

After a few moments, the Google Cloud console opens in this tab.

Note: To view a menu with a list of Google Cloud products and services, click the Navigation menu at the top-left. Navigation menu icon

Activate Cloud Shell

Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.

  1. Click Activate Cloud Shell Activate Cloud Shell icon at the top of the Google Cloud console.

When you are connected, you are already authenticated, and the project is set to your Project_ID, . The output contains a line that declares the Project_ID for this session:

Your Cloud Platform project in this session is set to {{{project_0.project_id | "PROJECT_ID"}}}

gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.

  1. (Optional) You can list the active account name with this command:
gcloud auth list
  1. Click Authorize.

Output:

ACTIVE: * ACCOUNT: {{{user_0.username | "ACCOUNT"}}} To set the active account, run: $ gcloud config set account `ACCOUNT`
  1. (Optional) You can list the project ID with this command:
gcloud config list project

Output:

[core] project = {{{project_0.project_id | "PROJECT_ID"}}} Note: For full documentation of gcloud, in Google Cloud, refer to the gcloud CLI overview guide.

Task 1. Deploy Apache Cassandra™ using Docker

  1. In the Cloud Console, browse to Compute Engine > VM Instances.

  2. Click Create Instance.

  3. Name your deployment apache-cassandra.

  4. Under Machine Type, verify the e2-medium Machine type is selected.

  5. Scroll down to the Container section and click Deploy Container.

  6. In the Container Image field, enter the following:

bitnami/cassandra:latest
  1. Leave the rest of the fields as default and click Select.

  2. From Advanced Options expand the Networking section and add a Network tag cql-server.

Networking section displaying the cql-server tag in the Network tags field.

  1. Click Create.

Click Check my progress to verify the objective. Deploy Apache Cassandra™ using Docker

  1. When the instance is available, click on the instance to view the VM instance details.

  2. Click the SSH button to connect in a browser.

  3. Enter the following command to view the running containers:

sudo docker ps

You should see a container using an image called bitnami/cassandra:latest. If you don't, give it a few seconds and run the previous command again. Eventually you should see something similar to this output:

The output, which includes information such as the container ID, ports, and commands.

Note the name of the Docker container. It will be something similar to klt-apache-cassandra-ynvd.

  1. Then, connect to the database by typing the following command, replacing <<image-name>> with the name of your container:
sudo docker exec -it <<image-name>> cqlsh -u cassandra -p cassandra Note: it may take a couple of minutes for your container to be ready to connect to cqlsh. If you get an authentication error, try again in a few minutes.
  1. Once you are logged in to the database, create a keyspace for the application to connect to:
CREATE KEYSPACE simpleapp WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
  1. Create a table for the application to use when reading and writing data:
CREATE TABLE simpleapp.data(store TEXT, item TEXT, quantity INT, order_time BIGINT, PRIMARY KEY ((store), order_time));
  1. Keep the CQL shell active but return to the Console in another browser window.

Click Check my progress to verify the objective. Create a keyspace and table for application in Docker container

Task 2. Create a firewall rule

Before you connect an application to the database, you'll need to create a firewall rule that allows CQL connections to the server. CQL connections are made over TCP on port 9042.

  1. In the Cloud Console, navigate to VPC Network > Firewall.

  2. Click Create Firewall Rule.

  3. For the name, use allow-cql.

  4. In the Target tags field enter cql-server.

  5. For Source IP ranges enter 0.0.0.0/0.

  6. Under Protocols and ports check the box next to tcp and enter 9042 in the field.

  7. Click Create.

Click Check my progress to verify the objective. Create a firewall rule

Task 3. Run an application to load data into Apache Cassandra™

  1. In Cloud Shell, download a simple java application with the following command:
curl -o sample-jar-with-dependencies.jar https://storage.googleapis.com/cloud-training/quests/datastax/sample-jar-with-dependencies.jar

The application loads 100 records into the table you created earlier.

  1. To run it, you will need to know the external IP address of the instance hosting the Cassandra™ database.

  2. In the Console, navigate to the Compute Engine > VM Instances page.

Note the external IP address of the apache-cassandra VM.

external IP address highlighted on the VM instances page

  1. Now, run the following command, replacing <<external-ip>> with the External IP address of your apache-cassandra VM:
java -jar sample-jar-with-dependencies.jar -u cassandra -p cassandra -h <<external-ip>> -d datacenter1
  1. Confirm that the application ran successfully by returning the CQL Shell and selecting all of the records from the table:
select count(*) from simpleapp.data;

The query should return 100.

  1. Run the app again. The same query should now return 200.

Click Check my progress to verify the objective. Run an application to load data into Apache Cassandra

Task 4. Install DataStax Enterprise using Docker

  1. In the Cloud Console, browse to Compute Engine > VM Instances.

  2. Click Create Instance.

  3. For the name, use dse-server.

  4. Under Machine Type, verify the e2-medium Machine type is selected.

  5. Scroll down to the Container section and click Deploy Container.

  6. In the Container image field, enter the following:

registry.hub.docker.com/datastax/dse-server:6.8.18
  1. Under Environment Variables click Add Variable.

  2. For the Name / Value Pair, enter the following:

Name Value
DS_LICENSE accept

The Docker image will deploy without authentication enabled. After deployment, you will create a modified config file that will override the default configurations to enable authentication. To do this, you will use a Configuration Volume. You can learn more about this from the Using the DSE configuration volume documentation. For now, all you need to know is that you need to mount a directory in the container.

  1. Under Volume mounts, click Add a volume mount. The New volume mount section should expand.

  2. For Volume Type, select Directory.

  3. For Mount path, use: /config.

  4. For Host path, use: /tmp/dse-config.

  5. Set Mode to Read/write.

  6. Click Done, then click Select.

  7. From Advanced Options expand Networking and add the Network Tag cql-server.

  8. Click Create.

Click Check my progress to verify the objective. Create an instance named dse-server

Task 5. Enable authentication on DataStax Enterprise

  1. When the VM Instance is available, click the dse-server instance.

  2. Click the SSH button to connect in a browser.

  3. Enter the following command to confirm that the DSE container loaded:

sudo docker ps

You should see a container using an image called registry.hub.docker.com/datastax/dse-server:6.8.18. Note the name of this container. It should be similar to klt-dse-server-llpl.

You will now need to enable authentication. To do this, you will copy a config file dse.yaml from inside the container to the host VM's local filesystem.

  1. Run the following command, replacing <<container-name>> with the name of your DSE container:
sudo docker cp <<container-name>>:/opt/dse/resources/dse/conf/dse.yaml /tmp/dse-config/
  1. Open the file in the Vim editor:
sudo vim /tmp/dse-config/dse.yaml
  1. Type i to go into insert mode.

  2. Browse to the following lines in the file:

# authentication_options: # enabled: false # default_scheme: internal # other_schemes: # scheme_permissions: false # allow_digest_with_kerberos: true # plain_text_without_ssl: warn # transitional_mode: disabled
  1. Uncomment all of the lines, and make sure there are no spaces at the start of the first line authentication_options:.

  2. Edit the second line so that it reads enabled: true.

The block of text should now look like this:

authentication_options: enabled: true default_scheme: internal other_schemes: scheme_permissions: false allow_digest_with_kerberos: true plain_text_without_ssl: warn transitional_mode: disabled
  1. Use Ctrl+c to save the file, type :wq, and hit ENTER to save and exit the editor.

  2. Now, restart the container, replacing <<container-name>> with the name of your DSE container:

sudo docker restart <<container-name>>

Click Check my progress to verify the objective. Enable Authentication on DataStax Enterprise

Task 6. Connect to DataStax Enterprise

  1. Once it has restarted, open a shell in the container, replacing <<container-name>> with the name of your DSE container:
sudo docker exec -it <<container-name>> bash
  1. Run CQLSH:
cqlsh

You should see the following error because authentication is enabled: Connection error: ('Unable to connect to any servers', {'127.0.0.1:9042': error(111, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")}).

  1. Run CQLSH again, this time passing the default username and password:
cqlsh -u cassandra -p cassandra
  1. Once you are logged in to the database, create a keyspace for the application to connect to:
CREATE KEYSPACE simpleapp WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
  1. Create a table for the application to use when reading and writing data:
CREATE TABLE simpleapp.data(store TEXT, item TEXT, quantity INT, order_time BIGINT, PRIMARY KEY ((store), order_time));

Keep the CQL Shell open and return to the Cloud Console.

Click Check my progress to verify the objective. Create a keyspace and table for application on dse-server instance

Task 7. Run the application to load data into DataStax Enterprise

  1. In the Console, navigate to the Compute Engine > VM Instances page. Note the external IP address of the dse-server VM.

  2. Open Cloud Shell and run the application again, replacing <<dse-external-ip>> with the external IP address of the VM hosting the DSE Docker image. Note, we are using a different datacenter name dc1:

java -jar sample-jar-with-dependencies.jar -u cassandra -p cassandra -h <<dse-external-ip>> -d dc1
  1. Confirm the application ran by returning to the CQL Shell and running the following query:
select count(*) from simpleapp.data;

You should see 100 records returned.

Note that you didn't actually have to modify the code! If you are interested, you can download the application code.

Click Check my progress to verify the objective. Run an application to load data into dse-server

Task 8. Migrate the data from Open Source Cassandra™ to DSE

  1. In the SSH window of your DSE VM instance, type exit to quit the CQL shell.

  2. In the same instance, download and unzip the DataStax bulkloader:

wget https://downloads.datastax.com/dsbulk/dsbulk.tar.gz tar xvzf dsbulk.tar.gz
  1. List the contents of your home directory:
cd ~ ls
  1. Browse to the latest dsbulk binary version folder (the name should resemble dsbulk-x.x.x), then cd into the bin directory:
cd dsbulk-x.x.x # replace with your version of dsbulk! cd bin
  1. Now, get its location so you can add it to your path:
pwd
  1. Copy the output and add it to the path, replacing <<your_path>> with the output from the previous command:
export PATH=<<your_path>>:$PATH
  1. Confirm that dsbulk was successfully added by checking for the version number, then return to the home directory:
dsbulk --version cd ~
  1. Export the records from the table in Apache Cassandra™, replacing <<external-ip>> with the external IP address of the apache-cassandra VM:
dsbulk unload -u cassandra -p cassandra -h <<external-ip>> -k simpleapp -t data -url export

The records will be exported to a csv file in ~/export.

  1. To view the exported records run:
cat ~/export/output-000001.csv
  1. To import the data into DSE, run the following command, replacing <<external-ip>> with the external IP address of the dse-server VM:
dsbulk load -u cassandra -p cassandra -h <<external-ip>> -k simpleapp -t data -url ~/export/output-000001.csv
  1. Reconnect to the CQL Shell on the DSE VM and rerun the count query:
cqlsh -u cassandra -p cassandra select count(*) from simpleapp.data;

You should now see that the number of records has increased following the import.

Click Check my progress to verify the objective. Migrate the data from Apache Cassandra™ to DSE

Congratulations!

In this lab, you migrated an application running on Apache Cassandra™ to DataStax Enterprise. You first deployed a Cassandra™ database and a DataStax Enterprise database using Docker. Next, you connected an application to both Cassandra™ and DSE using CQL Shell and ran some simple DDL commands to create a table, load some data, and query it. You then migrated the data from the Apache Cassandra™ database to the DSE database using the DataStax Bulk Loader dsbulk.

Next steps / learn more

  • DataStax on the Google Cloud Marketplace!
  • Take advantage of the largest library of technical courses at DataStax Academy

Google Cloud training and certification

...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.

Manual Last Updated October 11, 2023

Lab Last Tested October 11, 2023

Copyright 2024 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.