If one of the static nat rules failed to apply on the backend, the end result should be false

This commit is contained in:
alena 2011-08-12 18:00:16 -07:00
parent 779989ce6b
commit d72200bbfc
5 changed files with 22 additions and 8 deletions

View File

@ -25,7 +25,7 @@ public class SetFirewallRulesAnswer extends Answer {
protected SetFirewallRulesAnswer() {
}
public SetFirewallRulesAnswer(SetFirewallRulesCommand cmd, Boolean success, String[] results) {
public SetFirewallRulesAnswer(SetFirewallRulesCommand cmd, boolean success, String[] results) {
super(cmd, success, null);
assert (cmd.getRules().length == results.length) : "rules and their results should be the same length don't you think?";
this.results = results;

View File

@ -25,8 +25,8 @@ public class SetPortForwardingRulesAnswer extends Answer {
super();
}
public SetPortForwardingRulesAnswer(SetPortForwardingRulesCommand cmd, String[] results) {
super(cmd, true, null);
public SetPortForwardingRulesAnswer(SetPortForwardingRulesCommand cmd, String[] results, boolean success) {
super(cmd, success, null);
assert(cmd.getRules().length == results.length) : "Shouldn't the results match the commands?";
this.results = results;

View File

@ -25,7 +25,7 @@ public class SetStaticNatRulesAnswer extends Answer {
super();
}
public SetStaticNatRulesAnswer(SetStaticNatRulesCommand cmd, String[] results, Boolean success) {
public SetStaticNatRulesAnswer(SetStaticNatRulesCommand cmd, String[] results, boolean success) {
super(cmd, success, null);
assert(cmd.getRules().length == results.length) : "Shouldn't the results match the commands?";

View File

@ -171,6 +171,8 @@ public class VirtualRoutingResource implements Manager {
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
String[] results = new String[cmd.getRules().length];
int i = 0;
boolean endResult = true;
for (PortForwardingRuleTO rule : cmd.getRules()) {
String result = null;
final Script command = new Script(_firewallPath, _timeout, s_logger);
@ -183,10 +185,15 @@ public class VirtualRoutingResource implements Manager {
command.add("-r ", rule.getDstIp());
command.add("-d ", rule.getStringDstPortRange());
result = command.execute();
results[i++] = (!(result == null || result.isEmpty())) ? "Failed" : null;
if (result == null || result.isEmpty()) {
results[i++] = "Failed";
endResult = false;
} else {
results[i++] = null;
}
}
return new SetPortForwardingRulesAnswer(cmd, results);
return new SetPortForwardingRulesAnswer(cmd, results, endResult);
}
private Answer execute(SetStaticNatRulesCommand cmd) {

View File

@ -1244,6 +1244,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
String[] results = new String[cmd.getRules().length];
int i = 0;
boolean endResult = true;
for (PortForwardingRuleTO rule : cmd.getRules()) {
StringBuilder args = new StringBuilder();
args.append(routerIp);
@ -1256,10 +1258,15 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
String result = callHostPlugin(conn, "vmops", "setFirewallRule", "args", args.toString());
results[i++] = (result == null || result.isEmpty()) ? "Failed" : null;
if (result == null || result.isEmpty()) {
results[i++] = "Failed";
endResult = false;
} else {
results[i++] = null;
}
}
return new SetPortForwardingRulesAnswer(cmd, results);
return new SetPortForwardingRulesAnswer(cmd, results, endResult);
}
protected SetStaticNatRulesAnswer execute(SetStaticNatRulesCommand cmd) {