Neha Jain | de45c68 | 2018-04-05 11:51:29 -0400 | [diff] [blame] | 1 | #!/usr/bin/perl -s
|
| 2 | use strict;
|
| 3 |
|
| 4 | my $keyWord_standby = "standby";
|
| 5 | my $keyWord_active = "active";
|
| 6 | my $keyWord_true = "true";
|
| 7 | my $keyWord_false = "false";
|
| 8 | my $keyWord_success = "success";
|
| 9 | my $keyWord_failure = "failure";
|
| 10 | my $file_cluster = "sdnc.cluster";
|
| 11 | my $file_switchVoting = "switchVoting.sh";
|
| 12 | my $file_isPrimaryCluster = "sdnc.isPrimaryCluster";
|
| 13 |
|
| 14 | if ((!(-e $file_cluster)) || (!(-e $file_switchVoting))|| (!(-e $file_isPrimaryCluster))) {
|
| 15 | # file not exist.
|
| 16 | print qq|$keyWord_failure\n|;
|
| 17 | exit 1;
|
| 18 | }
|
| 19 |
|
| 20 | my $roleRes = qx("./$file_isPrimaryCluster");
|
| 21 | my $clusterRes = qx("./$file_cluster");
|
| 22 |
|
| 23 | if ( index ($clusterRes, $keyWord_standby) != -1) {
|
| 24 | # We are at standby side
|
| 25 | if ( index ($roleRes, $keyWord_false) != -1) {
|
| 26 | # We are at Secondary cluster
|
| 27 | sub_activate_secondary();
|
| 28 | } elsif ( index ($roleRes, $keyWord_true) != -1) {
|
| 29 | # We are at Primary cluster
|
| 30 | sub_activate_primary();
|
| 31 | } else {
|
| 32 | # Error.
|
| 33 | print qq|$keyWord_failure\n|;
|
| 34 | exit 1;
|
| 35 | }
|
| 36 | } elsif ( index ($clusterRes, $keyWord_active) != -1) {
|
| 37 | # We are at active side
|
| 38 | if ( index ($roleRes, $keyWord_false) != -1) {
|
| 39 | # We are at Secondary cluster
|
| 40 | sub_activate_primary();
|
| 41 | } elsif ( index ($roleRes, $keyWord_true) != -1) {
|
| 42 | # We are at Primary cluster
|
| 43 | sub_activate_secondary();
|
| 44 | } else {
|
| 45 | # Error.
|
| 46 | print qq|$keyWord_failure\n|;
|
| 47 | exit 1;
|
| 48 | }
|
| 49 | } else {
|
| 50 | # Error.
|
| 51 | print qq|$keyWord_failure\n|;
|
| 52 | exit 1;
|
| 53 | }
|
| 54 |
|
| 55 | sub sub_activate_primary {
|
| 56 | #Switching voting in Primary cluster
|
| 57 | system("./$file_switchVoting primary");
|
| 58 | print qq|$keyWord_success\n|;
|
| 59 | }
|
| 60 |
|
| 61 | sub sub_activate_secondary {
|
| 62 | #Switching voting in secondary cluster
|
| 63 | system("./$file_switchVoting secondary");
|
| 64 | print qq|$keyWord_success\n|;
|
| 65 | }
|