Masayoshi Kobayashi | f358ff5 | 2013-03-22 00:31:59 +0000 | [diff] [blame] | 1 | USERNAME=ubuntu |
| 2 | CASSANDRA_DIR='/home/ubuntu/apache-cassandra-1.1.4' |
| 3 | ZK_DIR='/home/ubuntu/zookeeper-3.4.5' |
| 4 | ONOS_DIR='/home/ubuntu/ONOS' |
| 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.." |
| 32 | dsh -g $basename "$ZK_DIR/bin/zkServer.sh start" |
| 33 | while [ 1 ]; do |
| 34 | nup=`dsh -g $basename "$ZK_DIR/bin/zkServer.sh status" | grep "Mode" | egrep "leader|follower" | wc -l` |
| 35 | if [ $nup == $nr_nodes ]; then |
| 36 | echo "everybody's up: $nup up of of $nr_nodes" |
| 37 | echo "ZK started" |
| 38 | break; |
| 39 | fi |
| 40 | echo "waiting for everybody's up: $nup up of of $nr_nodes" |
| 41 | sleep 1 |
| 42 | done |
| 43 | ;; |
| 44 | stop) |
| 45 | echo "Stopping ZK.." |
| 46 | dsh -g $basename "$ZK_DIR/bin/zkServer.sh stop" |
| 47 | ;; |
| 48 | status) |
| 49 | echo "Checking ZK Status" |
| 50 | dsh -g $basename "$ZK_DIR/bin/zkServer.sh status" |
| 51 | ;; |
| 52 | esac |
| 53 | } |
| 54 | |
| 55 | cassandra () { |
| 56 | case "$1" in |
| 57 | start) |
| 58 | echo "Starting Cassandra.." |
| 59 | echo " start cassandra at the seed node" |
| 60 | dsh -w ${basename}1 "cd $ONOS_DIR; ./start-cassandra.sh start" |
| 61 | sleep 1 |
| 62 | echo " start cassandra in rest nodes" |
| 63 | dsh -g ${basename} -x ${basename}1 "cd $ONOS_DIR; ./start-cassandra.sh start" |
| 64 | while [ 1 ]; do |
| 65 | echo $$ |
| 66 | dsh -w ${basename}1 "cd $ONOS_DIR; ./start-cassandra.sh status" > .cassandra_check.$$ |
| 67 | cat .cassandra_check.$$ |
| 68 | nup=`cat .cassandra_check.$$ | grep Normal |grep Up| wc -l` |
| 69 | if [ $nup == $nr_nodes ]; then |
| 70 | echo "everybody's up: $nup up of of $nr_nodes" |
| 71 | echo "Cassandra started" |
| 72 | break; |
| 73 | fi |
| 74 | echo "waiting for everybody's up: $nup up of of $nr_nodes" |
| 75 | sleep 1 |
| 76 | done |
| 77 | ;; |
| 78 | stop) |
| 79 | echo "Stopping Cassandra.." |
| 80 | dsh -g ${basename} "cd $ONOS_DIR; ./start-cassandra.sh stop" |
| 81 | ;; |
| 82 | cleandb) |
| 83 | echo "Removing all data in db" |
| 84 | dsh -w ${basename}1 "cd $ONOS_DIR; ./scripts/cleanup-cassandra.sh" |
| 85 | ;; |
Masayoshi Kobayashi | bd3d00e | 2013-04-03 22:59:57 +0000 | [diff] [blame] | 86 | checkdb) |
| 87 | echo "Check DB Status" |
| 88 | dsh -w ${basename}1 "cd $ONOS_DIR; ./scripts/check-db-status.sh" |
| 89 | ;; |
Masayoshi Kobayashi | f358ff5 | 2013-03-22 00:31:59 +0000 | [diff] [blame] | 90 | status) |
| 91 | echo "Checking Cassandra Status" |
| 92 | dsh -w ${basename}1 "cd $ONOS_DIR; ./start-cassandra.sh status" |
| 93 | ;; |
| 94 | esac |
| 95 | } |
| 96 | |
| 97 | onos () { |
| 98 | case "$1" in |
| 99 | start) |
Masayoshi Kobayashi | 0ab03da | 2013-03-26 00:43:02 +0000 | [diff] [blame] | 100 | if [ x$2 == "x" -o x$2 == "xall" ]; then |
| 101 | echo "Starting ONOS on all nodes" |
| 102 | dsh -g ${basename} "cd $ONOS_DIR; ./start-onos.sh start" |
Masayoshi Kobayashi | 4a1542b | 2013-04-02 22:34:13 +0000 | [diff] [blame] | 103 | dsh -g ${basename} "cd $ONOS_DIR; ./start-rest.sh start" |
Masayoshi Kobayashi | 0ab03da | 2013-03-26 00:43:02 +0000 | [diff] [blame] | 104 | else |
| 105 | echo "Starting ONOS on ${basename}$2" |
| 106 | dsh -w ${basename}$2 "cd $ONOS_DIR; ./start-onos.sh start" |
| 107 | fi |
Masayoshi Kobayashi | f358ff5 | 2013-03-22 00:31:59 +0000 | [diff] [blame] | 108 | ;; |
| 109 | stop) |
Masayoshi Kobayashi | 0ab03da | 2013-03-26 00:43:02 +0000 | [diff] [blame] | 110 | if [ x$2 == "x" -o x$2 == "xall" ]; then |
| 111 | echo "Stop ONOS on all nodes" |
| 112 | dsh -g ${basename} "cd $ONOS_DIR; ./start-onos.sh stop" |
| 113 | else |
| 114 | echo "Stop ONOS on ${basename}$2" |
| 115 | dsh -w ${basename}$2 "cd $ONOS_DIR; ./start-onos.sh stop" |
| 116 | fi |
Masayoshi Kobayashi | f358ff5 | 2013-03-22 00:31:59 +0000 | [diff] [blame] | 117 | ;; |
| 118 | status) |
| 119 | echo "Checking ONOS Status" |
| 120 | dsh -g ${basename} "cd $ONOS_DIR; ./start-onos.sh status" |
| 121 | ;; |
| 122 | esac |
| 123 | } |
Masayoshi Kobayashi | 0ab03da | 2013-03-26 00:43:02 +0000 | [diff] [blame] | 124 | switch () { |
| 125 | case "$1" in |
| 126 | local) |
| 127 | if [ x$2 == "x" -o x$2 == "xall" ]; then |
| 128 | echo "set all switches point to local controller" |
| 129 | dsh -g ${basename} "$ONOS_DIR/scripts/ctrl-local.sh" |
| 130 | else |
| 131 | dsh -w ${basename}$2 "$ONOS_DIR/scripts/ctrl-local.sh" |
| 132 | fi |
| 133 | ;; |
| 134 | all) |
| 135 | if [ x$2 == "x" -o x$2 == "xall" ]; then |
| 136 | echo "set all non-core switches point to all non-core controllers" |
Masayoshi Kobayashi | 4a1542b | 2013-04-02 22:34:13 +0000 | [diff] [blame] | 137 | 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] | 138 | else |
Masayoshi Kobayashi | 4a1542b | 2013-04-02 22:34:13 +0000 | [diff] [blame] | 139 | dsh -w ${basename}$2 "$ONOS_DIR/scripts/ctrl-add-ext.sh" |
Masayoshi Kobayashi | 0ab03da | 2013-03-26 00:43:02 +0000 | [diff] [blame] | 140 | fi |
| 141 | ;; |
| 142 | none) |
| 143 | if [ x$2 == "x" -o x$2 == "xall" ]; then |
| 144 | echo "all non-core switches loose controller" |
| 145 | dsh -g ${basename} -x ${basename}1 "$ONOS_DIR/scripts/ctrl-none.sh" |
| 146 | else |
| 147 | dsh -w ${basename}$2 "$ONOS_DIR/scripts/ctrl-none.sh" |
| 148 | fi |
| 149 | ;; |
| 150 | esac |
| 151 | } |