blob: 961a5cb5cfb64c9d44bf385c1c12418e47b0d3b2 [file] [log] [blame]
Neha Jainde45c682018-04-05 11:51:29 -04001#!/usr/bin/perl -s
2use strict;
3
4my $keyWord_standby = "standby";
5my $keyWord_active = "active";
6my $keyWord_true = "true";
7my $keyWord_false = "false";
8my $keyWord_success = "success";
9my $keyWord_failure = "failure";
10my $file_cluster = "sdnc.cluster";
11my $file_switchVoting = "switchVoting.sh";
12my $file_isPrimaryCluster = "sdnc.isPrimaryCluster";
13
14if ((!(-e $file_cluster)) || (!(-e $file_switchVoting))|| (!(-e $file_isPrimaryCluster))) {
15 # file not exist.
16 print qq|$keyWord_failure\n|;
17 exit 1;
18}
19
20my $roleRes = qx("./$file_isPrimaryCluster");
21my $clusterRes = qx("./$file_cluster");
22
23if ( 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
55sub sub_activate_primary {
56 #Switching voting in Primary cluster
57 system("./$file_switchVoting primary");
58 print qq|$keyWord_success\n|;
59}
60
61sub sub_activate_secondary {
62 #Switching voting in secondary cluster
63 system("./$file_switchVoting secondary");
64 print qq|$keyWord_success\n|;
65}