Skip to content

Commit

Permalink
Docker: allow automatic cluster registration
Browse files Browse the repository at this point in the history
A minimal example of how to use this change in docker-compose:
```
  register-cluster:
    image: cassandra-reaper:latest
    networks:
      - tlp_dashboards_net
    command: ["register-clusters", "cassandra:7199", "reaper", "8080"]
    depends_on:
      - cassandra
      - cassandra2
      - reaper
      - stress
```
  • Loading branch information
Radovan Zvoncek authored and rzvoncek committed Apr 23, 2020
1 parent 33d903c commit 505eb3a
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/docs/content/docs/configuration/docker_vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ The Docker environment variables listed in this section map directly to Reaper s
<code class="codeLarge">REAPER_INCREMENTAL_REPAIR</code> | [incrementalRepair]({{< relref "reaper_specific.md#incrementalrepair" >}}) | false
<code class="codeLarge">REAPER_JMX_AUTH_PASSWORD</code> | [password]({{< relref "reaper_specific.md#password" >}}) |
<code class="codeLarge">REAPER_JMX_AUTH_USERNAME</code> | [username]({{< relref "reaper_specific.md#username" >}}) |
<code class="codeLarge">REAPER_JMX_CREDENTIALS</code> | [jmxCredentials]({{< relref "reaper_specific.md#jmxcredentials" >}}) |
<code class="codeLarge">REAPER_JMX_CONNECTION_TIMEOUT_IN_SECONDS</code> | [jmxConnectionTimeoutInSeconds]({{< relref "reaper_specific.md#jmxconnectiontimeoutinseconds" >}}) | 20
<code class="codeLarge">REAPER_JMX_PORTS</code> | [jmxPorts]({{< relref "reaper_specific.md#jmxports" >}}) | {}
<code class="codeLarge">REAPER_LOGGING_APPENDERS_CONSOLE_LOG_FORMAT</code> | [logFormat]({{< relref "reaper_specific.md#logformat" >}}) | "%-6level [%d] [%t] %logger{5} - %msg %n"
Expand Down
25 changes: 25 additions & 0 deletions src/docs/content/docs/download/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,31 @@ The Docker Compose services available allow for orchestration of an environment

In addition to the environment using Reaper's default settings, Docker Compose services are provided that allow orchestration of an environment in which the connections between Reaper and Cassandra are SSL encrypted. The services which create this environment contain a `-ssl` suffix in their name.

It is also possible to automate registering the Cassandra cluster with Reaper and making Reaper start repairing non-system keyspaces automatically. To register a cluster, run the Reaper image with the `register-cluster` command:

```yaml
register-clusters:
image: cassandra-reaper:latest
links:
- cassandra
- reaper-in-memory
command: ["register-clusters", "cassandra:7199", "reaper-in-memory", "8080"]
```
The `register-clusters` arguments are:

- `cassandra:7199` - host and (JMX) port of a node in the cluster we want to register.
- `reaper-in-memory` - hostname of the Reaper instance.
- `8080` - the port on which Reaper listens on.

To make Reaper automatically start repairs, make sure the following environment variables are set:

```bash
REAPER_AUTO_SCHEDULING_ENABLED="True"
REAPER_AUTO_SCHEDULING_TIME_BEFORE_FIRST_SCHEDULE="PT1M"
REAPER_AUTO_SCHEDULING_PERIOD_BETWEEN_POLLS="PT1M"
```

