|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# This script contains all the code snippets from the guide, as well as some assert tests |
| 5 | +# to test if the instructions in the guide work. The user *could* use it, but it is intended |
| 6 | +# for testing only. |
| 7 | +# The script will install the operators, create a superset instance and briefly open a port |
| 8 | +# forward and connect to the superset instance to make sure it is up and running. |
| 9 | +# No running processes are left behind (i.e. the port-forwarding is closed at the end) |
| 10 | + |
| 11 | +if [ $# -eq 0 ] |
| 12 | +then |
| 13 | + echo "Installation method argument ('helm' or 'stackablectl') required." |
| 14 | + exit 1 |
| 15 | +fi |
| 16 | + |
| 17 | +case "$1" in |
| 18 | +"helm") |
| 19 | +echo "Adding 'stackable-dev' Helm Chart repository" |
| 20 | +# tag::helm-add-repo[] |
| 21 | +helm repo add stackable-dev https://repo.stackable.tech/repository/helm-dev/ |
| 22 | +# end::helm-add-repo[] |
| 23 | +echo "Installing Operators with Helm" |
| 24 | +# tag::helm-install-operators[] |
| 25 | +helm install --wait zookeeper-operator stackable-dev/zookeeper-operator --version {{ versions.zookeeper }} |
| 26 | +helm install --wait hdfs-operator stackable-dev/hdfs-operator --version {{ versions.hdfs }} |
| 27 | +helm install --wait commons-operator stackable-dev/commons-operator --version {{ versions.commons }} |
| 28 | +helm install --wait secret-operator stackable-dev/secret-operator --version {{ versions.secret }} |
| 29 | +# end::helm-install-operators[] |
| 30 | +;; |
| 31 | +"stackablectl") |
| 32 | +echo "installing Operators with stackablectl" |
| 33 | +# tag::stackablectl-install-operators[] |
| 34 | +stackablectl operator install \ |
| 35 | + commons={{ versions.commons }} \ |
| 36 | + secret={{ versions.secret }} \ |
| 37 | + zookeeper={{ versions.zookeeper }} \ |
| 38 | + hdfs={{ versions.hdfs }} |
| 39 | +# end::stackablectl-install-operators[] |
| 40 | +;; |
| 41 | +*) |
| 42 | +echo "Need to give 'helm' or 'stackablectl' as an argument for which installation method to use!" |
| 43 | +exit 1 |
| 44 | +;; |
| 45 | +esac |
| 46 | + |
| 47 | +echo "Creating Zookeeper cluster" |
| 48 | +# tag::install-zk[] |
| 49 | +kubectl apply -f zk.yaml |
| 50 | +# end::install-zk[] |
| 51 | + |
| 52 | +echo "Creating ZNode" |
| 53 | +# tag::install-zk[] |
| 54 | +kubectl apply -f znode.yaml |
| 55 | +# end::install-zk[] |
| 56 | + |
| 57 | +sleep 5 |
| 58 | + |
| 59 | +echo "Awaiting Zookeeper rollout finish" |
| 60 | +# tag::watch-zk-rollout[] |
| 61 | +kubectl rollout status --watch statefulset/simple-zk-server-default |
| 62 | +# end::watch-zk-rollout[] |
| 63 | + |
| 64 | +echo "Creating HDFS cluster" |
| 65 | +# tag::install-hdfs[] |
| 66 | +kubectl apply -f hdfs.yaml |
| 67 | +# end::install-hdfs[] |
| 68 | + |
| 69 | +sleep 5 |
| 70 | + |
| 71 | +echo "Awaiting HDFS rollout finish" |
| 72 | +# tag::watch-hdfs-rollout[] |
| 73 | +kubectl rollout status --watch statefulset/simple-hdfs-datanode-default |
| 74 | +kubectl rollout status --watch statefulset/simple-hdfs-namenode-default |
| 75 | +kubectl rollout status --watch statefulset/simple-hdfs-journalnode-default |
| 76 | +# end::watch-hdfs-rollout[] |
| 77 | + |
| 78 | +echo "Creating Helper" |
| 79 | +# tag::install-webhdfs[] |
| 80 | +kubectl apply -f webhdfs.yaml |
| 81 | +# end::install-webhdfs[] |
| 82 | + |
| 83 | +sleep 5 |
| 84 | + |
| 85 | +echo "Awaiting helper rollout finish" |
| 86 | +# tag::watch-helper-rollout[] |
| 87 | +kubectl rollout status --watch statefulset/webhdfs |
| 88 | +# end::watch-helper-rollout[] |
| 89 | + |
| 90 | +file_status() { |
| 91 | + # tag::file-status[] |
| 92 | + kubectl exec -n default webhdfs-0 -- curl -s -XGET "http://simple-hdfs-namenode-default-0:9870/webhdfs/v1/?op=LISTSTATUS" |
| 93 | + # end::file-status[] |
| 94 | +} |
| 95 | + |
| 96 | +echo "Confirm that HDFS is empty..." |
| 97 | +status=$(file_status | jq -r '.FileStatuses.FileStatus') |
| 98 | + |
| 99 | +if [ "$status" == "[]" ]; then |
| 100 | + echo "As expected, HDFS is empty" |
| 101 | +else |
| 102 | + echo "Detected status: $status" |
| 103 | + exit 1 |
| 104 | +fi |
| 105 | + |
| 106 | +echo "Copy test file" |
| 107 | +# tag::copy-file[] |
| 108 | +kubectl cp -n default ./testdata.txt webhdfs-0:/tmp |
| 109 | +# end::copy-file[] |
| 110 | + |
| 111 | +create_file() { |
| 112 | + # tag::create-file[] |
| 113 | + kubectl exec -n default webhdfs-0 -- \ |
| 114 | + curl -s -XPUT -T /tmp/testdata.txt "http://simple-hdfs-namenode-default-0:9870/webhdfs/v1/testdata.txt?user.name=stackable&op=CREATE&noredirect=true" |
| 115 | + # end::create-file[] |
| 116 | +} |
| 117 | + |
| 118 | +location=$(create_file | jq -r '.Location') |
| 119 | + |
| 120 | +echo "Redirect location: $location" |
| 121 | + |
| 122 | +# tag::create-file-redirected[] |
| 123 | +kubectl exec -n default webhdfs-0 -- curl -s -XPUT -T /tmp/testdata.txt "$location" |
| 124 | +# end::create-file-redirected[] |
| 125 | + |
| 126 | +echo "Confirm that HDFS is *not* empty..." |
| 127 | +found_file=$(file_status | jq -r '.FileStatuses.FileStatus[0].pathSuffix') |
| 128 | +echo "Created file: $found_file with status $(file_status)" |
| 129 | + |
| 130 | +echo "Delete file" |
| 131 | +delete_file() { |
| 132 | + # tag::delete-file[] |
| 133 | + kubectl exec -n default webhdfs-0 -- curl -s -XDELETE "http://simple-hdfs-namenode-default-0:9870/webhdfs/v1/testdata.txt?user.name=stackable&op=DELETE" |
| 134 | + # end::delete-file[] |
| 135 | +} |
| 136 | + |
| 137 | +deleted=$(delete_file | jq -r '.boolean') |
| 138 | + |
| 139 | +if [ "$deleted" == "true" ]; then |
| 140 | + echo "File was deleted!" |
| 141 | +else |
| 142 | + echo "Detected status: $deleted" |
| 143 | + exit 1 |
| 144 | +fi |
| 145 | + |
0 commit comments