Learn

Learn about latest technology

Build

Unleash your talent and coding!

Share

Let more people use it to improve!
 

Relationship between docker-cqlsh-cassandra

martes, 17 de julio de 2018


We have the most simplest architecture, two docker images/containers.  One of them with a Cassandra db and the other one contain an application(in my case Scala-Akka apps) could be any apps in any language but with ONE important exception our apps are using in his processes the CQLsh tool and specifically CQLsh tool - COPY FROM/TO.
zzz
In the above structure when the problems arise? The Application hosted in Container - II have some scripts and functions that make use of CQLsh tool for IMPORT FROM CVS file to Cassandra db(Container - I).

The main aspects in our lab:

Cassandra versions tested for us(From Official Repository)(Container - I):
  • 3.11.1
  • 3.7
  • 3.1.1
  • 3.2
CQL version: 3.4.+(Container - I)(Container - II)

When CQL version is not compatible you can add the following parameter( it is not recommended ):
  • cqlversion=Change cqlversion and use the  Database's cqlversion you want connect to
containerId=Container Id where is hosted Cassandra Database

We need to know from where is listening Cassandra (listen_address)  ref. Cassandra configuration file:
  • container_ip_address_where_is_cassandra=sudo docker inspect containerId -f '{{.NetworkSettings.IPAddress}}'
You ought define container_ip_address_where_is_cassandra, Cassandra listen_address  property as a OS Environment variable.

cqlsh --cqlversion=cql_version_compatible  listen_address

You can use the default port(9042) or any other if you change the configuration in cassandra.yaml

And the proper Docker File for CQLsh installation in our Container - II ought be:

1
2
3
4
5
6
7
8
..........
# Installing python
RUN apt-get update; \
  apt-get install -y python curl
# Installing cqlsh
RUN bash -c "python <(curl https://bootstrap.pypa.io/get-pip.py)"; \
  pip install cqlsh
...........
code. 1

The above(code. 1) is an snapshot of the Docker file part that make the cqlsh installation.

What can be done with this installation:
- create keyspaces
- create tables
- select
 
But the above installation does not encompass TWO important commands:

- COPY TO
- COPY FROM

When database is in different servers you use to get this mistake:

<stdin>:2:'module' object has no attribute 'parse_options' failing with the parse_options

I have analyze both source code(CQLsh from Cassandra and CQLsh from Python pip installation[pip in code. 1] ) and are different as well as the way that each code tackle the parse_options. You can have a look in CqlSh pip installation source code and the Cassandra cqlsh tool in your Cassandra container in  /usr/bin/cqlsh.py.

That is why if we need to make a COPY FROM/TO with CQLsh tool above solution (code. 1) It is NOT allowed.

There are several solutions for the above problem one of them is to install the CQLsh that come with Cassandra Official Image. It will be necessary only if I need to use CQLsh - COPY FROM/TO in any other case cqlsh via pip installation (code. 1) in image/CONTAINER II is good enough.

So My CQLsh Tool installation is from Cassandra Installation(ref. Cassandra versions tested):

Where the libraries in the Cassandra installation ver 3.7 - 3.11 can be found:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# cassandra download and run cassandra image 
docker run --name cassandra_image_37 -d cassandra:3.7

# copy python libraries from cassandra container
sudo docker cp cassandra_image_37:/usr/lib/python2.7 .

# cassandra libraries from cassandra container
sudo docker cp cassandra_image_37:/usr/share/cassandra .

# cqlsh python src and phyton shell script
sudo docker cp cassandra_image_37:/usr/bin/cqlsh .
sudo docker cp cassandra_image_37:/usr/bin/cqlsh.py .

# python bash from cassandra container
sudo docker cp cassandra_image_37:/usr/bin/python2.7 .

# open ssl libraries from cassandra container
sudo docker cp cassandra_image_37:/usr/lib/x86_64-linux-gnu/libssl.so.1.0.0 .

# cripto libraries from cassandra container
sudo docker cpcassandra_image_37:/usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0 .

Project for create the image with java base + scala and CQLsh tools for execute COPY FROM or COPY TO can be found in my github project.

These architecture is valid only for images that are living in the same Docker. In the same way we run containers  in the same Docker which is very easy to inspect. You can include Docker Machine and config the docker-compose.yml properly if you want to work with more replicas. Another different thing is when we are talking about orchestration (swarm, kubernetes, etc) and the communication between different machines/pods.




0 comentarios:

Publicar un comentario