Masayoshi Kobayashi | f0057de | 2013-06-20 16:55:22 -0700 | [diff] [blame] | 1 | CASSANDRA_DIR='${HOME}/apache-cassandra-1.1.4' |
| 2 | ZK_DIR='${HOME}/zookeeper-3.4.5' |
| 3 | ONOS_DIR='${HOME}/ONOS' |
Masayoshi Kobayashi | 972b846 | 2013-06-21 15:46:38 -0700 | [diff] [blame] | 4 | |
Masayoshi Kobayashi | f358ff5 | 2013-03-22 00:31:59 +0000 | [diff] [blame] | 5 | ZK_LIB='/var/lib/zookeeper' |
| 6 | CASSANDRA_LIB='/var/lib/cassandra' |
| 7 | |
| 8 | if [ x$CLUSTER == "x" ]; then |
| 9 | echo "CLUSTER is not set. Exitting." |
| 10 | exit |
| 11 | fi |
| 12 | if [ x$ONOS_CLUSTER_BASENAME == "x" ]; then |
| 13 | echo "ONOS_CLUSTER_BASENAME is not set. Exitting" |
| 14 | exit |
| 15 | fi |
| 16 | if [ x$ONOS_CLUSTER_NR_NODES == "x" ]; then |
| 17 | echo "ONOS_CLUSTER_NR_NODES is not set. Exitting" |
| 18 | exit |
| 19 | fi |
| 20 | |
| 21 | export basename=$ONOS_CLUSTER_BASENAME |
| 22 | export nr_nodes=$ONOS_CLUSTER_NR_NODES |
| 23 | |
| 24 | checkcluster () { |
| 25 | dsh -g $basename 'uname -a' |
| 26 | } |
| 27 | |
| 28 | zk () { |
| 29 | case "$1" in |
| 30 | start) |
| 31 | echo "Starting ZK.." |
Masayoshi Kobayashi | 9973090 | 2013-06-27 23:23:20 -0700 | [diff] [blame] | 32 | # dsh -g $basename "$ZK_DIR/bin/zkServer.sh start" |
| 33 | dsh -g $basename 'cd ONOS; ./start-zk.sh start' |
Masayoshi Kobayashi | f358ff5 | 2013-03-22 00:31:59 +0000 | [diff] [blame] | 34 | while [ 1 ]; do |
Masayoshi Kobayashi | 9973090 | 2013-06-27 23:23:20 -0700 | [diff] [blame] | 35 | # nup=`dsh -g $basename "$ZK_DIR/bin/zkServer.sh status" | grep "Mode" | egrep "leader|follower" | wc -l` |
| 36 | nup=`dsh -g $basename "cd ONOS; ./start-zk.sh status" | grep "Mode" | egrep "leader|follower|standalone" | wc -l` |
Masayoshi Kobayashi | f358ff5 | 2013-03-22 00:31:59 +0000 | [diff] [blame] | 37 | if [ $nup == $nr_nodes ]; then |
| 38 | echo "everybody's up: $nup up of of $nr_nodes" |
| 39 | echo "ZK started" |
| 40 | break; |
| 41 | fi |
| 42 | echo "waiting for everybody's up: $nup up of of $nr_nodes" |
| 43 | sleep 1 |
| 44 | done |
| 45 | ;; |
| 46 | stop) |
| 47 | echo "Stopping ZK.." |
| 48 | dsh -g $basename "$ZK_DIR/bin/zkServer.sh stop" |
| 49 | ;; |
| 50 | status) |
| 51 | echo "Checking ZK Status" |
| 52 | dsh -g $basename "$ZK_DIR/bin/zkServer.sh status" |
| 53 | ;; |
| 54 | esac |
| 55 | } |
| 56 | |
| 57 | cassandra () { |
| 58 | case "$1" in |
| 59 | start) |
| 60 | echo "Starting Cassandra.." |
| 61 | echo " start cassandra at the seed node" |
| 62 | dsh -w ${basename}1 "cd $ONOS_DIR; ./start-cassandra.sh start" |
| 63 | sleep 1 |
| 64 | echo " start cassandra in rest nodes" |
| 65 | dsh -g ${basename} -x ${basename}1 "cd $ONOS_DIR; ./start-cassandra.sh start" |
| 66 | while [ 1 ]; do |
| 67 | echo $$ |
| 68 | dsh -w ${basename}1 "cd $ONOS_DIR; ./start-cassandra.sh status" > .cassandra_check.$$ |
| 69 | cat .cassandra_check.$$ |
| 70 | nup=`cat .cassandra_check.$$ | grep Normal |grep Up| wc -l` |
| 71 | if [ $nup == $nr_nodes ]; then |
| 72 | echo "everybody's up: $nup up of of $nr_nodes" |
| 73 | echo "Cassandra started" |
| 74 | break; |
| 75 | fi |
| 76 | echo "waiting for everybody's up: $nup up of of $nr_nodes" |
| 77 | sleep 1 |
| 78 | done |
| 79 | ;; |
Masayoshi Kobayashi | f238c9e | 2013-06-10 01:41:13 +0000 | [diff] [blame] | 80 | bootup) |
| 81 | echo "Removing old Cassandra data and logs" |
| 82 | dsh -g ${basename} "rm -rf /var/lib/cassandra/*" |
| 83 | dsh -g ${basename} "rm -rf /var/log/cassandra/*" |
| 84 | |
| 85 | echo "Starting Cassandra nodes one by one..." |
| 86 | for (( c=1; c<=$nr_nodes; c++ )) |
| 87 | do |
| 88 | echo "Starting node ${basename}${c}" |
| 89 | dsh -g ${basename} -w ${basename}${c} "cd $ONOS_DIR; ./start-cassandra.sh start" |
| 90 | |
| 91 | #Wait until it's up |
| 92 | while [ 1 ]; do |
| 93 | echo $$ |
| 94 | dsh -w ${basename}1 "cd $ONOS_DIR; ./start-cassandra.sh status" > .cassandra_check.$$ |
| 95 | cat .cassandra_check.$$ |
| 96 | nup=`cat .cassandra_check.$$ | grep Normal |grep Up| wc -l` |
| 97 | if [ $nup == $c ]; then |
| 98 | echo "New node up: $nup up of of $nr_nodes" |
| 99 | break; |
| 100 | fi |
| 101 | echo "Waiting for new node to come up: $nup up of of $nr_nodes" |
| 102 | sleep 5 |
| 103 | done |
| 104 | done |
| 105 | ;; |
Masayoshi Kobayashi | f358ff5 | 2013-03-22 00:31:59 +0000 | [diff] [blame] | 106 | stop) |
| 107 | echo "Stopping Cassandra.." |
| 108 | dsh -g ${basename} "cd $ONOS_DIR; ./start-cassandra.sh stop" |
| 109 | ;; |
| 110 | cleandb) |
| 111 | echo "Removing all data in db" |
| 112 | dsh -w ${basename}1 "cd $ONOS_DIR; ./scripts/cleanup-cassandra.sh" |
| 113 | ;; |
Masayoshi Kobayashi | bd3d00e | 2013-04-03 22:59:57 +0000 | [diff] [blame] | 114 | checkdb) |
| 115 | echo "Check DB Status" |
| 116 | dsh -w ${basename}1 "cd $ONOS_DIR; ./scripts/check-db-status.sh" |
| 117 | ;; |
Masayoshi Kobayashi | f358ff5 | 2013-03-22 00:31:59 +0000 | [diff] [blame] | 118 | status) |
| 119 | echo "Checking Cassandra Status" |
| 120 | dsh -w ${basename}1 "cd $ONOS_DIR; ./start-cassandra.sh status" |
| 121 | ;; |
| 122 | esac |
| 123 | } |
| 124 | |
| 125 | onos () { |
| 126 | case "$1" in |
| 127 | start) |
Masayoshi Kobayashi | 0ab03da | 2013-03-26 00:43:02 +0000 | [diff] [blame] | 128 | if [ x$2 == "x" -o x$2 == "xall" ]; then |
| 129 | echo "Starting ONOS on all nodes" |
Masayoshi Kobayashi | 9973090 | 2013-06-27 23:23:20 -0700 | [diff] [blame] | 130 | dsh -w ${basename}1 "cd $ONOS_DIR; ./start-onos.sh start" |
| 131 | sleep 3 |
| 132 | dsh -g ${basename} -x ${basename}1 "cd $ONOS_DIR; ./start-onos.sh start" |
Masayoshi Kobayashi | 4a1542b | 2013-04-02 22:34:13 +0000 | [diff] [blame] | 133 | dsh -g ${basename} "cd $ONOS_DIR; ./start-rest.sh start" |
Masayoshi Kobayashi | 0ab03da | 2013-03-26 00:43:02 +0000 | [diff] [blame] | 134 | else |
| 135 | echo "Starting ONOS on ${basename}$2" |
| 136 | dsh -w ${basename}$2 "cd $ONOS_DIR; ./start-onos.sh start" |
| 137 | fi |
Masayoshi Kobayashi | f358ff5 | 2013-03-22 00:31:59 +0000 | [diff] [blame] | 138 | ;; |
| 139 | stop) |
Masayoshi Kobayashi | 0ab03da | 2013-03-26 00:43:02 +0000 | [diff] [blame] | 140 | if [ x$2 == "x" -o x$2 == "xall" ]; then |
| 141 | echo "Stop ONOS on all nodes" |
| 142 | dsh -g ${basename} "cd $ONOS_DIR; ./start-onos.sh stop" |
| 143 | else |
| 144 | echo "Stop ONOS on ${basename}$2" |
| 145 | dsh -w ${basename}$2 "cd $ONOS_DIR; ./start-onos.sh stop" |
| 146 | fi |
Masayoshi Kobayashi | f358ff5 | 2013-03-22 00:31:59 +0000 | [diff] [blame] | 147 | ;; |
| 148 | status) |
| 149 | echo "Checking ONOS Status" |
| 150 | dsh -g ${basename} "cd $ONOS_DIR; ./start-onos.sh status" |
| 151 | ;; |
| 152 | esac |
| 153 | } |
Masayoshi Kobayashi | 0ab03da | 2013-03-26 00:43:02 +0000 | [diff] [blame] | 154 | switch () { |
| 155 | case "$1" in |
| 156 | local) |
| 157 | if [ x$2 == "x" -o x$2 == "xall" ]; then |
| 158 | echo "set all switches point to local controller" |
| 159 | dsh -g ${basename} "$ONOS_DIR/scripts/ctrl-local.sh" |
| 160 | else |
| 161 | dsh -w ${basename}$2 "$ONOS_DIR/scripts/ctrl-local.sh" |
| 162 | fi |
| 163 | ;; |
| 164 | all) |
| 165 | if [ x$2 == "x" -o x$2 == "xall" ]; then |
| 166 | echo "set all non-core switches point to all non-core controllers" |
Masayoshi Kobayashi | 4a1542b | 2013-04-02 22:34:13 +0000 | [diff] [blame] | 167 | dsh -g ${basename} -x ${basename}1 "$ONOS_DIR/scripts/ctrl-add-ext.sh" |
Masayoshi Kobayashi | 0ab03da | 2013-03-26 00:43:02 +0000 | [diff] [blame] | 168 | else |
Masayoshi Kobayashi | 4a1542b | 2013-04-02 22:34:13 +0000 | [diff] [blame] | 169 | dsh -w ${basename}$2 "$ONOS_DIR/scripts/ctrl-add-ext.sh" |
Masayoshi Kobayashi | 0ab03da | 2013-03-26 00:43:02 +0000 | [diff] [blame] | 170 | fi |
| 171 | ;; |
| 172 | none) |
| 173 | if [ x$2 == "x" -o x$2 == "xall" ]; then |
| 174 | echo "all non-core switches loose controller" |
| 175 | dsh -g ${basename} -x ${basename}1 "$ONOS_DIR/scripts/ctrl-none.sh" |
| 176 | else |
| 177 | dsh -w ${basename}$2 "$ONOS_DIR/scripts/ctrl-none.sh" |
| 178 | fi |
| 179 | ;; |
| 180 | esac |
| 181 | } |