Multi-site High-availability Manual Failover (PoC) 11/39711/1
authorPrudence Au <prudence.au@amdocs.com>
Wed, 28 Mar 2018 15:15:32 +0000 (11:15 -0400)
committerPrudence Au <prudence.au@amdocs.com>
Wed, 28 Mar 2018 15:15:44 +0000 (11:15 -0400)
Change-Id: I690a52ec26acaf6c0d81a7a4f5dc9f922409be33
Signed-off-by: Prudence Au <prudence.au@amdocs.com>
Issue-ID: SDNC-214

Former-commit-id: d031a8ebdf7201a4616f195762ecf7afc4c79aa7

installation/sdnc/src/main/scripts/sdnc.cluster [new file with mode: 0755]
installation/sdnc/src/main/scripts/sdnc.failover [new file with mode: 0755]
installation/sdnc/src/main/scripts/sdnc.isPrimaryCluster [new file with mode: 0755]
installation/sdnc/src/main/scripts/switchVoting.sh [new file with mode: 0755]

diff --git a/installation/sdnc/src/main/scripts/sdnc.cluster b/installation/sdnc/src/main/scripts/sdnc.cluster
new file mode 100755 (executable)
index 0000000..35b6072
--- /dev/null
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+OOM_HOME=${OOM_HOME:-$HOME}
+
+if ! [ "$(command -v jq)" ]; then
+  echo "Error: jq is not installed."
+  echo "use: sudo apt install jq"
+  exit 1
+fi 
+
+IS_PRIMARY_CLUSTER=`./sdnc.isPrimaryCluster`
+
+case $IS_PRIMARY_CLUSTER in
+true)
+   MEMBER_NUMBER=1
+   ;;
+false)
+   MEMBER_NUMBER=4
+   ;;
+*)
+  echo "Error: isPrimaryODLCluster not defined in ${OOM_HOME}/oom/kubernetes/sdnc/values.yaml."
+  exit 1
+  ;;
+esac
+
+for pod_number in {0..2}
+do
+   curl  "http://localhost:3028$((${pod_number} + 1))" > /dev/null 2>&1
+   if [ "$?" = "7" ]; then
+      continue 
+   fi
+
+   VOTING_RESULT=`curl -u admin:admin -H "Content-Type: application/json" -H "Accept: application/json" -X GET http://localhost:3028$((${pod_number} + 1))/jolokia/read/org.opendaylight.controller:Category=Shards,name=member-$((${MEMBER_NUMBER} + ${pod_number}))-shard-default-config,type=DistributedConfigDatastore 2>/dev/null | jq '.value.Voting'` 
+
+   case $VOTING_RESULT in
+   true)
+      echo "active"
+      exit 0
+      ;;
+   false)
+      echo "standby"
+      exit 0
+      ;;
+   *) 
+     echo "Error: Voting status could not be determined."
+     exit 1
+     ;;
+   esac
+done
+
+echo "Error: Voting status could not be determined."
+exit 1
diff --git a/installation/sdnc/src/main/scripts/sdnc.failover b/installation/sdnc/src/main/scripts/sdnc.failover
new file mode 100755 (executable)
index 0000000..b002ae6
--- /dev/null
@@ -0,0 +1,65 @@
+#!/usr/bin/perl -s\r
+use strict;\r
+\r
+my $keyWord_standby = "standby";\r
+my $keyWord_active = "active";\r
+my $keyWord_true = "true";\r
+my $keyWord_false = "false";\r
+my $keyWord_success = "success";\r
+my $keyWord_failure = "failure";\r
+my $file_cluster = "sdnc.cluster";\r
+my $file_switchVoting = "switchVoting.sh";\r
+my $file_isPrimaryCluster = "sdnc.isPrimaryCluster";\r
+\r
+if ((!(-e $file_cluster)) || (!(-e $file_switchVoting))|| (!(-e $file_isPrimaryCluster))) {\r
+  # file not exist.\r
+  print qq|$keyWord_failure\n|;\r
+  exit 1;\r
+}\r
+\r
+my $roleRes = qx("./$file_isPrimaryCluster");\r
+my $clusterRes = qx("./$file_cluster");\r
+\r
+if ( index ($clusterRes, $keyWord_standby) != -1) {\r
+       # We are at standby side\r
+       if ( index ($roleRes, $keyWord_false) != -1) {\r
+          # We are at Secondary cluster\r
+          sub_activate_secondary();\r
+    } elsif ( index ($roleRes, $keyWord_true) != -1) {\r
+       # We are at Primary cluster\r
+          sub_activate_primary();\r
+    } else {\r
+      # Error.\r
+      print qq|$keyWord_failure\n|;\r
+      exit 1;          \r
+       }       \r
+} elsif ( index ($clusterRes, $keyWord_active) != -1) {\r
+    # We are at active side    \r
+       if ( index ($roleRes, $keyWord_false) != -1) {\r
+          # We are at Secondary cluster\r
+          sub_activate_primary();\r
+    } elsif ( index ($roleRes, $keyWord_true) != -1)  {\r
+       # We are at Primary cluster\r
+          sub_activate_secondary();\r
+    } else {\r
+      # Error.\r
+      print qq|$keyWord_failure\n|;\r
+      exit 1;          \r
+       }       \r
+} else {\r
+   # Error.\r
+  print qq|$keyWord_failure\n|;\r
+  exit 1;   \r
+}\r
+\r
+sub sub_activate_primary {\r
+               #Switching voting in Primary cluster \r
+        system("./$file_switchVoting primary");\r
+           print qq|$keyWord_success\n|;\r
+}\r
+\r
+sub sub_activate_secondary {\r
+               #Switching voting in secondary cluster\r
+        system("./$file_switchVoting secondary");\r
+           print qq|$keyWord_success\n|;\r
+}\r
diff --git a/installation/sdnc/src/main/scripts/sdnc.isPrimaryCluster b/installation/sdnc/src/main/scripts/sdnc.isPrimaryCluster
new file mode 100755 (executable)
index 0000000..c14f717
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+OOM_HOME=${OOM_HOME:-$HOME}
+
+IS_PRIMARY_CLUSTER=`awk '/isPrimaryODLCluster/ {print $2}' ${OOM_HOME}/oom/kubernetes/sdnc/values.yaml`
+
+if [ "$?" -eq "2" ]; then
+      echo "Make sure you are ubuntu user." >&2
+fi
+
+case $IS_PRIMARY_CLUSTER in 
+true|false)
+       echo $IS_PRIMARY_CLUSTER
+       ;;
+*)
+       echo "NOT CLUSTERED"
+       exit 1
+       ;;
+esac
diff --git a/installation/sdnc/src/main/scripts/switchVoting.sh b/installation/sdnc/src/main/scripts/switchVoting.sh
new file mode 100755 (executable)
index 0000000..05d1e0f
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+function usage()
+{
+    echo usage: switchVoting.sh primary\|secondary
+    exit 1
+}
+
+if [ $# -ne 1 ]; then
+    usage
+fi
+
+partition=$1
+
+if [ "$partition" == "primary" ]; then
+   curl -u admin:Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U -H "Content-Type: application/json" -H "Accept: application/json" -X POST http://localhost:30202/restconf/operations/cluster-admin:change-member-voting-states-for-all-shards -d '{ "input" : { "member-voting-state" : [ { "member-name" : "member-1", "voting":true}, { "member-name" : "member-2", "voting":true}, { "member-name" : "member-3", "voting":true},{ "member-name" : "member-4", "voting":false},{ "member-name" : "member-5", "voting":false},{ "member-name" : "member-6", "voting":false}] } }' > switch_voting_resp.json 2>/dev/null
+   echo "" >> switch_voting_resp.json
+   exit 0
+fi
+
+if [ "$partition" == "secondary" ]; then
+   curl -u admin:Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U -H "Content-Type: application/json" -H "Accept: application/json" -X POST http://localhost:30202/restconf/operations/cluster-admin:change-member-voting-states-for-all-shards -d '{ "input" : { "member-voting-state" : [ { "member-name" : "member-1", "voting":false}, { "member-name" : "member-2", "voting":false}, { "member-name" : "member-3", "voting":false},{ "member-name" : "member-4", "voting":true},{ "member-name" : "member-5", "voting":true},{ "member-name" : "member-6", "voting":true}] } }' > switch_voting_resp.json 2>/dev/null
+   echo "" >> switch_voting_resp.json
+   exit 0
+fi
+
+usage