-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-demo
executable file
·123 lines (99 loc) · 4.14 KB
/
setup-demo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
# Assign arguments
while getopts C:c:t:a:n: flag
do
case "${flag}" in
C) cluster_name=${OPTARG};; # Cluster name
c) count=${OPTARG};; # Number of nodes
t) trino_version=${OPTARG};; # Trino server version, e.g. 399
a) aerospike_trino=${OPTARG};; # Aerospike Trino connector version, e.g. 4.2.1-391
n) namespace=${OPTARG};; # Aerospike cluster namespace, e.g. test
esac
done
# Set defaults
if [ -z "$cluster_name" ]; then cluster_name="document-demo"; fi
if [ -z "$count" ]; then count=1; fi
if [ -z "$trino_version" ]; then trino_version="399"; fi
if [ -z "$aerospike_trino" ]; then aerospike_trino="4.2.1-391"; fi
if [ -z "$namespace" ]; then namespace="demo"; fi
# Update aerospike.conf
export NAMESPACE_NAME=$namespace
export CLUSTER_NAME=$cluster_name
envsubst < aerospike/aerospike.conf.template > aerospike/aerospike.conf
# Export namespace and cluster names
cat << EOF > aerospike/namespace.txt
${namespace}
EOF
cat << EOF > aerospike/clustername.txt
${cluster_name}
EOF
# Create the aerospike cluster
aerolab cluster create --name=${cluster_name} --count=${count} --featurefile=aerospike/features.conf --customconf=aerospike/aerospike.conf -v 6.1.0.2
# Create wine-regions cluster
aerolab cluster create --name=countries --count=1 --featurefile=aerospike/features.conf --customconf=aerospike/aerospike.conf -v 6.1.0.2
aerolab files upload --name=countries aerospike/countries.asb countries.asb
aerolab files upload --name=countries aerospike/restore.sh restore.sh
aerolab attach shell --name=countries -- ./restore.sh && kill $PPID
# Get cluster IP's
cluster=$( aerolab cluster list --json )
read -r -d '' IPLIST <<EOF
function run() {
let hostList1 = [];
let hostList2;
let cluster = JSON.parse(\`$cluster\`);
for(let i = 0; i < cluster.length; i++){
if(cluster[i].ClusterName === 'countries'){
hostList2 = cluster[i].IpAddress + ':3000';
}
else{
hostList1.push(cluster[i].IpAddress + ':3000');
}
}
return hostList1.join(',') + '|' + hostList2;
}
EOF
host_list=$( osascript -l 'JavaScript' <<< "${IPLIST}" )
host_list1=(${host_list//|/ })
host_list2=(${host_list##*|})
cat << EOF > trino/aerospike.properties
connector.name=aerospike
aerospike.hostlist=$host_list1
EOF
cat << EOF > trino/aerospike2.properties
connector.name=aerospike
aerospike.hostlist=$host_list2
EOF
# Create trino server/client, copy install script and run
aerolab client create base --group-name=trino
aerolab files upload --name=trino --client trino/trino-install.sh trino-install.sh
aerolab files upload --name=trino --client trino/start-trino.sh start-trino.sh
aerolab files upload --name=trino --client trino/aerospike.properties aerospike.properties
aerolab files upload --name=trino --client trino/aerospike2.properties aerospike2.properties
aerolab client attach -n trino -- ./trino-install.sh -n ${namespace} -t ${trino_version} -a ${aerospike_trino} && kill $PPID
# Update notebook.ipynb
hosts=(${host_list1//,/ })
host=(${hosts[0]//:/ }[0])
export HOST=$host
export NAMESPACE=$namespace
envsubst < jupyter/notebook.template > jupyter/notebook.ipynb
# Create jupyter tokenaerolab files upload --name jupyter --client jupyter/wine-data.json home/jovyan/wine-data.json
jupyter_token=$( openssl rand -hex 40 )
# Store token
cat << EOF > jupyter/token.txt
${jupyter_token}
EOF
# Create start-jupyter.sh
cat << EOF > jupyter/start-jupyter.sh
#!/bin/bash
su - jovyan -c "jupyter lab --no-browser --ip=\`hostname -I\` --port=8888 --ServerApp.token=${jupyter_token}"
EOF
chmod +x jupyter/start-jupyter.sh
# Create jupyter server/client, copy install script and run
aerolab client create tools --group-name=jupyter
aerolab files upload --name=jupyter --client jupyter/jupyter-install.sh jupyter-install.sh
aerolab files upload --name=jupyter --client jupyter/start-jupyter.sh start-jupyter.sh
aerolab files upload --name=jupyter --client jupyter/notebook.ipynb notebook.ipynb
aerolab files upload --name=jupyter --client jupyter/wine-data.json wine-data.json
aerolab client attach -n jupyter -- ./jupyter-install.sh && kill $PPID
rm -rf aerospike-server-enterprise-*.tgz
echo "Setup complete"