-
Notifications
You must be signed in to change notification settings - Fork 17
/
setup-examples
executable file
·130 lines (106 loc) · 3.55 KB
/
setup-examples
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
124
125
126
127
128
129
#!/usr/bin/env bash
set -o errexit
set -o nounset
# NB: can't put this in common.bash since finding
# common.bash depends on it
# http://www.ostricher.com/2014/10/the-right-way-to-get-the-directory-of-a-bash-script/
function get_scriptpath
{
local sdir='unset'
local target='unset'
local bsrc="${BASH_SOURCE[0]}"
while [[ -h $bsrc ]]
do
target="$(readlink $bsrc)"
if [[ $target == /* ]]
then
bsrc="$target"
else
sdir="$(dirname $bsrc)"
bsrc="$sdir/$target"
fi
done
echo "$(cd -P $(dirname $bsrc) && pwd)"
}
unset CDPATH
declare -r script_path="$(get_scriptpath)"
export PATH="$PATH:$script_path"
source "$script_path/common.bash"
# Defaults
declare -r riak_admin=dev1/bin/riak-admin
declare -r default_dev_cluster_path="$HOME/Projects/basho/riak/dev"
opt_setup_document_store='false'
function usage
{
echo "
setup-examples: Set up your dev cluster to run RiakClientExamples project
Usage: setup-dev-cluster [-d] [-p <riak dev path>]
-d Set up bucket types for Document Store and Search Data Types
examples. Run this *after* creating the blog_post_schema schema
and these indexes:
blog_posts
scores
hobbies
customers
-p Riak dev path (Default: \"$default_dev_cluster_path\")
"
exit 0
}
while getopts "dp:" opt; do
case $opt in
p)
opt_dev_cluster_path="$OPTARG";;
d)
opt_setup_document_store='true';;
*)
usage;;
esac
done
declare -r dev_cluster_path="${opt_dev_cluster_path:-$default_dev_cluster_path}"
if [[ -d $dev_cluster_path ]]
then
pinfo "Setting up dev cluster in $dev_cluster_path for RiakClientExamples"
else
errexit "Dev cluster path $dev_cluster_path does not exist!"
fi
pushd $dev_cluster_path > /dev/null
set +o errexit
# Note:
# run the following commands for the "Document Store"
# and "Search Data Types" examples.
# You must create these indexes first:
# blog_posts
# scores
# hobbies
# customers
#
if [[ $opt_setup_document_store == 'true' ]]
then
$riak_admin bucket-type create cms '{"props":{"datatype":"map","search_index":"blog_posts"}}'
$riak_admin bucket-type activate cms
$riak_admin bucket-type update counters '{"props":{"search_index":"scores"}}'
$riak_admin bucket-type update sets '{"props":{"search_index":"hobbies"}}'
$riak_admin bucket-type update maps '{"props":{"search_index":"customers"}}'
else
for bucket_type in animals quotes sports cars users indexes
do
$riak_admin bucket-type create "$bucket_type"
$riak_admin bucket-type activate "$bucket_type"
done
$riak_admin bucket-type create n_val_of_5 '{"props":{"n_val":5}}'
$riak_admin bucket-type activate n_val_of_5
$riak_admin bucket-type create maps '{"props":{"datatype":"map"}}'
$riak_admin bucket-type activate maps
$riak_admin bucket-type create sets '{"props":{"datatype":"set"}}'
$riak_admin bucket-type activate sets
$riak_admin bucket-type create counters '{"props":{"datatype":"counter"}}'
$riak_admin bucket-type activate counters
$riak_admin bucket-type create siblings '{"props":{"allow_mult":true}}'
$riak_admin bucket-type activate siblings
$riak_admin bucket-type create siblings_allowed '{"props":{"allow_mult":true}}'
$riak_admin bucket-type activate siblings_allowed
$riak_admin bucket-type create no_siblings '{"props":{"allow_mult":false}}'
$riak_admin bucket-type activate no_siblings
fi
set -o errexit
pinfo "Done!"