Skip to content

Commit

Permalink
Merge pull request #23 from basho/features/lrb/bucket-type-files
Browse files Browse the repository at this point in the history
Move table / bucket type defs to files.
  • Loading branch information
alexmoore authored Mar 6, 2017
2 parents 1f54803 + 20bd11c commit 9f18c30
Show file tree
Hide file tree
Showing 19 changed files with 68 additions and 87 deletions.
1 change: 1 addition & 0 deletions bucket-types/BLURB
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"props": {"n_val": 3, "table_def": "CREATE TABLE BLURB (blurb blob not null, time timestamp not null, PRIMARY KEY((blurb, quantum(time, 15, 'm')), blurb, time))"}}
1 change: 1 addition & 0 deletions bucket-types/GeoCheckin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"props": {"n_val": 3, "table_def": "CREATE TABLE GeoCheckin (geohash varchar not null, user varchar not null, time timestamp not null, weather varchar not null, temperature double, PRIMARY KEY((geohash, user, quantum(time, 15, m)), geohash, user, time))"}}
1 change: 1 addition & 0 deletions bucket-types/GeoCheckin_Wide
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"props": {"n_val": 3, "table_def": "CREATE TABLE GeoCheckin_Wide (geohash varchar not null, user varchar not null, time timestamp not null, weather varchar not null, temperature double, uv_index sint64, observed boolean not null, PRIMARY KEY((geohash, user, quantum(time, 15, 'm')), geohash, user, time))"}}
1 change: 1 addition & 0 deletions bucket-types/GeoCheckin_Wide_1_5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"props": {"n_val": 3, "table_def": "CREATE TABLE GeoCheckin_Wide_1_5 (geohash varchar not null, user varchar not null, time timestamp not null, weather varchar not null, temperature double, uv_index sint64, observed boolean not null, sensor_data blob, PRIMARY KEY((geohash, user, quantum(time, 15, 'm')), geohash, user, time))"}}
1 change: 1 addition & 0 deletions bucket-types/WeatherByRegion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"props": {"n_val": 3, "table_def": "CREATE TABLE WeatherByRegion (region varchar not null, state varchar not null, time timestamp not null, weather varchar not null, temperature double, uv_index sint64, observed boolean not null, PRIMARY KEY((region, state, quantum(time, 15, 'm')), region, state, time))"}}
1 change: 1 addition & 0 deletions bucket-types/consistent
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"props":{"consistent":true,"n_val":5}}
1 change: 1 addition & 0 deletions bucket-types/counters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"props":{"datatype":"counter"}}
1 change: 1 addition & 0 deletions bucket-types/gsets
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"props":{"datatype":"gset"}}
1 change: 1 addition & 0 deletions bucket-types/maps
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"props":{"datatype":"map"}}
Empty file added bucket-types/mr
Empty file.
1 change: 1 addition & 0 deletions bucket-types/no_siblings
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"props":{"allow_mult":"false"}}
1 change: 1 addition & 0 deletions bucket-types/other_counters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"props":{"datatype":"counter","allow_mult":true}}
Empty file added bucket-types/plain
Empty file.
Empty file added bucket-types/search_type
Empty file.
1 change: 1 addition & 0 deletions bucket-types/sets
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"props":{"datatype":"set"}}
1 change: 1 addition & 0 deletions bucket-types/write_once
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"props":{"write_once":true}}
1 change: 1 addition & 0 deletions bucket-types/yokozuna
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"props":{"datatype":"hll"}}
138 changes: 52 additions & 86 deletions lib/riak_cluster_config.bash
Original file line number Diff line number Diff line change
@@ -1,115 +1,81 @@
function riak_cluster_config
{
declare -r riak_admin="$1"
declare -ir http_port="$2"
declare -r strong_consistency="${3:-false}"
declare -r use_security="${4:-false}"

$riak_admin bucket-type create plain
$riak_admin bucket-type create search_type
$riak_admin bucket-type create mr
$riak_admin bucket-type create no_siblings '{"props":{"allow_mult":"false"}}'
$riak_admin bucket-type create maps '{"props":{"datatype":"map"}}'
$riak_admin bucket-type create sets '{"props":{"datatype":"set"}}'
$riak_admin bucket-type create counters '{"props":{"datatype":"counter"}}'
$riak_admin bucket-type create other_counters '{"props":{"datatype":"counter","allow_mult":true}}'
$riak_admin bucket-type create yokozuna '{"props":{}}'

set +o errexit
$riak_admin bucket-type create hlls '{"props":{"datatype":"hll"}}'
$riak_admin bucket-type create gsets '{"props":{"datatype":"gset"}}'
$riak_admin bucket-type create write_once '{"props":{"write_once":true}}'
$riak_admin bucket-type create GeoCheckin '{"props": {"n_val": 3, "table_def": "CREATE TABLE GeoCheckin (geohash varchar not null, user varchar not null, time timestamp not null, weather varchar not null, temperature double, PRIMARY KEY((geohash, user, quantum(time, 15, m)), geohash, user, time))"}}'
$riak_admin bucket-type create GeoCheckin_Wide '{"props": {"n_val": 3, "table_def": "CREATE TABLE GeoCheckin_Wide (geohash varchar not null, user varchar not null, time timestamp not null, weather varchar not null, temperature double, uv_index sint64, observed boolean not null, PRIMARY KEY((geohash, user, quantum(time, 15, 'm')), geohash, user, time))"}}'
$riak_admin bucket-type create 'GeoCheckin_Wide_1_5' '{"props": {"n_val": 3, "table_def": "CREATE TABLE GeoCheckin_Wide_1_5 (geohash varchar not null, user varchar not null, time timestamp not null, weather varchar not null, temperature double, uv_index sint64, observed boolean not null, sensor_data blob, PRIMARY KEY((geohash, user, quantum(time, 15, 'm')), geohash, user, time))"}}'
$riak_admin bucket-type create WeatherByRegion '{"props": {"n_val": 3, "table_def": "CREATE TABLE WeatherByRegion (region varchar not null, state varchar not null, time timestamp not null, weather varchar not null, temperature double, uv_index sint64, observed boolean not null, PRIMARY KEY((region, state, quantum(time, 15, 'm')), region, state, time))"}}'
$riak_admin bucket-type create BLURB '{"props": {"n_val": 3, "table_def": "CREATE TABLE BLURB (blurb blob not null, time timestamp not null, PRIMARY KEY((blurb, quantum(time, 15, 'm')), blurb, time))"}}'
set -o errexit

$riak_admin bucket-type activate plain
$riak_admin bucket-type activate search_type
$riak_admin bucket-type activate mr
$riak_admin bucket-type activate no_siblings
$riak_admin bucket-type activate maps
$riak_admin bucket-type activate sets
$riak_admin bucket-type activate counters
$riak_admin bucket-type activate other_counters
$riak_admin bucket-type activate yokozuna
# NB: using rcc_ prefix to prevent name clashes
local -r rcc_riak_admin="$1"
local -ir rcc_http_port="$2"
local -r rcc_strong_consistency="${3:-false}" # NB: not used anymore, keep as placeholder
local -r rcc_use_security="${4:-false}"
local -r rcc_bucket_type_file_path="${5:-nopath}"

local rcc_btf=''
local rcc_bucket_type_def=''
set +o errexit
$riak_admin bucket-type activate hlls
$riak_admin bucket-type activate gsets
$riak_admin bucket-type activate write_once
$riak_admin bucket-type activate GeoCheckin
$riak_admin bucket-type activate GeoCheckin_Wide
$riak_admin bucket-type activate GeoCheckin_Wide_1_5
$riak_admin bucket-type activate WeatherByRegion
$riak_admin bucket-type activate BLURB
for rcc_bucket_type_file in "$rcc_bucket_type_file_path"/*
do
rcc_bucket_type_def="$(< $rcc_bucket_type_file)"
rcc_bucket_type_name="$(basename $rcc_bucket_type_file)"
$rcc_riak_admin bucket-type create "$rcc_bucket_type_name" "$rcc_bucket_type_def"
$rcc_riak_admin bucket-type activate "$rcc_bucket_type_name"
done
set -o errexit

if [[ $strong_consistency == 'true' ]]
then
$riak_admin bucket-type create consistent '{"props":{"consistent":true,"n_val":5}}'
$riak_admin bucket-type activate consistent
fi

set +o errexit
echo -n 'Setting properties on test_multi_bucket HTTP CODE:'
curl -4so /dev/null -w "%{http_code}" -XPUT -H 'Content-type: application/json' localhost:$http_port/buckets/test_multi_bucket/props -d '{"props":{"allow_mult":true,"last_write_wins":false}}'
curl -4so /dev/null -w "%{http_code}" -XPUT -H 'Content-type: application/json' localhost:$rcc_http_port/buckets/test_multi_bucket/props -d '{"props":{"allow_mult":true,"last_write_wins":false}}'
echo ' ...DONE'
set -o errexit

if [[ $use_security == 'true' ]]
if [[ $rcc_use_security == 'true' ]]
then
# NB: don't exit on error due to 2.0.7
# TODO: set -o errexit when all Riak versions >= 2.1.4
set +o errexit
$riak_admin security enable
$riak_admin security add-group test
$rcc_riak_admin security enable
$rcc_riak_admin security add-group test

# cert auth users
$riak_admin security add-user riakuser 'groups=test'
$riak_admin security add-source riakuser 0.0.0.0/0 certificate
$riak_admin security add-user certuser 'groups=test'
$riak_admin security add-source certuser 0.0.0.0/0 certificate
$rcc_riak_admin security add-user riakuser 'groups=test'
$rcc_riak_admin security add-source riakuser 0.0.0.0/0 certificate
$rcc_riak_admin security add-user certuser 'groups=test'
$rcc_riak_admin security add-source certuser 0.0.0.0/0 certificate

# password auth users
$riak_admin security add-user riakpass 'password=Test1234' 'groups=test'
$riak_admin security add-user user 'password=password' 'groups=test'
$riak_admin security add-source riakpass 0.0.0.0/0 password
$riak_admin security add-source user 0.0.0.0/0 password
$rcc_riak_admin security add-user riakpass 'password=Test1234' 'groups=test'
$rcc_riak_admin security add-user user 'password=password' 'groups=test'
$rcc_riak_admin security add-source riakpass 0.0.0.0/0 password
$rcc_riak_admin security add-source user 0.0.0.0/0 password

# trust auth users
$riak_admin security add-user riak_trust_user password=riak_trust_user
$riak_admin security add-source riak_trust_user 0.0.0.0/0 trust
$rcc_riak_admin security add-user riak_trust_user password=riak_trust_user
$rcc_riak_admin security add-source riak_trust_user 0.0.0.0/0 trust

# NB: Riak 2.0.7 does not support chaining grants via commas
$riak_admin security grant riak_kv.get on any to all
$riak_admin security grant riak_kv.get_preflist on any to all
$riak_admin security grant riak_kv.put on any to all
$riak_admin security grant riak_kv.delete on any to all
$riak_admin security grant riak_kv.index on any to all
$riak_admin security grant riak_kv.list_keys on any to all
$riak_admin security grant riak_kv.list_buckets on any to all
$riak_admin security grant riak_kv.mapreduce on any to all
$rcc_riak_admin security grant riak_kv.get on any to all
$rcc_riak_admin security grant riak_kv.get_preflist on any to all
$rcc_riak_admin security grant riak_kv.put on any to all
$rcc_riak_admin security grant riak_kv.delete on any to all
$rcc_riak_admin security grant riak_kv.index on any to all
$rcc_riak_admin security grant riak_kv.list_keys on any to all
$rcc_riak_admin security grant riak_kv.list_buckets on any to all
$rcc_riak_admin security grant riak_kv.mapreduce on any to all

$riak_admin security grant riak_core.get_bucket on any to all
$riak_admin security grant riak_core.set_bucket on any to all
$riak_admin security grant riak_core.get_bucket_type on any to all
$riak_admin security grant riak_core.set_bucket_type on any to all
$rcc_riak_admin security grant riak_core.get_bucket on any to all
$rcc_riak_admin security grant riak_core.set_bucket on any to all
$rcc_riak_admin security grant riak_core.get_bucket_type on any to all
$rcc_riak_admin security grant riak_core.set_bucket_type on any to all

$riak_admin security grant search.admin on any to all
$riak_admin security grant search.query on any to all
$rcc_riak_admin security grant search.admin on any to all
$rcc_riak_admin security grant search.query on any to all

$riak_admin security grant riak_ts.get on any to all
$riak_admin security grant riak_ts.put on any to all
$riak_admin security grant riak_ts.delete on any to all
$riak_admin security grant riak_ts.list_keys on any to all
$riak_admin security grant riak_ts.coverage on any to all
$riak_admin security grant riak_ts.create_table on any to all
$riak_admin security grant riak_ts.query_select on any to all
$riak_admin security grant riak_ts.describe_table on any to all
$riak_admin security grant riak_ts.show_tables on any to all
$rcc_riak_admin security grant riak_ts.get on any to all
$rcc_riak_admin security grant riak_ts.put on any to all
$rcc_riak_admin security grant riak_ts.delete on any to all
$rcc_riak_admin security grant riak_ts.list_keys on any to all
$rcc_riak_admin security grant riak_ts.coverage on any to all
$rcc_riak_admin security grant riak_ts.create_table on any to all
$rcc_riak_admin security grant riak_ts.query_select on any to all
$rcc_riak_admin security grant riak_ts.describe_table on any to all
$rcc_riak_admin security grant riak_ts.show_tables on any to all
set -o errexit
fi

Expand Down
3 changes: 2 additions & 1 deletion setup-riak
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ declare riak_admin='riak-admin' # NB: will be set below
declare -r default_cluster_path="$HOME/basho/riak/rel"
declare -ir default_pb_port=8087
declare -ir default_http_port=8098
declare -r bucket_type_file_path="$script_path/bucket-types"

set +o nounset
if [[ -n $RIAK_CONF ]]
Expand Down Expand Up @@ -280,7 +281,7 @@ function setup_cluster
commit_cluster "$riak_admin"
if [[ $opt_setup_only == 'false' ]]
then
riak_cluster_config "$riak_admin" "$starting_http_port" "$opt_strong_consistency" "$opt_use_security"
riak_cluster_config "$riak_admin" "$starting_http_port" "$opt_strong_consistency" "$opt_use_security" "$bucket_type_file_path"
fi
return 0
}
Expand Down

0 comments on commit 9f18c30

Please sign in to comment.