#!/bin/bash

#############################################################################
#  Setting up the raft groups
#  
#  IPS:
#  ${node1}
#  ${node2}
#  ${node3}
#  
#  Run once from from any node
#############################################################################

# setup clusters
redis-cli -h ${node1} -p 19901 raft.cluster init
redis-cli -h ${node1} -p 19902 raft.cluster init
redis-cli -h ${node1} -p 19903 raft.cluster init
redis-cli -h ${node1} -p 19904 raft.cluster init

redis-cli -h ${node2} -p 19905 raft.cluster init
redis-cli -h ${node2} -p 19906 raft.cluster init
redis-cli -h ${node2} -p 19907 raft.cluster init
redis-cli -h ${node2} -p 19908 raft.cluster init

redis-cli -h ${node3} -p 19909 raft.cluster init
redis-cli -h ${node3} -p 19910 raft.cluster init
redis-cli -h ${node3} -p 19911 raft.cluster init
redis-cli -h ${node3} -p 19912 raft.cluster init

# setup groups
redis-cli -h ${node2} -p 19901 raft.cluster join ${node1}:19901
redis-cli -h ${node3} -p 19901 raft.cluster join ${node1}:19901

redis-cli -h ${node2} -p 19902 raft.cluster join ${node1}:19902
redis-cli -h ${node3} -p 19902 raft.cluster join ${node1}:19902

redis-cli -h ${node2} -p 19903 raft.cluster join ${node1}:19903
redis-cli -h ${node3} -p 19903 raft.cluster join ${node1}:19903

redis-cli -h ${node2} -p 19904 raft.cluster join ${node1}:19904
redis-cli -h ${node3} -p 19904 raft.cluster join ${node1}:19904

redis-cli -h ${node1} -p 19905 raft.cluster join ${node2}:19905
redis-cli -h ${node3} -p 19905 raft.cluster join ${node2}:19905

redis-cli -h ${node1} -p 19906 raft.cluster join ${node2}:19906
redis-cli -h ${node3} -p 19906 raft.cluster join ${node2}:19906

redis-cli -h ${node1} -p 19907 raft.cluster join ${node2}:19907
redis-cli -h ${node3} -p 19907 raft.cluster join ${node2}:19907

redis-cli -h ${node1} -p 19908 raft.cluster join ${node2}:19908
redis-cli -h ${node3} -p 19908 raft.cluster join ${node2}:19908

redis-cli -h ${node1} -p 19909 raft.cluster join ${node3}:19909
redis-cli -h ${node2} -p 19909 raft.cluster join ${node3}:19909

redis-cli -h ${node1} -p 19910 raft.cluster join ${node3}:19910
redis-cli -h ${node2} -p 19910 raft.cluster join ${node3}:19910

redis-cli -h ${node1} -p 19911 raft.cluster join ${node3}:19911
redis-cli -h ${node2} -p 19911 raft.cluster join ${node3}:19911

redis-cli -h ${node1} -p 19912 raft.cluster join ${node3}:19912
redis-cli -h ${node2} -p 19912 raft.cluster join ${node3}:19912