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