-
Notifications
You must be signed in to change notification settings - Fork 0
/
start-demo
executable file
·108 lines (88 loc) · 2.87 KB
/
start-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
#!/bin/bash
# Get namespace name
FILE=aerospike/namespace.txt
if [ -f "$FILE" ]; then
namespace=`cat aerospike/namespace.txt`
else
namespace=test
fi
# Get cluster name
FILE=aerospike/clustername.txt
if [ -f "$FILE" ]; then
cluster_name=`cat aerospike/clustername.txt`
else
cluster_name=document-demo
fi
#Start clients if not already
aerolab cluster start -n ${cluster_name}
aerolab cluster start -n countries
aerolab attach shell --name=countries -- ./restore.sh && kill $PPID
aerolab client start -n trino
aerolab client start -n jupyter
# 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}" )
echo $host_list
host_list1=(${host_list//|/ })
echo $host_list1
host_list2=(${host_list##*|})
echo $host_list2
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
aerolab files upload --name=trino --client trino/aerospike.properties /home/trino/trino-server/etc/catalog/aerospike.properties
aerolab files upload --name=trino --client trino/aerospike2.properties /home/trino/trino-server/etc/catalog/aerospike2.properties
aerolab client stop -n trino
aerolab client start -n trino
# Get Jupyter client IP
clients=$( aerolab client list --json )
read -r -d '' IPADDRESS <<EOF
function run() {
let clients = JSON.parse(\`$clients\`);
let ipAddress = clients[clients.findIndex(x => x.ClusterName === 'jupyter')].IpAddress + ':8888';
return ipAddress;
}
EOF
jupyter=$( osascript -l 'JavaScript' <<< "${IPADDRESS}" )
# Get jupyter token
FILE=jupyter/token.txt
if [ -f "$FILE" ]; then
token=`cat jupyter/token.txt`
else
token=""
fi
# Update notebook.ipynb
hosts=(${host_list1//,/ })
host=(${hosts[0]//:/ }[0])
export HOST=$host
export NAMESPACE=$namespace
envsubst < jupyter/notebook.template > jupyter/notebook.ipynb
aerolab files upload --name=jupyter --client jupyter/notebook.ipynb /home/jovyan/notebook.ipynb
# Start jupyter notebook in new window
osascript -e 'tell app "Terminal" to do script "aerolab client attach -n jupyter -- ./start-jupyter.sh"'
sleep 2
osascript -e 'do shell script "open http://'${jupyter}'?token='${token}'"'
# Start trino client/server in new window
sleep 2
osascript -e 'tell app "Terminal" to do script "aerolab client attach -n trino -- ./start-trino.sh -n '${namespace}'"' -e 'tell app "Terminal" to activate'