bug 11307: Enable CheckRouterAnswer to tell if redundant router's priority is bumped or not

This commit is contained in:
Sheng Yang 2011-09-14 02:58:43 -07:00
parent 9e0ee10e9f
commit 9cc1ecbce8
1 changed files with 27 additions and 5 deletions

View File

@ -23,6 +23,7 @@ public class CheckRouterAnswer extends Answer {
public static final String ROUTER_NAME = "router.name";
public static final String ROUTER_IP = "router.ip";
RedundantState state;
boolean isBumped;
protected CheckRouterAnswer() {
}
@ -30,7 +31,9 @@ public class CheckRouterAnswer extends Answer {
public CheckRouterAnswer(CheckRouterCommand cmd, String details, boolean parse) {
super(cmd, true, details);
if (parse) {
parseDetails(details);
if (!parseDetails(details)) {
this.result = false;
}
}
}
@ -38,16 +41,26 @@ public class CheckRouterAnswer extends Answer {
super(cmd, false, details);
}
protected void parseDetails(String details) {
if (details.startsWith("Status: MASTER")) {
protected boolean parseDetails(String details) {
String[] lines = details.split("&");
if (lines.length != 2) {
return false;
}
if (lines[0].startsWith("Status: MASTER")) {
state = RedundantState.MASTER;
} else if (details.startsWith("Status: BACKUP")) {
} else if (lines[0].startsWith("Status: BACKUP")) {
state = RedundantState.BACKUP;
} else if (details.startsWith("Status: FAULT")) {
} else if (lines[0].startsWith("Status: FAULT")) {
state = RedundantState.FAULT;
} else {
state = RedundantState.UNKNOWN;
}
if (lines[1].startsWith("Bumped: YES")) {
isBumped = true;
} else {
isBumped = false;
}
return true;
}
public void setState(RedundantState state) {
@ -57,4 +70,13 @@ public class CheckRouterAnswer extends Answer {
public RedundantState getState() {
return state;
}
public boolean isBumped() {
return isBumped;
}
public void setIsBumped(boolean isBumped) {
this.isBumped = isBumped;
}
}