From 757189e85a3d5653e21c50de3ba54ca5fe3f6afd Mon Sep 17 00:00:00 2001 From: Rodrigo Goncalves <rodrigo.g@ufsc.br> Date: Mon, 9 Sep 2024 17:35:50 +0000 Subject: [PATCH] Container to configure cassandra --- docker/cassandra-setup/Dockerfile | 5 +++ docker/cassandra-setup/entry.sql | 51 +++++++++++++++++++++++++++++ docker/cassandra-setup/keyspace.sql | 5 +++ docker/cassandra-setup/startup.sh | 13 ++++++++ 4 files changed, 74 insertions(+) create mode 100644 docker/cassandra-setup/Dockerfile create mode 100644 docker/cassandra-setup/entry.sql create mode 100644 docker/cassandra-setup/keyspace.sql create mode 100755 docker/cassandra-setup/startup.sh diff --git a/docker/cassandra-setup/Dockerfile b/docker/cassandra-setup/Dockerfile new file mode 100644 index 0000000..719ae38 --- /dev/null +++ b/docker/cassandra-setup/Dockerfile @@ -0,0 +1,5 @@ +FROM debian:12.5-slim +RUN apt update -y +RUN apt install -y python3 python3-pip python3-venv +RUN mkdir /startup +CMD ["/scripts/startup.sh"] \ No newline at end of file diff --git a/docker/cassandra-setup/entry.sql b/docker/cassandra-setup/entry.sql new file mode 100644 index 0000000..cfbb583 --- /dev/null +++ b/docker/cassandra-setup/entry.sql @@ -0,0 +1,51 @@ +CREATE TYPE smartdata_v1.v1_1_digital ( + value blob, + error tinyint, + confidence tinyint, + gw bigint +); + +CREATE TYPE smartdata_v1.v1_1_si ( + value double, + error tinyint, + confidence tinyint, + gw bigint +); + +CREATE TYPE smartdata_v1.v1_1_si_blob ( + period int, + gateway bigint, + uncertainty int, + data blob +); + + +CREATE TYPE smartdata_v1.v1_2_digital ( + value blob, + error tinyint, + confidence tinyint, + x int, + y int, + z int, + gw bigint +); + +CREATE TYPE smartdata_v1.v1_2_si ( + value double, + error tinyint, + confidence tinyint, + x int, + y int, + z int, + gw bigint +); + +CREATE TYPE smartdata_v1.v1_2_si_blob ( + x int, + y int, + z int, + period int, + gateway bigint, + uncertainty int, + data blob +); \ No newline at end of file diff --git a/docker/cassandra-setup/keyspace.sql b/docker/cassandra-setup/keyspace.sql new file mode 100644 index 0000000..483e36e --- /dev/null +++ b/docker/cassandra-setup/keyspace.sql @@ -0,0 +1,5 @@ +DROP KEYSPACE IF EXISTS smartdata_v1; + +CREATE KEYSPACE smartdata_v1 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'} AND durable_writes = true; + +USE smartdata_v1; \ No newline at end of file diff --git a/docker/cassandra-setup/startup.sh b/docker/cassandra-setup/startup.sh new file mode 100755 index 0000000..777cafb --- /dev/null +++ b/docker/cassandra-setup/startup.sh @@ -0,0 +1,13 @@ +#!/bin/bash +cd /startup +python3 -m venv venv +source ./venv/bin/activate +pip3 install cqlsh + +while ! cqlsh -e 'describe cluster' cassandra ; do + echo Waiting for cassandra to startup... + sleep 1 +done + +cqlsh -f /scripts/keyspace.sql cassandra +cqlsh -f /scripts/entry.sql cassandra \ No newline at end of file -- GitLab