All available Docker Compose services can be found in the [docker-compose.yml](https://github.com/thelastpickle/cassandra-reaper/blob/master/src/packaging/docker-compose.yml) file.


Expand Down
7 changes: 7 additions & 0 deletions src/packaging/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,10 @@ services:
- ./docker-services/reaper-in-memory/reaper-in-memory.env
links:
- cassandra

register-clusters:
image: cassandra-reaper:latest
links:
- cassandra
- reaper-in-memory
command: ["register-clusters", "cassandra:7199", "reaper-in-memory", "8080"]
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@
# limitations under the License.

REAPER_STORAGE_TYPE=memory

REAPER_AUTO_SCHEDULING_ENABLED="True"
REAPER_AUTO_SCHEDULING_INITIAL_DELAY_PERIOD="PT15S"
REAPER_AUTO_SCHEDULING_TIME_BEFORE_FIRST_SCHEDULE="PT1M"
REAPER_AUTO_SCHEDULING_PERIOD_BETWEEN_POLLS="PT1M"
7 changes: 4 additions & 3 deletions src/server/src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ENV REAPER_SEGMENT_COUNT=200 \
REAPER_AUTO_SCHEDULING_PERIOD_BETWEEN_POLLS=PT10M \
REAPER_AUTO_SCHEDULING_TIME_BEFORE_FIRST_SCHEDULE=PT5M \
REAPER_AUTO_SCHEDULING_SCHEDULE_SPREAD_PERIOD=PT6H \
REAPER_AUTO_SCHEDULING_EXCLUDED_CLUSTERS="[]" \
REAPER_AUTO_SCHEDULING_EXCLUDED_KEYSPACES="[]" \
REAPER_JMX_PORTS="{}" \
REAPER_JMX_AUTH_USERNAME="" \
Expand Down Expand Up @@ -76,9 +77,9 @@ ENV REAPER_SEGMENT_COUNT=200 \

# used to run spreaper cli
RUN apk add --update \
python \
py-pip \
&& pip install requests \
python3 \
py3-pip \
&& pip3 install requests \
&& rm -rf /var/cache/apk/*


Expand Down
56 changes: 55 additions & 1 deletion src/server/src/main/docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.

function wait_for {
HOST=$1
PORT=$2

echo "Checking if ${HOST}:${PORT} is up ..."
nc -zv ${HOST} ${PORT} > /dev/null 2>&1
port_open=$?
while [ "${port_open}" != 0 ]
do
echo "${HOST} is not yet up, will retry in 20s"
sleep 20
nc -zv ${HOST} ${PORT} > /dev/null 2>&1
port_open=$?
done
echo "${HOST}:${PORT} is up!"
}

if [ "$1" = 'cassandra-reaper' ]; then
set -x

# get around `/usr/local/bin/configure-persistence.sh: line 65: can't create /etc/cassandra-reaper.yml: Interrupted system call` unknown error
touch /etc/cassandra-reaper.yml
Expand All @@ -30,4 +46,42 @@ if [ "$1" = 'cassandra-reaper' ]; then
/etc/cassandra-reaper.yml
fi

if [ "$1" = 'register-clusters' ]; then

if [ -z "$2" ]; then
echo "The register-clusters command needs its 1st argument to be a 'host:port,...' string pointing to C* nodes to repair"
exit 1
fi
REAPER_AUTO_SCHEDULING_SEEDS=$2

if [ -z "$3" ]; then
echo "The register-clusters command needs additional argument indicating the Reaper host"
exit 1
fi
REAPER_HOST=$3

if [ -z "$4" ]; then
echo "The register-clusters command takes additional argument indicating the Reaper port. Defaulting to 8080"
REAPER_PORT=8080
else
REAPER_PORT=$4
fi

mkdir -p ~/.reaper
echo "admin" > ~/.reaper/credentials

wait_for ${REAPER_HOST} ${REAPER_PORT}

for SEED in $(echo "${REAPER_AUTO_SCHEDULING_SEEDS}" | sed "s/,/ /g"); do
SEED_HOST=$(echo ${SEED} | cut -d':' -f1)
SEED_PORT=$(echo ${SEED} | cut -d':' -f2)
wait_for ${SEED_HOST} ${SEED_PORT}
/usr/local/bin/spreaper login --reaper-host "${REAPER_HOST}" --reaper-port "${REAPER_PORT}" admin
/usr/local/bin/spreaper add-cluster --reaper-host "${REAPER_HOST}" --reaper-port "${REAPER_PORT}" "${SEED_HOST}" "${SEED_PORT}"
done

exit 0

fi

exec "$@"

0 comments on commit 505eb3a

Please sign in to comment.